зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1017912 - Restore tab in correct position when undoing close tab. r=bnicholson
This commit is contained in:
Родитель
8ef8ca2a41
Коммит
877c2ac1bb
|
@ -188,13 +188,18 @@ public class Tabs implements GeckoEventListener {
|
|||
}
|
||||
}
|
||||
|
||||
private Tab addTab(int id, String url, boolean external, int parentId, String title, boolean isPrivate) {
|
||||
private Tab addTab(int id, String url, boolean external, int parentId, String title, boolean isPrivate, int tabIndex) {
|
||||
final Tab tab = isPrivate ? new PrivateTab(mAppContext, id, url, external, parentId, title) :
|
||||
new Tab(mAppContext, id, url, external, parentId, title);
|
||||
synchronized (this) {
|
||||
lazyRegisterBookmarkObserver();
|
||||
mTabs.put(id, tab);
|
||||
mOrder.add(tab);
|
||||
|
||||
if (tabIndex > -1) {
|
||||
mOrder.add(tabIndex, tab);
|
||||
} else {
|
||||
mOrder.add(tab);
|
||||
}
|
||||
}
|
||||
|
||||
// Suppress the ADDED event to prevent animation of tabs created via session restore.
|
||||
|
@ -427,7 +432,8 @@ public class Tabs implements GeckoEventListener {
|
|||
tab = addTab(id, url, message.getBoolean("external"),
|
||||
message.getInt("parentId"),
|
||||
message.getString("title"),
|
||||
message.getBoolean("isPrivate"));
|
||||
message.getBoolean("isPrivate"),
|
||||
message.getInt("tabIndex"));
|
||||
|
||||
// If we added the tab as a stub, we should have already
|
||||
// selected it, so ignore this flag for stubbed tabs.
|
||||
|
@ -799,7 +805,10 @@ public class Tabs implements GeckoEventListener {
|
|||
// long as it's a valid URI.
|
||||
String tabUrl = (url != null && Uri.parse(url).getScheme() != null) ? url : null;
|
||||
|
||||
added = addTab(tabId, tabUrl, external, parentId, url, isPrivate);
|
||||
// Add the new tab to the end of the tab order.
|
||||
final int tabIndex = -1;
|
||||
|
||||
added = addTab(tabId, tabUrl, external, parentId, url, isPrivate, tabIndex);
|
||||
added.setDesktopMode(desktopMode);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -921,7 +921,12 @@ var BrowserApp = {
|
|||
aParams = aParams || {};
|
||||
|
||||
let newTab = new Tab(aURI, aParams);
|
||||
this._tabs.push(newTab);
|
||||
|
||||
if (typeof aParams.tabIndex == "number") {
|
||||
this._tabs.splice(aParams.tabIndex, 0, newTab);
|
||||
} else {
|
||||
this._tabs.push(newTab);
|
||||
}
|
||||
|
||||
let selected = "selected" in aParams ? aParams.selected : true;
|
||||
if (selected)
|
||||
|
@ -972,12 +977,14 @@ var BrowserApp = {
|
|||
if (aTab == this.selectedTab)
|
||||
this.selectedTab = null;
|
||||
|
||||
let tabIndex = this._tabs.indexOf(aTab);
|
||||
|
||||
let evt = document.createEvent("UIEvents");
|
||||
evt.initUIEvent("TabClose", true, false, window, null);
|
||||
evt.initUIEvent("TabClose", true, false, window, tabIndex);
|
||||
aTab.browser.dispatchEvent(evt);
|
||||
|
||||
aTab.destroy();
|
||||
this._tabs.splice(this._tabs.indexOf(aTab), 1);
|
||||
this._tabs.splice(tabIndex, 1);
|
||||
|
||||
if (aShowUndoToast) {
|
||||
// Get a title for the undo close toast. Fall back to the URL if there is no title.
|
||||
|
@ -3053,6 +3060,7 @@ Tab.prototype = {
|
|||
tabID: this.id,
|
||||
uri: uri,
|
||||
parentId: ("parentId" in aParams) ? aParams.parentId : -1,
|
||||
tabIndex: ("tabIndex" in aParams) ? aParams.tabIndex : -1,
|
||||
external: ("external" in aParams) ? aParams.external : false,
|
||||
selected: ("selected" in aParams) ? aParams.selected : true,
|
||||
title: title,
|
||||
|
|
|
@ -46,6 +46,10 @@ SessionStore.prototype = {
|
|||
_maxTabsUndo: 1,
|
||||
_pendingWrite: 0,
|
||||
|
||||
// The index where the most recently closed tab was in the tabs array
|
||||
// when it was closed.
|
||||
_lastClosedTabIndex: -1,
|
||||
|
||||
init: function ss_init() {
|
||||
// Get file references
|
||||
this._sessionFile = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
||||
|
@ -98,6 +102,8 @@ SessionStore.prototype = {
|
|||
for (let [ssid, win] in Iterator(this._windows))
|
||||
win.closedTabs = [];
|
||||
|
||||
this._lastClosedTabIndex = -1;
|
||||
|
||||
if (this._loadState == STATE_RUNNING) {
|
||||
// Save the purged state immediately
|
||||
this.saveState();
|
||||
|
@ -164,7 +170,7 @@ SessionStore.prototype = {
|
|||
}
|
||||
case "TabClose": {
|
||||
let browser = aEvent.target;
|
||||
this.onTabClose(window, browser);
|
||||
this.onTabClose(window, browser, aEvent.detail);
|
||||
this.onTabRemove(window, browser);
|
||||
break;
|
||||
}
|
||||
|
@ -269,7 +275,7 @@ SessionStore.prototype = {
|
|||
this.saveStateDelayed();
|
||||
},
|
||||
|
||||
onTabClose: function ss_onTabClose(aWindow, aBrowser) {
|
||||
onTabClose: function ss_onTabClose(aWindow, aBrowser, aTabIndex) {
|
||||
if (this._maxTabsUndo == 0)
|
||||
return;
|
||||
|
||||
|
@ -283,6 +289,8 @@ SessionStore.prototype = {
|
|||
let length = this._windows[aWindow.__SSID].closedTabs.length;
|
||||
if (length > this._maxTabsUndo)
|
||||
this._windows[aWindow.__SSID].closedTabs.splice(this._maxTabsUndo, length - this._maxTabsUndo);
|
||||
|
||||
this._lastClosedTabIndex = aTabIndex;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -845,11 +853,14 @@ SessionStore.prototype = {
|
|||
let params = {
|
||||
selected: true,
|
||||
isPrivate: closedTab.isPrivate,
|
||||
desktopMode: closedTab.desktopMode
|
||||
desktopMode: closedTab.desktopMode,
|
||||
tabIndex: this._lastClosedTabIndex
|
||||
};
|
||||
let tab = aWindow.BrowserApp.addTab(closedTab.entries[closedTab.index - 1].url, params);
|
||||
this._restoreHistory(closedTab, tab.browser.sessionHistory);
|
||||
|
||||
this._lastClosedTabIndex = -1;
|
||||
|
||||
// Put back the extra data
|
||||
tab.browser.__SS_extdata = closedTab.extData;
|
||||
|
||||
|
@ -869,6 +880,11 @@ SessionStore.prototype = {
|
|||
|
||||
// remove closed tab from the array
|
||||
closedTabs.splice(aIndex, 1);
|
||||
|
||||
// Forget the last closed tab index if we're forgetting the last closed tab.
|
||||
if (aIndex == 0) {
|
||||
this._lastClosedTabIndex = -1;
|
||||
}
|
||||
},
|
||||
|
||||
getTabValue: function ss_getTabValue(aTab, aKey) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче