[Pkg-mozext-commits] [tabmixplus] 13/51: Move adjustNewtabButtonvisibility to Tabmix.tabsUtils

David Prévot taffit at moszumanska.debian.org
Mon Feb 2 18:36:47 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 babbf853ca913c81f1ad7fac6a548b4c5d9fdcf4
Author: onemen <tabmix.onemen at gmail.com>
Date:   Fri Jan 2 14:47:16 2015 +0200

    Move adjustNewtabButtonvisibility to Tabmix.tabsUtils
---
 chrome/content/tab/scrollbox.xml    |   4 +-
 chrome/content/tab/tab.js           | 105 ++++++++++++++++++++++++++++++++++--
 chrome/content/tab/tabbrowser_4.xml |  98 +++------------------------------
 chrome/content/tabmix.js            |   6 +--
 4 files changed, 112 insertions(+), 101 deletions(-)

diff --git a/chrome/content/tab/scrollbox.xml b/chrome/content/tab/scrollbox.xml
index 943aaff..dd09ec6 100644
--- a/chrome/content/tab/scrollbox.xml
+++ b/chrome/content/tab/scrollbox.xml
@@ -407,7 +407,7 @@
             return;
 
           var tabBar = document.getBindingParent(this);
-          tabBar.adjustNewtabButtonvisibility();
+          Tabmix.tabsUtils.adjustNewtabButtonvisibility();
           let tabs = this._getScrollableElements();
           if (!tabs.length)
             return;
@@ -417,7 +417,7 @@
             // show Newtabbutton for the first time
             // for the case last tab in row fill the all strip and the button
             // is on the next row
-            tabBar.disAllowNewtabbutton = false;
+            Tabmix.tabsUtils.disAllowNewtabbutton = false;
             this.orient = "vertical";
             Tabmix.setItem(tabBar, "multibar", true);
             Tabmix.setItem("TabsToolbar", "multibar", true);
diff --git a/chrome/content/tab/tab.js b/chrome/content/tab/tab.js
index 75ac73e..bec66f6 100644
--- a/chrome/content/tab/tab.js
+++ b/chrome/content/tab/tab.js
@@ -198,8 +198,8 @@ var TabmixTabbar = {
         this.setFirstTabInRow();
       }
     }
-    else if (!this.isMultiRow && typeof tabBar.adjustNewtabButtonvisibility == "function")
-      tabBar.adjustNewtabButtonvisibility();
+    else
+      Tabmix.tabsUtils.adjustNewtabButtonvisibility();
   },
 
   // in Firefox 4.0+ rowheight can change when TabsInTitlebar or TabsOnTop
