From 8f6979cc61c83ac7e7a86ee167000b7f15c680ee Mon Sep 17 00:00:00 2001 From: Tim Taubert Date: Tue, 3 May 2011 20:30:08 +0200 Subject: [PATCH] Bug 595020 - Group name isn't displayed in title before TabView is loaded the first time; r=dao --- browser/base/content/browser-tabview.js | 28 ++++++-- browser/base/content/tabview/storage.js | 9 +++ browser/base/content/tabview/ui.js | 1 + browser/base/content/test/tabview/Makefile.in | 1 + .../test/tabview/browser_tabview_bug595020.js | 66 +++++++++++++++++++ 5 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 browser/base/content/test/tabview/browser_tabview_bug595020.js diff --git a/browser/base/content/browser-tabview.js b/browser/base/content/browser-tabview.js index 3020c7a58385..1a2c1b895c9d 100644 --- a/browser/base/content/browser-tabview.js +++ b/browser/base/content/browser-tabview.js @@ -44,7 +44,9 @@ let TabView = { _browserKeyHandlerInitialized: false, _isFrameLoading: false, _initFrameCallbacks: [], + _lastSessionGroupName: null, VISIBILITY_IDENTIFIER: "tabview-visibility", + LAST_SESSION_GROUP_NAME_IDENTIFIER: "tabview-last-session-group-name", // ---------- get windowTitle() { @@ -98,6 +100,10 @@ let TabView = { }; gBrowser.tabContainer.addEventListener( "TabShow", this._tabShowEventListener, true); + + // grab the last used group title + this._lastSessionGroupName = sessionstore.getWindowValue(window, + this.LAST_SESSION_GROUP_NAME_IDENTIFIER); } } }, @@ -216,18 +222,28 @@ let TabView = { }, getActiveGroupName: function TabView_getActiveGroupName() { + if (!this._window) + return this._lastSessionGroupName; + // We get the active group this way, instead of querying // GroupItems.getActiveGroupItem() because the tabSelect event // will not have happened by the time the browser tries to // update the title. + let groupItem = null; let activeTab = window.gBrowser.selectedTab; - if (activeTab._tabViewTabItem && activeTab._tabViewTabItem.parent){ - let groupName = activeTab._tabViewTabItem.parent.getTitle(); - if (groupName) - return groupName; + let activeTabItem = activeTab._tabViewTabItem; + + if (activeTab.pinned) { + // It's an app tab, so it won't have a .tabItem. However, its .parent + // will already be set as the active group. + groupItem = this._window.GroupItems.getActiveGroupItem(); + } else if (activeTabItem) { + groupItem = activeTabItem.parent; } - return null; - }, + + // groupItem may still be null, if the active tab is an orphan. + return groupItem ? groupItem.getTitle() : ""; + }, // ---------- updateContextMenu: function(tab, popup) { diff --git a/browser/base/content/tabview/storage.js b/browser/base/content/tabview/storage.js index 3a18dda10aea..65d4aa857d59 100644 --- a/browser/base/content/tabview/storage.js +++ b/browser/base/content/tabview/storage.js @@ -381,6 +381,15 @@ let Storage = { win, win.TabView.VISIBILITY_IDENTIFIER, data); }, + // ---------- + // Function: saveActiveGroupName + // Saves the active group's name for the given window. + saveActiveGroupName: function Storage_saveActiveGroupName(win) { + let groupName = win.TabView.getActiveGroupName(); + this._sessionStore.setWindowValue( + win, win.TabView.LAST_SESSION_GROUP_NAME_IDENTIFIER, groupName); + }, + // ---------- // Function: saveData // Generic routine for saving data to a window. diff --git a/browser/base/content/tabview/ui.js b/browser/base/content/tabview/ui.js index 6ebc8add0438..2963f88c9880 100644 --- a/browser/base/content/tabview/ui.js +++ b/browser/base/content/tabview/ui.js @@ -258,6 +258,7 @@ let UI = { function domWinClosedObserver(subject, topic, data) { if (topic == "domwindowclosed" && subject == gWindow) { self.isDOMWindowClosing = true; + Storage.saveActiveGroupName(gWindow); if (self.isTabViewVisible()) GroupItems.removeHiddenGroups(); TabItems.saveAll(true); diff --git a/browser/base/content/test/tabview/Makefile.in b/browser/base/content/test/tabview/Makefile.in index 29ffd7f45d6e..d80ddb817ca0 100644 --- a/browser/base/content/test/tabview/Makefile.in +++ b/browser/base/content/test/tabview/Makefile.in @@ -59,6 +59,7 @@ _BROWSER_FILES = \ browser_tabview_bug590606.js \ browser_tabview_bug591706.js \ browser_tabview_bug594958.js \ + browser_tabview_bug595020.js \ browser_tabview_bug595191.js \ browser_tabview_bug595436.js \ browser_tabview_bug595518.js \ diff --git a/browser/base/content/test/tabview/browser_tabview_bug595020.js b/browser/base/content/test/tabview/browser_tabview_bug595020.js new file mode 100644 index 000000000000..d6c2a40ced2a --- /dev/null +++ b/browser/base/content/test/tabview/browser_tabview_bug595020.js @@ -0,0 +1,66 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore); + +let stateStartup = {windows:[ + {tabs:[{entries:[{url:"about:home"}]}], extData:{"tabview-last-session-group-name":"title"}} +]}; + +function test() { + let assertWindowTitle = function (win, title) { + let browser = win.gBrowser.tabs[0].linkedBrowser; + let winTitle = win.gBrowser.getWindowTitleForBrowser(browser); + is(winTitle.indexOf(title), 0, "title starts with '" + title + "'"); + }; + + let testGroupNameChange = function (win) { + showTabView(function () { + let cw = win.TabView.getContentWindow(); + let groupItem = cw.GroupItems.groupItems[0]; + groupItem.setTitle("new-title"); + + hideTabView(function () { + assertWindowTitle(win, "new-title"); + waitForFocus(finish); + }, win); + }, win); + }; + + waitForExplicitFinish(); + + newWindowWithState(stateStartup, function (win) { + registerCleanupFunction(function () win.close()); + assertWindowTitle(win, "title"); + testGroupNameChange(win); + }); +} + +function newWindowWithState(state, callback) { + let opts = "chrome,all,dialog=no,height=800,width=800"; + let win = window.openDialog(getBrowserURL(), "_blank", opts); + + whenWindowLoaded(win, function () { + ss.setWindowState(win, JSON.stringify(state), true); + }); + + whenWindowStateReady(win, function () { + win.close(); + win = ss.undoCloseWindow(0); + whenWindowLoaded(win, function () callback(win)); + }); +} + +function whenWindowLoaded(win, callback) { + win.addEventListener("load", function onLoad() { + win.removeEventListener("load", onLoad, false); + executeSoon(callback); + }, false); +} + +function whenWindowStateReady(win, callback) { + win.addEventListener("SSWindowStateReady", function onReady() { + win.removeEventListener("SSWindowStateReady", onReady, false); + executeSoon(callback); + }, false); +}