Use "= default" to denote default constructor or destructor
[WebKit-https.git] / Source / WebCore / page / scrolling / ScrollingStateScrollingNode.cpp
1 /*
2  * Copyright (C) 2012, 2015 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 "ScrollingStateScrollingNode.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 ScrollingStateScrollingNode::ScrollingStateScrollingNode(ScrollingStateTree& stateTree, ScrollingNodeType nodeType, ScrollingNodeID nodeID)
37     : ScrollingStateNode(nodeType, stateTree, nodeID)
38 {
39 }
40
41 ScrollingStateScrollingNode::ScrollingStateScrollingNode(const ScrollingStateScrollingNode& stateNode, ScrollingStateTree& adoptiveTree)
42     : ScrollingStateNode(stateNode, adoptiveTree)
43     , m_scrollableAreaSize(stateNode.scrollableAreaSize())
44     , m_totalContentsSize(stateNode.totalContentsSize())
45     , m_reachableContentsSize(stateNode.reachableContentsSize())
46     , m_scrollPosition(stateNode.scrollPosition())
47     , m_requestedScrollPosition(stateNode.requestedScrollPosition())
48     , m_scrollOrigin(stateNode.scrollOrigin())
49 #if ENABLE(CSS_SCROLL_SNAP)
50     , m_snapOffsetsInfo(stateNode.m_snapOffsetsInfo)
51 #endif
52     , m_scrollableAreaParameters(stateNode.scrollableAreaParameters())
53     , m_requestedScrollPositionRepresentsProgrammaticScroll(stateNode.requestedScrollPositionRepresentsProgrammaticScroll())
54     , m_expectsWheelEventTestTrigger(stateNode.expectsWheelEventTestTrigger())
55 {
56     if (hasChangedProperty(ScrolledContentsLayer))
57         setScrolledContentsLayer(stateNode.scrolledContentsLayer().toRepresentation(adoptiveTree.preferredLayerRepresentation()));
58 }
59
60 ScrollingStateScrollingNode::~ScrollingStateScrollingNode() = default;
61
62 void ScrollingStateScrollingNode::setScrollableAreaSize(const FloatSize& size)
63 {
64     if (m_scrollableAreaSize == size)
65         return;
66
67     m_scrollableAreaSize = size;
68     setPropertyChanged(ScrollableAreaSize);
69 }
70
71 void ScrollingStateScrollingNode::setTotalContentsSize(const FloatSize& totalContentsSize)
72 {
73     if (m_totalContentsSize == totalContentsSize)
74         return;
75
76     m_totalContentsSize = totalContentsSize;
77     setPropertyChanged(TotalContentsSize);
78 }
79
80 void ScrollingStateScrollingNode::setReachableContentsSize(const FloatSize& reachableContentsSize)
81 {
82     if (m_reachableContentsSize == reachableContentsSize)
83         return;
84
85     m_reachableContentsSize = reachableContentsSize;
86     setPropertyChanged(ReachableContentsSize);
87 }
88
89 void ScrollingStateScrollingNode::setScrollPosition(const FloatPoint& scrollPosition)
90 {
91     if (m_scrollPosition == scrollPosition)
92         return;
93
94     m_scrollPosition = scrollPosition;
95     setPropertyChanged(ScrollPosition);
96 }
97
98 void ScrollingStateScrollingNode::setScrollOrigin(const IntPoint& scrollOrigin)
99 {
100     if (m_scrollOrigin == scrollOrigin)
101         return;
102
103     m_scrollOrigin = scrollOrigin;
104     setPropertyChanged(ScrollOrigin);
105 }
106
107 #if ENABLE(CSS_SCROLL_SNAP)
108 void ScrollingStateScrollingNode::setHorizontalSnapOffsets(const Vector<float>& snapOffsets)
109 {
110     if (m_snapOffsetsInfo.horizontalSnapOffsets == snapOffsets)
111         return;
112
113     m_snapOffsetsInfo.horizontalSnapOffsets = snapOffsets;
114     setPropertyChanged(HorizontalSnapOffsets);
115 }
116
117 void ScrollingStateScrollingNode::setVerticalSnapOffsets(const Vector<float>& snapOffsets)
118 {
119     if (m_snapOffsetsInfo.verticalSnapOffsets == snapOffsets)
120         return;
121
122     m_snapOffsetsInfo.verticalSnapOffsets = snapOffsets;
123     setPropertyChanged(VerticalSnapOffsets);
124 }
125
126 void ScrollingStateScrollingNode::setHorizontalSnapOffsetRanges(const Vector<ScrollOffsetRange<float>>& scrollOffsetRanges)
127 {
128     if (m_snapOffsetsInfo.horizontalSnapOffsetRanges == scrollOffsetRanges)
129         return;
130
131     m_snapOffsetsInfo.horizontalSnapOffsetRanges = scrollOffsetRanges;
132     setPropertyChanged(HorizontalSnapOffsetRanges);
133 }
134
135 void ScrollingStateScrollingNode::setVerticalSnapOffsetRanges(const Vector<ScrollOffsetRange<float>>& scrollOffsetRanges)
136 {
137     if (m_snapOffsetsInfo.verticalSnapOffsetRanges == scrollOffsetRanges)
138         return;
139
140     m_snapOffsetsInfo.verticalSnapOffsetRanges = scrollOffsetRanges;
141     setPropertyChanged(VerticalSnapOffsetRanges);
142 }
143
144 void ScrollingStateScrollingNode::setCurrentHorizontalSnapPointIndex(unsigned index)
145 {
146     if (m_currentHorizontalSnapPointIndex == index)
147         return;
148     
149     m_currentHorizontalSnapPointIndex = index;
150     setPropertyChanged(CurrentHorizontalSnapOffsetIndex);
151 }
152
153 void ScrollingStateScrollingNode::setCurrentVerticalSnapPointIndex(unsigned index)
154 {
155     if (m_currentVerticalSnapPointIndex == index)
156         return;
157     
158     m_currentVerticalSnapPointIndex = index;
159     setPropertyChanged(CurrentVerticalSnapOffsetIndex);
160 }
161 #endif
162
163 void ScrollingStateScrollingNode::setScrollableAreaParameters(const ScrollableAreaParameters& parameters)
164 {
165     if (m_scrollableAreaParameters == parameters)
166         return;
167
168     m_scrollableAreaParameters = parameters;
169     setPropertyChanged(ScrollableAreaParams);
170 }
171
172 void ScrollingStateScrollingNode::setRequestedScrollPosition(const FloatPoint& requestedScrollPosition, bool representsProgrammaticScroll)
173 {
174     m_requestedScrollPosition = requestedScrollPosition;
175     m_requestedScrollPositionRepresentsProgrammaticScroll = representsProgrammaticScroll;
176     setPropertyChanged(RequestedScrollPosition);
177 }
178
179 void ScrollingStateScrollingNode::setExpectsWheelEventTestTrigger(bool expectsTestTrigger)
180 {
181     if (expectsTestTrigger == m_expectsWheelEventTestTrigger)
182         return;
183
184     m_expectsWheelEventTestTrigger = expectsTestTrigger;
185     setPropertyChanged(ExpectsWheelEventTestTrigger);
186 }
187
188 void ScrollingStateScrollingNode::setScrolledContentsLayer(const LayerRepresentation& layerRepresentation)
189 {
190     if (layerRepresentation == m_scrolledContentsLayer)
191         return;
192
193     m_scrolledContentsLayer = layerRepresentation;
194     setPropertyChanged(ScrolledContentsLayer);
195 }
196
197 void ScrollingStateScrollingNode::dumpProperties(TextStream& ts, ScrollingStateTreeAsTextBehavior behavior) const
198 {
199     ScrollingStateNode::dumpProperties(ts, behavior);
200     
201     if (m_scrollPosition != FloatPoint()) {
202         TextStream::GroupScope scope(ts);
203         ts << "scroll position "
204             << TextStream::FormatNumberRespectingIntegers(m_scrollPosition.x()) << " "
205             << TextStream::FormatNumberRespectingIntegers(m_scrollPosition.y());
206     }
207
208     if (!m_scrollableAreaSize.isEmpty()) {
209         TextStream::GroupScope scope(ts);
210         ts << "scrollable area size "
211             << TextStream::FormatNumberRespectingIntegers(m_scrollableAreaSize.width()) << " "
212             << TextStream::FormatNumberRespectingIntegers(m_scrollableAreaSize.height());
213     }
214
215     if (!m_totalContentsSize.isEmpty()) {
216         TextStream::GroupScope scope(ts);
217         ts << "contents size "
218             << TextStream::FormatNumberRespectingIntegers(m_totalContentsSize.width()) << " "
219             << TextStream::FormatNumberRespectingIntegers(m_totalContentsSize.height());
220     }
221
222     if (m_reachableContentsSize != m_totalContentsSize)
223         ts.dumpProperty("reachable contents size", m_reachableContentsSize);
224
225     if (m_requestedScrollPosition != IntPoint()) {
226         TextStream::GroupScope scope(ts);
227         ts << "requested scroll position "
228             << TextStream::FormatNumberRespectingIntegers(m_requestedScrollPosition.x()) << " "
229             << TextStream::FormatNumberRespectingIntegers(m_requestedScrollPosition.y());
230     }
231     if (m_requestedScrollPositionRepresentsProgrammaticScroll)
232         ts.dumpProperty("requested scroll position represents programmatic scroll", m_requestedScrollPositionRepresentsProgrammaticScroll);
233
234     if (m_scrollOrigin != IntPoint())
235         ts.dumpProperty("scroll origin", m_scrollOrigin);
236
237 #if ENABLE(CSS_SCROLL_SNAP)
238     if (m_snapOffsetsInfo.horizontalSnapOffsets.size())
239         ts.dumpProperty("horizontal snap offsets", m_snapOffsetsInfo.horizontalSnapOffsets);
240
241     if (m_snapOffsetsInfo.verticalSnapOffsets.size())
242         ts.dumpProperty("vertical snap offsets", m_snapOffsetsInfo.verticalSnapOffsets);
243
244     if (m_currentHorizontalSnapPointIndex)
245         ts.dumpProperty("current horizontal snap point index", m_currentHorizontalSnapPointIndex);
246
247     if (m_currentVerticalSnapPointIndex)
248         ts.dumpProperty("current vertical snap point index", m_currentVerticalSnapPointIndex);
249 #endif
250
251     ts.dumpProperty("scrollable area parameters", m_scrollableAreaParameters);
252
253     if (m_expectsWheelEventTestTrigger)
254         ts.dumpProperty("expects wheel event test trigger", m_expectsWheelEventTestTrigger);
255
256     if ((behavior & ScrollingStateTreeAsTextBehaviorIncludeLayerIDs) && m_scrolledContentsLayer.layerID())
257         ts.dumpProperty("scrolled contents layer", m_scrolledContentsLayer.layerID());
258 }
259
260 } // namespace WebCore
261
262 #endif // ENABLE(ASYNC_SCROLLING) || USE(COORDINATED_GRAPHICS)