Coordinates-based snap offsets don't update correctly when container is scrolled
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Jul 2015 04:24:12 +0000 (04:24 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Jul 2015 04:24:12 +0000 (04:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=147215

Reviewed by Brent Fulgham.

Source/WebCore:

Fixes the way we append the snap offsets of child elements with coordinates. We
now consider the scroll offset of the parent scroll snapping container, so snap
offset recomputations don't fail on scroll snapping containers.

Test: css3/scroll-snap/scroll-snap-coordinate-overflow-resize.html

* page/scrolling/AxisScrollSnapOffsets.cpp:
(WebCore::appendChildSnapOffsets): Fixed to consider the scroll offset of the
    parent container.

LayoutTests:

Tests that snap offsets update properly on scrolled containers.

* css3/scroll-snap/scroll-snap-coordinate-overflow-resize-expected.txt: Added.
* css3/scroll-snap/scroll-snap-coordinate-overflow-resize.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@187210 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/css3/scroll-snap/scroll-snap-coordinate-overflow-resize-expected.txt [new file with mode: 0644]
LayoutTests/css3/scroll-snap/scroll-snap-coordinate-overflow-resize.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/scrolling/AxisScrollSnapOffsets.cpp

index 0eb3acd..076fcb2 100644 (file)
@@ -1,3 +1,15 @@
+2015-07-22  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Coordinates-based snap offsets don't update correctly when container is scrolled
+        https://bugs.webkit.org/show_bug.cgi?id=147215
+
+        Reviewed by Brent Fulgham.
+
+        Tests that snap offsets update properly on scrolled containers.
+
+        * css3/scroll-snap/scroll-snap-coordinate-overflow-resize-expected.txt: Added.
+        * css3/scroll-snap/scroll-snap-coordinate-overflow-resize.html: Added.
+
 2015-07-22  Myles C. Maxfield  <mmaxfield@apple.com>
 
         [El Capitan] Test Gardening
diff --git a/LayoutTests/css3/scroll-snap/scroll-snap-coordinate-overflow-resize-expected.txt b/LayoutTests/css3/scroll-snap/scroll-snap-coordinate-overflow-resize-expected.txt
new file mode 100644 (file)
index 0000000..ec2f0aa
--- /dev/null
@@ -0,0 +1,9 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+Scroll-snap offsets: vertical = { 0, 400, 800, 1200, 1600, 2000 }
+Scroll-snap offsets: vertical = { 0, 400, 800, 1200, 1600, 2000 }
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/css3/scroll-snap/scroll-snap-coordinate-overflow-resize.html b/LayoutTests/css3/scroll-snap/scroll-snap-coordinate-overflow-resize.html
new file mode 100644 (file)
index 0000000..0d9e3a9
--- /dev/null
@@ -0,0 +1,60 @@
+<html>
+
+<head>
+    <style>
+        #container {
+            width: 420px;
+            height: 400px;
+            overflow-y: scroll;
+            -webkit-scroll-snap-type: mandatory;
+        }
+
+        .cell {
+            width: 400px;
+            height: 400px;
+            -webkit-scroll-snap-coordinate: 0% 0%;
+        }
+    </style>
+    <script src="../../resources/js-test-pre.js"></script>
+    <script>
+    function setup()
+    {
+        var container = document.getElementById("container");
+
+        function dumpSnapOffsetsAndFinishTest()
+        {
+            debug("Scroll-snap offsets: " + window.internals.scrollSnapOffsets(container));
+            finishJSTest();
+        }
+
+        function dumpSnapOffsetsAndResizeElement()
+        {
+            debug("Scroll-snap offsets: " + window.internals.scrollSnapOffsets(container));
+            container.style.width = "425px";
+            setTimeout(dumpSnapOffsetsAndFinishTest, 0);
+        }
+
+        container.scrollTop = 800;
+        if (window.testRunner) {
+            window.jsTestIsAsync = true;
+            testRunner.dumpAsText();
+            testRunner.waitUntilDone();
+            setTimeout(dumpSnapOffsetsAndResizeElement, 0);
+        }
+    }
+    </script>
+</head>
+
+<body onload="setup()">
+    <div id="container">
+        <div class="cell"><div id="console"></div></div>
+        <div class="cell"></div>
+        <div class="cell"></div>
+        <div class="cell"></div>
+        <div class="cell"></div>
+        <div class="cell"></div>
+    </div>
+    <script src="../../resources/js-test-post.js"></script>
+</body>
+
+</html>
index 5ff1e07..4b37fec 100644 (file)
@@ -1,3 +1,20 @@
+2015-07-22  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Coordinates-based snap offsets don't update correctly when container is scrolled
+        https://bugs.webkit.org/show_bug.cgi?id=147215
+
+        Reviewed by Brent Fulgham.
+
+        Fixes the way we append the snap offsets of child elements with coordinates. We
+        now consider the scroll offset of the parent scroll snapping container, so snap
+        offset recomputations don't fail on scroll snapping containers.
+
+        Test: css3/scroll-snap/scroll-snap-coordinate-overflow-resize.html
+
+        * page/scrolling/AxisScrollSnapOffsets.cpp:
+        (WebCore::appendChildSnapOffsets): Fixed to consider the scroll offset of the
+            parent container.
+
 2015-07-22  Matthew Daiter  <mdaiter@apple.com>
 
         Needed to add methods to get PreviewCaptureLayers from Video
index f6d4a40..81d1e97 100644 (file)
@@ -60,7 +60,7 @@ static void appendChildSnapOffsets(HTMLElement& parent, bool shouldAddHorizontal
             continue;
         
         LayoutRect viewSize = box->contentBoxRect();
-        FloatPoint position = box->localToContainerPoint(FloatPoint(), parent.renderBox());
+        FloatPoint position = box->localToContainerPoint(FloatPoint(parent.renderBox()->scrollLeft(), parent.renderBox()->scrollTop()), parent.renderBox());
         for (auto& coordinate : scrollSnapCoordinates) {
             LayoutUnit lastPotentialSnapPositionX = position.x() + valueForLength(coordinate.width(), viewSize.width());
             if (shouldAddHorizontalChildOffsets && lastPotentialSnapPositionX > 0)