Bug 1264125 part 3 - Add getter of active time. r?birtles draft
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Wed, 19 Oct 2016 16:21:06 +0900
changeset 427857 be361e3d3a331ed308dcb838092daae1d442d360
parent 427856 08994593780ef3e7d91e2855340465f8676e092b
child 427858 c227b8b60b0e686dd6a1e60993f00c6302e043f6
push id33142
push usermantaroh@gmail.com
push dateFri, 21 Oct 2016 00:27:27 +0000
reviewersbirtles
bugs1264125
milestone52.0a1
Bug 1264125 part 3 - Add getter of active time. r?birtles MozReview-Commit-ID: B2xCp0iJ8xF
dom/animation/Animation.cpp
dom/animation/AnimationEffectReadOnly.cpp
dom/animation/ComputedTiming.h
--- a/dom/animation/Animation.cpp
+++ b/dom/animation/Animation.cpp
@@ -16,16 +16,18 @@
 #include "nsAnimationManager.h" // For CSSAnimation
 #include "nsDOMMutationObserver.h" // For nsAutoAnimationMutationBatch
 #include "nsIDocument.h" // For nsIDocument
 #include "nsIPresShell.h" // For nsIPresShell
 #include "nsThreadUtils.h" // For nsRunnableMethod and nsRevocableEventPtr
 #include "nsTransitionManager.h" // For CSSTransition
 #include "PendingAnimationTracker.h" // For PendingAnimationTracker
 
+typedef mozilla::ComputedTiming::AnimationPhase AnimationPhase;
+
 namespace mozilla {
 namespace dom {
 
 // Static members
 uint64_t Animation::sNextAnimationIndex = 0;
 
 NS_IMPL_CYCLE_COLLECTION_INHERITED(Animation, DOMEventTargetHelper,
                                    mTimeline,
--- a/dom/animation/AnimationEffectReadOnly.cpp
+++ b/dom/animation/AnimationEffectReadOnly.cpp
@@ -122,20 +122,16 @@ AnimationEffectReadOnly::GetComputedTimi
 
   // The default constructor for ComputedTiming sets all other members to
   // values consistent with an animation that has not been sampled.
   if (aLocalTime.IsNull()) {
     return result;
   }
   const TimeDuration& localTime = aLocalTime.Value();
 
-  // Calculate the time within the active interval.
-  // https://w3c.github.io/web-animations/#active-time
-  StickyTimeDuration activeTime;
-
   StickyTimeDuration beforeActiveBoundary =
     std::max(std::min(StickyTimeDuration(aTiming.mDelay), result.mEndTime),
              zeroDuration);
 
   StickyTimeDuration activeAfterBoundary =
     std::max(std::min(StickyTimeDuration(aTiming.mDelay +
                                          result.mActiveDuration),
                       result.mEndTime),
@@ -143,45 +139,46 @@ AnimationEffectReadOnly::GetComputedTimi
 
   if (localTime > activeAfterBoundary ||
       (aPlaybackRate >= 0 && localTime == activeAfterBoundary)) {
     result.mPhase = ComputedTiming::AnimationPhase::After;
     if (!result.FillsForwards()) {
       // The animation isn't active or filling at this time.
       return result;
     }
-    activeTime =
+    result.mActiveTime =
       std::max(std::min(StickyTimeDuration(localTime - aTiming.mDelay),
                         result.mActiveDuration),
                zeroDuration);
   } else if (localTime < beforeActiveBoundary ||
              (aPlaybackRate < 0 && localTime == beforeActiveBoundary)) {
     result.mPhase = ComputedTiming::AnimationPhase::Before;
     if (!result.FillsBackwards()) {
       // The animation isn't active or filling at this time.
       return result;
     }
-    activeTime = std::max(StickyTimeDuration(localTime - aTiming.mDelay),
-                          zeroDuration);
+    result.mActiveTime
+      = std::max(StickyTimeDuration(localTime - aTiming.mDelay),
+                 zeroDuration);
   } else {
     MOZ_ASSERT(result.mActiveDuration != zeroDuration,
                "How can we be in the middle of a zero-duration interval?");
     result.mPhase = ComputedTiming::AnimationPhase::Active;
-    activeTime = localTime - aTiming.mDelay;
+    result.mActiveTime = localTime - aTiming.mDelay;
   }
 
   // Convert active time to a multiple of iterations.
   // https://w3c.github.io/web-animations/#overall-progress
   double overallProgress;
   if (result.mDuration == zeroDuration) {
     overallProgress = result.mPhase == ComputedTiming::AnimationPhase::Before
                       ? 0.0
                       : result.mIterations;
   } else {
-    overallProgress = activeTime / result.mDuration;
+    overallProgress = result.mActiveTime / result.mDuration;
   }
 
   // Factor in iteration start offset.
   if (IsFinite(overallProgress)) {
     overallProgress += result.mIterationStart;
   }
 
   // Determine the 0-based index of the current iteration.
@@ -203,17 +200,18 @@ AnimationEffectReadOnly::GetComputedTimi
   // When we finish exactly at the end of an iteration we need to report
   // the end of the final iteration and not the start of the next iteration.
   // We *don't* want to do this when we have a zero-iteration animation or
   // when the animation has been effectively made into a zero-duration animation
   // using a negative end-delay, however.
   if (result.mPhase == ComputedTiming::AnimationPhase::After &&
       progress == 0.0 &&
       result.mIterations != 0.0 &&
-      (activeTime != zeroDuration || result.mDuration == zeroDuration)) {
+      (result.mActiveTime != zeroDuration ||
+       result.mDuration == zeroDuration)) {
     // The only way we can be in the after phase with a progress of zero and
     // a current iteration of zero, is if we have a zero iteration count or
     // were clipped using a negative end delay--both of which we should have
     // detected above.
     MOZ_ASSERT(result.mCurrentIteration != 0,
                "Should not have zero current iteration");
     progress = 1.0;
     if (result.mCurrentIteration != UINT64_MAX) {
--- a/dom/animation/ComputedTiming.h
+++ b/dom/animation/ComputedTiming.h
@@ -66,13 +66,19 @@ struct ComputedTiming
     Before, // Sampled prior to the start of the active interval
     Active, // Sampled within the active interval
     After   // Sampled after (or at) the end of the active interval
   };
   AnimationPhase      mPhase = AnimationPhase::Null;
 
   ComputedTimingFunction::BeforeFlag mBeforeFlag =
     ComputedTimingFunction::BeforeFlag::Unset;
+
+  // Active time is based on local time and start delay to calculate
+  // the overall progress and calculate elapsed time of cancel event of
+  // CSS-Animations/CSS-Transitions.
+  // For detail, see https://w3c.github.io/web-animations/#active-time
+  StickyTimeDuration mActiveTime;
 };
 
 } // namespace mozilla
 
 #endif // mozilla_ComputedTiming_h