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

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

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

Powered by Google App Engine
This is Rietveld 408576698