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