4b11681a812588b98423715bd25f8c04a1af2086
[WebKit-https.git] / Source / WebCore / page / scrolling / ScrollingStateScrollingNode.cpp
1 /*
2  * Copyright (C) 2012 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 #include "ScrollingStateTree.h"
30 #include <wtf/OwnPtr.h>
31
32 #if ENABLE(THREADED_SCROLLING)
33
34 namespace WebCore {
35
36 PassOwnPtr<ScrollingStateScrollingNode> ScrollingStateScrollingNode::create(ScrollingStateTree* stateTree)
37 {
38     return adoptPtr(new ScrollingStateScrollingNode(stateTree));
39 }
40
41 ScrollingStateScrollingNode::ScrollingStateScrollingNode(ScrollingStateTree* stateTree)
42     : ScrollingStateNode(stateTree)
43     , m_changedProperties(0)
44     , m_wheelEventHandlerCount(0)
45     , m_shouldUpdateScrollLayerPositionOnMainThread(0)
46     , m_horizontalScrollElasticity(ScrollElasticityNone)
47     , m_verticalScrollElasticity(ScrollElasticityNone)
48     , m_hasEnabledHorizontalScrollbar(false)
49     , m_hasEnabledVerticalScrollbar(false)
50     , m_requestedScrollPositionRepresentsProgrammaticScroll(false)
51     , m_horizontalScrollbarMode(ScrollbarAuto)
52     , m_verticalScrollbarMode(ScrollbarAuto)
53 {
54 }
55
56 ScrollingStateScrollingNode::ScrollingStateScrollingNode(ScrollingStateScrollingNode* stateNode)
57     : ScrollingStateNode(stateNode)
58     , m_changedProperties(stateNode->changedProperties())
59     , m_viewportRect(stateNode->viewportRect())
60     , m_contentsSize(stateNode->contentsSize())
61     , m_nonFastScrollableRegion(stateNode->nonFastScrollableRegion())
62     , m_wheelEventHandlerCount(stateNode->wheelEventHandlerCount())
63     , m_shouldUpdateScrollLayerPositionOnMainThread(stateNode->shouldUpdateScrollLayerPositionOnMainThread())
64     , m_horizontalScrollElasticity(stateNode->horizontalScrollElasticity())
65     , m_verticalScrollElasticity(stateNode->verticalScrollElasticity())
66     , m_hasEnabledHorizontalScrollbar(stateNode->hasEnabledHorizontalScrollbar())
67     , m_hasEnabledVerticalScrollbar(stateNode->hasEnabledVerticalScrollbar())
68     , m_requestedScrollPositionRepresentsProgrammaticScroll(stateNode->requestedScrollPositionRepresentsProgrammaticScroll())
69     , m_horizontalScrollbarMode(stateNode->horizontalScrollbarMode())
70     , m_verticalScrollbarMode(stateNode->verticalScrollbarMode())
71     , m_requestedScrollPosition(stateNode->requestedScrollPosition())
72     , m_scrollOrigin(stateNode->scrollOrigin())
73 {
74 }
75
76 ScrollingStateScrollingNode::~ScrollingStateScrollingNode()
77 {
78 }
79
80 void ScrollingStateScrollingNode::setHasChangedProperties()
81 {
82     m_changedProperties = All;
83     ScrollingStateNode::setHasChangedProperties();
84 }
85
86 PassOwnPtr<ScrollingStateNode> ScrollingStateScrollingNode::cloneAndResetNode()
87 {
88     OwnPtr<ScrollingStateScrollingNode> clone = adoptPtr(new ScrollingStateScrollingNode(this));
89
90     // Now that this node is cloned, reset our change properties.
91     setScrollLayerDidChange(false);
92     resetChangedProperties();
93
94     cloneAndResetChildNodes(clone.get());
95     return clone.release();
96 }
97
98 void ScrollingStateScrollingNode::setViewportRect(const IntRect& viewportRect)
99 {
100     if (m_viewportRect == viewportRect)
101         return;
102
103     m_viewportRect = viewportRect;
104     m_changedProperties |= ViewportRect;
105     m_scrollingStateTree->setHasChangedProperties(true);
106 }
107
108 void ScrollingStateScrollingNode::setContentsSize(const IntSize& contentsSize)
109 {
110     if (m_contentsSize == contentsSize)
111         return;
112
113     m_contentsSize = contentsSize;
114     m_changedProperties |= ContentsSize;
115     m_scrollingStateTree->setHasChangedProperties(true);
116 }
117
118 void ScrollingStateScrollingNode::setNonFastScrollableRegion(const Region& nonFastScrollableRegion)
119 {
120     if (m_nonFastScrollableRegion == nonFastScrollableRegion)
121         return;
122
123     m_nonFastScrollableRegion = nonFastScrollableRegion;
124     m_changedProperties |= NonFastScrollableRegion;
125     m_scrollingStateTree->setHasChangedProperties(true);
126 }
127
128 void ScrollingStateScrollingNode::setWheelEventHandlerCount(unsigned wheelEventHandlerCount)
129 {
130     if (m_wheelEventHandlerCount == wheelEventHandlerCount)
131         return;
132
133     m_wheelEventHandlerCount = wheelEventHandlerCount;
134     m_changedProperties |= WheelEventHandlerCount;
135     m_scrollingStateTree->setHasChangedProperties(true);
136 }
137
138 void ScrollingStateScrollingNode::setShouldUpdateScrollLayerPositionOnMainThread(MainThreadScrollingReasons reasons)
139 {
140     if (m_shouldUpdateScrollLayerPositionOnMainThread == reasons)
141         return;
142
143     m_shouldUpdateScrollLayerPositionOnMainThread = reasons;
144     m_changedProperties |= ShouldUpdateScrollLayerPositionOnMainThread;
145     m_scrollingStateTree->setHasChangedProperties(true);
146 }
147
148 void ScrollingStateScrollingNode::setHorizontalScrollElasticity(ScrollElasticity horizontalScrollElasticity)
149 {
150     if (m_horizontalScrollElasticity == horizontalScrollElasticity)
151         return;
152
153     m_horizontalScrollElasticity = horizontalScrollElasticity;
154     m_changedProperties |= HorizontalScrollElasticity;
155     m_scrollingStateTree->setHasChangedProperties(true);
156 }
157
158 void ScrollingStateScrollingNode::setVerticalScrollElasticity(ScrollElasticity verticalScrollElasticity)
159 {
160     if (m_verticalScrollElasticity == verticalScrollElasticity)
161         return;
162
163     m_verticalScrollElasticity = verticalScrollElasticity;
164     m_changedProperties |= VerticalScrollElasticity;
165     m_scrollingStateTree->setHasChangedProperties(true);
166 }
167
168 void ScrollingStateScrollingNode::setHasEnabledHorizontalScrollbar(bool hasEnabledHorizontalScrollbar)
169 {
170     if (m_hasEnabledHorizontalScrollbar == hasEnabledHorizontalScrollbar)
171         return;
172
173     m_hasEnabledHorizontalScrollbar = hasEnabledHorizontalScrollbar;
174     m_changedProperties |= HasEnabledHorizontalScrollbar;
175     m_scrollingStateTree->setHasChangedProperties(true);
176 }
177
178 void ScrollingStateScrollingNode::setHasEnabledVerticalScrollbar(bool hasEnabledVerticalScrollbar)
179 {
180     if (m_hasEnabledVerticalScrollbar == hasEnabledVerticalScrollbar)
181         return;
182
183     m_hasEnabledVerticalScrollbar = hasEnabledVerticalScrollbar;
184     m_changedProperties |= HasEnabledVerticalScrollbar;
185     m_scrollingStateTree->setHasChangedProperties(true);
186 }
187
188 void ScrollingStateScrollingNode::setHorizontalScrollbarMode(ScrollbarMode horizontalScrollbarMode)
189 {
190     if (m_horizontalScrollbarMode == horizontalScrollbarMode)
191         return;
192
193     m_horizontalScrollbarMode = horizontalScrollbarMode;
194     m_changedProperties |= HorizontalScrollbarMode;
195     m_scrollingStateTree->setHasChangedProperties(true);
196 }
197
198 void ScrollingStateScrollingNode::setVerticalScrollbarMode(ScrollbarMode verticalScrollbarMode)
199 {
200     if (m_verticalScrollbarMode == verticalScrollbarMode)
201         return;
202
203     m_verticalScrollbarMode = verticalScrollbarMode;
204     m_changedProperties |= VerticalScrollbarMode;
205     m_scrollingStateTree->setHasChangedProperties(true);
206 }
207
208 void ScrollingStateScrollingNode::setRequestedScrollPosition(const IntPoint& requestedScrollPosition, bool representsProgrammaticScroll)
209 {
210     m_requestedScrollPosition = requestedScrollPosition;
211     m_requestedScrollPositionRepresentsProgrammaticScroll = representsProgrammaticScroll;
212     m_changedProperties |= RequestedScrollPosition;
213     m_scrollingStateTree->setHasChangedProperties(true);
214 }
215
216 void ScrollingStateScrollingNode::setScrollOrigin(const IntPoint& scrollOrigin)
217 {
218     if (m_scrollOrigin == scrollOrigin)
219         return;
220
221     m_scrollOrigin = scrollOrigin;
222     m_changedProperties |= ScrollOrigin;
223     m_scrollingStateTree->setHasChangedProperties(true);
224 }
225
226 } // namespace WebCore
227
228 #endif // ENABLE(THREADED_SCROLLING)