ccdc832a0c0704503cbce599671f9c46a193119b
[WebKit-https.git] / Source / WebCore / page / scrolling / ScrollingStateFixedNode.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 "ScrollingStateFixedNode.h"
28
29 #include "GraphicsLayer.h"
30 #include "ScrollingStateTree.h"
31 #include "TextStream.h"
32
33 #if ENABLE(ASYNC_SCROLLING) || USE(COORDINATED_GRAPHICS)
34
35 namespace WebCore {
36
37 Ref<ScrollingStateFixedNode> ScrollingStateFixedNode::create(ScrollingStateTree& stateTree, ScrollingNodeID nodeID)
38 {
39     return adoptRef(*new ScrollingStateFixedNode(stateTree, nodeID));
40 }
41
42 ScrollingStateFixedNode::ScrollingStateFixedNode(ScrollingStateTree& tree, ScrollingNodeID nodeID)
43     : ScrollingStateNode(FixedNode, tree, nodeID)
44 {
45 }
46
47 ScrollingStateFixedNode::ScrollingStateFixedNode(const ScrollingStateFixedNode& node, ScrollingStateTree& adoptiveTree)
48     : ScrollingStateNode(node, adoptiveTree)
49     , m_constraints(FixedPositionViewportConstraints(node.viewportConstraints()))
50 {
51 }
52
53 ScrollingStateFixedNode::~ScrollingStateFixedNode()
54 {
55 }
56
57 Ref<ScrollingStateNode> ScrollingStateFixedNode::clone(ScrollingStateTree& adoptiveTree)
58 {
59     return adoptRef(*new ScrollingStateFixedNode(*this, adoptiveTree));
60 }
61
62 void ScrollingStateFixedNode::updateConstraints(const FixedPositionViewportConstraints& constraints)
63 {
64     if (m_constraints == constraints)
65         return;
66
67     m_constraints = constraints;
68     setPropertyChanged(ViewportConstraints);
69 }
70
71 void ScrollingStateFixedNode::syncLayerPositionForViewportRect(const LayoutRect& viewportRect)
72 {
73     FloatPoint position = m_constraints.layerPositionForViewportRect(viewportRect);
74     if (layer().representsGraphicsLayer())
75         static_cast<GraphicsLayer*>(layer())->syncPosition(position);
76 }
77
78 void ScrollingStateFixedNode::dumpProperties(TextStream& ts, int indent) const
79 {
80     ts << "(" << "Fixed 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.alignmentOffset().isEmpty()) {
97         writeIndent(ts, indent + 1);
98         ts << "(alignment offset " << m_constraints.alignmentOffset().width() << " " << m_constraints.alignmentOffset().height() << ")\n";
99     }
100
101     if (!m_constraints.viewportRectAtLastLayout().isEmpty()) {
102         writeIndent(ts, indent + 1);
103         FloatRect viewportRect = m_constraints.viewportRectAtLastLayout();
104         ts << "(viewport rect at last layout: " << viewportRect.x() << " " << viewportRect.y() << " " << viewportRect.width() << " " << viewportRect.height() << ")\n";
105     }
106
107     if (m_constraints.layerPositionAtLastLayout() != FloatPoint()) {
108         writeIndent(ts, indent + 1);
109         ts << "(layer position at last layout " << m_constraints.layerPositionAtLastLayout().x() << " " << m_constraints.layerPositionAtLastLayout().y() << ")\n";
110     }
111 }
112
113 } // namespace WebCore
114
115 #endif // ENABLE(ASYNC_SCROLLING) || USE(COORDINATED_GRAPHICS)