| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 G* * Redistributions in binary form must reproduce the above | 10 G* * Redistributions in binary form must reproduce the above |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 virtual bool isAnimating() const = 0; | 55 virtual bool isAnimating() const = 0; |
| 56 | 56 |
| 57 virtual SVGPropertyBase* createAnimatedValue() = 0; | 57 virtual SVGPropertyBase* createAnimatedValue() = 0; |
| 58 virtual void setAnimatedValue(SVGPropertyBase*) = 0; | 58 virtual void setAnimatedValue(SVGPropertyBase*) = 0; |
| 59 virtual void animationEnded(); | 59 virtual void animationEnded(); |
| 60 | 60 |
| 61 virtual SVGParsingError setBaseValueAsString(const String&) = 0; | 61 virtual SVGParsingError setBaseValueAsString(const String&) = 0; |
| 62 virtual bool needsSynchronizeAttribute() = 0; | 62 virtual bool needsSynchronizeAttribute() = 0; |
| 63 virtual void synchronizeAttribute(); | 63 virtual void synchronizeAttribute(); |
| 64 | 64 |
| 65 AnimatedPropertyType type() const { return m_type; } | 65 AnimatedPropertyType type() const { |
| 66 return static_cast<AnimatedPropertyType>(m_type); |
| 67 } |
| 66 | 68 |
| 67 SVGElement* contextElement() const { return m_contextElement; } | 69 SVGElement* contextElement() const { return m_contextElement; } |
| 68 | 70 |
| 69 const QualifiedName& attributeName() const { return m_attributeName; } | 71 const QualifiedName& attributeName() const { return m_attributeName; } |
| 70 | 72 |
| 73 CSSPropertyID cssPropertyId() const { |
| 74 return static_cast<CSSPropertyID>(m_cssPropertyId); |
| 75 } |
| 76 |
| 77 bool hasPresentationAttributeMapping() const { |
| 78 return cssPropertyId() != CSSPropertyInvalid; |
| 79 } |
| 80 |
| 71 bool isReadOnly() const { return m_isReadOnly; } | 81 bool isReadOnly() const { return m_isReadOnly; } |
| 72 | 82 |
| 73 void setReadOnly() { m_isReadOnly = true; } | 83 void setReadOnly() { m_isReadOnly = true; } |
| 74 | 84 |
| 75 bool isSpecified() const; | 85 bool isSpecified() const; |
| 76 | 86 |
| 77 DEFINE_INLINE_VIRTUAL_TRACE() {} | 87 DEFINE_INLINE_VIRTUAL_TRACE() {} |
| 78 | 88 |
| 79 protected: | 89 protected: |
| 80 SVGAnimatedPropertyBase(AnimatedPropertyType, | 90 SVGAnimatedPropertyBase(AnimatedPropertyType, |
| 81 SVGElement*, | 91 SVGElement*, |
| 82 const QualifiedName& attributeName); | 92 const QualifiedName& attributeName, |
| 93 CSSPropertyID = CSSPropertyInvalid); |
| 83 | 94 |
| 84 private: | 95 private: |
| 85 const AnimatedPropertyType m_type; | 96 static_assert(NumberOfAnimatedPropertyTypes <= (1u << 5), |
| 86 bool m_isReadOnly; | 97 "enough bits for AnimatedPropertyType (m_type)"); |
| 98 static constexpr int kCssPropertyBits = 9; |
| 99 static_assert((1u << kCssPropertyBits) - 1 >= lastCSSProperty, |
| 100 "enough bits for CSS property ids"); |
| 101 |
| 102 const unsigned m_type : 5; |
| 103 const unsigned m_cssPropertyId : kCssPropertyBits; |
| 104 unsigned m_isReadOnly : 1; |
| 87 | 105 |
| 88 // This raw pointer is safe since the SVG element is guaranteed to be kept | 106 // This raw pointer is safe since the SVG element is guaranteed to be kept |
| 89 // alive by a V8 wrapper. | 107 // alive by a V8 wrapper. |
| 90 // See http://crbug.com/528275 for the detail. | 108 // See http://crbug.com/528275 for the detail. |
| 91 UntracedMember<SVGElement> m_contextElement; | 109 UntracedMember<SVGElement> m_contextElement; |
| 92 | 110 |
| 93 const QualifiedName& m_attributeName; | 111 const QualifiedName& m_attributeName; |
| 94 }; | 112 }; |
| 95 | 113 |
| 96 template <typename Property> | 114 template <typename Property> |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 151 |
| 134 DEFINE_INLINE_VIRTUAL_TRACE() { | 152 DEFINE_INLINE_VIRTUAL_TRACE() { |
| 135 visitor->trace(m_baseValue); | 153 visitor->trace(m_baseValue); |
| 136 visitor->trace(m_currentValue); | 154 visitor->trace(m_currentValue); |
| 137 SVGAnimatedPropertyBase::trace(visitor); | 155 SVGAnimatedPropertyBase::trace(visitor); |
| 138 } | 156 } |
| 139 | 157 |
| 140 protected: | 158 protected: |
| 141 SVGAnimatedPropertyCommon(SVGElement* contextElement, | 159 SVGAnimatedPropertyCommon(SVGElement* contextElement, |
| 142 const QualifiedName& attributeName, | 160 const QualifiedName& attributeName, |
| 143 Property* initialValue) | 161 Property* initialValue, |
| 162 CSSPropertyID cssPropertyId = CSSPropertyInvalid) |
| 144 : SVGAnimatedPropertyBase(Property::classType(), | 163 : SVGAnimatedPropertyBase(Property::classType(), |
| 145 contextElement, | 164 contextElement, |
| 146 attributeName), | 165 attributeName, |
| 166 cssPropertyId), |
| 147 m_baseValue(initialValue) {} | 167 m_baseValue(initialValue) {} |
| 148 | 168 |
| 149 private: | 169 private: |
| 150 Member<Property> m_baseValue; | 170 Member<Property> m_baseValue; |
| 151 Member<Property> m_currentValue; | 171 Member<Property> m_currentValue; |
| 152 }; | 172 }; |
| 153 | 173 |
| 154 // Implementation of SVGAnimatedProperty which uses primitive types. | 174 // Implementation of SVGAnimatedProperty which uses primitive types. |
| 155 // This is for classes which return primitive type for its "animVal". | 175 // This is for classes which return primitive type for its "animVal". |
| 156 // Examples are SVGAnimatedBoolean, SVGAnimatedNumber, etc. | 176 // Examples are SVGAnimatedBoolean, SVGAnimatedNumber, etc. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 213 } |
| 194 | 214 |
| 195 PrimitiveType animVal() { | 215 PrimitiveType animVal() { |
| 196 this->contextElement()->ensureAttributeAnimValUpdated(); | 216 this->contextElement()->ensureAttributeAnimValUpdated(); |
| 197 return this->currentValue()->value(); | 217 return this->currentValue()->value(); |
| 198 } | 218 } |
| 199 | 219 |
| 200 protected: | 220 protected: |
| 201 SVGAnimatedProperty(SVGElement* contextElement, | 221 SVGAnimatedProperty(SVGElement* contextElement, |
| 202 const QualifiedName& attributeName, | 222 const QualifiedName& attributeName, |
| 203 Property* initialValue) | 223 Property* initialValue, |
| 224 CSSPropertyID cssPropertyId = CSSPropertyInvalid) |
| 204 : SVGAnimatedPropertyCommon<Property>(contextElement, | 225 : SVGAnimatedPropertyCommon<Property>(contextElement, |
| 205 attributeName, | 226 attributeName, |
| 206 initialValue), | 227 initialValue, |
| 228 cssPropertyId), |
| 207 m_baseValueUpdated(false) {} | 229 m_baseValueUpdated(false) {} |
| 208 | 230 |
| 209 bool m_baseValueUpdated; | 231 bool m_baseValueUpdated; |
| 210 }; | 232 }; |
| 211 | 233 |
| 212 // Implementation of SVGAnimatedProperty which uses tear-off value types. | 234 // Implementation of SVGAnimatedProperty which uses tear-off value types. |
| 213 // These classes has "void" for its PrimitiveType. | 235 // These classes has "void" for its PrimitiveType. |
| 214 // This is for classes which return special type for its "animVal". | 236 // This is for classes which return special type for its "animVal". |
| 215 // Examples are SVGAnimatedLength, SVGAnimatedRect, SVGAnimated*List, etc. | 237 // Examples are SVGAnimatedLength, SVGAnimatedRect, SVGAnimated*List, etc. |
| 216 template <typename Property, typename TearOffType> | 238 template <typename Property, typename TearOffType> |
| 217 class SVGAnimatedProperty<Property, TearOffType, void> | 239 class SVGAnimatedProperty<Property, TearOffType, void> |
| 218 : public SVGAnimatedPropertyCommon<Property> { | 240 : public SVGAnimatedPropertyCommon<Property> { |
| 219 public: | 241 public: |
| 220 static SVGAnimatedProperty<Property>* create( | 242 static SVGAnimatedProperty<Property>* create( |
| 221 SVGElement* contextElement, | 243 SVGElement* contextElement, |
| 222 const QualifiedName& attributeName, | 244 const QualifiedName& attributeName, |
| 223 Property* initialValue) { | 245 Property* initialValue, |
| 246 CSSPropertyID cssPropertyId = CSSPropertyInvalid) { |
| 224 return new SVGAnimatedProperty<Property>(contextElement, attributeName, | 247 return new SVGAnimatedProperty<Property>(contextElement, attributeName, |
| 225 initialValue); | 248 initialValue, cssPropertyId); |
| 226 } | 249 } |
| 227 | 250 |
| 228 void setAnimatedValue(SVGPropertyBase* value) override { | 251 void setAnimatedValue(SVGPropertyBase* value) override { |
| 229 SVGAnimatedPropertyCommon<Property>::setAnimatedValue(value); | 252 SVGAnimatedPropertyCommon<Property>::setAnimatedValue(value); |
| 230 updateAnimValTearOffIfNeeded(); | 253 updateAnimValTearOffIfNeeded(); |
| 231 } | 254 } |
| 232 | 255 |
| 233 void animationEnded() override { | 256 void animationEnded() override { |
| 234 SVGAnimatedPropertyCommon<Property>::animationEnded(); | 257 SVGAnimatedPropertyCommon<Property>::animationEnded(); |
| 235 updateAnimValTearOffIfNeeded(); | 258 updateAnimValTearOffIfNeeded(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 292 |
| 270 DEFINE_INLINE_VIRTUAL_TRACE() { | 293 DEFINE_INLINE_VIRTUAL_TRACE() { |
| 271 visitor->trace(m_baseValTearOff); | 294 visitor->trace(m_baseValTearOff); |
| 272 visitor->trace(m_animValTearOff); | 295 visitor->trace(m_animValTearOff); |
| 273 SVGAnimatedPropertyCommon<Property>::trace(visitor); | 296 SVGAnimatedPropertyCommon<Property>::trace(visitor); |
| 274 } | 297 } |
| 275 | 298 |
| 276 protected: | 299 protected: |
| 277 SVGAnimatedProperty(SVGElement* contextElement, | 300 SVGAnimatedProperty(SVGElement* contextElement, |
| 278 const QualifiedName& attributeName, | 301 const QualifiedName& attributeName, |
| 279 Property* initialValue) | 302 Property* initialValue, |
| 303 CSSPropertyID cssPropertyId = CSSPropertyInvalid) |
| 280 : SVGAnimatedPropertyCommon<Property>(contextElement, | 304 : SVGAnimatedPropertyCommon<Property>(contextElement, |
| 281 attributeName, | 305 attributeName, |
| 282 initialValue) {} | 306 initialValue, |
| 307 cssPropertyId) {} |
| 283 | 308 |
| 284 private: | 309 private: |
| 285 void updateAnimValTearOffIfNeeded() { | 310 void updateAnimValTearOffIfNeeded() { |
| 286 if (m_animValTearOff) | 311 if (m_animValTearOff) |
| 287 m_animValTearOff->setTarget(this->currentValue()); | 312 m_animValTearOff->setTarget(this->currentValue()); |
| 288 } | 313 } |
| 289 | 314 |
| 290 // When still (not animated): | 315 // When still (not animated): |
| 291 // Both m_animValTearOff and m_baseValTearOff target m_baseValue. | 316 // Both m_animValTearOff and m_baseValTearOff target m_baseValue. |
| 292 // When animated: | 317 // When animated: |
| 293 // m_animValTearOff targets m_currentValue. | 318 // m_animValTearOff targets m_currentValue. |
| 294 // m_baseValTearOff targets m_baseValue. | 319 // m_baseValTearOff targets m_baseValue. |
| 295 Member<TearOffType> m_baseValTearOff; | 320 Member<TearOffType> m_baseValTearOff; |
| 296 Member<TearOffType> m_animValTearOff; | 321 Member<TearOffType> m_animValTearOff; |
| 297 }; | 322 }; |
| 298 | 323 |
| 299 // Implementation of SVGAnimatedProperty which doesn't use tear-off value types. | 324 // Implementation of SVGAnimatedProperty which doesn't use tear-off value types. |
| 300 // This class has "void" for its TearOffType. | 325 // This class has "void" for its TearOffType. |
| 301 // Currently only used for SVGAnimatedPath. | 326 // Currently only used for SVGAnimatedPath. |
| 302 template <typename Property> | 327 template <typename Property> |
| 303 class SVGAnimatedProperty<Property, void, void> | 328 class SVGAnimatedProperty<Property, void, void> |
| 304 : public SVGAnimatedPropertyCommon<Property> { | 329 : public SVGAnimatedPropertyCommon<Property> { |
| 305 public: | 330 public: |
| 306 static SVGAnimatedProperty<Property>* create( | 331 static SVGAnimatedProperty<Property>* create( |
| 307 SVGElement* contextElement, | 332 SVGElement* contextElement, |
| 308 const QualifiedName& attributeName, | 333 const QualifiedName& attributeName, |
| 309 Property* initialValue) { | 334 Property* initialValue, |
| 335 CSSPropertyID cssPropertyId = CSSPropertyInvalid) { |
| 310 return new SVGAnimatedProperty<Property>(contextElement, attributeName, | 336 return new SVGAnimatedProperty<Property>(contextElement, attributeName, |
| 311 initialValue); | 337 initialValue, cssPropertyId); |
| 312 } | 338 } |
| 313 | 339 |
| 314 bool needsSynchronizeAttribute() override { | 340 bool needsSynchronizeAttribute() override { |
| 315 // DOM attribute synchronization is only needed if the property is being | 341 // DOM attribute synchronization is only needed if the property is being |
| 316 // animated. | 342 // animated. |
| 317 return this->isAnimating(); | 343 return this->isAnimating(); |
| 318 } | 344 } |
| 319 | 345 |
| 320 protected: | 346 protected: |
| 321 SVGAnimatedProperty(SVGElement* contextElement, | 347 SVGAnimatedProperty(SVGElement* contextElement, |
| 322 const QualifiedName& attributeName, | 348 const QualifiedName& attributeName, |
| 323 Property* initialValue) | 349 Property* initialValue, |
| 350 CSSPropertyID cssPropertyId = CSSPropertyInvalid) |
| 324 : SVGAnimatedPropertyCommon<Property>(contextElement, | 351 : SVGAnimatedPropertyCommon<Property>(contextElement, |
| 325 attributeName, | 352 attributeName, |
| 326 initialValue) {} | 353 initialValue, |
| 354 cssPropertyId) {} |
| 327 }; | 355 }; |
| 328 | 356 |
| 329 } // namespace blink | 357 } // namespace blink |
| 330 | 358 |
| 331 #endif // SVGAnimatedProperty_h | 359 #endif // SVGAnimatedProperty_h |
| OLD | NEW |