Fix scrolling tree dumping
[WebKit-https.git] / Source / WebCore / page / scrolling / ScrollingStateStickyNode.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 "ScrollingStateStickyNode.h"
28
29 #if ENABLE(ASYNC_SCROLLING) || USE(COORDINATED_GRAPHICS)
30
31 #include "GraphicsLayer.h"
32 #include "ScrollingStateTree.h"
33 #include "TextStream.h"
34
35 namespace WebCore {
36
37 Ref<ScrollingStateStickyNode> ScrollingStateStickyNode::create(ScrollingStateTree& stateTree, ScrollingNodeID nodeID)
38 {
39     return adoptRef(*new ScrollingStateStickyNode(stateTree, nodeID));
40 }
41
42 ScrollingStateStickyNode::ScrollingStateStickyNode(ScrollingStateTree& tree, ScrollingNodeID nodeID)
43     : ScrollingStateNode(StickyNode, tree, nodeID)
44 {
45 }
46
47 ScrollingStateStickyNode::ScrollingStateStickyNode(const ScrollingStateStickyNode& node, ScrollingStateTree& adoptiveTree)
48     : ScrollingStateNode(node, adoptiveTree)
49     , m_constraints(StickyPositionViewportConstraints(node.viewportConstraints()))
50 {
51 }
52
53 ScrollingStateStickyNode::~ScrollingStateStickyNode()
54 {
55 }
56
57 Ref<ScrollingStateNode> ScrollingStateStickyNode::clone(ScrollingStateTree& adoptiveTree)
58 {
59     return adoptRef(*new ScrollingStateStickyNode(*this, adoptiveTree));
60 }
61
62 void ScrollingStateStickyNode::updateConstraints(const StickyPositionViewportConstraints& constraints)
63 {
64     if (m_constraints == constraints)
65         return;
66
67     m_constraints = constraints;
68     setPropertyChanged(ViewportConstraints);
69 }
70
71 void ScrollingStateStickyNode::syncLayerPositionForViewportRect(const LayoutRect& viewportRect)
72 {
73     FloatPoint position = m_constraints.layerPositionForConstrainingRect(viewportRect);
74     if (layer().representsGraphicsLayer())
75         static_cast<GraphicsLayer*>(layer())->syncPosition(position);
76 }
77
78 void ScrollingStateStickyNode::dumpProperties(TextStream& ts, int indent, ScrollingStateTreeAsTextBehavior) const
79 {
80     ts << "(" << "Sticky node" << "\n";
81
82     if (m_constraints.anchorEdges()) {
83         writeIndent(ts, indent + 1);
84         ts << "(anchor edges: ";
85         if (m_constraints.hasAnchorEdge(ViewportConstraints::AnchorEdgeLeft))
86             ts << "AnchorEdgeLeft ";
87         if (m_constraints.hasAnchorEdge(ViewportConstraints::AnchorEdgeRight))
88             ts << "AnchorEdgeRight ";
89         if (m_constraints.hasAnchorEdge(ViewportConstraints::AnchorEdgeTop))
90             ts << "AnchorEdgeTop ";
91         if (m_constraints.hasAnchorEdge(ViewportConstraints::AnchorEdgeBottom))
92             ts << "AnchorEdgeBottom";
93         ts << ")\n";
94     }
95
96     if (m_constraints.hasAnchorEdge(ViewportConstraints::AnchorEdgeLeft)) {
97         writeIndent(ts, indent + 1);
98         ts << "(left offset " << m_constraints.leftOffset() << ")\n";
99     }
100     if (m_constraints.hasAnchorEdge(ViewportConstraints::AnchorEdgeRight)) {
101         writeIndent(ts, indent + 1);
102         ts << "(right offset " << m_constraints.rightOffset() << ")\n";
103     }
104     if (m_constraints.hasAnchorEdge(ViewportConstraints::AnchorEdgeTop)) {
105         writeIndent(ts, indent + 1);
106         ts << "(top offset " << m_constraints.topOffset() << ")\n";
107     }
108     if (m_constraints.hasAnchorEdge(ViewportConstraints::AnchorEdgeBottom)) {
109         writeIndent(ts, indent + 1);
110         ts << "(bottom offset " << m_constraints.bottomOffset() << ")\n";
111     }
112
113     writeIndent(ts, indent + 1);
114     FloatRect r = m_constraints.containingBlockRect();
115     ts << "(containing block rect " << r.x() << ", " << r.y() << " " << r.width() << " x " << r.height() << ")\n";
116
117     writeIndent(ts, indent + 1);
118     r = m_constraints.stickyBoxRect();
119     ts << "(sticky box rect " << r.x() << " " << r.y() << " " << r.width() << " " << r.height() << ")\n";
120
121     writeIndent(ts, indent + 1);
122     r = m_constraints.constrainingRectAtLastLayout();
123     ts << "(constraining rect " << r.x() << " " << r.y() << " " << r.width() << " " << r.height() << ")\n";
124
125     writeIndent(ts, indent + 1);
126     ts << "(sticky offset at last layout " << m_constraints.stickyOffsetAtLastLayout().width() << " " << m_constraints.stickyOffsetAtLastLayout().height() << ")\n";
127
128     writeIndent(ts, indent + 1);
129     ts << "(layer position at last layout " << m_constraints.layerPositionAtLastLayout().x() << " " << m_constraints.layerPositionAtLastLayout().y() << ")\n";
130 }
131
132 } // namespace WebCore
133
134 #endif // ENABLE(ASYNC_SCROLLING) || USE(COORDINATED_GRAPHICS)