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 "WebColor.h"
     31 #include "WebCommon.h"
     32 #include "WebCompositingReasons.h"
     33 #include "WebPoint.h"
     34 #include "WebPrivatePtr.h"
     35 #include "WebRect.h"
     36 #include "WebString.h"
     37 #include "WebVector.h"
     38 
     39 class SkMatrix44;
     40 class SkImageFilter;
     41 
     42 namespace WebKit {
     43 class WebAnimationDelegate;
     44 class WebFilterOperations;
     45 class WebLayerScrollClient;
     46 struct WebFloatPoint;
     47 struct WebFloatRect;
     48 struct WebLayerPositionConstraint;
     49 struct WebSize;
     50 
     51 class WebLayerImpl;
     52 
     53 class WebLayer {
     54 public:
     55     virtual ~WebLayer() { }
     56 
     57     // Returns a positive ID that will be unique across all WebLayers allocated in this process.
     58     virtual int id() const = 0;
     59 
     60     // Sets a region of the layer as invalid, i.e. needs to update its content.
     61     virtual void invalidateRect(const WebFloatRect&) = 0;
     62 
     63     // Sets the entire layer as invalid, i.e. needs to update its content.
     64     virtual void invalidate() = 0;
     65 
     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;
     72 
     73     virtual void setAnchorPoint(const WebFloatPoint&) = 0;
     74     virtual WebFloatPoint anchorPoint() const = 0;
     75 
     76     virtual void setAnchorPointZ(float) = 0;
     77     virtual float anchorPointZ() const = 0;
     78 
     79     virtual void setBounds(const WebSize&) = 0;
     80     virtual WebSize bounds() const = 0;
     81 
     82     virtual void setMasksToBounds(bool) = 0;
     83     virtual bool masksToBounds() const = 0;
     84 
     85     virtual void setMaskLayer(WebLayer*) = 0;
     86     virtual void setReplicaLayer(WebLayer*) = 0;
     87 
     88     virtual void setOpacity(float) = 0;
     89     virtual float opacity() const = 0;
     90 
     91     virtual void setOpaque(bool) = 0;
     92     virtual bool opaque() const = 0;
     93 
     94     virtual void setPosition(const WebFloatPoint&) = 0;
     95     virtual WebFloatPoint position() const = 0;
     96 
     97     virtual void setSublayerTransform(const SkMatrix44&) = 0;
     98     virtual SkMatrix44 sublayerTransform() const = 0;
     99 
    100     virtual void setTransform(const SkMatrix44&) = 0;
    101     virtual SkMatrix44 transform() const = 0;
    102 
    103     // Sets whether the layer draws its content when compositing.
    104     virtual void setDrawsContent(bool) = 0;
    105     virtual bool drawsContent() const = 0;
    106 
    107     virtual void setPreserves3D(bool) = 0;
    108 
    109     // Mark that this layer should use its parent's transform and double-sided
    110     // properties in determining this layer's backface visibility instead of
    111     // using its own properties. If this property is set, this layer must
    112     // have a parent, and the parent may not have this property set.
    113     // Note: This API is to work around issues with visibility the handling of
    114     // WebKit layers that have a contents layer (canvas, plugin, WebGL, video,
    115     // etc).
    116     virtual void setUseParentBackfaceVisibility(bool) = 0;
    117 
    118     virtual void setBackgroundColor(WebColor) = 0;
    119     virtual WebColor backgroundColor() const = 0;
    120 
    121     // Clear the filters in use by passing in a newly instantiated
    122     // WebFilterOperations object.
    123     virtual void setFilters(const WebFilterOperations&) = 0;
    124 
    125     // Set the root of the image filter graph for this layer. The
    126     // implementation should grab a ref on the passed-in filter in order
    127     // to retain ownership. The passed-in graph will be unref'ed by the
    128     // caller after this call.
    129     virtual void setFilter(SkImageFilter*) = 0;
    130 
    131     // Apply filters to pixels that show through the background of this layer.
    132     // Note: These filters are only possible on layers that are drawn directly
    133     // to a root render surface with an opaque background. This means if an
    134     // ancestor of the background-filtered layer sets certain properties
    135     // (opacity, transforms), it may conflict and hide the background filters.
    136     virtual void setBackgroundFilters(const WebFilterOperations&) = 0;
    137 
    138     virtual void setDebugName(WebString) = 0;
    139 
    140     // Provides a bitfield that describe why this composited layer was created.
    141     // FIXME: non-pure until the chromium-side implements this.
    142     virtual void setCompositingReasons(WebCompositingReasons) { }
    143 
    144     // An animation delegate is notified when animations are started and
    145     // stopped. The WebLayer does not take ownership of the delegate, and it is
    146     // the responsibility of the client to reset the layer's delegate before
    147     // deleting the delegate.
    148     virtual void setAnimationDelegate(WebAnimationDelegate*) = 0;
    149 
    150     // Returns false if the animation cannot be added.
    151     virtual bool addAnimation(WebAnimation*) = 0;
    152 
    153     // Removes all animations with the given id.
    154     virtual void removeAnimation(int animationId) = 0;
    155 
    156     // Removes all animations with the given id targeting the given property.
    157     virtual void removeAnimation(int animationId, WebAnimation::TargetProperty) = 0;
    158 
    159     // Pauses all animations with the given id.
    160     virtual void pauseAnimation(int animationId, double timeOffset) = 0;
    161 
    162     // The following functions suspend and resume all animations. The given time
    163     // is assumed to use the same time base as monotonicallyIncreasingTime().
    164     virtual void suspendAnimations(double monotonicTime) = 0;
    165     virtual void resumeAnimations(double monotonicTime) = 0;
    166 
    167     // Returns true if this layer has any active animations - useful for tests.
    168     virtual bool hasActiveAnimation() = 0;
    169 
    170     // Transfers all animations running on the current layer.
    171     virtual void transferAnimationsTo(WebLayer*) { }
    172 
    173     // Scrolling
    174     virtual void setScrollPosition(WebPoint) = 0;
    175     virtual WebPoint scrollPosition() const = 0;
    176 
    177     virtual void setMaxScrollPosition(WebSize) = 0;
    178     virtual WebSize maxScrollPosition() const = 0;
    179 
    180     virtual void setScrollable(bool) = 0;
    181     virtual bool scrollable() const = 0;
    182 
    183     virtual void setHaveWheelEventHandlers(bool) = 0;
    184     virtual bool haveWheelEventHandlers() const = 0;
    185 
    186     virtual void setShouldScrollOnMainThread(bool) = 0;
    187     virtual bool shouldScrollOnMainThread() const = 0;
    188 
    189     virtual void setNonFastScrollableRegion(const WebVector<WebRect>&) = 0;
    190     virtual WebVector<WebRect> nonFastScrollableRegion() const = 0;
    191 
    192     virtual void setTouchEventHandlerRegion(const WebVector<WebRect>&) { };
    193     virtual WebVector<WebRect> touchEventHandlerRegion() const { return WebVector<WebRect>();}
    194 
    195     virtual void setIsContainerForFixedPositionLayers(bool) = 0;
    196     virtual bool isContainerForFixedPositionLayers() const = 0;
    197 
    198     // This function sets layer position constraint. The constraint will be used
    199     // to adjust layer position during threaded scrolling.
    200     virtual void setPositionConstraint(const WebLayerPositionConstraint&) = 0;
    201     virtual WebLayerPositionConstraint positionConstraint() const = 0;
    202 
    203     // The scroll client is notified when the scroll position of the WebLayer
    204     // changes. Only a single scroll client can be set for a WebLayer at a time.
    205     // The WebLayer does not take ownership of the scroll client, and it is the
    206     // responsibility of the client to reset the layer's scroll client before
    207     // deleting the scroll client.
    208     virtual void setScrollClient(WebLayerScrollClient*) = 0;
    209 
    210     // Forces this layer to use a render surface. There is no benefit in doing
    211     // so, but this is to facilitate benchmarks and tests.
    212     virtual void setForceRenderSurface(bool) = 0;
    213 
    214     // True if the layer is not part of a tree attached to a WebLayerTreeView.
    215     virtual bool isOrphan() const = 0;
    216 };
    217 
    218 } // namespace WebKit
    219 
    220 #endif // WebLayer_h
    221