Bug 1395871 - Open customWidget menus on mousedown, rather than oncommand. draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Tue, 05 Sep 2017 21:35:20 -0700
changeset 659667 d51acab19adc1dc08a23cfc8680de3075991f19d
parent 659666 9dd6970bc434360ac037d8378c4f303a94da4627
child 659668 b64fb149c45a877feddc94081d4ebcd502a848ab
child 659669 d9fd8b5bc9bf13818b1de5e203fb923a65912050
push id78150
push userbmo:gandalf@aviary.pl
push dateWed, 06 Sep 2017 04:38:40 +0000
bugs1395871
milestone57.0a1
Bug 1395871 - Open customWidget menus on mousedown, rather than oncommand. MozReview-Commit-ID: 2K4uYSu7Nai
browser/components/customizableui/CustomizableUI.jsm
browser/components/extensions/ext-browserAction.js
--- a/browser/components/customizableui/CustomizableUI.jsm
+++ b/browser/components/customizableui/CustomizableUI.jsm
@@ -1218,16 +1218,17 @@ var CustomizableUIInternal = {
     this.notifyListeners("onWidgetBeforeDOMChange", aNode, aNextNode, aContainer);
     this.setLocationAttributes(aNode, aArea);
     aContainer.insertBefore(aNode, aNextNode);
     this.notifyListeners("onWidgetAfterDOMChange", aNode, aNextNode, aContainer);
   },
 
   handleEvent(aEvent) {
     switch (aEvent.type) {
+      case "mousedown":
       case "command":
         if (!this._originalEventInPanel(aEvent)) {
           break;
         }
         aEvent = aEvent.sourceEvent;
         // Fall through
       case "click":
       case "keypress":
@@ -1400,17 +1401,21 @@ var CustomizableUIInternal = {
 
       let tooltip = this.getLocalizedProperty(aWidget, "tooltiptext", additionalTooltipArguments);
       if (tooltip) {
         node.setAttribute("tooltiptext", tooltip);
       }
       node.setAttribute("class", "toolbarbutton-1 chromeclass-toolbar-additional");
 
       let commandHandler = this.handleWidgetCommand.bind(this, aWidget, node);
-      node.addEventListener("command", commandHandler);
+      if (aWidget.type === "view") {
+        node.addEventListener("mousedown", commandHandler);
+      } else {
+        node.addEventListener("command", commandHandler);
+      }
       let clickHandler = this.handleWidgetClick.bind(this, aWidget, node);
       node.addEventListener("click", clickHandler);
 
       // If the widget has a view, and has view showing / hiding listeners,
       // hook those up to this widget.
       if (aWidget.type == "view") {
         log.debug("Widget " + aWidget.id + " has a view. Auto-registering event handlers.");
         let viewNode = aDocument.getElementById(aWidget.viewId);
@@ -1716,17 +1721,17 @@ var CustomizableUIInternal = {
       if (aEvent.keyCode != aEvent.DOM_VK_RETURN) {
         return;
       }
       // If the user hit enter/return, we don't check preventDefault - it makes sense
       // that this was prevented, but we probably still want to close the panel.
       // If consumers don't want this to happen, they should specify the closemenu
       // attribute.
 
-    } else if (aEvent.type != "command") { // mouse events:
+    } else if (aEvent.type != "command" || aEvent.type != "mousedown") { // mouse events:
       if (aEvent.defaultPrevented || aEvent.button != 0) {
         return;
       }
       let isInteractive = this._isOnInteractiveElement(aEvent);
       log.debug("maybeAutoHidePanel: interactive ? " + isInteractive);
       if (isInteractive) {
         return;
       }
--- a/browser/components/extensions/ext-browserAction.js
+++ b/browser/components/extensions/ext-browserAction.js
@@ -259,17 +259,18 @@ this.browserAction = class extends Exten
     // Popups are shown only if a popup URL is defined; otherwise
     // a "click" event is dispatched. This is done for compatibility with the
     // Google Chrome onClicked extension API.
     if (this.getProperty(tab, "popup")) {
       if (this.widget.areaType == CustomizableUI.TYPE_MENU_PANEL) {
         await window.document.getElementById("nav-bar").overflowable.show();
       }
 
-      let event = new window.CustomEvent("command", {bubbles: true, cancelable: true});
+      const activationEvent = widget.type ? "mousedown" : "command";
+      let event = new window.CustomEvent(activationEvent, {bubbles: true, cancelable: true});
       widget.node.dispatchEvent(event);
     } else {
       this.tabManager.addActiveTabPermission(tab);
       this.emit("click");
     }
   }
 
   handleEvent(event) {