Title: [264203] trunk
Revision
264203
Author
[email protected]
Date
2020-07-09 16:37:38 -0700 (Thu, 09 Jul 2020)

Log Message

[macOS] Stuttery scrolling on tesla.com
https://bugs.webkit.org/show_bug.cgi?id=214159
<rdar://problem/64555500>

Reviewed by Wenson Hsieh.
Source/WebCore:

tesla.com uses scroll snapping, and also triggers layout during scrolling that could
cause scroll snap to yank the scroll position. This manifested as a change that affected
getBoundingClientRect which is used an an input to some transform math, causing the images
to move around.

Fix by ensuring that layout-triggered scroll snap does not happen if a user scroll is in progress,
when that scroll occurs via the scrolling thread. ScrollingTreeScrollingNodeDelegateMac has a
ScrollController that tracks when a gesture is in progress; push this state to
the ScrollingTree so it can be consulted from the main thread. The two subclasses
of ScrollableArea, RenderLayer and FrameView, then consult the ScrollingCoordinator
to ask whether a user scroll is in progress for their scrolling tree node.

Test: fast/scrolling/mac/adjust-scroll-snap-during-gesture.html

* page/FrameView.cpp:
(WebCore::FrameView::isUserScrollInProgress const):
* page/scrolling/AsyncScrollingCoordinator.cpp:
(WebCore::AsyncScrollingCoordinator::isUserScrollInProgress const):
* page/scrolling/AsyncScrollingCoordinator.h:
* page/scrolling/ScrollingCoordinator.h:
(WebCore::ScrollingCoordinator::isUserScrollInProgress const):
* page/scrolling/ScrollingTree.cpp:
(WebCore::ScrollingTree::handleWheelEvent):
(WebCore::ScrollingTree::isUserScrollInProgressForNode):
(WebCore::ScrollingTree::setUserScrollInProgressForNode):
(WebCore::ScrollingTree::clearNodesWithUserScrollInProgress):
* page/scrolling/ScrollingTree.h:
* page/scrolling/ScrollingTreeScrollingNode.cpp:
(WebCore::ScrollingTreeScrollingNode::isUserScrollProgress const):
(WebCore::ScrollingTreeScrollingNode::setUserScrollInProgress):
(WebCore::ScrollingTreeScrollingNode::setScrollSnapInProgress):
* page/scrolling/ScrollingTreeScrollingNode.h:
* page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm:
(WebCore::ScrollingTreeScrollingNodeDelegateMac::handleWheelEvent):
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::isUserScrollInProgress const):

LayoutTests:

* fast/scrolling/mac/adjust-scroll-snap-during-gesture-expected.txt: Added.
* fast/scrolling/mac/adjust-scroll-snap-during-gesture.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (264202 => 264203)


--- trunk/LayoutTests/ChangeLog	2020-07-09 23:04:17 UTC (rev 264202)
+++ trunk/LayoutTests/ChangeLog	2020-07-09 23:37:38 UTC (rev 264203)
@@ -1,3 +1,14 @@
+2020-07-09  Simon Fraser  <[email protected]>
+
+        [macOS] Stuttery scrolling on tesla.com
+        https://bugs.webkit.org/show_bug.cgi?id=214159
+        <rdar://problem/64555500>
+
+        Reviewed by Wenson Hsieh.
+
+        * fast/scrolling/mac/adjust-scroll-snap-during-gesture-expected.txt: Added.
+        * fast/scrolling/mac/adjust-scroll-snap-during-gesture.html: Added.
+
 2020-07-09  Chris Dumez  <[email protected]>
 
         Resync web-platform-tests/webrtc from upstream

Added: trunk/LayoutTests/fast/scrolling/mac/adjust-scroll-snap-during-gesture-expected.txt (0 => 264203)


--- trunk/LayoutTests/fast/scrolling/mac/adjust-scroll-snap-during-gesture-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/scrolling/mac/adjust-scroll-snap-during-gesture-expected.txt	2020-07-09 23:37:38 UTC (rev 264203)
@@ -0,0 +1,7 @@
+        
+PASS beforeChangeScrollLeft > 0 is true
+PASS beforeChangeScrollLeft is scroller.scrollLeft
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/scrolling/mac/adjust-scroll-snap-during-gesture.html (0 => 264203)


