initial import
[vuplus_webkit] / Source / WebCore / css / CSSWrapShapes.h
1 /*
2  * Copyright 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 CSSWrapShapes_h
31 #define CSSWrapShapes_h
32
33 #include "CSSPrimitiveValue.h"
34 #include "PlatformString.h"
35 #include "WindRule.h"
36 #include <wtf/RefPtr.h>
37 #include <wtf/Vector.h>
38
39 namespace WebCore {
40
41 class CSSWrapShape : public RefCounted<CSSWrapShape> {
42 public:
43     enum Type {
44         CSS_WRAP_SHAPE_RECT = 1,
45         CSS_WRAP_SHAPE_CIRCLE = 2,
46         CSS_WRAP_SHAPE_ELLIPSE = 3,
47         CSS_WRAP_SHAPE_POLYGON = 4,
48         CSS_WRAP_SHAPE_PATH = 5        
49     };
50     
51     virtual Type type() = 0;
52     virtual String cssText() const = 0;
53
54 public:
55     virtual ~CSSWrapShape() { }
56     
57 protected:
58     CSSWrapShape() { }
59 };
60
61 class CSSWrapShapeRect : public CSSWrapShape {
62 public:
63     static PassRefPtr<CSSWrapShapeRect> create() { return adoptRef(new CSSWrapShapeRect); }
64
65     CSSPrimitiveValue* left() const { return m_left.get(); }
66     CSSPrimitiveValue* top() const { return m_top.get(); }
67     CSSPrimitiveValue* width() const { return m_width.get(); }
68     CSSPrimitiveValue* height() const { return m_height.get(); }
69     CSSPrimitiveValue* radiusX() const { return m_radiusX.get(); }
70     CSSPrimitiveValue* radiusY() const { return m_radiusY.get(); }
71     
72     void setLeft(PassRefPtr<CSSPrimitiveValue> left) { m_left = left; }
73     void setTop(PassRefPtr<CSSPrimitiveValue> top) { m_top = top; }
74     void setWidth(PassRefPtr<CSSPrimitiveValue> width) { m_width = width; }
75     void setHeight(PassRefPtr<CSSPrimitiveValue> height) { m_height = height; }
76     void setRadiusX(PassRefPtr<CSSPrimitiveValue> radiusX) { m_radiusX = radiusX; }
77     void setRadiusY(PassRefPtr<CSSPrimitiveValue> radiusY) { m_radiusY = radiusY; }
78
79     virtual Type type() { return CSS_WRAP_SHAPE_RECT; }
80     virtual String cssText() const;
81     
82 private:
83     CSSWrapShapeRect() { }
84     
85     RefPtr<CSSPrimitiveValue> m_top;
86     RefPtr<CSSPrimitiveValue> m_left;
87     RefPtr<CSSPrimitiveValue> m_width;
88     RefPtr<CSSPrimitiveValue> m_height;
89     RefPtr<CSSPrimitiveValue> m_radiusX;
90     RefPtr<CSSPrimitiveValue> m_radiusY;
91 };
92
93 class CSSWrapShapeCircle : public CSSWrapShape {
94 public:
95     static PassRefPtr<CSSWrapShapeCircle> create() { return adoptRef(new CSSWrapShapeCircle); }
96
97     CSSPrimitiveValue* left() const { return m_left.get(); }
98     CSSPrimitiveValue* top() const { return m_top.get(); }
99     CSSPrimitiveValue* radius() const { return m_radius.get(); }
100     
101     void setLeft(PassRefPtr<CSSPrimitiveValue> left) { m_left = left; }
102     void setTop(PassRefPtr<CSSPrimitiveValue> top) { m_top = top; }
103     void setRadius(PassRefPtr<CSSPrimitiveValue> radius) { m_radius = radius; }
104
105     virtual Type type() { return CSS_WRAP_SHAPE_CIRCLE; }
106     virtual String cssText() const;
107     
108 private:
109     CSSWrapShapeCircle() { }
110     
111     RefPtr<CSSPrimitiveValue> m_top;
112     RefPtr<CSSPrimitiveValue> m_left;
113     RefPtr<CSSPrimitiveValue> m_radius;
114 };
115
116 class CSSWrapShapeEllipse : public CSSWrapShape {
117 public:
118     static PassRefPtr<CSSWrapShapeEllipse> create() { return adoptRef(new CSSWrapShapeEllipse); }
119
120     CSSPrimitiveValue* left() const { return m_left.get(); }
121     CSSPrimitiveValue* top() const { return m_top.get(); }
122     CSSPrimitiveValue* radiusX() const { return m_radiusX.get(); }
123     CSSPrimitiveValue* radiusY() const { return m_radiusY.get(); }
124     
125     void setLeft(PassRefPtr<CSSPrimitiveValue> left) { m_left = left; }
126     void setTop(PassRefPtr<CSSPrimitiveValue> top) { m_top = top; }
127     void setRadiusX(PassRefPtr<CSSPrimitiveValue> radiusX) { m_radiusX = radiusX; }
128     void setRadiusY(PassRefPtr<CSSPrimitiveValue> radiusY) { m_radiusY = radiusY; }
129
130     virtual Type type() { return CSS_WRAP_SHAPE_ELLIPSE; }
131     virtual String cssText() const;
132     
133 private:
134     CSSWrapShapeEllipse() { }
135     
136     RefPtr<CSSPrimitiveValue> m_top;
137     RefPtr<CSSPrimitiveValue> m_left;
138     RefPtr<CSSPrimitiveValue> m_radiusX;
139     RefPtr<CSSPrimitiveValue> m_radiusY;
140 };
141
142 class CSSWrapShapePolygon : public CSSWrapShape {
143 public:
144     static PassRefPtr<CSSWrapShapePolygon> create() { return adoptRef(new CSSWrapShapePolygon); }
145     
146     void appendPoint(PassRefPtr<CSSPrimitiveValue> x, PassRefPtr<CSSPrimitiveValue> y)
147     { 
148         m_values.append(x);
149         m_values.append(y);
150     }
151     
152     PassRefPtr<CSSPrimitiveValue> getXAt(unsigned i) { return m_values.at(i * 2); }
153     PassRefPtr<CSSPrimitiveValue> getYAt(unsigned i) { return m_values.at(i * 2 + 1); }
154     
155     void setWindRule(WindRule w) { m_windRule = w; }
156     WindRule windRule() const { return m_windRule; }
157     
158     virtual Type type() { return CSS_WRAP_SHAPE_POLYGON; }
159     virtual String cssText() const;
160     
161 private:
162     CSSWrapShapePolygon()
163         : m_windRule(RULE_NONZERO)
164     {
165     }
166     
167     Vector<RefPtr<CSSPrimitiveValue> > m_values;
168     WindRule m_windRule;    
169 };
170
171 } // namespace WebCore
172
173 #endif // CSSWrapShapes_h