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
--- 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;