From 2e393aa333c0dcf10a568a487fd586093118a569 Mon Sep 17 00:00:00 2001 From: piro Date: Thu, 16 Sep 2010 10:46:15 +0000 Subject: [PATCH] =?UTF-8?q?TabShow/TabHide=E3=82=A4=E3=83=99=E3=83=B3?= =?UTF-8?q?=E3=83=88=E3=81=AB=E5=9F=BA=E3=81=A5=E3=81=84=E3=81=A6=E3=83=84?= =?UTF-8?q?=E3=83=AA=E3=83=BC=E3=81=AE=E6=95=B4=E5=90=88=E6=80=A7=E3=82=92?= =?UTF-8?q?=E4=BF=9D=E3=81=A4=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@7241 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/treestyletab.js | 42 +----------- content/treestyletab/treestyletabbrowser.js | 73 ++++++++++++++++----- 2 files changed, 56 insertions(+), 59 deletions(-) diff --git a/content/treestyletab/treestyletab.js b/content/treestyletab/treestyletab.js index 33dfcd45..b6438c7f 100644 --- a/content/treestyletab/treestyletab.js +++ b/content/treestyletab/treestyletab.js @@ -195,17 +195,6 @@ var TreeStyleTabService = { ); } - if ('TabView' in window && TabView._initFrame) { - eval('TabView._initFrame = '+ - TabView._initFrame.toSource().replace( - /(iframe.addEventListener\()/, - - ) - ); - } - this.overrideExtensionsPreInit(); // hacks.js this.registerTabFocusAllowance(this.defaultTabFocusAllowance); @@ -1323,31 +1312,6 @@ catch(e) { items[aIndex].style.paddingLeft = aTab.getAttribute(this.kNEST)+'em'; }, this); }, - - initTabView : function TSTService_initTabView() - { - var iframe = document.getElementById('tab-view'); - iframe.removeEventListener('load', this, true); - - var frame = iframe.contentWindow; - if ( - !frame.Item || - !frame.Item.prototype || - !frame.Item.prototype.setParent || - frame.Item.prototype.__treestyletab__setParent - ) - return; - - frame.Item.prototype.__treestyletab__setParent = frame.Item.prototype.setParent; - frame.Item.prototype.setParent = function(aParent) { - if (this.tab && this.parent && this.parent != aParent) - frame.parent.TreeStyleTabService - .getTabBrowserFromChild(this.tab) - .treeStyleTab - .onTabGroupModified(this.tab); - return this.__treestyletab__setParent.apply(this, arguments); - }; - }, destroy : function TSTService_destroy() { @@ -1402,11 +1366,7 @@ catch(e) { return this.preInit(); case 'load': - if (aEvent.currentTarget == window || aEvent.currentTarget == document) - this.init(); - else - this.initTabView(); - return + return this.init(); case 'unload': return this.destroy(); diff --git a/content/treestyletab/treestyletabbrowser.js b/content/treestyletab/treestyletabbrowser.js index 764799cd..bab1e606 100644 --- a/content/treestyletab/treestyletabbrowser.js +++ b/content/treestyletab/treestyletabbrowser.js @@ -239,6 +239,8 @@ TreeStyleTabBrowser.prototype = { this.tabsHash = {}; this.tabStripPlaceHolder = null; + this.tabVisibilityChangedTabs = []; + this.internallyTabMovingCount = 0; this.subTreeMovingCount = 0; this.subTreeChildrenMovingCount = 0; @@ -277,6 +279,8 @@ TreeStyleTabBrowser.prototype = { b.mTabContainer.addEventListener('TabOpen', this, true); b.mTabContainer.addEventListener('TabClose', this, true); b.mTabContainer.addEventListener('TabMove', this, true); + b.mTabContainer.addEventListener('TabShow', this, true); + b.mTabContainer.addEventListener('TabHide', this, true); b.mTabContainer.addEventListener('SSTabRestoring', this, true); b.mTabContainer.addEventListener('SSTabRestored', this, true); b.mTabContainer.addEventListener('TabPinned', this, true); @@ -1577,6 +1581,8 @@ TreeStyleTabBrowser.prototype = { b.mTabContainer.removeEventListener('TabOpen', this, true); b.mTabContainer.removeEventListener('TabClose', this, true); b.mTabContainer.removeEventListener('TabMove', this, true); + b.mTabContainer.removeEventListener('TabShow', this, true); + b.mTabContainer.removeEventListener('TabHide', this, true); b.mTabContainer.removeEventListener('SSTabRestoring', this, true); b.mTabContainer.removeEventListener('SSTabRestored', this, true); b.mTabContainer.removeEventListener('TabPinned', this, true); @@ -1927,6 +1933,10 @@ TreeStyleTabBrowser.prototype = { case 'TabMove': return this.onTabMove(aEvent); + case 'TabShow': + case 'TabHide': + return this.onTabVisibilityChanged(aEvent); + case 'SSTabRestoring': return this.onTabRestoring(aEvent); @@ -2494,10 +2504,13 @@ TreeStyleTabBrowser.prototype = { } if (newParent != parent) { - if (newParent) - this.attachTabTo(aTab, newParent, { insertBefore : nextTab }); - else + if (newParent) { + if (newParent.hidden == aTab.hidden) + this.attachTabTo(aTab, newParent, { insertBefore : nextTab }); + } + else { this.partTab(aTab); + } } }, @@ -2516,6 +2529,45 @@ TreeStyleTabBrowser.prototype = { ); }, + onTabVisibilityChanged : function TSTBrowser_onTabVisibilityChanged(aEvent) + { + if (this.tabVisibilityChangedTimer) { + window.clearTimeout(this.tabVisibilityChangedTimer); + this.tabVisibilityChangedTimer = null; + } + this.tabVisibilityChangedTabs.push(aEvent.originalTarget); + this.tabVisibilityChangedTimer = window.setTimeout(function(aSelf) { + aSelf.tabVisibilityChangedTimer = null; + var tabs = aSelf.tabVisibilityChangedTabs; + aSelf.tabVisibilityChangedTabs = []; + aSelf.updateTreeByTabVisibility(tabs); + }, 0, this); + }, + tabVisibilityChangedTimer : null, + tabVisibilityChangedTabs : [], + updateTreeByTabVisibility : function TSTBrowser_updateTreeByTabVisibility(aChangedTabs) + { + aChangedTabs = aChangedTabs || []; + + var tabs = this.getAllTabsArray(this.mTabBrowser); + tabs.reverse().forEach(function(aTab) { + var parent = this.getParentTab(aTab); + if (parent && aTab.hidden != parent.hidden) { + this.collapseExpandTab(aTab, false, true); + let target = parent.hidden && aChangedTabs.indexOf(parent) > -1 ? + parent : aTab ; + this.partAllChildren(target, { + behavior : parent ? + this.getTreePref('closeParentBehavior') : + this.getTreePref('closeRootBehavior') + }); + this.partTab(target); + } + if (!aTab.hidden && aChangedTabs.indexOf(aTab) > -1) + this.attachTabFromPosition(aTab, tabs.length-1); + }, this); + }, + onTabRestoring : function TSTBrowser_onTabRestoring(aEvent) { this.restoreStructure(aEvent.originalTarget); @@ -3226,21 +3278,6 @@ TreeStyleTabBrowser.prototype = { { this.removeTabbrowserAttribute(this.kPRINT_PREVIEW); }, - - onTabGroupModified : function TSTBrowser_onTabGroupModified(aTab) - { - window.setTimeout(function(aSelf) { - if (aTab.hasAttribute(aSelf.kREMOVED)) - return; - aSelf.collapseExpandTab(aTab, false, true); - aSelf.partAllChildren(aTab, { - behavior : aSelf.getParentTab(aTab) ? - aSelf.getTreePref('closeParentBehavior') : - aSelf.getTreePref('closeRootBehavior') - }); - aSelf.partTab(aTab); - }, 0, this); - }, /* drag and drop */