--- trunk/LayoutTests/fast/scrolling/mac/adjust-scroll-snap-during-gesture.html	                        (rev 0)
+++ trunk/LayoutTests/fast/scrolling/mac/adjust-scroll-snap-during-gesture.html	2020-07-09 23:37:38 UTC (rev 264203)
@@ -0,0 +1,94 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:AsyncOverflowScrollingEnabled=true ] -->
+<html>
+<head>
+    <style>
+        body {
+            height: 2000px;
+        }
+        
+        .scroller {
+            width: 620px;
+            height: 120px;
+            border: 1px solid black;
+            overflow-x: scroll;
+            scroll-snap-type: x mandatory;
+        }
+        
+        .contents {
+            width: 200%;
+        }
+        
+        .box {
+            scroll-snap-align: start;
+            width: 100px;
+            height: 100px;
+            margin: 10px;
+            background-color: blue;
+            display: inline-block;
+        }
+        
+        .scroller.changed .box {
+            width: 110px;
+        }
+        
+    </style>
+    <script src=""
+    <script src=""
+    <script>
+        var jsTestIsAsync = true;
+
+        var scroller;
+        var beforeChangeScrollLeft;
+        async function scrollTest()
+        {
+            if (!window.eventSender) {
+                finishJSTest();
+                return;
+            }
+            
+            eventSender.monitorWheelEvents();
+            eventSender.mouseMoveTo(20, 20);
+            eventSender.mouseScrollByWithWheelAndMomentumPhases(-1, 0, "began", "none");
+            eventSender.mouseScrollByWithWheelAndMomentumPhases(-20, 0, "changed", "none");
+
+            await UIHelper.waitForEvent(scroller, 'scroll');
+            await UIHelper.animationFrame();
+
+            beforeChangeScrollLeft = scroller.scrollLeft;
+            shouldBeTrue('beforeChangeScrollLeft > 0');
+
+            scroller.classList.add('changed');
+            await UIHelper.animationFrame();
+            shouldBe('beforeChangeScrollLeft', 'scroller.scrollLeft');
+
+            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 0, "ended", "none");
+            await UIHelper.waitForScrollCompletion();
+
+            finishJSTest();
+        }
+
+        window.addEventListener('load', () => {
+            scroller = document.querySelector('.scroller');
+            setTimeout(scrollTest, 0);
+        }, false);
+    </script>
+</head>
+<body>
+    <div class="scroller">
+        <div class="contents">
+            <div class="box"></div>
+            <div class="box"></div>
+            <div class="box"></div>
+            <div class="box"></div>
+            <div class="box"></div>
+            <div class="box"></div>
+            <div class="box"></div>
+            <div class="box"></div>
+            <div class="box"></div>
+            <div class="box"></div>
+        </div>
+    </div>
+    <div id="console"></div>
+    <script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (264202 => 264203)


--- trunk/Source/WebCore/ChangeLog	2020-07-09 23:04:17 UTC (rev 264202)
+++ trunk/Source/WebCore/ChangeLog	2020-07-09 23:37:38 UTC (rev 264203)
@@ -1,3 +1,48 @@
+2020-07-09  Simon Fraser  <[email protected]>
+
+        [macOS] Stuttery scrolling on tesla.com
+        https://bugs.webkit.org/show_bug.cgi?id=214159
+        <rdar://problem/64555500>
+
+        Reviewed by Wenson Hsieh.
+        
+        tesla.com uses scroll snapping, and also triggers layout during scrolling that could
+        cause scroll snap to yank the scroll position. This manifested as a change that affected
+        getBoundingClientRect which is used an an input to some transform math, causing the images
+        to move around.
+
+        Fix by ensuring that layout-triggered scroll snap does not happen if a user scroll is in progress,
+        when that scroll occurs via the scrolling thread. ScrollingTreeScrollingNodeDelegateMac has a 
+        ScrollController that tracks when a gesture is in progress; push this state to
+        the ScrollingTree so it can be consulted from the main thread. The two subclasses
+        of ScrollableArea, RenderLayer and FrameView, then consult the ScrollingCoordinator
+        to ask whether a user scroll is in progress for their scrolling tree node.
+
+        Test: fast/scrolling/mac/adjust-scroll-snap-during-gesture.html
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::isUserScrollInProgress const):
+        * page/scrolling/AsyncScrollingCoordinator.cpp:
+        (WebCore::AsyncScrollingCoordinator::isUserScrollInProgress const):
+        * page/scrolling/AsyncScrollingCoordinator.h:
+        * page/scrolling/ScrollingCoordinator.h:
+        (WebCore::ScrollingCoordinator::isUserScrollInProgress const):
+        * page/scrolling/ScrollingTree.cpp:
+        (WebCore::ScrollingTree::handleWheelEvent):
+        (WebCore::ScrollingTree::isUserScrollInProgressForNode):
+        (WebCore::ScrollingTree::setUserScrollInProgressForNode):
+        (WebCore::ScrollingTree::clearNodesWithUserScrollInProgress):
+        * page/scrolling/ScrollingTree.h:
+        * page/scrolling/ScrollingTreeScrollingNode.cpp:
+        (WebCore::ScrollingTreeScrollingNode::isUserScrollProgress const):
+        (WebCore::ScrollingTreeScrollingNode::setUserScrollInProgress):
+        (WebCore::ScrollingTreeScrollingNode::setScrollSnapInProgress):
+        * page/scrolling/ScrollingTreeScrollingNode.h:
+        * page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm:
+        (WebCore::ScrollingTreeScrollingNodeDelegateMac::handleWheelEvent):
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::isUserScrollInProgress const):
+
 2020-07-09  Chris Dumez  <[email protected]>
 
         [Bindings] Add default value support for union types in dictionary members

