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 | |
38 | namespace WebCore { |
39 | |
40 | class ScrollingStateFixedNode; |
41 | class ScrollingTreeFrameScrollingNode; |
42 | class ScrollingTreeScrollingNode; |
43 | |
44 | class ScrollingTreeNode : public ThreadSafeRefCounted<ScrollingTreeNode> { |
45 | friend class ScrollingTree; |
46 | public: |
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 | |
83 | protected: |
84 | ScrollingTreeNode(ScrollingTree&, ScrollingNodeType, ScrollingNodeID); |
85 | ScrollingTree& scrollingTree() const { return m_scrollingTree; } |
86 | |
87 | WEBCORE_EXPORT virtual void relatedNodeScrollPositionDidChange(const ScrollingTreeScrollingNode& changedNode, const FloatRect& layoutViewport, FloatSize& cumulativeDelta); |
88 | |
89 | virtual void applyLayerPositions(const FloatRect& layoutViewport, FloatSize& cumulativeDelta) = 0; |
90 | |
91 | WEBCORE_EXPORT virtual void dumpProperties(WTF::TextStream&, ScrollingStateTreeAsTextBehavior) const; |
92 | |
93 | std::unique_ptr<Vector<RefPtr<ScrollingTreeNode>>> m_children; |
94 | |
95 | private: |
96 | ScrollingTree& m_scrollingTree; |
97 | |
98 | const ScrollingNodeType m_nodeType; |
99 | const ScrollingNodeID m_nodeID; |
100 | |
101 | ScrollingTreeNode* m_parent; |
102 | }; |
103 | |
104 | } // namespace WebCore |
105 | |
106 | #define SPECIALIZE_TYPE_TRAITS_SCROLLING_NODE(ToValueTypeName, predicate) \ |
107 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToValueTypeName) \ |
108 | static bool isType(const WebCore::ScrollingTreeNode& node) { return node.predicate; } \ |
109 | SPECIALIZE_TYPE_TRAITS_END() |
110 | |
111 | #endif // ENABLE(ASYNC_SCROLLING) |
112 | |