Use "= default" to denote default constructor or destructor
[WebKit-https.git] / Source / WebCore / page / scrolling / ScrollingTreeScrollingNode.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 "ScrollingTreeScrollingNode.h"
28
29 #if ENABLE(ASYNC_SCROLLING)
30
31 #include "ScrollingStateTree.h"
32 #include "ScrollingTree.h"
33 #include <wtf/text/TextStream.h>
34
35 namespace WebCore {
36
37 ScrollingTreeScrollingNode::ScrollingTreeScrollingNode(ScrollingTree& scrollingTree, ScrollingNodeType nodeType, ScrollingNodeID nodeID)
38     : ScrollingTreeNode(scrollingTree, nodeType, nodeID)
39 {
40 }
41
42 ScrollingTreeScrollingNode::~ScrollingTreeScrollingNode() = default;
43
44 void ScrollingTreeScrollingNode::commitStateBeforeChildren(const ScrollingStateNode& stateNode)
45 {
46     const ScrollingStateScrollingNode& state = downcast<ScrollingStateScrollingNode>(stateNode);
47
48     if (state.hasChangedProperty(ScrollingStateScrollingNode::ScrollableAreaSize))
49         m_scrollableAreaSize = state.scrollableAreaSize();
50
51     if (state.hasChangedProperty(ScrollingStateScrollingNode::TotalContentsSize)) {
52         if (scrollingTree().isRubberBandInProgress())
53             m_totalContentsSizeForRubberBand = m_totalContentsSize;
54         else
55             m_totalContentsSizeForRubberBand = state.totalContentsSize();
56
57         m_totalContentsSize = state.totalContentsSize();
58     }
59
60     if (state.hasChangedProperty(ScrollingStateScrollingNode::ReachableContentsSize))
61         m_reachableContentsSize = state.reachableContentsSize();
62
63     if (state.hasChangedProperty(ScrollingStateScrollingNode::ScrollPosition))
64         m_lastCommittedScrollPosition = state.scrollPosition();
65
66     if (state.hasChangedProperty(ScrollingStateScrollingNode::ScrollOrigin))
67         m_scrollOrigin = state.scrollOrigin();
68
69 #if ENABLE(CSS_SCROLL_SNAP)
70     if (state.hasChangedProperty(ScrollingStateScrollingNode::HorizontalSnapOffsets))
71         m_snapOffsetsInfo.horizontalSnapOffsets = state.horizontalSnapOffsets();
72
73     if (state.hasChangedProperty(ScrollingStateScrollingNode::VerticalSnapOffsets))
74         m_snapOffsetsInfo.verticalSnapOffsets = state.verticalSnapOffsets();
75
76     if (state.hasChangedProperty(ScrollingStateScrollingNode::HorizontalSnapOffsetRanges))
77         m_snapOffsetsInfo.horizontalSnapOffsetRanges = state.horizontalSnapOffsetRanges();
78
79     if (state.hasChangedProperty(ScrollingStateScrollingNode::VerticalSnapOffsetRanges))
80         m_snapOffsetsInfo.verticalSnapOffsetRanges = state.verticalSnapOffsetRanges();
81
82     if (state.hasChangedProperty(ScrollingStateScrollingNode::CurrentHorizontalSnapOffsetIndex))
83         m_currentHorizontalSnapPointIndex = state.currentHorizontalSnapPointIndex();
84
85     if (state.hasChangedProperty(ScrollingStateScrollingNode::CurrentVerticalSnapOffsetIndex))
86         m_currentVerticalSnapPointIndex = state.currentVerticalSnapPointIndex();
87 #endif
88
89     if (state.hasChangedProperty(ScrollingStateScrollingNode::ScrollableAreaParams))
90         m_scrollableAreaParameters = state.scrollableAreaParameters();
91 }
92
93 void ScrollingTreeScrollingNode::commitStateAfterChildren(const ScrollingStateNode& stateNode)
94 {
95     const ScrollingStateScrollingNode& scrollingStateNode = downcast<ScrollingStateScrollingNode>(stateNode);
96     if (scrollingStateNode.hasChangedProperty(ScrollingStateScrollingNode::RequestedScrollPosition))
97         scrollingTree().scrollingTreeNodeRequestsScroll(scrollingNodeID(), scrollingStateNode.requestedScrollPosition(), scrollingStateNode.requestedScrollPositionRepresentsProgrammaticScroll());
98 }
99
100 void ScrollingTreeScrollingNode::updateLayersAfterAncestorChange(const ScrollingTreeNode& changedNode, const FloatRect& fixedPositionRect, const FloatSize& cumulativeDelta)
101 {
102     if (!m_children)
103         return;
104
105     for (auto& child : *m_children)
106         child->updateLayersAfterAncestorChange(changedNode, fixedPositionRect, cumulativeDelta);
107 }
108
109 void ScrollingTreeScrollingNode::setScrollPosition(const FloatPoint& scrollPosition)
110 {
111     FloatPoint newScrollPosition = scrollPosition.constrainedBetween(minimumScrollPosition(), maximumScrollPosition());
112     setScrollPositionWithoutContentEdgeConstraints(newScrollPosition);
113 }
114
115 void ScrollingTreeScrollingNode::setScrollPositionWithoutContentEdgeConstraints(const FloatPoint& scrollPosition)
116 {
117     setScrollLayerPosition(scrollPosition, { });
118     scrollingTree().scrollingTreeNodeDidScroll(scrollingNodeID(), scrollPosition, std::nullopt);
119 }
120
121 FloatPoint ScrollingTreeScrollingNode::minimumScrollPosition() const
122 {
123     return FloatPoint();
124 }
125
126 FloatPoint ScrollingTreeScrollingNode::maximumScrollPosition() const
127 {
128     FloatPoint contentSizePoint(totalContentsSize());
129     return FloatPoint(contentSizePoint - scrollableAreaSize()).expandedTo(FloatPoint());
130 }
131
132 void ScrollingTreeScrollingNode::dumpProperties(TextStream& ts, ScrollingStateTreeAsTextBehavior behavior) const
133 {
134     ScrollingTreeNode::dumpProperties(ts, behavior);
135     ts.dumpProperty("scrollable area size", m_scrollableAreaSize);
136     ts.dumpProperty("total content size", m_totalContentsSize);
137     if (m_totalContentsSizeForRubberBand != m_totalContentsSize)
138         ts.dumpProperty("total content size for rubber band", m_totalContentsSizeForRubberBand);
139     if (m_reachableContentsSize != m_totalContentsSize)
140         ts.dumpProperty("reachable content size", m_reachableContentsSize);
141     ts.dumpProperty("last committed scroll position", m_lastCommittedScrollPosition);
142     if (m_scrollOrigin != IntPoint())
143         ts.dumpProperty("scroll origin", m_scrollOrigin);
144
145 #if ENABLE(CSS_SCROLL_SNAP)
146     if (m_snapOffsetsInfo.horizontalSnapOffsets.size())
147         ts.dumpProperty("horizontal snap offsets", m_snapOffsetsInfo.horizontalSnapOffsets);
148
149     if (m_snapOffsetsInfo.verticalSnapOffsets.size())
150         ts.dumpProperty("vertical snap offsets", m_snapOffsetsInfo.verticalSnapOffsets);
151
152     if (m_currentHorizontalSnapPointIndex)
153         ts.dumpProperty("current horizontal snap point index", m_currentHorizontalSnapPointIndex);
154
155     if (m_currentVerticalSnapPointIndex)
156         ts.dumpProperty("current vertical snap point index", m_currentVerticalSnapPointIndex);
157     
158 #endif
159
160     ts.dumpProperty("scrollable area parameters", m_scrollableAreaParameters);
161 }
162
163 } // namespace WebCore
164
165 #endif // ENABLE(ASYNC_SCROLLING)