// https://w3c.github.io/web-animations/#set-the-current-time void Animation::SetCurrentTime(const TimeDuration& aSeekTime) { // Return early if the current time has not changed. However, if we // are pause-pending, then setting the current time to any value // including the current value has the effect of aborting the // pause so we should not return early in that case. if (mPendingState != PendingState::PausePending && Nullable<TimeDuration>(aSeekTime) == GetCurrentTime()) { return; } AutoMutationBatchForAnimation mb(*this); SilentlySetCurrentTime(aSeekTime); if (mPendingState == PendingState::PausePending) { // Finish the pause operation mHoldTime.SetValue(aSeekTime); mStartTime.SetNull(); if (mReady) { mReady->MaybeResolve(this); } CancelPendingTasks(); } UpdateTiming(SeekFlag::DidSeek, SyncNotifyFlag::Async); if (IsRelevant()) { nsNodeUtils::AnimationChanged(this); } PostUpdate(); }
void Animation::SilentlySetPlaybackRate(double aPlaybackRate) { Nullable<TimeDuration> previousTime = GetCurrentTime(); mPlaybackRate = aPlaybackRate; if (!previousTime.IsNull()) { SilentlySetCurrentTime(previousTime.Value()); } }
void Animation::SilentlySetPlaybackRate(double aPlaybackRate) { Nullable<TimeDuration> previousTime = GetCurrentTime(); mPlaybackRate = aPlaybackRate; if (!previousTime.IsNull()) { ErrorResult rv; SilentlySetCurrentTime(previousTime.Value()); MOZ_ASSERT(!rv.Failed(), "Should not assert for non-null time"); } }
// https://w3c.github.io/web-animations/#finish-an-animation void Animation::Finish(ErrorResult& aRv) { if (mPlaybackRate == 0 || (mPlaybackRate > 0 && EffectEnd() == TimeDuration::Forever())) { aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } AutoMutationBatchForAnimation mb(*this); // Seek to the end TimeDuration limit = mPlaybackRate > 0 ? TimeDuration(EffectEnd()) : TimeDuration(0); bool didChange = GetCurrentTime() != Nullable<TimeDuration>(limit); SilentlySetCurrentTime(limit); // If we are paused or play-pending we need to fill in the start time in // order to transition to the finished state. // // We only do this, however, if we have an active timeline. If we have an // inactive timeline we can't transition into the finished state just like // we can't transition to the running state (this finished state is really // a substate of the running state). if (mStartTime.IsNull() && mTimeline && !mTimeline->GetCurrentTime().IsNull()) { mStartTime.SetValue(mTimeline->GetCurrentTime().Value() - limit.MultDouble(1.0 / mPlaybackRate)); didChange = true; } // If we just resolved the start time for a pause or play-pending // animation, we need to clear the task. We don't do this as a branch of // the above however since we can have a play-pending animation with a // resolved start time if we aborted a pause operation. if (!mStartTime.IsNull() && (mPendingState == PendingState::PlayPending || mPendingState == PendingState::PausePending)) { if (mPendingState == PendingState::PausePending) { mHoldTime.SetNull(); } CancelPendingTasks(); didChange = true; if (mReady) { mReady->MaybeResolve(this); } } UpdateTiming(SeekFlag::DidSeek, SyncNotifyFlag::Sync); if (didChange && IsRelevant()) { nsNodeUtils::AnimationChanged(this); } PostUpdate(); }
// Implements http://w3c.github.io/web-animations/#set-the-current-time void Animation::SetCurrentTime(const TimeDuration& aSeekTime) { SilentlySetCurrentTime(aSeekTime); if (mPendingState == PendingState::PausePending) { CancelPendingTasks(); if (mReady) { mReady->MaybeResolve(this); } } UpdateFinishedState(true); UpdateEffect(); PostUpdate(); }
// Implements http://w3c.github.io/web-animations/#set-the-current-time void Animation::SetCurrentTime(const TimeDuration& aSeekTime) { SilentlySetCurrentTime(aSeekTime); if (mPendingState == PendingState::PausePending) { // Finish the pause operation mHoldTime.SetValue(aSeekTime); mStartTime.SetNull(); if (mReady) { mReady->MaybeResolve(this); } CancelPendingTasks(); } UpdateTiming(SeekFlag::DidSeek, SyncNotifyFlag::Async); PostUpdate(); }