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

Side by Side Diff: third_party/WebKit/Source/core/animation/AnimationInputHelpers.cpp

Issue 2047293002: Code cleanup: Replace Element with Document in element.animate() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@_killForceConversionsToAnimatableValues
Patch Set: Fix unit test crash. Created 4 years, 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/animation/AnimationInputHelpers.h" 5 #include "core/animation/AnimationInputHelpers.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "core/SVGNames.h" 8 #include "core/SVGNames.h"
9 #include "core/css/CSSValueList.h" 9 #include "core/css/CSSValueList.h"
10 #include "core/css/parser/CSSParser.h" 10 #include "core/css/parser/CSSParser.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 Deprecation::countDeprecation(document, UseCounter::WebAnimation HyphenatedProperty); 46 Deprecation::countDeprecation(document, UseCounter::WebAnimation HyphenatedProperty);
47 return CSSPropertyInvalid; 47 return CSSPropertyInvalid;
48 } 48 }
49 if (isASCIIUpper(property[i])) 49 if (isASCIIUpper(property[i]))
50 builder.append('-'); 50 builder.append('-');
51 builder.append(property[i]); 51 builder.append(property[i]);
52 } 52 }
53 return cssPropertyID(builder.toString()); 53 return cssPropertyID(builder.toString());
54 } 54 }
55 55
56 CSSPropertyID AnimationInputHelpers::keyframeAttributeToPresentationAttribute(co nst String& property, const Element& element) 56 CSSPropertyID AnimationInputHelpers::keyframeAttributeToPresentationAttribute(co nst String& property)
57 { 57 {
58 if (!RuntimeEnabledFeatures::webAnimationsSVGEnabled() || !element.isSVGElem ent() || !isSVGPrefixed(property)) 58 if (!RuntimeEnabledFeatures::webAnimationsSVGEnabled() || !isSVGPrefixed(pro perty))
59 return CSSPropertyInvalid; 59 return CSSPropertyInvalid;
60 60
61 String unprefixedProperty = removeSVGPrefix(property); 61 String unprefixedProperty = removeSVGPrefix(property);
62 if (SVGElement::isAnimatableCSSProperty(QualifiedName(nullAtom, AtomicString (unprefixedProperty), nullAtom))) 62 if (SVGElement::isAnimatableCSSProperty(QualifiedName(nullAtom, AtomicString (unprefixedProperty), nullAtom)))
63 return cssPropertyID(unprefixedProperty); 63 return cssPropertyID(unprefixedProperty);
64 64
65 return CSSPropertyInvalid; 65 return CSSPropertyInvalid;
66 } 66 }
67 67
68 using AttributeNameMap = HashMap<QualifiedName, const QualifiedName*>; 68 using AttributeNameMap = HashMap<QualifiedName, const QualifiedName*>;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 } 177 }
178 return supportedAttributes; 178 return supportedAttributes;
179 } 179 }
180 180
181 QualifiedName svgAttributeName(const String& property) 181 QualifiedName svgAttributeName(const String& property)
182 { 182 {
183 ASSERT(!isSVGPrefixed(property)); 183 ASSERT(!isSVGPrefixed(property));
184 return QualifiedName(nullAtom, AtomicString(property), nullAtom); 184 return QualifiedName(nullAtom, AtomicString(property), nullAtom);
185 } 185 }
186 186
187 const QualifiedName* AnimationInputHelpers::keyframeAttributeToSVGAttribute(cons t String& property, Element& element) 187 const QualifiedName* AnimationInputHelpers::keyframeAttributeToSVGAttribute(cons t String& property)
188 { 188 {
189 if (!RuntimeEnabledFeatures::webAnimationsSVGEnabled() || !element.isSVGElem ent() || !isSVGPrefixed(property)) 189 if (!RuntimeEnabledFeatures::webAnimationsSVGEnabled() || !isSVGPrefixed(pro perty))
190 return nullptr;
191
192 SVGElement& svgElement = toSVGElement(element);
193 if (isSVGSMILElement(svgElement))
194 return nullptr; 190 return nullptr;
195 191
196 String unprefixedProperty = removeSVGPrefix(property); 192 String unprefixedProperty = removeSVGPrefix(property);
197 QualifiedName attributeName = svgAttributeName(unprefixedProperty); 193 QualifiedName attributeName = svgAttributeName(unprefixedProperty);
198 const AttributeNameMap& supportedAttributes = getSupportedAttributes(); 194 const AttributeNameMap& supportedAttributes = getSupportedAttributes();
199 auto iter = supportedAttributes.find(attributeName); 195 auto iter = supportedAttributes.find(attributeName);
200 if (iter == supportedAttributes.end() || !svgElement.propertyFromAttribute(* iter->value)) 196 if (iter == supportedAttributes.end())
201 return nullptr; 197 return nullptr;
202 198
203 return iter->value; 199 return iter->value;
204 } 200 }
205 201
206 PassRefPtr<TimingFunction> AnimationInputHelpers::parseTimingFunction(const Stri ng& string, Document* document, ExceptionState& exceptionState) 202 PassRefPtr<TimingFunction> AnimationInputHelpers::parseTimingFunction(const Stri ng& string, Document& document, ExceptionState& exceptionState)
207 { 203 {
208 if (string.isEmpty()) { 204 if (string.isEmpty()) {
209 exceptionState.throwTypeError("Easing may not be the empty string"); 205 exceptionState.throwTypeError("Easing may not be the empty string");
210 return nullptr; 206 return nullptr;
211 } 207 }
212 208
213 CSSValue* value = CSSParser::parseSingleValue(CSSPropertyTransitionTimingFun ction, string); 209 CSSValue* value = CSSParser::parseSingleValue(CSSPropertyTransitionTimingFun ction, string);
214 if (!value || !value->isValueList()) { 210 if (!value || !value->isValueList()) {
215 ASSERT(!value || value->isCSSWideKeyword()); 211 ASSERT(!value || value->isCSSWideKeyword());
216 bool throwTypeError = true; 212 bool throwTypeError = true;
217 if (document) { 213 if (string.startsWith("function")) {
218 if (string.startsWith("function")) { 214 // Due to a bug in old versions of the web-animations-next
219 // Due to a bug in old versions of the web-animations-next 215 // polyfill, in some circumstances the string passed in here
220 // polyfill, in some circumstances the string passed in here 216 // may be a Javascript function instead of the allowed values
221 // may be a Javascript function instead of the allowed values 217 // from the spec
222 // from the spec 218 // (http://w3c.github.io/web-animations/#dom-animationeffecttimingre adonly-easing)
223 // (http://w3c.github.io/web-animations/#dom-animationeffecttimi ngreadonly-easing) 219 // This bug was fixed in
224 // This bug was fixed in 220 // https://github.com/web-animations/web-animations-next/pull/423
225 // https://github.com/web-animations/web-animations-next/pull/42 3 221 // and we want to track how often it is still being hit. The
226 // and we want to track how often it is still being hit. The 222 // linear case is special because 'linear' is the default value
227 // linear case is special because 'linear' is the default value 223 // for easing. See http://crbug.com/601672
228 // for easing. See http://crbug.com/601672 224 if (string == "function (a){return a}") {
229 if (string == "function (a){return a}") { 225 Deprecation::countDeprecation(document, UseCounter::WebAnimation sEasingAsFunctionLinear);
230 Deprecation::countDeprecation(*document, UseCounter::WebAnim ationsEasingAsFunctionLinear); 226 throwTypeError = false;
231 throwTypeError = false; 227 } else {
232 } else { 228 UseCounter::count(document, UseCounter::WebAnimationsEasingAsFun ctionOther);
233 UseCounter::count(*document, UseCounter::WebAnimationsEasing AsFunctionOther);
234 }
235 } 229 }
236 } 230 }
237 231
238 // TODO(suzyh): This return clause exists so that the special linear 232 // TODO(suzyh): This return clause exists so that the special linear
239 // function case above is exempted from causing TypeErrors. The 233 // function case above is exempted from causing TypeErrors. The
240 // throwTypeError bool and this if-statement should be removed after the 234 // throwTypeError bool and this if-statement should be removed after the
241 // M53 branch point in July 2016, so that this case will also throw 235 // M53 branch point in July 2016, so that this case will also throw
242 // TypeErrors from M54 onward. 236 // TypeErrors from M54 onward.
243 if (!throwTypeError) { 237 if (!throwTypeError) {
244 return Timing::defaults().timingFunction; 238 return Timing::defaults().timingFunction;
245 } 239 }
246 240
247 exceptionState.throwTypeError("'" + string + "' is not a valid value for easing"); 241 exceptionState.throwTypeError("'" + string + "' is not a valid value for easing");
248 return nullptr; 242 return nullptr;
249 } 243 }
250 CSSValueList* valueList = toCSSValueList(value); 244 CSSValueList* valueList = toCSSValueList(value);
251 if (valueList->length() > 1) { 245 if (valueList->length() > 1) {
252 exceptionState.throwTypeError("Easing may not be set to a list of values "); 246 exceptionState.throwTypeError("Easing may not be set to a list of values ");
253 return nullptr; 247 return nullptr;
254 } 248 }
255 return CSSToStyleMap::mapAnimationTimingFunction(valueList->item(0), true); 249 return CSSToStyleMap::mapAnimationTimingFunction(valueList->item(0), true);
256 } 250 }
257 251
258 } // namespace blink 252 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698