| 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 |
| 238 // TODO(suzyh): This return clause exists so that the special linear |
| 239 // function case above is exempted from causing TypeErrors. The |
| 240 // 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 |
| 242 // TypeErrors from M54 onward. |
| 243 if (!throwTypeError) { |
| 244 return Timing::defaults().timingFunction; |
| 245 } |
| 246 |
| 247 exceptionState.throwTypeError("'" + string + "' is not a valid value for
easing"); |
| 231 return nullptr; | 248 return nullptr; |
| 232 } | 249 } |
| 233 CSSValueList* valueList = toCSSValueList(value); | 250 CSSValueList* valueList = toCSSValueList(value); |
| 234 if (valueList->length() > 1) | 251 if (valueList->length() > 1) { |
| 252 exceptionState.throwTypeError("Easing may not be set to a list of values
"); |
| 235 return nullptr; | 253 return nullptr; |
| 254 } |
| 236 return CSSToStyleMap::mapAnimationTimingFunction(*valueList->item(0), true); | 255 return CSSToStyleMap::mapAnimationTimingFunction(*valueList->item(0), true); |
| 237 } | 256 } |
| 238 | 257 |
| 239 } // namespace blink | 258 } // namespace blink |
| OLD | NEW |