Bug 1444392 - Part 3 - Simplify the PanelUI.show method. r=Gijs draft
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Tue, 03 Apr 2018 11:55:12 +0100
changeset 776591 b824d9c1dd2326019f7a59b7581d022d5d864d0d
parent 776590 db491b30c3149995e5681dfb3fa975233bac05db
push id104910
push userpaolo.mozmail@amadzone.org
push dateTue, 03 Apr 2018 10:55:58 +0000
reviewersGijs
bugs1444392
milestone61.0a1
Bug 1444392 - Part 3 - Simplify the PanelUI.show method. r=Gijs In addition to removing the unnecessary return value and the logic that may anchor the panel to anything other than the main menu button, this also fixes the asynchronous error handling. MozReview-Commit-ID: KaUKYUhrUoc
browser/components/customizableui/content/panelUI.js
browser/tools/mozscreenshots/mozscreenshots/extension/configurations/AppMenu.jsm
--- a/browser/components/customizableui/content/panelUI.js
+++ b/browser/components/customizableui/content/panelUI.js
@@ -189,46 +189,34 @@ const PanelUI = {
    * 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(aEvent) {
     this._ensureShortcutsShown();
-    return new Promise(resolve => {
-      this.ensureReady().then(() => {
-        if (this.panel.state == "open" ||
-            document.documentElement.hasAttribute("customizing")) {
-          resolve();
-          return;
-        }
+    (async () => {
+      await this.ensureReady();
+
+      if (this.panel.state == "open" ||
+          document.documentElement.hasAttribute("customizing")) {
+        return;
+      }
 
-        let anchor;
-        let domEvent = null;
-        if (!aEvent ||
-            aEvent.type == "command") {
-          anchor = this.menuButton;
-        } else {
-          domEvent = aEvent;
-          anchor = aEvent.target;
-        }
+      let domEvent = null;
+      if (aEvent && aEvent.type != "command") {
+        domEvent = aEvent;
+      }
 
-        this.panel.addEventListener("popupshown", function() {
-          resolve();
-        }, {once: true});
-
-        anchor = this._getPanelAnchor(anchor);
-        PanelMultiView.openPopup(this.panel, anchor, {
-          triggerEvent: domEvent,
-        }).catch(Cu.reportError);
-      }, (reason) => {
-        console.error("Error showing the PanelUI menu", reason);
+      let anchor = this._getPanelAnchor(this.menuButton);
+      await PanelMultiView.openPopup(this.panel, anchor, {
+        triggerEvent: domEvent,
       });
-    });
+    })().catch(Cu.reportError);
   },
 
   /**
    * If the menu panel is being shown, hide it.
    */
   hide() {
     if (document.documentElement.hasAttribute("customizing")) {
       return;
--- a/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/AppMenu.jsm
+++ b/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/AppMenu.jsm
@@ -54,17 +54,17 @@ var AppMenu = {
 
   },
 };
 
 async function reopenAppMenu(browserWindow) {
   browserWindow.PanelUI.hide();
   let view = browserWindow.document.getElementById("appMenu-mainView");
   let promiseViewShown = BrowserTestUtils.waitForEvent(view, "ViewShown");
-  await browserWindow.PanelUI.show();
+  browserWindow.PanelUI.show();
   await promiseViewShown;
 }
 
 function verifyConfigHelper() {
   if (isCustomizing()) {
     return "navigator:browser has the customizing attribute";
   }
   return undefined;