@@ -695,6 +695,103 @@ Tabmix.tabsUtils = {
     let tabstrip = this.tabBar.mTabstrip;
     Tabmix.setItem(tabstrip, "orient", vertical ? "vertical" : "horizontal");
     tabstrip._isRTLScrollbox = !vertical && Tabmix.rtl;
+  },
+
+  /**
+   * check that we have enough room to show new tab button after the last tab
+   * in the current row. we don't want the button to be on the next row when the
+   * tab is on the current row
+   */
+  adjustNewtabButtonvisibility: function() {
+    if (!TabmixTabbar.isMultiRow && this.tabBar.mTabstrip.orient == "vertical")
+      return;
+
+    if (!this.checkNewtabButtonVisibility) {
+      TabmixTabbar.showNewTabButtonOnSide(this.tabBar.overflow, "right-side");
+      return;
+    }
+
+    // when Private-tab enabled/disabled we need to reset
+    // tabsNewtabButton and afterTabsButtonsWidth
+    if (!Tabmix.tabsNewtabButton)
+      Tabmix.getAfterTabsButtonsWidth();
+
+    var lastTab = Tabmix.visibleTabs.last;
+    // button is visible
+    //         A: last tab and the button are in the same row:
+    //            check if we have room for the button in this row
+    //         B: last tab and the button are NOT in the same row:
+    //            NG - hide the button
+    if (!this.disAllowNewtabbutton) {
+      let sameRow = TabmixTabbar.inSameRow(lastTab, Tabmix.tabsNewtabButton);
+      if (sameRow) {
+        let tabstripEnd = this.tabBar.mTabstrip.scrollBoxObject.screenX +
+            this.tabBar.mTabstrip.scrollBoxObject.width;
+        let buttonEnd = Tabmix.tabsNewtabButton.boxObject.screenX +
+            Tabmix.tabsNewtabButton.boxObject.width;
+        this.disAllowNewtabbutton = buttonEnd > tabstripEnd;
+      }
+      else
+        this.disAllowNewtabbutton = true;
+      return;
+    }
+    // button is NOT visible
+    //         A: 2 last tabs are in the same row:
+    //            check if we have room for the button in this row
+    //         B: 2 last tabs are NOT in the same row:
+    //            check if we have room for the last tab + button after
+    //            previous to last tab.
+    else {
+      // ignor the case that this tab width is larger then the tabbar
+      let previousTab = Tabmix.visibleTabs.previous(lastTab);
+      if (!previousTab) {
+        this.disAllowNewtabbutton = false;
+        return;
+      }
+
+      // buttons that are not on TabsToolbar or not visible are null
+      let newTabButtonWidth = function(aOnSide) {
+        let width = 0, privatTabButton = TabmixTabbar.newPrivateTabButton();
+        if (privatTabButton) {
+          width += aOnSide ? privatTabButton.boxObject.width :
+                   Tabmix.afterTabsButtonsWidth[1];
+        }
+        if (Tabmix.sideNewTabButton) {
+          width += aOnSide ? Tabmix.sideNewTabButton.boxObject.width :
+                   Tabmix.afterTabsButtonsWidth[0];
+        }
+        return width;
+      };
+      let tsbo = this.tabBar.mTabstrip.scrollBoxObject;
+      let tsboEnd = tsbo.screenX + tsbo.width + newTabButtonWidth(true);
+      if (TabmixTabbar.inSameRow(lastTab, previousTab)) {
+        let buttonEnd = lastTab.boxObject.screenX + lastTab.boxObject.width +
+            newTabButtonWidth();
+        this.disAllowNewtabbutton = buttonEnd > tsboEnd;
+        return;
+      }
+      else {
+        let lastTabEnd = previousTab.boxObject.screenX +
+            previousTab.boxObject.width + lastTab.boxObject.width;
+        // both last tab and new tab button are in the next row
+        if (lastTabEnd > tsboEnd)
+          this.disAllowNewtabbutton = false;
+        else
+          this.disAllowNewtabbutton = lastTabEnd + newTabButtonWidth() > tsboEnd;
+        return;
+      }
+    }
+  },
+
+  get disAllowNewtabbutton() {
+    let toolbar = document.getElementById("TabsToolbar");
+    return toolbar.getAttribute("tabmix-show-newtabbutton") == "temporary-right-side";
+  },
+
+  set disAllowNewtabbutton(val) {
+    let newVal = this.tabBar.overflow || val;
+    TabmixTabbar.showNewTabButtonOnSide(newVal, "temporary-right-side");
+    return newVal;
   }
 };
 
