UI-process hit-testing needs to know about containing block relationships
[WebKit-https.git] / Source / WebKit / UIProcess / RemoteLayerTree / RemoteLayerTreeNode.h
1 /*
2  * Copyright (C) 2018 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 #include <WebCore/GraphicsLayer.h>
29 #include <wtf/RetainPtr.h>
30 #include <wtf/Vector.h>
31
32 OBJC_CLASS CALayer;
33 #if PLATFORM(IOS_FAMILY)
34 OBJC_CLASS UIView;
35 #endif
36
37 namespace WebKit {
38
39 class RemoteLayerTreeScrollbars;
40
41 class RemoteLayerTreeNode {
42     WTF_MAKE_FAST_ALLOCATED;
43 public:
44     RemoteLayerTreeNode(WebCore::GraphicsLayer::PlatformLayerID, RetainPtr<CALayer>);
45 #if PLATFORM(IOS_FAMILY)
46     RemoteLayerTreeNode(WebCore::GraphicsLayer::PlatformLayerID, RetainPtr<UIView>);
47 #endif
48     ~RemoteLayerTreeNode();
49
50     static std::unique_ptr<RemoteLayerTreeNode> createWithPlainLayer(WebCore::GraphicsLayer::PlatformLayerID);
51
52     CALayer *layer() const { return m_layer.get(); }
53 #if PLATFORM(IOS_FAMILY)
54     UIView *uiView() const { return m_uiView.get(); }
55 #endif
56
57     WebCore::GraphicsLayer::PlatformLayerID layerID() const { return m_layerID; }
58
59     const WebCore::Region& eventRegion() const { return m_eventRegion; }
60     void setEventRegion(const WebCore::Region&);
61
62     // If empty the layer is scrolled by an ancestor scroller.
63     const auto& nonAncestorScrollContainerIDs() const { return m_nonAncestorScrollLayerIDs; }
64     void addNonAncestorScrollContainerID(WebCore::GraphicsLayer::PlatformLayerID layerID) { m_nonAncestorScrollLayerIDs.append(layerID); }
65     void clearNonAncestorScrollContainerIDs() { m_nonAncestorScrollLayerIDs.clear(); }
66
67     void detachFromParent();
68
69     static WebCore::GraphicsLayer::PlatformLayerID layerID(CALayer *);
70     static RemoteLayerTreeNode* forCALayer(CALayer *);
71
72     static NSString *appendLayerDescription(NSString *description, CALayer *);
73
74 private:
75     void initializeLayer();
76
77     WebCore::GraphicsLayer::PlatformLayerID m_layerID;
78
79     RetainPtr<CALayer> m_layer;
80 #if PLATFORM(IOS_FAMILY)
81     RetainPtr<UIView> m_uiView;
82 #endif
83
84     WebCore::Region m_eventRegion;
85     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_nonAncestorScrollLayerIDs;
86 };
87
88 }