Modified: trunk/Source/WebCore/page/FrameView.cpp (264202 => 264203)


--- trunk/Source/WebCore/page/FrameView.cpp	2020-07-09 23:04:17 UTC (rev 264202)
+++ trunk/Source/WebCore/page/FrameView.cpp	2020-07-09 23:37:38 UTC (rev 264203)
@@ -2607,6 +2607,11 @@
 
 bool FrameView::isUserScrollInProgress() const
 {
+    if (auto scrollingCoordinator = this->scrollingCoordinator()) {
+        if (scrollingCoordinator->isUserScrollInProgress(scrollingNodeID()))
+            return true;
+    }
+
     if (auto scrollAnimator = existingScrollAnimator())
         return scrollAnimator->isUserScrollInProgress();
 

Modified: trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp (264202 => 264203)


--- trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp	2020-07-09 23:04:17 UTC (rev 264202)
+++ trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp	2020-07-09 23:37:38 UTC (rev 264203)
@@ -826,9 +826,20 @@
         m_scrollingTree->windowScreenDidChange(displayID, nominalFramesPerSecond);
 }
 
+bool AsyncScrollingCoordinator::isUserScrollInProgress(ScrollingNodeID nodeID) const
+{
+    if (m_scrollingTree)
+        return m_scrollingTree->isUserScrollInProgressForNode(nodeID);
+
+    return false;
+}
+
 bool AsyncScrollingCoordinator::isRubberBandInProgress() const
 {
-    return scrollingTree()->isRubberBandInProgress();
+    if (m_scrollingTree)
+        return m_scrollingTree->isRubberBandInProgress();
+
+    return false;
 }
 
 void AsyncScrollingCoordinator::setScrollPinningBehavior(ScrollPinningBehavior pinning)
@@ -906,7 +917,10 @@
 #if ENABLE(CSS_SCROLL_SNAP)
 bool AsyncScrollingCoordinator::isScrollSnapInProgress(ScrollingNodeID nodeID) const
 {
-    return scrollingTree()->isScrollSnapInProgressForNode(nodeID);
+    if (m_scrollingTree)
+        return m_scrollingTree->isScrollSnapInProgressForNode(nodeID);
+
+    return false;
 }
 
 void AsyncScrollingCoordinator::updateScrollSnapPropertiesWithFrameView(const FrameView& frameView)

Modified: trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.h (264202 => 264203)


--- trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.h	2020-07-09 23:04:17 UTC (rev 264202)
+++ trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.h	2020-07-09 23:37:38 UTC (rev 264203)
@@ -128,6 +128,7 @@
 
     WEBCORE_EXPORT void scrollBySimulatingWheelEventForTesting(ScrollingNodeID, FloatSize) final;
 
+    WEBCORE_EXPORT bool isUserScrollInProgress(ScrollingNodeID) const override;
     bool isRubberBandInProgress() const override;
     void setScrollPinningBehavior(ScrollPinningBehavior) override;
 

