Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / public / platform / WebLayer.h
blob83089ca7248ee0fa599542965cbdc6f3bb3a497e
1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef WebLayer_h
27 #define WebLayer_h
29 #include "WebBlendMode.h"
30 #include "WebColor.h"
31 #include "WebCommon.h"
32 #include "WebCompositorAnimation.h"
33 #include "WebDoublePoint.h"
34 #include "WebFloatPoint3D.h"
35 #include "WebPoint.h"
36 #include "WebRect.h"
37 #include "WebScrollBlocksOn.h"
38 #include "WebSize.h"
39 #include "WebString.h"
40 #include "WebVector.h"
42 class SkMatrix44;
43 class SkImageFilter;
45 namespace blink {
46 class WebCompositorAnimationDelegate;
47 class WebFilterOperations;
48 class WebLayerClient;
49 class WebLayerScrollClient;
50 struct WebFloatPoint;
51 struct WebLayerPositionConstraint;
53 class WebLayer {
54 public:
55 virtual ~WebLayer() { }
57 // Returns a positive ID that will be unique across all WebLayers allocated in this process.
58 virtual int id() const = 0;
60 // Sets a region of the layer as invalid, i.e. needs to update its content.
61 virtual void invalidateRect(const WebRect&) = 0;
63 // Sets the entire layer as invalid, i.e. needs to update its content.
64 virtual void invalidate() = 0;
66 // These functions do not take ownership of the WebLayer* parameter.
67 virtual void addChild(WebLayer*) = 0;
68 virtual void insertChild(WebLayer*, size_t index) = 0;
69 virtual void replaceChild(WebLayer* reference, WebLayer* newLayer) = 0;
70 virtual void removeFromParent() = 0;
71 virtual void removeAllChildren() = 0;
73 virtual void setBounds(const WebSize&) = 0;
74 virtual WebSize bounds() const = 0;
76 virtual void setMasksToBounds(bool) = 0;
77 virtual bool masksToBounds() const = 0;
79 virtual void setMaskLayer(WebLayer*) = 0;
80 virtual void setReplicaLayer(WebLayer*) = 0;
82 virtual void setOpacity(float) = 0;
83 virtual float opacity() const = 0;
85 virtual void setBlendMode(WebBlendMode) = 0;
86 virtual WebBlendMode blendMode() const = 0;
88 virtual void setIsRootForIsolatedGroup(bool) = 0;
89 virtual bool isRootForIsolatedGroup() = 0;
91 virtual void setOpaque(bool) = 0;
92 virtual bool opaque() const = 0;
94 virtual void setPosition(const WebFloatPoint&) = 0;
95 virtual WebFloatPoint position() const = 0;
97 virtual void setTransform(const SkMatrix44&) = 0;
98 virtual SkMatrix44 transform() const = 0;
100 virtual void setTransformOrigin(const WebFloatPoint3D&) { }
101 virtual WebFloatPoint3D transformOrigin() const { return WebFloatPoint3D(); }
103 // Sets whether the layer draws its content when compositing.
104 virtual void setDrawsContent(bool) = 0;
105 virtual bool drawsContent() const = 0;
107 // Sets whether the layer's transform should be flattened.
108 virtual void setShouldFlattenTransform(bool) = 0;
110 // Sets the id of the layer's 3d rendering context. Layers in the same 3d
111 // rendering context id are sorted with one another according to their 3d
112 // position rather than their tree order.
113 virtual void setRenderingContext(int id) = 0;
115 // Mark that this layer should use its parent's transform and double-sided
116 // properties in determining this layer's backface visibility instead of
117 // using its own properties. If this property is set, this layer must
118 // have a parent, and the parent may not have this property set.
119 // Note: This API is to work around issues with visibility the handling of
120 // WebKit layers that have a contents layer (canvas, plugin, WebGL, video,
121 // etc).
122 virtual void setUseParentBackfaceVisibility(bool) = 0;
124 virtual void setBackgroundColor(WebColor) = 0;
125 virtual WebColor backgroundColor() const = 0;
127 // Clear the filters in use by passing in a newly instantiated
128 // WebFilterOperations object.
129 virtual void setFilters(const WebFilterOperations&) = 0;
131 // Clear the background filters in use by passing in a newly instantiated
132 // WebFilterOperations object.
133 virtual void setBackgroundFilters(const WebFilterOperations&) = 0;
135 // An animation delegate is notified when animations are started and
136 // stopped. The WebLayer does not take ownership of the delegate, and it is
137 // the responsibility of the client to reset the layer's delegate before
138 // deleting the delegate.
139 virtual void setAnimationDelegate(WebCompositorAnimationDelegate*) = 0;
142 // Returns false if the animation cannot be added.
143 // Takes ownership of the WebCompositorAnimation object.
144 virtual bool addAnimation(WebCompositorAnimation*) = 0;
146 // Removes all animations with the given id.
147 virtual void removeAnimation(int animationId) = 0;
149 // Removes all animations with the given id targeting the given property.
150 virtual void removeAnimation(int animationId, WebCompositorAnimation::TargetProperty) = 0;
152 // Pauses all animations with the given id.
153 virtual void pauseAnimation(int animationId, double timeOffset) = 0;
155 // Returns true if this layer has any active animations - useful for tests.
156 virtual bool hasActiveAnimation() = 0;
158 // If a scroll parent is set, this layer will inherit its parent's scroll
159 // delta and offset even though it will not be a descendant of the scroll
160 // in the layer hierarchy.
161 virtual void setScrollParent(WebLayer*) = 0;
163 // A layer will not respect any clips established by layers between it and
164 // its nearest clipping ancestor. Note, the clip parent must be an ancestor.
165 // This is not a requirement of the scroll parent.
166 virtual void setClipParent(WebLayer*) = 0;
168 // Scrolling
169 virtual void setScrollPositionDouble(WebDoublePoint) = 0;
170 virtual WebDoublePoint scrollPositionDouble() const = 0;
171 // Blink tells cc the scroll offset through setScrollPositionDouble() using
172 // floating precision but it currently can only position cc layers at integer
173 // boundary. So Blink needs to also call setScrollCompensationAdjustment()
174 // to tell cc what's the part of the scroll offset that Blink doesn't handle
175 // but cc needs to take into consideration, e.g. compensating
176 // for fixed-position layer that's positioned in Blink using only integer scroll
177 // offset.
178 // We make this call explicit, instead of letting cc to infer the fractional part
179 // from the scroll offset, to be clear that this is Blink's limitation. Once
180 // Blink can fully handle fractional scroll offset, it can stop calling
181 // this function and cc side would just work.
182 virtual void setScrollCompensationAdjustment(WebDoublePoint) = 0;
184 // To set a WebLayer as scrollable we must specify the corresponding clip layer.
185 virtual void setScrollClipLayer(WebLayer*) = 0;
186 virtual bool scrollable() const = 0;
187 virtual void setUserScrollable(bool horizontal, bool vertical) = 0;
188 virtual bool userScrollableHorizontal() const = 0;
189 virtual bool userScrollableVertical() const = 0;
191 virtual void setHaveWheelEventHandlers(bool) = 0;
192 virtual bool haveWheelEventHandlers() const = 0;
194 virtual void setHaveScrollEventHandlers(bool) = 0;
195 virtual bool haveScrollEventHandlers() const = 0;
197 virtual void setShouldScrollOnMainThread(bool) = 0;
198 virtual bool shouldScrollOnMainThread() const = 0;
200 virtual void setNonFastScrollableRegion(const WebVector<WebRect>&) = 0;
201 virtual WebVector<WebRect> nonFastScrollableRegion() const = 0;
203 virtual void setTouchEventHandlerRegion(const WebVector<WebRect>&) = 0;
204 virtual WebVector<WebRect> touchEventHandlerRegion() const = 0;
206 // Setter and getter for Frame Timing rects.
207 // See http://w3c.github.io/frame-timing/ for definition of terms.
208 virtual void setFrameTimingRequests(const WebVector<std::pair<int64_t, WebRect>>&) = 0;
209 virtual WebVector<std::pair<int64_t, WebRect>> frameTimingRequests() const = 0;
211 // FIXME: Make pure once cc is updated. crbug.com/347272
212 virtual void setScrollBlocksOn(WebScrollBlocksOn) { }
213 virtual WebScrollBlocksOn scrollBlocksOn() const { return WebScrollBlocksOnNone; }
215 virtual void setIsContainerForFixedPositionLayers(bool) = 0;
216 virtual bool isContainerForFixedPositionLayers() const = 0;
218 // This function sets layer position constraint. The constraint will be used
219 // to adjust layer position during threaded scrolling.
220 virtual void setPositionConstraint(const WebLayerPositionConstraint&) = 0;
221 virtual WebLayerPositionConstraint positionConstraint() const = 0;
223 // The scroll client is notified when the scroll position of the WebLayer
224 // changes. Only a single scroll client can be set for a WebLayer at a time.
225 // The WebLayer does not take ownership of the scroll client, and it is the
226 // responsibility of the client to reset the layer's scroll client before
227 // deleting the scroll client.
228 virtual void setScrollClient(WebLayerScrollClient*) = 0;
230 // Forces this layer to use a render surface. There is no benefit in doing
231 // so, but this is to facilitate benchmarks and tests.
232 virtual void setForceRenderSurface(bool) = 0;
234 // True if the layer is not part of a tree attached to a WebLayerTreeView.
235 virtual bool isOrphan() const = 0;
237 virtual void setWebLayerClient(WebLayerClient*) = 0;
240 } // namespace blink
242 #endif // WebLayer_h