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

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

Issue 2287983002: Tighten SVGAnimationElement::shouldApplyAnimation (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/svg/SVGAnimationElement.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 } 171 }
172 172
173 void SVGAnimateElement::resetAnimatedType() 173 void SVGAnimateElement::resetAnimatedType()
174 { 174 {
175 SVGElement* targetElement = this->targetElement(); 175 SVGElement* targetElement = this->targetElement();
176 const QualifiedName& attributeName = this->attributeName(); 176 const QualifiedName& attributeName = this->attributeName();
177 177
178 m_animator.reset(targetElement); 178 m_animator.reset(targetElement);
179 179
180 ShouldApplyAnimationType shouldApply = shouldApplyAnimation(targetElement, a ttributeName); 180 ShouldApplyAnimationType shouldApply = shouldApplyAnimation(targetElement, a ttributeName);
181
182 if (shouldApply == DontApplyAnimation) 181 if (shouldApply == DontApplyAnimation)
183 return; 182 return;
184 if (shouldApply == ApplyXMLAnimation || shouldApply == ApplyXMLandCSSAnimati on) { 183 if (shouldApply == ApplyXMLAnimation || shouldApply == ApplyXMLandCSSAnimati on) {
185 // SVG DOM animVal animation code-path. 184 // SVG DOM animVal animation code-path.
186 SVGElementInstances animatedElements = findElementInstances(targetElemen t); 185 SVGElementInstances animatedElements = findElementInstances(targetElemen t);
187 ASSERT(!animatedElements.isEmpty()); 186 ASSERT(!animatedElements.isEmpty());
188 187
189 for (SVGElement* element : animatedElements) 188 for (SVGElement* element : animatedElements)
190 addReferenceTo(element); 189 addReferenceTo(element);
191 190
192 if (!m_animatedProperty) 191 if (!m_animatedProperty)
193 m_animatedProperty = m_animator.startAnimValAnimation(); 192 m_animatedProperty = m_animator.startAnimValAnimation();
194 else 193 else
195 m_animatedProperty = m_animator.resetAnimValToBaseVal(); 194 m_animatedProperty = m_animator.resetAnimValToBaseVal();
196 195
197 return; 196 return;
198 } 197 }
199 DCHECK_EQ(shouldApply, ApplyCSSAnimation); 198 DCHECK_EQ(shouldApply, ApplyCSSAnimation);
200 199
201 // CSS properties animation code-path. 200 // CSS properties animation code-path.
202 String baseValue; 201 String baseValue;
203 DCHECK(isTargetAttributeCSSProperty(targetElement, attributeName)); 202 DCHECK(isTargetAttributeCSSProperty(targetElement, attributeName));
204 computeCSSPropertyValue(targetElement, cssPropertyID(attributeName.localName ()), baseValue); 203 computeCSSPropertyValue(targetElement, cssPropertyID(attributeName.localName ()), baseValue);
205 204
206 m_animatedProperty = m_animator.constructFromString(baseValue); 205 m_animatedProperty = m_animator.constructFromString(baseValue);
207 } 206 }
208 207
209 static bool targetIsUsable(SVGElement* targetElement, const QualifiedName& attri bute)
210 {
211 return attribute != anyQName()
212 && targetElement->isConnected() && targetElement->parentNode();
213 }
214
215 void SVGAnimateElement::clearAnimatedType() 208 void SVGAnimateElement::clearAnimatedType()
216 { 209 {
217 if (!m_animatedProperty) 210 if (!m_animatedProperty)
218 return; 211 return;
219 212
220 // The animated property lock is held for the "result animation" (see SMILTi meContainer::updateAnimations()) 213 // The animated property lock is held for the "result animation" (see SMILTi meContainer::updateAnimations())
221 // while we're processing an animation group. We will very likely crash late r if we clear the animated type 214 // while we're processing an animation group. We will very likely crash late r if we clear the animated type
222 // while the lock is held. See crbug.com/581546. 215 // while the lock is held. See crbug.com/581546.
223 DCHECK(!animatedTypeIsLocked()); 216 DCHECK(!animatedTypeIsLocked());
224 217
225 SVGElement* targetElement = this->targetElement(); 218 SVGElement* targetElement = this->targetElement();
226 if (!targetElement) { 219 if (!targetElement) {
227 m_animatedProperty.clear(); 220 m_animatedProperty.clear();
228 return; 221 return;
229 } 222 }
230 223
231 ShouldApplyAnimationType shouldApply = shouldApplyAnimation(targetElement, a ttributeName()); 224 ShouldApplyAnimationType shouldApply = shouldApplyAnimation(targetElement, a ttributeName());
232 if (shouldApply == ApplyXMLandCSSAnimation || m_animator.isAnimatingCSSPrope rty()) { 225 if (shouldApply == ApplyXMLandCSSAnimation || m_animator.isAnimatingCSSPrope rty()) {
233 // CSS properties animation code-path. 226 // CSS properties animation code-path.
234 if (targetIsUsable(targetElement, attributeName())) { 227 if (shouldApply != DontApplyAnimation) {
235 CSSPropertyID id = cssPropertyID(attributeName().localName()); 228 CSSPropertyID id = cssPropertyID(attributeName().localName());
236 targetElement->ensureAnimatedSMILStyleProperties()->removeProperty(i d); 229 targetElement->ensureAnimatedSMILStyleProperties()->removeProperty(i d);
237 targetElement->setNeedsStyleRecalc(LocalStyleChange, StyleChangeReas onForTracing::create(StyleChangeReason::Animation)); 230 targetElement->setNeedsStyleRecalc(LocalStyleChange, StyleChangeReas onForTracing::create(StyleChangeReason::Animation));
238 } 231 }
239 } 232 }
240 if (shouldApply == ApplyXMLandCSSAnimation || m_animator.isAnimatingSVGDom() ) { 233 if (shouldApply == ApplyXMLandCSSAnimation || m_animator.isAnimatingSVGDom() ) {
241 // SVG DOM animVal animation code-path. 234 // SVG DOM animVal animation code-path.
242 m_animator.stopAnimValAnimation(); 235 m_animator.stopAnimValAnimation();
243 if (targetIsUsable(targetElement, attributeName())) 236 if (shouldApply != DontApplyAnimation)
244 targetElement->invalidateAnimatedAttribute(attributeName()); 237 targetElement->invalidateAnimatedAttribute(attributeName());
245 } 238 }
246 239
247 m_animatedProperty.clear(); 240 m_animatedProperty.clear();
248 m_animator.clear(); 241 m_animator.clear();
249 } 242 }
250 243
251 void SVGAnimateElement::applyResultsToTarget() 244 void SVGAnimateElement::applyResultsToTarget()
252 { 245 {
253 ASSERT(animatedPropertyType() != AnimatedTransformList || isSVGAnimateTransf ormElement(*this)); 246 ASSERT(animatedPropertyType() != AnimatedTransformList || isSVGAnimateTransf ormElement(*this));
254 ASSERT(animatedPropertyType() != AnimatedUnknown); 247 ASSERT(animatedPropertyType() != AnimatedUnknown);
255 248
256 // Early exit if our animated type got destructed by a previous endedActiveI nterval(). 249 // Early exit if our animated type got destructed by a previous endedActiveI nterval().
257 if (!m_animatedProperty) 250 if (!m_animatedProperty)
258 return; 251 return;
259 252
260 // We do update the style and the animation property independent of each oth er. 253 // We do update the style and the animation property independent of each oth er.
261 ShouldApplyAnimationType shouldApply = shouldApplyAnimation(targetElement(), attributeName()); 254 ShouldApplyAnimationType shouldApply = shouldApplyAnimation(targetElement(), attributeName());
262 DCHECK(targetElement()); 255 if (shouldApply == DontApplyAnimation)
263 if (!targetIsUsable(targetElement(), attributeName()))
264 return; 256 return;
265 if (shouldApply == ApplyXMLandCSSAnimation || m_animator.isAnimatingCSSPrope rty()) { 257 if (shouldApply == ApplyXMLandCSSAnimation || m_animator.isAnimatingCSSPrope rty()) {
266 // CSS properties animation code-path. 258 // CSS properties animation code-path.
267 // Convert the result of the animation to a String and apply it as CSS p roperty on the target. 259 // Convert the result of the animation to a String and apply it as CSS p roperty on the target.
268 CSSPropertyID id = cssPropertyID(attributeName().localName()); 260 CSSPropertyID id = cssPropertyID(attributeName().localName());
269 MutableStylePropertySet* propertySet = targetElement()->ensureAnimatedSM ILStyleProperties(); 261 MutableStylePropertySet* propertySet = targetElement()->ensureAnimatedSM ILStyleProperties();
270 if (propertySet->setProperty(id, m_animatedProperty->valueAsString(), fa lse, 0)) 262 if (propertySet->setProperty(id, m_animatedProperty->valueAsString(), fa lse, 0))
271 targetElement()->setNeedsStyleRecalc(LocalStyleChange, StyleChangeRe asonForTracing::create(StyleChangeReason::Animation)); 263 targetElement()->setNeedsStyleRecalc(LocalStyleChange, StyleChangeRe asonForTracing::create(StyleChangeReason::Animation));
272 } 264 }
273 if (shouldApply == ApplyXMLandCSSAnimation || m_animator.isAnimatingSVGDom() ) { 265 if (shouldApply == ApplyXMLandCSSAnimation || m_animator.isAnimatingSVGDom() ) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 { 330 {
339 visitor->trace(m_fromProperty); 331 visitor->trace(m_fromProperty);
340 visitor->trace(m_toProperty); 332 visitor->trace(m_toProperty);
341 visitor->trace(m_toAtEndOfDurationProperty); 333 visitor->trace(m_toAtEndOfDurationProperty);
342 visitor->trace(m_animatedProperty); 334 visitor->trace(m_animatedProperty);
343 visitor->trace(m_animator); 335 visitor->trace(m_animator);
344 SVGAnimationElement::trace(visitor); 336 SVGAnimationElement::trace(visitor);
345 } 337 }
346 338
347 } // namespace blink 339 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/svg/SVGAnimationElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698