1/*
2 * Copyright (C) 2017 Igalia S.L. 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#import "config.h"
27#import "ScrollingTreeRemoteFrameScrollingNodeIOS.h"
28
29#if PLATFORM(IOS)
30#if ENABLE(ASYNC_SCROLLING)
31
32#import "ScrollingTreeScrollingNodeDelegateIOS.h"
33
34#import <WebCore/ScrollingStateFrameScrollingNode.h>
35
36using namespace WebCore;
37
38namespace WebKit {
39
40Ref<ScrollingTreeRemoteFrameScrollingNodeIOS> ScrollingTreeRemoteFrameScrollingNodeIOS::create(WebCore::ScrollingTree& scrollingTree, WebCore::ScrollingNodeID nodeID)
41{
42 return adoptRef(*new ScrollingTreeRemoteFrameScrollingNodeIOS(scrollingTree, nodeID));
43}
44
45ScrollingTreeRemoteFrameScrollingNodeIOS::ScrollingTreeRemoteFrameScrollingNodeIOS(WebCore::ScrollingTree& scrollingTree, WebCore::ScrollingNodeID nodeID)
46 : ScrollingTreeFrameScrollingNodeIOS(scrollingTree, nodeID)
47{
48}
49
50ScrollingTreeRemoteFrameScrollingNodeIOS::~ScrollingTreeRemoteFrameScrollingNodeIOS()
51{
52}
53
54void ScrollingTreeRemoteFrameScrollingNodeIOS::setIsMainFrame(bool isMainFrame)
55{
56 if (isMainFrame != !m_scrollingNodeDelegate)
57 m_scrollingNodeDelegate.reset(isMainFrame ? nullptr : new ScrollingTreeScrollingNodeDelegateIOS(*this));
58}
59
60void ScrollingTreeRemoteFrameScrollingNodeIOS::commitStateBeforeChildren(const WebCore::ScrollingStateNode& stateNode)
61{
62 const auto& scrollingStateNode = downcast<ScrollingStateScrollingNode>(stateNode);
63 if (scrollingStateNode.hasChangedProperty(ScrollingStateScrollingNode::ScrollLayer) && m_scrollingNodeDelegate)
64 m_scrollingNodeDelegate->resetScrollViewDelegate();
65
66 ScrollingTreeFrameScrollingNodeIOS::commitStateBeforeChildren(stateNode);
67
68 if (m_scrollingNodeDelegate)
69 m_scrollingNodeDelegate->commitStateBeforeChildren(scrollingStateNode);
70}
71
72void ScrollingTreeRemoteFrameScrollingNodeIOS::commitStateAfterChildren(const ScrollingStateNode& stateNode)
73{
74 ScrollingTreeFrameScrollingNodeIOS::commitStateAfterChildren(stateNode);
75 if (m_scrollingNodeDelegate)
76 m_scrollingNodeDelegate->commitStateAfterChildren(downcast<ScrollingStateScrollingNode>(stateNode));
77}
78
79void ScrollingTreeRemoteFrameScrollingNodeIOS::updateLayersAfterDelegatedScroll(const FloatPoint& scrollPosition)
80{
81 if (m_scrollingNodeDelegate)
82 m_scrollingNodeDelegate->updateChildNodesAfterScroll(scrollPosition);
83 else
84 ScrollingTreeFrameScrollingNodeIOS::updateLayersAfterDelegatedScroll(scrollPosition);
85}
86
87void ScrollingTreeRemoteFrameScrollingNodeIOS::updateLayersAfterAncestorChange(const ScrollingTreeNode& changedNode, const FloatRect& fixedPositionRect, const FloatSize& cumulativeDelta)
88{
89 ASSERT(m_scrollingNodeDelegate);
90 m_scrollingNodeDelegate->updateLayersAfterAncestorChange(changedNode, this->fixedPositionRect(), cumulativeDelta);
91}
92
93FloatPoint ScrollingTreeRemoteFrameScrollingNodeIOS::scrollPosition() const
94{
95 return m_scrollingNodeDelegate ? m_scrollingNodeDelegate->scrollPosition() : ScrollingTreeFrameScrollingNodeIOS::scrollPosition();
96}
97
98void ScrollingTreeRemoteFrameScrollingNodeIOS::setScrollLayerPosition(const FloatPoint& scrollPosition, const FloatRect& layoutViewport)
99{
100 if (m_scrollingNodeDelegate)
101 m_scrollingNodeDelegate->setScrollLayerPosition(scrollPosition);
102 else
103 ScrollingTreeFrameScrollingNodeIOS::setScrollLayerPosition(scrollPosition, layoutViewport);
104}
105
106} // namespace WebKit
107
108#endif // ENABLE(ASYNC_SCROLLING)
109#endif // PLATFORM(IOS)