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

Side by Side Diff: Source/core/svg/SVGAnimateElement.cpp

Issue 303093002: SVG: remove |SVGAnimateElement::m_animatedPropertyType| (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix wrong if Created 6 years, 6 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) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
4 * Copyright (C) 2008 Apple Inc. All rights reserved. 4 * Copyright (C) 2008 Apple Inc. All rights reserved.
5 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 5 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 18 matching lines...) Expand all
29 #include "core/css/StylePropertySet.h" 29 #include "core/css/StylePropertySet.h"
30 #include "core/dom/QualifiedName.h" 30 #include "core/dom/QualifiedName.h"
31 #include "core/svg/SVGAnimatedTypeAnimator.h" 31 #include "core/svg/SVGAnimatedTypeAnimator.h"
32 #include "core/svg/SVGDocumentExtensions.h" 32 #include "core/svg/SVGDocumentExtensions.h"
33 #include "core/svg/SVGElementInstance.h" 33 #include "core/svg/SVGElementInstance.h"
34 34
35 namespace WebCore { 35 namespace WebCore {
36 36
37 SVGAnimateElement::SVGAnimateElement(const QualifiedName& tagName, Document& doc ument) 37 SVGAnimateElement::SVGAnimateElement(const QualifiedName& tagName, Document& doc ument)
38 : SVGAnimationElement(tagName, document) 38 : SVGAnimationElement(tagName, document)
39 , m_animatedPropertyType(AnimatedString)
40 { 39 {
41 ASSERT(isSVGAnimateElement(*this)); 40 ASSERT(isSVGAnimateElement(*this));
42 ScriptWrappable::init(this); 41 ScriptWrappable::init(this);
43 } 42 }
44 43
45 PassRefPtrWillBeRawPtr<SVGAnimateElement> SVGAnimateElement::create(Document& do cument) 44 PassRefPtrWillBeRawPtr<SVGAnimateElement> SVGAnimateElement::create(Document& do cument)
46 { 45 {
47 return adoptRefWillBeRefCountedGarbageCollected(new SVGAnimateElement(SVGNam es::animateTag, document)); 46 return adoptRefWillBeRefCountedGarbageCollected(new SVGAnimateElement(SVGNam es::animateTag, document));
48 } 47 }
49 48
50 SVGAnimateElement::~SVGAnimateElement() 49 SVGAnimateElement::~SVGAnimateElement()
51 { 50 {
52 // FIXME: Oilpan: Below prevent stopAnimValAnimation being called on |target Element|. This should be moved to |removeFrom| equivalent. 51 // FIXME: Oilpan: Below prevent stopAnimValAnimation being called on |target Element|. This should be moved to |removeFrom| equivalent.
53 #if !ENABLE(OILPAN) 52 #if !ENABLE(OILPAN)
54 if (targetElement()) 53 if (targetElement())
55 clearAnimatedType(targetElement()); 54 clearAnimatedType(targetElement());
56 #endif 55 #endif
57 } 56 }
58 57
58 AnimatedPropertyType SVGAnimateElement::animatedPropertyType()
59 {
60 return ensureAnimator()->type();
61 }
62
59 bool SVGAnimateElement::hasValidAttributeType() 63 bool SVGAnimateElement::hasValidAttributeType()
60 { 64 {
61 SVGElement* targetElement = this->targetElement(); 65 SVGElement* targetElement = this->targetElement();
62 if (!targetElement) 66 if (!targetElement)
63 return false; 67 return false;
64 68
65 return m_animatedPropertyType != AnimatedUnknown && !hasInvalidCSSAttributeT ype(); 69 return animatedPropertyType() != AnimatedUnknown && !hasInvalidCSSAttributeT ype();
66 } 70 }
67 71
68 void SVGAnimateElement::calculateAnimatedValue(float percentage, unsigned repeat Count, SVGSMILElement* resultElement) 72 void SVGAnimateElement::calculateAnimatedValue(float percentage, unsigned repeat Count, SVGSMILElement* resultElement)
69 { 73 {
70 ASSERT(resultElement); 74 ASSERT(resultElement);
71 SVGElement* targetElement = this->targetElement(); 75 SVGElement* targetElement = this->targetElement();
72 if (!targetElement || !isSVGAnimateElement(*resultElement)) 76 if (!targetElement || !isSVGAnimateElement(*resultElement))
73 return; 77 return;
74 78
75 ASSERT(m_animatedPropertyType == determineAnimatedPropertyType());
76
77 ASSERT(percentage >= 0 && percentage <= 1); 79 ASSERT(percentage >= 0 && percentage <= 1);
78 ASSERT(m_animatedPropertyType != AnimatedTransformList || isSVGAnimateTransf ormElement(*this));
79 ASSERT(m_animatedPropertyType != AnimatedUnknown);
80 ASSERT(m_animator); 80 ASSERT(m_animator);
81 ASSERT(m_animator->type() == m_animatedPropertyType); 81 ASSERT(animatedPropertyType() != AnimatedTransformList || isSVGAnimateTransf ormElement(*this));
82 ASSERT(animatedPropertyType() != AnimatedUnknown);
82 ASSERT(m_fromProperty); 83 ASSERT(m_fromProperty);
83 ASSERT(m_fromProperty->type() == m_animatedPropertyType); 84 ASSERT(m_fromProperty->type() == animatedPropertyType());
84 ASSERT(m_toProperty); 85 ASSERT(m_toProperty);
85 86
86 SVGAnimateElement* resultAnimationElement = toSVGAnimateElement(resultElemen t); 87 SVGAnimateElement* resultAnimationElement = toSVGAnimateElement(resultElemen t);
87 ASSERT(resultAnimationElement->m_animatedProperty); 88 ASSERT(resultAnimationElement->m_animatedProperty);
88 ASSERT(resultAnimationElement->m_animatedPropertyType == m_animatedPropertyT ype); 89 ASSERT(resultAnimationElement->animatedPropertyType() == animatedPropertyTyp e());
89 90
90 if (isSVGSetElement(*this)) 91 if (isSVGSetElement(*this))
91 percentage = 1; 92 percentage = 1;
92 93
93 if (calcMode() == CalcModeDiscrete) 94 if (calcMode() == CalcModeDiscrete)
94 percentage = percentage < 0.5 ? 0 : 1; 95 percentage = percentage < 0.5 ? 0 : 1;
95 96
96 // Target element might have changed. 97 // Target element might have changed.
97 m_animator->setContextElement(targetElement); 98 m_animator->setContextElement(targetElement);
98 99
(...skipping 11 matching lines...) Expand all
110 } 111 }
111 112
112 bool SVGAnimateElement::calculateFromAndToValues(const String& fromString, const String& toString) 113 bool SVGAnimateElement::calculateFromAndToValues(const String& fromString, const String& toString)
113 { 114 {
114 SVGElement* targetElement = this->targetElement(); 115 SVGElement* targetElement = this->targetElement();
115 if (!targetElement) 116 if (!targetElement)
116 return false; 117 return false;
117 118
118 determinePropertyValueTypes(fromString, toString); 119 determinePropertyValueTypes(fromString, toString);
119 ensureAnimator()->calculateFromAndToValues(m_fromProperty, m_toProperty, fro mString, toString); 120 ensureAnimator()->calculateFromAndToValues(m_fromProperty, m_toProperty, fro mString, toString);
120 ASSERT(m_animatedPropertyType == m_animator->type());
121 return true; 121 return true;
122 } 122 }
123 123
124 bool SVGAnimateElement::calculateFromAndByValues(const String& fromString, const String& byString) 124 bool SVGAnimateElement::calculateFromAndByValues(const String& fromString, const String& byString)
125 { 125 {
126 SVGElement* targetElement = this->targetElement(); 126 SVGElement* targetElement = this->targetElement();
127 if (!targetElement) 127 if (!targetElement)
128 return false; 128 return false;
129 129
130 if (animationMode() == ByAnimation && !isAdditive()) 130 if (animationMode() == ByAnimation && !isAdditive())
131 return false; 131 return false;
132 132
133 // from-by animation may only be used with attributes that support addition (e.g. most numeric attributes). 133 // from-by animation may only be used with attributes that support addition (e.g. most numeric attributes).
134 if (animationMode() == FromByAnimation && !animatedPropertyTypeSupportsAddit ion()) 134 if (animationMode() == FromByAnimation && !animatedPropertyTypeSupportsAddit ion())
135 return false; 135 return false;
136 136
137 ASSERT(!isSVGSetElement(*this)); 137 ASSERT(!isSVGSetElement(*this));
138 138
139 determinePropertyValueTypes(fromString, byString); 139 determinePropertyValueTypes(fromString, byString);
140 ensureAnimator()->calculateFromAndByValues(m_fromProperty, m_toProperty, fro mString, byString); 140 ensureAnimator()->calculateFromAndByValues(m_fromProperty, m_toProperty, fro mString, byString);
141 ASSERT(m_animatedPropertyType == m_animator->type());
142 return true; 141 return true;
143 } 142 }
144 143
145 namespace { 144 namespace {
146 145
147 WillBeHeapVector<RawPtrWillBeMember<SVGElement> > findElementInstances(SVGElemen t* targetElement) 146 WillBeHeapVector<RawPtrWillBeMember<SVGElement> > findElementInstances(SVGElemen t* targetElement)
148 { 147 {
149 ASSERT(targetElement); 148 ASSERT(targetElement);
150 WillBeHeapVector<RawPtrWillBeMember<SVGElement> > animatedElements; 149 WillBeHeapVector<RawPtrWillBeMember<SVGElement> > animatedElements;
151 150
152 animatedElements.append(targetElement); 151 animatedElements.append(targetElement);
153 152
154 const WillBeHeapHashSet<RawPtrWillBeWeakMember<SVGElement> >& instances = ta rgetElement->instancesForElement(); 153 const WillBeHeapHashSet<RawPtrWillBeWeakMember<SVGElement> >& instances = ta rgetElement->instancesForElement();
155 const WillBeHeapHashSet<RawPtrWillBeWeakMember<SVGElement> >::const_iterator end = instances.end(); 154 const WillBeHeapHashSet<RawPtrWillBeWeakMember<SVGElement> >::const_iterator end = instances.end();
156 for (WillBeHeapHashSet<RawPtrWillBeWeakMember<SVGElement> >::const_iterator it = instances.begin(); it != end; ++it) { 155 for (WillBeHeapHashSet<RawPtrWillBeWeakMember<SVGElement> >::const_iterator it = instances.begin(); it != end; ++it) {
157 if (SVGElement* shadowTreeElement = *it) 156 if (SVGElement* shadowTreeElement = *it)
158 animatedElements.append(shadowTreeElement); 157 animatedElements.append(shadowTreeElement);
159 } 158 }
160 159
161 return animatedElements; 160 return animatedElements;
162 } 161 }
163 162
164 } 163 }
165 164
166 void SVGAnimateElement::resetAnimatedType() 165 void SVGAnimateElement::resetAnimatedType()
167 { 166 {
168 SVGAnimatedTypeAnimator* animator = ensureAnimator(); 167 SVGAnimatedTypeAnimator* animator = ensureAnimator();
169 ASSERT(m_animatedPropertyType == animator->type());
170 168
171 SVGElement* targetElement = this->targetElement(); 169 SVGElement* targetElement = this->targetElement();
172 const QualifiedName& attributeName = this->attributeName(); 170 const QualifiedName& attributeName = this->attributeName();
173 ShouldApplyAnimation shouldApply = shouldApplyAnimation(targetElement, attri buteName); 171 ShouldApplyAnimation shouldApply = shouldApplyAnimation(targetElement, attri buteName);
174 172
175 if (shouldApply == DontApplyAnimation) 173 if (shouldApply == DontApplyAnimation)
176 return; 174 return;
177 175
178 if (shouldApply == ApplyXMLAnimation) { 176 if (shouldApply == ApplyXMLAnimation) {
179 // SVG DOM animVal animation code-path. 177 // SVG DOM animVal animation code-path.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 WillBeHeapVector<RawPtrWillBeMember<SVGElement> > animatedElements = fin dElementInstances(targetElement); 311 WillBeHeapVector<RawPtrWillBeMember<SVGElement> > animatedElements = fin dElementInstances(targetElement);
314 m_animator->stopAnimValAnimation(animatedElements); 312 m_animator->stopAnimValAnimation(animatedElements);
315 notifyTargetAndInstancesAboutAnimValChange(targetElement, attributeName( )); 313 notifyTargetAndInstancesAboutAnimValChange(targetElement, attributeName( ));
316 } 314 }
317 315
318 m_animatedProperty.clear(); 316 m_animatedProperty.clear();
319 } 317 }
320 318
321 void SVGAnimateElement::applyResultsToTarget() 319 void SVGAnimateElement::applyResultsToTarget()
322 { 320 {
323 ASSERT(m_animatedPropertyType != AnimatedTransformList || isSVGAnimateTransf ormElement(*this));
324 ASSERT(m_animatedPropertyType != AnimatedUnknown);
325 ASSERT(m_animator); 321 ASSERT(m_animator);
322 ASSERT(animatedPropertyType() != AnimatedTransformList || isSVGAnimateTransf ormElement(*this));
323 ASSERT(animatedPropertyType() != AnimatedUnknown);
326 324
327 // Early exit if our animated type got destructed by a previous endedActiveI nterval(). 325 // Early exit if our animated type got destructed by a previous endedActiveI nterval().
328 if (!m_animatedProperty) 326 if (!m_animatedProperty)
329 return; 327 return;
330 328
331 if (ensureAnimator()->isAnimatingCSSProperty()) { 329 if (m_animator->isAnimatingCSSProperty()) {
332 // CSS properties animation code-path. 330 // CSS properties animation code-path.
333 // Convert the result of the animation to a String and apply it as CSS p roperty on the target & all instances. 331 // Convert the result of the animation to a String and apply it as CSS p roperty on the target & all instances.
334 applyCSSPropertyToTargetAndInstances(targetElement(), attributeName(), m _animatedProperty->valueAsString()); 332 applyCSSPropertyToTargetAndInstances(targetElement(), attributeName(), m _animatedProperty->valueAsString());
335 return; 333 return;
336 } 334 }
337 335
338 // SVG DOM animVal animation code-path. 336 // SVG DOM animVal animation code-path.
339 // At this point the SVG DOM values are already changed, unlike for CSS. 337 // At this point the SVG DOM values are already changed, unlike for CSS.
340 // We only have to trigger update notifications here. 338 // We only have to trigger update notifications here.
341 notifyTargetAndInstancesAboutAnimValChange(targetElement(), attributeName()) ; 339 notifyTargetAndInstancesAboutAnimValChange(targetElement(), attributeName()) ;
342 } 340 }
343 341
344 bool SVGAnimateElement::animatedPropertyTypeSupportsAddition() const 342 bool SVGAnimateElement::animatedPropertyTypeSupportsAddition()
345 { 343 {
346 // Spec: http://www.w3.org/TR/SVG/animate.html#AnimationAttributesAndPropert ies. 344 // Spec: http://www.w3.org/TR/SVG/animate.html#AnimationAttributesAndPropert ies.
347 switch (m_animatedPropertyType) { 345 switch (animatedPropertyType()) {
348 case AnimatedBoolean: 346 case AnimatedBoolean:
349 case AnimatedEnumeration: 347 case AnimatedEnumeration:
350 case AnimatedPreserveAspectRatio: 348 case AnimatedPreserveAspectRatio:
351 case AnimatedString: 349 case AnimatedString:
352 case AnimatedUnknown: 350 case AnimatedUnknown:
353 return false; 351 return false;
354 default: 352 default:
355 return true; 353 return true;
356 } 354 }
357 } 355 }
358 356
359 bool SVGAnimateElement::isAdditive() const 357 bool SVGAnimateElement::isAdditive()
360 { 358 {
361 if (animationMode() == ByAnimation || animationMode() == FromByAnimation) 359 if (animationMode() == ByAnimation || animationMode() == FromByAnimation)
362 if (!animatedPropertyTypeSupportsAddition()) 360 if (!animatedPropertyTypeSupportsAddition())
363 return false; 361 return false;
364 362
365 return SVGAnimationElement::isAdditive(); 363 return SVGAnimationElement::isAdditive();
366 } 364 }
367 365
368 float SVGAnimateElement::calculateDistance(const String& fromString, const Strin g& toString) 366 float SVGAnimateElement::calculateDistance(const String& fromString, const Strin g& toString)
369 { 367 {
(...skipping 17 matching lines...) Expand all
387 resetAnimatedPropertyType(); 385 resetAnimatedPropertyType();
388 } 386 }
389 387
390 void SVGAnimateElement::resetAnimatedPropertyType() 388 void SVGAnimateElement::resetAnimatedPropertyType()
391 { 389 {
392 ASSERT(!m_animatedProperty); 390 ASSERT(!m_animatedProperty);
393 m_fromProperty.clear(); 391 m_fromProperty.clear();
394 m_toProperty.clear(); 392 m_toProperty.clear();
395 m_toAtEndOfDurationProperty.clear(); 393 m_toAtEndOfDurationProperty.clear();
396 m_animator.clear(); 394 m_animator.clear();
397 m_animatedPropertyType = determineAnimatedPropertyType();
398 } 395 }
399 396
400 SVGAnimatedTypeAnimator* SVGAnimateElement::ensureAnimator() 397 SVGAnimatedTypeAnimator* SVGAnimateElement::ensureAnimator()
401 { 398 {
402 if (!m_animator) 399 if (!m_animator)
403 m_animator = SVGAnimatedTypeAnimator::create(m_animatedPropertyType, thi s, targetElement()); 400 m_animator = SVGAnimatedTypeAnimator::create(this, targetElement());
404 ASSERT(m_animatedPropertyType == m_animator->type());
405 return m_animator.get(); 401 return m_animator.get();
406 } 402 }
407 403
408 void SVGAnimateElement::trace(Visitor* visitor) 404 void SVGAnimateElement::trace(Visitor* visitor)
409 { 405 {
410 visitor->trace(m_animator); 406 visitor->trace(m_animator);
411 SVGAnimationElement::trace(visitor); 407 SVGAnimationElement::trace(visitor);
412 } 408 }
413 409
414 } 410 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698