| 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #include "wtf/RefCounted.h" | 40 #include "wtf/RefCounted.h" |
| 41 | 41 |
| 42 namespace WebCore { | 42 namespace WebCore { |
| 43 | 43 |
| 44 class SVGElement; | 44 class SVGElement; |
| 45 | 45 |
| 46 class NewSVGAnimatedPropertyBase : public RefCounted<NewSVGAnimatedPropertyBase>
{ | 46 class NewSVGAnimatedPropertyBase : public RefCounted<NewSVGAnimatedPropertyBase>
{ |
| 47 public: | 47 public: |
| 48 virtual ~NewSVGAnimatedPropertyBase(); | 48 virtual ~NewSVGAnimatedPropertyBase(); |
| 49 | 49 |
| 50 virtual NewSVGPropertyBase* baseValueBase() = 0; |
| 50 virtual NewSVGPropertyBase* currentValueBase() = 0; | 51 virtual NewSVGPropertyBase* currentValueBase() = 0; |
| 51 | 52 |
| 52 virtual void animationStarted() = 0; | 53 virtual void animationStarted() = 0; |
| 53 virtual void resetToBaseVal() = 0; | 54 virtual PassRefPtr<NewSVGPropertyBase> createAnimatedValue() = 0; |
| 55 virtual void setAnimatedValue(PassRefPtr<NewSVGPropertyBase>) = 0; |
| 54 virtual void animationEnded() = 0; | 56 virtual void animationEnded() = 0; |
| 55 virtual void animValWillChange() = 0; | 57 virtual void animValWillChange() = 0; |
| 56 virtual void animValDidChange() = 0; | 58 virtual void animValDidChange() = 0; |
| 57 | 59 |
| 60 virtual bool needsSynchronizeAttribute() = 0; |
| 58 void synchronizeAttribute(); | 61 void synchronizeAttribute(); |
| 59 | 62 |
| 60 SVGElement* contextElement() | 63 SVGElement* contextElement() |
| 61 { | 64 { |
| 62 return m_contextElement; | 65 return m_contextElement; |
| 63 } | 66 } |
| 64 | 67 |
| 65 const QualifiedName& attributeName() const | 68 const QualifiedName& attributeName() const |
| 66 { | 69 { |
| 67 return m_attributeName; | 70 return m_attributeName; |
| 68 } | 71 } |
| 69 | 72 |
| 70 protected: | 73 protected: |
| 71 NewSVGAnimatedPropertyBase(SVGElement* contextElement, const QualifiedName&
attributeName) | 74 NewSVGAnimatedPropertyBase(SVGElement* contextElement, const QualifiedName&
attributeName); |
| 72 : m_contextElement(contextElement) | |
| 73 , m_attributeName(attributeName) | |
| 74 { | |
| 75 } | |
| 76 | 75 |
| 77 private: | 76 private: |
| 78 // This reference is kept alive from V8 wrapper | 77 // This reference is kept alive from V8 wrapper |
| 79 SVGElement* m_contextElement; | 78 SVGElement* m_contextElement; |
| 80 | 79 |
| 81 const QualifiedName& m_attributeName; | 80 const QualifiedName& m_attributeName; |
| 82 | 81 |
| 83 WTF_MAKE_NONCOPYABLE(NewSVGAnimatedPropertyBase); | 82 WTF_MAKE_NONCOPYABLE(NewSVGAnimatedPropertyBase); |
| 84 }; | 83 }; |
| 85 | 84 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 106 void setReadOnly() | 105 void setReadOnly() |
| 107 { | 106 { |
| 108 m_isReadOnly = true; | 107 m_isReadOnly = true; |
| 109 } | 108 } |
| 110 | 109 |
| 111 Property* baseValue() | 110 Property* baseValue() |
| 112 { | 111 { |
| 113 return m_baseValue.get(); | 112 return m_baseValue.get(); |
| 114 } | 113 } |
| 115 | 114 |
| 115 virtual NewSVGPropertyBase* baseValueBase() |
| 116 { |
| 117 return baseValue(); |
| 118 } |
| 119 |
| 116 Property* currentValue() | 120 Property* currentValue() |
| 117 { | 121 { |
| 118 return m_currentValue ? m_currentValue.get() : m_baseValue.get(); | 122 return m_currentValue ? m_currentValue.get() : m_baseValue.get(); |
| 119 } | 123 } |
| 120 | 124 |
| 121 virtual NewSVGPropertyBase* currentValueBase() | 125 virtual NewSVGPropertyBase* currentValueBase() |
| 122 { | 126 { |
| 123 return currentValue(); | 127 return currentValue(); |
| 124 } | 128 } |
| 125 | 129 |
| 126 void setBaseValueAsString(const String& value, SVGParsingError& parseError) | 130 void setBaseValueAsString(const String& value, SVGParsingError& parseError) |
| 127 { | 131 { |
| 128 TrackExceptionState es; | 132 TrackExceptionState es; |
| 129 | 133 |
| 130 m_baseValue->setValueAsString(value, es); | 134 m_baseValue->setValueAsString(value, es); |
| 131 | 135 |
| 132 if (es.hadException()) | 136 if (es.hadException()) |
| 133 parseError = ParsingAttributeFailedError; | 137 parseError = ParsingAttributeFailedError; |
| 134 } | 138 } |
| 135 | 139 |
| 136 bool isAnimating() const | 140 bool isAnimating() const |
| 137 { | 141 { |
| 138 // |m_currentValue| only exists while animation is active, | 142 return m_isAnimating; |
| 139 // so this can be used to check if this property is being animated. | |
| 140 return m_currentValue; | |
| 141 } | 143 } |
| 142 | 144 |
| 143 virtual void animationStarted() | 145 virtual void animationStarted() |
| 144 { | 146 { |
| 145 ASSERT(!isAnimating()); | 147 ASSERT(!isAnimating()); |
| 146 m_currentValue = m_baseValue->clone(); | 148 m_isAnimating = true; |
| 149 } |
| 150 |
| 151 virtual PassRefPtr<NewSVGPropertyBase> createAnimatedValue() |
| 152 { |
| 153 return m_baseValue->clone(); |
| 154 } |
| 155 |
| 156 virtual void setAnimatedValue(PassRefPtr<NewSVGPropertyBase> value) |
| 157 { |
| 158 ASSERT(isAnimating()); |
| 159 |
| 160 // FIXME: add type check |
| 161 m_currentValue = static_pointer_cast<Property>(value); |
| 147 | 162 |
| 148 if (m_animValTearOff) | 163 if (m_animValTearOff) |
| 149 m_animValTearOff->setTarget(m_currentValue); | 164 m_animValTearOff->setTarget(m_currentValue); |
| 150 } | 165 } |
| 151 | 166 |
| 152 virtual void animationEnded() | 167 virtual void animationEnded() |
| 153 { | 168 { |
| 154 ASSERT(isAnimating()); | 169 ASSERT(isAnimating()); |
| 170 m_isAnimating = false; |
| 171 |
| 172 ASSERT(m_currentValue); |
| 155 m_currentValue.clear(); | 173 m_currentValue.clear(); |
| 156 | 174 |
| 157 if (m_animValTearOff) | 175 if (m_animValTearOff) |
| 158 m_animValTearOff->setTarget(m_baseValue); | 176 m_animValTearOff->setTarget(m_baseValue); |
| 159 } | 177 } |
| 160 | 178 |
| 161 virtual void resetToBaseVal() | |
| 162 { | |
| 163 ASSERT(isAnimating()); | |
| 164 m_currentValue = m_baseValue->clone(); | |
| 165 | |
| 166 if (m_animValTearOff) | |
| 167 m_animValTearOff->setTarget(m_currentValue); | |
| 168 } | |
| 169 | |
| 170 virtual void animValWillChange() | 179 virtual void animValWillChange() |
| 171 { | 180 { |
| 172 ASSERT(isAnimating()); | 181 ASSERT(isAnimating()); |
| 173 } | 182 } |
| 174 | 183 |
| 175 virtual void animValDidChange() | 184 virtual void animValDidChange() |
| 176 { | 185 { |
| 177 ASSERT(isAnimating()); | 186 ASSERT(isAnimating()); |
| 178 } | 187 } |
| 179 | 188 |
| 189 virtual bool needsSynchronizeAttribute() |
| 190 { |
| 191 // DOM attribute synchronization is only needed if tear-off is being tou
ched from javascript or the property is being animated. |
| 192 // This prevents unnecessary attribute creation on target element. |
| 193 return m_baseValTearOff || isAnimating(); |
| 194 } |
| 195 |
| 180 // SVGAnimated* DOM Spec implementations: | 196 // SVGAnimated* DOM Spec implementations: |
| 181 | 197 |
| 182 // baseVal()/animVal() are only to be used from SVG DOM implementation. | 198 // baseVal()/animVal() are only to be used from SVG DOM implementation. |
| 183 // Use currentValue() from C++ code. | 199 // Use currentValue() from C++ code. |
| 184 virtual TearOffType* baseVal() | 200 virtual TearOffType* baseVal() |
| 185 { | 201 { |
| 186 if (!m_baseValTearOff) | 202 if (!m_baseValTearOff) |
| 187 m_baseValTearOff = TearOffType::create(m_baseValue, contextElement()
, PropertyIsNotAnimVal, attributeName()); | 203 m_baseValTearOff = TearOffType::create(m_baseValue, contextElement()
, PropertyIsNotAnimVal, attributeName()); |
| 188 | 204 |
| 189 return m_baseValTearOff.get(); | 205 return m_baseValTearOff.get(); |
| 190 } | 206 } |
| 191 | 207 |
| 192 TearOffType* animVal() | 208 TearOffType* animVal() |
| 193 { | 209 { |
| 194 if (!m_animValTearOff) | 210 if (!m_animValTearOff) |
| 195 m_animValTearOff = TearOffType::create(currentValue(), contextElemen
t(), PropertyIsAnimVal, attributeName()); | 211 m_animValTearOff = TearOffType::create(currentValue(), contextElemen
t(), PropertyIsAnimVal, attributeName()); |
| 196 | 212 |
| 197 return m_animValTearOff.get(); | 213 return m_animValTearOff.get(); |
| 198 } | 214 } |
| 199 | 215 |
| 200 protected: | 216 protected: |
| 201 NewSVGAnimatedProperty(SVGElement* contextElement, const QualifiedName& attr
ibuteName, PassRefPtr<Property> initialValue) | 217 NewSVGAnimatedProperty(SVGElement* contextElement, const QualifiedName& attr
ibuteName, PassRefPtr<Property> initialValue) |
| 202 : NewSVGAnimatedPropertyBase(contextElement, attributeName) | 218 : NewSVGAnimatedPropertyBase(contextElement, attributeName) |
| 219 , m_isReadOnly(false) |
| 220 , m_isAnimating(false) |
| 203 , m_baseValue(initialValue) | 221 , m_baseValue(initialValue) |
| 204 { | 222 { |
| 205 } | 223 } |
| 206 | 224 |
| 207 private: | 225 private: |
| 208 bool m_isReadOnly; | 226 bool m_isReadOnly; |
| 227 bool m_isAnimating; |
| 209 | 228 |
| 210 // When still (not animated): | 229 // When still (not animated): |
| 211 // Both m_animValTearOff and m_baseValTearOff target m_baseValue. | 230 // Both m_animValTearOff and m_baseValTearOff target m_baseValue. |
| 212 // When animated: | 231 // When animated: |
| 213 // m_animValTearOff targets m_currentValue. | 232 // m_animValTearOff targets m_currentValue. |
| 214 // m_baseValTearOff targets m_baseValue. | 233 // m_baseValTearOff targets m_baseValue. |
| 215 RefPtr<Property> m_baseValue; | 234 RefPtr<Property> m_baseValue; |
| 216 RefPtr<Property> m_currentValue; | 235 RefPtr<Property> m_currentValue; |
| 217 RefPtr<TearOffType> m_baseValTearOff; | 236 RefPtr<TearOffType> m_baseValTearOff; |
| 218 RefPtr<TearOffType> m_animValTearOff; | 237 RefPtr<TearOffType> m_animValTearOff; |
| 219 }; | 238 }; |
| 220 | 239 |
| 221 } | 240 } |
| 222 | 241 |
| 223 #endif // NewSVGAnimatedProperty_h | 242 #endif // NewSVGAnimatedProperty_h |
| OLD | NEW |