Bug 1466678 - Store multiple selected tabs in a WeakSet instead of a WeakMap r=jaws

MozReview-Commit-ID: 3sfRtQruInF

--HG--
extra : rebase_source : 52dd3036bb8d341ba1ea646fc93dcc405b030e36
This commit is contained in:
Oriol Brufau 2018-06-04 23:20:46 +02:00
Родитель d6790d5d8c
Коммит b3e0d71d8a
3 изменённых файлов: 16 добавлений и 16 удалений

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

@ -136,7 +136,7 @@ window._gBrowser = {
_removingTabs: [],
_multiSelectedTabsMap: new WeakMap(),
_multiSelectedTabsSet: new WeakSet(),
_lastMultiSelectedTabRef: null,
@ -2624,7 +2624,7 @@ window._gBrowser = {
return;
}
let selectedTabs = ChromeUtils.nondeterministicGetWeakMapKeys(this._multiSelectedTabsMap)
let selectedTabs = ChromeUtils.nondeterministicGetWeakSetKeys(this._multiSelectedTabsSet)
.filter(tab => tab.isConnected);
this.removeCollectionOfTabs(selectedTabs);
},
@ -3630,7 +3630,7 @@ window._gBrowser = {
}
aTab.setAttribute("multiselected", "true");
this._multiSelectedTabsMap.set(aTab, null);
this._multiSelectedTabsSet.add(aTab);
},
/**
@ -3661,28 +3661,28 @@ window._gBrowser = {
return;
}
aTab.removeAttribute("multiselected");
this._multiSelectedTabsMap.delete(aTab);
this._multiSelectedTabsSet.delete(aTab);
},
clearMultiSelectedTabs() {
const selectedTabs = ChromeUtils.nondeterministicGetWeakMapKeys(this._multiSelectedTabsMap);
const selectedTabs = ChromeUtils.nondeterministicGetWeakSetKeys(this._multiSelectedTabsSet);
for (let tab of selectedTabs) {
if (tab.isConnected && tab.multiselected) {
tab.removeAttribute("multiselected");
}
}
this._multiSelectedTabsMap = new WeakMap();
this._multiSelectedTabsSet = new WeakSet();
},
get multiSelectedTabsCount() {
return ChromeUtils.nondeterministicGetWeakMapKeys(this._multiSelectedTabsMap)
return ChromeUtils.nondeterministicGetWeakSetKeys(this._multiSelectedTabsSet)
.filter(tab => tab.isConnected && !tab.closing)
.length;
},
get lastMultiSelectedTab() {
let tab = this._lastMultiSelectedTabRef ? this._lastMultiSelectedTabRef.get() : null;
if (tab && tab.isConnected && this._multiSelectedTabsMap.has(tab)) {
if (tab && tab.isConnected && this._multiSelectedTabsSet.has(tab)) {
return tab;
}
return gBrowser.selectedTab;

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

@ -2,7 +2,7 @@ const PREF_MULTISELECT_TABS = "browser.tabs.multiselect";
add_task(async function clickWithoutPrefSet() {
let tab = await addTab();
let mSelectedTabs = gBrowser._multiSelectedTabsMap;
let mSelectedTabs = gBrowser._multiSelectedTabsSet;
isnot(gBrowser.selectedTab, tab, "Tab doesn't have focus");
@ -29,7 +29,7 @@ add_task(async function clickWithPrefSet() {
]
});
let mSelectedTabs = gBrowser._multiSelectedTabsMap;
let mSelectedTabs = gBrowser._multiSelectedTabsSet;
const initialFocusedTab = gBrowser.selectedTab;
const tab = await addTab();
@ -60,8 +60,8 @@ add_task(async function clearSelection() {
await triggerClickOn(tab1, { ctrlKey: true });
await triggerClickOn(tab2, { ctrlKey: true });
ok(tab1.multiselected && gBrowser._multiSelectedTabsMap.has(tab1), "Tab1 is (multi) selected");
ok(tab2.multiselected && gBrowser._multiSelectedTabsMap.has(tab2), "Tab2 is (multi) selected");
ok(tab1.multiselected && gBrowser._multiSelectedTabsSet.has(tab1), "Tab1 is (multi) selected");
ok(tab2.multiselected && gBrowser._multiSelectedTabsSet.has(tab2), "Tab2 is (multi) selected");
is(gBrowser.multiSelectedTabsCount, 2, "Two tabs (multi) selected");
isnot(tab3, gBrowser.selectedTab, "Tab3 doesn't have focus");

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

@ -5,7 +5,7 @@ add_task(async function prefNotSet() {
let tab2 = await addTab();
let tab3 = await addTab();
let mSelectedTabs = gBrowser._multiSelectedTabsMap;
let mSelectedTabs = gBrowser._multiSelectedTabsSet;
await BrowserTestUtils.switchTab(gBrowser, tab1);
@ -42,7 +42,7 @@ add_task(async function noItemsInTheCollectionBeforeShiftClicking() {
let tab3 = await addTab();
let tab4 = await addTab();
let tab5 = await addTab();
let mSelectedTabs = gBrowser._multiSelectedTabsMap;
let mSelectedTabs = gBrowser._multiSelectedTabsSet;
await BrowserTestUtils.switchTab(gBrowser, tab1);
@ -77,7 +77,7 @@ add_task(async function itemsInTheCollectionBeforeShiftClicking() {
let tab4 = await addTab();
let tab5 = await addTab();
let mSelectedTabs = gBrowser._multiSelectedTabsMap;
let mSelectedTabs = gBrowser._multiSelectedTabsSet;
await BrowserTestUtils.switchTab(gBrowser, () => triggerClickOn(tab1, {}));