Title: [262996] trunk
Revision
262996
Author
[email protected]
Date
2020-06-12 23:13:12 -0700 (Fri, 12 Jun 2020)

Log Message

REGRESSION(r261985): Unable to respond to large comments on Bugzilla with always-on scrollbars
https://bugs.webkit.org/show_bug.cgi?id=213135
<rdar://problem/64302086>

Reviewed by Tim Horton.
Source/WebCore:

The combination of programmatic scrolls (e.g. anchor click, reveal selection) and user scrolling
could result in a mismatch between the main thread and scrolling thread scroll positions, resulting
in missing tiles and offset cursor handling.

This happened if a programmatic scroll occurred and 'scrolledSinceLastCommit' was true for
the equivalent scrolling node at the start of a rendering update. synchronizeStateFromScrollingTree()
would take the scrolling thread's notion of the scroll position, clobbering the position resulting
from the programmatic scroll.

To fix this, call commitTreeStateIfNeeded() before synchronizeStateFromScrollingTree() to ensure that
any programmatic scrolls have been pushed to the scrolling tree before we fetch its state.

Some infrastructure is needed for testing; getting into the state where a programmatic
scroll and 'scrolledSinceLastCommit' happened in the same event loop cycle required adding
internals.scrollBySimulatingWheelEvent(), which just pokes the scrolling tree directly
without the complexities of wheel events dispatched via the UI process.

Test: scrollingcoordinator/mac/reveal-selection-tile-coverage.html

* page/scrolling/AsyncScrollingCoordinator.cpp:
(WebCore::AsyncScrollingCoordinator::scrollBySimulatingWheelEventForTesting):
* page/scrolling/AsyncScrollingCoordinator.h:
* page/scrolling/ScrollingCoordinator.h:
(WebCore::ScrollingCoordinator::scrollBySimulatingWheelEventForTesting):
* page/scrolling/ScrollingTree.cpp:
(WebCore::ScrollingTree::scrollBySimulatingWheelEventForTesting):
* page/scrolling/ScrollingTree.h:
* page/scrolling/mac/ScrollingCoordinatorMac.mm:
(WebCore::ScrollingCoordinatorMac::willStartRenderingUpdate):
* testing/Internals.cpp:
(WebCore::Internals::scrollBySimulatingWheelEvent):
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

Test that does a fake user scroll then a programmatic scroll from a timer (i.e. outside
the rendering update), then dumps tile caches to check that coverage rects match the
right scroll position.

* scrollingcoordinator/mac/reveal-selection-tile-coverage-expected.txt: Added.
* scrollingcoordinator/mac/reveal-selection-tile-coverage.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (262995 => 262996)


--- trunk/LayoutTests/ChangeLog	2020-06-13 03:09:21 UTC (rev 262995)
+++ trunk/LayoutTests/ChangeLog	2020-06-13 06:13:12 UTC (rev 262996)
@@ -1,3 +1,18 @@
+2020-06-12  Simon Fraser  <[email protected]>
+
+        REGRESSION(r261985): Unable to respond to large comments on Bugzilla with always-on scrollbars
+        https://bugs.webkit.org/show_bug.cgi?id=213135
+        <rdar://problem/64302086>
+
+        Reviewed by Tim Horton.
+
+        Test that does a fake user scroll then a programmatic scroll from a timer (i.e. outside
+        the rendering update), then dumps tile caches to check that coverage rects match the
+        right scroll position.
+
+        * scrollingcoordinator/mac/reveal-selection-tile-coverage-expected.txt: Added.
+        * scrollingcoordinator/mac/reveal-selection-tile-coverage.html: Added.
+
 2020-06-12  Wenson Hsieh  <[email protected]>
 
         [iPadOS] Focusing selects and color inputs should not bring up the software keyboard

Added: trunk/LayoutTests/scrollingcoordinator/mac/reveal-selection-tile-coverage-expected.txt (0 => 262996)


--- trunk/LayoutTests/scrollingcoordinator/mac/reveal-selection-tile-coverage-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/scrollingcoordinator/mac/reveal-selection-tile-coverage-expected.txt	2020-06-13 06:13:12 UTC (rev 262996)
@@ -0,0 +1,22 @@
+Scroll to here
+
+(GraphicsLayer
+  (anchor 0.00 0.00)
+  (bounds 785.00 3121.00)
+  (children 1
+    (GraphicsLayer
+      (bounds 785.00 3121.00)
+      (contentsOpaque 1)
+      (tile cache coverage 0, 1024 785 x 1024)
+      (tile size 785 x 512)
+      (top left tile 0, 2 tiles grid 1 x 2)
+      (in window 1)
+    )
+  )
+)
+PASS window.pageYOffset is 0
+PASS window.pageYOffset is 1026
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/scrollingcoordinator/mac/reveal-selection-tile-coverage.html (0 => 262996)


