[Pkg-mozext-commits] [tabmixplus] 38/107: New preference in Options>Display>Tab>Styles - 'Apply background color for squared tabs', Allow users to set custom background colors when Tree Style Tab extension installed

David Prévot taffit at moszumanska.debian.org
Tue Dec 29 19:02:48 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository tabmixplus.

commit ed123aaa1e52666f26028719635b7c421c7e2aed
Author: onemen <tabmix.onemen at gmail.com>
Date:   Thu Oct 29 17:46:45 2015 +0200

    New preference in Options>Display>Tab>Styles - 'Apply background color for squared tabs', Allow users to set custom background colors when Tree Style Tab extension installed
---
 chrome/content/preferences/appearance.js           |  5 +-
 chrome/content/preferences/appearance.xul          |  7 +-
 .../preferences/subdialogs/pref-appearance.xml     |  5 +-
 chrome/content/tab/tab.js                          | 11 +--
 chrome/content/tabmix.js                           |  9 +-
 chrome/locale/en-US/pref-appearance.dtd            |  1 -
 chrome/skin/app_version/all/mac/progress.css       |  2 +-
 chrome/skin/app_version/all/win/progress.css       |  2 +-
 modules/DynamicRules.jsm                           | 99 ++++++++++++++++++----
 modules/Services.jsm                               | 12 +++
 10 files changed, 117 insertions(+), 36 deletions(-)

diff --git a/chrome/content/preferences/appearance.js b/chrome/content/preferences/appearance.js
index bb7f2dd..1999bd1 100644
--- a/chrome/content/preferences/appearance.js
+++ b/chrome/content/preferences/appearance.js
@@ -15,9 +15,8 @@ var gAppearancePane = { // jshint ignore:line
       Tabmix.setItem("smoothScroll", "disabled", true);
     }
 
