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#include <wtf/OwnPtr.h>
33
34#if ENABLE(ASYNC_SCROLLING) || USE(COORDINATED_GRAPHICS)
35
36namespace WebCore {
37
38PassRefPtr<ScrollingStateFixedNode> ScrollingStateFixedNode::create(ScrollingStateTree& stateTree, ScrollingNodeID nodeID)
39{
40    return adoptRef(new ScrollingStateFixedNode(stateTree, nodeID));
41}
42
43ScrollingStateFixedNode::ScrollingStateFixedNode(ScrollingStateTree& tree, ScrollingNodeID nodeID)
44    : ScrollingStateNode(FixedNode, tree, nodeID)
45{
46}
47
48ScrollingStateFixedNode::ScrollingStateFixedNode(const ScrollingStateFixedNode& node, ScrollingStateTree& adoptiveTree)
49    : ScrollingStateNode(node, adoptiveTree)
50    , m_constraints(FixedPositionViewportConstraints(node.viewportConstraints()))
51{
52}
53
54ScrollingStateFixedNode::~ScrollingStateFixedNode()
55{
56}
57
58PassRefPtr<ScrollingStateNode> ScrollingStateFixedNode::clone(ScrollingStateTree& adoptiveTree)
59{
60    return adoptRef(new ScrollingStateFixedNode(*this, adoptiveTree));
61}
62
63void ScrollingStateFixedNode::updateConstraints(const FixedPositionViewportConstraints& constraints)
64{
65    if (m_constraints == constraints)
66        return;
67
68    m_constraints = constraints;
69    setPropertyChanged(ViewportConstraints);
70}
71
72void ScrollingStateFixedNode::syncLayerPositionForViewportRect(const LayoutRect& viewportRect)
73{
74    FloatPoint position = m_constraints.layerPositionForViewportRect(viewportRect);
75    if (layer().representsGraphicsLayer())
76        static_cast<GraphicsLayer*>(layer())->syncPosition(position);
77}
78
79void ScrollingStateFixedNode::dumpProperties(TextStream& ts, int indent) const
80{
81    ts << "(" << "Fixed node" << "\n";
82
83    if (m_constraints.anchorEdges()) {
84        writeIndent(ts, indent + 1);
85        ts << "(anchor edges: ";
86        if (m_constraints.hasAnchorEdge(ViewportConstraints::AnchorEdgeLeft))
87            ts << "AnchorEdgeLeft ";
88        if (m_constraints.hasAnchorEdge(ViewportConstraints::AnchorEdgeRight))
89            ts << "AnchorEdgeRight ";
90        if (m_constraints.hasAnchorEdge(ViewportConstraints::AnchorEdgeTop))
91            ts << "AnchorEdgeTop";
92        if (m_constraints.hasAnchorEdge(ViewportConstraints::AnchorEdgeBottom))
93            ts << "AnchorEdgeBottom";
94        ts << ")\n";
95    }
96
97    if (!m_constraints.alignmentOffset().isEmpty()) {
98        writeIndent(ts, indent + 1);
99        ts << "(alignment offset " << m_constraints.alignmentOffset().width() << " " << m_constraints.alignmentOffset().height() << ")\n";
100    }
101
102    if (!m_constraints.viewportRectAtLastLayout().isEmpty()) {
103        writeIndent(ts, indent + 1);
104        FloatRect viewportRect = m_constraints.viewportRectAtLastLayout();
105        ts << "(viewport rect at last layout: " << viewportRect.x() << " " << viewportRect.y() << " " << viewportRect.width() << " " << viewportRect.height() << ")\n";
106    }
107
108    if (m_constraints.layerPositionAtLastLayout() != FloatPoint()) {
109        writeIndent(ts, indent + 1);
110        ts << "(layer position at last layout " << m_constraints.layerPositionAtLastLayout().x() << " " << m_constraints.layerPositionAtLastLayout().y() << ")\n";
111    }
112}
113
114} // namespace WebCore
115
116#endif // ENABLE(ASYNC_SCROLLING) || USE(COORDINATED_GRAPHICS)
117