Bug 1398390 - Only react to mousedown if it is a left-click. r=Gijs
authorZibi Braniecki <zbraniecki@mozilla.com>
Sat, 09 Sep 2017 22:17:19 -0700
changeset 662260 48a86fd5097d92b917eafc7470ed6d9e0ddb0e7a
parent 662259 246b6aae81574dc633230f434efd7a06d344d558
child 662261 529bfc306853af0afdbc2471deaca2c979be8617
push id79014
push userbmo:bpostelnicu@mozilla.com
push dateMon, 11 Sep 2017 09:58:20 +0000
reviewersGijs
bugs1398390
milestone57.0a1
Bug 1398390 - Only react to mousedown if it is a left-click. r=Gijs MozReview-Commit-ID: Ie2Xgasg2eN
browser/base/content/browser-pageActions.js
browser/components/customizableui/CustomizableUI.jsm
browser/components/customizableui/content/panelUI.js
browser/components/downloads/content/indicator.js
browser/components/downloads/test/browser/browser_overflow_anchor.js
--- a/browser/base/content/browser-pageActions.js
+++ b/browser/base/content/browser-pageActions.js
@@ -552,17 +552,17 @@ var BrowserPageActions = {
   /**
    * Call this when the main page action button in the urlbar is activated.
    *
    * @param  event (DOM event, required)
    *         The click or whatever event.
    */
   mainButtonClicked(event) {
     event.stopPropagation();
-    if ((event.type == "click" && event.button != 0) ||
+    if ((event.type == "mousedown" && event.button != 0) ||
         (event.type == "keypress" && event.charCode != KeyEvent.DOM_VK_SPACE &&
          event.keyCode != KeyEvent.DOM_VK_RETURN)) {
       return;
     }
 
     // If the activated-action panel is open and anchored to the main button,
     // close it.
     let panelNode = this.activatedActionPanelNode;
--- a/browser/components/customizableui/CustomizableUI.jsm
+++ b/browser/components/customizableui/CustomizableUI.jsm
@@ -4225,16 +4225,19 @@ OverflowableToolbar.prototype = {
   },
 
   handleEvent(aEvent) {
     switch (aEvent.type) {
       case "aftercustomization":
         this._enable();
         break;
       case "mousedown":
+        if (aEvent.button != 0) {
+          break;
+        }
         if (aEvent.target == this._chevron) {
           this._onClickChevron(aEvent);
         } else {
           this._panel.hidePopup();
         }
         break;
       case "customizationstarting":
         this._disable();
--- a/browser/components/customizableui/content/panelUI.js
+++ b/browser/components/customizableui/content/panelUI.js
@@ -354,16 +354,19 @@ const PanelUI = {
    * @param aAnchor the element that spawned the subview.
    * @param aPlacementArea the CustomizableUI area that aAnchor is in.
    * @param aEvent the event triggering the view showing.
    */
   async showSubView(aViewId, aAnchor, aPlacementArea, aEvent) {
 
     let domEvent = null;
     if (aEvent) {
+      if (aEvent.type == "mousedown" && aEvent.button != 0) {
+        return;
+      }
       if (aEvent.type == "command" && aEvent.inputSource != null) {
         // Synthesize a new DOM mouse event to pass on the inputSource.
         domEvent = document.createEvent("MouseEvent");
         domEvent.initNSMouseEvent("click", true, true, null, 0, aEvent.screenX, aEvent.screenY,
                                   0, 0, false, false, false, false, 0, aEvent.target, 0, aEvent.inputSource);
       } else if (aEvent.mozInputSource != null) {
         domEvent = aEvent;
       }
--- a/browser/components/downloads/content/indicator.js
+++ b/browser/components/downloads/content/indicator.js
@@ -499,16 +499,20 @@ const DownloadsIndicatorView = {
   // User interface event functions
 
   onWindowUnload() {
     // This function is registered as an event listener, we can't use "this".
     DownloadsIndicatorView.ensureTerminated();
   },
 
   onCommand(aEvent) {
+    if (aEvent.type == "mousedown" && aEvent.button != 0) {
+      return;
+    }
+
     // If the downloads button is in the menu panel, open the Library
     let widgetGroup = CustomizableUI.getWidget("downloads-button");
     if (widgetGroup.areaType == CustomizableUI.TYPE_MENU_PANEL) {
       DownloadsPanel.showDownloadsHistory();
     } else {
       DownloadsPanel.showPanel();
     }
 
--- a/browser/components/downloads/test/browser/browser_overflow_anchor.js
+++ b/browser/components/downloads/test/browser/browser_overflow_anchor.js
@@ -33,17 +33,17 @@ add_task(async function test_overflow_an
   const kFlexyItems = ["urlbar-container"];
   registerCleanupFunction(() => unlockWidth(kFlexyItems));
   lockWidth(kFlexyItems);
 
   window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   await waitForOverflowed(button, true);
 
   let promise = promisePanelOpened();
-  button.node.dispatchEvent(new Event("mousedown"));
+  EventUtils.sendMouseEvent({ type: "mousedown", button: 0 }, button.node);
   await promise;
 
   let panel = DownloadsPanel.panel;
   let chevron = document.getElementById("nav-bar-overflow-button");
   is(panel.anchorNode, chevron, "Panel should be anchored to the chevron.");
 
   DownloadsPanel.hidePanel();
 
@@ -53,17 +53,17 @@ add_task(async function test_overflow_an
   // Put the window back to its original dimensions.
   window.resizeTo(oldWidth, window.outerHeight);
 
   // The downloads button should eventually be un-overflowed.
   await waitForOverflowed(button, false);
 
   // Now try opening the panel again.
   promise = promisePanelOpened();
-  button.node.dispatchEvent(new Event("mousedown"));
+  EventUtils.sendMouseEvent({ type: "mousedown", button: 0 }, button.node);
   await promise;
 
   is(panel.anchorNode.id, "downloads-indicator-anchor");
 
   DownloadsPanel.hidePanel();
 });
 
 /**