Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "core/SVGNames.h" | 8 #include "core/SVGNames.h" |
| 8 #include "core/css/CSSValueList.h" | 9 #include "core/css/CSSValueList.h" |
| 9 #include "core/css/parser/CSSParser.h" | 10 #include "core/css/parser/CSSParser.h" |
| 10 #include "core/css/resolver/CSSToStyleMap.h" | 11 #include "core/css/resolver/CSSToStyleMap.h" |
| 11 #include "core/frame/Deprecation.h" | 12 #include "core/frame/Deprecation.h" |
| 12 #include "core/svg/SVGElement.h" | 13 #include "core/svg/SVGElement.h" |
| 13 #include "core/svg/animation/SVGSMILElement.h" | 14 #include "core/svg/animation/SVGSMILElement.h" |
| 14 #include "wtf/text/StringBuilder.h" | 15 #include "wtf/text/StringBuilder.h" |
| 15 | 16 |
| 16 namespace blink { | 17 namespace blink { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 String unprefixedProperty = removeSVGPrefix(property); | 196 String unprefixedProperty = removeSVGPrefix(property); |
| 196 QualifiedName attributeName = svgAttributeName(unprefixedProperty); | 197 QualifiedName attributeName = svgAttributeName(unprefixedProperty); |
| 197 const AttributeNameMap& supportedAttributes = getSupportedAttributes(); | 198 const AttributeNameMap& supportedAttributes = getSupportedAttributes(); |
| 198 auto iter = supportedAttributes.find(attributeName); | 199 auto iter = supportedAttributes.find(attributeName); |
| 199 if (iter == supportedAttributes.end() || !svgElement.propertyFromAttribute(* iter->value)) | 200 if (iter == supportedAttributes.end() || !svgElement.propertyFromAttribute(* iter->value)) |
| 200 return nullptr; | 201 return nullptr; |
| 201 | 202 |
| 202 return iter->value; | 203 return iter->value; |
| 203 } | 204 } |
| 204 | 205 |
| 205 PassRefPtr<TimingFunction> AnimationInputHelpers::parseTimingFunction(const Stri ng& string, Document* document) | 206 PassRefPtr<TimingFunction> AnimationInputHelpers::parseTimingFunction(const Stri ng& string, Document* document, ExceptionState& exceptionState) |
| 206 { | 207 { |
| 207 if (string.isEmpty()) | 208 if (string.isEmpty()) { |
| 209 exceptionState.throwTypeError("Easing may not be the empty string"); | |
| 208 return nullptr; | 210 return nullptr; |
| 211 } | |
| 209 | 212 |
| 210 CSSValue* value = CSSParser::parseSingleValue(CSSPropertyTransitionTimingFun ction, string); | 213 CSSValue* value = CSSParser::parseSingleValue(CSSPropertyTransitionTimingFun ction, string); |
| 211 if (!value || !value->isValueList()) { | 214 if (!value || !value->isValueList()) { |
| 212 ASSERT(!value || value->isCSSWideKeyword()); | 215 ASSERT(!value || value->isCSSWideKeyword()); |
| 216 bool throwTypeError = true; | |
| 213 if (document) { | 217 if (document) { |
| 214 if (string.startsWith("function")) { | 218 if (string.startsWith("function")) { |
| 215 // 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 |
| 216 // polyfill, in some circumstances the string passed in here | 220 // polyfill, in some circumstances the string passed in here |
| 217 // may be a Javascript function instead of the allowed values | 221 // may be a Javascript function instead of the allowed values |
| 218 // from the spec | 222 // from the spec |
| 219 // (http://w3c.github.io/web-animations/#dom-animationeffecttimi ngreadonly-easing) | 223 // (http://w3c.github.io/web-animations/#dom-animationeffecttimi ngreadonly-easing) |
| 220 // This bug was fixed in | 224 // This bug was fixed in |
| 221 // https://github.com/web-animations/web-animations-next/pull/42 3 | 225 // https://github.com/web-animations/web-animations-next/pull/42 3 |
| 222 // 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 |
| 223 // linear case is special because 'linear' is the default value | 227 // linear case is special because 'linear' is the default value |
| 224 // for easing. | 228 // for easing. See http://crbug.com/601672 |
| 225 if (string == "function (a){return a}") | 229 if (string == "function (a){return a}") { |
| 226 UseCounter::count(*document, UseCounter::WebAnimationsEasing AsFunctionLinear); | 230 Deprecation::countDeprecation(*document, UseCounter::WebAnim ationsEasingAsFunctionLinear); |
| 227 else | 231 throwTypeError = false; |
| 232 } else { | |
| 228 UseCounter::count(*document, UseCounter::WebAnimationsEasing AsFunctionOther); | 233 UseCounter::count(*document, UseCounter::WebAnimationsEasing AsFunctionOther); |
| 234 } | |
| 229 } | 235 } |
| 230 } | 236 } |
| 237 if (throwTypeError) { | |
| 238 // TODO(suzyh): This throwTypeError guard and default return value | |
| 239 // exists so that the special linear function case above is exempted | |
| 240 // from causing TypeErrors. The bool and guard should be removed | |
| 241 // after the M53 branch point in July 2016, so that this case will | |
| 242 // also throw TypeErrors from M54 onward. | |
| 243 exceptionState.throwTypeError("'" + string + "' is not a valid value for easing"); | |
| 244 } else { | |
| 245 return Timing::defaults().timingFunction; | |
| 246 } | |
| 231 return nullptr; | 247 return nullptr; |
|
alancutter (OOO until 2018)
2016/04/13 00:46:38
Nit: Blink style is to arrange this as:
if (throw
suzyh_UTC10 (ex-contributor)
2016/04/13 01:48:09
I was trying to keep the temporary code all togeth
| |
| 232 } | 248 } |
| 233 CSSValueList* valueList = toCSSValueList(value); | 249 CSSValueList* valueList = toCSSValueList(value); |
| 234 if (valueList->length() > 1) | 250 if (valueList->length() > 1) { |
| 251 exceptionState.throwTypeError("Easing may not be set to a list of values "); | |
| 235 return nullptr; | 252 return nullptr; |
| 253 } | |
| 236 return CSSToStyleMap::mapAnimationTimingFunction(*valueList->item(0), true); | 254 return CSSToStyleMap::mapAnimationTimingFunction(*valueList->item(0), true); |
| 237 } | 255 } |
| 238 | 256 |
| 239 } // namespace blink | 257 } // namespace blink |
| OLD | NEW |