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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 | 78 |
79 bool SVGAnimateElement::hasValidAttributeType() | 79 bool SVGAnimateElement::hasValidAttributeType() |
80 { | 80 { |
81 SVGElement* targetElement = this->targetElement(); | 81 SVGElement* targetElement = this->targetElement(); |
82 if (!targetElement) | 82 if (!targetElement) |
83 return false; | 83 return false; |
84 | 84 |
85 return animatedPropertyType() != AnimatedUnknown && !hasInvalidCSSAttributeT ype(); | 85 return animatedPropertyType() != AnimatedUnknown && !hasInvalidCSSAttributeT ype(); |
86 } | 86 } |
87 | 87 |
88 namespace { | |
89 | |
90 class ParsePropertyFromString { | |
91 STACK_ALLOCATED(); | |
92 public: | |
93 explicit ParsePropertyFromString(SVGAnimatedTypeAnimator* animator) | |
94 : m_animator(animator) | |
95 { | |
96 } | |
97 | |
98 SVGPropertyBase* operator()(SVGAnimationElement*, const String& value) | |
99 { | |
100 return m_animator->createPropertyForAnimation(value); | |
101 } | |
102 | |
103 private: | |
104 SVGAnimatedTypeAnimator* m_animator; | |
105 }; | |
106 | |
107 } | |
108 | |
88 void SVGAnimateElement::calculateAnimatedValue(float percentage, unsigned repeat Count, SVGSMILElement* resultElement) | 109 void SVGAnimateElement::calculateAnimatedValue(float percentage, unsigned repeat Count, SVGSMILElement* resultElement) |
89 { | 110 { |
90 ASSERT(resultElement); | 111 ASSERT(resultElement); |
91 SVGElement* targetElement = this->targetElement(); | 112 SVGElement* targetElement = this->targetElement(); |
92 if (!targetElement || !isSVGAnimateElement(*resultElement)) | 113 if (!targetElement || !isSVGAnimateElement(*resultElement)) |
93 return; | 114 return; |
94 | 115 |
95 ASSERT(percentage >= 0 && percentage <= 1); | 116 ASSERT(percentage >= 0 && percentage <= 1); |
96 ASSERT(animatedPropertyType() != AnimatedTransformList || isSVGAnimateTransf ormElement(*this)); | 117 ASSERT(animatedPropertyType() != AnimatedTransformList || isSVGAnimateTransf ormElement(*this)); |
97 ASSERT(animatedPropertyType() != AnimatedUnknown); | 118 ASSERT(animatedPropertyType() != AnimatedUnknown); |
98 ASSERT(m_fromProperty); | 119 ASSERT(m_fromProperty); |
99 ASSERT(m_fromProperty->type() == animatedPropertyType()); | 120 ASSERT(m_fromProperty->type() == animatedPropertyType()); |
100 ASSERT(m_toProperty); | 121 ASSERT(m_toProperty); |
101 | 122 |
102 SVGAnimateElement* resultAnimationElement = toSVGAnimateElement(resultElemen t); | 123 SVGAnimateElement* resultAnimationElement = toSVGAnimateElement(resultElemen t); |
103 ASSERT(resultAnimationElement->m_animatedProperty); | 124 ASSERT(resultAnimationElement->m_animatedProperty); |
104 ASSERT(resultAnimationElement->animatedPropertyType() == animatedPropertyTyp e()); | 125 ASSERT(resultAnimationElement->animatedPropertyType() == animatedPropertyTyp e()); |
105 | 126 |
106 if (isSVGSetElement(*this)) | 127 if (isSVGSetElement(*this)) |
107 percentage = 1; | 128 percentage = 1; |
108 | 129 |
109 if (getCalcMode() == CalcModeDiscrete) | 130 if (getCalcMode() == CalcModeDiscrete) |
110 percentage = percentage < 0.5 ? 0 : 1; | 131 percentage = percentage < 0.5 ? 0 : 1; |
111 | 132 |
112 // Target element might have changed. | 133 // Target element might have changed. |
113 m_animator.setContextElement(targetElement); | 134 m_animator.setContextElement(targetElement); |
114 | 135 |
115 // Values-animation accumulates using the last values entry corresponding to the end of duration time. | 136 // Values-animation accumulates using the last values entry corresponding to |
116 SVGPropertyBase* toAtEndOfDurationProperty = m_toAtEndOfDurationProperty ? m _toAtEndOfDurationProperty.get() : m_toProperty.get(); | 137 // the end of duration time. |
117 m_animator.calculateAnimatedValue(percentage, repeatCount, m_fromProperty.ge t(), m_toProperty.get(), toAtEndOfDurationProperty, resultAnimationElement->m_an imatedProperty.get()); | 138 SVGPropertyBase* animatedValue = resultAnimationElement->m_animatedProperty; |
139 SVGPropertyBase* toAtEndOfDurationValue = | |
140 m_toAtEndOfDurationProperty ? m_toAtEndOfDurationProperty : m_toProperty ; | |
141 SVGPropertyBase* fromValue = | |
142 getAnimationMode() == ToAnimation ? animatedValue : m_fromProperty.get() ; | |
143 SVGPropertyBase* toValue = m_toProperty; | |
144 | |
145 // Apply CSS inheritance rules. | |
146 ParsePropertyFromString parsePropertyFromString(&m_animator); | |
147 adjustForInheritance<SVGPropertyBase*, ParsePropertyFromString>( | |
pdr.
2016/09/30 19:32:19
These are the only users of ParsePropertyFromStrin
fs
2016/09/30 19:39:07
You're way ahead of me it seems ;-) - that was goi
| |
148 parsePropertyFromString, fromPropertyValueType(), fromValue, targetEleme nt); | |
149 adjustForInheritance<SVGPropertyBase*, ParsePropertyFromString>( | |
150 parsePropertyFromString, toPropertyValueType(), toValue, targetElement); | |
151 | |
152 animatedValue->calculateAnimatedValue( | |
153 this, percentage, repeatCount, fromValue, toValue, toAtEndOfDurationValu e, targetElement); | |
118 } | 154 } |
119 | 155 |
120 bool SVGAnimateElement::calculateToAtEndOfDurationValue(const String& toAtEndOfD urationString) | 156 bool SVGAnimateElement::calculateToAtEndOfDurationValue(const String& toAtEndOfD urationString) |
121 { | 157 { |
122 if (toAtEndOfDurationString.isEmpty()) | 158 if (toAtEndOfDurationString.isEmpty()) |
123 return false; | 159 return false; |
124 m_toAtEndOfDurationProperty = m_animator.createAnimatedValueFromString(toAtE ndOfDurationString); | 160 m_toAtEndOfDurationProperty = m_animator.createPropertyForAnimation(toAtEndO fDurationString); |
125 return true; | 161 return true; |
126 } | 162 } |
127 | 163 |
128 bool SVGAnimateElement::calculateFromAndToValues(const String& fromString, const String& toString) | 164 bool SVGAnimateElement::calculateFromAndToValues(const String& fromString, const String& toString) |
129 { | 165 { |
130 SVGElement* targetElement = this->targetElement(); | 166 SVGElement* targetElement = this->targetElement(); |
131 if (!targetElement) | 167 if (!targetElement) |
132 return false; | 168 return false; |
133 | 169 |
134 determinePropertyValueTypes(fromString, toString); | 170 determinePropertyValueTypes(fromString, toString); |
135 m_animator.calculateFromAndToValues(m_fromProperty, m_toProperty, fromString , toString); | 171 m_fromProperty = m_animator.createPropertyForAnimation(fromString); |
172 m_toProperty = m_animator.createPropertyForAnimation(toString); | |
136 return true; | 173 return true; |
137 } | 174 } |
138 | 175 |
139 bool SVGAnimateElement::calculateFromAndByValues(const String& fromString, const String& byString) | 176 bool SVGAnimateElement::calculateFromAndByValues(const String& fromString, const String& byString) |
140 { | 177 { |
141 SVGElement* targetElement = this->targetElement(); | 178 SVGElement* targetElement = this->targetElement(); |
142 if (!targetElement) | 179 if (!targetElement) |
143 return false; | 180 return false; |
144 | 181 |
145 if (getAnimationMode() == ByAnimation && !isAdditive()) | 182 if (getAnimationMode() == ByAnimation && !isAdditive()) |
146 return false; | 183 return false; |
147 | 184 |
148 // from-by animation may only be used with attributes that support addition (e.g. most numeric attributes). | 185 // from-by animation may only be used with attributes that support addition (e.g. most numeric attributes). |
149 if (getAnimationMode() == FromByAnimation && !animatedPropertyTypeSupportsAd dition()) | 186 if (getAnimationMode() == FromByAnimation && !animatedPropertyTypeSupportsAd dition()) |
150 return false; | 187 return false; |
151 | 188 |
152 ASSERT(!isSVGSetElement(*this)); | 189 ASSERT(!isSVGSetElement(*this)); |
153 | 190 |
154 determinePropertyValueTypes(fromString, byString); | 191 determinePropertyValueTypes(fromString, byString); |
155 m_animator.calculateFromAndByValues(m_fromProperty, m_toProperty, fromString , byString); | 192 m_fromProperty = m_animator.createPropertyForAnimation(fromString); |
193 m_toProperty = m_animator.createPropertyForAnimation(byString); | |
194 m_toProperty->add(m_fromProperty, targetElement); | |
156 return true; | 195 return true; |
157 } | 196 } |
158 | 197 |
159 void SVGAnimateElement::resetAnimatedType() | 198 void SVGAnimateElement::resetAnimatedType() |
160 { | 199 { |
161 SVGElement* targetElement = this->targetElement(); | 200 SVGElement* targetElement = this->targetElement(); |
162 const QualifiedName& attributeName = this->attributeName(); | 201 const QualifiedName& attributeName = this->attributeName(); |
163 | 202 |
164 m_animator.reset(targetElement); | 203 m_animator.reset(targetElement); |
165 | 204 |
166 ShouldApplyAnimationType shouldApply = shouldApplyAnimation(targetElement, a ttributeName); | 205 ShouldApplyAnimationType shouldApply = shouldApplyAnimation(targetElement, a ttributeName); |
167 if (shouldApply == DontApplyAnimation) | 206 if (shouldApply == DontApplyAnimation) |
168 return; | 207 return; |
169 if (shouldApply == ApplyXMLAnimation || shouldApply == ApplyXMLandCSSAnimati on) { | 208 if (shouldApply == ApplyXMLAnimation || shouldApply == ApplyXMLandCSSAnimati on) { |
170 // SVG DOM animVal animation code-path. | 209 // SVG DOM animVal animation code-path. |
171 m_animatedProperty = m_animator.createAnimatedValue(); | 210 m_animatedProperty = m_animator.createAnimatedValue(); |
172 targetElement->setAnimatedAttribute(attributeName, m_animatedProperty); | 211 targetElement->setAnimatedAttribute(attributeName, m_animatedProperty); |
173 return; | 212 return; |
174 } | 213 } |
175 DCHECK_EQ(shouldApply, ApplyCSSAnimation); | 214 DCHECK_EQ(shouldApply, ApplyCSSAnimation); |
176 | 215 |
177 // CSS properties animation code-path. | 216 // CSS properties animation code-path. |
178 String baseValue; | 217 String baseValue; |
179 DCHECK(isTargetAttributeCSSProperty(targetElement, attributeName)); | 218 DCHECK(isTargetAttributeCSSProperty(targetElement, attributeName)); |
180 computeCSSPropertyValue(targetElement, cssPropertyID(attributeName.localName ()), baseValue); | 219 computeCSSPropertyValue(targetElement, cssPropertyID(attributeName.localName ()), baseValue); |
181 | 220 |
182 m_animatedProperty = m_animator.createAnimatedValueFromString(baseValue); | 221 m_animatedProperty = m_animator.createPropertyForAnimation(baseValue); |
183 } | 222 } |
184 | 223 |
185 void SVGAnimateElement::clearAnimatedType() | 224 void SVGAnimateElement::clearAnimatedType() |
186 { | 225 { |
187 if (!m_animatedProperty) | 226 if (!m_animatedProperty) |
188 return; | 227 return; |
189 | 228 |
190 // The animated property lock is held for the "result animation" (see SMILTi meContainer::updateAnimations()) | 229 // The animated property lock is held for the "result animation" (see SMILTi meContainer::updateAnimations()) |
191 // while we're processing an animation group. We will very likely crash late r if we clear the animated type | 230 // while we're processing an animation group. We will very likely crash late r if we clear the animated type |
192 // while the lock is held. See crbug.com/581546. | 231 // while the lock is held. See crbug.com/581546. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 | 310 |
272 return SVGAnimationElement::isAdditive(); | 311 return SVGAnimationElement::isAdditive(); |
273 } | 312 } |
274 | 313 |
275 float SVGAnimateElement::calculateDistance(const String& fromString, const Strin g& toString) | 314 float SVGAnimateElement::calculateDistance(const String& fromString, const Strin g& toString) |
276 { | 315 { |
277 // FIXME: A return value of float is not enough to support paced animations on lists. | 316 // FIXME: A return value of float is not enough to support paced animations on lists. |
278 SVGElement* targetElement = this->targetElement(); | 317 SVGElement* targetElement = this->targetElement(); |
279 if (!targetElement) | 318 if (!targetElement) |
280 return -1; | 319 return -1; |
281 | 320 SVGPropertyBase* fromValue = m_animator.createPropertyForAnimation(fromStrin g); |
282 return m_animator.calculateDistance(fromString, toString); | 321 SVGPropertyBase* toValue = m_animator.createPropertyForAnimation(toString); |
322 return fromValue->calculateDistance(toValue, targetElement); | |
283 } | 323 } |
284 | 324 |
285 void SVGAnimateElement::setTargetElement(SVGElement* target) | 325 void SVGAnimateElement::setTargetElement(SVGElement* target) |
286 { | 326 { |
287 SVGAnimationElement::setTargetElement(target); | 327 SVGAnimationElement::setTargetElement(target); |
288 resetAnimatedPropertyType(); | 328 resetAnimatedPropertyType(); |
289 } | 329 } |
290 | 330 |
291 void SVGAnimateElement::setAttributeName(const QualifiedName& attributeName) | 331 void SVGAnimateElement::setAttributeName(const QualifiedName& attributeName) |
292 { | 332 { |
(...skipping 14 matching lines...) Expand all Loading... | |
307 { | 347 { |
308 visitor->trace(m_fromProperty); | 348 visitor->trace(m_fromProperty); |
309 visitor->trace(m_toProperty); | 349 visitor->trace(m_toProperty); |
310 visitor->trace(m_toAtEndOfDurationProperty); | 350 visitor->trace(m_toAtEndOfDurationProperty); |
311 visitor->trace(m_animatedProperty); | 351 visitor->trace(m_animatedProperty); |
312 visitor->trace(m_animator); | 352 visitor->trace(m_animator); |
313 SVGAnimationElement::trace(visitor); | 353 SVGAnimationElement::trace(visitor); |
314 } | 354 } |
315 | 355 |
316 } // namespace blink | 356 } // namespace blink |
OLD | NEW |