Bug 586211 - Restore hidden tabs after visible ones. r=zpao, a=beta5+

This commit is contained in:
Dan Witte 2010-08-27 08:12:02 -07:00
Родитель 60e5e11fd0
Коммит 2b5db9ee7d
2 изменённых файлов: 35 добавлений и 13 удалений

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

@ -2078,19 +2078,33 @@ SessionStoreService.prototype = {
}
if (aTabs.length > 0) {
// Load hidden tabs last, by pushing them to the end of the list
let unhiddenTabs = aTabs.length;
for (let t = 0; t < unhiddenTabs; ) {
if (aTabs[t].hidden) {
aTabs = aTabs.concat(aTabs.splice(t, 1));
aTabData = aTabData.concat(aTabData.splice(t, 1));
if (aSelectTab > t)
--aSelectTab;
--unhiddenTabs;
continue;
}
++t;
}
// Determine if we can optimize & load visible tabs first
let maxVisibleTabs = Math.ceil(tabbrowser.tabContainer.mTabstrip.scrollClientSize /
aTabs[aTabs.length - 1].clientWidth);
aTabs[unhiddenTabs - 1].clientWidth);
// make sure we restore visible tabs first, if there are enough
if (maxVisibleTabs < aTabs.length && aSelectTab > 1) {
if (maxVisibleTabs < unhiddenTabs && aSelectTab > 1) {
let firstVisibleTab = 0;
if (aTabs.length - maxVisibleTabs > aSelectTab) {
if (unhiddenTabs - maxVisibleTabs > aSelectTab) {
// aSelectTab is leftmost since we scroll to it when possible
firstVisibleTab = aSelectTab - 1;
} else {
// aSelectTab is rightmost or no more room to scroll right
firstVisibleTab = aTabs.length - maxVisibleTabs;
firstVisibleTab = unhiddenTabs - maxVisibleTabs;
}
aTabs = aTabs.splice(firstVisibleTab, maxVisibleTabs).concat(aTabs);
aTabData = aTabData.splice(firstVisibleTab, maxVisibleTabs).concat(aTabData);

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

@ -52,10 +52,16 @@ function test() {
waitForExplicitFinish();
// builds the tests state based on a few parameters
function buildTestState(num, selected) {
function buildTestState(num, selected, hidden) {
let state = { windows: [ { "tabs": [], "selected": selected } ] };
while (num--)
while (num--) {
state.windows[0].tabs.push({entries: [{url: "http://example.com/"}]});
let i = state.windows[0].tabs.length - 1;
if (hidden.length > 0 && i == hidden[0]) {
state.windows[0].tabs[i].hidden = true;
hidden.splice(0, 1);
}
}
return state;
}
@ -80,17 +86,17 @@ function test() {
}
// the number of tests we're running
let numTests = 4;
let numTests = 6;
let completedTests = 0;
let tabMinWidth = parseInt(getComputedStyle(gBrowser.selectedTab, null).minWidth);
function runTest(testNum, totalTabs, selectedTab, shownTabs, order) {
function runTest(testNum, totalTabs, selectedTab, shownTabs, hiddenTabs, order) {
let test = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMEventListener,
Ci.nsISupportsWeakReference]),
state: buildTestState(totalTabs, selectedTab),
state: buildTestState(totalTabs, selectedTab, hiddenTabs),
numTabsToShow: shownTabs,
expectedOrder: order,
actualOrder: [],
@ -157,10 +163,12 @@ function test() {
}
// actually create & run the tests
runTest(1, 13, 1, 6, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
runTest(2, 13, 13, 6, [12, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6]);
runTest(3, 13, 4, 6, [3, 4, 5, 6, 7, 8, 0, 1, 2, 9, 10, 11, 12]);
runTest(4, 13, 11, 6, [10, 7, 8, 9, 11, 12, 0, 1, 2, 3, 4, 5, 6]);
runTest(1, 13, 1, 6, [], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
runTest(2, 13, 13, 6, [], [12, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6]);
runTest(3, 13, 4, 6, [], [3, 4, 5, 6, 7, 8, 0, 1, 2, 9, 10, 11, 12]);
runTest(4, 13, 11, 6, [], [10, 7, 8, 9, 11, 12, 0, 1, 2, 3, 4, 5, 6]);
runTest(5, 13, 13, 6, [0, 4, 9], [12, 6, 7, 8, 10, 11, 1, 2, 3, 5, 0, 4, 9]);
runTest(6, 13, 4, 6, [1, 7, 12], [3, 4, 5, 6, 8, 9, 0, 2, 10, 11, 1, 7, 12]);
// finish() is run by the last test to finish, so no cleanup down here
}