| 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 27 matching lines...) Expand all Loading... |
| 38 #include "core/svg/properties/SVGPropertyTearOff.h" | 38 #include "core/svg/properties/SVGPropertyTearOff.h" |
| 39 #include "platform/heap/Handle.h" | 39 #include "platform/heap/Handle.h" |
| 40 #include "wtf/Noncopyable.h" | 40 #include "wtf/Noncopyable.h" |
| 41 #include "wtf/PassRefPtr.h" | 41 #include "wtf/PassRefPtr.h" |
| 42 #include "wtf/RefCounted.h" | 42 #include "wtf/RefCounted.h" |
| 43 | 43 |
| 44 namespace blink { | 44 namespace blink { |
| 45 | 45 |
| 46 class SVGElement; | 46 class SVGElement; |
| 47 | 47 |
| 48 class SVGAnimatedPropertyBase : public RefCountedWillBeGarbageCollectedFinalized
<SVGAnimatedPropertyBase> { | 48 class SVGAnimatedPropertyBase : public GarbageCollectedFinalized<SVGAnimatedProp
ertyBase> { |
| 49 WTF_MAKE_NONCOPYABLE(SVGAnimatedPropertyBase); | 49 WTF_MAKE_NONCOPYABLE(SVGAnimatedPropertyBase); |
| 50 public: | 50 public: |
| 51 virtual ~SVGAnimatedPropertyBase(); | 51 virtual ~SVGAnimatedPropertyBase(); |
| 52 | 52 |
| 53 virtual SVGPropertyBase* currentValueBase() = 0; | 53 virtual SVGPropertyBase* currentValueBase() = 0; |
| 54 virtual const SVGPropertyBase& baseValueBase() const = 0; | 54 virtual const SVGPropertyBase& baseValueBase() const = 0; |
| 55 virtual bool isAnimating() const = 0; | 55 virtual bool isAnimating() const = 0; |
| 56 | 56 |
| 57 virtual PassRefPtrWillBeRawPtr<SVGPropertyBase> createAnimatedValue() = 0; | 57 virtual RawPtr<SVGPropertyBase> createAnimatedValue() = 0; |
| 58 virtual void setAnimatedValue(PassRefPtrWillBeRawPtr<SVGPropertyBase>) = 0; | 58 virtual void setAnimatedValue(RawPtr<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 | 65 AnimatedPropertyType type() const |
| 66 { | 66 { |
| 67 return m_type; | 67 return m_type; |
| 68 } | 68 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 96 protected: | 96 protected: |
| 97 SVGAnimatedPropertyBase(AnimatedPropertyType, SVGElement*, const QualifiedNa
me& attributeName); | 97 SVGAnimatedPropertyBase(AnimatedPropertyType, SVGElement*, const QualifiedNa
me& attributeName); |
| 98 | 98 |
| 99 private: | 99 private: |
| 100 const AnimatedPropertyType m_type; | 100 const AnimatedPropertyType m_type; |
| 101 bool m_isReadOnly; | 101 bool m_isReadOnly; |
| 102 | 102 |
| 103 // This raw pointer is safe since the SVG element is guaranteed to be kept | 103 // This raw pointer is safe since the SVG element is guaranteed to be kept |
| 104 // alive by a V8 wrapper. | 104 // alive by a V8 wrapper. |
| 105 // See http://crbug.com/528275 for the detail. | 105 // See http://crbug.com/528275 for the detail. |
| 106 RawPtrWillBeUntracedMember<SVGElement> m_contextElement; | 106 UntracedMember<SVGElement> m_contextElement; |
| 107 | 107 |
| 108 const QualifiedName& m_attributeName; | 108 const QualifiedName& m_attributeName; |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 template <typename Property> | 111 template <typename Property> |
| 112 class SVGAnimatedPropertyCommon : public SVGAnimatedPropertyBase { | 112 class SVGAnimatedPropertyCommon : public SVGAnimatedPropertyBase { |
| 113 public: | 113 public: |
| 114 Property* baseValue() | 114 Property* baseValue() |
| 115 { | 115 { |
| 116 return m_baseValue.get(); | 116 return m_baseValue.get(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 139 bool isAnimating() const override | 139 bool isAnimating() const override |
| 140 { | 140 { |
| 141 return m_currentValue; | 141 return m_currentValue; |
| 142 } | 142 } |
| 143 | 143 |
| 144 SVGParsingError setBaseValueAsString(const String& value) override | 144 SVGParsingError setBaseValueAsString(const String& value) override |
| 145 { | 145 { |
| 146 return m_baseValue->setValueAsString(value); | 146 return m_baseValue->setValueAsString(value); |
| 147 } | 147 } |
| 148 | 148 |
| 149 PassRefPtrWillBeRawPtr<SVGPropertyBase> createAnimatedValue() override | 149 RawPtr<SVGPropertyBase> createAnimatedValue() override |
| 150 { | 150 { |
| 151 return m_baseValue->clone(); | 151 return m_baseValue->clone(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void setAnimatedValue(PassRefPtrWillBeRawPtr<SVGPropertyBase> passValue) ove
rride | 154 void setAnimatedValue(RawPtr<SVGPropertyBase> passValue) override |
| 155 { | 155 { |
| 156 RefPtrWillBeRawPtr<SVGPropertyBase> value = passValue; | 156 RawPtr<SVGPropertyBase> value = passValue; |
| 157 ASSERT(value->type() == Property::classType()); | 157 ASSERT(value->type() == Property::classType()); |
| 158 m_currentValue = static_pointer_cast<Property>(value.release()); | 158 m_currentValue = static_pointer_cast<Property>(value.release()); |
| 159 } | 159 } |
| 160 | 160 |
| 161 void animationEnded() override | 161 void animationEnded() override |
| 162 { | 162 { |
| 163 m_currentValue.clear(); | 163 m_currentValue.clear(); |
| 164 | 164 |
| 165 SVGAnimatedPropertyBase::animationEnded(); | 165 SVGAnimatedPropertyBase::animationEnded(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 DEFINE_INLINE_VIRTUAL_TRACE() | 168 DEFINE_INLINE_VIRTUAL_TRACE() |
| 169 { | 169 { |
| 170 visitor->trace(m_baseValue); | 170 visitor->trace(m_baseValue); |
| 171 visitor->trace(m_currentValue); | 171 visitor->trace(m_currentValue); |
| 172 SVGAnimatedPropertyBase::trace(visitor); | 172 SVGAnimatedPropertyBase::trace(visitor); |
| 173 } | 173 } |
| 174 | 174 |
| 175 protected: | 175 protected: |
| 176 SVGAnimatedPropertyCommon(SVGElement* contextElement, const QualifiedName& a
ttributeName, PassRefPtrWillBeRawPtr<Property> initialValue) | 176 SVGAnimatedPropertyCommon(SVGElement* contextElement, const QualifiedName& a
ttributeName, RawPtr<Property> initialValue) |
| 177 : SVGAnimatedPropertyBase(Property::classType(), contextElement, attribu
teName) | 177 : SVGAnimatedPropertyBase(Property::classType(), contextElement, attribu
teName) |
| 178 , m_baseValue(initialValue) | 178 , m_baseValue(initialValue) |
| 179 { | 179 { |
| 180 } | 180 } |
| 181 | 181 |
| 182 private: | 182 private: |
| 183 RefPtrWillBeMember<Property> m_baseValue; | 183 Member<Property> m_baseValue; |
| 184 RefPtrWillBeMember<Property> m_currentValue; | 184 Member<Property> m_currentValue; |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 // Implementation of SVGAnimatedProperty which uses primitive types. | 187 // Implementation of SVGAnimatedProperty which uses primitive types. |
| 188 // This is for classes which return primitive type for its "animVal". | 188 // This is for classes which return primitive type for its "animVal". |
| 189 // Examples are SVGAnimatedBoolean, SVGAnimatedNumber, etc. | 189 // Examples are SVGAnimatedBoolean, SVGAnimatedNumber, etc. |
| 190 template <typename Property, typename TearOffType = typename Property::TearOffTy
pe, typename PrimitiveType = typename Property::PrimitiveType> | 190 template <typename Property, typename TearOffType = typename Property::TearOffTy
pe, typename PrimitiveType = typename Property::PrimitiveType> |
| 191 class SVGAnimatedProperty : public SVGAnimatedPropertyCommon<Property> { | 191 class SVGAnimatedProperty : public SVGAnimatedPropertyCommon<Property> { |
| 192 public: | 192 public: |
| 193 bool needsSynchronizeAttribute() override | 193 bool needsSynchronizeAttribute() override |
| 194 { | 194 { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 this->contextElement()->svgAttributeBaseValChanged(this->attributeName()
); | 227 this->contextElement()->svgAttributeBaseValChanged(this->attributeName()
); |
| 228 } | 228 } |
| 229 | 229 |
| 230 PrimitiveType animVal() | 230 PrimitiveType animVal() |
| 231 { | 231 { |
| 232 this->contextElement()->ensureAttributeAnimValUpdated(); | 232 this->contextElement()->ensureAttributeAnimValUpdated(); |
| 233 return this->currentValue()->value(); | 233 return this->currentValue()->value(); |
| 234 } | 234 } |
| 235 | 235 |
| 236 protected: | 236 protected: |
| 237 SVGAnimatedProperty(SVGElement* contextElement, const QualifiedName& attribu
teName, PassRefPtrWillBeRawPtr<Property> initialValue) | 237 SVGAnimatedProperty(SVGElement* contextElement, const QualifiedName& attribu
teName, RawPtr<Property> initialValue) |
| 238 : SVGAnimatedPropertyCommon<Property>(contextElement, attributeName, ini
tialValue) | 238 : SVGAnimatedPropertyCommon<Property>(contextElement, attributeName, ini
tialValue) |
| 239 , m_baseValueUpdated(false) | 239 , m_baseValueUpdated(false) |
| 240 { | 240 { |
| 241 } | 241 } |
| 242 | 242 |
| 243 bool m_baseValueUpdated; | 243 bool m_baseValueUpdated; |
| 244 }; | 244 }; |
| 245 | 245 |
| 246 // Implementation of SVGAnimatedProperty which uses tear-off value types. | 246 // Implementation of SVGAnimatedProperty which uses tear-off value types. |
| 247 // These classes has "void" for its PrimitiveType. | 247 // These classes has "void" for its PrimitiveType. |
| 248 // This is for classes which return special type for its "animVal". | 248 // This is for classes which return special type for its "animVal". |
| 249 // Examples are SVGAnimatedLength, SVGAnimatedRect, SVGAnimated*List, etc. | 249 // Examples are SVGAnimatedLength, SVGAnimatedRect, SVGAnimated*List, etc. |
| 250 template <typename Property, typename TearOffType> | 250 template <typename Property, typename TearOffType> |
| 251 class SVGAnimatedProperty<Property, TearOffType, void> : public SVGAnimatedPrope
rtyCommon<Property> { | 251 class SVGAnimatedProperty<Property, TearOffType, void> : public SVGAnimatedPrope
rtyCommon<Property> { |
| 252 public: | 252 public: |
| 253 static PassRefPtrWillBeRawPtr<SVGAnimatedProperty<Property>> create(SVGEleme
nt* contextElement, const QualifiedName& attributeName, PassRefPtrWillBeRawPtr<P
roperty> initialValue) | 253 static RawPtr<SVGAnimatedProperty<Property>> create(SVGElement* contextEleme
nt, const QualifiedName& attributeName, RawPtr<Property> initialValue) |
| 254 { | 254 { |
| 255 return adoptRefWillBeNoop(new SVGAnimatedProperty<Property>(contextEleme
nt, attributeName, initialValue)); | 255 return new SVGAnimatedProperty<Property>(contextElement, attributeName,
initialValue); |
| 256 } | 256 } |
| 257 | 257 |
| 258 void setAnimatedValue(PassRefPtrWillBeRawPtr<SVGPropertyBase> value) overrid
e | 258 void setAnimatedValue(RawPtr<SVGPropertyBase> value) override |
| 259 { | 259 { |
| 260 SVGAnimatedPropertyCommon<Property>::setAnimatedValue(value); | 260 SVGAnimatedPropertyCommon<Property>::setAnimatedValue(value); |
| 261 updateAnimValTearOffIfNeeded(); | 261 updateAnimValTearOffIfNeeded(); |
| 262 } | 262 } |
| 263 | 263 |
| 264 void animationEnded() override | 264 void animationEnded() override |
| 265 { | 265 { |
| 266 SVGAnimatedPropertyCommon<Property>::animationEnded(); | 266 SVGAnimatedPropertyCommon<Property>::animationEnded(); |
| 267 updateAnimValTearOffIfNeeded(); | 267 updateAnimValTearOffIfNeeded(); |
| 268 } | 268 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 298 } | 298 } |
| 299 | 299 |
| 300 DEFINE_INLINE_VIRTUAL_TRACE() | 300 DEFINE_INLINE_VIRTUAL_TRACE() |
| 301 { | 301 { |
| 302 visitor->trace(m_baseValTearOff); | 302 visitor->trace(m_baseValTearOff); |
| 303 visitor->trace(m_animValTearOff); | 303 visitor->trace(m_animValTearOff); |
| 304 SVGAnimatedPropertyCommon<Property>::trace(visitor); | 304 SVGAnimatedPropertyCommon<Property>::trace(visitor); |
| 305 } | 305 } |
| 306 | 306 |
| 307 protected: | 307 protected: |
| 308 SVGAnimatedProperty(SVGElement* contextElement, const QualifiedName& attribu
teName, PassRefPtrWillBeRawPtr<Property> initialValue) | 308 SVGAnimatedProperty(SVGElement* contextElement, const QualifiedName& attribu
teName, RawPtr<Property> initialValue) |
| 309 : SVGAnimatedPropertyCommon<Property>(contextElement, attributeName, ini
tialValue) | 309 : SVGAnimatedPropertyCommon<Property>(contextElement, attributeName, ini
tialValue) |
| 310 { | 310 { |
| 311 } | 311 } |
| 312 | 312 |
| 313 private: | 313 private: |
| 314 void updateAnimValTearOffIfNeeded() | 314 void updateAnimValTearOffIfNeeded() |
| 315 { | 315 { |
| 316 if (m_animValTearOff) | 316 if (m_animValTearOff) |
| 317 m_animValTearOff->setTarget(this->currentValue()); | 317 m_animValTearOff->setTarget(this->currentValue()); |
| 318 } | 318 } |
| 319 | 319 |
| 320 // When still (not animated): | 320 // When still (not animated): |
| 321 // Both m_animValTearOff and m_baseValTearOff target m_baseValue. | 321 // Both m_animValTearOff and m_baseValTearOff target m_baseValue. |
| 322 // When animated: | 322 // When animated: |
| 323 // m_animValTearOff targets m_currentValue. | 323 // m_animValTearOff targets m_currentValue. |
| 324 // m_baseValTearOff targets m_baseValue. | 324 // m_baseValTearOff targets m_baseValue. |
| 325 RefPtrWillBeMember<TearOffType> m_baseValTearOff; | 325 Member<TearOffType> m_baseValTearOff; |
| 326 RefPtrWillBeMember<TearOffType> m_animValTearOff; | 326 Member<TearOffType> m_animValTearOff; |
| 327 }; | 327 }; |
| 328 | 328 |
| 329 // Implementation of SVGAnimatedProperty which doesn't use tear-off value types. | 329 // Implementation of SVGAnimatedProperty which doesn't use tear-off value types. |
| 330 // This class has "void" for its TearOffType. | 330 // This class has "void" for its TearOffType. |
| 331 // Currently only used for SVGAnimatedPath. | 331 // Currently only used for SVGAnimatedPath. |
| 332 template <typename Property> | 332 template <typename Property> |
| 333 class SVGAnimatedProperty<Property, void, void> : public SVGAnimatedPropertyComm
on<Property> { | 333 class SVGAnimatedProperty<Property, void, void> : public SVGAnimatedPropertyComm
on<Property> { |
| 334 public: | 334 public: |
| 335 static PassRefPtrWillBeRawPtr<SVGAnimatedProperty<Property>> create(SVGEleme
nt* contextElement, const QualifiedName& attributeName, PassRefPtrWillBeRawPtr<P
roperty> initialValue) | 335 static RawPtr<SVGAnimatedProperty<Property>> create(SVGElement* contextEleme
nt, const QualifiedName& attributeName, RawPtr<Property> initialValue) |
| 336 { | 336 { |
| 337 return adoptRefWillBeNoop(new SVGAnimatedProperty<Property>(contextEleme
nt, attributeName, initialValue)); | 337 return new SVGAnimatedProperty<Property>(contextElement, attributeName,
initialValue); |
| 338 } | 338 } |
| 339 | 339 |
| 340 bool needsSynchronizeAttribute() override | 340 bool needsSynchronizeAttribute() override |
| 341 { | 341 { |
| 342 // DOM attribute synchronization is only needed if the property is being
animated. | 342 // DOM attribute synchronization is only needed if the property is being
animated. |
| 343 return this->isAnimating(); | 343 return this->isAnimating(); |
| 344 } | 344 } |
| 345 | 345 |
| 346 protected: | 346 protected: |
| 347 SVGAnimatedProperty(SVGElement* contextElement, const QualifiedName& attribu
teName, PassRefPtrWillBeRawPtr<Property> initialValue) | 347 SVGAnimatedProperty(SVGElement* contextElement, const QualifiedName& attribu
teName, RawPtr<Property> initialValue) |
| 348 : SVGAnimatedPropertyCommon<Property>(contextElement, attributeName, ini
tialValue) | 348 : SVGAnimatedPropertyCommon<Property>(contextElement, attributeName, ini
tialValue) |
| 349 { | 349 { |
| 350 } | 350 } |
| 351 }; | 351 }; |
| 352 | 352 |
| 353 } // namespace blink | 353 } // namespace blink |
| 354 | 354 |
| 355 #endif // SVGAnimatedProperty_h | 355 #endif // SVGAnimatedProperty_h |
| OLD | NEW |