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