Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: Source/core/svg/properties/SVGAnimatedProperty.h

Issue 208133002: [SVG] Remove "New" prefix from properties implementation. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 10 matching lines...) Expand all
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef NewSVGAnimatedProperty_h 31 #ifndef SVGAnimatedProperty_h
32 #define NewSVGAnimatedProperty_h 32 #define SVGAnimatedProperty_h
33 33
34 #include "bindings/v8/ExceptionStatePlaceholder.h" 34 #include "bindings/v8/ExceptionStatePlaceholder.h"
35 #include "bindings/v8/ScriptWrappable.h" 35 #include "bindings/v8/ScriptWrappable.h"
36 #include "core/dom/ExceptionCode.h" 36 #include "core/dom/ExceptionCode.h"
37 #include "core/svg/SVGParsingError.h" 37 #include "core/svg/SVGParsingError.h"
38 #include "core/svg/properties/NewSVGPropertyTearOff.h"
39 #include "core/svg/properties/SVGPropertyInfo.h" 38 #include "core/svg/properties/SVGPropertyInfo.h"
39 #include "core/svg/properties/SVGPropertyTearOff.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 WebCore { 44 namespace WebCore {
45 45
46 class SVGElement; 46 class SVGElement;
47 47
48 class NewSVGAnimatedPropertyBase : public RefCounted<NewSVGAnimatedPropertyBase> { 48 class SVGAnimatedPropertyBase : public RefCounted<SVGAnimatedPropertyBase> {
49 public: 49 public:
50 virtual ~NewSVGAnimatedPropertyBase(); 50 virtual ~SVGAnimatedPropertyBase();
51 51
52 virtual NewSVGPropertyBase* currentValueBase() = 0; 52 virtual SVGPropertyBase* currentValueBase() = 0;
53 53
54 virtual void animationStarted(); 54 virtual void animationStarted();
55 virtual PassRefPtr<NewSVGPropertyBase> createAnimatedValue() = 0; 55 virtual PassRefPtr<SVGPropertyBase> createAnimatedValue() = 0;
56 virtual void setAnimatedValue(PassRefPtr<NewSVGPropertyBase>) = 0; 56 virtual void setAnimatedValue(PassRefPtr<SVGPropertyBase>) = 0;
57 virtual void animationEnded(); 57 virtual void animationEnded();
58 58
59 virtual bool needsSynchronizeAttribute() = 0; 59 virtual bool needsSynchronizeAttribute() = 0;
60 virtual void synchronizeAttribute(); 60 virtual void synchronizeAttribute();
61 61
62 AnimatedPropertyType type() const 62 AnimatedPropertyType type() const
63 { 63 {
64 return m_type; 64 return m_type;
65 } 65 }
66 66
(...skipping 18 matching lines...) Expand all
85 } 85 }
86 86
87 void setReadOnly() 87 void setReadOnly()
88 { 88 {
89 m_isReadOnly = true; 89 m_isReadOnly = true;
90 } 90 }
91 91
92 bool isSpecified() const; 92 bool isSpecified() const;
93 93
94 protected: 94 protected:
95 NewSVGAnimatedPropertyBase(AnimatedPropertyType, SVGElement*, const Qualifie dName& attributeName); 95 SVGAnimatedPropertyBase(AnimatedPropertyType, SVGElement*, const QualifiedNa me& attributeName);
96 void commitChange(); 96 void commitChange();
97 97
98 private: 98 private:
99 const AnimatedPropertyType m_type; 99 const AnimatedPropertyType m_type;
100 bool m_isReadOnly; 100 bool m_isReadOnly;
101 bool m_isAnimating; 101 bool m_isAnimating;
102 102
103 // This reference is kept alive from V8 wrapper 103 // This reference is kept alive from V8 wrapper
104 SVGElement* m_contextElement; 104 SVGElement* m_contextElement;
105 105
106 const QualifiedName& m_attributeName; 106 const QualifiedName& m_attributeName;
107 107
108 WTF_MAKE_NONCOPYABLE(NewSVGAnimatedPropertyBase); 108 WTF_MAKE_NONCOPYABLE(SVGAnimatedPropertyBase);
109 }; 109 };
110 110
111 template <typename Property> 111 template <typename Property>
112 class NewSVGAnimatedPropertyCommon : public NewSVGAnimatedPropertyBase { 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();
117 } 117 }
118 118
119 Property* currentValue() 119 Property* currentValue()
120 { 120 {
121 return m_currentValue ? m_currentValue.get() : m_baseValue.get(); 121 return m_currentValue ? m_currentValue.get() : m_baseValue.get();
122 } 122 }
123 123
124 const Property* currentValue() const 124 const Property* currentValue() const
125 { 125 {
126 return const_cast<NewSVGAnimatedPropertyCommon*>(this)->currentValue(); 126 return const_cast<SVGAnimatedPropertyCommon*>(this)->currentValue();
127 } 127 }
128 128
129 virtual NewSVGPropertyBase* currentValueBase() OVERRIDE 129 virtual SVGPropertyBase* currentValueBase() OVERRIDE
130 { 130 {
131 return currentValue(); 131 return currentValue();
132 } 132 }
133 133
134 void setBaseValueAsString(const String& value, SVGParsingError& parseError) 134 void setBaseValueAsString(const String& value, SVGParsingError& parseError)
135 { 135 {
136 TrackExceptionState es; 136 TrackExceptionState es;
137 137
138 m_baseValue->setValueAsString(value, es); 138 m_baseValue->setValueAsString(value, es);
139 139
140 if (es.hadException()) 140 if (es.hadException())
141 parseError = ParsingAttributeFailedError; 141 parseError = ParsingAttributeFailedError;
142 } 142 }
143 143
144 virtual PassRefPtr<NewSVGPropertyBase> createAnimatedValue() OVERRIDE 144 virtual PassRefPtr<SVGPropertyBase> createAnimatedValue() OVERRIDE
145 { 145 {
146 return m_baseValue->clone(); 146 return m_baseValue->clone();
147 } 147 }
148 148
149 virtual void setAnimatedValue(PassRefPtr<NewSVGPropertyBase> passValue) OVER RIDE 149 virtual void setAnimatedValue(PassRefPtr<SVGPropertyBase> passValue) OVERRID E
150 { 150 {
151 ASSERT(isAnimating()); 151 ASSERT(isAnimating());
152 152
153 RefPtr<NewSVGPropertyBase> value = passValue; 153 RefPtr<SVGPropertyBase> value = passValue;
154 ASSERT(value->type() == Property::classType()); 154 ASSERT(value->type() == Property::classType());
155 m_currentValue = static_pointer_cast<Property>(value.release()); 155 m_currentValue = static_pointer_cast<Property>(value.release());
156 } 156 }
157 157
158 virtual void animationEnded() OVERRIDE 158 virtual void animationEnded() OVERRIDE
159 { 159 {
160 NewSVGAnimatedPropertyBase::animationEnded(); 160 SVGAnimatedPropertyBase::animationEnded();
161 161
162 ASSERT(m_currentValue); 162 ASSERT(m_currentValue);
163 m_currentValue.clear(); 163 m_currentValue.clear();
164 } 164 }
165 165
166 protected: 166 protected:
167 NewSVGAnimatedPropertyCommon(SVGElement* contextElement, const QualifiedName & attributeName, PassRefPtr<Property> initialValue) 167 SVGAnimatedPropertyCommon(SVGElement* contextElement, const QualifiedName& a ttributeName, PassRefPtr<Property> initialValue)
168 : NewSVGAnimatedPropertyBase(Property::classType(), contextElement, attr ibuteName) 168 : SVGAnimatedPropertyBase(Property::classType(), contextElement, attribu teName)
169 , m_baseValue(initialValue) 169 , m_baseValue(initialValue)
170 { 170 {
171 } 171 }
172 172
173 private: 173 private:
174 RefPtr<Property> m_baseValue; 174 RefPtr<Property> m_baseValue;
175 RefPtr<Property> m_currentValue; 175 RefPtr<Property> m_currentValue;
176 }; 176 };
177 177
178 // Implementation of SVGAnimatedProperty which uses primitive types. 178 // Implementation of SVGAnimatedProperty which uses primitive types.
179 // This is for classes which return primitive type for its "animVal". 179 // This is for classes which return primitive type for its "animVal".
180 // Examples are SVGAnimatedBoolean, SVGAnimatedNumber, etc. 180 // Examples are SVGAnimatedBoolean, SVGAnimatedNumber, etc.
181 template <typename Property, typename TearOffType = typename Property::TearOffTy pe, typename PrimitiveType = typename Property::PrimitiveType> 181 template <typename Property, typename TearOffType = typename Property::TearOffTy pe, typename PrimitiveType = typename Property::PrimitiveType>
182 class NewSVGAnimatedProperty : public NewSVGAnimatedPropertyCommon<Property> { 182 class SVGAnimatedProperty : public SVGAnimatedPropertyCommon<Property> {
183 public: 183 public:
184 static PassRefPtr<NewSVGAnimatedProperty<Property> > create(SVGElement* cont extElement, const QualifiedName& attributeName, PassRefPtr<Property> initialValu e) 184 static PassRefPtr<SVGAnimatedProperty<Property> > create(SVGElement* context Element, const QualifiedName& attributeName, PassRefPtr<Property> initialValue)
185 { 185 {
186 return adoptRef(new NewSVGAnimatedProperty<Property>(contextElement, att ributeName, initialValue)); 186 return adoptRef(new SVGAnimatedProperty<Property>(contextElement, attrib uteName, initialValue));
187 } 187 }
188 188
189 virtual bool needsSynchronizeAttribute() OVERRIDE 189 virtual bool needsSynchronizeAttribute() OVERRIDE
190 { 190 {
191 // DOM attribute synchronization is only needed if tear-off is being tou ched from javascript or the property is being animated. 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. 192 // This prevents unnecessary attribute creation on target element.
193 return m_baseValueUpdated || this->isAnimating(); 193 return m_baseValueUpdated || this->isAnimating();
194 } 194 }
195 195
196 virtual void synchronizeAttribute() OVERRIDE 196 virtual void synchronizeAttribute() OVERRIDE
197 { 197 {
198 NewSVGAnimatedPropertyBase::synchronizeAttribute(); 198 SVGAnimatedPropertyBase::synchronizeAttribute();
199 m_baseValueUpdated = false; 199 m_baseValueUpdated = false;
200 } 200 }
201 201
202 // SVGAnimated* DOM Spec implementations: 202 // SVGAnimated* DOM Spec implementations:
203 203
204 // baseVal()/setBaseVal()/animVal() are only to be used from SVG DOM impleme ntation. 204 // baseVal()/setBaseVal()/animVal() are only to be used from SVG DOM impleme ntation.
205 // Use currentValue() from C++ code. 205 // Use currentValue() from C++ code.
206 PrimitiveType baseVal() 206 PrimitiveType baseVal()
207 { 207 {
208 return this->baseValue()->value(); 208 return this->baseValue()->value();
(...skipping 13 matching lines...) Expand all
222 this->contextElement()->invalidateSVGAttributes(); 222 this->contextElement()->invalidateSVGAttributes();
223 this->contextElement()->svgAttributeChanged(this->attributeName()); 223 this->contextElement()->svgAttributeChanged(this->attributeName());
224 } 224 }
225 225
226 PrimitiveType animVal() 226 PrimitiveType animVal()
227 { 227 {
228 return this->currentValue()->value(); 228 return this->currentValue()->value();
229 } 229 }
230 230
231 protected: 231 protected:
232 NewSVGAnimatedProperty(SVGElement* contextElement, const QualifiedName& attr ibuteName, PassRefPtr<Property> initialValue) 232 SVGAnimatedProperty(SVGElement* contextElement, const QualifiedName& attribu teName, PassRefPtr<Property> initialValue)
233 : NewSVGAnimatedPropertyCommon<Property>(contextElement, attributeName, initialValue) 233 : SVGAnimatedPropertyCommon<Property>(contextElement, attributeName, ini tialValue)
234 , m_baseValueUpdated(false) 234 , m_baseValueUpdated(false)
235 { 235 {
236 } 236 }
237 237
238 bool m_baseValueUpdated; 238 bool m_baseValueUpdated;
239 }; 239 };
240 240
241 // Implementation of SVGAnimatedProperty which uses tear-off value types. 241 // Implementation of SVGAnimatedProperty which uses tear-off value types.
242 // These classes has "void" for its PrimitiveType. 242 // These classes has "void" for its PrimitiveType.
243 // This is for classes which return special type for its "animVal". 243 // This is for classes which return special type for its "animVal".
244 // Examples are SVGAnimatedLength, SVGAnimatedRect, SVGAnimated*List, etc. 244 // Examples are SVGAnimatedLength, SVGAnimatedRect, SVGAnimated*List, etc.
245 template <typename Property, typename TearOffType> 245 template <typename Property, typename TearOffType>
246 class NewSVGAnimatedProperty<Property, TearOffType, void> : public NewSVGAnimate dPropertyCommon<Property> { 246 class SVGAnimatedProperty<Property, TearOffType, void> : public SVGAnimatedPrope rtyCommon<Property> {
247 public: 247 public:
248 static PassRefPtr<NewSVGAnimatedProperty<Property> > create(SVGElement* cont extElement, const QualifiedName& attributeName, PassRefPtr<Property> initialValu e) 248 static PassRefPtr<SVGAnimatedProperty<Property> > create(SVGElement* context Element, const QualifiedName& attributeName, PassRefPtr<Property> initialValue)
249 { 249 {
250 return adoptRef(new NewSVGAnimatedProperty<Property>(contextElement, att ributeName, initialValue)); 250 return adoptRef(new SVGAnimatedProperty<Property>(contextElement, attrib uteName, initialValue));
251 } 251 }
252 252
253 virtual void setAnimatedValue(PassRefPtr<NewSVGPropertyBase> value) OVERRIDE 253 virtual void setAnimatedValue(PassRefPtr<SVGPropertyBase> value) OVERRIDE
254 { 254 {
255 NewSVGAnimatedPropertyCommon<Property>::setAnimatedValue(value); 255 SVGAnimatedPropertyCommon<Property>::setAnimatedValue(value);
256 updateAnimValTearOffIfNeeded(); 256 updateAnimValTearOffIfNeeded();
257 } 257 }
258 258
259 virtual void animationEnded() OVERRIDE 259 virtual void animationEnded() OVERRIDE
260 { 260 {
261 NewSVGAnimatedPropertyCommon<Property>::animationEnded(); 261 SVGAnimatedPropertyCommon<Property>::animationEnded();
262 updateAnimValTearOffIfNeeded(); 262 updateAnimValTearOffIfNeeded();
263 } 263 }
264 264
265 virtual bool needsSynchronizeAttribute() OVERRIDE 265 virtual bool needsSynchronizeAttribute() OVERRIDE
266 { 266 {
267 // DOM attribute synchronization is only needed if tear-off is being tou ched from javascript or the property is being animated. 267 // DOM attribute synchronization is only needed if tear-off is being tou ched from javascript or the property is being animated.
268 // This prevents unnecessary attribute creation on target element. 268 // This prevents unnecessary attribute creation on target element.
269 return m_baseValTearOff || this->isAnimating(); 269 return m_baseValTearOff || this->isAnimating();
270 } 270 }
271 271
(...skipping 14 matching lines...) Expand all
286 286
287 TearOffType* animVal() 287 TearOffType* animVal()
288 { 288 {
289 if (!m_animValTearOff) 289 if (!m_animValTearOff)
290 m_animValTearOff = TearOffType::create(this->currentValue(), this->c ontextElement(), PropertyIsAnimVal, this->attributeName()); 290 m_animValTearOff = TearOffType::create(this->currentValue(), this->c ontextElement(), PropertyIsAnimVal, this->attributeName());
291 291
292 return m_animValTearOff.get(); 292 return m_animValTearOff.get();
293 } 293 }
294 294
295 protected: 295 protected:
296 NewSVGAnimatedProperty(SVGElement* contextElement, const QualifiedName& attr ibuteName, PassRefPtr<Property> initialValue) 296 SVGAnimatedProperty(SVGElement* contextElement, const QualifiedName& attribu teName, PassRefPtr<Property> initialValue)
297 : NewSVGAnimatedPropertyCommon<Property>(contextElement, attributeName, initialValue) 297 : SVGAnimatedPropertyCommon<Property>(contextElement, attributeName, ini tialValue)
298 { 298 {
299 } 299 }
300 300
301 private: 301 private:
302 void updateAnimValTearOffIfNeeded() 302 void updateAnimValTearOffIfNeeded()
303 { 303 {
304 if (m_animValTearOff) 304 if (m_animValTearOff)
305 m_animValTearOff->setTarget(this->currentValue()); 305 m_animValTearOff->setTarget(this->currentValue());
306 } 306 }
307 307
308 // When still (not animated): 308 // When still (not animated):
309 // Both m_animValTearOff and m_baseValTearOff target m_baseValue. 309 // Both m_animValTearOff and m_baseValTearOff target m_baseValue.
310 // When animated: 310 // When animated:
311 // m_animValTearOff targets m_currentValue. 311 // m_animValTearOff targets m_currentValue.
312 // m_baseValTearOff targets m_baseValue. 312 // m_baseValTearOff targets m_baseValue.
313 RefPtr<TearOffType> m_baseValTearOff; 313 RefPtr<TearOffType> m_baseValTearOff;
314 RefPtr<TearOffType> m_animValTearOff; 314 RefPtr<TearOffType> m_animValTearOff;
315 }; 315 };
316 316
317 } 317 }
318 318
319 #endif // NewSVGAnimatedProperty_h 319 #endif // SVGAnimatedProperty_h
OLDNEW
« no previous file with comments | « Source/core/svg/properties/NewSVGPropertyTearOff.cpp ('k') | Source/core/svg/properties/SVGAnimatedProperty.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698