// http://w3c.github.io/web-animations/#pause-an-animation void Animation::DoPause(ErrorResult& aRv) { if (IsPausedOrPausing()) { return; } // If we are transitioning from idle, fill in the current time if (GetCurrentTime().IsNull()) { if (mPlaybackRate >= 0.0) { mHoldTime.SetValue(TimeDuration(0)); } else { if (EffectEnd() == TimeDuration::Forever()) { aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } mHoldTime.SetValue(TimeDuration(EffectEnd())); } } bool reuseReadyPromise = false; if (mPendingState == PendingState::PlayPending) { CancelPendingTasks(); reuseReadyPromise = true; } // Mark this as no longer running on the compositor so that next time // we update animations we won't throttle them and will have a chance // to remove the animation from any layer it might be on. mIsRunningOnCompositor = false; if (!reuseReadyPromise) { // Clear ready promise. We'll create a new one lazily. mReady = nullptr; } mPendingState = PendingState::PausePending; nsIDocument* doc = GetRenderedDocument(); if (doc) { PendingAnimationTracker* tracker = doc->GetOrCreatePendingAnimationTracker(); tracker->AddPausePending(*this); } else { TriggerOnNextTick(Nullable<TimeDuration>()); } UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async); }
// https://w3c.github.io/web-animations/#pause-an-animation void Animation::DoPause(ErrorResult& aRv) { if (IsPausedOrPausing()) { return; } AutoMutationBatchForAnimation mb(*this); // If we are transitioning from idle, fill in the current time if (GetCurrentTime().IsNull()) { if (mPlaybackRate >= 0.0) { mHoldTime.SetValue(TimeDuration(0)); } else { if (EffectEnd() == TimeDuration::Forever()) { aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } mHoldTime.SetValue(TimeDuration(EffectEnd())); } } bool reuseReadyPromise = false; if (mPendingState == PendingState::PlayPending) { CancelPendingTasks(); reuseReadyPromise = true; } if (!reuseReadyPromise) { // Clear ready promise. We'll create a new one lazily. mReady = nullptr; } mPendingState = PendingState::PausePending; nsIDocument* doc = GetRenderedDocument(); if (doc) { PendingAnimationTracker* tracker = doc->GetOrCreatePendingAnimationTracker(); tracker->AddPausePending(*this); } else { TriggerOnNextTick(Nullable<TimeDuration>()); } UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async); if (IsRelevant()) { nsNodeUtils::AnimationChanged(this); } }
// http://w3c.github.io/web-animations/#pause-an-animation void Animation::DoPause() { if (IsPausedOrPausing()) { return; } bool reuseReadyPromise = false; if (mPendingState == PendingState::PlayPending) { CancelPendingTasks(); reuseReadyPromise = true; } // Mark this as no longer running on the compositor so that next time // we update animations we won't throttle them and will have a chance // to remove the animation from any layer it might be on. mIsRunningOnCompositor = false; if (!reuseReadyPromise) { // Clear ready promise. We'll create a new one lazily. mReady = nullptr; } mPendingState = PendingState::PausePending; nsIDocument* doc = GetRenderedDocument(); if (!doc) { TriggerOnNextTick(Nullable<TimeDuration>()); return; } PendingAnimationTracker* tracker = doc->GetOrCreatePendingAnimationTracker(); tracker->AddPausePending(*this); UpdateFinishedState(); }
// https://w3c.github.io/web-animations/#setting-the-target-effect void Animation::SetEffectNoUpdate(AnimationEffectReadOnly* aEffect) { RefPtr<Animation> kungFuDeathGrip(this); if (mEffect == aEffect) { return; } AutoMutationBatchForAnimation mb(*this); bool wasRelevant = mIsRelevant; if (mEffect) { if (!aEffect) { // If the new effect is null, call ResetPendingTasks before clearing // mEffect since ResetPendingTasks needs it to get the appropriate // PendingAnimationTracker. ResetPendingTasks(); } // We need to notify observers now because once we set mEffect to null // we won't be able to find the target element to notify. if (mIsRelevant) { nsNodeUtils::AnimationRemoved(this); } // Break links with the old effect and then drop it. RefPtr<AnimationEffectReadOnly> oldEffect = mEffect; mEffect = nullptr; oldEffect->SetAnimation(nullptr); // The following will not do any notification because mEffect is null. UpdateRelevance(); } if (aEffect) { // Break links from the new effect to its previous animation, if any. RefPtr<AnimationEffectReadOnly> newEffect = aEffect; Animation* prevAnim = aEffect->GetAnimation(); if (prevAnim) { prevAnim->SetEffect(nullptr); } // Create links with the new effect. SetAnimation(this) will also update // mIsRelevant of this animation, and then notify mutation observer if // needed by calling Animation::UpdateRelevance(), so we don't need to // call it again. mEffect = newEffect; mEffect->SetAnimation(this); // Notify possible add or change. // If the target is different, the change notification will be ignored by // AutoMutationBatchForAnimation. if (wasRelevant && mIsRelevant) { nsNodeUtils::AnimationChanged(this); } // Reschedule pending pause or pending play tasks. // If we have a pending animation, it will either be registered // in the pending animation tracker and have a null pending ready time, // or, after it has been painted, it will be removed from the tracker // and assigned a pending ready time. // After updating the effect we'll typically need to repaint so if we've // already been assigned a pending ready time, we should clear it and put // the animation back in the tracker. if (!mPendingReadyTime.IsNull()) { mPendingReadyTime.SetNull(); nsIDocument* doc = GetRenderedDocument(); if (doc) { PendingAnimationTracker* tracker = doc->GetOrCreatePendingAnimationTracker(); if (mPendingState == PendingState::PlayPending) { tracker->AddPlayPending(*this); } else { tracker->AddPausePending(*this); } } } } UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async); }