Bug 916732 - PanelUI should have dedicated show() API. r=Gijs
authorBlair McBride <bmcbride@mozilla.com>
Tue, 08 Oct 2013 21:24:26 +1300
changeset 164867 13213dc602172391a81dcabffa4d2d385a4615a7
parent 164866 aa03fbc1149f56b60a48f836908a7fb0a7673779
child 164868 d7cfe43bfada551c0fdefa5db7b9172ae7ad5f91
push id4703
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 20:24:19 +0000
treeherdermozilla-aurora@20af7fbd96c1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs916732
milestone27.0a1
Bug 916732 - PanelUI should have dedicated show() API. r=Gijs
browser/components/customizableui/content/panelUI.js
--- a/browser/components/customizableui/content/panelUI.js
+++ b/browser/components/customizableui/content/panelUI.js
@@ -85,64 +85,82 @@ const PanelUI = {
    */
   setMainView: function(aMainView) {
     this._ensureEventListenersAdded();
     this.multiView.setMainView(aMainView);
   },
 
   /**
    * Opens the menu panel if it's closed, or closes it if it's
-   * open. If the event target has a child with the toolbarbutton-icon
-   * attribute, the panel will be anchored on that child. Otherwise, the panel
-   * is anchored on the event target itself.
+   * open.
    *
    * @param aEvent the event that triggers the toggle.
    */
   toggle: function(aEvent) {
     // Don't show the panel if the window is in customization mode,
     // since this button doubles as an exit path for the user in this case.
     if (document.documentElement.hasAttribute("customizing")) {
       return;
     }
     this._ensureEventListenersAdded();
     if (this.panel.state == "open") {
       this.hide();
     } else if (this.panel.state == "closed") {
-      this.ensureReady().then(function() {
-        this.panel.hidden = false;
-        let editControlPlacement = CustomizableUI.getPlacementOfWidget("edit-controls");
-        if (editControlPlacement && editControlPlacement.area == CustomizableUI.AREA_PANEL) {
-          updateEditUIVisibility();
-        }
+      this.show(aEvent);
+    }
+  },
+
+  /**
+   * Opens the menu panel. If the event target has a child with the
+   * toolbarbutton-icon attribute, the panel will be anchored on that child.
+   * Otherwise, the panel is anchored on the event target itself.
+   *
+   * @param aEvent the event (if any) that triggers showing the menu.
+   */
+  show: function(aEvent) {
+    if (this.panel.state == "open" || this.panel.state == "showing" ||
+        document.documentElement.hasAttribute("customizing")) {
+      return;
+    }
 
-        let anchor;
-        if (aEvent.type == "mousedown" ||
-            aEvent.type == "command") {
-          anchor = this.menuButton;
-        } else {
-          anchor = aEvent.target;
-        }
-        let iconAnchor =
-          document.getAnonymousElementByAttribute(anchor, "class",
-                                                  "toolbarbutton-icon");
+    this.ensureReady().then(() => {
+      this.panel.hidden = false;
+      let editControlPlacement = CustomizableUI.getPlacementOfWidget("edit-controls");
+      if (editControlPlacement && editControlPlacement.area == CustomizableUI.AREA_PANEL) {
+        updateEditUIVisibility();
+      }
 
-        // Only focus the panel if it's opened using the keyboard, so that
-        // cut/copy/paste buttons will work for mouse users.
-        let keyboardOpened = aEvent.sourceEvent &&
-                             aEvent.sourceEvent.target.localName == "key";
-        this.panel.setAttribute("noautofocus", !keyboardOpened);
-        this.panel.openPopup(iconAnchor || anchor, "bottomcenter topright");
-      }.bind(this));
-    }
+      let anchor;
+      if (aEvent.type == "mousedown" ||
+          aEvent.type == "command") {
+        anchor = this.menuButton;
+      } else {
+        anchor = aEvent.target;
+      }
+      let iconAnchor =
+        document.getAnonymousElementByAttribute(anchor, "class",
+                                                "toolbarbutton-icon");
+
+      // Only focus the panel if it's opened using the keyboard, so that
+      // cut/copy/paste buttons will work for mouse users.
+      let keyboardOpened = aEvent.sourceEvent &&
+                           aEvent.sourceEvent.target.localName == "key";
+      this.panel.setAttribute("noautofocus", !keyboardOpened);
+      this.panel.openPopup(iconAnchor || anchor, "bottomcenter topright");
+    });
   },
 
   /**
    * If the menu panel is being shown, hide it.
    */
   hide: function() {
+    if (document.documentElement.hasAttribute("customizing")) {
+      return;
+    }
+
     this.panel.hidePopup();
   },
 
   handleEvent: function(aEvent) {
     switch (aEvent.type) {
       case "popupshowing":
         // Fall through
       case "popupshown":