1 /* 2 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20 #ifndef SVGAnimatedType_h 21 #define SVGAnimatedType_h 22 23 #include "core/svg/SVGAngle.h" 24 #include "core/svg/SVGColor.h" 25 #include "core/svg/SVGLength.h" 26 #include "core/svg/SVGLengthList.h" 27 #include "core/svg/SVGNumberList.h" 28 #include "core/svg/SVGPointList.h" 29 #include "core/svg/SVGPreserveAspectRatio.h" 30 #include "core/svg/SVGRect.h" 31 #include "core/svg/SVGTransformList.h" 32 #include "core/svg/properties/SVGPropertyInfo.h" 33 34 namespace WebCore { 35 36 class SVGPathByteStream; 37 38 class SVGAnimatedType { 39 WTF_MAKE_FAST_ALLOCATED; 40 public: 41 virtual ~SVGAnimatedType(); 42 43 static PassOwnPtr<SVGAnimatedType> createAngleAndEnumeration(std::pair<SVGAngle, unsigned>*); 44 static PassOwnPtr<SVGAnimatedType> createBoolean(bool*); 45 static PassOwnPtr<SVGAnimatedType> createColor(Color*); 46 static PassOwnPtr<SVGAnimatedType> createEnumeration(unsigned*); 47 static PassOwnPtr<SVGAnimatedType> createInteger(int*); 48 static PassOwnPtr<SVGAnimatedType> createIntegerOptionalInteger(std::pair<int, int>*); 49 static PassOwnPtr<SVGAnimatedType> createLength(SVGLength*); 50 static PassOwnPtr<SVGAnimatedType> createLengthList(SVGLengthList*); 51 static PassOwnPtr<SVGAnimatedType> createNumber(float*); 52 static PassOwnPtr<SVGAnimatedType> createNumberList(SVGNumberList*); 53 static PassOwnPtr<SVGAnimatedType> createNumberOptionalNumber(std::pair<float, float>*); 54 static PassOwnPtr<SVGAnimatedType> createPath(PassOwnPtr<SVGPathByteStream>); 55 static PassOwnPtr<SVGAnimatedType> createPointList(SVGPointList*); 56 static PassOwnPtr<SVGAnimatedType> createPreserveAspectRatio(SVGPreserveAspectRatio*); 57 static PassOwnPtr<SVGAnimatedType> createRect(SVGRect*); 58 static PassOwnPtr<SVGAnimatedType> createString(String*); 59 static PassOwnPtr<SVGAnimatedType> createTransformList(SVGTransformList*); 60 static bool supportsAnimVal(AnimatedPropertyType); 61 62 AnimatedPropertyType type() const { return m_type; } 63 64 // Non-mutable accessors. 65 const std::pair<SVGAngle, unsigned>& angleAndEnumeration() const 66 { 67 ASSERT(m_type == AnimatedAngle); 68 return *m_data.angleAndEnumeration; 69 } 70 71 const bool& boolean() const 72 { 73 ASSERT(m_type == AnimatedBoolean); 74 return *m_data.boolean; 75 } 76 77 const Color& color() const 78 { 79 ASSERT(m_type == AnimatedColor); 80 return *m_data.color; 81 } 82 83 const unsigned& enumeration() const 84 { 85 ASSERT(m_type == AnimatedEnumeration); 86 return *m_data.enumeration; 87 } 88 89 const int& integer() const 90 { 91 ASSERT(m_type == AnimatedInteger); 92 return *m_data.integer; 93 } 94 95 const pair<int, int>& integerOptionalInteger() const 96 { 97 ASSERT(m_type == AnimatedIntegerOptionalInteger); 98 return *m_data.integerOptionalInteger; 99 } 100 101 const SVGLength& length() const 102 { 103 ASSERT(m_type == AnimatedLength); 104 return *m_data.length; 105 } 106 107 const SVGLengthList& lengthList() const 108 { 109 ASSERT(m_type == AnimatedLengthList); 110 return *m_data.lengthList; 111 } 112 113 const float& number() const 114 { 115 ASSERT(m_type == AnimatedNumber); 116 return *m_data.number; 117 } 118 119 const SVGNumberList& numberList() const 120 { 121 ASSERT(m_type == AnimatedNumberList); 122 return *m_data.numberList; 123 } 124 125 const pair<float, float>& numberOptionalNumber() const 126 { 127 ASSERT(m_type == AnimatedNumberOptionalNumber); 128 return *m_data.numberOptionalNumber; 129 } 130 131 const SVGPathByteStream* path() const 132 { 133 ASSERT(m_type == AnimatedPath); 134 return m_data.path; 135 } 136 137 const SVGPointList& pointList() const 138 { 139 ASSERT(m_type == AnimatedPoints); 140 return *m_data.pointList; 141 } 142 143 const SVGPreserveAspectRatio& preserveAspectRatio() const 144 { 145 ASSERT(m_type == AnimatedPreserveAspectRatio); 146 return *m_data.preserveAspectRatio; 147 } 148 149 const SVGRect& rect() const 150 { 151 ASSERT(m_type == AnimatedRect); 152 return *m_data.rect; 153 } 154 155 const String& string() const 156 { 157 ASSERT(m_type == AnimatedString); 158 return *m_data.string; 159 } 160 161 const SVGTransformList& transformList() const 162 { 163 ASSERT(m_type == AnimatedTransformList); 164 return *m_data.transformList; 165 } 166 167 // Mutable accessors. 168 std::pair<SVGAngle, unsigned>& angleAndEnumeration() 169 { 170 ASSERT(m_type == AnimatedAngle); 171 return *m_data.angleAndEnumeration; 172 } 173 174 bool& boolean() 175 { 176 ASSERT(m_type == AnimatedBoolean); 177 return *m_data.boolean; 178 } 179 180 Color& color() 181 { 182 ASSERT(m_type == AnimatedColor); 183 return *m_data.color; 184 } 185 186 unsigned& enumeration() 187 { 188 ASSERT(m_type == AnimatedEnumeration); 189 return *m_data.enumeration; 190 } 191 192 int& integer() 193 { 194 ASSERT(m_type == AnimatedInteger); 195 return *m_data.integer; 196 } 197 198 pair<int, int>& integerOptionalInteger() 199 { 200 ASSERT(m_type == AnimatedIntegerOptionalInteger); 201 return *m_data.integerOptionalInteger; 202 } 203 204 SVGLength& length() 205 { 206 ASSERT(m_type == AnimatedLength); 207 return *m_data.length; 208 } 209 210 SVGLengthList& lengthList() 211 { 212 ASSERT(m_type == AnimatedLengthList); 213 return *m_data.lengthList; 214 } 215 216 float& number() 217 { 218 ASSERT(m_type == AnimatedNumber); 219 return *m_data.number; 220 } 221 222 SVGNumberList& numberList() 223 { 224 ASSERT(m_type == AnimatedNumberList); 225 return *m_data.numberList; 226 } 227 228 pair<float, float>& numberOptionalNumber() 229 { 230 ASSERT(m_type == AnimatedNumberOptionalNumber); 231 return *m_data.numberOptionalNumber; 232 } 233 234 SVGPathByteStream* path() 235 { 236 ASSERT(m_type == AnimatedPath); 237 return m_data.path; 238 } 239 240 SVGPointList& pointList() 241 { 242 ASSERT(m_type == AnimatedPoints); 243 return *m_data.pointList; 244 } 245 246 SVGPreserveAspectRatio& preserveAspectRatio() 247 { 248 ASSERT(m_type == AnimatedPreserveAspectRatio); 249 return *m_data.preserveAspectRatio; 250 } 251 252 SVGRect& rect() 253 { 254 ASSERT(m_type == AnimatedRect); 255 return *m_data.rect; 256 } 257 258 String& string() 259 { 260 ASSERT(m_type == AnimatedString); 261 return *m_data.string; 262 } 263 264 SVGTransformList& transformList() 265 { 266 ASSERT(m_type == AnimatedTransformList); 267 return *m_data.transformList; 268 } 269 270 String valueAsString(); 271 bool setValueAsString(const QualifiedName&, const String&); 272 273 private: 274 SVGAnimatedType(AnimatedPropertyType); 275 276 AnimatedPropertyType m_type; 277 278 union DataUnion { 279 DataUnion() 280 : length(0) 281 { 282 } 283 284 std::pair<SVGAngle, unsigned>* angleAndEnumeration; 285 bool* boolean; 286 Color* color; 287 unsigned* enumeration; 288 int* integer; 289 std::pair<int, int>* integerOptionalInteger; 290 SVGLength* length; 291 SVGLengthList* lengthList; 292 float* number; 293 SVGNumberList* numberList; 294 std::pair<float, float>* numberOptionalNumber; 295 SVGPathByteStream* path; 296 SVGPreserveAspectRatio* preserveAspectRatio; 297 SVGPointList* pointList; 298 SVGRect* rect; 299 String* string; 300 SVGTransformList* transformList; 301 } m_data; 302 }; 303 304 } // namespace WebCore 305 306 #endif // SVGAnimatedType_h 307