--- trunk/LayoutTests/scrollingcoordinator/mac/reveal-selection-tile-coverage.html	                        (rev 0)
+++ trunk/LayoutTests/scrollingcoordinator/mac/reveal-selection-tile-coverage.html	2020-06-13 06:13:12 UTC (rev 262996)
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <style>
+        .filler {
+            height: 1000px;
+            width: 100px;
+            margin: 10px;
+            background-color: silver;
+        }
+    </style>
+    <script src=""
+    <script src=""
+    <script>
+        jsTestIsAsync = true;
+
+        async function scrollTest()
+        {
+            shouldBe('window.pageYOffset', '0');
+
+            if (!window.internals) {
+                finishJSTest();
+                return;
+            }
+            
+            await UIHelper.animationFrame(); // Wait for scrolling tree commit
+
+            setTimeout(async () => {
+                internals.scrollBySimulatingWheelEvent(document.scrollingElement, 0, 100);
+                window.location.href = '';
+
+                shouldBe('window.pageYOffset', '1026');
+
+                await UIHelper.animationFrame();
+
+                if (window.internals)
+                    document.getElementById('layers').innerText = internals.layerTreeAsText(document, internals.LAYER_TREE_INCLUDES_TILE_CACHES);
+
+                finishJSTest();
+            }, 0);
+        }
+
+        window.addEventListener('load', () => {
+            setTimeout(scrollTest, 0);
+        }, false);
+
+    </script>
+</head>
+<body>
+    <div class="filler"></div>
+    <p id="anchor">Scroll to here</p>
+    <div class="filler"></div>
+    <div class="filler"></div>
+<pre id="layers"></pre>
+<div id="console"></div>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (262995 => 262996)


--- trunk/Source/WebCore/ChangeLog	2020-06-13 03:09:21 UTC (rev 262995)
+++ trunk/Source/WebCore/ChangeLog	2020-06-13 06:13:12 UTC (rev 262996)
@@ -1,3 +1,45 @@
+2020-06-12  Simon Fraser  <[email protected]>
+
+        REGRESSION(r261985): Unable to respond to large comments on Bugzilla with always-on scrollbars
+        https://bugs.webkit.org/show_bug.cgi?id=213135
+        <rdar://problem/64302086>
+
+        Reviewed by Tim Horton.
+        
+        The combination of programmatic scrolls (e.g. anchor click, reveal selection) and user scrolling
+        could result in a mismatch between the main thread and scrolling thread scroll positions, resulting
+        in missing tiles and offset cursor handling.
+        
+        This happened if a programmatic scroll occurred and 'scrolledSinceLastCommit' was true for
+        the equivalent scrolling node at the start of a rendering update. synchronizeStateFromScrollingTree()
+        would take the scrolling thread's notion of the scroll position, clobbering the position resulting
+        from the programmatic scroll.
+
+        To fix this, call commitTreeStateIfNeeded() before synchronizeStateFromScrollingTree() to ensure that
+        any programmatic scrolls have been pushed to the scrolling tree before we fetch its state.
+        
+        Some infrastructure is needed for testing; getting into the state where a programmatic
+        scroll and 'scrolledSinceLastCommit' happened in the same event loop cycle required adding
+        internals.scrollBySimulatingWheelEvent(), which just pokes the scrolling tree directly
+        without the complexities of wheel events dispatched via the UI process.
+
+        Test: scrollingcoordinator/mac/reveal-selection-tile-coverage.html
+
+        * page/scrolling/AsyncScrollingCoordinator.cpp:
+        (WebCore::AsyncScrollingCoordinator::scrollBySimulatingWheelEventForTesting):
+        * page/scrolling/AsyncScrollingCoordinator.h:
+        * page/scrolling/ScrollingCoordinator.h:
+        (WebCore::ScrollingCoordinator::scrollBySimulatingWheelEventForTesting):
+        * page/scrolling/ScrollingTree.cpp:
+        (WebCore::ScrollingTree::scrollBySimulatingWheelEventForTesting):
+        * page/scrolling/ScrollingTree.h:
+        * page/scrolling/mac/ScrollingCoordinatorMac.mm:
+        (WebCore::ScrollingCoordinatorMac::willStartRenderingUpdate):
+        * testing/Internals.cpp:
+        (WebCore::Internals::scrollBySimulatingWheelEvent):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2020-06-12  David Kilzer  <[email protected]>
 
         [IPC hardening] Check enum values in IPC::Decoder::decodeEnum() an IPC::Encoder::encodeEnum()

