Fix scrolling tree dumping
[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 "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_horizontalSnapOffsets(stateNode.horizontalSnapOffsets())
51     , m_verticalSnapOffsets(stateNode.verticalSnapOffsets())
52 #endif
53     , m_scrollableAreaParameters(stateNode.scrollableAreaParameters())
54     , m_requestedScrollPositionRepresentsProgrammaticScroll(stateNode.requestedScrollPositionRepresentsProgrammaticScroll())
55     , m_expectsWheelEventTestTrigger(stateNode.expectsWheelEventTestTrigger())
56 {
57 }
58
59 ScrollingStateScrollingNode::~ScrollingStateScrollingNode()
60 {
61 }
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::setScrollPosition(const FloatPoint& scrollPosition)
91 {
92     if (m_scrollPosition == scrollPosition)
93         return;
94
95     m_scrollPosition = scrollPosition;
96     setPropertyChanged(ScrollPosition);
97 }
98
99 void ScrollingStateScrollingNode::setScrollOrigin(const IntPoint& scrollOrigin)
100 {
101     if (m_scrollOrigin == scrollOrigin)
102         return;
103
104     m_scrollOrigin = scrollOrigin;
105     setPropertyChanged(ScrollOrigin);
106 }
107
108 #if ENABLE(CSS_SCROLL_SNAP)
109 void ScrollingStateScrollingNode::setHorizontalSnapOffsets(const Vector<float>& snapOffsets)
110 {
111     if (m_horizontalSnapOffsets == snapOffsets)
112         return;
113
114     m_horizontalSnapOffsets = snapOffsets;
115     setPropertyChanged(HorizontalSnapOffsets);
116 }
117
118 void ScrollingStateScrollingNode::setVerticalSnapOffsets(const Vector<float>& snapOffsets)
119 {
120     if (m_verticalSnapOffsets == snapOffsets)
121         return;
122
123     m_verticalSnapOffsets = snapOffsets;
124     setPropertyChanged(VerticalSnapOffsets);
125 }
126
127 void ScrollingStateScrollingNode::setCurrentHorizontalSnapPointIndex(unsigned index)
128 {
129     if (m_currentHorizontalSnapPointIndex == index)
130         return;
131     
132     m_currentHorizontalSnapPointIndex = index;
133     setPropertyChanged(CurrentHorizontalSnapOffsetIndex);
134 }
135
136 void ScrollingStateScrollingNode::setCurrentVerticalSnapPointIndex(unsigned index)
137 {
138     if (m_currentVerticalSnapPointIndex == index)
139         return;
140     
141     m_currentVerticalSnapPointIndex = index;
142     setPropertyChanged(CurrentVerticalSnapOffsetIndex);
143 }
144 #endif
145
146 void ScrollingStateScrollingNode::setScrollableAreaParameters(const ScrollableAreaParameters& parameters)
147 {
148     if (m_scrollableAreaParameters == parameters)
149         return;
150
151     m_scrollableAreaParameters = parameters;
152     setPropertyChanged(ScrollableAreaParams);
153 }
154
155 void ScrollingStateScrollingNode::setRequestedScrollPosition(const FloatPoint& requestedScrollPosition, bool representsProgrammaticScroll)
156 {
157     m_requestedScrollPosition = requestedScrollPosition;
158     m_requestedScrollPositionRepresentsProgrammaticScroll = representsProgrammaticScroll;
159     setPropertyChanged(RequestedScrollPosition);
160 }
161
162 void ScrollingStateScrollingNode::setExpectsWheelEventTestTrigger(bool expectsTestTrigger)
163 {
164     if (expectsTestTrigger == m_expectsWheelEventTestTrigger)
165         return;
166
167     m_expectsWheelEventTestTrigger = expectsTestTrigger;
168     setPropertyChanged(ExpectsWheelEventTestTrigger);
169 }
170
171 void ScrollingStateScrollingNode::dumpProperties(TextStream& ts, int indent, ScrollingStateTreeAsTextBehavior) const
172 {
173     if (m_scrollPosition != FloatPoint()) {
174         writeIndent(ts, indent + 1);
175         ts << "(scroll position "
176             << TextStream::FormatNumberRespectingIntegers(m_scrollPosition.x()) << " "
177             << TextStream::FormatNumberRespectingIntegers(m_scrollPosition.y()) << ")\n";
178     }
179
180     if (!m_scrollableAreaSize.isEmpty()) {
181         writeIndent(ts, indent + 1);
182         ts << "(scrollable area size "
183             << TextStream::FormatNumberRespectingIntegers(m_scrollableAreaSize.width()) << " "
184             << TextStream::FormatNumberRespectingIntegers(m_scrollableAreaSize.height()) << ")\n";
185     }
186
187     if (!m_totalContentsSize.isEmpty()) {
188         writeIndent(ts, indent + 1);
189         ts << "(contents size "
190             << TextStream::FormatNumberRespectingIntegers(m_totalContentsSize.width()) << " "
191             << TextStream::FormatNumberRespectingIntegers(m_totalContentsSize.height()) << ")\n";
192     }
193
194     if (m_requestedScrollPosition != IntPoint()) {
195         writeIndent(ts, indent + 1);
196         ts << "(requested scroll position "
197             << TextStream::FormatNumberRespectingIntegers(m_requestedScrollPosition.x()) << " "
198             << TextStream::FormatNumberRespectingIntegers(m_requestedScrollPosition.y()) << ")\n";
199     }
200
201     if (m_scrollOrigin != IntPoint()) {
202         writeIndent(ts, indent + 1);
203         ts << "(scroll origin " << m_scrollOrigin.x() << " " << m_scrollOrigin.y() << ")\n";
204     }
205 }
206
207 } // namespace WebCore
208
209 #endif // ENABLE(ASYNC_SCROLLING) || USE(COORDINATED_GRAPHICS)