Home | History | Annotate | Download | only in platform
      1 /*
      2  * Copyright (C) 2011 Google 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  *
      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.
     13  *
     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.
     24  */
     25 
     26 #ifndef WebLayer_h
     27 #define WebLayer_h
     28 
     29 #include "WebAnimation.h"
     30 #include "WebBlendMode.h"
     31 #include "WebColor.h"
     32 #include "WebCommon.h"
     33 #include "WebFloatPoint3D.h"
     34 #include "WebPoint.h"
     35 #include "WebRect.h"
     36 #include "WebSize.h"
     37 #include "WebString.h"
     38 #include "WebVector.h"
     39 
     40 class SkMatrix44;
     41 class SkImageFilter;
     42 
     43 namespace blink {
     44 class WebAnimationDelegate;
     45 class WebFilterOperations;
     46 class WebLayerClient;
     47 class WebLayerScrollClient;
     48 struct WebFloatPoint;
     49 struct WebFloatRect;
     50 struct WebLayerPositionConstraint;
     51 
     52 class WebLayer {
     53 public:
     54     virtual ~WebLayer() { }
     55 
     56     // Returns a positive ID that will be unique across all WebLayers allocated in this process.
     57     virtual int id() const = 0;
     58 
     59     // Sets a region of the layer as invalid, i.e. needs to update its content.
     60     virtual void invalidateRect(const WebFloatRect&) = 0;
     61 
     62     // Sets the entire layer as invalid, i.e. needs to update its content.
     63     virtual void invalidate() = 0;
     64 
     65     // These functions do not take ownership of the WebLayer* parameter.
     66     virtual void addChild(WebLayer*) = 0;
     67     virtual void insertChild(WebLayer*, size_t index) = 0;
     68     virtual void replaceChild(WebLayer* reference, WebLayer* newLayer) = 0;
     69     virtual void removeFromParent() = 0;
     70     virtual void removeAllChildren() = 0;
     71 
     72     virtual void setBounds(const WebSize&) = 0;
     73     virtual WebSize bounds() const = 0;
     74 
     75     virtual void setMasksToBounds(bool) = 0;
     76     virtual bool masksToBounds() const = 0;
     77 
     78     virtual void setMaskLayer(WebLayer*) = 0;
     79     virtual void setReplicaLayer(WebLayer*) = 0;
     80 
     81     virtual void setOpacity(float) = 0;
     82     virtual float opacity() const = 0;
     83 
     84     virtual void setBlendMode(WebBlendMode) = 0;
     85     virtual WebBlendMode blendMode() const = 0;
     86 
     87     virtual void setIsRootForIsolatedGroup(bool) = 0;
     88     virtual bool isRootForIsolatedGroup() = 0;
     89 
     90     virtual void setOpaque(bool) = 0;
     91     virtual bool opaque() const = 0;
     92 
     93     virtual void setPosition(const WebFloatPoint&) = 0;
     94     virtual WebFloatPoint position() const = 0;
     95 
     96     virtual void setTransform(const SkMatrix44&) = 0;
     97     virtual SkMatrix44 transform() const = 0;
     98 
     99     virtual void setTransformOrigin(const WebFloatPoint3D&) { }
    100     virtual WebFloatPoint3D transformOrigin() const { return WebFloatPoint3D(); }
    101 
    102     // Sets whether the layer draws its content when compositing.
    103     virtual void setDrawsContent(bool) = 0;
    104     virtual bool drawsContent() const = 0;
    105 
    106     // Sets whether the layer's transform should be flattened.
    107     virtual void setShouldFlattenTransform(bool) = 0;
    108 
    109     // Sets the id of the layer's 3d rendering context. Layers in the same 3d
    110     // rendering context id are sorted with one another according to their 3d
    111     // position rather than their tree order.
    112     virtual void setRenderingContext(int id) = 0;
    113 
    114     // Mark that this layer should use its parent's transform and double-sided
    115     // properties in determining this layer's backface visibility instead of
    116     // using its own properties. If this property is set, this layer must
    117     // have a parent, and the parent may not have this property set.
    118     // Note: This API is to work around issues with visibility the handling of
    119     // WebKit layers that have a contents layer (canvas, plugin, WebGL, video,
    120     // etc).
    121     virtual void setUseParentBackfaceVisibility(bool) = 0;
    122 
    123     virtual void setBackgroundColor(WebColor) = 0;
    124     virtual WebColor backgroundColor() const = 0;
    125 
    126     // Clear the filters in use by passing in a newly instantiated
    127     // WebFilterOperations object.
    128     virtual void setFilters(const WebFilterOperations&) = 0;
    129 
    130     // Apply filters to pixels that show through the background of this layer.
    131     // Note: These filters are only possible on layers that are drawn directly
    132     // to a root render surface with an opaque background. This means if an
    133     // ancestor of the background-filtered layer sets certain properties
    134     // (opacity, transforms), it may conflict and hide the background filters.
    135     virtual void setBackgroundFilters(const WebFilterOperations&) = 0;
    136 
    137     // An animation delegate is notified when animations are started and
    138     // stopped. The WebLayer does not take ownership of the delegate, and it is
    139     // the responsibility of the client to reset the layer's delegate before
    140     // deleting the delegate.
    141     virtual void setAnimationDelegate(WebAnimationDelegate*) = 0;
    142 
    143 
    144     // Returns false if the animation cannot be added.
    145     // Takes ownership of the WebAnimation object.
    146     virtual bool addAnimation(WebAnimation*) = 0;
    147 
    148     // Removes all animations with the given id.
    149     virtual void removeAnimation(int animationId) = 0;
    150 
    151     // Removes all animations with the given id targeting the given property.
    152     virtual void removeAnimation(int animationId, WebAnimation::TargetProperty) = 0;
    153 
    154     // Pauses all animations with the given id.
    155     virtual void pauseAnimation(int animationId, double timeOffset) = 0;
    156 
    157     // Returns true if this layer has any active animations - useful for tests.
    158     virtual bool hasActiveAnimation() = 0;
    159 
    160     // If a scroll parent is set, this layer will inherit its parent's scroll
    161     // delta and offset even though it will not be a descendant of the scroll
    162     // in the layer hierarchy.
    163     virtual void setScrollParent(WebLayer*) = 0;
    164 
    165     // A layer will not respect any clips established by layers between it and
    166     // its nearest clipping ancestor. Note, the clip parent must be an ancestor.
    167     // This is not a requirement of the scroll parent.
    168     virtual void setClipParent(WebLayer*) = 0;
    169 
    170     // Scrolling
    171     virtual void setScrollPosition(WebPoint) = 0;
    172     virtual WebPoint scrollPosition() const = 0;
    173 
    174     // To set a WebLayer as scrollable we must specify the corresponding clip layer.
    175     virtual void setScrollClipLayer(WebLayer*) = 0;
    176     virtual bool scrollable() const = 0;
    177     virtual void setUserScrollable(bool horizontal, bool vertical) = 0;
    178     virtual bool userScrollableHorizontal() const = 0;
    179     virtual bool userScrollableVertical() const = 0;
    180 
    181     virtual void setHaveWheelEventHandlers(bool) = 0;
    182     virtual bool haveWheelEventHandlers() const = 0;
    183 
    184     virtual void setHaveScrollEventHandlers(bool) = 0;
    185     virtual bool haveScrollEventHandlers() const = 0;
    186 
    187     virtual void setShouldScrollOnMainThread(bool) = 0;
    188     virtual bool shouldScrollOnMainThread() const = 0;
    189 
    190     virtual void setNonFastScrollableRegion(const WebVector<WebRect>&) = 0;
    191     virtual WebVector<WebRect> nonFastScrollableRegion() const = 0;
    192 
    193     virtual void setTouchEventHandlerRegion(const WebVector<WebRect>&) = 0;
    194     virtual WebVector<WebRect> touchEventHandlerRegion() const = 0;
    195 
    196     virtual void setIsContainerForFixedPositionLayers(bool) = 0;
    197     virtual bool isContainerForFixedPositionLayers() const = 0;
    198 
    199     // This function sets layer position constraint. The constraint will be used
    200     // to adjust layer position during threaded scrolling.
    201     virtual void setPositionConstraint(const WebLayerPositionConstraint&) = 0;
    202     virtual WebLayerPositionConstraint positionConstraint() const = 0;
    203 
    204     // The scroll client is notified when the scroll position of the WebLayer
    205     // changes. Only a single scroll client can be set for a WebLayer at a time.
    206     // The WebLayer does not take ownership of the scroll client, and it is the
    207     // responsibility of the client to reset the layer's scroll client before
    208     // deleting the scroll client.
    209     virtual void setScrollClient(WebLayerScrollClient*) = 0;
    210 
    211     // Forces this layer to use a render surface. There is no benefit in doing
    212     // so, but this is to facilitate benchmarks and tests.
    213     virtual void setForceRenderSurface(bool) = 0;
    214 
    215     // True if the layer is not part of a tree attached to a WebLayerTreeView.
    216     virtual bool isOrphan() const = 0;
    217 
    218     virtual void setWebLayerClient(WebLayerClient*) = 0;
    219 };
    220 
    221 } // namespace blink
    222 
    223 #endif // WebLayer_h
    224