Remove scrolling tree dependency on wheel event handler counts, and use fast scrollin...
[WebKit-https.git] / Source / WebCore / page / scrolling / ScrollingStateFrameScrollingNode.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 #include "ScrollingStateFrameScrollingNode.h"
28
29 #if ENABLE(ASYNC_SCROLLING) || USE(COORDINATED_GRAPHICS)
30
31 #include "ScrollingStateTree.h"
32 #include "TextStream.h"
33
34 namespace WebCore {
35
36 PassRefPtr<ScrollingStateFrameScrollingNode> ScrollingStateFrameScrollingNode::create(ScrollingStateTree& stateTree, ScrollingNodeID nodeID)
37 {
38     return adoptRef(new ScrollingStateFrameScrollingNode(stateTree, nodeID));
39 }
40
41 ScrollingStateFrameScrollingNode::ScrollingStateFrameScrollingNode(ScrollingStateTree& stateTree, ScrollingNodeID nodeID)
42     : ScrollingStateScrollingNode(stateTree, FrameScrollingNode, nodeID)
43 #if PLATFORM(MAC)
44     , m_verticalScrollbarPainter(0)
45     , m_horizontalScrollbarPainter(0)
46 #endif
47     , m_frameScaleFactor(1)
48     , m_synchronousScrollingReasons(0)
49     , m_behaviorForFixed(StickToDocumentBounds)
50     , m_headerHeight(0)
51     , m_footerHeight(0)
52     , m_requestedScrollPositionRepresentsProgrammaticScroll(false)
53     , m_topContentInset(0)
54 {
55 }
56
57 ScrollingStateFrameScrollingNode::ScrollingStateFrameScrollingNode(const ScrollingStateFrameScrollingNode& stateNode, ScrollingStateTree& adoptiveTree)
58     : ScrollingStateScrollingNode(stateNode, adoptiveTree)
59 #if PLATFORM(MAC)
60     , m_verticalScrollbarPainter(stateNode.verticalScrollbarPainter())
61     , m_horizontalScrollbarPainter(stateNode.horizontalScrollbarPainter())
62 #endif
63     , m_nonFastScrollableRegion(stateNode.nonFastScrollableRegion())
64     , m_frameScaleFactor(stateNode.frameScaleFactor())
65     , m_synchronousScrollingReasons(stateNode.synchronousScrollingReasons())
66     , m_behaviorForFixed(stateNode.scrollBehaviorForFixedElements())
67     , m_headerHeight(stateNode.headerHeight())
68     , m_footerHeight(stateNode.footerHeight())
69     , m_requestedScrollPosition(stateNode.requestedScrollPosition())
70     , m_requestedScrollPositionRepresentsProgrammaticScroll(stateNode.requestedScrollPositionRepresentsProgrammaticScroll())
71     , m_topContentInset(stateNode.topContentInset())
72 {
73     if (hasChangedProperty(ScrolledContentsLayer))
74         setScrolledContentsLayer(stateNode.scrolledContentsLayer().toRepresentation(adoptiveTree.preferredLayerRepresentation()));
75
76     if (hasChangedProperty(CounterScrollingLayer))
77         setCounterScrollingLayer(stateNode.counterScrollingLayer().toRepresentation(adoptiveTree.preferredLayerRepresentation()));
78
79     if (hasChangedProperty(InsetClipLayer))
80         setInsetClipLayer(stateNode.insetClipLayer().toRepresentation(adoptiveTree.preferredLayerRepresentation()));
81
82     if (hasChangedProperty(ContentShadowLayer))
83         setContentShadowLayer(stateNode.contentShadowLayer().toRepresentation(adoptiveTree.preferredLayerRepresentation()));
84
85     if (hasChangedProperty(HeaderLayer))
86         setHeaderLayer(stateNode.headerLayer().toRepresentation(adoptiveTree.preferredLayerRepresentation()));
87
88     if (hasChangedProperty(FooterLayer))
89         setFooterLayer(stateNode.footerLayer().toRepresentation(adoptiveTree.preferredLayerRepresentation()));
90 }
91
92 ScrollingStateFrameScrollingNode::~ScrollingStateFrameScrollingNode()
93 {
94 }
95
96 PassRefPtr<ScrollingStateNode> ScrollingStateFrameScrollingNode::clone(ScrollingStateTree& adoptiveTree)
97 {
98     return adoptRef(new ScrollingStateFrameScrollingNode(*this, adoptiveTree));
99 }
100
101 void ScrollingStateFrameScrollingNode::setFrameScaleFactor(float scaleFactor)
102 {
103     if (m_frameScaleFactor == scaleFactor)
104         return;
105
106     m_frameScaleFactor = scaleFactor;
107
108     setPropertyChanged(FrameScaleFactor);
109 }
110
111 void ScrollingStateFrameScrollingNode::setNonFastScrollableRegion(const Region& nonFastScrollableRegion)
112 {
113     if (m_nonFastScrollableRegion == nonFastScrollableRegion)
114         return;
115
116     m_nonFastScrollableRegion = nonFastScrollableRegion;
117     setPropertyChanged(NonFastScrollableRegion);
118 }
119
120 void ScrollingStateFrameScrollingNode::setSynchronousScrollingReasons(SynchronousScrollingReasons reasons)
121 {
122     if (m_synchronousScrollingReasons == reasons)
123         return;
124
125     m_synchronousScrollingReasons = reasons;
126     setPropertyChanged(ReasonsForSynchronousScrolling);
127 }
128
129 void ScrollingStateFrameScrollingNode::setScrollBehaviorForFixedElements(ScrollBehaviorForFixedElements behaviorForFixed)
130 {
131     if (m_behaviorForFixed == behaviorForFixed)
132         return;
133
134     m_behaviorForFixed = behaviorForFixed;
135     setPropertyChanged(BehaviorForFixedElements);
136 }
137     
138 void ScrollingStateFrameScrollingNode::setHeaderHeight(int headerHeight)
139 {
140     if (m_headerHeight == headerHeight)
141         return;
142
143     m_headerHeight = headerHeight;
144     setPropertyChanged(HeaderHeight);
145 }
146
147 void ScrollingStateFrameScrollingNode::setFooterHeight(int footerHeight)
148 {
149     if (m_footerHeight == footerHeight)
150         return;
151
152     m_footerHeight = footerHeight;
153     setPropertyChanged(FooterHeight);
154 }
155
156 void ScrollingStateFrameScrollingNode::setTopContentInset(float topContentInset)
157 {
158     if (m_topContentInset == topContentInset)
159         return;
160
161     m_topContentInset = topContentInset;
162     setPropertyChanged(TopContentInset);
163 }
164
165 void ScrollingStateFrameScrollingNode::setScrolledContentsLayer(const LayerRepresentation& layerRepresentation)
166 {
167     if (layerRepresentation == m_scrolledContentsLayer)
168         return;
169     
170     m_scrolledContentsLayer = layerRepresentation;
171     setPropertyChanged(ScrolledContentsLayer);
172 }
173
174 void ScrollingStateFrameScrollingNode::setCounterScrollingLayer(const LayerRepresentation& layerRepresentation)
175 {
176     if (layerRepresentation == m_counterScrollingLayer)
177         return;
178     
179     m_counterScrollingLayer = layerRepresentation;
180     setPropertyChanged(CounterScrollingLayer);
181 }
182
183 void ScrollingStateFrameScrollingNode::setInsetClipLayer(const LayerRepresentation& layerRepresentation)
184 {
185     if (layerRepresentation == m_insetClipLayer)
186         return;
187     
188     m_insetClipLayer = layerRepresentation;
189     setPropertyChanged(InsetClipLayer);
190 }
191
192 void ScrollingStateFrameScrollingNode::setContentShadowLayer(const LayerRepresentation& layerRepresentation)
193 {
194     if (layerRepresentation == m_contentShadowLayer)
195         return;
196     
197     m_contentShadowLayer = layerRepresentation;
198     setPropertyChanged(ContentShadowLayer);
199 }
200
201 void ScrollingStateFrameScrollingNode::setHeaderLayer(const LayerRepresentation& layerRepresentation)
202 {
203     if (layerRepresentation == m_headerLayer)
204         return;
205     
206     m_headerLayer = layerRepresentation;
207     setPropertyChanged(HeaderLayer);
208 }
209
210 void ScrollingStateFrameScrollingNode::setFooterLayer(const LayerRepresentation& layerRepresentation)
211 {
212     if (layerRepresentation == m_footerLayer)
213         return;
214     
215     m_footerLayer = layerRepresentation;
216     setPropertyChanged(FooterLayer);
217 }
218
219 #if !PLATFORM(MAC)
220 void ScrollingStateFrameScrollingNode::setScrollbarPaintersFromScrollbars(Scrollbar*, Scrollbar*)
221 {
222 }
223 #endif
224
225 void ScrollingStateFrameScrollingNode::dumpProperties(TextStream& ts, int indent) const
226 {
227     ts << "(Frame scrolling node" << "\n";
228     
229     ScrollingStateScrollingNode::dumpProperties(ts, indent);
230     
231     if (m_frameScaleFactor != 1) {
232         writeIndent(ts, indent + 1);
233         ts << "(frame scale factor " << m_frameScaleFactor << ")\n";
234     }
235     
236     if (!m_nonFastScrollableRegion.isEmpty()) {
237         ++indent;
238         writeIndent(ts, indent);
239         ts << "(non-fast-scrollable region";
240         ++indent;
241         for (auto rect : m_nonFastScrollableRegion.rects()) {
242             ts << "\n";
243             writeIndent(ts, indent);
244             ts << rect;
245         }
246         ts << ")\n";
247         indent -= 2;
248     }
249
250     if (m_synchronousScrollingReasons) {
251         writeIndent(ts, indent + 1);
252         ts << "(Scrolling on main thread because: " << ScrollingCoordinator::synchronousScrollingReasonsAsText(m_synchronousScrollingReasons) << ")\n";
253     }
254     
255     // FIXME: dump more properties.
256 }
257
258 } // namespace WebCore
259
260 #endif // ENABLE(ASYNC_SCROLLING) || USE(COORDINATED_GRAPHICS)