Bug 1446343 part 2 - Convert size attributes to outer size for sessionstore. r=mikedeboer

MozReview-Commit-ID: FS6yrGggD7o

--HG--
extra : rebase_source : c4b5c404292dd2c70d2c2933cdd429e903012143
This commit is contained in:
Xidorn Quan 2018-04-06 15:01:04 +10:00
Родитель 8c8cef5c1d
Коммит 88729f16df
3 изменённых файлов: 72 добавлений и 15 удалений

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

@ -4345,23 +4345,41 @@ var SessionStoreInternal = {
}
}
var dimension;
switch (aAttribute) {
case "width":
dimension = aWindow.outerWidth;
break;
case "height":
dimension = aWindow.outerHeight;
break;
default:
dimension = aAttribute in aWindow ? aWindow[aAttribute] : "";
break;
// We want to persist the size / position in normal state, so that
// we can restore to them even if the window is currently maximized
// or minimized. However, attributes on window object only reflect
// the current state of the window, so when it isn't in the normal
// sizemode, their values aren't what we want the window to restore
// to. In that case, try to read from the attributes of the root
// element first instead.
if (aWindow.windowState != aWindow.STATE_NORMAL) {
let docElem = aWindow.document.documentElement;
let attr = parseInt(docElem.getAttribute(aAttribute), 10);
if (attr) {
if (aAttribute != "width" && aAttribute != "height") {
return attr;
}
// Width and height attribute report the inner size, but we want
// to store the outer size, so add the difference.
let xulWin = aWindow.getInterface(Ci.nsIDocShell)
.treeOwner
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIXULWindow);
let diff = aAttribute == "width"
? xulWin.outerToInnerWidthDifferenceInCSSPixels
: xulWin.outerToInnerHeightDifferenceInCSSPixels;
return attr + diff;
}
}
if (aWindow.windowState == aWindow.STATE_NORMAL) {
return dimension;
switch (aAttribute) {
case "width":
return aWindow.outerWidth;
case "height":
return aWindow.outerHeight;
default:
return aAttribute in aWindow ? aWindow[aAttribute] : "";
}
return aWindow.document.documentElement.getAttribute(aAttribute) || dimension;
},
/**

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

@ -269,4 +269,4 @@ skip-if = !crashreporter || !e10s # Tabs can't crash without e10s
[browser_cookies_legacy.js]
[browser_cookies_privacy.js]
[browser_speculative_connect.js]
[browser_1446343-windowsize.js]

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

@ -0,0 +1,39 @@
add_task(async function test() {
const win = await BrowserTestUtils.openNewBrowserWindow();
async function changeSizeMode(mode) {
let promise = BrowserTestUtils.waitForEvent(win, "sizemodechange");
win[mode]();
await promise;
}
if (win.windowState != win.STATE_NORMAL) {
await changeSizeMode("restore");
}
const {outerWidth, outerHeight, screenX, screenY} = win;
function checkCurrentState(sizemode) {
let state = JSON.parse(ss.getWindowState(win));
let winState = state.windows[0];
let msgSuffix = ` should match on ${sizemode} mode`;
is(winState.width, outerWidth, "width" + msgSuffix);
is(winState.height, outerHeight, "height" + msgSuffix);
// The position attributes seem to be affected on macOS when the
// window gets maximized, so skip checking them for now.
if (AppConstants.platform != "macosx" || sizemode == "normal") {
is(winState.screenX, screenX, "screenX" + msgSuffix);
is(winState.screenY, screenY, "screenY" + msgSuffix);
}
is(winState.sizemode, sizemode, "sizemode should match");
}
checkCurrentState("normal");
await changeSizeMode("maximize");
checkCurrentState("maximized");
await changeSizeMode("minimize");
checkCurrentState("minimized");
// Clean up.
await BrowserTestUtils.closeWindow(win);
});