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 = 1, 45 CSSBasicShapeCircleType = 2, 46 CSSBasicShapeEllipseType = 3, 47 CSSBasicShapePolygonType = 4, 48 CSSBasicShapeInsetRectangleType = 5 49 }; 50 51 virtual Type type() const = 0; 52 virtual String cssText() const = 0; 53 virtual bool equals(const CSSBasicShape&) const = 0; 54 55 virtual String serializeResolvingVariables(const HashMap<AtomicString, String>&) const = 0; 56 virtual bool hasVariableReference() const = 0; 57 58 public: ~CSSBasicShape()59 virtual ~CSSBasicShape() { } 60 61 protected: CSSBasicShape()62 CSSBasicShape() { } 63 }; 64 65 class CSSBasicShapeRectangle : public CSSBasicShape { 66 public: create()67 static PassRefPtr<CSSBasicShapeRectangle> create() { return adoptRef(new CSSBasicShapeRectangle); } 68 x()69 CSSPrimitiveValue* x() const { return m_x.get(); } y()70 CSSPrimitiveValue* y() const { return m_y.get(); } width()71 CSSPrimitiveValue* width() const { return m_width.get(); } height()72 CSSPrimitiveValue* height() const { return m_height.get(); } radiusX()73 CSSPrimitiveValue* radiusX() const { return m_radiusX.get(); } radiusY()74 CSSPrimitiveValue* radiusY() const { return m_radiusY.get(); } 75 setX(PassRefPtr<CSSPrimitiveValue> x)76 void setX(PassRefPtr<CSSPrimitiveValue> x) { m_x = x; } setY(PassRefPtr<CSSPrimitiveValue> y)77 void setY(PassRefPtr<CSSPrimitiveValue> y) { m_y = y; } setWidth(PassRefPtr<CSSPrimitiveValue> width)78 void setWidth(PassRefPtr<CSSPrimitiveValue> width) { m_width = width; } setHeight(PassRefPtr<CSSPrimitiveValue> height)79 void setHeight(PassRefPtr<CSSPrimitiveValue> height) { m_height = height; } setRadiusX(PassRefPtr<CSSPrimitiveValue> radiusX)80 void setRadiusX(PassRefPtr<CSSPrimitiveValue> radiusX) { m_radiusX = radiusX; } setRadiusY(PassRefPtr<CSSPrimitiveValue> radiusY)81 void setRadiusY(PassRefPtr<CSSPrimitiveValue> radiusY) { m_radiusY = radiusY; } 82 type()83 virtual Type type() const { return CSSBasicShapeRectangleType; } 84 virtual String cssText() const; 85 virtual bool equals(const CSSBasicShape&) const; 86 87 virtual String serializeResolvingVariables(const HashMap<AtomicString, String>&) const; 88 virtual bool hasVariableReference() const; 89 90 private: CSSBasicShapeRectangle()91 CSSBasicShapeRectangle() { } 92 93 RefPtr<CSSPrimitiveValue> m_y; 94 RefPtr<CSSPrimitiveValue> m_x; 95 RefPtr<CSSPrimitiveValue> m_width; 96 RefPtr<CSSPrimitiveValue> m_height; 97 RefPtr<CSSPrimitiveValue> m_radiusX; 98 RefPtr<CSSPrimitiveValue> m_radiusY; 99 }; 100 101 class CSSBasicShapeInsetRectangle : public CSSBasicShape { 102 public: create()103 static PassRefPtr<CSSBasicShapeInsetRectangle> create() { return adoptRef(new CSSBasicShapeInsetRectangle); } 104 top()105 CSSPrimitiveValue* top() const { return m_top.get(); } right()106 CSSPrimitiveValue* right() const { return m_right.get(); } bottom()107 CSSPrimitiveValue* bottom() const { return m_bottom.get(); } left()108 CSSPrimitiveValue* left() const { return m_left.get(); } radiusX()109 CSSPrimitiveValue* radiusX() const { return m_radiusX.get(); } radiusY()110 CSSPrimitiveValue* radiusY() const { return m_radiusY.get(); } 111 setTop(PassRefPtr<CSSPrimitiveValue> top)112 void setTop(PassRefPtr<CSSPrimitiveValue> top) { m_top = top; } setRight(PassRefPtr<CSSPrimitiveValue> right)113 void setRight(PassRefPtr<CSSPrimitiveValue> right) { m_right = right; } setBottom(PassRefPtr<CSSPrimitiveValue> bottom)114 void setBottom(PassRefPtr<CSSPrimitiveValue> bottom) { m_bottom = bottom; } setLeft(PassRefPtr<CSSPrimitiveValue> left)115 void setLeft(PassRefPtr<CSSPrimitiveValue> left) { m_left = left; } setRadiusX(PassRefPtr<CSSPrimitiveValue> radiusX)116 void setRadiusX(PassRefPtr<CSSPrimitiveValue> radiusX) { m_radiusX = radiusX; } setRadiusY(PassRefPtr<CSSPrimitiveValue> radiusY)117 void setRadiusY(PassRefPtr<CSSPrimitiveValue> radiusY) { m_radiusY = radiusY; } 118 type()119 virtual Type type() const { return CSSBasicShapeInsetRectangleType; } 120 virtual String cssText() const; 121 virtual bool equals(const CSSBasicShape&) const; 122 123 virtual String serializeResolvingVariables(const HashMap<AtomicString, String>&) const; 124 virtual bool hasVariableReference() const; 125 126 private: CSSBasicShapeInsetRectangle()127 CSSBasicShapeInsetRectangle() { } 128 129 RefPtr<CSSPrimitiveValue> m_right; 130 RefPtr<CSSPrimitiveValue> m_top; 131 RefPtr<CSSPrimitiveValue> m_bottom; 132 RefPtr<CSSPrimitiveValue> m_left; 133 RefPtr<CSSPrimitiveValue> m_radiusX; 134 RefPtr<CSSPrimitiveValue> m_radiusY; 135 }; 136 137 class CSSBasicShapeCircle : public CSSBasicShape { 138 public: create()139 static PassRefPtr<CSSBasicShapeCircle> create() { return adoptRef(new CSSBasicShapeCircle); } 140 centerX()141 CSSPrimitiveValue* centerX() const { return m_centerX.get(); } centerY()142 CSSPrimitiveValue* centerY() const { return m_centerY.get(); } radius()143 CSSPrimitiveValue* radius() const { return m_radius.get(); } 144 setCenterX(PassRefPtr<CSSPrimitiveValue> centerX)145 void setCenterX(PassRefPtr<CSSPrimitiveValue> centerX) { m_centerX = centerX; } setCenterY(PassRefPtr<CSSPrimitiveValue> centerY)146 void setCenterY(PassRefPtr<CSSPrimitiveValue> centerY) { m_centerY = centerY; } setRadius(PassRefPtr<CSSPrimitiveValue> radius)147 void setRadius(PassRefPtr<CSSPrimitiveValue> radius) { m_radius = radius; } 148 type()149 virtual Type type() const { return CSSBasicShapeCircleType; } 150 virtual String cssText() const; 151 virtual bool equals(const CSSBasicShape&) const; 152 153 virtual String serializeResolvingVariables(const HashMap<AtomicString, String>&) const; 154 virtual bool hasVariableReference() const; 155 156 private: CSSBasicShapeCircle()157 CSSBasicShapeCircle() { } 158 159 RefPtr<CSSPrimitiveValue> m_centerY; 160 RefPtr<CSSPrimitiveValue> m_centerX; 161 RefPtr<CSSPrimitiveValue> m_radius; 162 }; 163 164 class CSSBasicShapeEllipse : public CSSBasicShape { 165 public: create()166 static PassRefPtr<CSSBasicShapeEllipse> create() { return adoptRef(new CSSBasicShapeEllipse); } 167 centerX()168 CSSPrimitiveValue* centerX() const { return m_centerX.get(); } centerY()169 CSSPrimitiveValue* centerY() const { return m_centerY.get(); } radiusX()170 CSSPrimitiveValue* radiusX() const { return m_radiusX.get(); } radiusY()171 CSSPrimitiveValue* radiusY() const { return m_radiusY.get(); } 172 setCenterX(PassRefPtr<CSSPrimitiveValue> centerX)173 void setCenterX(PassRefPtr<CSSPrimitiveValue> centerX) { m_centerX = centerX; } setCenterY(PassRefPtr<CSSPrimitiveValue> centerY)174 void setCenterY(PassRefPtr<CSSPrimitiveValue> centerY) { m_centerY = centerY; } setRadiusX(PassRefPtr<CSSPrimitiveValue> radiusX)175 void setRadiusX(PassRefPtr<CSSPrimitiveValue> radiusX) { m_radiusX = radiusX; } setRadiusY(PassRefPtr<CSSPrimitiveValue> radiusY)176 void setRadiusY(PassRefPtr<CSSPrimitiveValue> radiusY) { m_radiusY = radiusY; } 177 type()178 virtual Type type() const { return CSSBasicShapeEllipseType; } 179 virtual String cssText() const; 180 virtual bool equals(const CSSBasicShape&) const; 181 182 virtual String serializeResolvingVariables(const HashMap<AtomicString, String>&) const; 183 virtual bool hasVariableReference() const; 184 185 private: CSSBasicShapeEllipse()186 CSSBasicShapeEllipse() { } 187 188 RefPtr<CSSPrimitiveValue> m_centerX; 189 RefPtr<CSSPrimitiveValue> m_centerY; 190 RefPtr<CSSPrimitiveValue> m_radiusX; 191 RefPtr<CSSPrimitiveValue> m_radiusY; 192 }; 193 194 class CSSBasicShapePolygon : public CSSBasicShape { 195 public: create()196 static PassRefPtr<CSSBasicShapePolygon> create() { return adoptRef(new CSSBasicShapePolygon); } 197 appendPoint(PassRefPtr<CSSPrimitiveValue> x,PassRefPtr<CSSPrimitiveValue> y)198 void appendPoint(PassRefPtr<CSSPrimitiveValue> x, PassRefPtr<CSSPrimitiveValue> y) 199 { 200 m_values.append(x); 201 m_values.append(y); 202 } 203 getXAt(unsigned i)204 PassRefPtr<CSSPrimitiveValue> getXAt(unsigned i) const { return m_values.at(i * 2); } getYAt(unsigned i)205 PassRefPtr<CSSPrimitiveValue> getYAt(unsigned i) const { return m_values.at(i * 2 + 1); } values()206 const Vector<RefPtr<CSSPrimitiveValue> >& values() const { return m_values; } 207 setWindRule(WindRule w)208 void setWindRule(WindRule w) { m_windRule = w; } windRule()209 WindRule windRule() const { return m_windRule; } 210 type()211 virtual Type type() const { return CSSBasicShapePolygonType; } 212 virtual String cssText() const; 213 virtual bool equals(const CSSBasicShape&) const; 214 virtual String serializeResolvingVariables(const HashMap<AtomicString, String>&) const; 215 virtual bool hasVariableReference() const; 216 217 private: CSSBasicShapePolygon()218 CSSBasicShapePolygon() 219 : m_windRule(RULE_NONZERO) 220 { 221 } 222 223 Vector<RefPtr<CSSPrimitiveValue> > m_values; 224 WindRule m_windRule; 225 }; 226 227 } // namespace WebCore 228 229 #endif // CSSBasicShapes_h 230