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#pragma once
27
28#if ENABLE(ASYNC_SCROLLING)
29
30#include "IntRect.h"
31#include "ScrollTypes.h"
32#include "ScrollingCoordinator.h"
33#include "ScrollingStateNode.h"
34#include "TouchAction.h"
35#include <wtf/RefCounted.h>
36#include <wtf/TypeCasts.h>
37
38namespace WebCore {
39
40class ScrollingStateFixedNode;
41class ScrollingTreeFrameScrollingNode;
42class ScrollingTreeScrollingNode;
43
44class ScrollingTreeNode : public ThreadSafeRefCounted<ScrollingTreeNode> {
45 friend class ScrollingTree;
46public:
47 virtual ~ScrollingTreeNode();
48
49 ScrollingNodeType nodeType() const { return m_nodeType; }
50 ScrollingNodeID scrollingNodeID() const { return m_nodeID; }
51
52 bool isFixedNode() const { return nodeType() == ScrollingNodeType::Fixed; }
53 bool isStickyNode() const { return nodeType() == ScrollingNodeType::Sticky; }
54 bool isPositionedNode() const { return nodeType() == ScrollingNodeType::Positioned; }
55 bool isScrollingNode() const { return isFrameScrollingNode() || isOverflowScrollingNode(); }
56 bool isFrameScrollingNode() const { return nodeType() == ScrollingNodeType::MainFrame || nodeType() == ScrollingNodeType::Subframe; }
57 bool isFrameHostingNode() const { return nodeType() == ScrollingNodeType::FrameHosting; }
58 bool isOverflowScrollingNode() const { return nodeType() == ScrollingNodeType::Overflow; }
59
60 virtual void commitStateBeforeChildren(const ScrollingStateNode&) = 0;
61 virtual void commitStateAfterChildren(const ScrollingStateNode&) { }
62
63 ScrollingTreeNode* parent() const { return m_parent; }
64 void setParent(ScrollingTreeNode* parent) { m_parent = parent; }
65
66 WEBCORE_EXPORT bool isRootNode() const;
67
68 Vector<RefPtr<ScrollingTreeNode>>* children() { return m_children.get(); }
69 const Vector<RefPtr<ScrollingTreeNode>>* children() const { return m_children.get(); }
70
71 void appendChild(Ref<ScrollingTreeNode>&&);
72 void removeChild(ScrollingTreeNode&);
73
74 WEBCORE_EXPORT ScrollingTreeFrameScrollingNode* enclosingFrameNodeIncludingSelf();
75 WEBCORE_EXPORT ScrollingTreeScrollingNode* enclosingScrollingNodeIncludingSelf();
76
77 WEBCORE_EXPORT void dump(WTF::TextStream&, ScrollingStateTreeAsTextBehavior) const;
78
79 virtual LayoutPoint parentToLocalPoint(LayoutPoint point) const { return point; }
80 virtual LayoutPoint localToContentsPoint(LayoutPoint point) const { return point; }
81 virtual ScrollingTreeScrollingNode* scrollingNodeForPoint(LayoutPoint) const;
82
83protected:
84 ScrollingTreeNode(ScrollingTree&, ScrollingNodeType, ScrollingNodeID);
85 ScrollingTree& scrollingTree() const { return m_scrollingTree; }
86
87 virtual void applyLayerPositions() = 0;
88
89 WEBCORE_EXPORT virtual void dumpProperties(WTF::TextStream&, ScrollingStateTreeAsTextBehavior) const;
90
91 std::unique_ptr<Vector<RefPtr<ScrollingTreeNode>>> m_children;
92
93private:
94 ScrollingTree& m_scrollingTree;
95
96 const ScrollingNodeType m_nodeType;
97 const ScrollingNodeID m_nodeID;
98
99 ScrollingTreeNode* m_parent;
100};
101
102} // namespace WebCore
103
104#define SPECIALIZE_TYPE_TRAITS_SCROLLING_NODE(ToValueTypeName, predicate) \
105SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToValueTypeName) \
106 static bool isType(const WebCore::ScrollingTreeNode& node) { return node.predicate; } \
107SPECIALIZE_TYPE_TRAITS_END()
108
109#endif // ENABLE(ASYNC_SCROLLING)
110