Modified: trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp (262995 => 262996)


--- trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp	2020-06-13 03:09:21 UTC (rev 262995)
+++ trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp	2020-06-13 06:13:12 UTC (rev 262996)
@@ -531,6 +531,12 @@
 #endif
 }
 
+void AsyncScrollingCoordinator::scrollBySimulatingWheelEventForTesting(ScrollingNodeID nodeID, FloatSize delta)
+{
+    if (m_scrollingTree)
+        m_scrollingTree->scrollBySimulatingWheelEventForTesting(nodeID, delta);
+}
+
 void AsyncScrollingCoordinator::scrollableAreaScrollbarLayerDidChange(ScrollableArea& scrollableArea, ScrollbarOrientation orientation)
 {
     ASSERT(isMainThread());

Modified: trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.h (262995 => 262996)


--- trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.h	2020-06-13 03:09:21 UTC (rev 262995)
+++ trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.h	2020-06-13 06:13:12 UTC (rev 262996)
@@ -126,6 +126,8 @@
     WEBCORE_EXPORT void reconcileScrollingState(FrameView&, const FloatPoint&, const LayoutViewportOriginOrOverrideRect&, ScrollType, ViewportRectStability, ScrollingLayerPositionAction) override;
     void reconcileScrollPosition(FrameView&, ScrollingLayerPositionAction);
 
+    WEBCORE_EXPORT void scrollBySimulatingWheelEventForTesting(ScrollingNodeID, FloatSize) final;
+
     bool isRubberBandInProgress() const override;
     void setScrollPinningBehavior(ScrollPinningBehavior) override;
 

Modified: trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.h (262995 => 262996)


--- trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.h	2020-06-13 03:09:21 UTC (rev 262995)
+++ trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.h	2020-06-13 06:13:12 UTC (rev 262996)
@@ -145,6 +145,8 @@
     virtual ScrollingNodeID parentOfNode(ScrollingNodeID) const { return 0; }
     virtual Vector<ScrollingNodeID> childrenOfNode(ScrollingNodeID) const { return { }; }
 
+    virtual void scrollBySimulatingWheelEventForTesting(ScrollingNodeID, FloatSize) { }
+
     struct NodeLayers {
         GraphicsLayer* layer { nullptr };
         GraphicsLayer* scrollContainerLayer { nullptr };

Modified: trunk/Source/WebCore/page/scrolling/ScrollingTree.cpp (262995 => 262996)


--- trunk/Source/WebCore/page/scrolling/ScrollingTree.cpp	2020-06-13 03:09:21 UTC (rev 262995)
+++ trunk/Source/WebCore/page/scrolling/ScrollingTree.cpp	2020-06-13 06:13:12 UTC (rev 262996)
@@ -541,6 +541,17 @@
     return false;
 }
 
+void ScrollingTree::scrollBySimulatingWheelEventForTesting(ScrollingNodeID nodeID, FloatSize delta)
+{
+    LockHolder locker(m_treeMutex);
+
+    auto* node = nodeForID(nodeID);
+    if (!is<ScrollingTreeScrollingNode>(node))
+        return;
+
+    downcast<ScrollingTreeScrollingNode>(*node).scrollBy(delta);
+}
+
 void ScrollingTree::windowScreenDidChange(PlatformDisplayID displayID, Optional<unsigned> nominalFramesPerSecond)
 {
     LockHolder locker(m_treeStateMutex);

Modified: trunk/Source/WebCore/page/scrolling/ScrollingTree.h (262995 => 262996)


--- trunk/Source/WebCore/page/scrolling/ScrollingTree.h	2020-06-13 03:09:21 UTC (rev 262995)
+++ trunk/Source/WebCore/page/scrolling/ScrollingTree.h	2020-06-13 06:13:12 UTC (rev 262996)
@@ -193,6 +193,8 @@
     bool isMonitoringWheelEvents() const { return m_isMonitoringWheelEvents; }
     bool inCommitTreeState() const { return m_inCommitTreeState; }
 
+    void scrollBySimulatingWheelEventForTesting(ScrollingNodeID, FloatSize);
+
     virtual void lockLayersForHitTesting() { }
     virtual void unlockLayersForHitTesting() { }
 

Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm (262995 => 262996)


--- trunk/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm	2020-06-13 03:09:21 UTC (rev 262995)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm	2020-06-13 06:13:12 UTC (rev 262996)
@@ -114,6 +114,7 @@
 {
     RefPtr<ThreadedScrollingTree> threadedScrollingTree = downcast<ThreadedScrollingTree>(scrollingTree());
     threadedScrollingTree->willStartRenderingUpdate();
+    commitTreeStateIfNeeded();
     synchronizeStateFromScrollingTree();
 }
 

Modified: trunk/Source/WebCore/testing/Internals.cpp (262995 => 262996)


--- trunk/Source/WebCore/testing/Internals.cpp	2020-06-13 03:09:21 UTC (rev 262995)
+++ trunk/Source/WebCore/testing/Internals.cpp	2020-06-13 06:13:12 UTC (rev 262996)
@@ -1849,6 +1849,51 @@
     return { };
 }
 
+ExceptionOr<void> Internals::scrollBySimulatingWheelEvent(Element& element, double deltaX, double deltaY)
+{
+    Document* document = contextDocument();
+    if (!document || !document->view())
+        return Exception { InvalidAccessError };
+
+    if (!element.renderBox())
+        return Exception { InvalidAccessError };
+
+    RenderBox& box = *element.renderBox();
+    ScrollableArea* scrollableArea;
+
+    if (&element == document->scrollingElementForAPI()) {
+        FrameView* frameView = box.frame().mainFrame().view();
+        if (!frameView || !frameView->isScrollable())
+            return Exception { InvalidAccessError };
+
+        scrollableArea = frameView;
+    } else {
+        if (!box.canBeScrolledAndHasScrollableArea())
+            return Exception { InvalidAccessError };
+
+        scrollableArea = box.layer();
+    }
+    
+    if (!scrollableArea)
+        return Exception { InvalidAccessError };
+
+    auto scrollingNodeID = scrollableArea->scrollingNodeID();
+    if (!scrollingNodeID)
+        return Exception { InvalidAccessError };
+
+    auto page = document->page();
+    if (!page)
+        return Exception { InvalidAccessError };
+
+    auto scrollingCoordinator = page->scrollingCoordinator();
+    if (!scrollingCoordinator)
+        return Exception { InvalidAccessError };
+
+    scrollingCoordinator->scrollBySimulatingWheelEventForTesting(scrollingNodeID, FloatSize(deltaX, deltaY));
+
+    return { };
+}
+
 ExceptionOr<Ref<DOMRect>> Internals::layoutViewportRect()
 {
     Document* document = contextDocument();

Modified: trunk/Source/WebCore/testing/Internals.h (262995 => 262996)


--- trunk/Source/WebCore/testing/Internals.h	2020-06-13 03:09:21 UTC (rev 262995)
+++ trunk/Source/WebCore/testing/Internals.h	2020-06-13 06:13:12 UTC (rev 262996)
@@ -284,6 +284,7 @@
 
     ExceptionOr<void> setScrollViewPosition(int x, int y);
     ExceptionOr<void> unconstrainedScrollTo(Element&, double x, double y);
+    ExceptionOr<void> scrollBySimulatingWheelEvent(Element&, double deltaX, double deltaY);
 
     ExceptionOr<Ref<DOMRect>> layoutViewportRect();
     ExceptionOr<Ref<DOMRect>> visualViewportRect();

Modified: trunk/Source/WebCore/testing/Internals.idl (262995 => 262996)


--- trunk/Source/WebCore/testing/Internals.idl	2020-06-13 03:09:21 UTC (rev 262995)
+++ trunk/Source/WebCore/testing/Internals.idl	2020-06-13 06:13:12 UTC (rev 262996)
@@ -328,6 +328,9 @@
     // Like Element.scrollTo(), but without constaints, for testing rubber-banding.
     [MayThrowException] void unconstrainedScrollTo(Element element, unrestricted double x, unrestricted double y);
 
+    // Scrolls the element by the given delta, approximating the async wheel event handling code path where available.
+    [MayThrowException] void scrollBySimulatingWheelEvent(Element element, unrestricted double deltaX, unrestricted double deltaY);
+
     [MayThrowException] DOMRect layoutViewportRect();
     [MayThrowException] DOMRect visualViewportRect();
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to