@@ -1645,7 +1742,7 @@ var gTMPprefObserver = {
   setShowNewTabButtonAttr: function(aShow, aPosition) {
     // check new tab button visibility when we are in multi-row and the
     // preference is to show new-tab-button after last tab
-    gBrowser.tabContainer._checkNewtabButtonVisibility =
+    Tabmix.tabsUtils.checkNewtabButtonVisibility =
                   TabmixTabbar.isMultiRow && ((aShow && aPosition == 2) ||
                   !!TabmixTabbar.newPrivateTabButton());
 
@@ -1671,7 +1768,7 @@ var gTMPprefObserver = {
     if (aShow) {
       if (gBrowser.tabContainer.overflow)
         attrValue = "right-side";
-      else if (gBrowser.tabContainer.disAllowNewtabbutton)
+      else if (Tabmix.tabsUtils.disAllowNewtabbutton)
         attrValue = "temporary-right-side";
     }
     Tabmix.setItem("TabsToolbar", "tabmix-show-newtabbutton", attrValue);
diff --git a/chrome/content/tab/tabbrowser_4.xml b/chrome/content/tab/tabbrowser_4.xml
index b119fe7..f657b50 100644
--- a/chrome/content/tab/tabbrowser_4.xml
+++ b/chrome/content/tab/tabbrowser_4.xml
@@ -365,7 +365,7 @@
           this._inUpdateVerticalTabStrip = true;
 
           // we must adjustNewtabButtonvisibility before get lastTabRowNumber
-          this.adjustNewtabButtonvisibility();
+          Tabmix.tabsUtils.adjustNewtabButtonvisibility();
           let visibleRows = TabmixTabbar.visibleRows;
           // this.lastTabRowNumber is null when we hide the tabbar
           let rows = aReset || this.childNodes.length == 1 ? 1 : (this.lastTabRowNumber || 1);
@@ -402,7 +402,8 @@
 
           if (!this.overflow) {
             // prevent new-tab-button on the right from flickering when new tabs animate is on.
-            if (this.disAllowNewtabbutton && Services.prefs.getBoolPref("browser.tabs.animate")) {
+            if (Tabmix.tabsUtils.disAllowNewtabbutton &&
+                Services.prefs.getBoolPref("browser.tabs.animate")) {
               // after 250ms new tab is fully opened
               if (!this.adjustNewtabButtonTimeout) {
                 let timeout = 250, callerName = Tabmix.callerName();
@@ -418,17 +419,17 @@
                 // didn't changed or when we get here from _enterVerticalMode
                 if (callerName != "_enterVerticalMode" &&
                      (multibar != currentMultibar || rows != visibleRows))
-                  this.disAllowNewtabbutton = false;
+                  Tabmix.tabsUtils.disAllowNewtabbutton = false;
                */
                 let self = this;
                 this.adjustNewtabButtonTimeout = setTimeout(function() {
-                  self.adjustNewtabButtonvisibility();
+                  Tabmix.tabsUtils.adjustNewtabButtonvisibility();
                   self.adjustNewtabButtonTimeout = null;
                 }, timeout);
               }
             }
             else
-              this.adjustNewtabButtonvisibility();
+              Tabmix.tabsUtils.adjustNewtabButtonvisibility();
           }
 
           this._inUpdateVerticalTabStrip = false;
@@ -464,93 +465,6 @@
       <property name="canScrollTabsRight" readonly="true"
                 onget="return !this.mTabstrip._scrollButtonDown.disabled;"/>
 
-      <!--
-        check that we have enough room to show new tab button after the last tab in the current row
-        we don't want the button to be on the next row when the tab is on the current row
-      -->
-      <method name="adjustNewtabButtonvisibility">
-        <body><![CDATA[
-          if (!TabmixTabbar.isMultiRow && this.mTabstrip.orient == "vertical")
-            return;
-
-          if (!this._checkNewtabButtonVisibility) {
-            TabmixTabbar.showNewTabButtonOnSide(this.overflow, "right-side");
-            return;
-          }
-
-          // when Private-tab enabled/disabled we need to reset
-          // tabsNewtabButton and afterTabsButtonsWidth
-          if (!Tabmix.tabsNewtabButton)
-            Tabmix.getAfterTabsButtonsWidth();
-
-         var lastTab = Tabmix.visibleTabs.last;
-         // button is visible
-         //         A: last tab and the button are in the same row - check if we have room for the button in this row
-         //         B: last tab and the button are NOT in the same row  - NG - hide the button
-         if (!this.disAllowNewtabbutton) {
-           let sameRow = TabmixTabbar.inSameRow(lastTab, Tabmix.tabsNewtabButton);
-           if (sameRow) {
-             let tabstripEnd = this.mTabstrip.scrollBoxObject.screenX + this.mTabstrip.scrollBoxObject.width;
-             let buttonEnd = Tabmix.tabsNewtabButton.boxObject.screenX + Tabmix.tabsNewtabButton.boxObject.width
-             this.disAllowNewtabbutton = buttonEnd > tabstripEnd;
-           }
-           else
-             this.disAllowNewtabbutton = true;
-           return;
-         }
-         // button is NOT visible
-         //         A: 2 last tabs are in the same row - check if we have room for the button in this row
-         //         B: 2 last tabs are NOT in the same row - check if we have room for the last tab + button
-         //              after previous to last tab.
-         else {
-           // ignor the case that this tab width is larger then the tabbar
-           let previousTab = Tabmix.visibleTabs.previous(lastTab);
-           if (!previousTab) {
-             this.disAllowNewtabbutton = false;
-             return;
-           }
-
-           // buttons that are not on TabsToolbar or not visible are null
-           let newTabButtonWidth = function(aOnSide) {
-             let width = 0, privatTabButton = TabmixTabbar.newPrivateTabButton();
-             if (privatTabButton)
-               width += aOnSide ? privatTabButton.boxObject.width : Tabmix.afterTabsButtonsWidth[1];
-             if (Tabmix.sideNewTabButton)
-               width += aOnSide ? Tabmix.sideNewTabButton.boxObject.width : Tabmix.afterTabsButtonsWidth[0];
-             return width;
-           }
-           let tsbo = this.mTabstrip.scrollBoxObject;
-           let tsboEnd = tsbo.screenX + tsbo.width + newTabButtonWidth(true);
-           if (TabmixTabbar.inSameRow(lastTab, previousTab)) {
-             let buttonEnd = lastTab.boxObject.screenX + lastTab.boxObject.width + newTabButtonWidth();
-             this.disAllowNewtabbutton = buttonEnd > tsboEnd;
-             return;
-           }
-           else {
-             let lastTabEnd = previousTab.boxObject.screenX + previousTab.boxObject.width
-                                         + lastTab.boxObject.width;
-             // both last tab and new tab button are in the next row
-             if (lastTabEnd > tsboEnd)
-               this.disAllowNewtabbutton = false;
-             else
-               this.disAllowNewtabbutton = lastTabEnd + newTabButtonWidth() > tsboEnd;
-             return;
-           }
-         }
-        ]]></body>
-      </method>
-
-      <property name="disAllowNewtabbutton">
-        <getter><![CDATA[
-          return document.getElementById("TabsToolbar").getAttribute("tabmix-show-newtabbutton") == "temporary-right-side";
-        ]]></getter>
-        <setter><![CDATA[
-          let newVal = this.overflow || val;
-          TabmixTabbar.showNewTabButtonOnSide(this.overflow || val, "temporary-right-side");
-          return newVal;
-        ]]></setter>
-      </property>
-
       <property name="topTabY" readonly="true">
         <getter><![CDATA[
           return this.tabstripInnerbox.boxObject.y + Tabmix.getStyle(this.tabstripInnerbox, "paddingTop");
diff --git a/chrome/content/tabmix.js b/chrome/content/tabmix.js
index c05178d..544c594 100644
--- a/chrome/content/tabmix.js
+++ b/chrome/content/tabmix.js
@@ -781,7 +781,7 @@ var TMP_eventListener = {
     }
     else if (!this._onOpenTimeout) {
       let self = this;
-      let timeout = gBrowser.tabContainer.disAllowNewtabbutton &&
+      let timeout = Tabmix.tabsUtils.disAllowNewtabbutton &&
           Services.prefs.getBoolPref("browser.tabs.animate") ? 0 : 200;
       this._onOpenTimeout = window.setTimeout( function TMP_onOpenTimeout(tab) {
         if (self._onOpenTimeout) {
@@ -884,8 +884,8 @@ var TMP_eventListener = {
         aTab._tPos >= Tabmix.visibleTabs.last._tPos)
       tabBar.mTabstrip.ensureElementIsVisible(gBrowser.selectedTab, false);
 
-    if (tabBar.disAllowNewtabbutton)
-      tabBar.adjustNewtabButtonvisibility();
+    if (Tabmix.tabsUtils.disAllowNewtabbutton)
+      Tabmix.tabsUtils.adjustNewtabButtonvisibility();
     if (TabmixTabbar.isMultiRow && tabBar.hasAttribute("multibar")) {
       _updateTabstrip();
       setTimeout(function(){_updateTabstrip();}, 0);

-- 
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