Scroll snap logic should be triggered when resizing the WebView
https://bugs.webkit.org/show_bug.cgi?id=142590
<rdar://problem/20125088>
Reviewed by Simon Fraser.
Source/WebCore:
Tests coming in a second patch.
Resizing of the main frame or overflow regions was properly recalculating the scroll snap points,
but there was no code to honor these values when window resizing was occurring. The correction was
handled in two ways:
1. Scrolling thread operations that moved to new snap points needed to notify the main thread that
it had shifted to a new snap point, so that the resize code (which happens on the main thread)
could ensure that we stayed clamped to the correct 'tile' in the snap region.
2. Main thread (overflow) resizes were likewise missing code to honor the current snap position
after resizing calculations were complete.
This change also required the addition of two indices to the scrollable area to track which scroll
snap point was currently being used. We don't bother with a 'none' case because you cannot have a
'none' state when you have an active set of scroll snap points, and we do not execute this code
if the scroll snap points are null.
The FrameView code was computing updated snap offsets after it had dispatched frame view layout
information to the scrolling thread, which was wrong. This was also corrected.
I think it might be possible to track all of this state inside the ScrollController, but the current
scroll snap architecture destroys and recreates the state each time a new set of interactions starts.
This should be fixed in the future, which would allow us to remove some of this local state.
* page/FrameView.cpp:
(WebCore::FrameView::performPostLayoutTasks): Make sure 'updateSnapOffsets' is called prior to
calling 'frameViewLayoutUpdated' so the scrolling thread gets correct updated points. Add a new
call to 'scrollToNearestActiveSnapPoint', which will keep us on our current snap point during
resize (if appropriate).
* page/scrolling/AsyncScrollingCoordinator.cpp:
(WebCore::AsyncScrollingCoordinator::updateScrollSnapOffsetIndices): Added. This finds and notifies
the correct scroll region when a new snap position (index) has been selected by user interaction on
the scrolling thread.
(WebCore::AsyncScrollingCoordinator::deferTestsForReason): Added an assertion for 'isMainThread'.
(WebCore::AsyncScrollingCoordinator::removeTestDeferralForReason): Ditto.
* page/scrolling/AsyncScrollingCoordinator.h:
* page/scrolling/AxisScrollSnapOffsets.h:
(WebCore::closestSnapOffset): Modified to also return the selected snap point index so we can track
it to handle resize operations.
* page/scrolling/ScrollingTree.h:
(WebCore::ScrollingTree::updateScrollSnapOffsetIndices):
* page/scrolling/ThreadedScrollingTree.cpp:
(WebCore::ThreadedScrollingTree::updateScrollSnapOffsetIndices): Added method to dispatch the active
horizontal and vertical scroll snap indices back to the main thread.
* page/scrolling/ThreadedScrollingTree.h:
* page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:
(WebCore::ScrollingTreeFrameScrollingNodeMac::handleWheelEvent): After the scroll controller processes
the current event, notify the main thread of any change in the active scroll snap index.
* platform/ScrollAnimator.cpp:
(WebCore::ScrollAnimator::activeScrollSnapOffsetIndexDidChange): Added method to allow ScrollAnimator
clients to find out about the current scroll snap state, which is only known by the ScrollController.
(WebCore::ScrollAnimator::activeScrollSnapOffsetIndexForAxis): Ditto.
* platform/ScrollAnimator.h:
* platform/ScrollView.cpp:
(WebCore::ScrollView::scrollToNearestActiveSnapPoint): Added method that allows us to set scroll position
to one of our active scroll snap offsets.
* platform/ScrollView.h:
* platform/ScrollableArea.cpp:
(WebCore::ScrollableArea::handleWheelEvent): If the active scroll snap offset has changed, make sure we
keep track of the new values for potential resize operations.
(WebCore::ScrollableArea::clearHorizontalSnapOffsets): Make sure to also clear out the current snap index.
(WebCore::ScrollableArea::clearVerticalSnapOffsets): Ditto.
(WebCore::ScrollableArea::nearestActiveSnapPoint): New method that returns an updated IntPoint reflecting
the proper scroll position based on the active scroll snap offset.
* platform/ScrollableArea.h:
(WebCore::ScrollableArea::currentHorizontalSnapPointIndex): Added.
(WebCore::ScrollableArea::setCurrentHorizontalSnapPointIndex): Added.
(WebCore::ScrollableArea::currentVerticalSnapPointIndex): Added.
(WebCore::ScrollableArea::setCurrentVerticalSnapPointIndex): Added.
(WebCore::ScrollableArea::scrollToNearestActiveSnapPoint): Added.
* platform/cocoa/ScrollController.h:
(WebCore::ScrollControllerClient::activeScrollOffsetIndex): Added new method for clients to implement.
(WebCore::ScrollController::activeScrollSnapOffsetIndexDidChange): Added.
(WebCore::ScrollController::setScrollSnapOffsetIndexDidChange): Added.
* platform/cocoa/ScrollController.mm:
(WebCore::ScrollController::activeScrollSnapOffsetIndexForAxis): Helper method to return current active
index (if applicable).
(WebCore::ScrollController::setActiveScrollSnapOffsetIndexForAxis): Helper function to safely set
the current active index.
(WebCore::ScrollController::beginScrollSnapAnimation): Updated to keep track of the new active scroll snap
index, as well as whether the current animation actually changed the active snap point offset.
* platform/cocoa/ScrollSnapAnimatorState.h: Revise to use modern C++ initializers, and to track a new index
that represents the current scroll snap offset.
* platform/cocoa/ScrollSnapAnimatorState.mm:
(WebCore::ScrollSnapAnimatorState::ScrollSnapAnimatorState): Update for modern C++ syntax.
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::scrollToNearestActiveSnapPoint): New method to set scroll position to be one of our
active scroll snap points.
(WebCore::RenderLayer::updateScrollInfoAfterLayout): Add a new call to 'scrollToNearestActiveSnapPoint' so that
we stay on the current scroll snap offset during resizing.
* rendering/RenderLayer.h:
Source/WebKit2:
* UIProcess/ios/RemoteScrollingCoordinatorProxyIOS.mm:
(RemoteScrollingCoordinatorProxy::closestSnapOffsetForMainFrameScrolling): Modify use of 'closestSnapOffset' to satisfy the additional
argument I added. This is currently not used for anything on iOS.
* UIProcess/Scrolling/ios/ScrollingTreeOverflowScrollingNodeIOS.mm: Ditto.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@184139 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp b/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp
index eccf413..b4d6422 100644
--- a/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp
+++ b/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp
@@ -562,8 +562,33 @@
}
#if PLATFORM(COCOA)
+void AsyncScrollingCoordinator::setActiveScrollSnapIndices(ScrollingNodeID scrollingNodeID, unsigned horizontalIndex, unsigned verticalIndex)
+{
+ ASSERT(isMainThread());
+
+ if (!m_page)
+ return;
+
+ FrameView* frameView = frameViewForScrollingNode(scrollingNodeID);
+ if (!frameView)
+ return;
+
+ if (scrollingNodeID == frameView->scrollLayerID()) {
+ frameView->setCurrentHorizontalSnapPointIndex(horizontalIndex);
+ frameView->setCurrentVerticalSnapPointIndex(verticalIndex);
+ return;
+ }
+
+ // Overflow-scroll area.
+ if (ScrollableArea* scrollableArea = frameView->scrollableAreaForScrollLayerID(scrollingNodeID)) {
+ scrollableArea->setCurrentHorizontalSnapPointIndex(horizontalIndex);
+ scrollableArea->setCurrentVerticalSnapPointIndex(verticalIndex);
+ }
+}
+
void AsyncScrollingCoordinator::deferTestsForReason(WheelEventTestTrigger::ScrollableAreaIdentifier identifier, WheelEventTestTrigger::DeferTestTriggerReason reason) const
{
+ ASSERT(isMainThread());
if (!m_page || !m_page->expectsWheelEventTriggers())
return;
@@ -575,6 +600,7 @@
void AsyncScrollingCoordinator::removeTestDeferralForReason(WheelEventTestTrigger::ScrollableAreaIdentifier identifier, WheelEventTestTrigger::DeferTestTriggerReason reason) const
{
+ ASSERT(isMainThread());
if (!m_page || !m_page->expectsWheelEventTriggers())
return;