TabShow/TabHideイベントに基づいてツリーの整合性を保つように

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@7241 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2010-09-16 10:46:15 +00:00
parent 2ef43fcb8e
commit 2e393aa333
2 changed files with 56 additions and 59 deletions

View File

@ -195,17 +195,6 @@ var TreeStyleTabService = {
); );
} }
if ('TabView' in window && TabView._initFrame) {
eval('TabView._initFrame = '+
TabView._initFrame.toSource().replace(
/(iframe.addEventListener\()/,
<![CDATA[
iframe.addEventListener('load', TreeStyleTabService, true);
$1]]>
)
);
}
this.overrideExtensionsPreInit(); // hacks.js this.overrideExtensionsPreInit(); // hacks.js
this.registerTabFocusAllowance(this.defaultTabFocusAllowance); this.registerTabFocusAllowance(this.defaultTabFocusAllowance);
@ -1324,31 +1313,6 @@ catch(e) {
}, this); }, 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() destroy : function TSTService_destroy()
{ {
this.utils.inWindowDestoructionProcess = true; this.utils.inWindowDestoructionProcess = true;
@ -1402,11 +1366,7 @@ catch(e) {
return this.preInit(); return this.preInit();
case 'load': case 'load':
if (aEvent.currentTarget == window || aEvent.currentTarget == document) return this.init();
this.init();
else
this.initTabView();
return
case 'unload': case 'unload':
return this.destroy(); return this.destroy();

View File

@ -239,6 +239,8 @@ TreeStyleTabBrowser.prototype = {
this.tabsHash = {}; this.tabsHash = {};
this.tabStripPlaceHolder = null; this.tabStripPlaceHolder = null;
this.tabVisibilityChangedTabs = [];
this.internallyTabMovingCount = 0; this.internallyTabMovingCount = 0;
this.subTreeMovingCount = 0; this.subTreeMovingCount = 0;
this.subTreeChildrenMovingCount = 0; this.subTreeChildrenMovingCount = 0;
@ -277,6 +279,8 @@ TreeStyleTabBrowser.prototype = {
b.mTabContainer.addEventListener('TabOpen', this, true); b.mTabContainer.addEventListener('TabOpen', this, true);
b.mTabContainer.addEventListener('TabClose', this, true); b.mTabContainer.addEventListener('TabClose', this, true);
b.mTabContainer.addEventListener('TabMove', 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('SSTabRestoring', this, true);
b.mTabContainer.addEventListener('SSTabRestored', this, true); b.mTabContainer.addEventListener('SSTabRestored', this, true);
b.mTabContainer.addEventListener('TabPinned', this, true); b.mTabContainer.addEventListener('TabPinned', this, true);
@ -1577,6 +1581,8 @@ TreeStyleTabBrowser.prototype = {
b.mTabContainer.removeEventListener('TabOpen', this, true); b.mTabContainer.removeEventListener('TabOpen', this, true);
b.mTabContainer.removeEventListener('TabClose', this, true); b.mTabContainer.removeEventListener('TabClose', this, true);
b.mTabContainer.removeEventListener('TabMove', 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('SSTabRestoring', this, true);
b.mTabContainer.removeEventListener('SSTabRestored', this, true); b.mTabContainer.removeEventListener('SSTabRestored', this, true);
b.mTabContainer.removeEventListener('TabPinned', this, true); b.mTabContainer.removeEventListener('TabPinned', this, true);
@ -1927,6 +1933,10 @@ TreeStyleTabBrowser.prototype = {
case 'TabMove': case 'TabMove':
return this.onTabMove(aEvent); return this.onTabMove(aEvent);
case 'TabShow':
case 'TabHide':
return this.onTabVisibilityChanged(aEvent);
case 'SSTabRestoring': case 'SSTabRestoring':
return this.onTabRestoring(aEvent); return this.onTabRestoring(aEvent);
@ -2494,11 +2504,14 @@ TreeStyleTabBrowser.prototype = {
} }
if (newParent != parent) { if (newParent != parent) {
if (newParent) if (newParent) {
if (newParent.hidden == aTab.hidden)
this.attachTabTo(aTab, newParent, { insertBefore : nextTab }); this.attachTabTo(aTab, newParent, { insertBefore : nextTab });
else }
else {
this.partTab(aTab); this.partTab(aTab);
} }
}
}, },
updateChildrenArray : function TSTBrowser_updateChildrenArray(aTab) updateChildrenArray : function TSTBrowser_updateChildrenArray(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) onTabRestoring : function TSTBrowser_onTabRestoring(aEvent)
{ {
this.restoreStructure(aEvent.originalTarget); this.restoreStructure(aEvent.originalTarget);
@ -3227,21 +3279,6 @@ TreeStyleTabBrowser.prototype = {
this.removeTabbrowserAttribute(this.kPRINT_PREVIEW); 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 */ /* drag and drop */
get tabbarDNDObserver() get tabbarDNDObserver()