Bug 1499227 - Trigger multiselect on mousedown event instead of on click event. r=jaws
authorAbdoulaye O. Ly <ablayelyfondou@gmail.com>
Wed, 24 Oct 2018 17:26:24 +0000
changeset 491172 1564ebaca63f8f796ababdcb61c7df09c189b3a9
parent 491171 121ccc3d4437ee3a44aa29d4c94feb17073f815c
child 491173 7790c75ca3911352162feecf5b61dbe29233b259
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersjaws
bugs1499227
milestone65.0a1
Bug 1499227 - Trigger multiselect on mousedown event instead of on click event. r=jaws Differential Revision: https://phabricator.services.mozilla.com/D9359
browser/base/content/tabbrowser.xml
browser/base/content/test/tabs/browser_multiselect_tabs_close.js
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -2309,92 +2309,91 @@
       <handler event="dragstart"><![CDATA[
         if (this.mOverCloseButton) {
           event.stopPropagation();
         }
       ]]></handler>
 
       <handler event="mousedown" phase="capturing">
       <![CDATA[
-        if (event.button == 0 && !this.selected && this.multiselected) {
-          gBrowser.lockClearMultiSelectionOnce();
-        }
+        let tabContainer = this.parentNode;
 
-        let tabContainer = this.parentNode;
         if (tabContainer._closeTabByDblclick &&
             event.button == 0 &&
             event.detail == 1) {
           this._selectedOnFirstMouseDown = this.selected;
         }
 
         if (this.selected) {
           this.style.MozUserFocus = "ignore";
-        } else {
-          // When browser.tabs.multiselect config is set to false,
-          // then we ignore the state of multi-selection keys (Ctrl/Cmd).
-          const tabSelectionToggled = tabContainer._multiselectEnabled &&
-            (event.getModifierState("Accel") || event.shiftKey);
-
-          if (this.mOverCloseButton || this._overPlayingIcon || tabSelectionToggled) {
+        } else if (this.mOverCloseButton || this._overPlayingIcon) {
             // Prevent tabbox.xml from selecting the tab.
             event.stopPropagation();
-          }
         }
 
         if (event.button == 1) {
           gBrowser.warmupTab(gBrowser._findTabToBlurTo(this));
         }
+
+        if (event.button == 0 && tabContainer._multiselectEnabled) {
+          let shiftKey = event.shiftKey;
+          let accelKey = event.getModifierState("Accel");
+          if (shiftKey) {
+            const lastSelectedTab = gBrowser.lastMultiSelectedTab;
+            if (!accelKey) {
+              gBrowser.selectedTab = lastSelectedTab;
+
+              // Make sure selection is cleared when tab-switch doesn't happen.
+              gBrowser.clearMultiSelectedTabs(false);
+            }
+            gBrowser.addRangeToMultiSelectedTabs(lastSelectedTab, this);
+
+            // Prevent tabbox.xml from selecting the tab.
+            event.stopPropagation();
+          } else if (accelKey) {
+            // Ctrl (Cmd for mac) key is pressed
+            if (this.multiselected) {
+              gBrowser.removeFromMultiSelectedTabs(this, true);
+            } else if (this != gBrowser.selectedTab) {
+              gBrowser.addToMultiSelectedTabs(this, false);
+              gBrowser.lastMultiSelectedTab = this;
+            }
+
+            // Prevent tabbox.xml from selecting the tab.
+            event.stopPropagation();
+          } else if (!this.selected && this.multiselected) {
+            gBrowser.lockClearMultiSelectionOnce();
+          }
+        }
       ]]>
       </handler>
       <handler event="mouseup">
         // Make sure that clear-selection is released.
         // Otherwise selection using Shift key may be broken.
         gBrowser.unlockClearMultiSelection();
 
         this.style.MozUserFocus = "";
       </handler>
 
       <handler event="click" button="0"><![CDATA[
-        let tabContainer = this.parentNode;
-        if (tabContainer._multiselectEnabled) {
-          let shiftKey = event.shiftKey;
-          let accelKey = event.getModifierState("Accel");
-          if (shiftKey) {
-            const lastSelectedTab = gBrowser.lastMultiSelectedTab;
-            if (!accelKey) {
-              gBrowser.selectedTab = lastSelectedTab;
+        if (event.getModifierState("Accel") || event.shiftKey) {
+          return;
+        }
 
-              // Make sure selection is cleared when tab-switch doesn't happen.
-              gBrowser.clearMultiSelectedTabs(false);
-            }
-            gBrowser.addRangeToMultiSelectedTabs(lastSelectedTab, this);
-            return;
-          }
-          if (accelKey) {
-            // Ctrl (Cmd for mac) key is pressed
-            if (this.multiselected) {
-              gBrowser.removeFromMultiSelectedTabs(this, true);
-            } else if (this != gBrowser.selectedTab) {
-              gBrowser.addToMultiSelectedTabs(this, false);
-              gBrowser.lastMultiSelectedTab = this;
-            }
-            return;
-          }
+        if (gBrowser.multiSelectedTabsCount > 0 &&
+          !this.mOverCloseButton &&
+          !this._overPlayingIcon) {
+          // Tabs were previously multi-selected and user clicks on a tab
+          // without holding Ctrl/Cmd Key
 
-          const overCloseButton = event.originalTarget.getAttribute("anonid") == "close-button";
-          if (gBrowser.multiSelectedTabsCount > 0 && !overCloseButton && !this._overPlayingIcon) {
-            // Tabs were previously multi-selected and user clicks on a tab
-            // without holding Ctrl/Cmd Key
+          // Force positional attributes to update when the
+          // target (of the click) is the "active" tab.
+          let updatePositionalAttr = gBrowser.selectedTab == this;
 
-            // Force positional attributes to update when the
-            // target (of the click) is the "active" tab.
-            let updatePositionalAttr = gBrowser.selectedTab == this;
-
-            gBrowser.clearMultiSelectedTabs(updatePositionalAttr);
-          }
+          gBrowser.clearMultiSelectedTabs(updatePositionalAttr);
         }
 
         if (this._overPlayingIcon) {
           if (this.multiselected) {
             gBrowser.toggleMuteAudioOnMultiSelectedTabs(this);
           } else {
             this.toggleMuteAudio();
           }
--- a/browser/base/content/test/tabs/browser_multiselect_tabs_close.js
+++ b/browser/base/content/test/tabs/browser_multiselect_tabs_close.js
@@ -43,17 +43,18 @@ add_task(async function usingTabCloseBut
   ok(tab2.multiselected, "Tab2 is multiselected");
   ok(!tab2.closing, "Tab2 is not closing");
   ok(!tab3.multiselected, "Tab3 is not multiselected");
   ok(!tab3.closing, "Tab3 is not closing");
   ok(tab4.closing, "Tab4 is closing");
   is(gBrowser.multiSelectedTabsCount, 2, "Two multiselected tabs");
 
   // Closing a selected tab
-  let tab2CloseBtn = document.getAnonymousElementByAttribute(tab1, "anonid", "close-button");
+  let tab2CloseBtn = document.getAnonymousElementByAttribute(tab2, "anonid", "close-button");
+  tab2.mOverCloseButton = true;
   let tab1Closing = BrowserTestUtils.waitForTabClosing(tab1);
   let tab2Closing = BrowserTestUtils.waitForTabClosing(tab2);
   tab2CloseBtn.click();
   await tab1Closing;
   await tab2Closing;
 
   ok(tab1.closing, "Tab1 is closing");
   ok(tab2.closing, "Tab2 is closing");