Bug 784410. Don't target bubbling scroll commands at an element unless we have at least one device pixel to scroll to. r=mats
authorRobert O'Callahan <robert@ocallahan.org>
Wed, 29 Aug 2012 23:21:40 +1200
changeset 105794 17b1db7b293fdfe59b4f2b558023129b5d804cf4
parent 105793 3d7e89acf4c28738781595a4b586d0c92f31b171
child 105795 67c5a4852b9f85cb48c40ed2bf8f279b927e0a6a
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersmats
bugs784410
milestone18.0a1
Bug 784410. Don't target bubbling scroll commands at an element unless we have at least one device pixel to scroll to. r=mats
layout/base/nsLayoutUtils.cpp
layout/generic/test/Makefile.in
layout/generic/test/test_bug784410.html
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -957,23 +957,24 @@ nsLayoutUtils::GetNearestScrollableFrame
   for (nsIFrame* f = aFrame; f; f = nsLayoutUtils::GetCrossDocParentFrame(f)) {
     nsIScrollableFrame* scrollableFrame = do_QueryFrame(f);
     if (scrollableFrame) {
       nsPresContext::ScrollbarStyles ss = scrollableFrame->GetScrollbarStyles();
       uint32_t scrollbarVisibility = scrollableFrame->GetScrollbarVisibility();
       nsRect scrollRange = scrollableFrame->GetScrollRange();
       // Require visible scrollbars or something to scroll to in
       // the given direction.
+      nscoord oneDevPixel = f->PresContext()->DevPixelsToAppUnits(1);
       if (aDirection == eVertical ?
           (ss.mVertical != NS_STYLE_OVERFLOW_HIDDEN &&
            ((scrollbarVisibility & nsIScrollableFrame::VERTICAL) ||
-            scrollRange.height > 0)) :
+            scrollRange.height >= oneDevPixel)) :
           (ss.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN &&
            ((scrollbarVisibility & nsIScrollableFrame::HORIZONTAL) ||
-            scrollRange.width > 0)))
+            scrollRange.width >= oneDevPixel)))
         return scrollableFrame;
     }
   }
   return nullptr;
 }
 
 // static
 nsIScrollableFrame*
--- a/layout/generic/test/Makefile.in
+++ b/layout/generic/test/Makefile.in
@@ -96,16 +96,17 @@ MOCHITEST_FILES = \
   test_selection_splitText-normalize.html \
   test_bug524925.html \
   test_bug719503.html \
   test_bug719515.html \
   test_bug719518.html \
   test_bug719523.html \
   test_bug735641.html \
   test_bug748961.html \
+  test_bug784410.html \
   test_bug785324.html \
   $(NULL)
 
 MOCHITEST_CHROME_FILES = \
   frame_selection_underline.xhtml \
   frame_selection_underline-ref.xhtml \
   frame_selection_underline.css \
   test_selection_underline.html \
new file mode 100644
--- /dev/null
+++ b/layout/generic/test/test_bug784410.html
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test bug 784410</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<p id="display"></p>
+<div id="outer" style="overflow:auto; height:200px; border:2px dotted black;" onscroll="doneScroll()">
+  <div id="d" style="overflow:auto; height:102px;" onscroll="doneScroll()">
+    <div id="inner" style="height:100.1px; border:1px solid black; background:yellow;">Hello</div>
+  </div>
+  <div style="height:500px;"></div>
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript;version=1.7">
+var sel = window.getSelection();
+var outer = document.getElementById("outer");
+var d = document.getElementById("d");
+var inner = document.getElementById("inner");
+var smoothScrollPref = "general.smoothScroll";
+
+function innerScrollOffset() {
+  return inner.getBoundingClientRect().top - d.getBoundingClientRect().top;
+}
+var innerStartScrollOffset = innerScrollOffset();
+
+var done = false;
+function doneScroll() {
+  if (done) {
+    return;
+  }
+  done = true;
+  is(innerScrollOffset(), innerStartScrollOffset, "Inner element should not have scrolled down");
+  ok(outer.scrollTop > 0, "Outer element should have scrolled down");
+  SpecialPowers.clearUserPref(smoothScrollPref);
+  SimpleTest.finish();
+}
+
+function test() {
+  SpecialPowers.setBoolPref(smoothScrollPref, false);
+  sel.collapse(inner.firstChild, 2);
+  synthesizeKey("VK_PAGE_DOWN", {});
+}
+
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(test);
+
+</script>
+</pre>
+</body>
+</html>