Use "= default" to denote default constructor or destructor
[WebKit-https.git] / Source / WebCore / page / scrolling / coordinatedgraphics / ScrollingCoordinatorCoordinatedGraphics.cpp
1 /*
2  * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
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 THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "ScrollingCoordinatorCoordinatedGraphics.h"
28
29 #if USE(COORDINATED_GRAPHICS)
30
31 #include "CoordinatedGraphicsLayer.h"
32 #include "FrameView.h"
33 #include "HostWindow.h"
34 #include "Page.h"
35 #include "RenderLayer.h"
36 #include "RenderLayerBacking.h"
37 #include "ScrollingConstraints.h"
38 #include "ScrollingStateFixedNode.h"
39 #include "ScrollingStateScrollingNode.h"
40 #include "ScrollingStateStickyNode.h"
41 #include "ScrollingStateTree.h"
42
43 namespace WebCore {
44
45 ScrollingCoordinatorCoordinatedGraphics::ScrollingCoordinatorCoordinatedGraphics(Page* page)
46     : ScrollingCoordinator(page)
47     , m_scrollingStateTree(std::make_unique<ScrollingStateTree>())
48 {
49 }
50
51 ScrollingCoordinatorCoordinatedGraphics::~ScrollingCoordinatorCoordinatedGraphics() = default;
52
53 ScrollingNodeID ScrollingCoordinatorCoordinatedGraphics::attachToStateTree(ScrollingNodeType nodeType, ScrollingNodeID newNodeID, ScrollingNodeID parentID)
54 {
55     return m_scrollingStateTree->attachNode(nodeType, newNodeID, parentID);
56 }
57
58 void ScrollingCoordinatorCoordinatedGraphics::detachFromStateTree(ScrollingNodeID nodeID)
59 {
60     auto* node = m_scrollingStateTree->stateNodeForID(nodeID);
61     if (node && node->nodeType() == FixedNode)
62         downcast<CoordinatedGraphicsLayer>(*static_cast<GraphicsLayer*>(node->layer())).setFixedToViewport(false);
63
64     m_scrollingStateTree->detachNode(nodeID);
65 }
66
67 void ScrollingCoordinatorCoordinatedGraphics::clearStateTree()
68 {
69     m_scrollingStateTree->clear();
70 }
71
72 void ScrollingCoordinatorCoordinatedGraphics::updateNodeLayer(ScrollingNodeID nodeID, GraphicsLayer* graphicsLayer)
73 {
74     auto* node = m_scrollingStateTree->stateNodeForID(nodeID);
75     if (!node)
76         return;
77
78     node->setLayer(graphicsLayer);
79 }
80
81 void ScrollingCoordinatorCoordinatedGraphics::updateNodeViewportConstraints(ScrollingNodeID nodeID, const ViewportConstraints& constraints)
82 {
83     auto* node = m_scrollingStateTree->stateNodeForID(nodeID);
84     if (!node)
85         return;
86
87     switch (constraints.constraintType()) {
88     case ViewportConstraints::FixedPositionConstraint: {
89         auto& layer = node->layer();
90         if (layer.representsGraphicsLayer())
91             downcast<CoordinatedGraphicsLayer>(static_cast<GraphicsLayer*>(layer))->setFixedToViewport(true);
92         break;
93     }
94     case ViewportConstraints::StickyPositionConstraint:
95         break; // FIXME : Support sticky elements.
96     default:
97         ASSERT_NOT_REACHED();
98     }
99 }
100
101 void ScrollingCoordinatorCoordinatedGraphics::scrollableAreaScrollLayerDidChange(ScrollableArea& scrollableArea)
102 {
103     auto* layer = downcast<CoordinatedGraphicsLayer>(scrollLayerForScrollableArea(scrollableArea));
104     if (!layer)
105         return;
106
107     layer->setScrollableArea(&scrollableArea);
108 }
109
110 void ScrollingCoordinatorCoordinatedGraphics::willDestroyScrollableArea(ScrollableArea& scrollableArea)
111 {
112     auto* layer = downcast<CoordinatedGraphicsLayer>(scrollLayerForScrollableArea(scrollableArea));
113     if (!layer)
114         return;
115
116     layer->setScrollableArea(nullptr);
117 }
118
119 bool ScrollingCoordinatorCoordinatedGraphics::requestScrollPositionUpdate(FrameView& frameView, const IntPoint& scrollPosition)
120 {
121     if (!frameView.delegatesScrolling())
122         return false;
123
124     frameView.hostWindow()->delegatedScrollRequested(scrollPosition);
125     return true;
126 }
127
128 } // namespace WebCore
129
130 #endif // USE(COORDINATED_GRAPHICS)