Use "= default" to denote default constructor or destructor
[WebKit-https.git] / Source / WebCore / page / scrolling / ScrollingStateFrameScrollingNode.cpp
1 /*
2  * Copyright (C) 2014, 2016 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 <wtf/text/TextStream.h>
33
34 namespace WebCore {
35
36 Ref<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 {
44 }
45
46 ScrollingStateFrameScrollingNode::ScrollingStateFrameScrollingNode(const ScrollingStateFrameScrollingNode& stateNode, ScrollingStateTree& adoptiveTree)
47     : ScrollingStateScrollingNode(stateNode, adoptiveTree)
48 #if PLATFORM(MAC)
49     , m_verticalScrollerImp(stateNode.verticalScrollerImp())
50     , m_horizontalScrollerImp(stateNode.horizontalScrollerImp())
51 #endif
52     , m_eventTrackingRegions(stateNode.eventTrackingRegions())
53     , m_requestedScrollPosition(stateNode.requestedScrollPosition())
54     , m_layoutViewport(stateNode.layoutViewport())
55     , m_minLayoutViewportOrigin(stateNode.minLayoutViewportOrigin())
56     , m_maxLayoutViewportOrigin(stateNode.maxLayoutViewportOrigin())
57     , m_frameScaleFactor(stateNode.frameScaleFactor())
58     , m_topContentInset(stateNode.topContentInset())
59     , m_headerHeight(stateNode.headerHeight())
60     , m_footerHeight(stateNode.footerHeight())
61     , m_synchronousScrollingReasons(stateNode.synchronousScrollingReasons())
62     , m_behaviorForFixed(stateNode.scrollBehaviorForFixedElements())
63     , m_requestedScrollPositionRepresentsProgrammaticScroll(stateNode.requestedScrollPositionRepresentsProgrammaticScroll())
64     , m_fixedElementsLayoutRelativeToFrame(stateNode.fixedElementsLayoutRelativeToFrame())
65     , m_visualViewportEnabled(stateNode.visualViewportEnabled())
66 {
67     if (hasChangedProperty(CounterScrollingLayer))
68         setCounterScrollingLayer(stateNode.counterScrollingLayer().toRepresentation(adoptiveTree.preferredLayerRepresentation()));
69
70     if (hasChangedProperty(InsetClipLayer))
71         setInsetClipLayer(stateNode.insetClipLayer().toRepresentation(adoptiveTree.preferredLayerRepresentation()));
72
73     if (hasChangedProperty(ContentShadowLayer))
74         setContentShadowLayer(stateNode.contentShadowLayer().toRepresentation(adoptiveTree.preferredLayerRepresentation()));
75
76     if (hasChangedProperty(HeaderLayer))
77         setHeaderLayer(stateNode.headerLayer().toRepresentation(adoptiveTree.preferredLayerRepresentation()));
78
79     if (hasChangedProperty(FooterLayer))
80         setFooterLayer(stateNode.footerLayer().toRepresentation(adoptiveTree.preferredLayerRepresentation()));
81 }
82
83 ScrollingStateFrameScrollingNode::~ScrollingStateFrameScrollingNode() = default;
84
85 Ref<ScrollingStateNode> ScrollingStateFrameScrollingNode::clone(ScrollingStateTree& adoptiveTree)
86 {
87     return adoptRef(*new ScrollingStateFrameScrollingNode(*this, adoptiveTree));
88 }
89
90 void ScrollingStateFrameScrollingNode::setFrameScaleFactor(float scaleFactor)
91 {
92     if (m_frameScaleFactor == scaleFactor)
93         return;
94
95     m_frameScaleFactor = scaleFactor;
96
97     setPropertyChanged(FrameScaleFactor);
98 }
99
100 void ScrollingStateFrameScrollingNode::setEventTrackingRegions(const EventTrackingRegions& eventTrackingRegions)
101 {
102     if (m_eventTrackingRegions == eventTrackingRegions)
103         return;
104
105     m_eventTrackingRegions = eventTrackingRegions;
106     setPropertyChanged(EventTrackingRegion);
107 }
108
109 void ScrollingStateFrameScrollingNode::setSynchronousScrollingReasons(SynchronousScrollingReasons reasons)
110 {
111     if (m_synchronousScrollingReasons == reasons)
112         return;
113
114     m_synchronousScrollingReasons = reasons;
115     setPropertyChanged(ReasonsForSynchronousScrolling);
116 }
117
118 void ScrollingStateFrameScrollingNode::setScrollBehaviorForFixedElements(ScrollBehaviorForFixedElements behaviorForFixed)
119 {
120     if (m_behaviorForFixed == behaviorForFixed)
121         return;
122
123     m_behaviorForFixed = behaviorForFixed;
124     setPropertyChanged(BehaviorForFixedElements);
125 }
126
127 void ScrollingStateFrameScrollingNode::setLayoutViewport(const FloatRect& r)
128 {
129     if (m_layoutViewport == r)
130         return;
131
132     m_layoutViewport = r;
133     setPropertyChanged(LayoutViewport);
134 }
135
136 void ScrollingStateFrameScrollingNode::setMinLayoutViewportOrigin(const FloatPoint& p)
137 {
138     if (m_minLayoutViewportOrigin == p)
139         return;
140
141     m_minLayoutViewportOrigin = p;
142     setPropertyChanged(MinLayoutViewportOrigin);
143 }
144
145 void ScrollingStateFrameScrollingNode::setMaxLayoutViewportOrigin(const FloatPoint& p)
146 {
147     if (m_maxLayoutViewportOrigin == p)
148         return;
149
150     m_maxLayoutViewportOrigin = p;
151     setPropertyChanged(MaxLayoutViewportOrigin);
152 }
153
154 void ScrollingStateFrameScrollingNode::setHeaderHeight(int headerHeight)
155 {
156     if (m_headerHeight == headerHeight)
157         return;
158
159     m_headerHeight = headerHeight;
160     setPropertyChanged(HeaderHeight);
161 }
162
163 void ScrollingStateFrameScrollingNode::setFooterHeight(int footerHeight)
164 {
165     if (m_footerHeight == footerHeight)
166         return;
167
168     m_footerHeight = footerHeight;
169     setPropertyChanged(FooterHeight);
170 }
171
172 void ScrollingStateFrameScrollingNode::setTopContentInset(float topContentInset)
173 {
174     if (m_topContentInset == topContentInset)
175         return;
176
177     m_topContentInset = topContentInset;
178     setPropertyChanged(TopContentInset);
179 }
180
181 void ScrollingStateFrameScrollingNode::setCounterScrollingLayer(const LayerRepresentation& layerRepresentation)
182 {
183     if (layerRepresentation == m_counterScrollingLayer)
184         return;
185     
186     m_counterScrollingLayer = layerRepresentation;
187     setPropertyChanged(CounterScrollingLayer);
188 }
189
190 void ScrollingStateFrameScrollingNode::setInsetClipLayer(const LayerRepresentation& layerRepresentation)
191 {
192     if (layerRepresentation == m_insetClipLayer)
193         return;
194     
195     m_insetClipLayer = layerRepresentation;
196     setPropertyChanged(InsetClipLayer);
197 }
198
199 void ScrollingStateFrameScrollingNode::setContentShadowLayer(const LayerRepresentation& layerRepresentation)
200 {
201     if (layerRepresentation == m_contentShadowLayer)
202         return;
203     
204     m_contentShadowLayer = layerRepresentation;
205     setPropertyChanged(ContentShadowLayer);
206 }
207
208 void ScrollingStateFrameScrollingNode::setHeaderLayer(const LayerRepresentation& layerRepresentation)
209 {
210     if (layerRepresentation == m_headerLayer)
211         return;
212     
213     m_headerLayer = layerRepresentation;
214     setPropertyChanged(HeaderLayer);
215 }
216
217 void ScrollingStateFrameScrollingNode::setFooterLayer(const LayerRepresentation& layerRepresentation)
218 {
219     if (layerRepresentation == m_footerLayer)
220         return;
221     
222     m_footerLayer = layerRepresentation;
223     setPropertyChanged(FooterLayer);
224 }
225
226 void ScrollingStateFrameScrollingNode::setFixedElementsLayoutRelativeToFrame(bool fixedElementsLayoutRelativeToFrame)
227 {
228     if (fixedElementsLayoutRelativeToFrame == m_fixedElementsLayoutRelativeToFrame)
229         return;
230     
231     m_fixedElementsLayoutRelativeToFrame = fixedElementsLayoutRelativeToFrame;
232     setPropertyChanged(FixedElementsLayoutRelativeToFrame);
233 }
234
235 // Only needed while visual viewports are runtime-switchable.
236 void ScrollingStateFrameScrollingNode::setVisualViewportEnabled(bool visualViewportEnabled)
237 {
238     if (visualViewportEnabled == m_visualViewportEnabled)
239         return;
240     
241     m_visualViewportEnabled = visualViewportEnabled;
242     setPropertyChanged(VisualViewportEnabled);
243 }
244
245 #if !PLATFORM(MAC)
246 void ScrollingStateFrameScrollingNode::setScrollerImpsFromScrollbars(Scrollbar*, Scrollbar*)
247 {
248 }
249 #endif
250
251 void ScrollingStateFrameScrollingNode::dumpProperties(TextStream& ts, ScrollingStateTreeAsTextBehavior behavior) const
252 {
253     ts << "Frame scrolling node";
254     
255     ScrollingStateScrollingNode::dumpProperties(ts, behavior);
256     
257     if (behavior & ScrollingStateTreeAsTextBehaviorIncludeLayerIDs) {
258         ts.dumpProperty("counter scrolling layer ID", m_counterScrollingLayer.layerID());
259         ts.dumpProperty("inset clip layer ID", m_insetClipLayer.layerID());
260         ts.dumpProperty("content shadow layer ID", m_contentShadowLayer.layerID());
261         ts.dumpProperty("header layer ID", m_headerLayer.layerID());
262         ts.dumpProperty("footer layer ID", m_footerLayer.layerID());
263     }
264
265     if (m_frameScaleFactor != 1)
266         ts.dumpProperty("frame scale factor", m_frameScaleFactor);
267     if (m_topContentInset)
268         ts.dumpProperty("top content inset", m_topContentInset);
269     if (m_headerHeight)
270         ts.dumpProperty("header height", m_headerHeight);
271     if (m_footerHeight)
272         ts.dumpProperty("footer height", m_footerHeight);
273     
274     if (m_visualViewportEnabled) {
275         ts.dumpProperty("visual viewport enabled", m_visualViewportEnabled);
276         ts.dumpProperty("layout viewport", m_layoutViewport);
277         ts.dumpProperty("min layout viewport origin", m_minLayoutViewportOrigin);
278         ts.dumpProperty("max layout viewport origin", m_maxLayoutViewportOrigin);
279     }
280     
281     if (m_behaviorForFixed == StickToViewportBounds)
282         ts.dumpProperty("behavior for fixed", m_behaviorForFixed);
283
284     if (!m_eventTrackingRegions.asynchronousDispatchRegion.isEmpty()) {
285         TextStream::GroupScope scope(ts);
286         ts << "asynchronous event dispatch region";
287         for (auto rect : m_eventTrackingRegions.asynchronousDispatchRegion.rects()) {
288             ts << "\n";
289             ts.writeIndent();
290             ts << rect;
291         }
292     }
293
294     if (!m_eventTrackingRegions.eventSpecificSynchronousDispatchRegions.isEmpty()) {
295         for (const auto& synchronousEventRegion : m_eventTrackingRegions.eventSpecificSynchronousDispatchRegions) {
296             TextStream::GroupScope scope(ts);
297             ts << "synchronous event dispatch region for event " << synchronousEventRegion.key;
298             for (auto rect : synchronousEventRegion.value.rects()) {
299                 ts << "\n";
300                 ts.writeIndent();
301                 ts << rect;
302             }
303         }
304     }
305
306     if (m_synchronousScrollingReasons)
307         ts.dumpProperty("Scrolling on main thread because:", ScrollingCoordinator::synchronousScrollingReasonsAsText(m_synchronousScrollingReasons));
308     
309     ts.dumpProperty("behavior for fixed", m_behaviorForFixed);
310
311     if (m_requestedScrollPosition != FloatPoint())
312         ts.dumpProperty("requested scroll position", m_requestedScrollPosition);
313     if (m_requestedScrollPositionRepresentsProgrammaticScroll)
314         ts.dumpProperty("requested scroll position represents programmatic scroll", m_requestedScrollPositionRepresentsProgrammaticScroll);
315
316     if (m_fixedElementsLayoutRelativeToFrame)
317         ts.dumpProperty("fixed elements lay out relative to frame", m_fixedElementsLayoutRelativeToFrame);
318 }
319
320 } // namespace WebCore
321
322 #endif // ENABLE(ASYNC_SCROLLING) || USE(COORDINATED_GRAPHICS)