Use "= default" to denote default constructor or destructor
[WebKit-https.git] / Source / WebCore / page / scrolling / ScrollingTreeFrameScrollingNode.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 "ScrollingTreeFrameScrollingNode.h"
28
29 #if ENABLE(ASYNC_SCROLLING)
30
31 #include "FrameView.h"
32 #include "Logging.h"
33 #include "ScrollingStateTree.h"
34 #include "ScrollingTree.h"
35 #include <wtf/text/TextStream.h>
36
37 namespace WebCore {
38
39 ScrollingTreeFrameScrollingNode::ScrollingTreeFrameScrollingNode(ScrollingTree& scrollingTree, ScrollingNodeID nodeID)
40     : ScrollingTreeScrollingNode(scrollingTree, FrameScrollingNode, nodeID)
41 {
42 }
43
44 ScrollingTreeFrameScrollingNode::~ScrollingTreeFrameScrollingNode() = default;
45
46 void ScrollingTreeFrameScrollingNode::commitStateBeforeChildren(const ScrollingStateNode& stateNode)
47 {
48     ScrollingTreeScrollingNode::commitStateBeforeChildren(stateNode);
49     
50     const ScrollingStateFrameScrollingNode& state = downcast<ScrollingStateFrameScrollingNode>(stateNode);
51
52     if (state.hasChangedProperty(ScrollingStateFrameScrollingNode::FrameScaleFactor))
53         m_frameScaleFactor = state.frameScaleFactor();
54
55     if (state.hasChangedProperty(ScrollingStateFrameScrollingNode::ReasonsForSynchronousScrolling))
56         m_synchronousScrollingReasons = state.synchronousScrollingReasons();
57
58     if (state.hasChangedProperty(ScrollingStateFrameScrollingNode::HeaderHeight))
59         m_headerHeight = state.headerHeight();
60
61     if (state.hasChangedProperty(ScrollingStateFrameScrollingNode::FooterHeight))
62         m_footerHeight = state.footerHeight();
63
64     if (state.hasChangedProperty(ScrollingStateFrameScrollingNode::BehaviorForFixedElements))
65         m_behaviorForFixed = state.scrollBehaviorForFixedElements();
66
67     if (state.hasChangedProperty(ScrollingStateFrameScrollingNode::TopContentInset))
68         m_topContentInset = state.topContentInset();
69
70     if (state.hasChangedProperty(ScrollingStateFrameScrollingNode::FixedElementsLayoutRelativeToFrame))
71         m_fixedElementsLayoutRelativeToFrame = state.fixedElementsLayoutRelativeToFrame();
72
73     if (state.hasChangedProperty(ScrollingStateFrameScrollingNode::LayoutViewport))
74         m_layoutViewport = state.layoutViewport();
75
76     if (state.hasChangedProperty(ScrollingStateFrameScrollingNode::MinLayoutViewportOrigin))
77         m_minLayoutViewportOrigin = state.minLayoutViewportOrigin();
78
79     if (state.hasChangedProperty(ScrollingStateFrameScrollingNode::MaxLayoutViewportOrigin))
80         m_maxLayoutViewportOrigin = state.maxLayoutViewportOrigin();
81 }
82
83 void ScrollingTreeFrameScrollingNode::scrollBy(const FloatSize& delta)
84 {
85     setScrollPosition(scrollPosition() + delta);
86 }
87
88 void ScrollingTreeFrameScrollingNode::scrollByWithoutContentEdgeConstraints(const FloatSize& offset)
89 {
90     setScrollPositionWithoutContentEdgeConstraints(scrollPosition() + offset);
91 }
92
93 void ScrollingTreeFrameScrollingNode::setScrollPosition(const FloatPoint& scrollPosition)
94 {
95     FloatPoint newScrollPosition = scrollPosition.constrainedBetween(minimumScrollPosition(), maximumScrollPosition());
96     setScrollPositionWithoutContentEdgeConstraints(newScrollPosition);
97 }
98
99 FloatRect ScrollingTreeFrameScrollingNode::layoutViewportForScrollPosition(const FloatPoint& visibleContentOrigin, float scale) const
100 {
101     ASSERT(scrollingTree().visualViewportEnabled());
102
103     FloatRect visibleContentRect(visibleContentOrigin, scrollableAreaSize());
104     LayoutRect visualViewport(FrameView::visibleDocumentRect(visibleContentRect, headerHeight(), footerHeight(), totalContentsSize(), scale));
105     LayoutRect layoutViewport(m_layoutViewport);
106
107     LOG_WITH_STREAM(Scrolling, stream << "\nScrolling thread: " << "(visibleContentOrigin " << visibleContentOrigin << ") fixed behavior " << m_behaviorForFixed);
108     LOG_WITH_STREAM(Scrolling, stream << "  layoutViewport: " << layoutViewport);
109     LOG_WITH_STREAM(Scrolling, stream << "  visualViewport: " << visualViewport);
110     LOG_WITH_STREAM(Scrolling, stream << "  scroll positions: min: " << minLayoutViewportOrigin() << " max: "<< maxLayoutViewportOrigin());
111
112     LayoutPoint newLocation = FrameView::computeLayoutViewportOrigin(LayoutRect(visualViewport), LayoutPoint(minLayoutViewportOrigin()), LayoutPoint(maxLayoutViewportOrigin()), layoutViewport, m_behaviorForFixed);
113
114     if (layoutViewport.location() != newLocation) {
115         layoutViewport.setLocation(newLocation);
116         LOG_WITH_STREAM(Scrolling, stream << " new layoutViewport " << layoutViewport);
117     }
118
119     return layoutViewport;
120 }
121
122 FloatSize ScrollingTreeFrameScrollingNode::viewToContentsOffset(const FloatPoint& scrollPosition) const
123 {
124     return toFloatSize(scrollPosition) - FloatSize(0, headerHeight() + topContentInset());
125 }
126
127 void ScrollingTreeFrameScrollingNode::dumpProperties(TextStream& ts, ScrollingStateTreeAsTextBehavior behavior) const
128 {
129     ts << "frame scrolling node";
130     ScrollingTreeScrollingNode::dumpProperties(ts, behavior);
131
132     ts.dumpProperty("layout viewport", m_layoutViewport);
133     ts.dumpProperty("min layoutViewport origin", m_minLayoutViewportOrigin);
134     ts.dumpProperty("max layoutViewport origin", m_maxLayoutViewportOrigin);
135
136     if (m_frameScaleFactor != 1)
137         ts.dumpProperty("frame scale factor", m_frameScaleFactor);
138     if (m_topContentInset)
139         ts.dumpProperty("top content inset", m_topContentInset);
140
141     if (m_headerHeight)
142         ts.dumpProperty("header height", m_headerHeight);
143     if (m_footerHeight)
144         ts.dumpProperty("footer height", m_footerHeight);
145     if (m_synchronousScrollingReasons)
146         ts.dumpProperty("synchronous scrolling reasons", ScrollingCoordinator::synchronousScrollingReasonsAsText(m_synchronousScrollingReasons));
147
148     ts.dumpProperty("behavior for fixed", m_behaviorForFixed);
149     if (m_fixedElementsLayoutRelativeToFrame)
150         ts.dumpProperty("fixed elements lay out relative to frame", m_fixedElementsLayoutRelativeToFrame);
151 }
152
153
154 } // namespace WebCore
155
156 #endif // ENABLE(ASYNC_SCROLLING)