Refactor ScrollingCoordinator::setSynchronousScrollingReasons to accept a FrameView
https://bugs.webkit.org/show_bug.cgi?id=171923

Patch by Frederic Wang <fwang@igalia.com> on 2017-05-10
Reviewed by Simon Fraser.

Currently ScrollingCoordinator::setSynchronousScrollingReasons implementations assumes
SynchronousScrollingReasons apply to the main frame. This commit allows to specify
a FrameView in order to prepare support for fast scrolling of frames.

No new tests, no behavior changes.

* page/scrolling/AsyncScrollingCoordinator.cpp:
(WebCore::AsyncScrollingCoordinator::setSynchronousScrollingReasons): Use the FrameView to
find the state node.
(WebCore::AsyncScrollingCoordinator::updateScrollLayerPosition): Rename this function
updateMainFrameScrollLayerPosition and use the specified FrameView.
* page/scrolling/AsyncScrollingCoordinator.h: Add FrameView parameter.
* page/scrolling/ScrollingCoordinator.cpp:
(WebCore::ScrollingCoordinator::updateSynchronousScrollingReasons): Remove the const since
AsyncScrollingCoordinator uses scrollLayerForFrameView. Pass the frameView to
setSynchronousScrollingReasons.
* page/scrolling/ScrollingCoordinator.h:
(WebCore::ScrollingCoordinator::setSynchronousScrollingReasons): Add FrameView parameter.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@216592 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 960b81a..601ef51 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,29 @@
+2017-05-10  Frederic Wang  <fwang@igalia.com>
+
+        Refactor ScrollingCoordinator::setSynchronousScrollingReasons to accept a FrameView
+        https://bugs.webkit.org/show_bug.cgi?id=171923
+
+        Reviewed by Simon Fraser.
+
+        Currently ScrollingCoordinator::setSynchronousScrollingReasons implementations assumes
+        SynchronousScrollingReasons apply to the main frame. This commit allows to specify
+        a FrameView in order to prepare support for fast scrolling of frames.
+
+        No new tests, no behavior changes.
+
+        * page/scrolling/AsyncScrollingCoordinator.cpp:
+        (WebCore::AsyncScrollingCoordinator::setSynchronousScrollingReasons): Use the FrameView to
+        find the state node.
+        (WebCore::AsyncScrollingCoordinator::updateScrollLayerPosition): Rename this function
+        updateMainFrameScrollLayerPosition and use the specified FrameView.
+        * page/scrolling/AsyncScrollingCoordinator.h: Add FrameView parameter.
+        * page/scrolling/ScrollingCoordinator.cpp:
+        (WebCore::ScrollingCoordinator::updateSynchronousScrollingReasons): Remove the const since
+        AsyncScrollingCoordinator uses scrollLayerForFrameView. Pass the frameView to
+        setSynchronousScrollingReasons.
+        * page/scrolling/ScrollingCoordinator.h:
+        (WebCore::ScrollingCoordinator::setSynchronousScrollingReasons): Add FrameView parameter.
+
 2017-05-10  Antti Koivisto  <antti@apple.com>
 
         REGRESSION (r207372) Visibility property is not inherited when used in an animation
diff --git a/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp b/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp
index 769cd28..a2feb3e 100644
--- a/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp
+++ b/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp
@@ -581,32 +581,25 @@
     }
 }
 
-void AsyncScrollingCoordinator::setSynchronousScrollingReasons(SynchronousScrollingReasons reasons)
+void AsyncScrollingCoordinator::setSynchronousScrollingReasons(FrameView& frameView, SynchronousScrollingReasons reasons)
 {
-    if (!m_scrollingStateTree->rootStateNode())
+    ScrollingStateFrameScrollingNode* scrollingStateNode = static_cast<ScrollingStateFrameScrollingNode*>(m_scrollingStateTree->stateNodeForID(frameView.scrollLayerID()));
+    if (!scrollingStateNode)
         return;
 
     // The FrameView's GraphicsLayer is likely to be out-of-synch with the PlatformLayer
     // at this point. So we'll update it before we switch back to main thread scrolling
     // in order to avoid layer positioning bugs.
     if (reasons)
-        updateMainFrameScrollLayerPosition();
-    m_scrollingStateTree->rootStateNode()->setSynchronousScrollingReasons(reasons);
+        updateScrollLayerPosition(frameView);
+    scrollingStateNode->setSynchronousScrollingReasons(reasons);
 }
 
