Bug 1435142 - Part 1: pref to enable close selected tab by dblclicking it. r=dao
☠☠ backed out by ea5c6ffc930e ☠ ☠
authorHector Zhao <bzhao@mozilla.com>
Fri, 02 Feb 2018 11:37:58 +0800
changeset 769696 069febd18b9e2b445ecdaf4e6f2151c9450d6247
parent 769695 f2149d69f47cd9e7a2d0b478c2c63cb020dbfda9
child 769697 e9ddfb08a712c1698441277bef7cfda96dee38c7
push id103206
push userbmo:bdahl@mozilla.com
push dateMon, 19 Mar 2018 23:33:04 +0000
reviewersdao
bugs1435142
milestone61.0a1
Bug 1435142 - Part 1: pref to enable close selected tab by dblclicking it. r=dao MozReview-Commit-ID: ErulnUeVK0F
browser/app/profile/firefox.js
browser/base/content/tabbrowser.xml
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -453,16 +453,17 @@ pref("browser.link.open_newwindow.restri
 // different.
 #ifdef XP_MACOSX
 pref("browser.link.open_newwindow.disabled_in_fullscreen", true);
 #else
 pref("browser.link.open_newwindow.disabled_in_fullscreen", false);
 #endif
 
 // Tabbed browser
+pref("browser.tabs.closeTabByDblclick", false);
 pref("browser.tabs.closeWindowWithLastTab", true);
 pref("browser.tabs.insertRelatedAfterCurrent", true);
 pref("browser.tabs.warnOnClose", true);
 pref("browser.tabs.warnOnCloseOtherTabs", true);
 pref("browser.tabs.warnOnOpen", true);
 pref("browser.tabs.maxOpenBeforeWarn", 15);
 pref("browser.tabs.loadInBackground", true);
 pref("browser.tabs.opentabfor.middleclick", true);
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -138,16 +138,19 @@
           );
 
           this._tabMinWidth = this._tabMinWidthPref;
 
           this._setPositionalAttributes();
 
           CustomizableUI.addListener(this);
           this._updateNewTabVisibility();
+
+          XPCOMUtils.defineLazyPreferenceGetter(this, "_closeTabByDblclick",
+            "browser.tabs.closeTabByDblclick", false);
         ]]>
       </constructor>
 
       <destructor>
         <![CDATA[
           Services.prefs.removeObserver("privacy.userContext", this);
 
           CustomizableUI.removeListener(this);
@@ -1684,16 +1687,17 @@
           if (!gMultiProcessBrowser || (val && this.hasAttribute("visuallyselected"))) {
             this._visuallySelected = val;
           }
 
           return val;
         ]]>
         </setter>
       </property>
+      <field name="_selectedOnFirstMouseDown">false</field>
 
       <property name="pinned" readonly="true">
         <getter>
           return this.getAttribute("pinned") == "true";
         </getter>
       </property>
       <property name="hidden" readonly="true">
         <getter>
@@ -1981,16 +1985,23 @@
       <handler event="dragstart"><![CDATA[
         if (this.mOverCloseButton) {
           event.stopPropagation();
         }
       ]]></handler>
 
       <handler event="mousedown" phase="capturing">
       <![CDATA[
+        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 if (this.mOverCloseButton ||
                    this._overPlayingIcon) {
           // Prevent tabbox.xml from selecting the tab.
           event.stopPropagation();
         }
       ]]>
@@ -2016,16 +2027,27 @@
         }
       ]]></handler>
 
       <handler event="dblclick" button="0" phase="capturing"><![CDATA[
         // for the one-close-button case
         if (event.originalTarget.getAttribute("anonid") == "close-button") {
           event.stopPropagation();
         }
+
+        let tabContainer = this.parentNode;
+        if (tabContainer._closeTabByDblclick &&
+            this._selectedOnFirstMouseDown &&
+            this.selected &&
+            !this._overPlayingIcon) {
+          gBrowser.removeTab(this, {
+            animate: true,
+            byMouse: event.mozInputSource == MouseEvent.MOZ_SOURCE_MOUSE,
+          });
+        }
       ]]></handler>
 
       <handler event="animationend">
       <![CDATA[
         if (event.originalTarget.getAttribute("anonid") == "tab-loading-burst") {
           this.removeAttribute("bursting");
         }
       ]]>