better handling of duplicated tabs

This commit is contained in:
SHIMODA Hiroshi 2011-12-13 16:10:49 +09:00
parent 8d981a7d13
commit 4c51a856b1

View File

@ -603,6 +603,7 @@ TreeStyleTabBrowser.prototype = {
w.addEventListener(this.kEVENT_TYPE_PRINT_PREVIEW_EXITED, this, false); w.addEventListener(this.kEVENT_TYPE_PRINT_PREVIEW_EXITED, this, false);
w.addEventListener('tabviewhidden', this, true); w.addEventListener('tabviewhidden', this, true);
w.addEventListener(this.kEVENT_TYPE_TAB_FOCUS_SWITCHING_END, this, false); w.addEventListener(this.kEVENT_TYPE_TAB_FOCUS_SWITCHING_END, this, false);
w.addEventListener('SSWindowStateBusy', this, false);
b.addEventListener('nsDOMMultipleTabHandlerTabsClosing', this, false); b.addEventListener('nsDOMMultipleTabHandlerTabsClosing', this, false);
@ -1784,6 +1785,7 @@ TreeStyleTabBrowser.prototype = {
w.removeEventListener(this.kEVENT_TYPE_PRINT_PREVIEW_EXITED, this, false); w.removeEventListener(this.kEVENT_TYPE_PRINT_PREVIEW_EXITED, this, false);
w.removeEventListener('tabviewhidden', this, true); w.removeEventListener('tabviewhidden', this, true);
w.removeEventListener(this.kEVENT_TYPE_TAB_FOCUS_SWITCHING_END, this, false); w.removeEventListener(this.kEVENT_TYPE_TAB_FOCUS_SWITCHING_END, this, false);
w.removeEventListener('SSWindowStateBusy', this, false);
b.removeEventListener('nsDOMMultipleTabHandlerTabsClosing', this, false); b.removeEventListener('nsDOMMultipleTabHandlerTabsClosing', this, false);
@ -2045,9 +2047,11 @@ TreeStyleTabBrowser.prototype = {
} }
return; return;
/*
case 'sessionstore-windows-restored': case 'sessionstore-windows-restored':
case 'sessionstore-browser-state-restored': case 'sessionstore-browser-state-restored':
return this.onWindowStateRestored(); return this.onWindowStateRestored();
*/
case 'private-browsing-change-granted': case 'private-browsing-change-granted':
this.collapseExpandAllSubtree(false, true); this.collapseExpandAllSubtree(false, true);
@ -2286,29 +2290,28 @@ TreeStyleTabBrowser.prototype = {
var tabs = this.getAllTabsArray(this.mTabBrowser); var tabs = this.getAllTabsArray(this.mTabBrowser);
tabs = tabs.filter(function(aTab) { tabs = tabs.filter(function(aTab) {
var id = this.getTabValue(aTab, this.kID); if (aTab.__treestyletab__structureRestored) // onWindowStateRestored can be called twice
return false;
if ( if (
!id || // tabs opened by externals applications !aTab.getAttribute(this.kID) || // tabs opened by externals applications
!aTab.linkedBrowser.__SS_restoreState !aTab.linkedBrowser.__SS_restoreState
) )
return false; return false;
var currentId = aTab.getAttribute(this.kID); var currentId = aTab.getAttribute(this.kID);
var restored = id == currentId; if (this.tabsHash[currentId] == aTab)
if (!restored) { delete this.tabsHash[currentId];
delete this.tabsHash[id];
aTab.setAttribute(this.kID, id); this.resetTabState(aTab);
var [id, duplicated] = this._restoreTabId(aTab);
this.setTabValue(aTab, this.kID, id);
this.tabsHash[id] = aTab; this.tabsHash[id] = aTab;
}
aTab.__treestyletab__structureRestored = true; aTab.__treestyletab__structureRestored = true;
aTab.__treestyletab__duplicated = duplicated;
aTab.removeAttribute(this.kPARENT);
aTab.removeAttribute(this.kCHILDREN);
aTab.removeAttribute(this.kSUBTREE_COLLAPSED);
aTab.removeAttribute(this.kCOLLAPSED);
aTab.removeAttribute(this.kNEST);
this.updateTabCollapsed(aTab, false, true);
return true; return true;
}, this); }, this);
@ -2321,24 +2324,25 @@ TreeStyleTabBrowser.prototype = {
}, },
restoreOneTab : function TSTBrowser_restoreOneTab(aTab) restoreOneTab : function TSTBrowser_restoreOneTab(aTab)
{ {
let duplicated = aTab.__treestyletab__duplicated;
let subTreeCollapsed = this.getTabValue(aTab, this.kSUBTREE_COLLAPSED) == 'true'; let subTreeCollapsed = this.getTabValue(aTab, this.kSUBTREE_COLLAPSED) == 'true';
let children = this.getTabValue(aTab, this.kCHILDREN); let children = this.getTabValue(aTab, this.kCHILDREN);
this.deleteTabValue(aTab, this.kCHILDREN); this.deleteTabValue(aTab, this.kCHILDREN);
if (children) { if (children) {
subTreeCollapsed = this._restoreSubtreeCollapsedState(aTab, subTreeCollapsed); subTreeCollapsed = this._restoreSubtreeCollapsedState(aTab, subTreeCollapsed);
children.split('|').forEach(function(aChild) { let self = this;
aChild = this.getTabById(aChild); this._restoreChildTabsRelation(aTab, children, duplicated, function(aChild) {
if (aChild) { let refId = self.getTabValue(aChild, self.kINSERT_BEFORE);
this.attachTabTo(aChild, aTab, { if (refId && duplicated) refId = self.redirectId(refId);
return {
forceExpand : true, // to prevent to collapse the selected tab forceExpand : true, // to prevent to collapse the selected tab
dontAnimate : true, dontAnimate : true,
insertBefore : this.getTabById(this.getTabValue(aChild, this.kINSERT_BEFORE)) insertBefore : self.getTabById(refId)
};
}); });
this.collapseExpandTab(aChild, subTreeCollapsed, true);
}
}, this);
this.collapseExpandSubtree(aTab, subTreeCollapsed, true); this.collapseExpandSubtree(aTab, subTreeCollapsed, true);
} }
delete aTab.__treestyletab__duplicated;
return true return true
}, },
@ -2466,6 +2470,15 @@ TreeStyleTabBrowser.prototype = {
return this.cancelDelayedExpandOnTabSelect(); return this.cancelDelayedExpandOnTabSelect();
case 'SSWindowStateBusy':
let (self = this) {
this.Deferred.next(function() {
self.onWindowStateRestored();
});
}
return;
case 'nsDOMMultipleTabHandlerTabsClosing': case 'nsDOMMultipleTabHandlerTabsClosing':
if (!this.onTabsClosing(aEvent)) if (!this.onTabsClosing(aEvent))
aEvent.preventDefault(); aEvent.preventDefault();
@ -3329,7 +3342,13 @@ TreeStyleTabBrowser.prototype = {
let isSubtreeCollapsed = this._restoreSubtreeCollapsedState(aTab); let isSubtreeCollapsed = this._restoreSubtreeCollapsedState(aTab);
let childTabs = this._restoreChildTabsRelation(aTab, children, mayBeDuplicated); let restoringMultipleTabs = this.windowService.restoringTree;
let options = {
dontExpand : restoringMultipleTabs,
dontUpdateIndent : true,
dontAnimate : restoringMultipleTabs
};
let childTabs = this._restoreChildTabsRelation(aTab, children, mayBeDuplicated, options);
this._restoreTabPositionAndIndent(aTab, childTabs, mayBeDuplicated); this._restoreTabPositionAndIndent(aTab, childTabs, mayBeDuplicated);
@ -3400,7 +3419,7 @@ TreeStyleTabBrowser.prototype = {
this.setTabValue(aTab, this.kSUBTREE_COLLAPSED, isSubtreeCollapsed); this.setTabValue(aTab, this.kSUBTREE_COLLAPSED, isSubtreeCollapsed);
return isSubtreeCollapsed; return isSubtreeCollapsed;
}, },
_restoreChildTabsRelation : function TSTBrowser_restoreChildTabsRelation(aTab, aChildrenList, aMayBeDuplicated) _restoreChildTabsRelation : function TSTBrowser_restoreChildTabsRelation(aTab, aChildrenList, aMayBeDuplicated, aOptions)
{ {
var childTabs = []; var childTabs = [];
if (!aChildrenList) if (!aChildrenList)
@ -3414,14 +3433,12 @@ TreeStyleTabBrowser.prototype = {
return this.redirectId(aChild); return this.redirectId(aChild);
}, this); }, this);
var restoringMultipleTabs = this.windowService.restoringTree;
aChildrenList.forEach(function(aChildTab) { aChildrenList.forEach(function(aChildTab) {
if (aChildTab && (aChildTab = this.getTabById(aChildTab))) { if (aChildTab && (aChildTab = this.getTabById(aChildTab))) {
this.attachTabTo(aChildTab, aTab, { let options = aOptions;
dontExpand : restoringMultipleTabs, if (options && typeof options == 'function')
dontUpdateIndent : true, options = options(aChildTab);
dontAnimate : restoringMultipleTabs this.attachTabTo(aChildTab, aTab, options);
});
childTabs.push(aChildTab); childTabs.push(aChildTab);
} }
}, this); }, this);
@ -4297,15 +4314,19 @@ TreeStyleTabBrowser.prototype = {
dontAnimate : true dontAnimate : true
}); });
/* reset attributes before restoring */ this.resetTabState(aTab);
this.updateTabsIndent([aTab], undefined, true);
},
resetTabState : function TSTBrowser_resetTabState(aTab)
{
aTab.removeAttribute(this.kID); aTab.removeAttribute(this.kID);
aTab.removeAttribute(this.kPARENT); aTab.removeAttribute(this.kPARENT);
aTab.removeAttribute(this.kCHILDREN); aTab.removeAttribute(this.kCHILDREN);
aTab.removeAttribute(this.kSUBTREE_COLLAPSED); aTab.removeAttribute(this.kSUBTREE_COLLAPSED);
aTab.removeAttribute(this.kCOLLAPSED); aTab.removeAttribute(this.kCOLLAPSED);
aTab.removeAttribute(this.kCOLLAPSED_DONE);
aTab.removeAttribute(this.kNEST); aTab.removeAttribute(this.kNEST);
this.updateTabsIndent([aTab], undefined, true); this.updateTabCollapsed(aTab, false, true);
}, },
resetAllTabs : function TSTBrowser_resetAllTabs(aDetachAllChildren) resetAllTabs : function TSTBrowser_resetAllTabs(aDetachAllChildren)