Bug 1538762 - Ensure the Android session store respects the layout scroll range. r=kats

Differential Revision: https://phabricator.services.mozilla.com/D25144

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Botond Ballo 2019-03-28 00:38:19 +00:00
parent 72f3e593fd
commit cba0362f99
2 changed files with 19 additions and 4 deletions

View File

@ -352,9 +352,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1498892
checkScroll(browser, testData);
// Check that the layout scroll range is still respected.
// TODO: This should start passing after bug 1516056 is fixed.
todo_is(browser.contentWindow.scrollX, 0, "Layout scroll range should be respected");
todo_is(browser.contentWindow.scrollY, 0, "Layout scroll range should be respected");
is(browser.contentWindow.scrollX, 0, "Layout scroll range should be respected");
is(browser.contentWindow.scrollY, 0, "Layout scroll range should be respected");
// Now go back in history and check that the scroll position
// is restored there as well.

View File

@ -287,7 +287,23 @@ void SessionStoreUtils::RestoreScrollPosition(const GlobalObject& aGlobal,
int pos_X = atoi(token.get());
token = tokenizer.nextToken();
int pos_Y = atoi(token.get());
aWindow.ScrollTo(pos_X, pos_Y);
// Self-clamp the layout scroll position to the layout scroll range.
// This step will be unnecessary after bug 1516056, when window.scrollTo()
// will start performing this clamping itself.
CSSCoord layoutPosX = pos_X;
CSSCoord layoutPosY = pos_Y;
ErrorResult rv;
CSSCoord layoutPosMaxX = aWindow.GetScrollMaxX(rv);
CSSCoord layoutPosMaxY = aWindow.GetScrollMaxY(rv);
if (layoutPosX > layoutPosMaxX) {
layoutPosX = layoutPosMaxX;
}
if (layoutPosY > layoutPosMaxY) {
layoutPosY = layoutPosMaxY;
}
aWindow.ScrollTo(layoutPosX, layoutPosY);
if (nsCOMPtr<Document> doc = aWindow.GetExtantDoc()) {
if (nsPresContext* presContext = doc->GetPresContext()) {