[CSS Parser] Support the spring animation timing function
authorhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Nov 2016 23:04:55 +0000 (23:04 +0000)
committerhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Nov 2016 23:04:55 +0000 (23:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=164654

Reviewed by Dean Jackson.

* css/CSSValueKeywords.in:
* css/parser/CSSPropertyParser.cpp:
(WebCore::consumeSpringFunction):
(WebCore::consumeAnimationTimingFunction):
(WebCore::consumeAnimationValue):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208615 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/css/CSSValueKeywords.in
Source/WebCore/css/parser/CSSPropertyParser.cpp

index e5fbd33..e9e7d64 100644 (file)
@@ -1,3 +1,16 @@
+2016-11-11  Dave Hyatt  <hyatt@apple.com>
+
+        [CSS Parser] Support the spring animation timing function
+        https://bugs.webkit.org/show_bug.cgi?id=164654
+
+        Reviewed by Dean Jackson.
+
+        * css/CSSValueKeywords.in:
+        * css/parser/CSSPropertyParser.cpp:
+        (WebCore::consumeSpringFunction):
+        (WebCore::consumeAnimationTimingFunction):
+        (WebCore::consumeAnimationValue):
+
 2016-11-11  Chris Dumez  <cdumez@apple.com>
 
         WorkerGlobalScope's indexedDB property should be on the prototype, not the instance
index 19a6af5..c1c052a 100644 (file)
@@ -1199,6 +1199,7 @@ blur
 drop-shadow
 url
 cubic-bezier
+spring
 steps
 
 // colors
index 7cb1e7d..9a9deea 100644 (file)
@@ -1183,7 +1183,41 @@ static RefPtr<CSSValue> consumeCubicBezier(CSSParserTokenRange& range)
     return nullptr;
 }
 
-static RefPtr<CSSValue> consumeAnimationTimingFunction(CSSParserTokenRange& range)
+static RefPtr<CSSValue> consumeSpringFunction(CSSParserTokenRange& range)
+{
+    ASSERT(range.peek().functionId() == CSSValueSpring);
+    CSSParserTokenRange rangeCopy = range;
+    CSSParserTokenRange args = consumeFunction(rangeCopy);
+
+    // Mass must be greater than 0.
+    double mass;
+    if (!consumeNumberRaw(args, mass) || mass <= 0)
+        return nullptr;
+    
+    // Stiffness must be greater than 0.
+    double stiffness;
+    if (!consumeNumberRaw(args, stiffness) || stiffness <= 0)
+        return nullptr;
+    
+    // Damping coefficient must be greater than or equal to 0.
+    double damping;
+    if (!consumeNumberRaw(args, damping) || damping < 0)
+        return nullptr;
+    
+    // Initial velocity may have any value.
+    double initialVelocity;
+    if (!consumeNumberRaw(args, initialVelocity))
+        return nullptr;
+
+    if (!args.atEnd())
+        return nullptr;
+
+    range = rangeCopy;
+
+    return CSSSpringTimingFunctionValue::create(mass, stiffness, damping, initialVelocity);
+}
+
+static RefPtr<CSSValue> consumeAnimationTimingFunction(CSSParserTokenRange& range, const CSSParserContext& context)
 {
     CSSValueID id = range.peek().id();
     if (id == CSSValueEase || id == CSSValueLinear || id == CSSValueEaseIn
@@ -1195,6 +1229,8 @@ static RefPtr<CSSValue> consumeAnimationTimingFunction(CSSParserTokenRange& rang
         return consumeCubicBezier(range);
     if (function == CSSValueSteps)
         return consumeSteps(range);
+    if (context.springTimingFunctionEnabled && function == CSSValueSpring)
+        return consumeSpringFunction(range);
     return nullptr;
 }
 
@@ -1221,7 +1257,7 @@ static RefPtr<CSSValue> consumeAnimationValue(CSSPropertyID property, CSSParserT
         return consumeTransitionProperty(range);
     case CSSPropertyAnimationTimingFunction:
     case CSSPropertyTransitionTimingFunction:
-        return consumeAnimationTimingFunction(range);
+        return consumeAnimationTimingFunction(range, context);
     default:
         ASSERT_NOT_REACHED();
         return nullptr;