Bug 851445. When saving a frame scroll position, if we're in the process of trying to scroll to a saved scroll position, save the desired position instead of the actual current position. r=mats

This commit is contained in:
Robert O'Callahan 2013-03-21 15:44:37 +13:00
parent 638906f989
commit 37411c9523
4 changed files with 53 additions and 3 deletions

View File

@ -147,6 +147,8 @@ MOCHITEST_FILES = \
file_bug842853.html \
test_bug849219.html \
test_bug851485.html \
test_bug851445.html \
bug851445_helper.html \
$(NULL)
# Tests for bugs 441782, 467672 and 570378 don't pass reliably on Windows, because of bug 469208

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<body style="height:1000px">
<script>
var docElement = document.documentElement;
docElement.style.display = 'none';
docElement.offsetTop;
docElement.style.display = '';
</script>
</body>
</html>

View File

@ -0,0 +1,34 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=851445
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 851445</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=851445">Mozilla Bug 851445</a>
<p id="display"></p>
<iframe id="f" style="width:400px; height:400px;"></iframe>
<script>
SimpleTest.waitForExplicitFinish();
function handleLoad() {
f.contentWindow.scrollTo(0,100);
function handleLoad2() {
// Verify that the scroll position was retained
is(f.contentWindow.scrollY, 100);
SimpleTest.finish();
}
f.onload = handleLoad2;
f.contentWindow.location.reload();
}
f.src = "bug851445_helper.html?" + Math.random();
f.onload = handleLoad;
</script>
</body>
</html>

View File

@ -3888,7 +3888,12 @@ nsGfxScrollFrameInner::SaveState()
}
nsPresState* state = new nsPresState();
state->SetScrollState(GetLogicalScrollPosition());
// Save mRestorePos instead of our actual current scroll position, if it's
// valid. This ensures if a reframe occurs while we're in the process
// of loading content to scroll to a restored position, we'll keep trying
// after the reframe.
nsPoint pt = mRestorePos.y == -1 ? GetLogicalScrollPosition() : mRestorePos;
state->SetScrollState(pt);
return state;
}
@ -3896,8 +3901,6 @@ void
nsGfxScrollFrameInner::RestoreState(nsPresState* aState)
{
mRestorePos = aState->GetScrollState();
mLastPos.x = -1;
mLastPos.y = -1;
mDidHistoryRestore = true;
mLastPos = mScrolledFrame ? GetLogicalScrollPosition() : nsPoint(0,0);
}