2 * Copyright (C) 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "RemoteScrollingCoordinatorProxy.h"
29 #if ENABLE(ASYNC_SCROLLING)
31 #include "ArgumentCoders.h"
32 #include "MessageDecoder.h"
33 #include "MessageEncoder.h"
34 #include "RemoteLayerTreeDrawingAreaProxy.h"
35 #include "RemoteScrollingCoordinator.h"
36 #include "RemoteScrollingCoordinatorMessages.h"
37 #include "RemoteScrollingCoordinatorTransaction.h"
38 #include "RemoteScrollingTree.h"
39 #include "WebPageProxy.h"
40 #include "WebProcessProxy.h"
41 #include <WebCore/ScrollingStateTree.h>
42 #include <WebCore/ScrollingTreeScrollingNode.h>
44 using namespace WebCore;
48 RemoteScrollingCoordinatorProxy::RemoteScrollingCoordinatorProxy(WebPageProxy& webPageProxy)
49 : m_webPageProxy(webPageProxy)
50 , m_scrollingTree(RemoteScrollingTree::create(*this))
51 , m_propagatesMainFrameScrolls(true)
55 RemoteScrollingCoordinatorProxy::~RemoteScrollingCoordinatorProxy()
59 ScrollingNodeID RemoteScrollingCoordinatorProxy::rootScrollingNodeID() const
61 if (!m_scrollingTree->rootNode())
64 return m_scrollingTree->rootNode()->scrollingNodeID();
67 const RemoteLayerTreeHost* RemoteScrollingCoordinatorProxy::layerTreeHost() const
69 DrawingAreaProxy* drawingArea = m_webPageProxy.drawingArea();
70 if (!drawingArea || drawingArea->type() != DrawingAreaTypeRemoteLayerTree) {
75 RemoteLayerTreeDrawingAreaProxy* remoteDrawingArea = toRemoteLayerTreeDrawingAreaProxy(drawingArea);
76 return &remoteDrawingArea->remoteLayerTreeHost();
79 void RemoteScrollingCoordinatorProxy::updateScrollingTree(const RemoteScrollingCoordinatorTransaction& transaction, bool& fixedOrStickyLayerChanged)
81 OwnPtr<ScrollingStateTree> stateTree = const_cast<RemoteScrollingCoordinatorTransaction&>(transaction).scrollingStateTree().release();
83 const RemoteLayerTreeHost* layerTreeHost = this->layerTreeHost();
89 connectStateNodeLayers(*stateTree, *layerTreeHost, fixedOrStickyLayerChanged);
90 m_scrollingTree->commitNewTreeState(stateTree.release());
94 void RemoteScrollingCoordinatorProxy::connectStateNodeLayers(ScrollingStateTree& stateTree, const RemoteLayerTreeHost& layerTreeHost, bool& fixedOrStickyLayerChanged)
96 for (auto& currNode : stateTree.nodeMap().values()) {
97 switch (currNode->nodeType()) {
98 case FrameScrollingNode:
99 case OverflowScrollingNode: {
100 ScrollingStateScrollingNode* scrollingStateNode = toScrollingStateScrollingNode(currNode);
102 if (scrollingStateNode->hasChangedProperty(ScrollingStateNode::ScrollLayer))
103 scrollingStateNode->setLayer(layerTreeHost.getLayer(scrollingStateNode->layer()));
105 if (scrollingStateNode->hasChangedProperty(ScrollingStateScrollingNode::ScrolledContentsLayer))
106 scrollingStateNode->setScrolledContentsLayer(layerTreeHost.getLayer(scrollingStateNode->scrolledContentsLayer()));
108 if (scrollingStateNode->hasChangedProperty(ScrollingStateScrollingNode::CounterScrollingLayer))
109 scrollingStateNode->setCounterScrollingLayer(layerTreeHost.getLayer(scrollingStateNode->counterScrollingLayer()));
111 // FIXME: we should never have header and footer layers coming from the WebProcess.
112 if (scrollingStateNode->hasChangedProperty(ScrollingStateScrollingNode::HeaderLayer))
113 scrollingStateNode->setHeaderLayer(layerTreeHost.getLayer(scrollingStateNode->headerLayer()));
115 if (scrollingStateNode->hasChangedProperty(ScrollingStateScrollingNode::FooterLayer))
116 scrollingStateNode->setFooterLayer(layerTreeHost.getLayer(scrollingStateNode->footerLayer()));
120 if (currNode->hasChangedProperty(ScrollingStateNode::ScrollLayer)) {
121 currNode->setLayer(layerTreeHost.getLayer(currNode->layer()));
122 fixedOrStickyLayerChanged = true;
126 if (currNode->hasChangedProperty(ScrollingStateNode::ScrollLayer)) {
127 currNode->setLayer(layerTreeHost.getLayer(currNode->layer()));
128 fixedOrStickyLayerChanged = true;
136 bool RemoteScrollingCoordinatorProxy::handleWheelEvent(const PlatformWheelEvent& event)
138 ScrollingTree::EventResult result = m_scrollingTree->tryToHandleWheelEvent(event);
139 return result == ScrollingTree::DidHandleEvent; // FIXME: handle other values.
142 bool RemoteScrollingCoordinatorProxy::isPointInNonFastScrollableRegion(const IntPoint& p) const
144 return m_scrollingTree->isPointInNonFastScrollableRegion(p);
147 void RemoteScrollingCoordinatorProxy::viewportChangedViaDelegatedScrolling(ScrollingNodeID nodeID, const FloatRect& viewportRect, double scale)
149 m_scrollingTree->viewportChangedViaDelegatedScrolling(nodeID, viewportRect, scale);
152 // This comes from the scrolling tree.
153 void RemoteScrollingCoordinatorProxy::scrollingTreeNodeDidScroll(ScrollingNodeID scrolledNodeID, const FloatPoint& newScrollPosition, SetOrSyncScrollingLayerPosition scrollingLayerPositionAction)
155 // Scroll updates for the main frame are sent via WebPageProxy::updateVisibleContentRects()
156 // so don't send them here.
157 if (!m_propagatesMainFrameScrolls && scrolledNodeID == rootScrollingNodeID())
160 m_webPageProxy.send(Messages::RemoteScrollingCoordinator::ScrollPositionChangedForNode(scrolledNodeID, newScrollPosition, scrollingLayerPositionAction));
163 void RemoteScrollingCoordinatorProxy::scrollingTreeNodeRequestsScroll(ScrollingNodeID scrolledNodeID, const FloatPoint& scrollPosition, bool representsProgrammaticScroll)
165 if (scrolledNodeID == rootScrollingNodeID())
166 m_webPageProxy.requestScroll(scrollPosition, representsProgrammaticScroll);
169 } // namespace WebKit
171 #endif // ENABLE(ASYNC_SCROLLING)