From a6d9ab66d677779d75bbb527f9badc9bbd572dde Mon Sep 17 00:00:00 2001 From: Brian Birtles Date: Wed, 1 Apr 2015 12:23:25 +0900 Subject: [PATCH] Bug 1109390 part 23 - Add aborted pause behavior; r=jwatt When a pending pause operation is interrupted by a play operation we should preserve the original start time of the animation so that it appears to continue moving uninterrupted. At the same time, however, for consistency with other calls to play(), the operation should complete asynchronously. --- dom/animation/AnimationPlayer.cpp | 36 +++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/dom/animation/AnimationPlayer.cpp b/dom/animation/AnimationPlayer.cpp index c65378f4f9f..4a49eab760c 100644 --- a/dom/animation/AnimationPlayer.cpp +++ b/dom/animation/AnimationPlayer.cpp @@ -429,6 +429,8 @@ AnimationPlayer::ComposeStyle(nsRefPtr& aStyleRule, void AnimationPlayer::DoPlay(LimitBehavior aLimitBehavior) { + bool abortedPause = mPendingState == PendingState::PausePending; + bool reuseReadyPromise = false; if (mPendingState != PendingState::NotPending) { CancelPendingTasks(); @@ -452,12 +454,20 @@ AnimationPlayer::DoPlay(LimitBehavior aLimitBehavior) mHoldTime.SetValue(TimeDuration(0)); } - if (mHoldTime.IsNull()) { + // If the hold time is null then we're either already playing normally (and + // we can ignore this call) or we aborted a pending pause operation (in which + // case, for consistency, we need to go through the motions of doing an + // asynchronous start even though we already have a resolved start time). + if (mHoldTime.IsNull() && !abortedPause) { return; } - // Clear the start time until we resolve a new one - mStartTime.SetNull(); + // Clear the start time until we resolve a new one (unless we are aborting + // a pending pause operation, in which case we keep the old start time so + // that the animation continues moving uninterrupted by the aborted pause). + if (!abortedPause) { + mStartTime.SetNull(); + } if (!reuseReadyPromise) { // Clear ready promise. We'll create a new one lazily. @@ -513,15 +523,19 @@ AnimationPlayer::ResumeAt(const TimeDuration& aReadyTime) // but it's currently not necessary. MOZ_ASSERT(mPendingState == PendingState::PlayPending, "Expected to resume a play-pending player"); - MOZ_ASSERT(!mHoldTime.IsNull(), - "A player in the play-pending state should have a resolved" - " hold time"); + MOZ_ASSERT(mHoldTime.IsNull() != mStartTime.IsNull(), + "A player in the play-pending state should have either a" + " resolved hold time or resolved start time (but not both)"); - if (mPlaybackRate != 0) { - mStartTime.SetValue(aReadyTime - (mHoldTime.Value() / mPlaybackRate)); - mHoldTime.SetNull(); - } else { - mStartTime.SetValue(aReadyTime); + // If we aborted a pending pause operation we will already have a start time + // we should use. In all other cases, we resolve it from the ready time. + if (mStartTime.IsNull()) { + if (mPlaybackRate != 0) { + mStartTime.SetValue(aReadyTime - (mHoldTime.Value() / mPlaybackRate)); + mHoldTime.SetNull(); + } else { + mStartTime.SetValue(aReadyTime); + } } mPendingState = PendingState::NotPending;