Bug 849219 - Store the scroll state also when the position is 0,0 to avoid scrolling to an #ID on reload. r=roc
authorMats Palmgren <matspal@gmail.com>
Fri, 15 Mar 2013 23:32:35 +0100
changeset 124987 a8f58efc2619aef34e3c186fad253c097aa3e1df
parent 124986 a809066fbda900d83978f7156fec99b87ce9b6c5
child 124988 6ce79dc8036bd1e104e9b259b0be6c1b2734d4fd
push id24720
push usermpalmgren@mozilla.com
push dateFri, 15 Mar 2013 22:32:16 +0000
treeherdermozilla-inbound@501804a40144 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs849219
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 849219 - Store the scroll state also when the position is 0,0 to avoid scrolling to an #ID on reload. r=roc
layout/base/tests/Makefile.in
layout/base/tests/test_bug849219.html
layout/generic/nsGfxScrollFrame.cpp
--- a/layout/base/tests/Makefile.in
+++ b/layout/base/tests/Makefile.in
@@ -141,16 +141,17 @@ MOCHITEST_FILES =	\
 		test_bug761572.html \
 		test_bug770106.html \
 		test_maxLineBoxWidth.html \
 		test_remote_frame.html \
 		test_bug842853.html \
 		test_bug842853-2.html \
 		  file_bug842853.sjs \
 		  file_bug842853.html \
+		test_bug849219.html \
 		$(NULL)
 
 # Tests for bugs 441782, 467672 and 570378 don't pass reliably on Windows, because of bug 469208
 ifeq (,$(filter windows,$(MOZ_WIDGET_TOOLKIT)))
 # THESE TESTS (BELOW) DO NOT RUN ON WINDOWS
 MOCHITEST_FILES += \
 		bidi_numeral_test.js \
 		$(NULL)
new file mode 100644
--- /dev/null
+++ b/layout/base/tests/test_bug849219.html
@@ -0,0 +1,50 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=849219
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 849219</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript">
+
+  /** Test for Bug 849219 **/
+
+SimpleTest.waitForExplicitFinish();
+
+function runTest() {
+  var win = e.contentWindow;
+  if (win.location.hash != '') {
+    is(win.scrollY,0);
+    SimpleTest.finish();
+    return;
+  }
+  win.location.hash='#anchor'
+  win.scrollTo(0,0);
+  win.location.reload()
+}
+
+
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=849219">Mozilla Bug 849219</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+<script>
+
+var e = document.createElement('iframe');
+var url = 'data:text/html,<a href="%23anchor">Click to scroll to anchor</a><div style="height:5000px"></div><a name="anchor">FAIL</a>'
+e.setAttribute('src',url);
+e.setAttribute('onload','runTest()');
+document.body.appendChild(e);
+
+</script>
+</body>
+</html>
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -3881,26 +3881,18 @@ nsPresState*
 nsGfxScrollFrameInner::SaveState()
 {
   nsIScrollbarMediator* mediator = do_QueryFrame(GetScrolledFrame());
   if (mediator) {
     // child handles its own scroll state, so don't bother saving state here
     return nullptr;
   }
 
-  nsPoint scrollPos = GetLogicalScrollPosition();
-  // Don't save scroll position if we are at (0,0)
-  if (scrollPos == nsPoint(0,0)) {
-    return nullptr;
-  }
-
   nsPresState* state = new nsPresState();
-
-  state->SetScrollState(scrollPos);
-
+  state->SetScrollState(GetLogicalScrollPosition());
   return state;
 }
 
 void
 nsGfxScrollFrameInner::RestoreState(nsPresState* aState)
 {
   mRestorePos = aState->GetScrollState();
   mLastPos.x = -1;