From 7c6b3475badf9d05e99fb1edf9b26a92d6f5d25c Mon Sep 17 00:00:00 2001 From: SHIMODA Hiroshi Date: Mon, 9 Apr 2012 20:18:52 +0900 Subject: [PATCH] Store the original state of the "Tabs on Top" for user's expectation correctly --- defaults/preferences/treestyletab.js | 1 - modules/browser.js | 37 +++++++++++++--------- modules/window.js | 47 ++++++++++++++++++---------- 3 files changed, 53 insertions(+), 32 deletions(-) diff --git a/defaults/preferences/treestyletab.js b/defaults/preferences/treestyletab.js index e7804e5b..75ede4cc 100644 --- a/defaults/preferences/treestyletab.js +++ b/defaults/preferences/treestyletab.js @@ -585,7 +585,6 @@ pref("browser.link.open_newwindow.restriction.override", 0); pref("browser.tabs.loadFolderAndReplace.override", false); pref("browser.tabs.insertRelatedAfterCurrent.override", false); pref("browser.tabs.insertRelatedAfterCurrent.override.force", true); -pref("extensions.treestyletab.tabsOnTopShouldBeRestored", false); /** * Extra commands for selected tabs (Multiple Tab Handler) diff --git a/modules/browser.js b/modules/browser.js index b491c0d4..fe72282d 100644 --- a/modules/browser.js +++ b/modules/browser.js @@ -1498,15 +1498,22 @@ TreeStyleTabBrowser.prototype = { // remove ordinal for "tabs on top" https://bugzilla.mozilla.org/show_bug.cgi?id=544815 if (this.position == 'top') { this.removeTabStripAttribute('ordinal'); - // Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=555987 - // This should be done when the value of the "ordinal" attribute - // is modified dynamically. So, we don' have to do it before - // the browser window is completely initialized. if (TabsOnTop && !this.windowService.isPopupWindow && this.windowService.initialized) { - TabsOnTop.enabled = !TabsOnTop.enabled; + let currentState = TabsOnTop.enabled; + let originalState = this.getTreePref('tabsOnTop.originalState'); + if (originalState !== null && + currentState != originalState && + this.windowService.tabsOnTopChangingByUI && + !this.windowService.changingTabsOnTop) + this.setTreePref('tabsOnTop.originalState', currentState); + // Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=555987 + // This should be done when the value of the "ordinal" attribute + // is modified dynamically. So, we don' have to do it before + // the browser window is completely initialized. + TabsOnTop.enabled = !currentState; this.Deferred.next(function() { - TabsOnTop.enabled = !TabsOnTop.enabled; + TabsOnTop.enabled = currentState; }).error(this.defaultDeferredErrorHandler); } } @@ -1525,10 +1532,7 @@ TreeStyleTabBrowser.prototype = { if (TabsOnTop && !this.windowService.isPopupWindow) { let updateTabsOnTop = function() { - let tabsWasOnTop = TabsOnTop.enabled; - TabsOnTop.enabled = TabsOnTop.enabled && self.position == 'top' && self.fixed; - if (tabsWasOnTop && !TabsOnTop.enabled) - self.setTreePref('tabsOnTopShouldBeRestored', true); + self.windowService.updateTabsOnTop(); }; // TabsOnTop.enabled is always "false" before the browser window is // completely initialized. So, we have to check it with delay only @@ -4467,24 +4471,27 @@ TreeStyleTabBrowser.prototype = { onTabsOnTopSyncCommand : function TSTBrowser_onTabsOnTopSyncCommand(aEnabled) { if ( + this.windowService.tabsOnTopChangingByUI || !aEnabled || this.position != 'top' || this.fixed || - !this.windowService.isPopupWindow + this.windowService.isPopupWindow ) return; + this.windowService.tabsOnTopChangingByUI = true; var self = this; this.Deferred .next(function() { self.windowService.toggleFixed(self.mTabBrowser); }) .next(function() { - if (self.window.TabsOnTop.enabled != aEnabled) { -dump('onTabsOnTopSyncCommand, set to '+aEnabled+'\n'); + if (self.window.TabsOnTop.enabled != aEnabled) self.window.TabsOnTop.enabled = aEnabled; - } }) - .error(this.defaultDeferredErrorHandler); + .error(this.defaultDeferredErrorHandler) + .next(function() { + self.windowService.tabsOnTopChangingByUI = false; + }); }, onTreeStyleTabPrintPreviewEntered : function TSTBrowser_onTreeStyleTabPrintPreviewEntered(aEvent) diff --git a/modules/window.js b/modules/window.js index b51b34fe..6849b16b 100644 --- a/modules/window.js +++ b/modules/window.js @@ -387,8 +387,8 @@ TreeStyleTabWindow.prototype = { namespace = void(0); var self = this; var restorePrefs = function() { - if (prefs.getPref('extensions.treestyletab.tabsOnTopShouldBeRestored')) { - prefs.clearPref('extensions.treestyletab.tabsOnTopShouldBeRestored'); + if (prefs.getPref('extensions.treestyletab.tabsOnTop.originalState')) { + prefs.clearPref('extensions.treestyletab.tabsOnTop.originalState'); try { self.browser.treeStyleTab.position = 'top'; } @@ -980,25 +980,40 @@ TreeStyleTabWindow.prototype = { updateTabsOnTop : function TSTWindow_updateTabsOnTop() { var w = this.window; - if (this.isPopupWindow || !('TabsOnTop' in w) || !('enabled' in w.TabsOnTop)) + if ( + this.isPopupWindow || + this.tabsOnTopChangingByUI || + this.tabsOnTopChangingByTST || + !('TabsOnTop' in w) || + !('enabled' in w.TabsOnTop) + ) return; - var TabsOnTop = w.TabsOnTop; - if (!('_tabsOnTopDefaultState' in this)) - this._tabsOnTopDefaultState = TabsOnTop.enabled; + this.tabsOnTopChangingByTST = true; - if (this.browser.treeStyleTab.position != 'top' || - !this.browser.treeStyleTab.fixed) { - if (TabsOnTop.enabled) { - TabsOnTop.enabled = false; - this.setTreePref('tabsOnTopShouldBeRestored', true); + try { + var TabsOnTop = w.TabsOnTop; + var originalState = this.getTreePref('tabsOnTop.originalState'); + if (originalState === null) { + let current = this.getDefaultPref('browser.tabs.onTop') === null ? + TabsOnTop.enabled : + this.getPref('browser.tabs.onTop') ; + this.setTreePref('tabsOnTop.originalState', originalState = current); + } + + if (this.browser.treeStyleTab.position != 'top' || + !this.browser.treeStyleTab.fixed) { + if (TabsOnTop.enabled) + TabsOnTop.enabled = false; + } + else { + if (TabsOnTop.enabled != originalState) + TabsOnTop.enabled = originalState; + this.clearTreePref('tabsOnTop.originalState'); } } - else if ('_tabsOnTopDefaultState' in this) { - if (TabsOnTop.enabled!= this._tabsOnTopDefaultState) - TabsOnTop.enabled = this._tabsOnTopDefaultState; - delete this._tabsOnTopDefaultState; - this.setTreePref('tabsOnTopShouldBeRestored', false); + finally { + this.tabsOnTopChangingByTST = false; } },