Bug 1244590 - Part 2: Retrieve KeyframeEffectOptions from constructor. draft
authorBoris Chiou <boris.chiou@gmail.com>
Thu, 05 May 2016 18:50:16 +0800
changeset 369277 c158a2418b964c0695f5e837d9bb1ba55e88ecd3
parent 369276 540a41fa0016e18f139246b7ca6e24b85c19ca94
child 369278 6d20f8be0711f430290457097b196a652ed5ba52
push id18826
push userbmo:boris.chiou@gmail.com
push dateSat, 21 May 2016 11:25:24 +0000
bugs1244590
milestone49.0a1
Bug 1244590 - Part 2: Retrieve KeyframeEffectOptions from constructor. MozReview-Commit-ID: DtkJ6eLj4tl
dom/animation/KeyframeEffect.cpp
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -701,16 +701,48 @@ KeyframeEffectReadOnly::ResetIsRunningOn
     property.mIsRunningOnCompositor = false;
   }
 }
 
 KeyframeEffectReadOnly::~KeyframeEffectReadOnly()
 {
 }
 
+static const KeyframeEffectOptions&
+KeyframeEffectOptionsFromUnion(
+  const UnrestrictedDoubleOrKeyframeEffectOptions& aOptions)
+{
+  MOZ_ASSERT(aOptions.IsKeyframeEffectOptions());
+  return aOptions.GetAsKeyframeEffectOptions();
+}
+
+static const KeyframeEffectOptions&
+KeyframeEffectOptionsFromUnion(
+  const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions)
+{
+  MOZ_ASSERT(aOptions.IsKeyframeAnimationOptions());
+  return aOptions.GetAsKeyframeAnimationOptions();
+}
+
+template <class OptionsType>
+static KeyframeEffectParams
+KeyframeEffectParamsFromUnion(const OptionsType& aOptions,
+                              ErrorResult& aRv)
+{
+  KeyframeEffectParams result;
+  if (!aOptions.IsUnrestrictedDouble()) {
+    const KeyframeEffectOptions& options =
+      KeyframeEffectOptionsFromUnion(aOptions);
+    // TODO: If the grammar of spacing is not correct, we should throw a
+    //       TypeError, aRv.Throw(NS_ERROR_TYPE_ERR). Parse spacing string and
+    //       handle TypeError in the next patch.
+  }
+  return result;
+}
+
 static Maybe<OwningAnimationTarget>
 ConvertTarget(const Nullable<ElementOrCSSPseudoElement>& aTarget)
 {
   // Return value optimization.
   Maybe<OwningAnimationTarget> result;
 
   if (aTarget.IsNull()) {
     return result;
@@ -745,19 +777,19 @@ KeyframeEffectReadOnly::ConstructKeyfram
   }
 
   TimingParams timingParams =
     TimingParams::FromOptionsUnion(aOptions, doc, aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
 
+  KeyframeEffectParams effectOptions =
+    KeyframeEffectParamsFromUnion(aOptions, aRv);
   Maybe<OwningAnimationTarget> target = ConvertTarget(aTarget);
-  // TODO: Use options data from input in the next patch.
-  KeyframeEffectParams effectOptions;
   RefPtr<KeyframeEffectType> effect =
     new KeyframeEffectType(doc, target, timingParams, effectOptions);
 
   effect->SetKeyframes(aGlobal.Context(), aKeyframes, aRv);
   if (aRv.Failed()) {
     return nullptr;
   }