Modified: trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.h (264202 => 264203)


--- trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.h	2020-07-09 23:04:17 UTC (rev 264202)
+++ trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.h	2020-07-09 23:37:38 UTC (rev 264203)
@@ -171,6 +171,7 @@
     virtual String scrollingStateTreeAsText(ScrollingStateTreeAsTextBehavior = ScrollingStateTreeAsTextBehaviorNormal) const;
     virtual String scrollingTreeAsText(ScrollingStateTreeAsTextBehavior = ScrollingStateTreeAsTextBehaviorNormal) const;
     virtual bool isRubberBandInProgress() const { return false; }
+    virtual bool isUserScrollInProgress(ScrollingNodeID) const { return false; }
     virtual bool isScrollSnapInProgress(ScrollingNodeID) const { return false; }
     virtual void updateScrollSnapPropertiesWithFrameView(const FrameView&) { }
     virtual void setScrollPinningBehavior(ScrollPinningBehavior) { }

Modified: trunk/Source/WebCore/page/scrolling/ScrollingTree.cpp (264202 => 264203)


--- trunk/Source/WebCore/page/scrolling/ScrollingTree.cpp	2020-07-09 23:04:17 UTC (rev 264202)
+++ trunk/Source/WebCore/page/scrolling/ScrollingTree.cpp	2020-07-09 23:37:38 UTC (rev 264203)
@@ -110,8 +110,10 @@
         if (!asyncFrameOrOverflowScrollingEnabled())
             return m_rootNode->handleWheelEvent(wheelEvent);
 
-        if (m_gestureState.handleGestureCancel(wheelEvent))
+        if (m_gestureState.handleGestureCancel(wheelEvent)) {
+            clearNodesWithUserScrollInProgress();
             return WheelEventHandlingResult::handled();
+        }
 
         m_gestureState.receivedWheelEvent(wheelEvent);
 
@@ -467,6 +469,32 @@
 }
 
 // Can be called from the main thread.
+bool ScrollingTree::isUserScrollInProgressForNode(ScrollingNodeID nodeID)
+{
+    if (!nodeID)
+        return false;
+
+    LockHolder lock(m_treeStateMutex);
+    return m_treeState.nodesWithActiveUserScrolls.contains(nodeID);
+}
+    
+void ScrollingTree::setUserScrollInProgressForNode(ScrollingNodeID nodeID, bool isScrolling)
+{
+    ASSERT(nodeID);
+    LockHolder locker(m_treeStateMutex);
+    if (isScrolling)
+        m_treeState.nodesWithActiveUserScrolls.add(nodeID);
+    else
+        m_treeState.nodesWithActiveUserScrolls.remove(nodeID);
+}
+
+void ScrollingTree::clearNodesWithUserScrollInProgress()
+{
+    LockHolder locker(m_treeStateMutex);
+    m_treeState.nodesWithActiveUserScrolls.clear();
+}
+
+// Can be called from the main thread.
 bool ScrollingTree::isScrollSnapInProgressForNode(ScrollingNodeID nodeID)
 {
     if (!nodeID)

Modified: trunk/Source/WebCore/page/scrolling/ScrollingTree.h (264202 => 264203)


--- trunk/Source/WebCore/page/scrolling/ScrollingTree.h	2020-07-09 23:04:17 UTC (rev 264202)
+++ trunk/Source/WebCore/page/scrolling/ScrollingTree.h	2020-07-09 23:37:38 UTC (rev 264203)
@@ -95,8 +95,12 @@
     void setMainFrameIsRubberBanding(bool);
     bool isRubberBandInProgress();
 
+    bool isUserScrollInProgressForNode(ScrollingNodeID);
+    void setUserScrollInProgressForNode(ScrollingNodeID, bool);
+    void clearNodesWithUserScrollInProgress();
+
+    bool isScrollSnapInProgressForNode(ScrollingNodeID);
     void setNodeScrollSnapInProgress(ScrollingNodeID, bool);
-    bool isScrollSnapInProgressForNode(ScrollingNodeID);
 
     virtual void invalidate() { }
     WEBCORE_EXPORT virtual void commitTreeState(std::unique_ptr<ScrollingStateTree>&&);
@@ -246,6 +250,7 @@
         PlatformDisplayID displayID { 0 };
         Optional<unsigned> nominalFramesPerSecond;
         HashSet<ScrollingNodeID> nodesWithActiveScrollSnap;
+        HashSet<ScrollingNodeID> nodesWithActiveUserScrolls;
         bool mainFrameIsRubberBanding { false };
     };
     

