blob: 22ab0ec766a2a6df35cccd8d732374e057bd0fed [file] [log] [blame]
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +00001/*
bfulgham@apple.com355e6662015-04-30 00:29:05 +00002 * Copyright (C) 2014-2015 Apple Inc. All rights reserved.
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +00003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27
28#if ENABLE(ASYNC_SCROLLING)
29#include "AsyncScrollingCoordinator.h"
30
cdumez@apple.comb7bae2c2016-06-17 15:43:14 +000031#include "Document.h"
enrica@apple.comfd21a092014-07-22 23:28:37 +000032#include "EditorClient.h"
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +000033#include "Frame.h"
34#include "FrameView.h"
35#include "GraphicsLayer.h"
bfulgham@apple.com06c96282015-05-02 00:39:37 +000036#include "Logging.h"
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +000037#include "MainFrame.h"
38#include "Page.h"
bfulgham@apple.com355e6662015-04-30 00:29:05 +000039#include "ScrollAnimator.h"
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +000040#include "ScrollingConstraints.h"
41#include "ScrollingStateFixedNode.h"
simon.fraser@apple.com79ad80a2014-05-19 20:23:10 +000042#include "ScrollingStateFrameScrollingNode.h"
43#include "ScrollingStateOverflowScrollingNode.h"
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +000044#include "ScrollingStateStickyNode.h"
45#include "ScrollingStateTree.h"
simon.fraser@apple.comeee0f0c2016-11-09 23:41:14 +000046#include "Settings.h"
simon.fraser@apple.coma98439e2016-11-13 03:24:27 +000047#include "TextStream.h"
bfulgham@apple.com355e6662015-04-30 00:29:05 +000048#include "WheelEventTestTrigger.h"
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +000049
50namespace WebCore {
51
52AsyncScrollingCoordinator::AsyncScrollingCoordinator(Page* page)
53 : ScrollingCoordinator(page)
andersca@apple.com574a7452014-11-21 20:10:13 +000054 , m_updateNodeScrollPositionTimer(*this, &AsyncScrollingCoordinator::updateScrollPositionAfterAsyncScrollTimerFired)
weinig@apple.com2663f8f2014-12-31 20:01:02 +000055 , m_scrollingStateTree(std::make_unique<ScrollingStateTree>(this))
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +000056{
57}
58
59AsyncScrollingCoordinator::~AsyncScrollingCoordinator()
60{
61}
62
simon.fraser@apple.come5d6ecb2014-01-04 03:55:23 +000063void AsyncScrollingCoordinator::scrollingStateTreePropertiesChanged()
64{
65 scheduleTreeStateCommit();
66}
67
wenson_hsieh@apple.com70bbd212015-09-29 22:56:20 +000068static inline void setStateScrollingNodeSnapOffsetsAsFloat(ScrollingStateScrollingNode& node, ScrollEventAxis axis, const Vector<LayoutUnit>* snapOffsets, float deviceScaleFactor)
commit-queue@webkit.org4ad6b202014-08-15 21:09:13 +000069{
70 // FIXME: Incorporate current page scale factor in snapping to device pixel. Perhaps we should just convert to float here and let UI process do the pixel snapping?
71 Vector<float> snapOffsetsAsFloat;
wenson_hsieh@apple.com70bbd212015-09-29 22:56:20 +000072 if (snapOffsets) {
73 snapOffsetsAsFloat.reserveInitialCapacity(snapOffsets->size());
74 for (auto& offset : *snapOffsets)
75 snapOffsetsAsFloat.uncheckedAppend(roundToDevicePixel(offset, deviceScaleFactor, false));
76 }
commit-queue@webkit.org4ad6b202014-08-15 21:09:13 +000077 if (axis == ScrollEventAxis::Horizontal)
78 node.setHorizontalSnapOffsets(snapOffsetsAsFloat);
79 else
80 node.setVerticalSnapOffsets(snapOffsetsAsFloat);
81}
82
benjamin@webkit.org1ad546c2016-06-11 01:18:37 +000083void AsyncScrollingCoordinator::setEventTrackingRegionsDirty()
simon.fraser@apple.com79049592015-04-04 22:39:29 +000084{
benjamin@webkit.org1ad546c2016-06-11 01:18:37 +000085 m_eventTrackingRegionsDirty = true;
simon.fraser@apple.com79049592015-04-04 22:39:29 +000086 // We have to schedule a commit, but the computed non-fast region may not have actually changed.
87 scheduleTreeStateCommit();
88}
89
90void AsyncScrollingCoordinator::willCommitTree()
91{
benjamin@webkit.org1ad546c2016-06-11 01:18:37 +000092 updateEventTrackingRegions();
simon.fraser@apple.com79049592015-04-04 22:39:29 +000093}
94
benjamin@webkit.org1ad546c2016-06-11 01:18:37 +000095void AsyncScrollingCoordinator::updateEventTrackingRegions()
simon.fraser@apple.com79049592015-04-04 22:39:29 +000096{
benjamin@webkit.org1ad546c2016-06-11 01:18:37 +000097 if (!m_eventTrackingRegionsDirty)
simon.fraser@apple.com79049592015-04-04 22:39:29 +000098 return;
99
simon.fraser@apple.com8c341c42015-04-10 05:21:14 +0000100 if (!m_scrollingStateTree->rootStateNode())
101 return;
102
benjamin@webkit.org1ad546c2016-06-11 01:18:37 +0000103 m_scrollingStateTree->rootStateNode()->setEventTrackingRegions(absoluteEventTrackingRegions());
104 m_eventTrackingRegionsDirty = false;
simon.fraser@apple.com79049592015-04-04 22:39:29 +0000105}
106
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000107void AsyncScrollingCoordinator::frameViewLayoutUpdated(FrameView& frameView)
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000108{
109 ASSERT(isMainThread());
110 ASSERT(m_page);
111
112 // If there isn't a root node yet, don't do anything. We'll be called again after creating one.
113 if (!m_scrollingStateTree->rootStateNode())
114 return;
115
116 // Compute the region of the page that we can't do fast scrolling for. This currently includes
117 // all scrollable areas, such as subframes, overflow divs and list boxes. We need to do this even if the
118 // frame view whose layout was updated is not the main frame.
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000119 // In the future, we may want to have the ability to set non-fast scrolling regions for more than
120 // just the root node. But right now, this concept only applies to the root.
benjamin@webkit.org1ad546c2016-06-11 01:18:37 +0000121 m_scrollingStateTree->rootStateNode()->setEventTrackingRegions(absoluteEventTrackingRegions());
122 m_eventTrackingRegionsDirty = false;
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000123
124 if (!coordinatesScrollingForFrameView(frameView))
125 return;
126
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000127 ScrollingStateFrameScrollingNode* node = downcast<ScrollingStateFrameScrollingNode>(m_scrollingStateTree->stateNodeForID(frameView.scrollLayerID()));
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000128 if (!node)
129 return;
130
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000131 Scrollbar* verticalScrollbar = frameView.verticalScrollbar();
132 Scrollbar* horizontalScrollbar = frameView.horizontalScrollbar();
mmaxfield@apple.com9c7b0c42016-03-13 03:58:41 +0000133 node->setScrollerImpsFromScrollbars(verticalScrollbar, horizontalScrollbar);
simon.fraser@apple.com79ad80a2014-05-19 20:23:10 +0000134
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000135 node->setFrameScaleFactor(frameView.frame().frameScaleFactor());
136 node->setHeaderHeight(frameView.headerHeight());
137 node->setFooterHeight(frameView.footerHeight());
138 node->setTopContentInset(frameView.topContentInset());
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000139
simon.fraser@apple.comeee0f0c2016-11-09 23:41:14 +0000140 node->setVisualViewportEnabled(visualViewportEnabled());
141 node->setLayoutViewport(frameView.layoutViewportRect());
142 node->setMinLayoutViewportOrigin(frameView.minStableLayoutViewportOrigin());
143 node->setMaxLayoutViewportOrigin(frameView.maxStableLayoutViewportOrigin());
144
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000145 node->setScrollOrigin(frameView.scrollOrigin());
146 node->setScrollableAreaSize(frameView.visibleContentRect().size());
147 node->setTotalContentsSize(frameView.totalContentsSize());
148 node->setReachableContentsSize(frameView.totalContentsSize());
simon.fraser@apple.combf9a5d82015-04-30 23:44:49 +0000149 node->setFixedElementsLayoutRelativeToFrame(frameView.fixedElementsLayoutRelativeToFrame());
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000150
commit-queue@webkit.org4ad6b202014-08-15 21:09:13 +0000151#if ENABLE(CSS_SCROLL_SNAP)
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000152 frameView.updateSnapOffsets();
wenson_hsieh@apple.com70bbd212015-09-29 22:56:20 +0000153 updateScrollSnapPropertiesWithFrameView(frameView);
commit-queue@webkit.org4ad6b202014-08-15 21:09:13 +0000154#endif
155
bfulgham@apple.com06c96282015-05-02 00:39:37 +0000156#if PLATFORM(COCOA)
157 Page* page = frameView.frame().page();
158 if (page && page->expectsWheelEventTriggers()) {
159 LOG(WheelEventTestTriggers, " AsyncScrollingCoordinator::frameViewLayoutUpdated: Expects wheel event test trigger=%d", page->expectsWheelEventTriggers());
160 node->setExpectsWheelEventTestTrigger(page->expectsWheelEventTriggers());
161 }
162#endif
163
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000164 ScrollableAreaParameters scrollParameters;
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000165 scrollParameters.horizontalScrollElasticity = frameView.horizontalScrollElasticity();
166 scrollParameters.verticalScrollElasticity = frameView.verticalScrollElasticity();
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000167 scrollParameters.hasEnabledHorizontalScrollbar = horizontalScrollbar && horizontalScrollbar->enabled();
168 scrollParameters.hasEnabledVerticalScrollbar = verticalScrollbar && verticalScrollbar->enabled();
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000169 scrollParameters.horizontalScrollbarMode = frameView.horizontalScrollbarMode();
170 scrollParameters.verticalScrollbarMode = frameView.verticalScrollbarMode();
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000171
172 node->setScrollableAreaParameters(scrollParameters);
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000173}
174
benjamin@webkit.org1ad546c2016-06-11 01:18:37 +0000175void AsyncScrollingCoordinator::frameViewEventTrackingRegionsChanged(FrameView&)
simon.fraser@apple.com734cb1b2014-02-06 06:55:20 +0000176{
177 if (!m_scrollingStateTree->rootStateNode())
178 return;
179
benjamin@webkit.org1ad546c2016-06-11 01:18:37 +0000180 setEventTrackingRegionsDirty();
simon.fraser@apple.com734cb1b2014-02-06 06:55:20 +0000181}
182
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000183void AsyncScrollingCoordinator::frameViewRootLayerDidChange(FrameView& frameView)
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000184{
185 ASSERT(isMainThread());
186 ASSERT(m_page);
187
188 if (!coordinatesScrollingForFrameView(frameView))
189 return;
simon.fraser@apple.comd475c7f2014-05-09 02:26:22 +0000190
191 // FIXME: In some navigation scenarios, the FrameView has no RenderView or that RenderView has not been composited.
192 // This needs cleaning up: https://bugs.webkit.org/show_bug.cgi?id=132724
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000193 if (!frameView.scrollLayerID())
simon.fraser@apple.comd475c7f2014-05-09 02:26:22 +0000194 return;
195
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000196 // If the root layer does not have a ScrollingStateNode, then we should create one.
197 ensureRootStateNodeForFrameView(frameView);
198 ASSERT(m_scrollingStateTree->rootStateNode());
199
200 ScrollingCoordinator::frameViewRootLayerDidChange(frameView);
201
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000202 ScrollingStateFrameScrollingNode* node = downcast<ScrollingStateFrameScrollingNode>(m_scrollingStateTree->stateNodeForID(frameView.scrollLayerID()));
simon.fraser@apple.combb2165c2014-02-14 19:13:54 +0000203 node->setLayer(scrollLayerForFrameView(frameView));
simon.fraser@apple.com7080ea82014-05-20 19:13:14 +0000204 node->setScrolledContentsLayer(rootContentLayerForFrameView(frameView));
simon.fraser@apple.combb2165c2014-02-14 19:13:54 +0000205 node->setCounterScrollingLayer(counterScrollingLayerForFrameView(frameView));
bdakin@apple.come2e03fb2014-05-04 20:40:40 +0000206 node->setInsetClipLayer(insetClipLayerForFrameView(frameView));
bdakin@apple.comae3d31b2014-05-12 23:21:51 +0000207 node->setContentShadowLayer(contentShadowLayerForFrameView(frameView));
simon.fraser@apple.combb2165c2014-02-14 19:13:54 +0000208 node->setHeaderLayer(headerLayerForFrameView(frameView));
209 node->setFooterLayer(footerLayerForFrameView(frameView));
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000210 node->setScrollBehaviorForFixedElements(frameView.scrollBehaviorForFixedElements());
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000211}
212
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000213bool AsyncScrollingCoordinator::requestScrollPositionUpdate(FrameView& frameView, const IntPoint& scrollPosition)
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000214{
215 ASSERT(isMainThread());
216 ASSERT(m_page);
217
218 if (!coordinatesScrollingForFrameView(frameView))
219 return false;
220
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000221 bool isProgrammaticScroll = frameView.inProgrammaticScroll();
cdumez@apple.comfd6ef2a2016-09-12 19:50:50 +0000222 if (isProgrammaticScroll || frameView.frame().document()->pageCacheState() != Document::NotInPageCache)
utatane.tea@gmail.com43926962016-11-27 06:08:16 +0000223 updateScrollPositionAfterAsyncScroll(frameView.scrollLayerID(), scrollPosition, std::nullopt, isProgrammaticScroll, ScrollingLayerPositionAction::Set);
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000224
225 // If this frame view's document is being put into the page cache, we don't want to update our
226 // main frame scroll position. Just let the FrameView think that we did.
cdumez@apple.comfd6ef2a2016-09-12 19:50:50 +0000227 if (frameView.frame().document()->pageCacheState() != Document::NotInPageCache)
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000228 return true;
229
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000230 ScrollingStateScrollingNode* stateNode = downcast<ScrollingStateScrollingNode>(m_scrollingStateTree->stateNodeForID(frameView.scrollLayerID()));
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000231 if (!stateNode)
232 return false;
233
simon.fraser@apple.com61d3e782014-12-06 01:25:21 +0000234 stateNode->setRequestedScrollPosition(scrollPosition, isProgrammaticScroll);
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000235 return true;
236}
237
utatane.tea@gmail.com43926962016-11-27 06:08:16 +0000238void AsyncScrollingCoordinator::scheduleUpdateScrollPositionAfterAsyncScroll(ScrollingNodeID nodeID, const FloatPoint& scrollPosition, const std::optional<FloatPoint>& layoutViewportOrigin, bool programmaticScroll, ScrollingLayerPositionAction scrollingLayerPositionAction)
simon.fraser@apple.com7ad60ba2014-01-25 00:04:18 +0000239{
simon.fraser@apple.comeee0f0c2016-11-09 23:41:14 +0000240 ScheduledScrollUpdate scrollUpdate(nodeID, scrollPosition, layoutViewportOrigin, programmaticScroll, scrollingLayerPositionAction);
simon.fraser@apple.com7ad60ba2014-01-25 00:04:18 +0000241
simon.fraser@apple.com61d3e782014-12-06 01:25:21 +0000242 // For programmatic scrolls, requestScrollPositionUpdate() has already called updateScrollPositionAfterAsyncScroll().
243 if (programmaticScroll)
244 return;
245
simon.fraser@apple.com7ad60ba2014-01-25 00:04:18 +0000246 if (m_updateNodeScrollPositionTimer.isActive()) {
247 if (m_scheduledScrollUpdate.matchesUpdateType(scrollUpdate)) {
248 m_scheduledScrollUpdate.scrollPosition = scrollPosition;
249 return;
250 }
251
simon.fraser@apple.com2c30b1b2014-04-28 17:28:11 +0000252 // If the parameters don't match what was previously scheduled, dispatch immediately.
simon.fraser@apple.com7ad60ba2014-01-25 00:04:18 +0000253 m_updateNodeScrollPositionTimer.stop();
simon.fraser@apple.comeee0f0c2016-11-09 23:41:14 +0000254 updateScrollPositionAfterAsyncScroll(m_scheduledScrollUpdate.nodeID, m_scheduledScrollUpdate.scrollPosition, m_scheduledScrollUpdate.layoutViewportOrigin, m_scheduledScrollUpdate.isProgrammaticScroll, m_scheduledScrollUpdate.updateLayerPositionAction);
255 updateScrollPositionAfterAsyncScroll(nodeID, scrollPosition, layoutViewportOrigin, programmaticScroll, scrollingLayerPositionAction);
simon.fraser@apple.com7ad60ba2014-01-25 00:04:18 +0000256 return;
257 }
258
259 m_scheduledScrollUpdate = scrollUpdate;
260 m_updateNodeScrollPositionTimer.startOneShot(0);
261}
262
andersca@apple.com574a7452014-11-21 20:10:13 +0000263void AsyncScrollingCoordinator::updateScrollPositionAfterAsyncScrollTimerFired()
simon.fraser@apple.com7ad60ba2014-01-25 00:04:18 +0000264{
simon.fraser@apple.comeee0f0c2016-11-09 23:41:14 +0000265 updateScrollPositionAfterAsyncScroll(m_scheduledScrollUpdate.nodeID, m_scheduledScrollUpdate.scrollPosition, m_scheduledScrollUpdate.layoutViewportOrigin, m_scheduledScrollUpdate.isProgrammaticScroll, m_scheduledScrollUpdate.updateLayerPositionAction);
simon.fraser@apple.com7ad60ba2014-01-25 00:04:18 +0000266}
267
simon.fraser@apple.comc4239082014-06-10 00:37:06 +0000268FrameView* AsyncScrollingCoordinator::frameViewForScrollingNode(ScrollingNodeID scrollingNodeID) const
269{
simon.fraser@apple.com8bbf8692014-06-12 22:24:13 +0000270 if (!m_scrollingStateTree->rootStateNode())
271 return nullptr;
272
simon.fraser@apple.comc4239082014-06-10 00:37:06 +0000273 if (scrollingNodeID == m_scrollingStateTree->rootStateNode()->scrollingNodeID())
274 return m_page->mainFrame().view();
275
276 ScrollingStateNode* stateNode = m_scrollingStateTree->stateNodeForID(scrollingNodeID);
277 if (!stateNode)
278 return nullptr;
279
280 // Find the enclosing frame scrolling node.
281 ScrollingStateNode* parentNode = stateNode;
282 while (parentNode && parentNode->nodeType() != FrameScrollingNode)
283 parentNode = parentNode->parent();
284
285 if (!parentNode)
286 return nullptr;
287
288 // Walk the frame tree to find the matching FrameView. This is not ideal, but avoids back pointers to FrameViews
289 // from ScrollingTreeStateNodes.
290 for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
291 if (FrameView* view = frame->view()) {
292 if (view->scrollLayerID() == parentNode->scrollingNodeID())
293 return view;
294 }
295 }
296
297 return nullptr;
298}
299
utatane.tea@gmail.com43926962016-11-27 06:08:16 +0000300void AsyncScrollingCoordinator::updateScrollPositionAfterAsyncScroll(ScrollingNodeID scrollingNodeID, const FloatPoint& scrollPosition, std::optional<FloatPoint> layoutViewportOrigin, bool programmaticScroll, ScrollingLayerPositionAction scrollingLayerPositionAction)
simon.fraser@apple.com7ad60ba2014-01-25 00:04:18 +0000301{
302 ASSERT(isMainThread());
303
304 if (!m_page)
305 return;
306
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000307 FrameView* frameViewPtr = frameViewForScrollingNode(scrollingNodeID);
308 if (!frameViewPtr)
simon.fraser@apple.com7ad60ba2014-01-25 00:04:18 +0000309 return;
310
simon.fraser@apple.com0e87c832016-11-19 19:34:18 +0000311 LOG_WITH_STREAM(Scrolling, stream << "AsyncScrollingCoordinator::updateScrollPositionAfterAsyncScroll node " << scrollingNodeID << " scrollPosition " << scrollPosition << " action " << scrollingLayerPositionAction);
simon.fraser@apple.coma98439e2016-11-13 03:24:27 +0000312
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000313 FrameView& frameView = *frameViewPtr;
simon.fraser@apple.com543255a2014-03-31 21:23:27 +0000314
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000315 if (scrollingNodeID == frameView.scrollLayerID()) {
simon.fraser@apple.com0e87c832016-11-19 19:34:18 +0000316 reconcileScrollingState(frameView, scrollPosition, layoutViewportOrigin, programmaticScroll, true, scrollingLayerPositionAction);
simon.fraser@apple.com543255a2014-03-31 21:23:27 +0000317
bfulgham@apple.com355e6662015-04-30 00:29:05 +0000318#if PLATFORM(COCOA)
319 if (m_page->expectsWheelEventTriggers()) {
320 frameView.scrollAnimator().setWheelEventTestTrigger(m_page->testTrigger());
321 if (const auto& trigger = m_page->testTrigger())
bfulgham@apple.com06c96282015-05-02 00:39:37 +0000322 trigger->removeTestDeferralForReason(reinterpret_cast<WheelEventTestTrigger::ScrollableAreaIdentifier>(scrollingNodeID), WheelEventTestTrigger::ScrollingThreadSyncNeeded);
bfulgham@apple.com355e6662015-04-30 00:29:05 +0000323 }
324#endif
325
simon.fraser@apple.com543255a2014-03-31 21:23:27 +0000326 return;
simon.fraser@apple.com7ad60ba2014-01-25 00:04:18 +0000327 }
simon.fraser@apple.com543255a2014-03-31 21:23:27 +0000328
329 // Overflow-scroll area.
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000330 if (ScrollableArea* scrollableArea = frameView.scrollableAreaForScrollLayerID(scrollingNodeID)) {
simon.fraser@apple.com0e87c832016-11-19 19:34:18 +0000331 scrollableArea->setIsUserScroll(scrollingLayerPositionAction == ScrollingLayerPositionAction::Sync);
simon.fraser@apple.com543255a2014-03-31 21:23:27 +0000332 scrollableArea->scrollToOffsetWithoutAnimation(scrollPosition);
simon.fraser@apple.comc1a4d462014-05-06 01:10:30 +0000333 scrollableArea->setIsUserScroll(false);
simon.fraser@apple.com0e87c832016-11-19 19:34:18 +0000334 if (scrollingLayerPositionAction == ScrollingLayerPositionAction::Set)
akling@apple.com26f8fc82015-01-16 21:33:01 +0000335 m_page->editorClient().overflowScrollPositionChanged();
bfulgham@apple.com355e6662015-04-30 00:29:05 +0000336
337#if PLATFORM(COCOA)
338 if (m_page->expectsWheelEventTriggers()) {
339 frameView.scrollAnimator().setWheelEventTestTrigger(m_page->testTrigger());
340 if (const auto& trigger = m_page->testTrigger())
bfulgham@apple.com06c96282015-05-02 00:39:37 +0000341 trigger->removeTestDeferralForReason(reinterpret_cast<WheelEventTestTrigger::ScrollableAreaIdentifier>(scrollingNodeID), WheelEventTestTrigger::ScrollingThreadSyncNeeded);
bfulgham@apple.com355e6662015-04-30 00:29:05 +0000342 }
343#endif
simon.fraser@apple.comc1a4d462014-05-06 01:10:30 +0000344 }
simon.fraser@apple.com7ad60ba2014-01-25 00:04:18 +0000345}
346
simon.fraser@apple.com0e87c832016-11-19 19:34:18 +0000347void AsyncScrollingCoordinator::reconcileScrollingState(FrameView& frameView, const FloatPoint& scrollPosition, const LayoutViewportOriginOrOverrideRect& layoutViewportOriginOrOverrideRect, bool programmaticScroll, bool inStableState, ScrollingLayerPositionAction scrollingLayerPositionAction)
simon.fraser@apple.coma98439e2016-11-13 03:24:27 +0000348{
349 bool oldProgrammaticScroll = frameView.inProgrammaticScroll();
350 frameView.setInProgrammaticScroll(programmaticScroll);
351
utatane.tea@gmail.com43926962016-11-27 06:08:16 +0000352 std::optional<FloatRect> layoutViewportRect;
simon.fraser@apple.com0e87c832016-11-19 19:34:18 +0000353
simon.fraser@apple.coma98439e2016-11-13 03:24:27 +0000354 WTF::switchOn(layoutViewportOriginOrOverrideRect,
utatane.tea@gmail.com43926962016-11-27 06:08:16 +0000355 [&frameView](std::optional<FloatPoint> origin) {
simon.fraser@apple.coma98439e2016-11-13 03:24:27 +0000356 if (origin)
simon.fraser@apple.com7fded232016-11-15 21:06:06 +0000357 frameView.setBaseLayoutViewportOrigin(LayoutPoint(origin.value()), FrameView::TriggerLayoutOrNot::No);
utatane.tea@gmail.com43926962016-11-27 06:08:16 +0000358 }, [&frameView, &layoutViewportRect, inStableState, visualViewportEnabled = visualViewportEnabled()](std::optional<FloatRect> overrideRect) {
simon.fraser@apple.com0e87c832016-11-19 19:34:18 +0000359 layoutViewportRect = overrideRect;
360 if (overrideRect && inStableState) {
361 if (visualViewportEnabled)
362 frameView.setLayoutViewportOverrideRect(LayoutRect(overrideRect.value()));
simon.fraser@apple.coma98439e2016-11-13 03:24:27 +0000363#if PLATFORM(IOS)
simon.fraser@apple.com0e87c832016-11-19 19:34:18 +0000364 else
365 frameView.setCustomFixedPositionLayoutRect(enclosingIntRect(overrideRect.value()));
simon.fraser@apple.coma98439e2016-11-13 03:24:27 +0000366#endif
simon.fraser@apple.com0e87c832016-11-19 19:34:18 +0000367 }
simon.fraser@apple.coma98439e2016-11-13 03:24:27 +0000368 }
369 );
370
371 frameView.setConstrainsScrollingToContentEdge(false);
372 frameView.notifyScrollPositionChanged(roundedIntPoint(scrollPosition));
373 frameView.setConstrainsScrollingToContentEdge(true);
374 frameView.setInProgrammaticScroll(oldProgrammaticScroll);
375
simon.fraser@apple.com0e87c832016-11-19 19:34:18 +0000376 if (!programmaticScroll && scrollingLayerPositionAction != ScrollingLayerPositionAction::Set) {
377 if (inStableState)
378 reconcileViewportConstrainedLayerPositions(frameView.rectForFixedPositionLayout(), scrollingLayerPositionAction);
379 else if (layoutViewportRect)
380 reconcileViewportConstrainedLayerPositions(LayoutRect(layoutViewportRect.value()), scrollingLayerPositionAction);
381 }
simon.fraser@apple.coma98439e2016-11-13 03:24:27 +0000382
383 GraphicsLayer* scrollLayer = scrollLayerForFrameView(frameView);
384 if (!scrollLayer)
385 return;
386
387 GraphicsLayer* counterScrollingLayer = counterScrollingLayerForFrameView(frameView);
388 GraphicsLayer* insetClipLayer = insetClipLayerForFrameView(frameView);
389 GraphicsLayer* contentShadowLayer = contentShadowLayerForFrameView(frameView);
390 GraphicsLayer* scrolledContentsLayer = rootContentLayerForFrameView(frameView);
391 GraphicsLayer* headerLayer = headerLayerForFrameView(frameView);
392 GraphicsLayer* footerLayer = footerLayerForFrameView(frameView);
393
394 ASSERT(frameView.scrollPosition() == roundedIntPoint(scrollPosition));
simon.fraser@apple.com7fded232016-11-15 21:06:06 +0000395 LayoutPoint scrollPositionForFixed = frameView.scrollPositionForFixedPosition();
simon.fraser@apple.coma98439e2016-11-13 03:24:27 +0000396 float topContentInset = frameView.topContentInset();
397
398 FloatPoint positionForInsetClipLayer;
399 if (insetClipLayer)
400 positionForInsetClipLayer = FloatPoint(insetClipLayer->position().x(), FrameView::yPositionForInsetClipLayer(scrollPosition, topContentInset));
401 FloatPoint positionForContentsLayer = frameView.positionForRootContentLayer();
402
403 FloatPoint positionForHeaderLayer = FloatPoint(scrollPositionForFixed.x(), FrameView::yPositionForHeaderLayer(scrollPosition, topContentInset));
404 FloatPoint positionForFooterLayer = FloatPoint(scrollPositionForFixed.x(),
405 FrameView::yPositionForFooterLayer(scrollPosition, topContentInset, frameView.totalContentsSize().height(), frameView.footerHeight()));
406
simon.fraser@apple.com0e87c832016-11-19 19:34:18 +0000407 if (programmaticScroll || scrollingLayerPositionAction == ScrollingLayerPositionAction::Set) {
simon.fraser@apple.coma98439e2016-11-13 03:24:27 +0000408 scrollLayer->setPosition(-frameView.scrollPosition());
409 if (counterScrollingLayer)
410 counterScrollingLayer->setPosition(scrollPositionForFixed);
411 if (insetClipLayer)
412 insetClipLayer->setPosition(positionForInsetClipLayer);
413 if (contentShadowLayer)
414 contentShadowLayer->setPosition(positionForContentsLayer);
415 if (scrolledContentsLayer)
416 scrolledContentsLayer->setPosition(positionForContentsLayer);
417 if (headerLayer)
418 headerLayer->setPosition(positionForHeaderLayer);
419 if (footerLayer)
420 footerLayer->setPosition(positionForFooterLayer);
421 } else {
422 scrollLayer->syncPosition(-frameView.scrollPosition());
423 if (counterScrollingLayer)
424 counterScrollingLayer->syncPosition(scrollPositionForFixed);
425 if (insetClipLayer)
426 insetClipLayer->syncPosition(positionForInsetClipLayer);
427 if (contentShadowLayer)
428 contentShadowLayer->syncPosition(positionForContentsLayer);
429 if (scrolledContentsLayer)
430 scrolledContentsLayer->syncPosition(positionForContentsLayer);
431 if (headerLayer)
432 headerLayer->syncPosition(positionForHeaderLayer);
433 if (footerLayer)
434 footerLayer->syncPosition(positionForFooterLayer);
435 }
436}
437
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000438void AsyncScrollingCoordinator::scrollableAreaScrollbarLayerDidChange(ScrollableArea& scrollableArea, ScrollbarOrientation orientation)
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000439{
440 ASSERT(isMainThread());
441 ASSERT(m_page);
442
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000443 if (&scrollableArea != static_cast<ScrollableArea*>(m_page->mainFrame().view()))
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000444 return;
445
446 if (orientation == VerticalScrollbar)
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000447 scrollableArea.verticalScrollbarLayerDidChange();
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000448 else
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000449 scrollableArea.horizontalScrollbarLayerDidChange();
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000450}
451
452ScrollingNodeID AsyncScrollingCoordinator::attachToStateTree(ScrollingNodeType nodeType, ScrollingNodeID newNodeID, ScrollingNodeID parentID)
453{
454 return m_scrollingStateTree->attachNode(nodeType, newNodeID, parentID);
455}
456
457void AsyncScrollingCoordinator::detachFromStateTree(ScrollingNodeID nodeID)
458{
459 m_scrollingStateTree->detachNode(nodeID);
460}
461
462void AsyncScrollingCoordinator::clearStateTree()
463{
464 m_scrollingStateTree->clear();
465}
466
simon.fraser@apple.com0e87c832016-11-19 19:34:18 +0000467void AsyncScrollingCoordinator::reconcileViewportConstrainedLayerPositions(const LayoutRect& viewportRect, ScrollingLayerPositionAction action)
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000468{
469 if (!m_scrollingStateTree->rootStateNode())
470 return;
471
simon.fraser@apple.com2f1f1812014-06-18 21:43:30 +0000472 auto children = m_scrollingStateTree->rootStateNode()->children();
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000473 if (!children)
474 return;
475
simon.fraser@apple.com0e87c832016-11-19 19:34:18 +0000476 LOG_WITH_STREAM(Scrolling, stream << "AsyncScrollingCoordinator::reconcileViewportConstrainedLayerPositions for viewport rect " << viewportRect);
simon.fraser@apple.coma98439e2016-11-13 03:24:27 +0000477
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000478 // FIXME: We'll have to traverse deeper into the tree at some point.
simon.fraser@apple.comc4239082014-06-10 00:37:06 +0000479 for (auto& child : *children)
simon.fraser@apple.com0e87c832016-11-19 19:34:18 +0000480 child->reconcileLayerPositionForViewportRect(viewportRect, action);
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000481}
482
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000483void AsyncScrollingCoordinator::ensureRootStateNodeForFrameView(FrameView& frameView)
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000484{
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000485 ASSERT(frameView.scrollLayerID());
486 attachToStateTree(FrameScrollingNode, frameView.scrollLayerID(), 0);
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000487}
488
simon.fraser@apple.com7080ea82014-05-20 19:13:14 +0000489void AsyncScrollingCoordinator::updateFrameScrollingNode(ScrollingNodeID nodeID, GraphicsLayer* layer, GraphicsLayer* scrolledContentsLayer, GraphicsLayer* counterScrollingLayer, GraphicsLayer* insetClipLayer, const ScrollingGeometry* scrollingGeometry)
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000490{
cdumez@apple.com2cd7a212014-10-06 05:14:36 +0000491 ScrollingStateFrameScrollingNode* node = downcast<ScrollingStateFrameScrollingNode>(m_scrollingStateTree->stateNodeForID(nodeID));
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000492 ASSERT(node);
493 if (!node)
494 return;
495
simon.fraser@apple.combb2165c2014-02-14 19:13:54 +0000496 node->setLayer(layer);
bdakin@apple.come2e03fb2014-05-04 20:40:40 +0000497 node->setInsetClipLayer(insetClipLayer);
simon.fraser@apple.com7080ea82014-05-20 19:13:14 +0000498 node->setScrolledContentsLayer(scrolledContentsLayer);
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000499 node->setCounterScrollingLayer(counterScrollingLayer);
simon.fraser@apple.come2fcc422014-03-27 02:15:48 +0000500
simon.fraser@apple.com6cced982014-03-27 06:50:40 +0000501 if (scrollingGeometry) {
502 node->setScrollOrigin(scrollingGeometry->scrollOrigin);
503 node->setScrollPosition(scrollingGeometry->scrollPosition);
504 node->setTotalContentsSize(scrollingGeometry->contentSize);
simon.fraser@apple.comc9dc9002014-06-27 18:28:39 +0000505 node->setReachableContentsSize(scrollingGeometry->reachableContentSize);
simon.fraser@apple.com79ad80a2014-05-19 20:23:10 +0000506 node->setScrollableAreaSize(scrollingGeometry->scrollableAreaSize);
507 }
508}
509
510void AsyncScrollingCoordinator::updateOverflowScrollingNode(ScrollingNodeID nodeID, GraphicsLayer* layer, GraphicsLayer* scrolledContentsLayer, const ScrollingGeometry* scrollingGeometry)
511{
cdumez@apple.com2cd7a212014-10-06 05:14:36 +0000512 ScrollingStateOverflowScrollingNode* node = downcast<ScrollingStateOverflowScrollingNode>(m_scrollingStateTree->stateNodeForID(nodeID));
simon.fraser@apple.com79ad80a2014-05-19 20:23:10 +0000513 ASSERT(node);
514 if (!node)
515 return;
516
517 node->setLayer(layer);
518 node->setScrolledContentsLayer(scrolledContentsLayer);
519
520 if (scrollingGeometry) {
521 node->setScrollOrigin(scrollingGeometry->scrollOrigin);
522 node->setScrollPosition(scrollingGeometry->scrollPosition);
523 node->setTotalContentsSize(scrollingGeometry->contentSize);
simon.fraser@apple.comc9dc9002014-06-27 18:28:39 +0000524 node->setReachableContentsSize(scrollingGeometry->reachableContentSize);
simon.fraser@apple.com79ad80a2014-05-19 20:23:10 +0000525 node->setScrollableAreaSize(scrollingGeometry->scrollableAreaSize);
commit-queue@webkit.org4ad6b202014-08-15 21:09:13 +0000526#if ENABLE(CSS_SCROLL_SNAP)
wenson_hsieh@apple.com70bbd212015-09-29 22:56:20 +0000527 setStateScrollingNodeSnapOffsetsAsFloat(*node, ScrollEventAxis::Horizontal, &scrollingGeometry->horizontalSnapOffsets, m_page->deviceScaleFactor());
528 setStateScrollingNodeSnapOffsetsAsFloat(*node, ScrollEventAxis::Vertical, &scrollingGeometry->verticalSnapOffsets, m_page->deviceScaleFactor());
bfulgham@apple.comb10296b2015-06-19 19:24:59 +0000529 node->setCurrentHorizontalSnapPointIndex(scrollingGeometry->currentHorizontalSnapPointIndex);
530 node->setCurrentVerticalSnapPointIndex(scrollingGeometry->currentVerticalSnapPointIndex);
commit-queue@webkit.org4ad6b202014-08-15 21:09:13 +0000531#endif
simon.fraser@apple.com6cced982014-03-27 06:50:40 +0000532 }
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000533}
534
535void AsyncScrollingCoordinator::updateViewportConstrainedNode(ScrollingNodeID nodeID, const ViewportConstraints& constraints, GraphicsLayer* graphicsLayer)
536{
537 ASSERT(supportsFixedPositionLayers());
538
539 ScrollingStateNode* node = m_scrollingStateTree->stateNodeForID(nodeID);
540 if (!node)
541 return;
542
543 switch (constraints.constraintType()) {
544 case ViewportConstraints::FixedPositionConstraint: {
cdumez@apple.com2cd7a212014-10-06 05:14:36 +0000545 ScrollingStateFixedNode& fixedNode = downcast<ScrollingStateFixedNode>(*node);
546 fixedNode.setLayer(graphicsLayer);
547 fixedNode.updateConstraints((const FixedPositionViewportConstraints&)constraints);
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000548 break;
549 }
550 case ViewportConstraints::StickyPositionConstraint: {
cdumez@apple.com2cd7a212014-10-06 05:14:36 +0000551 ScrollingStateStickyNode& stickyNode = downcast<ScrollingStateStickyNode>(*node);
552 stickyNode.setLayer(graphicsLayer);
553 stickyNode.updateConstraints((const StickyPositionViewportConstraints&)constraints);
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000554 break;
555 }
556 }
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000557}
558
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000559void AsyncScrollingCoordinator::setSynchronousScrollingReasons(SynchronousScrollingReasons reasons)
560{
561 if (!m_scrollingStateTree->rootStateNode())
562 return;
563
564 // The FrameView's GraphicsLayer is likely to be out-of-synch with the PlatformLayer
565 // at this point. So we'll update it before we switch back to main thread scrolling
566 // in order to avoid layer positioning bugs.
567 if (reasons)
568 updateMainFrameScrollLayerPosition();
569 m_scrollingStateTree->rootStateNode()->setSynchronousScrollingReasons(reasons);
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000570}
571
572void AsyncScrollingCoordinator::updateMainFrameScrollLayerPosition()
573{
574 ASSERT(isMainThread());
575
576 if (!m_page)
577 return;
578
579 FrameView* frameView = m_page->mainFrame().view();
580 if (!frameView)
581 return;
582
simon.fraser@apple.com9960e2c2015-03-30 04:13:45 +0000583 if (GraphicsLayer* scrollLayer = scrollLayerForFrameView(*frameView))
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000584 scrollLayer->setPosition(-frameView->scrollPosition());
585}
586
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000587bool AsyncScrollingCoordinator::isRubberBandInProgress() const
588{
589 return scrollingTree()->isRubberBandInProgress();
590}
591
592void AsyncScrollingCoordinator::setScrollPinningBehavior(ScrollPinningBehavior pinning)
593{
594 scrollingTree()->setScrollPinningBehavior(pinning);
595}
596
simon.fraser@apple.comeee0f0c2016-11-09 23:41:14 +0000597bool AsyncScrollingCoordinator::visualViewportEnabled() const
598{
599 return m_page->mainFrame().settings().visualViewportEnabled();
600}
601
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000602String AsyncScrollingCoordinator::scrollingStateTreeAsText() const
603{
simon.fraser@apple.com79049592015-04-04 22:39:29 +0000604 if (m_scrollingStateTree->rootStateNode()) {
benjamin@webkit.org1ad546c2016-06-11 01:18:37 +0000605 if (m_eventTrackingRegionsDirty)
606 m_scrollingStateTree->rootStateNode()->setEventTrackingRegions(absoluteEventTrackingRegions());
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000607 return m_scrollingStateTree->rootStateNode()->scrollingStateTreeAsText();
simon.fraser@apple.com79049592015-04-04 22:39:29 +0000608 }
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000609
610 return String();
611}
612
bfulgham@apple.com06c96282015-05-02 00:39:37 +0000613#if PLATFORM(COCOA)
bfulgham@apple.comb2287ea2015-05-12 01:12:01 +0000614void AsyncScrollingCoordinator::setActiveScrollSnapIndices(ScrollingNodeID scrollingNodeID, unsigned horizontalIndex, unsigned verticalIndex)
615{
616 ASSERT(isMainThread());
617
618 if (!m_page)
619 return;
620
621 FrameView* frameView = frameViewForScrollingNode(scrollingNodeID);
622 if (!frameView)
623 return;
624
625 if (scrollingNodeID == frameView->scrollLayerID()) {
626 frameView->setCurrentHorizontalSnapPointIndex(horizontalIndex);
627 frameView->setCurrentVerticalSnapPointIndex(verticalIndex);
628 return;
629 }
630
631 // Overflow-scroll area.
632 if (ScrollableArea* scrollableArea = frameView->scrollableAreaForScrollLayerID(scrollingNodeID)) {
633 scrollableArea->setCurrentHorizontalSnapPointIndex(horizontalIndex);
634 scrollableArea->setCurrentVerticalSnapPointIndex(verticalIndex);
635 }
636}
637
bfulgham@apple.com06c96282015-05-02 00:39:37 +0000638void AsyncScrollingCoordinator::deferTestsForReason(WheelEventTestTrigger::ScrollableAreaIdentifier identifier, WheelEventTestTrigger::DeferTestTriggerReason reason) const
639{
bfulgham@apple.comb2287ea2015-05-12 01:12:01 +0000640 ASSERT(isMainThread());
bfulgham@apple.com06c96282015-05-02 00:39:37 +0000641 if (!m_page || !m_page->expectsWheelEventTriggers())
642 return;
643
644 if (const auto& trigger = m_page->testTrigger()) {
645 LOG(WheelEventTestTriggers, " (!) AsyncScrollingCoordinator::deferTestsForReason: Deferring %p for reason %d.", identifier, reason);
646 trigger->deferTestsForReason(identifier, reason);
647 }
648}
649
650void AsyncScrollingCoordinator::removeTestDeferralForReason(WheelEventTestTrigger::ScrollableAreaIdentifier identifier, WheelEventTestTrigger::DeferTestTriggerReason reason) const
651{
bfulgham@apple.comb2287ea2015-05-12 01:12:01 +0000652 ASSERT(isMainThread());
bfulgham@apple.com06c96282015-05-02 00:39:37 +0000653 if (!m_page || !m_page->expectsWheelEventTriggers())
654 return;
655
656 if (const auto& trigger = m_page->testTrigger()) {
657 LOG(WheelEventTestTriggers, " (!) AsyncScrollingCoordinator::removeTestDeferralForReason: Deferring %p for reason %d.", identifier, reason);
658 trigger->removeTestDeferralForReason(identifier, reason);
659 }
660}
661#endif
662
bfulgham@apple.comf5a9fff2015-05-19 21:58:30 +0000663#if ENABLE(CSS_SCROLL_SNAP)
664bool AsyncScrollingCoordinator::isScrollSnapInProgress() const
665{
666 return scrollingTree()->isScrollSnapInProgress();
667}
wenson_hsieh@apple.com70bbd212015-09-29 22:56:20 +0000668
669void AsyncScrollingCoordinator::updateScrollSnapPropertiesWithFrameView(const FrameView& frameView)
670{
671 if (auto node = downcast<ScrollingStateFrameScrollingNode>(m_scrollingStateTree->stateNodeForID(frameView.scrollLayerID()))) {
672 setStateScrollingNodeSnapOffsetsAsFloat(*node, ScrollEventAxis::Horizontal, frameView.horizontalSnapOffsets(), m_page->deviceScaleFactor());
673 setStateScrollingNodeSnapOffsetsAsFloat(*node, ScrollEventAxis::Vertical, frameView.verticalSnapOffsets(), m_page->deviceScaleFactor());
674 node->setCurrentHorizontalSnapPointIndex(frameView.currentHorizontalSnapPointIndex());
675 node->setCurrentVerticalSnapPointIndex(frameView.currentVerticalSnapPointIndex());
676 }
677}
bfulgham@apple.comf5a9fff2015-05-19 21:58:30 +0000678#endif
679
simon.fraser@apple.com6576a4b2014-01-02 19:41:45 +0000680} // namespace WebCore
681
682#endif // ENABLE(ASYNC_SCROLLING)