Bug 1244591 - Part 1: Implement KeyframeEffect.setFrames r=birtles,smaug
authorRyo Kato <ryo_kato@hashedhyphen.com>
Sat, 09 Apr 2016 15:33:34 +0900
changeset 294457 e956fb34b9d8f9686d8fde7c86bd749e108c4971
parent 294456 7df8f4cd5d4aa4237d60bbdbc62a1e41186ee57b
child 294458 4f2cae28821142346e72b97f09aae288f75571c2
push id30203
push usercbook@mozilla.com
push dateFri, 22 Apr 2016 13:56:37 +0000
treeherdermozilla-central@fc15477ce628 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbirtles, smaug
bugs1244591
milestone48.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 1244591 - Part 1: Implement KeyframeEffect.setFrames r=birtles,smaug WebIDL referes to KeyframeEffect::SetFrames(), which is derived from KeyframeEffectReadOnly::SetFrames() in terms of implementation. In addition, make KeyframeEffectReadOnly::ConstructKeyframeEffect call KeyframeEffectReadOnly::SetFrames() to simplify the code. MozReview-Commit-ID: 7ASbtoN7Tnp
dom/animation/KeyframeEffect.cpp
dom/animation/KeyframeEffect.h
dom/webidl/KeyframeEffect.webidl
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -433,16 +433,47 @@ KeyframesEqualIgnoringComputedOffsets(co
         a.mTimingFunction != b.mTimingFunction ||
         a.mPropertyValues != b.mPropertyValues) {
       return false;
     }
   }
   return true;
 }
 
+// https://w3c.github.io/web-animations/#dom-keyframeeffect-setframes
+void
+KeyframeEffectReadOnly::SetFrames(JSContext* aContext,
+                                  JS::Handle<JSObject*> aFrames,
+                                  ErrorResult& aRv)
+{
+  nsIDocument* doc = AnimationUtils::GetCurrentRealmDocument(aContext);
+  if (!doc) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return;
+  }
+
+  nsTArray<Keyframe> keyframes =
+    KeyframeUtils::GetKeyframesFromObject(aContext, aFrames, aRv);
+  if (aRv.Failed()) {
+    return;
+  }
+
+  RefPtr<nsStyleContext> styleContext;
+  nsIPresShell* shell = doc->GetShell();
+  if (shell && mTarget) {
+    nsIAtom* pseudo =
+      mPseudoType < CSSPseudoElementType::Count ?
+      nsCSSPseudoElements::GetPseudoAtom(mPseudoType) : nullptr;
+    styleContext =
+      nsComputedDOMStyle::GetStyleContextForElement(mTarget, pseudo, shell);
+  }
+
+  SetFrames(Move(keyframes), styleContext);
+}
+
 void
 KeyframeEffectReadOnly::SetFrames(nsTArray<Keyframe>&& aFrames,
                                   nsStyleContext* aStyleContext)
 {
   if (KeyframesEqualIgnoringComputedOffsets(aFrames, mFrames)) {
     return;
   }
 
@@ -720,37 +751,23 @@ KeyframeEffectReadOnly::ConstructKeyfram
   CSSPseudoElementType pseudoType = CSSPseudoElementType::NotPseudo;
   if (target.IsElement()) {
     targetElement = &target.GetAsElement();
   } else {
     targetElement = target.GetAsCSSPseudoElement().ParentElement();
     pseudoType = target.GetAsCSSPseudoElement().GetType();
   }
 
-  nsTArray<Keyframe> keyframes =
-    KeyframeUtils::GetKeyframesFromObject(aGlobal.Context(), aFrames, aRv);
-  if (aRv.Failed()) {
-    return nullptr;
-  }
-
   RefPtr<KeyframeEffectType> effect =
     new KeyframeEffectType(targetElement->OwnerDoc(), targetElement,
                            pseudoType, timingParams);
-
-  RefPtr<nsStyleContext> styleContext;
-  nsIPresShell* shell = doc->GetShell();
-  if (shell && targetElement) {
-    nsIAtom* pseudo =
-      pseudoType < CSSPseudoElementType::Count ?
-      nsCSSPseudoElements::GetPseudoAtom(pseudoType) : nullptr;
-    styleContext =
-      nsComputedDOMStyle::GetStyleContextForElement(targetElement, pseudo,
-                                                    shell);
+  effect->SetFrames(aGlobal.Context(), aFrames, aRv);
+  if (aRv.Failed()) {
+    return nullptr;
   }
-  effect->SetFrames(Move(keyframes), styleContext);
 
   return effect.forget();
 }
 
 void
 KeyframeEffectReadOnly::ResetIsRunningOnCompositor()
 {
   for (AnimationProperty& property : mProperties) {
--- a/dom/animation/KeyframeEffect.h
+++ b/dom/animation/KeyframeEffect.h
@@ -276,16 +276,18 @@ public:
 
   bool IsInPlay() const;
   bool IsCurrent() const;
   bool IsInEffect() const;
 
   void SetAnimation(Animation* aAnimation);
   Animation* GetAnimation() const { return mAnimation; }
 
+  void SetFrames(JSContext* aContext, JS::Handle<JSObject*> aFrames,
+                 ErrorResult& aRv);
   void SetFrames(nsTArray<Keyframe>&& aFrames, nsStyleContext* aStyleContext);
   const AnimationProperty*
   GetAnimationOfProperty(nsCSSProperty aProperty) const;
   bool HasAnimationOfProperty(nsCSSProperty aProperty) const {
     return GetAnimationOfProperty(aProperty) != nullptr;
   }
   bool HasAnimationOfProperties(const nsCSSProperty* aProperties,
                                 size_t aPropertyCount) const;
--- a/dom/webidl/KeyframeEffect.webidl
+++ b/dom/webidl/KeyframeEffect.webidl
@@ -72,11 +72,11 @@ interface KeyframeEffect : KeyframeEffec
   // Bug 1067769 - Allow setting KeyframeEffect.target
   // inherit attribute Animatable?                 target;
   // Bug 1216843 - implement animation composition
   // inherit attribute IterationCompositeOperation iterationComposite;
   // Bug 1216844 - implement additive animation
   // inherit attribute CompositeOperation          composite;
   // Bug 1244590 - implement spacing modes
   // inherit attribute DOMString                   spacing;
-  // Bug 1244591 - implement setFrames
-  // void setFrames (object? frames);
+  [Throws]
+  void setFrames (object? frames);
 };