-    if (browserWindow.Tabmix.extensions.treeStyleTab) {
-      Tabmix.setItem("treeStyleTab.bg.msg", "hidden", null);
-      window.treeStyleTab = true;
+    if (!TabmixSvc.australis) {
+      Tabmix.setItem("squaredTabs", "hidden", true);
     }
 
     Tabmix.setItem("tabXLeft", "disabled", !browserWindow.Tabmix.defaultCloseButtons || null);
diff --git a/chrome/content/preferences/appearance.xul b/chrome/content/preferences/appearance.xul
index 75d11df..9a5b415 100644
--- a/chrome/content/preferences/appearance.xul
+++ b/chrome/content/preferences/appearance.xul
@@ -47,6 +47,7 @@
       <preference id="pref_unloadedTab"       name="extensions.tabmix.unloadedTab"              type="bool"/>
       <preference id="pref_otherTab"          name="extensions.tabmix.otherTab"                 type="bool"/>
       <preference id="pref_disableBackground" name="extensions.tabmix.disableBackground"        type="bool"/>
+      <preference id="pref_squaredTabs"       name="extensions.tabmix.squaredTabsStyle"         type="bool"/>
       <preference id="pref_lockedIcon"        name="extensions.tabmix.extraIcons.locked"        type="bool"/>
       <preference id="pref_protectedIcon"     name="extensions.tabmix.extraIcons.protected"     type="bool"/>
       <preference id="pref_autoreloadIcon"    name="extensions.tabmix.extraIcons.autoreload"    type="bool"/>
@@ -192,11 +193,10 @@
             </hbox>
             <checkbox_tmp id="unreadTabreload" class="indent" label="&unreadAfterReload.label;"
                       preference="pref_unreadTabreload" observes="obs_unreadTab"/>
-            <label id="treeStyleTab.bg.msg" class="header" hidden="true"
-                   value="&backgroundDisabled.label;"
-                   style="text-decoration: underline; color: #CC0000; margin-top: 10px;"/>
             <checkbox_tmp id="disableBackground" label="&disableBackground.label;"
                           preference="pref_disableBackground"/>
+            <checkbox_tmp id="squaredTabs" label="&squaredTabs.label;"
+                          preference="pref_squaredTabs" observes="obs_disableBackground"/>
           </groupbox>
           <groupbox flex="1">
             <caption label="&show.ontab.label;"/>
@@ -299,6 +299,7 @@
       <broadcaster id="obs_hideAllTabsButton"/>
       <broadcaster id="obs_smoothScroll" inverseDependency="true"/>
       <broadcaster id="obs_unreadTab"/>
+      <broadcaster id="obs_disableBackground" inverseDependency="true"/>
       <broadcaster id="obs_showTabX"/>
     </broadcasterset>
 
diff --git a/chrome/content/preferences/subdialogs/pref-appearance.xml b/chrome/content/preferences/subdialogs/pref-appearance.xml
index a6fefc6..d62c42e 100644
--- a/chrome/content/preferences/subdialogs/pref-appearance.xml
+++ b/chrome/content/preferences/subdialogs/pref-appearance.xml
@@ -68,7 +68,8 @@
           useThis.checked = checked;
           this.disabled = !checked;
 
-          this.treeStyleTab = window.opener.treeStyleTab && this.id != "progressMeter";
+          this.disableBgColor = Tabmix.prefs.getBoolPref("disableBackground") &&
+                                this.id != "progressMeter";
 
           useThis.nextSibling.value = document.getElementById("_" + this.id).label;
           // colorpicker need some time untile its ready
@@ -193,7 +194,7 @@
       <method name="updateDisableState">
         <parameter name="aID"/>
         <body><![CDATA[
-          var disableBg = this.treeStyleTab && aID == "bg";
+          var disableBg = this.disableBgColor && aID == "bg";
           var disabled = this.disabled || disableBg ||
                            !this._getElementById(aID).checked;
           if (disableBg)
diff --git a/chrome/content/tab/tab.js b/chrome/content/tab/tab.js
index 0c21804..13d8f46 100644
--- a/chrome/content/tab/tab.js
+++ b/chrome/content/tab/tab.js
@@ -1710,13 +1710,13 @@ var gTMPprefObserver = {
                   '#tabbrowser-tabs:not([overflow="true"]) > .tabbrowser-arrowscrollbox[flowing="multibar"]' +
                   ' > .tabs-newtab-button[command="cmd_newNavigatorTab"] {height: #px;}'
                   .replace("#", Tabmix._buttonsHeight);
-    this.insertRule(newRule);
+    this.insertRule(newRule, "new-tab-height");
 
     if (TabmixSvc.australis && !Tabmix.isVersion(310) && !TabmixSvc.isLinux && !TabmixSvc.isMac) {
       newRule = '#main-window[privatebrowsingmode=temporary] #private-browsing-indicator {' +
                 '  height: #px;'.replace("#", Tabmix._buttonsHeight) +
                 '}';
-      this.insertRule(newRule);
+      this.insertRule(newRule, "pb-indicator-height");
     }
 
     if (TabmixSvc.isMac && !TabmixSvc.australis)
@@ -1724,12 +1724,12 @@ var gTMPprefObserver = {
 
     newRule = '#tabmixScrollBox[flowing="multibar"] > toolbarbutton {' +
       '  height: #px;}'.replace("#", Tabmix._buttonsHeight);
-    this.insertRule(newRule);
+    this.insertRule(newRule, "scrollbutton-height");
 
     let _buttonsHeight = Tabmix.isVersion(310) ? Tabmix._buttonsHeight - 1 : Tabmix._buttonsHeight;
     newRule = '#TabsToolbar[multibar] > .toolbarbutton-1 {' +
       '  height: #px;}'.replace("#", _buttonsHeight);
-    this.insertRule(newRule);
+    this.insertRule(newRule, "toolbarbutton-height");
     delete Tabmix._buttonsHeight;
 
     // we don't show icons on menu on Mac OS X
@@ -1829,8 +1829,9 @@ var gTMPprefObserver = {
         attribValue.push("text");
       if (prefValues.bg && !Tabmix.prefs.getBoolPref("disableBackground")) {
         attribValue.push("bg");
-        if (TabmixSvc.australis && !Tabmix.extensions.treeStyleTab)
+        if (TabmixSvc.isAustralisBgStyle(gBrowser.tabContainer.orient)) {
           attribValue.push("aus");
+        }
       }
       attribValue = attribValue.join(" ");
     }
diff --git a/chrome/content/tabmix.js b/chrome/content/tabmix.js
index 2c0bc7c..b419aa6 100644
--- a/chrome/content/tabmix.js
+++ b/chrome/content/tabmix.js
@@ -134,6 +134,7 @@ Tabmix.getButtonsHeight = function() {
   }
   else
     this._buttonsHeight = 24;
+  return this._buttonsHeight;
 };
 
 Tabmix.getAfterTabsButtonsWidth = function TMP_getAfterTabsButtonsWidth() {
@@ -451,8 +452,10 @@ var TMP_eventListener = {
       Tabmix.setItem(tabsToolbar, "tabmix_aero", true);
     }
 
-    if (TabmixSvc.australis)
-      tabBar.setAttribute("tabmix_australis", Tabmix.extensions.treeStyleTab ? "tst" : "true");
+    if (TabmixSvc.australis) {
+      let australis = TabmixSvc.isAustralisBgStyle(tabBar.orient);
+      tabBar.setAttribute("tabmix_australis", australis ? "true" : "classic");
+    }
 
     var skin = Services.prefs.getCharPref("general.skins.selectedSkin");
     if (skin == "classic/1.0") {
@@ -485,7 +488,7 @@ var TMP_eventListener = {
       }
       switch (skin) {
         case "Australis":
-          tabBar.setAttribute("tabmix_australis", Tabmix.extensions.treeStyleTab ? "tst" : "true");
+          tabBar.setAttribute("tabmix_australis", "true");
           break;
         case "cfxe": // Chromifox Extreme
         case "cfxec":
diff --git a/chrome/locale/en-US/pref-appearance.dtd b/chrome/locale/en-US/pref-appearance.dtd
index b32dcda..689bd67 100644
--- a/chrome/locale/en-US/pref-appearance.dtd
+++ b/chrome/locale/en-US/pref-appearance.dtd
@@ -8,7 +8,6 @@
 <!ENTITY unreadAfterReload.label "set tab as unread after reload">
 <!ENTITY disableBackground.label "Disable custom background colors">
 <!ENTITY squaredTabs.label "Apply background color for squared tabs">
-<!ENTITY backgroundDisabled.label "Tabs background colors are disabled when TreeStyleTabs is installed">
 <!ENTITY otherTabs.label "Other Tabs">
 <!ENTITY italic.label "Italic">
 <!ENTITY bold.label "Bold">
diff --git a/chrome/skin/app_version/all/mac/progress.css b/chrome/skin/app_version/all/mac/progress.css
index 95e36d4..6e29ac8 100644
--- a/chrome/skin/app_version/all/mac/progress.css
+++ b/chrome/skin/app_version/all/mac/progress.css
@@ -20,7 +20,7 @@
   margin: 1px 2px;
 }
 
-.tabbrowser-tabs[tabmix_australis]:not([treestyletab-mode="vertical"])
+.tabbrowser-tabs[tabmix_australis="true"]:not([treestyletab-mode="vertical"])
     > .tabbrowser-tab > .tab-stack > .tab-progress-container > .tab-progress {
   margin: 4px 7px 0px 7px;
 }
diff --git a/chrome/skin/app_version/all/win/progress.css b/chrome/skin/app_version/all/win/progress.css
index 3537ae2..e74b5be 100644
--- a/chrome/skin/app_version/all/win/progress.css
+++ b/chrome/skin/app_version/all/win/progress.css
@@ -6,7 +6,7 @@
 **/
 
 /* :::: progress bar on tabs :::: */
-.tabbrowser-tabs[tabmix_australis]:not([treestyletab-mode="vertical"])
+.tabbrowser-tabs[tabmix_australis="true"]:not([treestyletab-mode="vertical"])
     > .tabbrowser-tab > .tab-stack > .tab-progress-container > .tab-progress {
   margin: 4px 7px 0px 7px;
 }
diff --git a/modules/DynamicRules.jsm b/modules/DynamicRules.jsm
index d57c65e..6c38d1e 100644
--- a/modules/DynamicRules.jsm
+++ b/modules/DynamicRules.jsm
@@ -26,6 +26,7 @@ XPCOMUtils.defineLazyGetter(this, "SSS", function() {
 
 const NAMESPACE = '@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");\n';
 const STYLENAMES = ["currentTab", "unloadedTab", "unreadTab", "otherTab", "progressMeter"];
+const EXTRAPREFS = ["squaredTabsStyle"];
 
 this.DynamicRules = {
 
@@ -40,27 +41,34 @@ this.DynamicRules = {
 
   _initialized: false,
 
+  get isAustralis() {
+    return TabmixSvc.isAustralisBgStyle(this.orient);
+  },
+
   init: function(aWindow) {
     if (this._initialized)
       return;
     this._initialized = true;
 
-    this.treeStyleTab = aWindow.Tabmix.extensions.treeStyleTab;
+    this.orient = aWindow.document.getElementById("tabbrowser-tabs").orient;
+    this.styleType = this.isAustralis ? "australis" : "classic";
     this.windows10 = aWindow.navigator.oscpu.startsWith("Windows NT 10.0");
 
     Prefs.addObserver("", this, false);
-    STYLENAMES.forEach(function(pref) {
+    STYLENAMES.concat(EXTRAPREFS).forEach(function(pref) {
       Services.prefs.addObserver("extensions.tabmix." + pref, this, false);
     }, this);
+    Services.obs.addObserver(this, "browser-window-before-show", false);
     Services.obs.addObserver(this, "quit-application", false);
 
     this.createTemplates();
-    for (let rule of Object.keys(this.cssTemplates))
-      this.userChangedStyle(rule);
   },
 
   observe: function(subject, topic, data) {
     switch (topic) {
+      case "browser-window-before-show":
+        this.registerMutationObserver(subject);
+        break;
       case "nsPref:changed":
         this.onPrefChange(data);
         break;
@@ -70,6 +78,24 @@ this.DynamicRules = {
     }
   },
 
+  registerMutationObserver: function(window) {
+    function tabsMotate(aMutations) {
+      for (let mutation of aMutations) {
+        if (mutation.attributeName == "orient") {
+          this.orient = mutation.target.orient;
+          this.updateStyleType();
+          return;
+        }
+      }
+    }
+    let Observer = new window.MutationObserver(tabsMotate.bind(this));
+    Observer.observe(window.gBrowser.tabContainer, {attributes: true});
+    window.addEventListener("unload", function unload() {
+      window.removeEventListener("unload", unload);
+      Observer.disconnect();
+    });
+  },
+
   onPrefChange: function(data) {
     let prefName = data.split(".").pop();
     if (STYLENAMES.indexOf(prefName) > -1) {
@@ -77,13 +103,16 @@ this.DynamicRules = {
         this.userChangedStyle(prefName, true);
       else
         this.registerSheet(prefName);
+    } else if (prefName == "squaredTabsStyle") {
+      this.updateStyleType();
     }
   },
 
   onQuitApplication: function() {
+    Services.obs.removeObserver(this, "browser-window-before-show", false);
     Services.obs.removeObserver(this, "quit-application");
     Prefs.removeObserver("", this);
-    STYLENAMES.forEach(function(pref) {
+    STYLENAMES.concat(EXTRAPREFS).forEach(function(pref) {
       Services.prefs.removeObserver("extensions.tabmix." + pref, this);
       this.unregisterSheet(pref);
     }, this);
@@ -91,16 +120,12 @@ this.DynamicRules = {
 
   updateOpenedWindows: function(ruleName) {
     // update all opened windows
-    let windowsEnum = Services.wm.getEnumerator("navigator:browser");
-    while (windowsEnum.hasMoreElements()) {
-      let window = windowsEnum.getNext();
-      if (!window.closed) {
-        if (ruleName != "progressMeter")
-          window.gTMPprefObserver.updateTabsStyle(ruleName);
-        else
-          window.gTMPprefObserver.setProgressMeter();
-      }
-    }
+    TabmixSvc.forEachBrowserWindow(window => {
+      if (ruleName != "progressMeter")
+        window.gTMPprefObserver.updateTabsStyle(ruleName);
+      else
+        window.gTMPprefObserver.setProgressMeter();
+    });
   },
 
   createTemplates: function() {
@@ -146,7 +171,7 @@ this.DynamicRules = {
       },
     };
 
-    if (TabmixSvc.australis && !this.treeStyleTab) {
+    if (this.isAustralis) {
       bgImage.bg = 'url("chrome://browser/skin/customizableui/background-noise-toolbar.png"),\n' +
             space20 + bottomBorder +
             space20 + bgImage.body;
@@ -188,6 +213,9 @@ this.DynamicRules = {
     };
 
     this.cssTemplates = styleRules;
+    for (let rule of Object.keys(this.cssTemplates)) {
+      this.userChangedStyle(rule);
+    }
   },
 
   userChangedStyle: function(ruleName, notifyWindows) {
@@ -230,7 +258,7 @@ this.DynamicRules = {
       if (rule == "text") {
         if (prefObj.text)
           style[rule] = cssText.replace(/#textColor/g, prefObj.textColor);
-      } else if (prefObj.bg && (!this.treeStyleTab || name == "progressMeter")) {
+      } else if (prefObj.bg) {
         style[rule] = cssText.replace(/#bottomColor/g, prefObj.bgColor)
                              .replace(/#topColor/g, prefObj.bgTopColor);
       }
@@ -239,6 +267,43 @@ this.DynamicRules = {
     this.registerSheet(name);
   },
 
+  // update background type when squaredTabsStyle pref or tabbar
+  // orient changed
+  updateStyleType: function() {
+    let australis = this.isAustralis;
+    if (australis == (this.styleType == "australis")) {
+      return;
+    }
+    this.styleType = australis ? "australis" : "classic";
+
+    TabmixSvc.tabStylePrefs = {};
+    this.createTemplates();
+
+    function updateButtonHeight(Tabmix, rules) {
+      let newHeight = Tabmix.getButtonsHeight();
+      ["new-tab", "pb-indicator", "scrollbutton", "toolbarbutton"].forEach(name => {
+        let rule = rules[name + "-height"];
+        if (typeof rule == "object") {
+          rule.style.setProperty("height", newHeight + "px", "important");
+        }
+      });
+    }
+
+    TabmixSvc.forEachBrowserWindow(window => {
+      let {Tabmix, TabmixTabbar, gBrowser, gTMPprefObserver} = window;
+      gTMPprefObserver.updateStyleAttributes();
+      updateButtonHeight(Tabmix, gTMPprefObserver.dynamicRules);
+
+      // update multi-row heights
+      gBrowser.tabContainer.mTabstrip._singleRowHeight = null;
+      TabmixTabbar._heights = [];
+      TabmixTabbar.visibleRows = 1;
+      Tabmix.tabsUtils.updateVerticalTabStrip();
+      TabmixTabbar.setFirstTabInRow();
+      TabmixTabbar.updateBeforeAndAfter();
+    });
+  },
+
   /** create/update styleSheet for type of tab or progressMeter
    *  we get here in these cases
    *      - when we initialize this service
diff --git a/modules/Services.jsm b/modules/Services.jsm
index 1b60aae..7795c01 100644
--- a/modules/Services.jsm
+++ b/modules/Services.jsm
@@ -184,6 +184,10 @@ this.TabmixSvc = {
       // add missing preference to the default branch
       let prefs = Services.prefs.getDefaultBranch("");
 
+      if (TabmixSvc.australis) {
+        prefs.setBoolPref("extensions.tabmix.squaredTabsStyle", false);
+      }
+
       if (isVersion(320))
         prefs.setBoolPref("extensions.tabmix.tabcontext.openNonRemoteWindow", true);
 
@@ -245,6 +249,14 @@ this.TabmixSvc = {
     settingPreference: false,
   },
 
+  isAustralisBgStyle: function(orient) {
+    if (typeof orient != "string") {
+      throw Components.Exception("orient is not valid", Components.results.NS_ERROR_INVALID_ARG);
+    }
+    return TabmixSvc.australis && orient == "horizontal" &&
+      !this.prefBranch.getBoolPref("squaredTabsStyle");
+  },
+
   blockedClickingOptions: []
 };
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/tabmixplus.git



More information about the Pkg-mozext-commits mailing list