-void AsyncScrollingCoordinator::updateMainFrameScrollLayerPosition()
+void AsyncScrollingCoordinator::updateScrollLayerPosition(FrameView& frameView)
 {
     ASSERT(isMainThread());
-
-    if (!m_page)
-        return;
-
-    FrameView* frameView = m_page->mainFrame().view();
-    if (!frameView)
-        return;
-
-    if (GraphicsLayer* scrollLayer = scrollLayerForFrameView(*frameView))
-        scrollLayer->setPosition(-frameView->scrollPosition());
+    if (GraphicsLayer* scrollLayer = scrollLayerForFrameView(frameView))
+        scrollLayer->setPosition(-frameView.scrollPosition());
 }
 
 bool AsyncScrollingCoordinator::isRubberBandInProgress() const
diff --git a/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.h b/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.h
index 99c2033..4f20871 100644
--- a/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.h
+++ b/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.h
@@ -115,12 +115,12 @@
     WEBCORE_EXPORT void reconcileViewportConstrainedLayerPositions(const LayoutRect& viewportRect, ScrollingLayerPositionAction) override;
     WEBCORE_EXPORT void scrollableAreaScrollbarLayerDidChange(ScrollableArea&, ScrollbarOrientation) override;
 
-    WEBCORE_EXPORT void setSynchronousScrollingReasons(SynchronousScrollingReasons) override;
+    WEBCORE_EXPORT void setSynchronousScrollingReasons(FrameView&, SynchronousScrollingReasons) final;
 
     virtual void scheduleTreeStateCommit() = 0;
 
     void ensureRootStateNodeForFrameView(FrameView&);
-    void updateMainFrameScrollLayerPosition();
+    void updateScrollLayerPosition(FrameView&);
 
     void updateScrollPositionAfterAsyncScrollTimerFired();
     void setEventTrackingRegionsDirty();
diff --git a/Source/WebCore/page/scrolling/ScrollingCoordinator.cpp b/Source/WebCore/page/scrolling/ScrollingCoordinator.cpp
index 1d9e423..6dbd3a8 100644
--- a/Source/WebCore/page/scrolling/ScrollingCoordinator.cpp
+++ b/Source/WebCore/page/scrolling/ScrollingCoordinator.cpp
@@ -343,14 +343,14 @@
     return synchronousScrollingReasons;
 }
 
-void ScrollingCoordinator::updateSynchronousScrollingReasons(const FrameView& frameView)
+void ScrollingCoordinator::updateSynchronousScrollingReasons(FrameView& frameView)
 {
     // FIXME: Once we support async scrolling of iframes, we'll have to track the synchronous scrolling
     // reasons per frame (maybe on scrolling tree nodes).
     if (!frameView.frame().isMainFrame())
         return;
 
-    setSynchronousScrollingReasons(synchronousScrollingReasons(frameView));
+    setSynchronousScrollingReasons(frameView, synchronousScrollingReasons(frameView));
 }
 
 void ScrollingCoordinator::setForceSynchronousScrollLayerPositionUpdates(bool forceSynchronousScrollLayerPositionUpdates)
diff --git a/Source/WebCore/page/scrolling/ScrollingCoordinator.h b/Source/WebCore/page/scrolling/ScrollingCoordinator.h
index 381785f..56b0993 100644
--- a/Source/WebCore/page/scrolling/ScrollingCoordinator.h
+++ b/Source/WebCore/page/scrolling/ScrollingCoordinator.h
@@ -234,10 +234,10 @@
     Page* m_page; // FIXME: ideally this would be a reference but it gets nulled on async teardown.
 
 private:
-    virtual void setSynchronousScrollingReasons(SynchronousScrollingReasons) { }
+    virtual void setSynchronousScrollingReasons(FrameView&, SynchronousScrollingReasons) { }
 
     virtual bool hasVisibleSlowRepaintViewportConstrainedObjects(const FrameView&) const;
-    void updateSynchronousScrollingReasons(const FrameView&);
+    void updateSynchronousScrollingReasons(FrameView&);
 
     EventTrackingRegions absoluteEventTrackingRegionsForFrame(const Frame&) const;