Combine event and touch action regions into a single class
[WebKit-https.git] / Source / WebKit / Shared / RemoteLayerTree / RemoteLayerTreeTransaction.h
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 #include "DrawingAreaInfo.h"
29 #include "DynamicViewportSizeUpdate.h"
30 #include "EditorState.h"
31 #include "GenericCallback.h"
32 #include "PlatformCAAnimationRemote.h"
33 #include "RemoteLayerBackingStore.h"
34 #include <WebCore/Color.h>
35 #include <WebCore/FilterOperations.h>
36 #include <WebCore/FloatPoint3D.h>
37 #include <WebCore/FloatSize.h>
38 #include <WebCore/LayoutMilestone.h>
39 #include <WebCore/PlatformCALayer.h>
40 #include <WebCore/TransformationMatrix.h>
41 #include <wtf/HashMap.h>
42 #include <wtf/HashSet.h>
43 #include <wtf/text/StringHash.h>
44 #include <wtf/text/WTFString.h>
45
46 namespace IPC {
47 class Decoder;
48 class Encoder;
49 }
50
51 namespace WebKit {
52
53 class RemoteLayerTreeTransaction {
54 public:
55     enum LayerChange {
56         NameChanged                     = 1LLU << 1,
57         ChildrenChanged                 = 1LLU << 2,
58         PositionChanged                 = 1LLU << 3,
59         BoundsChanged                   = 1LLU << 4,
60         BackgroundColorChanged          = 1LLU << 5,
61         AnchorPointChanged              = 1LLU << 6,
62         BorderWidthChanged              = 1LLU << 7,
63         BorderColorChanged              = 1LLU << 8,
64         OpacityChanged                  = 1LLU << 9,
65         TransformChanged                = 1LLU << 10,
66         SublayerTransformChanged        = 1LLU << 11,
67         HiddenChanged                   = 1LLU << 12,
68         GeometryFlippedChanged          = 1LLU << 13,
69         DoubleSidedChanged              = 1LLU << 14,
70         MasksToBoundsChanged            = 1LLU << 15,
71         OpaqueChanged                   = 1LLU << 16,
72         ContentsHiddenChanged           = 1LLU << 17,
73         MaskLayerChanged                = 1LLU << 18,
74         ClonedContentsChanged           = 1LLU << 19,
75         ContentsRectChanged             = 1LLU << 20,
76         ContentsScaleChanged            = 1LLU << 21,
77         CornerRadiusChanged             = 1LLU << 22,
78         ShapeRoundedRectChanged         = 1LLU << 23,
79         ShapePathChanged                = 1LLU << 24,
80         MinificationFilterChanged       = 1LLU << 25,
81         MagnificationFilterChanged      = 1LLU << 26,
82         BlendModeChanged                = 1LLU << 27,
83         WindRuleChanged                 = 1LLU << 28,
84         SpeedChanged                    = 1LLU << 29,
85         TimeOffsetChanged               = 1LLU << 30,
86         BackingStoreChanged             = 1LLU << 31,
87         BackingStoreAttachmentChanged   = 1LLU << 32,
88         FiltersChanged                  = 1LLU << 33,
89         AnimationsChanged               = 1LLU << 34,
90         EdgeAntialiasingMaskChanged     = 1LLU << 35,
91         CustomAppearanceChanged         = 1LLU << 36,
92         UserInteractionEnabledChanged   = 1LLU << 37,
93         EventRegionChanged              = 1LLU << 38,
94     };
95
96     struct LayerCreationProperties {
97         LayerCreationProperties();
98
99         void encode(IPC::Encoder&) const;
100         static Optional<LayerCreationProperties> decode(IPC::Decoder&);
101
102         WebCore::GraphicsLayer::PlatformLayerID layerID;
103         WebCore::PlatformCALayer::LayerType type;
104
105         WebCore::GraphicsLayer::EmbeddedViewID embeddedViewID;
106
107         uint32_t hostingContextID;
108         float hostingDeviceScaleFactor;
109     };
110
111     struct LayerProperties {
112         LayerProperties();
113         LayerProperties(const LayerProperties& other);
114
115         void encode(IPC::Encoder&) const;
116         static bool decode(IPC::Decoder&, LayerProperties&);
117
118         void notePropertiesChanged(OptionSet<LayerChange> changeFlags)
119         {
120             changedProperties.add(changeFlags);
121             everChangedProperties.add(changeFlags);
122         }
123
124         void resetChangedProperties()
125         {
126             changedProperties = { };
127         }
128
129         OptionSet<LayerChange> changedProperties;
130         OptionSet<LayerChange> everChangedProperties;
131
132         String name;
133         std::unique_ptr<WebCore::TransformationMatrix> transform;
134         std::unique_ptr<WebCore::TransformationMatrix> sublayerTransform;
135         std::unique_ptr<WebCore::FloatRoundedRect> shapeRoundedRect;
136
137         Vector<WebCore::GraphicsLayer::PlatformLayerID> children;
138
139         Vector<std::pair<String, PlatformCAAnimationRemote::Properties>> addedAnimations;
140         HashSet<String> keyPathsOfAnimationsToRemove;
141
142         WebCore::FloatPoint3D position;
143         WebCore::FloatPoint3D anchorPoint;
144         WebCore::FloatRect bounds;
145         WebCore::FloatRect contentsRect;
146         std::unique_ptr<RemoteLayerBackingStore> backingStore;
147         std::unique_ptr<WebCore::FilterOperations> filters;
148         WebCore::Path shapePath;
149         WebCore::GraphicsLayer::PlatformLayerID maskLayerID;
150         WebCore::GraphicsLayer::PlatformLayerID clonedLayerID;
151         double timeOffset;
152         float speed;
153         float contentsScale;
154         float cornerRadius;
155         float borderWidth;
156         float opacity;
157         WebCore::Color backgroundColor;
158         WebCore::Color borderColor;
159         unsigned edgeAntialiasingMask;
160         WebCore::GraphicsLayer::CustomAppearance customAppearance;
161         WebCore::PlatformCALayer::FilterType minificationFilter;
162         WebCore::PlatformCALayer::FilterType magnificationFilter;
163         WebCore::BlendMode blendMode;
164         WebCore::WindRule windRule;
165         bool hidden;
166         bool backingStoreAttached;
167         bool geometryFlipped;
168         bool doubleSided;
169         bool masksToBounds;
170         bool opaque;
171         bool contentsHidden;
172         bool userInteractionEnabled;
173         WebCore::EventRegion eventRegion;
174     };
175
176     explicit RemoteLayerTreeTransaction();
177     ~RemoteLayerTreeTransaction();
178     RemoteLayerTreeTransaction(RemoteLayerTreeTransaction&&);
179     RemoteLayerTreeTransaction& operator=(RemoteLayerTreeTransaction&&);
180
181     void encode(IPC::Encoder&) const;
182     static bool decode(IPC::Decoder&, RemoteLayerTreeTransaction&);
183
184     WebCore::GraphicsLayer::PlatformLayerID rootLayerID() const { return m_rootLayerID; }
185     void setRootLayerID(WebCore::GraphicsLayer::PlatformLayerID);
186     void layerPropertiesChanged(PlatformCALayerRemote&);
187     void setCreatedLayers(Vector<LayerCreationProperties>);
188     void setDestroyedLayerIDs(Vector<WebCore::GraphicsLayer::PlatformLayerID>);
189     void setLayerIDsWithNewlyUnreachableBackingStore(Vector<WebCore::GraphicsLayer::PlatformLayerID>);
190
191 #if !defined(NDEBUG) || !LOG_DISABLED
192     WTF::CString description() const;
193     void dump() const;
194 #endif
195
196     typedef HashMap<WebCore::GraphicsLayer::PlatformLayerID, std::unique_ptr<LayerProperties>> LayerPropertiesMap;
197
198     Vector<LayerCreationProperties> createdLayers() const { return m_createdLayers; }
199     Vector<WebCore::GraphicsLayer::PlatformLayerID> destroyedLayers() const { return m_destroyedLayerIDs; }
200     Vector<WebCore::GraphicsLayer::PlatformLayerID> layerIDsWithNewlyUnreachableBackingStore() const { return m_layerIDsWithNewlyUnreachableBackingStore; }
201
202     Vector<RefPtr<PlatformCALayerRemote>>& changedLayers() { return m_changedLayers; }
203
204     const LayerPropertiesMap& changedLayerProperties() const { return m_changedLayerProperties; }
205     LayerPropertiesMap& changedLayerProperties() { return m_changedLayerProperties; }
206
207     WebCore::IntSize contentsSize() const { return m_contentsSize; }
208     void setContentsSize(const WebCore::IntSize& size) { m_contentsSize = size; };
209
210     WebCore::IntPoint scrollOrigin() const { return m_scrollOrigin; }
211     void setScrollOrigin(const WebCore::IntPoint& origin) { m_scrollOrigin = origin; };
212
213     WebCore::LayoutSize baseLayoutViewportSize() const { return m_baseLayoutViewportSize; }
214     void setBaseLayoutViewportSize(const WebCore::LayoutSize& size) { m_baseLayoutViewportSize = size; };
215     
216     WebCore::LayoutPoint minStableLayoutViewportOrigin() const { return m_minStableLayoutViewportOrigin; }
217     void setMinStableLayoutViewportOrigin(const WebCore::LayoutPoint& point) { m_minStableLayoutViewportOrigin = point; };
218     
219     WebCore::LayoutPoint maxStableLayoutViewportOrigin() const { return m_maxStableLayoutViewportOrigin; }
220     void setMaxStableLayoutViewportOrigin(const WebCore::LayoutPoint& point) { m_maxStableLayoutViewportOrigin = point; };
221     
222     WebCore::Color pageExtendedBackgroundColor() const { return m_pageExtendedBackgroundColor; }
223     void setPageExtendedBackgroundColor(WebCore::Color color) { m_pageExtendedBackgroundColor = color; }
224
225     WebCore::IntPoint scrollPosition() const { return m_scrollPosition; }
226     void setScrollPosition(WebCore::IntPoint p) { m_scrollPosition = p; }
227
228     double pageScaleFactor() const { return m_pageScaleFactor; }
229     void setPageScaleFactor(double pageScaleFactor) { m_pageScaleFactor = pageScaleFactor; }
230
231     bool scaleWasSetByUIProcess() const { return m_scaleWasSetByUIProcess; }
232     void setScaleWasSetByUIProcess(bool scaleWasSetByUIProcess) { m_scaleWasSetByUIProcess = scaleWasSetByUIProcess; }
233     
234     uint64_t renderTreeSize() const { return m_renderTreeSize; }
235     void setRenderTreeSize(uint64_t renderTreeSize) { m_renderTreeSize = renderTreeSize; }
236
237     double minimumScaleFactor() const { return m_minimumScaleFactor; }
238     void setMinimumScaleFactor(double scale) { m_minimumScaleFactor = scale; }
239
240     double maximumScaleFactor() const { return m_maximumScaleFactor; }
241     void setMaximumScaleFactor(double scale) { m_maximumScaleFactor = scale; }
242
243     double initialScaleFactor() const { return m_initialScaleFactor; }
244     void setInitialScaleFactor(double scale) { m_initialScaleFactor = scale; }
245
246     double viewportMetaTagWidth() const { return m_viewportMetaTagWidth; }
247     void setViewportMetaTagWidth(double width) { m_viewportMetaTagWidth = width; }
248
249     bool viewportMetaTagWidthWasExplicit() const { return m_viewportMetaTagWidthWasExplicit; }
250     void setViewportMetaTagWidthWasExplicit(bool widthWasExplicit) { m_viewportMetaTagWidthWasExplicit = widthWasExplicit; }
251
252     bool viewportMetaTagCameFromImageDocument() const { return m_viewportMetaTagCameFromImageDocument; }
253     void setViewportMetaTagCameFromImageDocument(bool cameFromImageDocument) { m_viewportMetaTagCameFromImageDocument = cameFromImageDocument; }
254
255     bool isInStableState() const { return m_isInStableState; }
256     void setIsInStableState(bool isInStableState) { m_isInStableState = isInStableState; }
257
258     bool allowsUserScaling() const { return m_allowsUserScaling; }
259     void setAllowsUserScaling(bool allowsUserScaling) { m_allowsUserScaling = allowsUserScaling; }
260
261     bool avoidsUnsafeArea() const { return m_avoidsUnsafeArea; }
262     void setAvoidsUnsafeArea(bool avoidsUnsafeArea) { m_avoidsUnsafeArea = avoidsUnsafeArea; }
263
264     uint64_t transactionID() const { return m_transactionID; }
265     void setTransactionID(uint64_t transactionID) { m_transactionID = transactionID; }
266
267     ActivityStateChangeID activityStateChangeID() const { return m_activityStateChangeID; }
268     void setActivityStateChangeID(ActivityStateChangeID activityStateChangeID) { m_activityStateChangeID = activityStateChangeID; }
269
270     typedef CallbackID TransactionCallbackID;
271     const Vector<TransactionCallbackID>& callbackIDs() const { return m_callbackIDs; }
272     void setCallbackIDs(Vector<TransactionCallbackID>&& callbackIDs) { m_callbackIDs = WTFMove(callbackIDs); }
273
274     OptionSet<WebCore::LayoutMilestone> newlyReachedLayoutMilestones() const { return m_newlyReachedLayoutMilestones; }
275     void setNewlyReachedLayoutMilestones(OptionSet<WebCore::LayoutMilestone> milestones) { m_newlyReachedLayoutMilestones = milestones; }
276
277     bool hasEditorState() const { return !!m_editorState; }
278     const EditorState& editorState() const { return m_editorState.value(); }
279     void setEditorState(const EditorState& editorState) { m_editorState = editorState; }
280
281     Optional<DynamicViewportSizeUpdateID> dynamicViewportSizeUpdateID() const { return m_dynamicViewportSizeUpdateID; }
282     void setDynamicViewportSizeUpdateID(DynamicViewportSizeUpdateID resizeID) { m_dynamicViewportSizeUpdateID = resizeID; }
283     
284 private:
285     WebCore::GraphicsLayer::PlatformLayerID m_rootLayerID;
286     Vector<RefPtr<PlatformCALayerRemote>> m_changedLayers; // Only used in the Web process.
287     LayerPropertiesMap m_changedLayerProperties; // Only used in the UI process.
288
289     Vector<LayerCreationProperties> m_createdLayers;
290     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_destroyedLayerIDs;
291     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_videoLayerIDsPendingFullscreen;
292     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_layerIDsWithNewlyUnreachableBackingStore;
293
294     Vector<TransactionCallbackID> m_callbackIDs;
295
296     WebCore::IntSize m_contentsSize;
297     WebCore::IntPoint m_scrollOrigin;
298     WebCore::LayoutSize m_baseLayoutViewportSize;
299     WebCore::LayoutPoint m_minStableLayoutViewportOrigin;
300     WebCore::LayoutPoint m_maxStableLayoutViewportOrigin;
301     WebCore::IntPoint m_scrollPosition;
302     WebCore::Color m_pageExtendedBackgroundColor;
303     double m_pageScaleFactor { 1 };
304     double m_minimumScaleFactor { 1 };
305     double m_maximumScaleFactor { 1 };
306     double m_initialScaleFactor { 1 };
307     double m_viewportMetaTagWidth { -1 };
308     uint64_t m_renderTreeSize { 0 };
309     uint64_t m_transactionID { 0 };
310     ActivityStateChangeID m_activityStateChangeID { ActivityStateChangeAsynchronous };
311     OptionSet<WebCore::LayoutMilestone> m_newlyReachedLayoutMilestones;
312     bool m_scaleWasSetByUIProcess { false };
313     bool m_allowsUserScaling { false };
314     bool m_avoidsUnsafeArea { true };
315     bool m_viewportMetaTagWidthWasExplicit { false };
316     bool m_viewportMetaTagCameFromImageDocument { false };
317     bool m_isInStableState { false };
318
319     Optional<EditorState> m_editorState;
320     Optional<DynamicViewportSizeUpdateID> m_dynamicViewportSizeUpdateID;
321 };
322
323 } // namespace WebKit