1/*
2 * Copyright (C) 2014 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 "ScrollingTreeScrollingNode.h"
31
32namespace WebCore {
33
34class PlatformWheelEvent;
35class ScrollingTree;
36class ScrollingStateScrollingNode;
37
38class WEBCORE_EXPORT ScrollingTreeFrameScrollingNode : public ScrollingTreeScrollingNode {
39public:
40 virtual ~ScrollingTreeFrameScrollingNode();
41
42 void commitStateBeforeChildren(const ScrollingStateNode&) override;
43
44 SynchronousScrollingReasons synchronousScrollingReasons() const { return m_synchronousScrollingReasons; }
45 bool shouldUpdateScrollLayerPositionSynchronously() const { return m_synchronousScrollingReasons; }
46 bool fixedElementsLayoutRelativeToFrame() const { return m_fixedElementsLayoutRelativeToFrame; }
47
48 FloatSize viewToContentsOffset(const FloatPoint& scrollPosition) const;
49 FloatRect layoutViewportForScrollPosition(const FloatPoint& visibleContentOrigin, float scale) const;
50
51 FloatRect layoutViewport() const { return m_layoutViewport; };
52 void setLayoutViewport(const FloatRect& r) { m_layoutViewport = r; };
53
54 float frameScaleFactor() const { return m_frameScaleFactor; }
55
56protected:
57 ScrollingTreeFrameScrollingNode(ScrollingTree&, ScrollingNodeType, ScrollingNodeID);
58
59 int headerHeight() const { return m_headerHeight; }
60 int footerHeight() const { return m_footerHeight; }
61 float topContentInset() const { return m_topContentInset; }
62
63 FloatPoint minLayoutViewportOrigin() const { return m_minLayoutViewportOrigin; }
64 FloatPoint maxLayoutViewportOrigin() const { return m_maxLayoutViewportOrigin; }
65
66 ScrollBehaviorForFixedElements scrollBehaviorForFixedElements() const { return m_behaviorForFixed; }
67
68private:
69 LayoutPoint parentToLocalPoint(LayoutPoint) const final;
70 LayoutPoint localToContentsPoint(LayoutPoint) const final;
71
72 void updateViewportForCurrentScrollPosition(Optional<FloatRect>) override;
73 bool scrollPositionAndLayoutViewportMatch(const FloatPoint& position, Optional<FloatRect> overrideLayoutViewport) override;
74
75 void dumpProperties(WTF::TextStream&, ScrollingStateTreeAsTextBehavior) const override;
76
77 FloatRect m_layoutViewport;
78 FloatPoint m_minLayoutViewportOrigin;
79 FloatPoint m_maxLayoutViewportOrigin;
80
81 float m_frameScaleFactor { 1 };
82 float m_topContentInset { 0 };
83
84 int m_headerHeight { 0 };
85 int m_footerHeight { 0 };
86
87 SynchronousScrollingReasons m_synchronousScrollingReasons { 0 };
88 ScrollBehaviorForFixedElements m_behaviorForFixed { StickToDocumentBounds };
89
90 bool m_fixedElementsLayoutRelativeToFrame { false };
91};
92
93} // namespace WebCore
94
95SPECIALIZE_TYPE_TRAITS_SCROLLING_NODE(ScrollingTreeFrameScrollingNode, isFrameScrollingNode())
96
97#endif // ENABLE(ASYNC_SCROLLING)
98