acd2df225eb3fcd4f80c60dc97a6f1ee710f591f
[WebKit-https.git] / Source / WebCore / page / scrolling / AsyncScrollingCoordinator.cpp
1 /*
2  * Copyright (C) 2014 Apple Inc. All rights reserved.
3  *
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
31 #include "EditorClient.h"
32 #include "Frame.h"
33 #include "FrameView.h"
34 #include "GraphicsLayer.h"
35 #include "MainFrame.h"
36 #include "Page.h"
37 #include "ScrollingConstraints.h"
38 #include "ScrollingStateFixedNode.h"
39 #include "ScrollingStateFrameScrollingNode.h"
40 #include "ScrollingStateOverflowScrollingNode.h"
41 #include "ScrollingStateStickyNode.h"
42 #include "ScrollingStateTree.h"
43
44 namespace WebCore {
45
46 AsyncScrollingCoordinator::AsyncScrollingCoordinator(Page* page)
47     : ScrollingCoordinator(page)
48     , m_updateNodeScrollPositionTimer(this, &AsyncScrollingCoordinator::updateScrollPositionAfterAsyncScrollTimerFired)
49     , m_scrollingStateTree(ScrollingStateTree::create(this))
50 {
51 }
52
53 AsyncScrollingCoordinator::~AsyncScrollingCoordinator()
54 {
55 }
56
57 void AsyncScrollingCoordinator::scrollingStateTreePropertiesChanged()
58 {
59     scheduleTreeStateCommit();
60 }
61
62 static inline void setStateScrollingNodeSnapOffsetsAsFloat(ScrollingStateScrollingNode& node, ScrollEventAxis axis, const Vector<LayoutUnit>& snapOffsets, float deviceScaleFactor)
63 {
64     // 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?
65     Vector<float> snapOffsetsAsFloat;
66     snapOffsetsAsFloat.reserveInitialCapacity(snapOffsets.size());
67     for (size_t i = 0; i < snapOffsets.size(); ++i)
68         snapOffsetsAsFloat.append(roundToDevicePixel(snapOffsets[i], deviceScaleFactor, false));
69
70     if (axis == ScrollEventAxis::Horizontal)
71         node.setHorizontalSnapOffsets(snapOffsetsAsFloat);
72     else
73         node.setVerticalSnapOffsets(snapOffsetsAsFloat);
74 }
75
76 void AsyncScrollingCoordinator::frameViewLayoutUpdated(FrameView* frameView)
77 {
78     ASSERT(isMainThread());
79     ASSERT(m_page);
80
81     // If there isn't a root node yet, don't do anything. We'll be called again after creating one.
82     if (!m_scrollingStateTree->rootStateNode())
83         return;
84
85     // Compute the region of the page that we can't do fast scrolling for. This currently includes
86     // all scrollable areas, such as subframes, overflow divs and list boxes. We need to do this even if the
87     // frame view whose layout was updated is not the main frame.
88     // In the future, we may want to have the ability to set non-fast scrolling regions for more than
89     // just the root node. But right now, this concept only applies to the root.
90     m_scrollingStateTree->rootStateNode()->setNonFastScrollableRegion(computeNonFastScrollableRegion(&m_page->mainFrame(), IntPoint()));
91
92     if (!coordinatesScrollingForFrameView(frameView))
93         return;
94
95     ScrollingStateFrameScrollingNode* node = downcast<ScrollingStateFrameScrollingNode>(m_scrollingStateTree->stateNodeForID(frameView->scrollLayerID()));
96     if (!node)
97         return;
98
99     Scrollbar* verticalScrollbar = frameView->verticalScrollbar();
100     Scrollbar* horizontalScrollbar = frameView->horizontalScrollbar();
101     node->setScrollbarPaintersFromScrollbars(verticalScrollbar, horizontalScrollbar);
102     
103     node->setFrameScaleFactor(frameView->frame().frameScaleFactor());
104     node->setHeaderHeight(frameView->headerHeight());
105     node->setFooterHeight(frameView->footerHeight());
106     node->setTopContentInset(frameView->topContentInset());
107
108     node->setScrollOrigin(frameView->scrollOrigin());
109     node->setScrollableAreaSize(frameView->visibleContentRect().size());
110     node->setTotalContentsSize(frameView->totalContentsSize());
111     node->setReachableContentsSize(frameView->totalContentsSize());
112
113 #if ENABLE(CSS_SCROLL_SNAP)
114     frameView->updateSnapOffsets();
115     if (const Vector<LayoutUnit>* horizontalSnapOffsets = frameView->horizontalSnapOffsets())
116         setStateScrollingNodeSnapOffsetsAsFloat(*node, ScrollEventAxis::Horizontal, *horizontalSnapOffsets, m_page->deviceScaleFactor());
117
118     if (const Vector<LayoutUnit>* verticalSnapOffsets = frameView->verticalSnapOffsets())
119         setStateScrollingNodeSnapOffsetsAsFloat(*node, ScrollEventAxis::Vertical, *verticalSnapOffsets, m_page->deviceScaleFactor());
120 #endif
121
122     ScrollableAreaParameters scrollParameters;
123     scrollParameters.horizontalScrollElasticity = frameView->horizontalScrollElasticity();
124     scrollParameters.verticalScrollElasticity = frameView->verticalScrollElasticity();
125     scrollParameters.hasEnabledHorizontalScrollbar = horizontalScrollbar && horizontalScrollbar->enabled();
126     scrollParameters.hasEnabledVerticalScrollbar = verticalScrollbar && verticalScrollbar->enabled();
127     scrollParameters.horizontalScrollbarMode = frameView->horizontalScrollbarMode();
128     scrollParameters.verticalScrollbarMode = frameView->verticalScrollbarMode();
129
130     node->setScrollableAreaParameters(scrollParameters);
131 }
132
133 void AsyncScrollingCoordinator::frameViewNonFastScrollableRegionChanged(FrameView*)
134 {
135     if (!m_scrollingStateTree->rootStateNode())
136         return;
137
138     m_scrollingStateTree->rootStateNode()->setNonFastScrollableRegion(computeNonFastScrollableRegion(&m_page->mainFrame(), IntPoint()));
139 }
140
141 void AsyncScrollingCoordinator::frameViewRootLayerDidChange(FrameView* frameView)
142 {
143     ASSERT(isMainThread());
144     ASSERT(m_page);
145
146     if (!coordinatesScrollingForFrameView(frameView))
147         return;
148     
149     // FIXME: In some navigation scenarios, the FrameView has no RenderView or that RenderView has not been composited.
150     // This needs cleaning up: https://bugs.webkit.org/show_bug.cgi?id=132724
151     if (!frameView->scrollLayerID())
152         return;
153     
154     // If the root layer does not have a ScrollingStateNode, then we should create one.
155     ensureRootStateNodeForFrameView(frameView);
156     ASSERT(m_scrollingStateTree->rootStateNode());
157
158     ScrollingCoordinator::frameViewRootLayerDidChange(frameView);
159
160     ScrollingStateFrameScrollingNode* node = downcast<ScrollingStateFrameScrollingNode>(m_scrollingStateTree->stateNodeForID(frameView->scrollLayerID()));
161     node->setLayer(scrollLayerForFrameView(frameView));
162     node->setScrolledContentsLayer(rootContentLayerForFrameView(frameView));
163     node->setCounterScrollingLayer(counterScrollingLayerForFrameView(frameView));
164     node->setInsetClipLayer(insetClipLayerForFrameView(frameView));
165     node->setContentShadowLayer(contentShadowLayerForFrameView(frameView));
166     node->setHeaderLayer(headerLayerForFrameView(frameView));
167     node->setFooterLayer(footerLayerForFrameView(frameView));
168     node->setScrollBehaviorForFixedElements(frameView->scrollBehaviorForFixedElements());
169 }
170
171 bool AsyncScrollingCoordinator::requestScrollPositionUpdate(FrameView* frameView, const IntPoint& scrollPosition)
172 {
173     ASSERT(isMainThread());
174     ASSERT(m_page);
175
176     if (!coordinatesScrollingForFrameView(frameView))
177         return false;
178
179     if (frameView->inProgrammaticScroll() || frameView->frame().document()->inPageCache())
180         updateScrollPositionAfterAsyncScroll(frameView->scrollLayerID(), scrollPosition, frameView->inProgrammaticScroll(), SetScrollingLayerPosition);
181
182     // If this frame view's document is being put into the page cache, we don't want to update our
183     // main frame scroll position. Just let the FrameView think that we did.
184     if (frameView->frame().document()->inPageCache())
185         return true;
186
187     ScrollingStateScrollingNode* stateNode = downcast<ScrollingStateScrollingNode>(m_scrollingStateTree->stateNodeForID(frameView->scrollLayerID()));
188     if (!stateNode)
189         return false;
190
191     stateNode->setRequestedScrollPosition(scrollPosition, frameView->inProgrammaticScroll());
192     return true;
193 }
194
195 void AsyncScrollingCoordinator::scheduleUpdateScrollPositionAfterAsyncScroll(ScrollingNodeID nodeID, const FloatPoint& scrollPosition, bool programmaticScroll, SetOrSyncScrollingLayerPosition scrollingLayerPositionAction)
196 {
197     ScheduledScrollUpdate scrollUpdate(nodeID, scrollPosition, programmaticScroll, scrollingLayerPositionAction);
198     
199     if (m_updateNodeScrollPositionTimer.isActive()) {
200         if (m_scheduledScrollUpdate.matchesUpdateType(scrollUpdate)) {
201             m_scheduledScrollUpdate.scrollPosition = scrollPosition;
202             return;
203         }
204     
205         // If the parameters don't match what was previously scheduled, dispatch immediately.
206         m_updateNodeScrollPositionTimer.stop();
207         updateScrollPositionAfterAsyncScroll(m_scheduledScrollUpdate.nodeID, m_scheduledScrollUpdate.scrollPosition, m_scheduledScrollUpdate.isProgrammaticScroll, m_scheduledScrollUpdate.updateLayerPositionAction);
208         updateScrollPositionAfterAsyncScroll(nodeID, scrollPosition, programmaticScroll, scrollingLayerPositionAction);
209         return;
210     }
211
212     m_scheduledScrollUpdate = scrollUpdate;
213     m_updateNodeScrollPositionTimer.startOneShot(0);
214 }
215
216 void AsyncScrollingCoordinator::updateScrollPositionAfterAsyncScrollTimerFired(Timer*)
217 {
218     updateScrollPositionAfterAsyncScroll(m_scheduledScrollUpdate.nodeID, m_scheduledScrollUpdate.scrollPosition, m_scheduledScrollUpdate.isProgrammaticScroll, m_scheduledScrollUpdate.updateLayerPositionAction);
219 }
220
221 FrameView* AsyncScrollingCoordinator::frameViewForScrollingNode(ScrollingNodeID scrollingNodeID) const
222 {
223     if (!m_scrollingStateTree->rootStateNode())
224         return nullptr;
225     
226     if (scrollingNodeID == m_scrollingStateTree->rootStateNode()->scrollingNodeID())
227         return m_page->mainFrame().view();
228
229     ScrollingStateNode* stateNode = m_scrollingStateTree->stateNodeForID(scrollingNodeID);
230     if (!stateNode)
231         return nullptr;
232
233     // Find the enclosing frame scrolling node.
234     ScrollingStateNode* parentNode = stateNode;
235     while (parentNode && parentNode->nodeType() != FrameScrollingNode)
236         parentNode = parentNode->parent();
237     
238     if (!parentNode)
239         return nullptr;
240     
241     // Walk the frame tree to find the matching FrameView. This is not ideal, but avoids back pointers to FrameViews
242     // from ScrollingTreeStateNodes.
243     for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
244         if (FrameView* view = frame->view()) {
245             if (view->scrollLayerID() == parentNode->scrollingNodeID())
246                 return view;
247         }
248     }
249
250     return nullptr;
251 }
252
253 void AsyncScrollingCoordinator::updateScrollPositionAfterAsyncScroll(ScrollingNodeID scrollingNodeID, const FloatPoint& scrollPosition, bool programmaticScroll, SetOrSyncScrollingLayerPosition scrollingLayerPositionAction)
254 {
255     ASSERT(isMainThread());
256
257     if (!m_page)
258         return;
259
260     FrameView* frameView = frameViewForScrollingNode(scrollingNodeID);
261     if (!frameView)
262         return;
263
264     if (scrollingNodeID == frameView->scrollLayerID()) {
265         bool oldProgrammaticScroll = frameView->inProgrammaticScroll();
266         frameView->setInProgrammaticScroll(programmaticScroll);
267
268         frameView->setConstrainsScrollingToContentEdge(false);
269         frameView->notifyScrollPositionChanged(roundedIntPoint(scrollPosition));
270         frameView->setConstrainsScrollingToContentEdge(true);
271
272         frameView->setInProgrammaticScroll(oldProgrammaticScroll);
273
274         if (GraphicsLayer* scrollLayer = scrollLayerForFrameView(frameView)) {
275             GraphicsLayer* counterScrollingLayer = counterScrollingLayerForFrameView(frameView);
276             GraphicsLayer* insetClipLayer = insetClipLayerForFrameView(frameView);
277             GraphicsLayer* contentShadowLayer = contentShadowLayerForFrameView(frameView);
278             GraphicsLayer* scrolledContentsLayer = rootContentLayerForFrameView(frameView);
279             GraphicsLayer* headerLayer = headerLayerForFrameView(frameView);
280             GraphicsLayer* footerLayer = footerLayerForFrameView(frameView);
281             LayoutSize scrollOffsetForFixed = frameView->scrollOffsetForFixedPosition();
282
283             float topContentInset = frameView->topContentInset();
284             FloatPoint positionForInsetClipLayer = FloatPoint(0, FrameView::yPositionForInsetClipLayer(scrollPosition, topContentInset));
285             FloatPoint positionForContentsLayer = FloatPoint(scrolledContentsLayer->position().x(),
286                 FrameView::yPositionForRootContentLayer(scrollPosition, topContentInset, frameView->headerHeight()));
287             FloatPoint positionForHeaderLayer = FloatPoint(scrollOffsetForFixed.width(), FrameView::yPositionForHeaderLayer(scrollPosition, topContentInset));
288             FloatPoint positionForFooterLayer = FloatPoint(scrollOffsetForFixed.width(),
289                 FrameView::yPositionForFooterLayer(scrollPosition, topContentInset, frameView->totalContentsSize().height(), frameView->footerHeight()));
290
291             if (programmaticScroll || scrollingLayerPositionAction == SetScrollingLayerPosition) {
292                 scrollLayer->setPosition(-frameView->scrollPosition());
293                 if (counterScrollingLayer)
294                     counterScrollingLayer->setPosition(toLayoutPoint(scrollOffsetForFixed));
295                 if (insetClipLayer)
296                     insetClipLayer->setPosition(positionForInsetClipLayer);
297                 if (contentShadowLayer)
298                     contentShadowLayer->setPosition(positionForContentsLayer);
299                 if (scrolledContentsLayer)
300                     scrolledContentsLayer->setPosition(positionForContentsLayer);
301                 if (headerLayer)
302                     headerLayer->setPosition(positionForHeaderLayer);
303                 if (footerLayer)
304                     footerLayer->setPosition(positionForFooterLayer);
305             } else {
306                 scrollLayer->syncPosition(-frameView->scrollPosition());
307                 if (counterScrollingLayer)
308                     counterScrollingLayer->syncPosition(toLayoutPoint(scrollOffsetForFixed));
309                 if (insetClipLayer)
310                     insetClipLayer->syncPosition(positionForInsetClipLayer);
311                 if (contentShadowLayer)
312                     contentShadowLayer->syncPosition(positionForContentsLayer);
313                 if (scrolledContentsLayer)
314                     scrolledContentsLayer->syncPosition(positionForContentsLayer);
315                 if (headerLayer)
316                     headerLayer->syncPosition(positionForHeaderLayer);
317                 if (footerLayer)
318                     footerLayer->syncPosition(positionForFooterLayer);
319
320                 LayoutRect viewportRect = frameView->viewportConstrainedVisibleContentRect();
321                 syncChildPositions(viewportRect);
322             }
323         }
324
325         return;
326     }
327
328     // Overflow-scroll area.
329     if (ScrollableArea* scrollableArea = frameView->scrollableAreaForScrollLayerID(scrollingNodeID)) {
330         scrollableArea->setIsUserScroll(scrollingLayerPositionAction == SyncScrollingLayerPosition);
331         scrollableArea->scrollToOffsetWithoutAnimation(scrollPosition);
332         scrollableArea->setIsUserScroll(false);
333         if (scrollingLayerPositionAction == SetScrollingLayerPosition)
334             m_page->editorClient()->overflowScrollPositionChanged();
335     }
336 }
337
338 void AsyncScrollingCoordinator::scrollableAreaScrollbarLayerDidChange(ScrollableArea* scrollableArea, ScrollbarOrientation orientation)
339 {
340     ASSERT(isMainThread());
341     ASSERT(m_page);
342
343     if (scrollableArea != static_cast<ScrollableArea*>(m_page->mainFrame().view()))
344         return;
345
346     if (orientation == VerticalScrollbar)
347         scrollableArea->verticalScrollbarLayerDidChange();
348     else
349         scrollableArea->horizontalScrollbarLayerDidChange();
350 }
351
352 ScrollingNodeID AsyncScrollingCoordinator::attachToStateTree(ScrollingNodeType nodeType, ScrollingNodeID newNodeID, ScrollingNodeID parentID)
353 {
354     return m_scrollingStateTree->attachNode(nodeType, newNodeID, parentID);
355 }
356
357 void AsyncScrollingCoordinator::detachFromStateTree(ScrollingNodeID nodeID)
358 {
359     m_scrollingStateTree->detachNode(nodeID);
360 }
361
362 void AsyncScrollingCoordinator::clearStateTree()
363 {
364     m_scrollingStateTree->clear();
365 }
366
367 void AsyncScrollingCoordinator::syncChildPositions(const LayoutRect& viewportRect)
368 {
369     if (!m_scrollingStateTree->rootStateNode())
370         return;
371
372     auto children = m_scrollingStateTree->rootStateNode()->children();
373     if (!children)
374         return;
375
376     // FIXME: We'll have to traverse deeper into the tree at some point.
377     for (auto& child : *children)
378         child->syncLayerPositionForViewportRect(viewportRect);
379 }
380
381 void AsyncScrollingCoordinator::ensureRootStateNodeForFrameView(FrameView* frameView)
382 {
383     ASSERT(frameView->scrollLayerID());
384     attachToStateTree(FrameScrollingNode, frameView->scrollLayerID(), 0);
385 }
386
387 void AsyncScrollingCoordinator::updateFrameScrollingNode(ScrollingNodeID nodeID, GraphicsLayer* layer, GraphicsLayer* scrolledContentsLayer, GraphicsLayer* counterScrollingLayer, GraphicsLayer* insetClipLayer, const ScrollingGeometry* scrollingGeometry)
388 {
389     ScrollingStateFrameScrollingNode* node = downcast<ScrollingStateFrameScrollingNode>(m_scrollingStateTree->stateNodeForID(nodeID));
390     ASSERT(node);
391     if (!node)
392         return;
393
394     node->setLayer(layer);
395     node->setInsetClipLayer(insetClipLayer);
396     node->setScrolledContentsLayer(scrolledContentsLayer);
397     node->setCounterScrollingLayer(counterScrollingLayer);
398
399     if (scrollingGeometry) {
400         node->setScrollOrigin(scrollingGeometry->scrollOrigin);
401         node->setScrollPosition(scrollingGeometry->scrollPosition);
402         node->setTotalContentsSize(scrollingGeometry->contentSize);
403         node->setReachableContentsSize(scrollingGeometry->reachableContentSize);
404         node->setScrollableAreaSize(scrollingGeometry->scrollableAreaSize);
405     }
406 }
407     
408 void AsyncScrollingCoordinator::updateOverflowScrollingNode(ScrollingNodeID nodeID, GraphicsLayer* layer, GraphicsLayer* scrolledContentsLayer, const ScrollingGeometry* scrollingGeometry)
409 {
410     ScrollingStateOverflowScrollingNode* node = downcast<ScrollingStateOverflowScrollingNode>(m_scrollingStateTree->stateNodeForID(nodeID));
411     ASSERT(node);
412     if (!node)
413         return;
414
415     node->setLayer(layer);
416     node->setScrolledContentsLayer(scrolledContentsLayer);
417     
418     if (scrollingGeometry) {
419         node->setScrollOrigin(scrollingGeometry->scrollOrigin);
420         node->setScrollPosition(scrollingGeometry->scrollPosition);
421         node->setTotalContentsSize(scrollingGeometry->contentSize);
422         node->setReachableContentsSize(scrollingGeometry->reachableContentSize);
423         node->setScrollableAreaSize(scrollingGeometry->scrollableAreaSize);
424 #if ENABLE(CSS_SCROLL_SNAP)
425         setStateScrollingNodeSnapOffsetsAsFloat(*node, ScrollEventAxis::Horizontal, scrollingGeometry->horizontalSnapOffsets, m_page->deviceScaleFactor());
426         setStateScrollingNodeSnapOffsetsAsFloat(*node, ScrollEventAxis::Vertical, scrollingGeometry->verticalSnapOffsets, m_page->deviceScaleFactor());
427 #endif
428     }
429 }
430
431 void AsyncScrollingCoordinator::updateViewportConstrainedNode(ScrollingNodeID nodeID, const ViewportConstraints& constraints, GraphicsLayer* graphicsLayer)
432 {
433     ASSERT(supportsFixedPositionLayers());
434
435     ScrollingStateNode* node = m_scrollingStateTree->stateNodeForID(nodeID);
436     if (!node)
437         return;
438
439     switch (constraints.constraintType()) {
440     case ViewportConstraints::FixedPositionConstraint: {
441         ScrollingStateFixedNode& fixedNode = downcast<ScrollingStateFixedNode>(*node);
442         fixedNode.setLayer(graphicsLayer);
443         fixedNode.updateConstraints((const FixedPositionViewportConstraints&)constraints);
444         break;
445     }
446     case ViewportConstraints::StickyPositionConstraint: {
447         ScrollingStateStickyNode& stickyNode = downcast<ScrollingStateStickyNode>(*node);
448         stickyNode.setLayer(graphicsLayer);
449         stickyNode.updateConstraints((const StickyPositionViewportConstraints&)constraints);
450         break;
451     }
452     }
453 }
454
455 void AsyncScrollingCoordinator::setSynchronousScrollingReasons(SynchronousScrollingReasons reasons)
456 {
457     if (!m_scrollingStateTree->rootStateNode())
458         return;
459
460     // The FrameView's GraphicsLayer is likely to be out-of-synch with the PlatformLayer
461     // at this point. So we'll update it before we switch back to main thread scrolling
462     // in order to avoid layer positioning bugs.
463     if (reasons)
464         updateMainFrameScrollLayerPosition();
465     m_scrollingStateTree->rootStateNode()->setSynchronousScrollingReasons(reasons);
466 }
467
468 void AsyncScrollingCoordinator::updateMainFrameScrollLayerPosition()
469 {
470     ASSERT(isMainThread());
471
472     if (!m_page)
473         return;
474
475     FrameView* frameView = m_page->mainFrame().view();
476     if (!frameView)
477         return;
478
479     if (GraphicsLayer* scrollLayer = scrollLayerForFrameView(frameView))
480         scrollLayer->setPosition(-frameView->scrollPosition());
481 }
482
483 void AsyncScrollingCoordinator::recomputeWheelEventHandlerCountForFrameView(FrameView* frameView)
484 {
485     ScrollingStateFrameScrollingNode* node = downcast<ScrollingStateFrameScrollingNode>(m_scrollingStateTree->stateNodeForID(frameView->scrollLayerID()));
486     if (!node)
487         return;
488     node->setWheelEventHandlerCount(computeCurrentWheelEventHandlerCount());
489 }
490
491 bool AsyncScrollingCoordinator::isRubberBandInProgress() const
492 {
493     return scrollingTree()->isRubberBandInProgress();
494 }
495
496 void AsyncScrollingCoordinator::setScrollPinningBehavior(ScrollPinningBehavior pinning)
497 {
498     scrollingTree()->setScrollPinningBehavior(pinning);
499 }
500
501 String AsyncScrollingCoordinator::scrollingStateTreeAsText() const
502 {
503     if (m_scrollingStateTree->rootStateNode())
504         return m_scrollingStateTree->rootStateNode()->scrollingStateTreeAsText();
505
506     return String();
507 }
508
509 } // namespace WebCore
510
511 #endif // ENABLE(ASYNC_SCROLLING)