Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / css / CSSBasicShapes.h
1 /*
2  * Copyright (C) 2011 Adobe Systems Incorporated. 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
9  *    copyright notice, this list of conditions and the following
10  *    disclaimer.
11  * 2. Redistributions in binary form must reproduce the above
12  *    copyright notice, this list of conditions and the following
13  *    disclaimer in the documentation and/or other materials
14  *    provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
25  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
26  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 #ifndef CSSBasicShapes_h
31 #define CSSBasicShapes_h
32
33 #include "core/css/CSSPrimitiveValue.h"
34 #include "platform/graphics/WindRule.h"
35 #include "wtf/RefPtr.h"
36 #include "wtf/Vector.h"
37 #include "wtf/text/WTFString.h"
38
39 namespace WebCore {
40
41 class CSSBasicShape : public RefCounted<CSSBasicShape> {
42 public:
43     enum Type {
44         CSSBasicShapeRectangleType,
45         CSSDeprecatedBasicShapeCircleType,
46         CSSDeprecatedBasicShapeEllipseType,
47         CSSBasicShapeEllipseType,
48         CSSBasicShapePolygonType,
49         CSSBasicShapeInsetRectangleType,
50         CSSBasicShapeCircleType,
51         CSSBasicShapeInsetType
52     };
53
54     virtual Type type() const = 0;
55     virtual String cssText() const = 0;
56     virtual bool equals(const CSSBasicShape&) const = 0;
57
58     CSSPrimitiveValue* layoutBox() const { return m_layoutBox.get(); }
59     void setLayoutBox(PassRefPtr<CSSPrimitiveValue> layoutBox) { m_layoutBox = layoutBox; }
60
61 public:
62     virtual ~CSSBasicShape() { }
63
64 protected:
65     CSSBasicShape() { }
66     RefPtr<CSSPrimitiveValue> m_layoutBox;
67 };
68
69 class CSSBasicShapeRectangle FINAL : public CSSBasicShape {
70 public:
71     static PassRefPtr<CSSBasicShapeRectangle> create() { return adoptRef(new CSSBasicShapeRectangle); }
72
73     CSSPrimitiveValue* x() const { return m_x.get(); }
74     CSSPrimitiveValue* y() const { return m_y.get(); }
75     CSSPrimitiveValue* width() const { return m_width.get(); }
76     CSSPrimitiveValue* height() const { return m_height.get(); }
77     CSSPrimitiveValue* radiusX() const { return m_radiusX.get(); }
78     CSSPrimitiveValue* radiusY() const { return m_radiusY.get(); }
79
80     void setX(PassRefPtr<CSSPrimitiveValue> x) { m_x = x; }
81     void setY(PassRefPtr<CSSPrimitiveValue> y) { m_y = y; }
82     void setWidth(PassRefPtr<CSSPrimitiveValue> width) { m_width = width; }
83     void setHeight(PassRefPtr<CSSPrimitiveValue> height) { m_height = height; }
84     void setRadiusX(PassRefPtr<CSSPrimitiveValue> radiusX) { m_radiusX = radiusX; }
85     void setRadiusY(PassRefPtr<CSSPrimitiveValue> radiusY) { m_radiusY = radiusY; }
86
87     virtual Type type() const OVERRIDE { return CSSBasicShapeRectangleType; }
88     virtual String cssText() const OVERRIDE;
89     virtual bool equals(const CSSBasicShape&) const OVERRIDE;
90
91 private:
92     CSSBasicShapeRectangle() { }
93
94     RefPtr<CSSPrimitiveValue> m_y;
95     RefPtr<CSSPrimitiveValue> m_x;
96     RefPtr<CSSPrimitiveValue> m_width;
97     RefPtr<CSSPrimitiveValue> m_height;
98     RefPtr<CSSPrimitiveValue> m_radiusX;
99     RefPtr<CSSPrimitiveValue> m_radiusY;
100 };
101
102 class CSSBasicShapeInsetRectangle FINAL : public CSSBasicShape {
103 public:
104     static PassRefPtr<CSSBasicShapeInsetRectangle> create() { return adoptRef(new CSSBasicShapeInsetRectangle); }
105
106     CSSPrimitiveValue* top() const { return m_top.get(); }
107     CSSPrimitiveValue* right() const { return m_right.get(); }
108     CSSPrimitiveValue* bottom() const { return m_bottom.get(); }
109     CSSPrimitiveValue* left() const { return m_left.get(); }
110     CSSPrimitiveValue* radiusX() const { return m_radiusX.get(); }
111     CSSPrimitiveValue* radiusY() const { return m_radiusY.get(); }
112
113     void setTop(PassRefPtr<CSSPrimitiveValue> top) { m_top = top; }
114     void setRight(PassRefPtr<CSSPrimitiveValue> right) { m_right = right; }
115     void setBottom(PassRefPtr<CSSPrimitiveValue> bottom) { m_bottom = bottom; }
116     void setLeft(PassRefPtr<CSSPrimitiveValue> left) { m_left = left; }
117     void setRadiusX(PassRefPtr<CSSPrimitiveValue> radiusX) { m_radiusX = radiusX; }
118     void setRadiusY(PassRefPtr<CSSPrimitiveValue> radiusY) { m_radiusY = radiusY; }
119
120     virtual Type type() const OVERRIDE { return CSSBasicShapeInsetRectangleType; }
121     virtual String cssText() const OVERRIDE;
122     virtual bool equals(const CSSBasicShape&) const OVERRIDE;
123
124 private:
125     CSSBasicShapeInsetRectangle() { }
126
127     RefPtr<CSSPrimitiveValue> m_right;
128     RefPtr<CSSPrimitiveValue> m_top;
129     RefPtr<CSSPrimitiveValue> m_bottom;
130     RefPtr<CSSPrimitiveValue> m_left;
131     RefPtr<CSSPrimitiveValue> m_radiusX;
132     RefPtr<CSSPrimitiveValue> m_radiusY;
133 };
134
135 class CSSBasicShapeCircle FINAL : public CSSBasicShape {
136 public:
137     static PassRefPtr<CSSBasicShapeCircle> create() { return adoptRef(new CSSBasicShapeCircle); }
138
139     virtual Type type() const OVERRIDE { return CSSBasicShapeCircleType; }
140     virtual String cssText() const OVERRIDE;
141     virtual bool equals(const CSSBasicShape&) const OVERRIDE;
142
143     CSSPrimitiveValue* centerX() const { return m_centerX.get(); }
144     CSSPrimitiveValue* centerY() const { return m_centerY.get(); }
145     CSSPrimitiveValue* radius() const { return m_radius.get(); }
146
147     void setCenterX(PassRefPtr<CSSPrimitiveValue> centerX) { m_centerX = centerX; }
148     void setCenterY(PassRefPtr<CSSPrimitiveValue> centerY) { m_centerY = centerY; }
149     void setRadius(PassRefPtr<CSSPrimitiveValue> radius) { m_radius = radius; }
150
151 private:
152     CSSBasicShapeCircle() { }
153
154     RefPtr<CSSPrimitiveValue> m_centerX;
155     RefPtr<CSSPrimitiveValue> m_centerY;
156     RefPtr<CSSPrimitiveValue> m_radius;
157 };
158
159 class CSSDeprecatedBasicShapeCircle FINAL : public CSSBasicShape {
160 public:
161     static PassRefPtr<CSSDeprecatedBasicShapeCircle> create() { return adoptRef(new CSSDeprecatedBasicShapeCircle); }
162
163     CSSPrimitiveValue* centerX() const { return m_centerX.get(); }
164     CSSPrimitiveValue* centerY() const { return m_centerY.get(); }
165     CSSPrimitiveValue* radius() const { return m_radius.get(); }
166
167     void setCenterX(PassRefPtr<CSSPrimitiveValue> centerX) { m_centerX = centerX; }
168     void setCenterY(PassRefPtr<CSSPrimitiveValue> centerY) { m_centerY = centerY; }
169     void setRadius(PassRefPtr<CSSPrimitiveValue> radius) { m_radius = radius; }
170
171     virtual Type type() const OVERRIDE { return CSSDeprecatedBasicShapeCircleType; }
172
173     virtual String cssText() const OVERRIDE;
174     virtual bool equals(const CSSBasicShape&) const OVERRIDE;
175
176 private:
177     CSSDeprecatedBasicShapeCircle() { }
178
179     RefPtr<CSSPrimitiveValue> m_centerY;
180     RefPtr<CSSPrimitiveValue> m_centerX;
181     RefPtr<CSSPrimitiveValue> m_radius;
182 };
183
184 class CSSBasicShapeEllipse FINAL : public CSSBasicShape {
185 public:
186     static PassRefPtr<CSSBasicShapeEllipse> create() { return adoptRef(new CSSBasicShapeEllipse); }
187
188     virtual Type type() const OVERRIDE { return CSSBasicShapeEllipseType; }
189     virtual String cssText() const OVERRIDE;
190     virtual bool equals(const CSSBasicShape&) const OVERRIDE;
191
192     CSSPrimitiveValue* centerX() const { return m_centerX.get(); }
193     CSSPrimitiveValue* centerY() const { return m_centerY.get(); }
194     CSSPrimitiveValue* radiusX() const { return m_radiusX.get(); }
195     CSSPrimitiveValue* radiusY() const { return m_radiusY.get(); }
196
197     void setCenterX(PassRefPtr<CSSPrimitiveValue> centerX) { m_centerX = centerX; }
198     void setCenterY(PassRefPtr<CSSPrimitiveValue> centerY) { m_centerY = centerY; }
199     void setRadiusX(PassRefPtr<CSSPrimitiveValue> radiusX) { m_radiusX = radiusX; }
200     void setRadiusY(PassRefPtr<CSSPrimitiveValue> radiusY) { m_radiusY = radiusY; }
201
202 private:
203     CSSBasicShapeEllipse() { }
204
205     RefPtr<CSSPrimitiveValue> m_centerX;
206     RefPtr<CSSPrimitiveValue> m_centerY;
207     RefPtr<CSSPrimitiveValue> m_radiusX;
208     RefPtr<CSSPrimitiveValue> m_radiusY;
209 };
210
211 class CSSDeprecatedBasicShapeEllipse FINAL : public CSSBasicShape {
212 public:
213     static PassRefPtr<CSSDeprecatedBasicShapeEllipse> create() { return adoptRef(new CSSDeprecatedBasicShapeEllipse); }
214
215     CSSPrimitiveValue* centerX() const { return m_centerX.get(); }
216     CSSPrimitiveValue* centerY() const { return m_centerY.get(); }
217     CSSPrimitiveValue* radiusX() const { return m_radiusX.get(); }
218     CSSPrimitiveValue* radiusY() const { return m_radiusY.get(); }
219
220     void setCenterX(PassRefPtr<CSSPrimitiveValue> centerX) { m_centerX = centerX; }
221     void setCenterY(PassRefPtr<CSSPrimitiveValue> centerY) { m_centerY = centerY; }
222     void setRadiusX(PassRefPtr<CSSPrimitiveValue> radiusX) { m_radiusX = radiusX; }
223     void setRadiusY(PassRefPtr<CSSPrimitiveValue> radiusY) { m_radiusY = radiusY; }
224
225     virtual Type type() const OVERRIDE { return CSSDeprecatedBasicShapeEllipseType; }
226     virtual String cssText() const OVERRIDE;
227     virtual bool equals(const CSSBasicShape&) const OVERRIDE;
228
229 private:
230     CSSDeprecatedBasicShapeEllipse() { }
231
232     RefPtr<CSSPrimitiveValue> m_centerX;
233     RefPtr<CSSPrimitiveValue> m_centerY;
234     RefPtr<CSSPrimitiveValue> m_radiusX;
235     RefPtr<CSSPrimitiveValue> m_radiusY;
236 };
237
238 class CSSBasicShapePolygon FINAL : public CSSBasicShape {
239 public:
240     static PassRefPtr<CSSBasicShapePolygon> create() { return adoptRef(new CSSBasicShapePolygon); }
241
242     void appendPoint(PassRefPtr<CSSPrimitiveValue> x, PassRefPtr<CSSPrimitiveValue> y)
243     {
244         m_values.append(x);
245         m_values.append(y);
246     }
247
248     PassRefPtr<CSSPrimitiveValue> getXAt(unsigned i) const { return m_values.at(i * 2); }
249     PassRefPtr<CSSPrimitiveValue> getYAt(unsigned i) const { return m_values.at(i * 2 + 1); }
250     const Vector<RefPtr<CSSPrimitiveValue> >& values() const { return m_values; }
251
252     void setWindRule(WindRule w) { m_windRule = w; }
253     WindRule windRule() const { return m_windRule; }
254
255     virtual Type type() const OVERRIDE { return CSSBasicShapePolygonType; }
256     virtual String cssText() const OVERRIDE;
257     virtual bool equals(const CSSBasicShape&) const OVERRIDE;
258 private:
259     CSSBasicShapePolygon()
260         : m_windRule(RULE_NONZERO)
261     {
262     }
263
264     Vector<RefPtr<CSSPrimitiveValue> > m_values;
265     WindRule m_windRule;
266 };
267
268 class CSSBasicShapeInset : public CSSBasicShape {
269 public:
270     static PassRefPtr<CSSBasicShapeInset> create() { return adoptRef(new CSSBasicShapeInset); }
271
272     CSSPrimitiveValue* top() const { return m_top.get(); }
273     CSSPrimitiveValue* right() const { return m_right.get(); }
274     CSSPrimitiveValue* bottom() const { return m_bottom.get(); }
275     CSSPrimitiveValue* left() const { return m_left.get(); }
276
277     CSSPrimitiveValue* topLeftRadius() const { return m_topLeftRadius.get(); }
278     CSSPrimitiveValue* topRightRadius() const { return m_topRightRadius.get(); }
279     CSSPrimitiveValue* bottomRightRadius() const { return m_bottomRightRadius.get(); }
280     CSSPrimitiveValue* bottomLeftRadius() const { return m_bottomLeftRadius.get(); }
281
282     void setTop(PassRefPtr<CSSPrimitiveValue> top) { m_top = top; }
283     void setRight(PassRefPtr<CSSPrimitiveValue> right) { m_right = right; }
284     void setBottom(PassRefPtr<CSSPrimitiveValue> bottom) { m_bottom = bottom; }
285     void setLeft(PassRefPtr<CSSPrimitiveValue> left) { m_left = left; }
286
287     void updateShapeSize4Values(CSSPrimitiveValue* top, CSSPrimitiveValue* right, CSSPrimitiveValue* bottom, CSSPrimitiveValue* left)
288     {
289         setTop(top);
290         setRight(right);
291         setBottom(bottom);
292         setLeft(left);
293     }
294
295     void updateShapeSize1Value(CSSPrimitiveValue* value1)
296     {
297         updateShapeSize4Values(value1, value1, value1, value1);
298     }
299
300     void updateShapeSize2Values(CSSPrimitiveValue* value1,  CSSPrimitiveValue* value2)
301     {
302         updateShapeSize4Values(value1, value2, value1, value2);
303     }
304
305     void updateShapeSize3Values(CSSPrimitiveValue* value1, CSSPrimitiveValue* value2,  CSSPrimitiveValue* value3)
306     {
307         updateShapeSize4Values(value1, value2, value3, value2);
308     }
309
310
311     void setTopLeftRadius(PassRefPtr<CSSPrimitiveValue> radius) { m_topLeftRadius = radius; }
312     void setTopRightRadius(PassRefPtr<CSSPrimitiveValue> radius) { m_topRightRadius = radius; }
313     void setBottomRightRadius(PassRefPtr<CSSPrimitiveValue> radius) { m_bottomRightRadius = radius; }
314     void setBottomLeftRadius(PassRefPtr<CSSPrimitiveValue> radius) { m_bottomLeftRadius = radius; }
315
316     virtual Type type() const OVERRIDE { return CSSBasicShapeInsetType; }
317     virtual String cssText() const OVERRIDE;
318     virtual bool equals(const CSSBasicShape&) const OVERRIDE;
319
320 private:
321     CSSBasicShapeInset() { }
322
323     RefPtr<CSSPrimitiveValue> m_top;
324     RefPtr<CSSPrimitiveValue> m_right;
325     RefPtr<CSSPrimitiveValue> m_bottom;
326     RefPtr<CSSPrimitiveValue> m_left;
327
328     RefPtr<CSSPrimitiveValue> m_topLeftRadius;
329     RefPtr<CSSPrimitiveValue> m_topRightRadius;
330     RefPtr<CSSPrimitiveValue> m_bottomRightRadius;
331     RefPtr<CSSPrimitiveValue> m_bottomLeftRadius;
332 };
333
334 } // namespace WebCore
335
336 #endif // CSSBasicShapes_h