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