• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/GraphicsTypes.h"
35 #include "wtf/RefPtr.h"
36 #include "wtf/Vector.h"
37 #include "wtf/text/WTFString.h"
38 
39 namespace blink {
40 
41 class CSSBasicShape : public RefCountedWillBeGarbageCollected<CSSBasicShape> {
42     DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(CSSBasicShape);
43 public:
44     enum Type {
45         CSSBasicShapeEllipseType,
46         CSSBasicShapePolygonType,
47         CSSBasicShapeCircleType,
48         CSSBasicShapeInsetType
49     };
50 
51     virtual Type type() const = 0;
52     virtual String cssText() const = 0;
53     virtual bool equals(const CSSBasicShape&) const = 0;
54 
referenceBox()55     CSSPrimitiveValue* referenceBox() const { return m_referenceBox.get(); }
setReferenceBox(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> referenceBox)56     void setReferenceBox(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> referenceBox) { m_referenceBox = referenceBox; }
57 
trace(Visitor * visitor)58     virtual void trace(Visitor* visitor) { visitor->trace(m_referenceBox); }
59 
60 protected:
CSSBasicShape()61     CSSBasicShape() { }
62     RefPtrWillBeMember<CSSPrimitiveValue> m_referenceBox;
63 };
64 
65 class CSSBasicShapeCircle FINAL : public CSSBasicShape {
66 public:
create()67     static PassRefPtrWillBeRawPtr<CSSBasicShapeCircle> create() { return adoptRefWillBeNoop(new CSSBasicShapeCircle); }
68 
type()69     virtual Type type() const OVERRIDE { return CSSBasicShapeCircleType; }
70     virtual String cssText() const OVERRIDE;
71     virtual bool equals(const CSSBasicShape&) const OVERRIDE;
72 
centerX()73     CSSPrimitiveValue* centerX() const { return m_centerX.get(); }
centerY()74     CSSPrimitiveValue* centerY() const { return m_centerY.get(); }
radius()75     CSSPrimitiveValue* radius() const { return m_radius.get(); }
76 
setCenterX(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> centerX)77     void setCenterX(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> centerX) { m_centerX = centerX; }
setCenterY(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> centerY)78     void setCenterY(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> centerY) { m_centerY = centerY; }
setRadius(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radius)79     void setRadius(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radius) { m_radius = radius; }
80 
81     virtual void trace(Visitor*);
82 
83 private:
CSSBasicShapeCircle()84     CSSBasicShapeCircle() { }
85 
86     RefPtrWillBeMember<CSSPrimitiveValue> m_centerX;
87     RefPtrWillBeMember<CSSPrimitiveValue> m_centerY;
88     RefPtrWillBeMember<CSSPrimitiveValue> m_radius;
89 };
90 
91 class CSSBasicShapeEllipse FINAL : public CSSBasicShape {
92 public:
create()93     static PassRefPtrWillBeRawPtr<CSSBasicShapeEllipse> create() { return adoptRefWillBeNoop(new CSSBasicShapeEllipse); }
94 
type()95     virtual Type type() const OVERRIDE { return CSSBasicShapeEllipseType; }
96     virtual String cssText() const OVERRIDE;
97     virtual bool equals(const CSSBasicShape&) const OVERRIDE;
98 
centerX()99     CSSPrimitiveValue* centerX() const { return m_centerX.get(); }
centerY()100     CSSPrimitiveValue* centerY() const { return m_centerY.get(); }
radiusX()101     CSSPrimitiveValue* radiusX() const { return m_radiusX.get(); }
radiusY()102     CSSPrimitiveValue* radiusY() const { return m_radiusY.get(); }
103 
setCenterX(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> centerX)104     void setCenterX(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> centerX) { m_centerX = centerX; }
setCenterY(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> centerY)105     void setCenterY(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> centerY) { m_centerY = centerY; }
setRadiusX(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radiusX)106     void setRadiusX(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radiusX) { m_radiusX = radiusX; }
setRadiusY(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radiusY)107     void setRadiusY(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radiusY) { m_radiusY = radiusY; }
108 
109     virtual void trace(Visitor*);
110 
111 private:
CSSBasicShapeEllipse()112     CSSBasicShapeEllipse() { }
113 
114     RefPtrWillBeMember<CSSPrimitiveValue> m_centerX;
115     RefPtrWillBeMember<CSSPrimitiveValue> m_centerY;
116     RefPtrWillBeMember<CSSPrimitiveValue> m_radiusX;
117     RefPtrWillBeMember<CSSPrimitiveValue> m_radiusY;
118 };
119 
120 class CSSBasicShapePolygon FINAL : public CSSBasicShape {
121 public:
create()122     static PassRefPtrWillBeRawPtr<CSSBasicShapePolygon> create() { return adoptRefWillBeNoop(new CSSBasicShapePolygon); }
123 
appendPoint(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> x,PassRefPtrWillBeRawPtr<CSSPrimitiveValue> y)124     void appendPoint(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> x, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> y)
125     {
126         m_values.append(x);
127         m_values.append(y);
128     }
129 
getXAt(unsigned i)130     PassRefPtrWillBeRawPtr<CSSPrimitiveValue> getXAt(unsigned i) const { return m_values.at(i * 2); }
getYAt(unsigned i)131     PassRefPtrWillBeRawPtr<CSSPrimitiveValue> getYAt(unsigned i) const { return m_values.at(i * 2 + 1); }
values()132     const WillBeHeapVector<RefPtrWillBeMember<CSSPrimitiveValue> >& values() const { return m_values; }
133 
setWindRule(WindRule w)134     void setWindRule(WindRule w) { m_windRule = w; }
windRule()135     WindRule windRule() const { return m_windRule; }
136 
type()137     virtual Type type() const OVERRIDE { return CSSBasicShapePolygonType; }
138     virtual String cssText() const OVERRIDE;
139     virtual bool equals(const CSSBasicShape&) const OVERRIDE;
140 
141     virtual void trace(Visitor*);
142 
143 private:
CSSBasicShapePolygon()144     CSSBasicShapePolygon()
145         : m_windRule(RULE_NONZERO)
146     {
147     }
148 
149     WillBeHeapVector<RefPtrWillBeMember<CSSPrimitiveValue> > m_values;
150     WindRule m_windRule;
151 };
152 
153 class CSSBasicShapeInset : public CSSBasicShape {
154 public:
create()155     static PassRefPtrWillBeRawPtr<CSSBasicShapeInset> create() { return adoptRefWillBeNoop(new CSSBasicShapeInset); }
156 
top()157     CSSPrimitiveValue* top() const { return m_top.get(); }
right()158     CSSPrimitiveValue* right() const { return m_right.get(); }
bottom()159     CSSPrimitiveValue* bottom() const { return m_bottom.get(); }
left()160     CSSPrimitiveValue* left() const { return m_left.get(); }
161 
topLeftRadius()162     CSSPrimitiveValue* topLeftRadius() const { return m_topLeftRadius.get(); }
topRightRadius()163     CSSPrimitiveValue* topRightRadius() const { return m_topRightRadius.get(); }
bottomRightRadius()164     CSSPrimitiveValue* bottomRightRadius() const { return m_bottomRightRadius.get(); }
bottomLeftRadius()165     CSSPrimitiveValue* bottomLeftRadius() const { return m_bottomLeftRadius.get(); }
166 
setTop(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> top)167     void setTop(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> top) { m_top = top; }
setRight(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> right)168     void setRight(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> right) { m_right = right; }
setBottom(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> bottom)169     void setBottom(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> bottom) { m_bottom = bottom; }
setLeft(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> left)170     void setLeft(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> left) { m_left = left; }
171 
updateShapeSize4Values(CSSPrimitiveValue * top,CSSPrimitiveValue * right,CSSPrimitiveValue * bottom,CSSPrimitiveValue * left)172     void updateShapeSize4Values(CSSPrimitiveValue* top, CSSPrimitiveValue* right, CSSPrimitiveValue* bottom, CSSPrimitiveValue* left)
173     {
174         setTop(top);
175         setRight(right);
176         setBottom(bottom);
177         setLeft(left);
178     }
179 
updateShapeSize1Value(CSSPrimitiveValue * value1)180     void updateShapeSize1Value(CSSPrimitiveValue* value1)
181     {
182         updateShapeSize4Values(value1, value1, value1, value1);
183     }
184 
updateShapeSize2Values(CSSPrimitiveValue * value1,CSSPrimitiveValue * value2)185     void updateShapeSize2Values(CSSPrimitiveValue* value1,  CSSPrimitiveValue* value2)
186     {
187         updateShapeSize4Values(value1, value2, value1, value2);
188     }
189 
updateShapeSize3Values(CSSPrimitiveValue * value1,CSSPrimitiveValue * value2,CSSPrimitiveValue * value3)190     void updateShapeSize3Values(CSSPrimitiveValue* value1, CSSPrimitiveValue* value2,  CSSPrimitiveValue* value3)
191     {
192         updateShapeSize4Values(value1, value2, value3, value2);
193     }
194 
195 
setTopLeftRadius(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radius)196     void setTopLeftRadius(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radius) { m_topLeftRadius = radius; }
setTopRightRadius(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radius)197     void setTopRightRadius(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radius) { m_topRightRadius = radius; }
setBottomRightRadius(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radius)198     void setBottomRightRadius(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radius) { m_bottomRightRadius = radius; }
setBottomLeftRadius(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radius)199     void setBottomLeftRadius(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radius) { m_bottomLeftRadius = radius; }
200 
type()201     virtual Type type() const OVERRIDE { return CSSBasicShapeInsetType; }
202     virtual String cssText() const OVERRIDE;
203     virtual bool equals(const CSSBasicShape&) const OVERRIDE;
204 
205     virtual void trace(Visitor*);
206 
207 private:
CSSBasicShapeInset()208     CSSBasicShapeInset() { }
209 
210     RefPtrWillBeMember<CSSPrimitiveValue> m_top;
211     RefPtrWillBeMember<CSSPrimitiveValue> m_right;
212     RefPtrWillBeMember<CSSPrimitiveValue> m_bottom;
213     RefPtrWillBeMember<CSSPrimitiveValue> m_left;
214 
215     RefPtrWillBeMember<CSSPrimitiveValue> m_topLeftRadius;
216     RefPtrWillBeMember<CSSPrimitiveValue> m_topRightRadius;
217     RefPtrWillBeMember<CSSPrimitiveValue> m_bottomRightRadius;
218     RefPtrWillBeMember<CSSPrimitiveValue> m_bottomLeftRadius;
219 };
220 
221 } // namespace blink
222 
223 #endif // CSSBasicShapes_h
224