[Pkg-mozext-commits] [tabmixplus] 08/51: Move all visibleTabs helper functions to one place

David Prévot taffit at moszumanska.debian.org
Mon Feb 2 18:36:45 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 c6db1c4f49ec6db4bd75e2b1bd671052ccda7312
Author: onemen <tabmix.onemen at gmail.com>
Date:   Thu Jan 1 10:33:19 2015 +0200

    Move all visibleTabs helper functions to one place
---
 chrome/content/click/click.js           |  2 +-
 chrome/content/extensions/extensions.js |  2 +-
 chrome/content/minit/minit.js           | 22 +-------------
 chrome/content/minit/tablib.js          |  4 +--
 chrome/content/places/places.js         |  3 +-
 chrome/content/tab/scrollbox.xml        | 10 +++----
 chrome/content/tab/tab.js               | 52 +++++++++++++++++++++++++++++++--
 chrome/content/tab/tabbrowser_4.xml     | 34 +++------------------
 chrome/content/tabmix.js                |  9 +++---
 9 files changed, 68 insertions(+), 70 deletions(-)

diff --git a/chrome/content/click/click.js b/chrome/content/click/click.js
index da81ec8..389604c 100644
--- a/chrome/content/click/click.js
+++ b/chrome/content/click/click.js
@@ -511,7 +511,7 @@ var TabmixContext = {
     var lockedTab = aTab.hasAttribute("locked");
     var tabsCount = gBrowser.visibleTabs.length;
     var unpinnedTabs = tabsCount - TabmixTabbar._real_numPinnedTabs;
-    var cIndex = TMP_TabView.getIndexInVisibleTabsFromTab(aTab);
+    var cIndex = Tabmix.visibleTabs.indexOf(aTab);
     if (Tabmix.rtl)
       cIndex = tabsCount - 1 - cIndex;
 
diff --git a/chrome/content/extensions/extensions.js b/chrome/content/extensions/extensions.js
index b4695ae..e5f5af0 100644
--- a/chrome/content/extensions/extensions.js
+++ b/chrome/content/extensions/extensions.js
@@ -670,7 +670,7 @@ TMP_extensionsCompatibility.treeStyleTab = {
      *  other places windows
      */
     Tabmix.changeCode(TMP_Places, "TMP_Places.openGroup")._replace(
-      'var tabBar = gBrowser.tabContainer;',
+      'var tabs = gBrowser.visibleTabs;',
       'let TSTOpenGroupBookmarkBehavior = arguments.length > 3 && arguments[3] ||\n' +
       '        TreeStyleTabService.openGroupBookmarkBehavior();\n' +
       '    $&'
diff --git a/chrome/content/minit/minit.js b/chrome/content/minit/minit.js
index 67e724b..9b5a8a0 100644
--- a/chrome/content/minit/minit.js
+++ b/chrome/content/minit/minit.js
@@ -569,7 +569,7 @@ var TMP_tabDNDObserver = {
     var numTabs = tabs.length;
     if (!tabBar.hasAttribute("multibar")) {
       let i = event.target.localName == "tab" ?
-          TMP_TabView.getIndexInVisibleTabsFromTab(event.target) : 0;
+          Tabmix.visibleTabs.indexOf(event.target) : 0;
       for (; i < numTabs; i++) {
         let tab = tabs[i];
         if (Tabmix.compare(mX, Tabmix.itemEnd(tab, Tabmix.ltr), Tabmix.ltr))
@@ -919,22 +919,6 @@ var TMP_TabView = { /* jshint ignore: line */
     return firstTab;
   },
 
-  previousVisibleSibling: function (aTab) {
-    var tabs = gBrowser.visibleTabs;
-    var index = tabs.indexOf(aTab);
-    if (--index > -1)
-      return tabs[index];
-    return null;
-  },
-
-  nextVisibleSibling: function (aTab) {
-    var tabs = gBrowser.visibleTabs;
-    var index = tabs.indexOf(aTab);
-    if (index > -1 && ++index < tabs.length)
-      return tabs[index];
-    return null;
-  },
-
   // includung _removingTabs
   currentGroup: function () {
     return Array.filter(gBrowser.tabs, function(tab) !tab.hidden);
@@ -953,10 +937,6 @@ var TMP_TabView = { /* jshint ignore: line */
     if (aTab)
       return gBrowser.visibleTabs.indexOf(aTab);
     return -1;
-  },
-
-  getIndexInVisibleTabsFrom_tPos: function (aIndex) {
-    return this.getIndexInVisibleTabsFromTab(gBrowser.tabs.item(aIndex));
   }
 };
 
diff --git a/chrome/content/minit/tablib.js b/chrome/content/minit/tablib.js
index 678dffc..c6cb9ba 100644
--- a/chrome/content/minit/tablib.js
+++ b/chrome/content/minit/tablib.js
@@ -1281,8 +1281,8 @@ var tablib = {
 
       // if no tabmix_selectedID go to previous tab, from first tab go to the next tab
       if (tempIndex == -1)
-        this.selectedTab = aTab == tabs[0] ? TMP_TabView.nextVisibleSibling(aTab) :
-                                             TMP_TabView.previousVisibleSibling(aTab);
+        this.selectedTab = aTab == tabs[0] ? Tabmix.visibleTabs.next(aTab) :
+                                             Tabmix.visibleTabs.previous(aTab);
       else
         this.selectedTab = tabs[tempIndex];
 
diff --git a/chrome/content/places/places.js b/chrome/content/places/places.js
index 8a36630..7b8607e 100644
--- a/chrome/content/places/places.js
+++ b/chrome/content/places/places.js
@@ -246,7 +246,6 @@ var TMP_Places = {
   //
   //TODO - try to use sessionStore to add many tabs
   openGroup: function TMP_PC_openGroup(bmGroup, bmIds, aWhere) {
-    var tabBar = gBrowser.tabContainer;
     var tabs = gBrowser.visibleTabs;
 
     var doReplace = (/^tab/).test(aWhere) ? false :
@@ -277,7 +276,7 @@ var TMP_Places = {
 
     var tabToSelect = null;
     var prevTab = (!doReplace && openTabNext && gBrowser.mCurrentTab._tPos < tabs.length - 1) ?
-                  gBrowser.mCurrentTab : tabBar.visibleTabsLastChild;
+                   gBrowser.mCurrentTab : Tabmix.visibleTabs.last;
     var tabPos, index;
     var multiple = bmGroup.length > 1;
     for (i = 0; i < bmGroup.length ; i++) {
diff --git a/chrome/content/tab/scrollbox.xml b/chrome/content/tab/scrollbox.xml
index 04908de..943aaff 100644
--- a/chrome/content/tab/scrollbox.xml
+++ b/chrome/content/tab/scrollbox.xml
@@ -303,9 +303,9 @@
               !this.isMultiRow) {
             let tab;
             if (isScrollingLeft)
-              tab = TMP_TabView.nextVisibleSibling(element);
+              tab = Tabmix.visibleTabs.next(element);
             else
-              tab = TMP_TabView.previousVisibleSibling(element);
+              tab = Tabmix.visibleTabs.previous(element);
             if (tab) {
               offset = Math.min(this.minOffset, this.offsetRatio * tab.getBoundingClientRect().width);
               if (!isScrollingLeft)
@@ -566,8 +566,8 @@
           //XXX don't do anything on Linux when hovering last tab and
           // we show close button on tab on hover
           if (!TabmixSvc.isLinux || TabmixTabbar.visibleRows == 1 ||
-              (!tabs.visibleTabsLastChild.hasAttribute("showbutton") &&
-               !tabs.visibleTabsLastChild.hasAttribute("showbutton_removed")))
+              (!Tabmix.visibleTabs.last.hasAttribute("showbutton") &&
+               !Tabmix.visibleTabs.last.hasAttribute("showbutton_removed")))
             tabs.updateVerticalTabStrip();
         }
         else
@@ -617,7 +617,7 @@
           //XXX don't do anything on Linux when hovering last tab and
           // we show close button on tab on hover
           if (!TabmixSvc.isLinux || TabmixTabbar.visibleRows == 1 ||
-              !tabs.visibleTabsLastChild.hasAttribute("showbutton"))
+              !Tabmix.visibleTabs.last.hasAttribute("showbutton"))
             tabs.updateVerticalTabStrip();
         }
         else
diff --git a/chrome/content/tab/tab.js b/chrome/content/tab/tab.js
index 15ac2bb..ef13325 100644
--- a/chrome/content/tab/tab.js
+++ b/chrome/content/tab/tab.js
@@ -457,7 +457,7 @@ var TabmixTabbar = {
     var tabs = gBrowser.visibleTabs;
 
     var firstTab = tabs[0];
-    var lastTab = tabBar.visibleTabsLastChild;
+    var lastTab = Tabmix.visibleTabs.last;
     var topY = tabBar.topTabY;
     var lastTabRow = tabBar.lastTabRowNumber;
     if (lastTabRow == 1) { // one row
@@ -471,7 +471,7 @@ var TabmixTabbar = {
       if (lastTab.getAttribute("selected") == "true") {
         // check if previous to last tab in the 1st row
         // this happen when the selected tab is the first tab in the 2nd row
-        var prev = TMP_TabView.previousVisibleSibling(lastTab);
+        var prev = Tabmix.visibleTabs.previous(lastTab);
         if (prev && tabBar.getTabRowNumber(prev, topY) == 1)
           return lastTab.boxObject.height;
         else
@@ -480,7 +480,7 @@ var TabmixTabbar = {
       else if (firstTab.getAttribute("selected") == "true") {
         // check if 2nd visible tab is in the 2nd row
         // (not likely that user set tab width to more then half screen width)
-        var next = TMP_TabView.nextVisibleSibling(firstTab);
+        var next = Tabmix.visibleTabs.next(firstTab);
         if (next && tabBar.getTabRowNumber(next, topY) == 2)
           return lastTab.boxObject.height;
         else
@@ -555,6 +555,52 @@ var TabmixTabbar = {
 
 }; // TabmixTabbar end
 
+Tabmix.visibleTabs = {
+  get first() {
+    var tabs = gBrowser.tabs;
+    for (let i = 0; i < tabs.length; i++){
+      let tab = tabs[i];
+      if (!tab.hidden && !tab.closing)
+        return tab;
+    }
+    return gBrowser.selectedTab;
+  },
+
+  get last() {
+    // we only need the last visible tab,
+    // find it directly instead of using gBrowser.tabContainer.visibleTabs
+    var tabs = gBrowser.tabs;
+    for (let i = tabs.length - 1; i >= 0; i--){
+      let tab = tabs[i];
+      if (!tab.hidden && !tab.closing)
+        return tab;
+    }
+    return gBrowser.selectedTab;
+  },
+
+  previous: function (aTab) {
+    var tabs = gBrowser.visibleTabs;
+    var index = tabs.indexOf(aTab);
+    if (--index > -1)
+      return tabs[index];
+    return null;
+  },
+
+  next: function (aTab) {
+    var tabs = gBrowser.visibleTabs;
+    var index = tabs.indexOf(aTab);
+    if (index > -1 && ++index < tabs.length)
+      return tabs[index];
+    return null;
+  },
+
+  indexOf: function (aTab) {
+    if (aTab)
+      return gBrowser.visibleTabs.indexOf(aTab);
+    return -1;
+  }
+};
+
 // Function to catch changes to Tab Mix preferences and update existing windows and tabs
 //
 var gTMPprefObserver = {
diff --git a/chrome/content/tab/tabbrowser_4.xml b/chrome/content/tab/tabbrowser_4.xml
index 4b6fcfc..a5bc512 100644
--- a/chrome/content/tab/tabbrowser_4.xml
+++ b/chrome/content/tab/tabbrowser_4.xml
@@ -562,32 +562,6 @@
         ]]></getter>
       </property>
 
-      <property name="visibleTabsFirstChild" readonly="true">
-        <getter><![CDATA[
-          var tabs = this.childNodes;
-          for (let i = 0; i < tabs.length; i++){
-            let tab = tabs[i];
-            if (!tab.hidden && !tab.closing)
-              return tab;
-          }
-          return this.selectedItem;
-        ]]></getter>
-      </property>
-
-      <property name="visibleTabsLastChild" readonly="true">
-        <getter><![CDATA[
-          // we only need the last visible tab,
-          // find it directly instead of using this.visibleTabs
-          var tabs = this.childNodes;
-          for (let i = tabs.length - 1; i >= 0; i--){
-            let tab = tabs[i];
-            if (!tab.hidden && !tab.closing)
-              return tab;
-          }
-          return this.selectedItem;
-        ]]></getter>
-      </property>
-
       <!--
         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
@@ -607,7 +581,7 @@
           if (!Tabmix.tabsNewtabButton)
             Tabmix.getAfterTabsButtonsWidth();
 
-         var lastTab = this.visibleTabsLastChild;
+         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
@@ -628,7 +602,7 @@
          //              after previous to last tab.
          else {
            // ignor the case that this tab width is larger then the tabbar
-           let previousTab = TMP_TabView.previousVisibleSibling(lastTab);
+           let previousTab = Tabmix.visibleTabs.previous(lastTab);
            if (!previousTab) {
              this.disAllowNewtabbutton = false;
              return;
@@ -683,7 +657,7 @@
 
       <property name="lastTabRowNumber" readonly="true">
         <getter><![CDATA[
-          return this.getTabRowNumber(this.visibleTabsLastChild, this.topTabY);
+          return this.getTabRowNumber(Tabmix.visibleTabs.last, this.topTabY);
         ]]></getter>
       </property>
 
@@ -820,7 +794,7 @@
       </method>
       <property name="lastTabVisible" readonly="true">
         <getter><![CDATA[
-          return this.mTabstrip.isElementVisible(this.visibleTabsLastChild);
+          return this.mTabstrip.isElementVisible(Tabmix.visibleTabs.last);
         ]]></getter>
       </property>
 
diff --git a/chrome/content/tabmix.js b/chrome/content/tabmix.js
index 67bbec1..86871a8 100644
--- a/chrome/content/tabmix.js
+++ b/chrome/content/tabmix.js
@@ -128,8 +128,7 @@ Tabmix.getButtonsHeight = function() {
     let stripIsHidden = TabmixTabbar.hideMode !== 0 && !tabBar.visible;
     if (stripIsHidden)
       tabBar.visible = true;
-    this._buttonsHeight =
-            tabBar.visibleTabsFirstChild.getBoundingClientRect().height;
+    this._buttonsHeight = Tabmix.visibleTabs.first.getBoundingClientRect().height;
     if (stripIsHidden)
       tabBar.visible = false;
   }
@@ -839,8 +838,8 @@ var TMP_eventListener = {
     // we would like to get early respond when row height is going to change.
     var updateNow = !Services.prefs.getBoolPref("browser.tabs.animate");
     if (!updateNow && tabBar.hasAttribute("multibar")) {
-      let lastTab = tabBar.visibleTabsLastChild;
-      if (!TabmixTabbar.inSameRow(lastTab, TMP_TabView.previousVisibleSibling(lastTab))) {
+      let lastTab = Tabmix.visibleTabs.last;
+      if (!TabmixTabbar.inSameRow(lastTab, Tabmix.visibleTabs.previous(lastTab))) {
         updateNow = true;
         // if the removed tab is single in its row hide it
         if (lastTab == tab)
@@ -882,7 +881,7 @@ var TMP_eventListener = {
 
     // workaround when we remove last visible tab
     if (tabBar.firstChild.pinned && TabmixTabbar.isMultiRow && tabBar.overflow &&
-        aTab._tPos >= tabBar.visibleTabsLastChild._tPos)
+        aTab._tPos >= Tabmix.visibleTabs.last._tPos)
       tabBar.mTabstrip.ensureElementIsVisible(gBrowser.selectedTab, false);
 
     if (tabBar.disAllowNewtabbutton)

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