Bug 1331154 - 5. Notify browser.js when a tab gets moved. r=sebastian

Session store will be notified in the next patch.

MozReview-Commit-ID: APTJykdnMF2

--HG--
extra : rebase_source : f3cdd3e5529f470834c32d6ae2289a6d272cba67
This commit is contained in:
Tom Klein 2017-02-02 21:02:51 -06:00
Родитель 8494bb4923
Коммит 9994c5b150
2 изменённых файлов: 32 добавлений и 2 удалений

Просмотреть файл

@ -1137,8 +1137,10 @@ public class Tabs implements BundleEventListener {
// but we need the indices with respect to mOrder, which lists all tabs, both private and
// non-private, in the order in which they were added.
// The positions in mOrder of the from and to tabs.
final int fromPosition;
final int toPosition;
synchronized (this) {
final int fromPosition;
if (tabPositionCache.mTabId == fromTabId) {
fromPosition = tabPositionCache.mOrderPosition;
} else {
@ -1147,7 +1149,7 @@ public class Tabs implements BundleEventListener {
// Start the toPosition search from the mOrder from position.
final int adjustedToPositionHint = fromPosition + (toPositionHint - fromPositionHint);
final int toPosition = getOrderPositionForTab(toTabId, adjustedToPositionHint, fromPositionHint < toPositionHint);
toPosition = getOrderPositionForTab(toTabId, adjustedToPositionHint, fromPositionHint < toPositionHint);
// Remember where the tab was moved to so that if this move continues we'll be ready.
tabPositionCache.cache(fromTabId, toPosition);
@ -1174,5 +1176,12 @@ public class Tabs implements BundleEventListener {
}
queuePersistAllTabs();
final GeckoBundle data = new GeckoBundle();
data.putInt("fromTabId", fromTabId);
data.putInt("fromPosition", fromPosition);
data.putInt("toTabId", toTabId);
data.putInt("toPosition", toPosition);
EventDispatcher.getInstance().dispatch("Tab:Move", data);
}
}

Просмотреть файл

@ -393,6 +393,7 @@ var BrowserApp = {
"Tab:Load",
"Tab:Selected",
"Tab:Closed",
"Tab:Move",
"Browser:LoadManifest",
"Browser:Quit",
"Fonts:Reload",
@ -1316,6 +1317,22 @@ var BrowserApp = {
this._tabs.splice(tabIndex, 1);
},
_handleTabMove(fromTabId, fromPosition, toTabId, toPosition) {
let movedTab = this._tabs[fromPosition];
if (movedTab.id != fromTabId || this._tabs[toPosition].id != toTabId) {
// The gecko and/or java Tabs tabs lists changed sometime between when the Tabs list was
// updated and when news of the update arrived here.
throw "Moved tab mismatch: (" + fromTabId + ", " + movedTab.id + "), " +
"(" + toTabId + ", " + this._tabs[toPosition].id + ")";
}
let step = (fromPosition < toPosition) ? 1 : -1;
for (let i = fromPosition; i != toPosition; i += step) {
this._tabs[i] = this._tabs[i + step];
}
this._tabs[toPosition] = movedTab;
},
// Use this method to select a tab from JS. This method sends a message
// to Java to select the tab in the Java UI (we'll get a Tab:Selected message
// back from Java when that happens).
@ -1898,6 +1915,10 @@ var BrowserApp = {
this._handleTabClosed(this.getTabForId(data.tabId), data.showUndoToast);
break;
}
case "Tab:Move":
this._handleTabMove(data.fromTabId, data.fromPosition, data.toTabId, data.toPosition);
break;
}
},