Modified: trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.cpp (264202 => 264203)


--- trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.cpp	2020-07-09 23:04:17 UTC (rev 264202)
+++ trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.cpp	2020-07-09 23:37:38 UTC (rev 264203)
@@ -219,16 +219,26 @@
         || scrollPosition.y() > maxScrollPosition.y();
 }
 
-void ScrollingTreeScrollingNode::setScrollSnapInProgress(bool isSnapping)
+bool ScrollingTreeScrollingNode::isUserScrollProgress() const
 {
-    scrollingTree().setNodeScrollSnapInProgress(scrollingNodeID(), isSnapping);
+    return scrollingTree().isUserScrollInProgressForNode(scrollingNodeID());
 }
 
+void ScrollingTreeScrollingNode::setUserScrollInProgress(bool isUserScrolling)
+{
+    scrollingTree().setUserScrollInProgressForNode(scrollingNodeID(), isUserScrolling);
+}
+
 bool ScrollingTreeScrollingNode::isScrollSnapInProgress() const
 {
     return scrollingTree().isScrollSnapInProgressForNode(scrollingNodeID());
 }
 
+void ScrollingTreeScrollingNode::setScrollSnapInProgress(bool isSnapping)
+{
+    scrollingTree().setNodeScrollSnapInProgress(scrollingNodeID(), isSnapping);
+}
+
 FloatPoint ScrollingTreeScrollingNode::adjustedScrollPosition(const FloatPoint& scrollPosition, ScrollClamping clamping) const
 {
     if (clamping == ScrollClamping::Clamped)

Modified: trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.h (264202 => 264203)


--- trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.h	2020-07-09 23:04:17 UTC (rev 264202)
+++ trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.h	2020-07-09 23:37:38 UTC (rev 264203)
@@ -68,8 +68,11 @@
     RectEdges<bool> edgePinnedState() const;
     bool isRubberBanding() const;
 
+    bool isUserScrollProgress() const;
+    void setUserScrollInProgress(bool);
+
+    bool isScrollSnapInProgress() const;
     void setScrollSnapInProgress(bool);
-    bool isScrollSnapInProgress() const;
 
     // These are imperative; they adjust the scrolling layers.
     void scrollTo(const FloatPoint&, ScrollType = ScrollType::User, ScrollClamping = ScrollClamping::Clamped);

Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm (264202 => 264203)


--- trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm	2020-07-09 23:04:17 UTC (rev 264202)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm	2020-07-09 23:37:38 UTC (rev 264203)
@@ -139,7 +139,11 @@
         deferWheelEventTestCompletionForReason(reinterpret_cast<WheelEventTestMonitor::ScrollableAreaIdentifier>(scrollingNode().scrollingNodeID()), WheelEventTestMonitor::HandlingWheelEvent);
 #endif
 
+    bool wasInUserScroll = m_scrollController.isUserScrollInProgress();
     m_scrollController.updateGestureInProgressState(wheelEvent);
+    bool isInUserScroll = m_scrollController.isUserScrollInProgress();
+    if (isInUserScroll != wasInUserScroll)
+        scrollingNode().setUserScrollInProgress(isInUserScroll);
 
     // PlatformWheelEventPhaseMayBegin fires when two fingers touch the trackpad, and is used to flash overlay scrollbars.
     // We know we're scrollable at this point, so handle the event.

Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (264202 => 264203)


--- trunk/Source/WebCore/rendering/RenderLayer.cpp	2020-07-09 23:04:17 UTC (rev 264202)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp	2020-07-09 23:37:38 UTC (rev 264203)
@@ -1876,6 +1876,11 @@
     if (!scrollsOverflow())
         return false;
 
+    if (auto scrollingCoordinator = page().scrollingCoordinator()) {
+        if (scrollingCoordinator->isUserScrollInProgress(scrollingNodeID()))
+            return true;
+    }
+
     if (auto scrollAnimator = existingScrollAnimator())
         return scrollAnimator->isUserScrollInProgress();
     
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to