Bug 1216842 - Part 4: Move ParseEasing into AnimationUtils. r=cam
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Wed, 27 Jan 2016 02:08:00 +0100
changeset 282492 28618bbe4f248d332abc2b499b75b9cddaf7ebd2
parent 282491 eabcf625bf8e8bb5d9dc887ddc3bef9a9fdeeee1
child 282493 aa3d8793e82d719f95259cf31eabec278837081b
push id71186
push usercbook@mozilla.com
push dateMon, 01 Feb 2016 08:10:10 +0000
treeherdermozilla-inbound@978349072992 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscam
bugs1216842
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1216842 - Part 4: Move ParseEasing into AnimationUtils. r=cam ParseEasing will be also used in AnimationEffectTimingReadOnly class.
dom/animation/AnimationUtils.cpp
dom/animation/AnimationUtils.h
dom/animation/KeyframeEffect.cpp
--- a/dom/animation/AnimationUtils.cpp
+++ b/dom/animation/AnimationUtils.cpp
@@ -1,20 +1,23 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "AnimationUtils.h"
 
+#include "nsCSSParser.h" // For nsCSSParser
 #include "nsDebug.h"
 #include "nsIAtom.h"
 #include "nsIContent.h"
 #include "nsString.h"
+#include "mozilla/ComputedTimingFunction.h" // ComputedTimingFunction
+#include "mozilla/dom/Element.h" // For dom::Element
 
 namespace mozilla {
 
 /* static */ void
 AnimationUtils::LogAsyncAnimationFailure(nsCString& aMessage,
                                          const nsIContent* aContent)
 {
   if (aContent) {
@@ -28,9 +31,71 @@ AnimationUtils::LogAsyncAnimationFailure
       aMessage.Append('\'');
     }
     aMessage.Append(']');
   }
   aMessage.Append('\n');
   printf_stderr("%s", aMessage.get());
 }
 
+/* static */ Maybe<ComputedTimingFunction>
+AnimationUtils::ParseEasing(const dom::Element* aTarget,
+                            const nsAString& aEasing)
+{
+  if (!aTarget) {
+    return Nothing();
+  }
+
+  nsIDocument* doc = aTarget->OwnerDoc();
+
+  nsCSSValue value;
+  nsCSSParser parser;
+  parser.ParseLonghandProperty(eCSSProperty_animation_timing_function,
+                               aEasing,
+                               doc->GetDocumentURI(),
+                               doc->GetDocumentURI(),
+                               doc->NodePrincipal(),
+                               value);
+
+  switch (value.GetUnit()) {
+    case eCSSUnit_List: {
+      const nsCSSValueList* list = value.GetListValue();
+      if (list->mNext) {
+        // don't support a list of timing functions
+        break;
+      }
+      switch (list->mValue.GetUnit()) {
+        case eCSSUnit_Enumerated:
+          // Return Nothing() if "linear" is passed in.
+          if (list->mValue.GetIntValue() ==
+              NS_STYLE_TRANSITION_TIMING_FUNCTION_LINEAR) {
+            return Nothing();
+          }
+          // Fall through
+        case eCSSUnit_Cubic_Bezier:
+        case eCSSUnit_Steps: {
+          nsTimingFunction timingFunction;
+          nsRuleNode::ComputeTimingFunction(list->mValue, timingFunction);
+          ComputedTimingFunction computedTimingFunction;
+          computedTimingFunction.Init(timingFunction);
+          return Some(computedTimingFunction);
+        }
+        default:
+          MOZ_ASSERT_UNREACHABLE("unexpected animation-timing-function list "
+                                 "item unit");
+        break;
+      }
+      break;
+    }
+    case eCSSUnit_Null:
+    case eCSSUnit_Inherit:
+    case eCSSUnit_Initial:
+    case eCSSUnit_Unset:
+    case eCSSUnit_TokenStream:
+      break;
+    default:
+      MOZ_ASSERT_UNREACHABLE("unexpected animation-timing-function unit");
+      break;
+  }
+  return Nothing();
+}
+
 } // namespace mozilla
