From fabd5f546dff729548a72618893cc9b82151ee9d Mon Sep 17 00:00:00 2001 From: SHIMODA Hiroshi Date: Wed, 1 Dec 2010 17:40:18 +0900 Subject: [PATCH] split methods and add a new API getAncestorTabs() --- content/treestyletab/treestyletabbrowser.js | 40 ++++++++++----------- modules/utils.js | 11 ++++++ 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/content/treestyletab/treestyletabbrowser.js b/content/treestyletab/treestyletabbrowser.js index b0470b22..a3521e45 100644 --- a/content/treestyletab/treestyletabbrowser.js +++ b/content/treestyletab/treestyletabbrowser.js @@ -4171,15 +4171,8 @@ TreeStyleTabBrowser.prototype = { { if (!aTabs || !aTabs.length || !this._treeViewEnabled) return; - if (aLevel === void(0)) { - var parentTab = this.getParentTab(aTabs[0]); - var aLevel = 0; - while (parentTab) - { - aLevel++; - parentTab = this.getParentTab(parentTab); - } - } + if (aLevel === void(0)) + aLevel = this.getAncestorTabs(aTabs[0]).length; var b = this.mTabBrowser; var margin = this.indent < 0 ? this.baseIndent : this.indent ; @@ -4195,18 +4188,7 @@ TreeStyleTabBrowser.prototype = { if (!aTab.parentNode) return; // ignore removed tabs this.updateTabIndent(aTab, indent, aJustNow); aTab.setAttribute(this.kNEST, aLevel); - if ( - !aLevel || - this.maxTreeLevel < 0 || - this.maxTreeLevel > aLevel - ) { - aTab.setAttribute(this.kALLOW_COLLAPSE, true); - this.collapseExpandSubtree(aTab, this.isSubtreeCollapsed(aTab)); - } - else { - this.collapseExpandSubtree(aTab, false); - aTab.removeAttribute(this.kALLOW_COLLAPSE); - } + this.updateCanCollapseSubtree(aTab, aLevel); this.updateTabsIndent(this.getChildTabs(aTab), aLevel+1, aJustNow); }, this); }, @@ -4393,6 +4375,22 @@ TreeStyleTabBrowser.prototype = { }, _horizontalTabMaxIndentBase : 0, + updateCanCollapseSubtree : function TSTBrowser_updateCanCollapseSubtree(aTab, aLevel) + { + if ( + !aLevel || + this.maxTreeLevel < 0 || + this.maxTreeLevel > aLevel + ) { + aTab.setAttribute(this.kALLOW_COLLAPSE, true); + this.collapseExpandSubtree(aTab, this.isSubtreeCollapsed(aTab)); + } + else { + this.collapseExpandSubtree(aTab, false); + aTab.removeAttribute(this.kALLOW_COLLAPSE); + } + }, + updateTabsCount : function TSTBrowser_updateTabsCount(aTab, aDontUpdateAncestor) { var count = document.getAnonymousElementByAttribute(aTab, 'class', this.kCOUNTER); diff --git a/modules/utils.js b/modules/utils.js index 1baf9921..3ff8ba8d 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -1428,6 +1428,17 @@ var TreeStyleTabUtils = { ).singleNodeValue; }, + getAncestorTabs : function TSTUtils_getAncestorTabs(aTab) /* PUBLIC API */ + { + var tabs = []; + var parentTab = aTab; + while (parentTab = this.getParentTab(parentTab)) + { + tabs.push(parentTab); + } + return tabs; + }, + getRootTab : function TSTUtils_getRootTab(aTab) /* PUBLIC API */ { if (!aTab) return null;