Bug 1245748 - Use Keyframe-based utility functions when constructing KeyframeEffect(ReadOnly); r=heycam draft
authorBrian Birtles <birtles@gmail.com>
Tue, 22 Mar 2016 16:35:53 +0900
changeset 344237 9ae9a7d4e823a1ff3740d4e9ad5a9b4e1d474761
parent 344236 0511514f862d927bc59b3436798aca16796f8763
child 344238 1167cfff6e2bbc5aac92aea0a439788cac96f3c5
push id13778
push userbbirtles@mozilla.com
push dateThu, 24 Mar 2016 03:27:42 +0000
reviewersheycam
bugs1245748
milestone48.0a1
Bug 1245748 - Use Keyframe-based utility functions when constructing KeyframeEffect(ReadOnly); r=heycam MozReview-Commit-ID: 72vLatkFqMq
dom/animation/KeyframeEffect.cpp
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -10,16 +10,17 @@
 #include "mozilla/dom/KeyframeEffectBinding.h"
 #include "mozilla/AnimationUtils.h"
 #include "mozilla/EffectCompositor.h"
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/LookAndFeel.h" // For LookAndFeel::GetInt
 #include "mozilla/KeyframeUtils.h"
 #include "mozilla/StyleAnimationValue.h"
 #include "Layers.h" // For Layer
+#include "nsComputedDOMStyle.h" // nsComputedDOMStyle::GetStyleContextForElement
 #include "nsCSSPropertySet.h"
 #include "nsCSSProps.h" // For nsCSSProps::PropHasFlags
 #include "nsCSSPseudoElements.h" // For CSSPseudoElementType
 #include "nsDOMMutationObserver.h" // For nsAutoAnimationMutationBatch
 #include <algorithm> // For std::max
 
 namespace mozilla {
 
@@ -700,24 +701,42 @@ KeyframeEffectReadOnly::ConstructKeyfram
     pseudoType = target.GetAsCSSPseudoElement().GetType();
   }
 
   if (!targetElement->GetComposedDoc()) {
     aRv.Throw(NS_ERROR_DOM_ANIM_TARGET_NOT_IN_DOC_ERR);
     return nullptr;
   }
 
-  InfallibleTArray<AnimationProperty> animationProperties;
-  KeyframeUtils::BuildAnimationPropertyList(aGlobal.Context(), targetElement,
-                                            pseudoType, aFrames,
-                                            animationProperties, aRv);
-
+  nsTArray<Keyframe> keyframes =
+    KeyframeUtils::GetKeyframesFromObject(aGlobal.Context(), aFrames, aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
+  KeyframeUtils::ApplyDistributeSpacing(keyframes);
+
+  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);
+  }
+
+  nsTArray<AnimationProperty> animationProperties;
+  if (styleContext) {
+    animationProperties =
+      KeyframeUtils::GetAnimationPropertiesFromKeyframes(styleContext,
+                                                         targetElement,
+                                                         pseudoType,
+                                                         keyframes);
+  }
 
   RefPtr<KeyframeEffectType> effect =
     new KeyframeEffectType(targetElement->OwnerDoc(), targetElement,
                            pseudoType, timingParams);
   effect->mProperties = Move(animationProperties);
   return effect.forget();
 }