--- a/dom/animation/AnimationUtils.h
+++ b/dom/animation/AnimationUtils.h
@@ -10,16 +10,22 @@
 #include "mozilla/TimeStamp.h"
 #include "mozilla/dom/Nullable.h"
 #include "nsStringFwd.h"
 
 class nsIContent;
 
 namespace mozilla {
 
+class ComputedTimingFunction;
+
+namespace dom {
+class Element;
+}
+
 class AnimationUtils
 {
 public:
   static dom::Nullable<double>
     TimeDurationToDouble(const dom::Nullable<TimeDuration>& aTime)
   {
     dom::Nullable<double> result;
 
@@ -39,13 +45,21 @@ public:
       result.SetValue(TimeDuration::FromMilliseconds(aTime.Value()));
     }
 
     return result;
   }
 
   static void LogAsyncAnimationFailure(nsCString& aMessage,
                                        const nsIContent* aContent = nullptr);
+
+  /**
+   * Parses a CSS <single-transition-timing-function> value from
+   * aEasing into a ComputedTimingFunction.  If parsing fails, Nothing() will
+   * be returned.
+   */
+  static Maybe<ComputedTimingFunction>
+    ParseEasing(const dom::Element* aTarget, const nsAString& aEasing);
 };
 
 } // namespace mozilla
 
 #endif
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -860,73 +860,16 @@ struct PropertyValuesPair
  */
 struct OffsetIndexedKeyframe
 {
   binding_detail::FastKeyframe mKeyframeDict;
   nsTArray<PropertyValuesPair> mPropertyValuePairs;
 };
 
 /**
- * Parses a CSS <single-transition-timing-function> value from
- * aEasing into a ComputedTimingFunction.  If parsing fails, Nothing() will
- * be returned.
- */
-static Maybe<ComputedTimingFunction>
-ParseEasing(Element* aTarget,
-            const nsAString& aEasing)
-{
-  nsIDocument* doc = aTarget->OwnerDoc();
-
-  nsCSSValue value;
-  nsCSSParser parser;
-  parser.ParseLonghandProperty(eCSSProperty_animation_timing_function,
-                               aEasing,
-                               doc->GetDocumentURI(),
-                               doc->GetDocumentURI(),
-                               doc->NodePrincipal(),
-                               value);
-
-  switch (value.GetUnit()) {
-    case eCSSUnit_List: {
-      const nsCSSValueList* list = value.GetListValue();
-      if (list->mNext) {
-        // don't support a list of timing functions
-        break;
-      }
-      switch (list->mValue.GetUnit()) {
-        case eCSSUnit_Enumerated:
-        case eCSSUnit_Cubic_Bezier:
-        case eCSSUnit_Steps: {
-          nsTimingFunction timingFunction;
-          nsRuleNode::ComputeTimingFunction(list->mValue, timingFunction);
-          ComputedTimingFunction computedTimingFunction;
-          computedTimingFunction.Init(timingFunction);
-          return Some(computedTimingFunction);
-        }
-        default:
-          MOZ_ASSERT_UNREACHABLE("unexpected animation-timing-function list "
-                                 "item unit");
-        break;
-      }
-      break;
-    }
-    case eCSSUnit_Null:
-    case eCSSUnit_Inherit:
-    case eCSSUnit_Initial:
-    case eCSSUnit_Unset:
-    case eCSSUnit_TokenStream:
-      break;
-    default:
-      MOZ_ASSERT_UNREACHABLE("unexpected animation-timing-function unit");
-      break;
-  }
-  return Nothing();
-}
-
-/**
  * An additional property (for a property-values pair) found on a Keyframe
  * or PropertyIndexedKeyframes object.
  */
 struct AdditionalProperty
 {
   nsCSSProperty mProperty;
   size_t mJsidIndex;        // Index into |ids| in GetPropertyValuesPairs.
 
@@ -1205,17 +1148,17 @@ GenerateValueEntries(Element* aTarget,
 {
   nsCSSPropertySet properties;              // All properties encountered.
   nsCSSPropertySet propertiesWithFromValue; // Those with a defined 0% value.
   nsCSSPropertySet propertiesWithToValue;   // Those with a defined 100% value.
 
   for (OffsetIndexedKeyframe& keyframe : aKeyframes) {
     float offset = float(keyframe.mKeyframeDict.mOffset.Value());
     Maybe<ComputedTimingFunction> easing =
-      ParseEasing(aTarget, keyframe.mKeyframeDict.mEasing);
+      AnimationUtils::ParseEasing(aTarget, keyframe.mKeyframeDict.mEasing);
     // We ignore keyframe.mKeyframeDict.mComposite since we don't support
     // composite modes on keyframes yet.
 
     // keyframe.mPropertyValuePairs is currently sorted by CSS property IDL
     // name, since that was the order we read the properties from the JS
     // object.  Re-sort the list so that longhand properties appear before
     // shorthands, and with shorthands all appearing in increasing order of
     // number of components.  For two longhand properties, or two shorthands
@@ -1467,17 +1410,17 @@ BuildAnimationPropertyListFromPropertyIn
   binding_detail::FastPropertyIndexedKeyframes keyframes;
   if (!keyframes.Init(aCx, aValue, "PropertyIndexedKeyframes argument",
                       false)) {
     aRv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   Maybe<ComputedTimingFunction> easing =
-    ParseEasing(aTarget, keyframes.mEasing);
+    AnimationUtils::ParseEasing(aTarget, keyframes.mEasing);
 
   // We ignore easing.mComposite since we don't support composite modes on
   // keyframes yet.
 
   // Get all the property--value-list pairs off the object.
   JS::Rooted<JSObject*> object(aCx, &aValue.toObject());
   nsTArray<PropertyValuesPair> propertyValuesPairs;
   if (!GetPropertyValuesPairs(aCx, object, ListAllowance::eAllow,