tizen beta release
[profile/ivi/webkit-efl.git] / Source / WebKit / chromium / public / WebLayer.h
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 "platform/WebColor.h"
30 #include "platform/WebCommon.h"
31 #include "platform/WebPrivatePtr.h"
32
33 class SkMatrix44;
34 namespace WebCore { class LayerChromium; }
35
36 namespace WebKit {
37 struct WebFloatPoint;
38 class WebLayerClient;
39 struct WebSize;
40
41 class WebLayer {
42 public:
43     WEBKIT_EXPORT static WebLayer create(WebLayerClient*);
44
45     WebLayer() { }
46     WebLayer(const WebLayer& layer) { assign(layer); }
47     virtual ~WebLayer() { reset(); }
48     WebLayer& operator=(const WebLayer& layer)
49     {
50         assign(layer);
51         return *this;
52     }
53     bool isNull() { return m_private.isNull(); }
54     WEBKIT_EXPORT void reset();
55     WEBKIT_EXPORT void assign(const WebLayer&);
56     WEBKIT_EXPORT bool equals(const WebLayer&) const;
57
58     WEBKIT_EXPORT WebLayer rootLayer() const;
59     WEBKIT_EXPORT WebLayer parent() const;
60     WEBKIT_EXPORT void addChild(const WebLayer&);
61     WEBKIT_EXPORT void insertChild(const WebLayer&, size_t index);
62     WEBKIT_EXPORT void replaceChild(const WebLayer& reference, const WebLayer& newLayer);
63     WEBKIT_EXPORT void removeFromParent();
64     WEBKIT_EXPORT void removeAllChildren();
65
66     WEBKIT_EXPORT void setAnchorPoint(const WebFloatPoint&);
67     WEBKIT_EXPORT WebFloatPoint anchorPoint() const;
68
69     WEBKIT_EXPORT void setAnchorPointZ(float);
70     WEBKIT_EXPORT float anchorPointZ() const;
71
72     WEBKIT_EXPORT void setBounds(const WebSize&);
73     WEBKIT_EXPORT WebSize bounds() const;
74
75     WEBKIT_EXPORT void setMasksToBounds(bool);
76     WEBKIT_EXPORT bool masksToBounds() const;
77
78     WEBKIT_EXPORT void setMaskLayer(const WebLayer&);
79     WEBKIT_EXPORT WebLayer maskLayer() const;
80
81     WEBKIT_EXPORT void setOpacity(float);
82     WEBKIT_EXPORT float opacity() const;
83
84     WEBKIT_EXPORT void setOpaque(bool);
85     WEBKIT_EXPORT bool opaque() const;
86
87     WEBKIT_EXPORT void setPosition(const WebFloatPoint&);
88     WEBKIT_EXPORT WebFloatPoint position() const;
89
90     WEBKIT_EXPORT void setSublayerTransform(const SkMatrix44&);
91     WEBKIT_EXPORT SkMatrix44 sublayerTransform() const;
92
93     WEBKIT_EXPORT void setTransform(const SkMatrix44&);
94     WEBKIT_EXPORT SkMatrix44 transform() const;
95
96     WEBKIT_EXPORT void setDebugBorderColor(const WebColor&);
97     WEBKIT_EXPORT void setDebugBorderWidth(float);
98
99     template<typename T> T to()
100     {
101         T res;
102         res.WebLayer::assign(*this);
103         return res;
104     }
105
106     template<typename T> const T toConst() const
107     {
108         T res;
109         res.WebLayer::assign(*this);
110         return res;
111     }
112
113 #if WEBKIT_IMPLEMENTATION
114     WebLayer(const WTF::PassRefPtr<WebCore::LayerChromium>&);
115     WebLayer& operator=(const WTF::PassRefPtr<WebCore::LayerChromium>&);
116     operator WTF::PassRefPtr<WebCore::LayerChromium>() const;
117     template<typename T> T* unwrap()
118     {
119         return static_cast<T*>(m_private.get());
120     }
121
122     template<typename T> const T* constUnwrap() const
123     {
124         return static_cast<const T*>(m_private.get());
125     }
126 #endif
127
128 protected:
129     WebPrivatePtr<WebCore::LayerChromium> m_private;
130 };
131
132 inline bool operator==(const WebLayer& a, const WebLayer& b)
133 {
134     return a.equals(b);
135 }
136
137 inline bool operator!=(const WebLayer& a, const WebLayer& b)
138 {
139     return !(a == b);
140 }
141
142 } // namespace WebKit
143
144 #endif // WebLayer_h