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