Bug 1340916 - Part 3: Add a helper function to create TimingParams CSS animation/transition properties. r=birtles
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Mon, 20 Feb 2017 11:02:52 +0900
changeset 372785 94a6e5edb0753e088b04aeebef98e113d42d6770
parent 372784 b68b600c854ba2669a3a2b2933c696fa77511c8e
child 372786 7b8628e541b608ae2395791fc8dcfec6f2a931fe
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbirtles
bugs1340916
milestone54.0a1
Bug 1340916 - Part 3: Add a helper function to create TimingParams CSS animation/transition properties. r=birtles MozReview-Commit-ID: 3CmCc44FhvA
layout/style/AnimationCommon.h
layout/style/nsAnimationManager.cpp
layout/style/nsTransitionManager.cpp
--- a/layout/style/AnimationCommon.h
+++ b/layout/style/AnimationCommon.h
@@ -10,16 +10,17 @@
 #include "mozilla/AnimationCollection.h"
 #include "mozilla/AnimationComparator.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/LinkedList.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/dom/Animation.h"
 #include "mozilla/Attributes.h" // For MOZ_NON_OWNING_REF
 #include "mozilla/Assertions.h"
+#include "mozilla/TimingParams.h"
 #include "nsContentUtils.h"
 #include "nsCSSPseudoElements.h"
 #include "nsCycleCollectionParticipant.h"
 
 class nsIFrame;
 class nsPresContext;
 
 namespace mozilla {
@@ -266,11 +267,31 @@ PhaseType GetAnimationPhaseWithoutEffect
 
   // If we don't have a target effect, the duration will be zero so the phase is
   // 'before' if the current time is less than zero.
   return currentTime.Value() < TimeDuration()
          ? PhaseType::Before
          : PhaseType::After;
 };
 
+inline TimingParams
+TimingParamsFromCSSParams(float aDuration, float aDelay,
+                          float aIterationCount,
+                          dom::PlaybackDirection aDirection,
+                          dom::FillMode aFillMode)
+{
+  MOZ_ASSERT(aIterationCount >= 0.0 && !IsNaN(aIterationCount),
+             "aIterations should be nonnegative & finite, as ensured by "
+             "CSSParser");
+
+  TimingParams timing;
+  timing.mDuration.emplace(StickyTimeDuration::FromMilliseconds(aDuration));
+  timing.mDelay = TimeDuration::FromMilliseconds(aDelay);
+  timing.mIterations = aIterationCount;
+  timing.mDirection = aDirection;
+  timing.mFill = aFillMode;
+
+  return timing;
+}
+
 } // namespace mozilla
 
 #endif /* !defined(mozilla_css_AnimationCommon_h) */
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -579,32 +579,23 @@ private:
     const Maybe<ComputedTimingFunction>& aInheritedTimingFunction,
     nsTArray<Keyframe>& aKeyframes);
   void AppendProperty(nsPresContext* aPresContext,
                       nsCSSPropertyID aProperty,
                       nsTArray<PropertyValuePair>& aPropertyValues);
   nsCSSValue GetComputedValue(nsPresContext* aPresContext,
                               nsCSSPropertyID aProperty);
 
-  static TimingParams TimingParamsFrom(
-    const StyleAnimation& aStyleAnimation)
+  static TimingParams TimingParamsFrom(const StyleAnimation& aStyleAnimation)
   {
-    TimingParams timing;
-
-    timing.mDuration.emplace(StickyTimeDuration::FromMilliseconds(
-                               aStyleAnimation.GetDuration()));
-    timing.mDelay = TimeDuration::FromMilliseconds(aStyleAnimation.GetDelay());
-    timing.mIterations = aStyleAnimation.GetIterationCount();
-    MOZ_ASSERT(timing.mIterations >= 0.0 && !IsNaN(timing.mIterations),
-               "mIterations should be nonnegative & finite, as ensured by "
-               "CSSParser");
-    timing.mDirection = aStyleAnimation.GetDirection();
-    timing.mFill = aStyleAnimation.GetFillMode();
-
-    return timing;
+    return TimingParamsFromCSSParams(aStyleAnimation.GetDuration(),
+                                     aStyleAnimation.GetDelay(),
+                                     aStyleAnimation.GetIterationCount(),
+                                     aStyleAnimation.GetDirection(),
+                                     aStyleAnimation.GetFillMode());
   }
 
   RefPtr<nsStyleContext> mStyleContext;
   RefPtr<dom::Element> mTarget;
   RefPtr<dom::DocumentTimeline> mTimeline;
 
   ResolvedStyleCache mResolvedStyles;
   RefPtr<nsStyleContext> mStyleWithoutAnimation;
--- a/layout/style/nsTransitionManager.cpp
+++ b/layout/style/nsTransitionManager.cpp
@@ -889,22 +889,21 @@ nsTransitionManager::ConsiderInitiatingT
     }
 
     duration *= valuePortion;
 
     startForReversingTest = oldPT->ToValue();
     reversePortion = valuePortion;
   }
 
-  TimingParams timing;
-  timing.mDuration.emplace(StickyTimeDuration::FromMilliseconds(duration));
-  timing.mDelay = TimeDuration::FromMilliseconds(delay);
-  timing.mIterations = 1.0;
-  timing.mDirection = dom::PlaybackDirection::Normal;
-  timing.mFill = dom::FillMode::Backwards;
+  TimingParams timing =
+    TimingParamsFromCSSParams(duration, delay,
+                              1.0 /* iteration count */,
+                              dom::PlaybackDirection::Normal,
+                              dom::FillMode::Backwards);
 
   // aElement is non-null here, so we emplace it directly.
   Maybe<OwningAnimationTarget> target;
   target.emplace(aElement, aNewStyleContext->GetPseudoType());
   KeyframeEffectParams effectOptions;
   RefPtr<ElementPropertyTransition> pt =
     new ElementPropertyTransition(aElement->OwnerDoc(), target, timing,
                                   startForReversingTest, reversePortion,