2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-08-10 11:06:44 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
#include "Animation.h"
|
2014-08-30 10:11:57 +04:00
|
|
|
#include "AnimationUtils.h"
|
2015-04-21 04:22:09 +03:00
|
|
|
#include "mozilla/dom/AnimationBinding.h"
|
2015-07-31 00:25:00 +03:00
|
|
|
#include "mozilla/dom/AnimationPlaybackEvent.h"
|
2019-01-08 09:45:18 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2019-03-29 18:11:04 +03:00
|
|
|
#include "mozilla/dom/DocumentInlines.h"
|
2016-05-30 03:01:11 +03:00
|
|
|
#include "mozilla/dom/DocumentTimeline.h"
|
2018-07-03 05:05:23 +03:00
|
|
|
#include "mozilla/AnimationEventDispatcher.h"
|
2016-04-28 18:22:43 +03:00
|
|
|
#include "mozilla/AnimationTarget.h"
|
2015-04-01 06:23:25 +03:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2015-10-22 09:16:18 +03:00
|
|
|
#include "mozilla/Maybe.h" // For Maybe
|
2018-06-01 19:30:30 +03:00
|
|
|
#include "mozilla/TypeTraits.h" // For std::forward<>
|
2016-01-14 04:24:24 +03:00
|
|
|
#include "nsAnimationManager.h" // For CSSAnimation
|
2015-10-22 09:16:18 +03:00
|
|
|
#include "nsDOMMutationObserver.h" // For nsAutoAnimationMutationBatch
|
2015-07-30 00:21:00 +03:00
|
|
|
#include "nsThreadUtils.h" // For nsRunnableMethod and nsRevocableEventPtr
|
2016-01-14 04:24:24 +03:00
|
|
|
#include "nsTransitionManager.h" // For CSSTransition
|
2015-04-21 04:22:09 +03:00
|
|
|
#include "PendingAnimationTracker.h" // For PendingAnimationTracker
|
2014-08-10 11:06:44 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-06-09 05:13:53 +03:00
|
|
|
// Static members
|
2015-09-15 05:20:26 +03:00
|
|
|
uint64_t Animation::sNextAnimationIndex = 0;
|
2015-06-09 05:13:53 +03:00
|
|
|
|
2015-07-31 00:23:00 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(Animation, DOMEventTargetHelper, mTimeline,
|
|
|
|
mEffect, mReady, mFinished)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(Animation, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(Animation, DOMEventTargetHelper)
|
|
|
|
|
2017-08-30 02:02:48 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Animation)
|
2015-07-31 00:23:00 +03:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2014-08-10 11:06:44 +04:00
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
JSObject* Animation::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return dom::Animation_Binding::Wrap(aCx, this, aGivenProto);
|
2014-08-10 11:06:44 +04:00
|
|
|
}
|
|
|
|
|
2015-10-22 09:16:18 +03:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Utility methods
|
|
|
|
//
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
// A wrapper around nsAutoAnimationMutationBatch that looks up the
|
|
|
|
// appropriate document from the supplied animation.
|
|
|
|
class MOZ_RAII AutoMutationBatchForAnimation {
|
|
|
|
public:
|
|
|
|
explicit AutoMutationBatchForAnimation(
|
|
|
|
const Animation& aAnimation MOZ_GUARD_OBJECT_NOTIFIER_PARAM) {
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2016-03-21 11:49:50 +03:00
|
|
|
Maybe<NonOwningAnimationTarget> target =
|
|
|
|
nsNodeUtils::GetTargetForAnimation(&aAnimation);
|
|
|
|
if (!target) {
|
2015-10-22 09:16:18 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For mutation observers, we use the OwnerDoc.
|
2019-01-02 16:05:23 +03:00
|
|
|
mAutoBatch.emplace(target->mElement->OwnerDoc());
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2015-10-22 09:16:18 +03:00
|
|
|
private:
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
Maybe<nsAutoAnimationMutationBatch> mAutoBatch;
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2015-04-27 04:05:46 +03:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Animation interface:
|
|
|
|
//
|
|
|
|
// ---------------------------------------------------------------------------
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<Animation> Animation::Constructor(
|
2016-01-17 03:02:00 +03:00
|
|
|
const GlobalObject& aGlobal, AnimationEffect* aEffect,
|
2016-05-30 03:01:11 +03:00
|
|
|
const Optional<AnimationTimeline*>& aTimeline, ErrorResult& aRv) {
|
2016-01-17 03:02:00 +03:00
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
|
|
|
|
RefPtr<Animation> animation = new Animation(global);
|
|
|
|
|
2016-05-30 03:01:11 +03:00
|
|
|
AnimationTimeline* timeline;
|
|
|
|
if (aTimeline.WasPassed()) {
|
|
|
|
timeline = aTimeline.Value();
|
|
|
|
} else {
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* document =
|
2016-05-30 03:01:11 +03:00
|
|
|
AnimationUtils::GetCurrentRealmDocument(aGlobal.Context());
|
|
|
|
if (!document) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
timeline = document->Timeline();
|
|
|
|
}
|
|
|
|
|
2016-05-31 03:42:37 +03:00
|
|
|
animation->SetTimelineNoUpdate(timeline);
|
2016-08-24 09:36:14 +03:00
|
|
|
animation->SetEffectNoUpdate(aEffect);
|
2016-01-17 03:02:00 +03:00
|
|
|
|
|
|
|
return animation.forget();
|
|
|
|
}
|
|
|
|
|
2016-01-08 11:17:00 +03:00
|
|
|
void Animation::SetId(const nsAString& aId) {
|
|
|
|
if (mId == aId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mId = aId;
|
|
|
|
nsNodeUtils::AnimationChanged(this);
|
|
|
|
}
|
2015-04-27 04:05:46 +03:00
|
|
|
|
2018-05-07 05:15:16 +03:00
|
|
|
void Animation::SetEffect(AnimationEffect* aEffect) {
|
2016-08-24 09:36:14 +03:00
|
|
|
SetEffectNoUpdate(aEffect);
|
|
|
|
PostUpdate();
|
|
|
|
}
|
|
|
|
|
2017-12-15 23:55:08 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#setting-the-target-effect
|
2018-05-07 05:15:16 +03:00
|
|
|
void Animation::SetEffectNoUpdate(AnimationEffect* aEffect) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Animation> kungFuDeathGrip(this);
|
2015-10-07 08:30:27 +03:00
|
|
|
|
2015-08-18 10:57:00 +03:00
|
|
|
if (mEffect == aEffect) {
|
|
|
|
return;
|
|
|
|
}
|
2016-07-13 13:44:19 +03:00
|
|
|
|
2016-08-16 15:00:35 +03:00
|
|
|
AutoMutationBatchForAnimation mb(*this);
|
|
|
|
bool wasRelevant = mIsRelevant;
|
|
|
|
|
2015-04-27 04:05:46 +03:00
|
|
|
if (mEffect) {
|
2016-08-16 15:00:35 +03:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2016-07-13 13:44:19 +03:00
|
|
|
// Break links with the old effect and then drop it.
|
2018-05-07 05:15:16 +03:00
|
|
|
RefPtr<AnimationEffect> oldEffect = mEffect;
|
2016-07-13 13:44:19 +03:00
|
|
|
mEffect = nullptr;
|
|
|
|
oldEffect->SetAnimation(nullptr);
|
2016-08-16 15:00:35 +03:00
|
|
|
|
|
|
|
// The following will not do any notification because mEffect is null.
|
|
|
|
UpdateRelevance();
|
2015-04-27 04:05:46 +03:00
|
|
|
}
|
2016-07-13 13:44:19 +03:00
|
|
|
|
|
|
|
if (aEffect) {
|
|
|
|
// Break links from the new effect to its previous animation, if any.
|
2018-05-07 05:15:16 +03:00
|
|
|
RefPtr<AnimationEffect> newEffect = aEffect;
|
2016-07-13 13:44:19 +03:00
|
|
|
Animation* prevAnim = aEffect->GetAnimation();
|
|
|
|
if (prevAnim) {
|
|
|
|
prevAnim->SetEffect(nullptr);
|
|
|
|
}
|
|
|
|
|
2016-08-29 11:22:46 +03:00
|
|
|
// 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.
|
2016-07-13 13:44:19 +03:00
|
|
|
mEffect = newEffect;
|
2015-10-07 08:30:27 +03:00
|
|
|
mEffect->SetAnimation(this);
|
2016-07-13 13:44:19 +03:00
|
|
|
|
2016-08-29 11:22:46 +03:00
|
|
|
// Notify possible add or change.
|
2016-08-16 15:00:35 +03:00
|
|
|
// If the target is different, the change notification will be ignored by
|
|
|
|
// AutoMutationBatchForAnimation.
|
|
|
|
if (wasRelevant && mIsRelevant) {
|
|
|
|
nsNodeUtils::AnimationChanged(this);
|
|
|
|
}
|
|
|
|
|
2018-07-12 11:05:13 +03:00
|
|
|
ReschedulePendingTasks();
|
2015-04-27 04:05:46 +03:00
|
|
|
}
|
2015-08-17 07:59:45 +03:00
|
|
|
|
|
|
|
UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async);
|
2015-04-27 04:05:46 +03:00
|
|
|
}
|
|
|
|
|
2015-04-28 11:21:58 +03:00
|
|
|
void Animation::SetTimeline(AnimationTimeline* aTimeline) {
|
2016-05-31 03:42:37 +03:00
|
|
|
SetTimelineNoUpdate(aTimeline);
|
|
|
|
PostUpdate();
|
|
|
|
}
|
|
|
|
|
2017-12-15 23:55:08 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#setting-the-timeline
|
2016-05-31 03:42:37 +03:00
|
|
|
void Animation::SetTimelineNoUpdate(AnimationTimeline* aTimeline) {
|
2015-04-28 11:21:58 +03:00
|
|
|
if (mTimeline == aTimeline) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-20 10:03:29 +03:00
|
|
|
StickyTimeDuration activeTime =
|
|
|
|
mEffect ? mEffect->GetComputedTiming().mActiveTime : StickyTimeDuration();
|
|
|
|
|
2016-08-24 21:12:09 +03:00
|
|
|
RefPtr<AnimationTimeline> oldTimeline = mTimeline;
|
|
|
|
if (oldTimeline) {
|
|
|
|
oldTimeline->RemoveAnimation(this);
|
2016-05-31 03:42:38 +03:00
|
|
|
}
|
|
|
|
|
2015-04-28 11:21:58 +03:00
|
|
|
mTimeline = aTimeline;
|
2016-05-31 03:42:37 +03:00
|
|
|
if (!mStartTime.IsNull()) {
|
|
|
|
mHoldTime.SetNull();
|
|
|
|
}
|
2015-04-28 11:21:58 +03:00
|
|
|
|
2016-12-20 10:03:29 +03:00
|
|
|
if (!aTimeline) {
|
|
|
|
MaybeQueueCancelEvent(activeTime);
|
|
|
|
}
|
2015-07-30 00:21:00 +03:00
|
|
|
UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async);
|
2015-04-28 11:21:58 +03:00
|
|
|
}
|
|
|
|
|
2017-12-15 23:55:08 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#set-the-animation-start-time
|
2015-04-21 04:22:09 +03:00
|
|
|
void Animation::SetStartTime(const Nullable<TimeDuration>& aNewStartTime) {
|
2018-07-26 09:07:52 +03:00
|
|
|
// Return early if the start time will not change. However, if we
|
|
|
|
// are pending, then setting the start time to any value
|
|
|
|
// including the current value has the effect of aborting
|
|
|
|
// pending tasks so we should not return early in that case.
|
|
|
|
if (!Pending() && aNewStartTime == mStartTime) {
|
2015-10-22 09:16:18 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoMutationBatchForAnimation mb(*this);
|
|
|
|
|
2015-04-28 06:49:12 +03:00
|
|
|
Nullable<TimeDuration> timelineTime;
|
2015-02-09 13:26:27 +03:00
|
|
|
if (mTimeline) {
|
|
|
|
// The spec says to check if the timeline is active (has a resolved time)
|
|
|
|
// before using it here, but we don't need to since it's harmless to set
|
|
|
|
// the already null time to null.
|
2018-12-07 01:16:48 +03:00
|
|
|
timelineTime = mTimeline->GetCurrentTimeAsDuration();
|
2015-02-09 13:26:27 +03:00
|
|
|
}
|
|
|
|
if (timelineTime.IsNull() && !aNewStartTime.IsNull()) {
|
|
|
|
mHoldTime.SetNull();
|
|
|
|
}
|
2015-04-28 06:49:12 +03:00
|
|
|
|
2018-12-07 01:16:48 +03:00
|
|
|
Nullable<TimeDuration> previousCurrentTime = GetCurrentTimeAsDuration();
|
2018-02-13 09:04:18 +03:00
|
|
|
|
|
|
|
ApplyPendingPlaybackRate();
|
2015-02-09 13:26:27 +03:00
|
|
|
mStartTime = aNewStartTime;
|
2018-02-13 09:04:18 +03:00
|
|
|
|
2015-02-09 13:26:27 +03:00
|
|
|
if (!aNewStartTime.IsNull()) {
|
2015-03-13 23:10:45 +03:00
|
|
|
if (mPlaybackRate != 0.0) {
|
|
|
|
mHoldTime.SetNull();
|
|
|
|
}
|
2015-02-09 13:26:27 +03:00
|
|
|
} else {
|
|
|
|
mHoldTime = previousCurrentTime;
|
|
|
|
}
|
|
|
|
|
2015-03-27 09:56:45 +03:00
|
|
|
CancelPendingTasks();
|
2015-02-09 13:26:27 +03:00
|
|
|
if (mReady) {
|
|
|
|
// We may have already resolved mReady, but in that case calling
|
|
|
|
// MaybeResolve is a no-op, so that's okay.
|
|
|
|
mReady->MaybeResolve(this);
|
|
|
|
}
|
|
|
|
|
2016-04-27 05:34:05 +03:00
|
|
|
UpdateTiming(SeekFlag::DidSeek, SyncNotifyFlag::Async);
|
2015-10-22 09:16:18 +03:00
|
|
|
if (IsRelevant()) {
|
|
|
|
nsNodeUtils::AnimationChanged(this);
|
|
|
|
}
|
2015-02-12 20:56:57 +03:00
|
|
|
PostUpdate();
|
2015-02-09 13:26:27 +03:00
|
|
|
}
|
|
|
|
|
2017-12-15 23:55:08 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#current-time
|
2018-02-13 09:04:18 +03:00
|
|
|
Nullable<TimeDuration> Animation::GetCurrentTimeForHoldTime(
|
|
|
|
const Nullable<TimeDuration>& aHoldTime) const {
|
2014-10-20 08:55:45 +04:00
|
|
|
Nullable<TimeDuration> result;
|
2018-02-13 09:04:18 +03:00
|
|
|
if (!aHoldTime.IsNull()) {
|
|
|
|
result = aHoldTime;
|
2014-12-04 23:13:38 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-04-28 06:49:12 +03:00
|
|
|
if (mTimeline && !mStartTime.IsNull()) {
|
2018-12-07 01:16:48 +03:00
|
|
|
Nullable<TimeDuration> timelineTime = mTimeline->GetCurrentTimeAsDuration();
|
2014-12-04 23:13:38 +03:00
|
|
|
if (!timelineTime.IsNull()) {
|
2018-02-13 09:04:18 +03:00
|
|
|
result = CurrentTimeFromTimelineTime(timelineTime.Value(),
|
|
|
|
mStartTime.Value(), mPlaybackRate);
|
2014-10-20 08:55:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2014-08-10 11:06:44 +04:00
|
|
|
}
|
|
|
|
|
2017-12-15 23:55:08 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#set-the-current-time
|
2015-04-21 04:22:09 +03:00
|
|
|
void Animation::SetCurrentTime(const TimeDuration& aSeekTime) {
|
2015-10-22 09:16:18 +03:00
|
|
|
// 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 &&
|
2018-12-07 01:16:48 +03:00
|
|
|
Nullable<TimeDuration>(aSeekTime) == GetCurrentTimeAsDuration()) {
|
2015-10-22 09:16:18 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoMutationBatchForAnimation mb(*this);
|
|
|
|
|
2015-03-09 19:50:39 +03:00
|
|
|
SilentlySetCurrentTime(aSeekTime);
|
|
|
|
|
2015-03-27 09:56:45 +03:00
|
|
|
if (mPendingState == PendingState::PausePending) {
|
2015-05-18 05:41:19 +03:00
|
|
|
// Finish the pause operation
|
|
|
|
mHoldTime.SetValue(aSeekTime);
|
2018-02-13 09:04:18 +03:00
|
|
|
|
|
|
|
ApplyPendingPlaybackRate();
|
2015-05-18 05:41:19 +03:00
|
|
|
mStartTime.SetNull();
|
|
|
|
|
2015-03-27 09:56:45 +03:00
|
|
|
if (mReady) {
|
|
|
|
mReady->MaybeResolve(this);
|
|
|
|
}
|
2015-05-18 05:41:19 +03:00
|
|
|
CancelPendingTasks();
|
2015-03-27 09:56:45 +03:00
|
|
|
}
|
2015-03-09 19:50:39 +03:00
|
|
|
|
2015-07-30 00:21:00 +03:00
|
|
|
UpdateTiming(SeekFlag::DidSeek, SyncNotifyFlag::Async);
|
2015-10-22 09:16:18 +03:00
|
|
|
if (IsRelevant()) {
|
|
|
|
nsNodeUtils::AnimationChanged(this);
|
|
|
|
}
|
2015-03-09 19:50:39 +03:00
|
|
|
PostUpdate();
|
|
|
|
}
|
|
|
|
|
2018-02-13 09:04:18 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#set-the-playback-rate
|
2015-04-21 04:22:09 +03:00
|
|
|
void Animation::SetPlaybackRate(double aPlaybackRate) {
|
2018-02-13 09:04:18 +03:00
|
|
|
mPendingPlaybackRate.reset();
|
|
|
|
|
2015-10-22 09:16:18 +03:00
|
|
|
if (aPlaybackRate == mPlaybackRate) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoMutationBatchForAnimation mb(*this);
|
|
|
|
|
2018-12-07 01:16:48 +03:00
|
|
|
Nullable<TimeDuration> previousTime = GetCurrentTimeAsDuration();
|
2015-03-13 23:10:45 +03:00
|
|
|
mPlaybackRate = aPlaybackRate;
|
|
|
|
if (!previousTime.IsNull()) {
|
|
|
|
SetCurrentTime(previousTime.Value());
|
|
|
|
}
|
2015-10-22 09:16:18 +03:00
|
|
|
|
2018-12-07 01:16:48 +03:00
|
|
|
// In the case where GetCurrentTimeAsDuration() returns the same result before
|
|
|
|
// and after updating mPlaybackRate, SetCurrentTime will return early since,
|
2015-10-22 09:16:18 +03:00
|
|
|
// as far as it can tell, nothing has changed.
|
|
|
|
// As a result, we need to perform the following updates here:
|
|
|
|
// - update timing (since, if the sign of the playback rate has changed, our
|
|
|
|
// finished state may have changed),
|
|
|
|
// - dispatch a change notification for the changed playback rate, and
|
|
|
|
// - update the playback rate on animations on layers.
|
|
|
|
UpdateTiming(SeekFlag::DidSeek, SyncNotifyFlag::Async);
|
2015-10-22 09:16:18 +03:00
|
|
|
if (IsRelevant()) {
|
|
|
|
nsNodeUtils::AnimationChanged(this);
|
|
|
|
}
|
2015-10-22 09:16:18 +03:00
|
|
|
PostUpdate();
|
2015-03-13 23:10:45 +03:00
|
|
|
}
|
|
|
|
|
2018-02-13 09:04:18 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#seamlessly-update-the-playback-rate
|
|
|
|
void Animation::UpdatePlaybackRate(double aPlaybackRate) {
|
|
|
|
if (mPendingPlaybackRate && mPendingPlaybackRate.value() == aPlaybackRate) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-03 09:13:52 +03:00
|
|
|
// Calculate the play state using the existing playback rate since below we
|
|
|
|
// want to know if the animation is _currently_ finished or not, not whether
|
|
|
|
// it _will_ be finished.
|
|
|
|
AnimationPlayState playState = PlayState();
|
|
|
|
|
2018-02-13 09:04:18 +03:00
|
|
|
mPendingPlaybackRate = Some(aPlaybackRate);
|
|
|
|
|
|
|
|
// If we already have a pending task, there is nothing more to do since the
|
|
|
|
// playback rate will be applied then.
|
|
|
|
if (Pending()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoMutationBatchForAnimation mb(*this);
|
|
|
|
|
|
|
|
if (playState == AnimationPlayState::Idle ||
|
|
|
|
playState == AnimationPlayState::Paused) {
|
|
|
|
// We are either idle or paused. In either case we can apply the pending
|
|
|
|
// playback rate immediately.
|
|
|
|
ApplyPendingPlaybackRate();
|
|
|
|
|
|
|
|
// We don't need to update timing or post an update here because:
|
|
|
|
//
|
|
|
|
// * the current time hasn't changed -- it's either unresolved or fixed
|
|
|
|
// with a hold time -- so the output won't have changed
|
|
|
|
// * the finished state won't have changed even if the sign of the
|
|
|
|
// playback rate changed since we're not finished (we're paused or idle)
|
|
|
|
// * the playback rate on layers doesn't need to be updated since we're not
|
|
|
|
// moving. Once we get a start time etc. we'll update the playback rate
|
|
|
|
// then.
|
|
|
|
//
|
|
|
|
// All we need to do is update observers so that, e.g. DevTools, report the
|
|
|
|
// right information.
|
|
|
|
if (IsRelevant()) {
|
|
|
|
nsNodeUtils::AnimationChanged(this);
|
|
|
|
}
|
|
|
|
} else if (playState == AnimationPlayState::Finished) {
|
2018-12-07 01:16:48 +03:00
|
|
|
MOZ_ASSERT(mTimeline && !mTimeline->GetCurrentTimeAsDuration().IsNull(),
|
2018-02-13 09:04:18 +03:00
|
|
|
"If we have no active timeline, we should be idle or paused");
|
|
|
|
if (aPlaybackRate != 0) {
|
|
|
|
// The unconstrained current time can only be unresolved if either we
|
|
|
|
// don't have an active timeline (and we already asserted that is not
|
|
|
|
// true) or we have an unresolved start time (in which case we should be
|
|
|
|
// paused).
|
|
|
|
MOZ_ASSERT(!GetUnconstrainedCurrentTime().IsNull(),
|
|
|
|
"Unconstrained current time should be resolved");
|
|
|
|
TimeDuration unconstrainedCurrentTime =
|
|
|
|
GetUnconstrainedCurrentTime().Value();
|
2018-12-07 01:16:48 +03:00
|
|
|
TimeDuration timelineTime = mTimeline->GetCurrentTimeAsDuration().Value();
|
2018-02-13 09:04:18 +03:00
|
|
|
mStartTime = StartTimeFromTimelineTime(
|
|
|
|
timelineTime, unconstrainedCurrentTime, aPlaybackRate);
|
|
|
|
} else {
|
2018-12-07 01:16:48 +03:00
|
|
|
mStartTime = mTimeline->GetCurrentTimeAsDuration();
|
2018-02-13 09:04:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ApplyPendingPlaybackRate();
|
|
|
|
|
|
|
|
// Even though we preserve the current time, we might now leave the finished
|
|
|
|
// state (e.g. if the playback rate changes sign) so we need to update
|
|
|
|
// timing.
|
|
|
|
UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async);
|
|
|
|
if (IsRelevant()) {
|
|
|
|
nsNodeUtils::AnimationChanged(this);
|
|
|
|
}
|
|
|
|
PostUpdate();
|
|
|
|
} else {
|
|
|
|
ErrorResult rv;
|
|
|
|
Play(rv, LimitBehavior::Continue);
|
|
|
|
MOZ_ASSERT(!rv.Failed(),
|
|
|
|
"We should only fail to play when using auto-rewind behavior");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-15 23:55:08 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#play-state
|
2015-04-21 04:22:09 +03:00
|
|
|
AnimationPlayState Animation::PlayState() const {
|
2018-12-07 01:16:48 +03:00
|
|
|
Nullable<TimeDuration> currentTime = GetCurrentTimeAsDuration();
|
2017-11-21 11:10:59 +03:00
|
|
|
if (currentTime.IsNull() && !Pending()) {
|
2014-10-20 08:55:45 +04:00
|
|
|
return AnimationPlayState::Idle;
|
|
|
|
}
|
|
|
|
|
2017-11-21 11:10:59 +03:00
|
|
|
if (mPendingState == PendingState::PausePending ||
|
|
|
|
(mStartTime.IsNull() && !Pending())) {
|
2014-10-20 08:55:45 +04:00
|
|
|
return AnimationPlayState::Paused;
|
|
|
|
}
|
|
|
|
|
2018-10-03 09:13:52 +03:00
|
|
|
double playbackRate = CurrentOrPendingPlaybackRate();
|
2017-11-21 11:10:59 +03:00
|
|
|
if (!currentTime.IsNull() &&
|
2018-10-03 09:13:52 +03:00
|
|
|
((playbackRate > 0.0 && currentTime.Value() >= EffectEnd()) ||
|
|
|
|
(playbackRate < 0.0 && currentTime.Value() <= TimeDuration()))) {
|
2014-10-20 08:55:45 +04:00
|
|
|
return AnimationPlayState::Finished;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AnimationPlayState::Running;
|
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
Promise* Animation::GetReady(ErrorResult& aRv) {
|
2015-07-31 00:23:00 +03:00
|
|
|
nsCOMPtr<nsIGlobalObject> global = GetOwnerGlobal();
|
|
|
|
if (!mReady && global) {
|
|
|
|
mReady = Promise::Create(global, aRv); // Lazily create on demand
|
2014-12-18 02:42:40 +03:00
|
|
|
}
|
|
|
|
if (!mReady) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
2017-02-28 22:50:35 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2017-11-21 11:10:59 +03:00
|
|
|
if (!Pending()) {
|
2015-03-18 16:22:11 +03:00
|
|
|
mReady->MaybeResolve(this);
|
2014-12-18 02:42:40 +03:00
|
|
|
}
|
|
|
|
return mReady;
|
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
Promise* Animation::GetFinished(ErrorResult& aRv) {
|
2015-07-31 00:23:00 +03:00
|
|
|
nsCOMPtr<nsIGlobalObject> global = GetOwnerGlobal();
|
|
|
|
if (!mFinished && global) {
|
|
|
|
mFinished = Promise::Create(global, aRv); // Lazily create on demand
|
2015-03-18 16:22:11 +03:00
|
|
|
}
|
|
|
|
if (!mFinished) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
2017-02-28 22:50:35 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (mFinishedIsResolved) {
|
2015-07-30 00:21:00 +03:00
|
|
|
MaybeResolveFinishedPromise();
|
2015-03-18 16:22:11 +03:00
|
|
|
}
|
|
|
|
return mFinished;
|
|
|
|
}
|
|
|
|
|
2019-04-18 09:24:52 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#cancel-an-animation
|
2019-04-18 09:49:25 +03:00
|
|
|
void Animation::Cancel(PostRestyleMode aPostRestyle) {
|
|
|
|
bool newlyIdle = false;
|
|
|
|
|
2019-04-18 09:24:52 +03:00
|
|
|
if (PlayState() != AnimationPlayState::Idle) {
|
2019-04-18 09:49:25 +03:00
|
|
|
newlyIdle = true;
|
|
|
|
|
2019-04-18 09:24:52 +03:00
|
|
|
ResetPendingTasks();
|
|
|
|
|
|
|
|
if (mFinished) {
|
|
|
|
mFinished->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
|
|
|
|
}
|
|
|
|
ResetFinishedPromise();
|
|
|
|
|
|
|
|
QueuePlaybackEvent(NS_LITERAL_STRING("cancel"),
|
|
|
|
GetTimelineCurrentTimeAsTimeStamp());
|
|
|
|
}
|
|
|
|
|
|
|
|
StickyTimeDuration activeTime =
|
|
|
|
mEffect ? mEffect->GetComputedTiming().mActiveTime : StickyTimeDuration();
|
|
|
|
|
|
|
|
mHoldTime.SetNull();
|
|
|
|
mStartTime.SetNull();
|
|
|
|
|
2019-04-18 09:25:54 +03:00
|
|
|
// Allow our effect to remove itself from the its target element's EffectSet.
|
2019-04-18 09:49:25 +03:00
|
|
|
UpdateEffect(aPostRestyle);
|
2019-04-18 09:24:52 +03:00
|
|
|
|
|
|
|
if (mTimeline) {
|
|
|
|
mTimeline->RemoveAnimation(this);
|
|
|
|
}
|
|
|
|
MaybeQueueCancelEvent(activeTime);
|
|
|
|
|
2019-04-18 09:49:25 +03:00
|
|
|
if (newlyIdle && aPostRestyle == PostRestyleMode::IfNeeded) {
|
|
|
|
PostUpdate();
|
|
|
|
}
|
2015-04-27 02:53:19 +03:00
|
|
|
}
|
|
|
|
|
2017-12-15 23:55:08 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#finish-an-animation
|
2015-04-16 19:15:20 +03:00
|
|
|
void Animation::Finish(ErrorResult& aRv) {
|
2018-02-13 09:04:18 +03:00
|
|
|
double effectivePlaybackRate = CurrentOrPendingPlaybackRate();
|
|
|
|
|
|
|
|
if (effectivePlaybackRate == 0 ||
|
|
|
|
(effectivePlaybackRate > 0 && EffectEnd() == TimeDuration::Forever())) {
|
2015-04-16 19:15:20 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-22 09:16:18 +03:00
|
|
|
AutoMutationBatchForAnimation mb(*this);
|
|
|
|
|
2018-02-13 09:04:18 +03:00
|
|
|
ApplyPendingPlaybackRate();
|
|
|
|
|
2015-10-22 09:16:18 +03:00
|
|
|
// Seek to the end
|
2015-04-16 19:15:20 +03:00
|
|
|
TimeDuration limit =
|
|
|
|
mPlaybackRate > 0 ? TimeDuration(EffectEnd()) : TimeDuration(0);
|
2018-12-07 01:16:48 +03:00
|
|
|
bool didChange = GetCurrentTimeAsDuration() != Nullable<TimeDuration>(limit);
|
2015-07-14 22:45:00 +03:00
|
|
|
SilentlySetCurrentTime(limit);
|
2015-04-16 19:15:20 +03:00
|
|
|
|
2015-05-19 04:08:46 +03:00
|
|
|
// 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 &&
|
2018-12-07 01:16:48 +03:00
|
|
|
!mTimeline->GetCurrentTimeAsDuration().IsNull()) {
|
|
|
|
mStartTime = StartTimeFromTimelineTime(
|
|
|
|
mTimeline->GetCurrentTimeAsDuration().Value(), limit, mPlaybackRate);
|
2015-10-22 09:16:18 +03:00
|
|
|
didChange = true;
|
2015-05-19 04:08:46 +03:00
|
|
|
}
|
|
|
|
|
2015-07-14 22:45:00 +03:00
|
|
|
// 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();
|
|
|
|
}
|
2015-04-16 19:15:20 +03:00
|
|
|
CancelPendingTasks();
|
2015-10-22 09:16:18 +03:00
|
|
|
didChange = true;
|
2015-04-16 19:15:20 +03:00
|
|
|
if (mReady) {
|
|
|
|
mReady->MaybeResolve(this);
|
|
|
|
}
|
|
|
|
}
|
2015-07-30 00:21:00 +03:00
|
|
|
UpdateTiming(SeekFlag::DidSeek, SyncNotifyFlag::Sync);
|
2015-10-22 09:16:18 +03:00
|
|
|
if (didChange && IsRelevant()) {
|
|
|
|
nsNodeUtils::AnimationChanged(this);
|
|
|
|
}
|
2015-04-16 19:15:20 +03:00
|
|
|
PostUpdate();
|
|
|
|
}
|
|
|
|
|
2015-05-19 08:00:48 +03:00
|
|
|
void Animation::Play(ErrorResult& aRv, LimitBehavior aLimitBehavior) {
|
2016-05-31 03:42:37 +03:00
|
|
|
PlayNoUpdate(aRv, aLimitBehavior);
|
2014-11-17 07:46:01 +03:00
|
|
|
PostUpdate();
|
2014-10-20 08:55:43 +04:00
|
|
|
}
|
|
|
|
|
2017-12-15 23:55:08 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#reverse-an-animation
|
2015-07-09 23:54:00 +03:00
|
|
|
void Animation::Reverse(ErrorResult& aRv) {
|
2018-12-07 01:16:48 +03:00
|
|
|
if (!mTimeline || mTimeline->GetCurrentTimeAsDuration().IsNull()) {
|
2015-07-09 23:54:00 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-13 09:04:18 +03:00
|
|
|
double effectivePlaybackRate = CurrentOrPendingPlaybackRate();
|
|
|
|
|
|
|
|
if (effectivePlaybackRate == 0.0) {
|
2015-07-09 23:54:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-13 09:04:18 +03:00
|
|
|
Maybe<double> originalPendingPlaybackRate = mPendingPlaybackRate;
|
|
|
|
|
|
|
|
mPendingPlaybackRate = Some(-effectivePlaybackRate);
|
2015-10-22 09:16:18 +03:00
|
|
|
|
2015-07-09 23:54:00 +03:00
|
|
|
Play(aRv, LimitBehavior::AutoRewind);
|
2015-10-22 09:16:18 +03:00
|
|
|
|
2017-03-28 08:51:51 +03:00
|
|
|
// If Play() threw, restore state and don't report anything to mutation
|
|
|
|
// observers.
|
|
|
|
if (aRv.Failed()) {
|
2018-02-13 09:04:18 +03:00
|
|
|
mPendingPlaybackRate = originalPendingPlaybackRate;
|
2017-03-28 08:51:51 +03:00
|
|
|
}
|
|
|
|
|
2017-03-28 08:51:53 +03:00
|
|
|
// Play(), above, unconditionally calls PostUpdate so we don't need to do
|
|
|
|
// it here.
|
2015-07-09 23:54:00 +03:00
|
|
|
}
|
|
|
|
|
2015-04-27 04:05:46 +03:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// JS wrappers for Animation interface:
|
|
|
|
//
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
Nullable<double> Animation::GetStartTimeAsDouble() const {
|
2014-12-04 19:28:38 +03:00
|
|
|
return AnimationUtils::TimeDurationToDouble(mStartTime);
|
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
void Animation::SetStartTimeAsDouble(const Nullable<double>& aStartTime) {
|
2015-02-09 13:26:27 +03:00
|
|
|
return SetStartTime(AnimationUtils::DoubleToTimeDuration(aStartTime));
|
|
|
|
}
|
2015-04-21 04:22:09 +03:00
|
|
|
|
|
|
|
Nullable<double> Animation::GetCurrentTimeAsDouble() const {
|
2018-12-07 01:16:48 +03:00
|
|
|
return AnimationUtils::TimeDurationToDouble(GetCurrentTimeAsDuration());
|
2014-10-20 08:55:45 +04:00
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
void Animation::SetCurrentTimeAsDouble(const Nullable<double>& aCurrentTime,
|
2015-03-09 19:50:39 +03:00
|
|
|
ErrorResult& aRv) {
|
|
|
|
if (aCurrentTime.IsNull()) {
|
2018-12-07 01:16:48 +03:00
|
|
|
if (!GetCurrentTimeAsDuration().IsNull()) {
|
2015-03-09 19:50:39 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SetCurrentTime(TimeDuration::FromMilliseconds(aCurrentTime.Value()));
|
|
|
|
}
|
|
|
|
|
2015-04-27 04:05:46 +03:00
|
|
|
// ---------------------------------------------------------------------------
|
2014-08-10 11:06:48 +04:00
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
void Animation::Tick() {
|
Bug 1208938 part 3 - Update pending finishing handling; r=heycam
Animation::Tick contains special handling to cope with pending ready times
that are in the future. This was originally introduced to cope with the
situation where we are called multiple times per refresh-driver tick.
As of bug 1195180, Animation::Tick should no longer be called multiple
times per refresh driver tick. It would seem, therefore, that we no longer
need to check for a future time. However, since introducing this check, the
vsync refresh driver timer has been added which means that we can still have
a recorded time from TimeStamp::Now that is ahead of the vsync time used to
update the refresh driver. In that case, however, rather than waiting for the
next tick, we should simply clamp that pending ready time to the refresh driver
time and finish pending immediately.
This patch also updates one of the tests for reversing. With this updated
behavior we can sometimes arrive at a situation where when an Animation starts
and its ready promise resolves, its currentTime is still 0. If we call
reverse() at this point on an animation with an infinite active duration it
should throw an InvalidStateError. To avoid this situation, this test makes
sure we wait an extra frame before calling reverse().
2015-10-07 08:30:28 +03:00
|
|
|
// Finish pending if we have a pending ready time, but only if we also
|
|
|
|
// have an active timeline.
|
2015-03-27 09:56:45 +03:00
|
|
|
if (mPendingState != PendingState::NotPending &&
|
2015-01-09 01:57:58 +03:00
|
|
|
!mPendingReadyTime.IsNull() && mTimeline &&
|
2018-12-07 01:16:48 +03:00
|
|
|
!mTimeline->GetCurrentTimeAsDuration().IsNull()) {
|
Bug 1208938 part 3 - Update pending finishing handling; r=heycam
Animation::Tick contains special handling to cope with pending ready times
that are in the future. This was originally introduced to cope with the
situation where we are called multiple times per refresh-driver tick.
As of bug 1195180, Animation::Tick should no longer be called multiple
times per refresh driver tick. It would seem, therefore, that we no longer
need to check for a future time. However, since introducing this check, the
vsync refresh driver timer has been added which means that we can still have
a recorded time from TimeStamp::Now that is ahead of the vsync time used to
update the refresh driver. In that case, however, rather than waiting for the
next tick, we should simply clamp that pending ready time to the refresh driver
time and finish pending immediately.
This patch also updates one of the tests for reversing. With this updated
behavior we can sometimes arrive at a situation where when an Animation starts
and its ready promise resolves, its currentTime is still 0. If we call
reverse() at this point on an animation with an infinite active duration it
should throw an InvalidStateError. To avoid this situation, this test makes
sure we wait an extra frame before calling reverse().
2015-10-07 08:30:28 +03:00
|
|
|
// Even though mPendingReadyTime is initialized using TimeStamp::Now()
|
|
|
|
// during the *previous* tick of the refresh driver, it can still be
|
|
|
|
// ahead of the *current* timeline time when we are using the
|
|
|
|
// vsync timer so we need to clamp it to the timeline time.
|
2018-12-07 01:16:48 +03:00
|
|
|
TimeDuration currentTime = mTimeline->GetCurrentTimeAsDuration().Value();
|
2018-02-26 19:08:55 +03:00
|
|
|
if (currentTime < mPendingReadyTime.Value()) {
|
|
|
|
mPendingReadyTime.SetValue(currentTime);
|
|
|
|
}
|
2015-04-01 06:23:24 +03:00
|
|
|
FinishPendingAt(mPendingReadyTime.Value());
|
2015-01-09 01:57:58 +03:00
|
|
|
mPendingReadyTime.SetNull();
|
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
if (IsPossiblyOrphanedPendingAnimation()) {
|
2018-12-07 01:16:48 +03:00
|
|
|
MOZ_ASSERT(mTimeline && !mTimeline->GetCurrentTimeAsDuration().IsNull(),
|
2016-07-25 11:56:34 +03:00
|
|
|
"Orphaned pending animations should have an active timeline");
|
2018-12-07 01:16:48 +03:00
|
|
|
FinishPendingAt(mTimeline->GetCurrentTimeAsDuration().Value());
|
2015-01-09 01:57:58 +03:00
|
|
|
}
|
2014-12-25 10:28:24 +03:00
|
|
|
|
2015-07-30 00:21:00 +03:00
|
|
|
UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async);
|
2015-08-18 10:11:55 +03:00
|
|
|
|
2016-07-25 11:56:34 +03:00
|
|
|
if (!mEffect) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-06 05:04:06 +03:00
|
|
|
// Update layers if we are newly finished.
|
2018-05-07 05:08:59 +03:00
|
|
|
KeyframeEffect* keyframeEffect = mEffect->AsKeyframeEffect();
|
2016-07-25 11:56:34 +03:00
|
|
|
if (keyframeEffect && !keyframeEffect->Properties().IsEmpty() &&
|
2016-01-06 05:04:06 +03:00
|
|
|
!mFinishedAtLastComposeStyle &&
|
|
|
|
PlayState() == AnimationPlayState::Finished) {
|
|
|
|
PostUpdate();
|
|
|
|
}
|
2014-08-10 11:06:47 +04:00
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
void Animation::TriggerOnNextTick(const Nullable<TimeDuration>& aReadyTime) {
|
2015-01-09 01:57:58 +03:00
|
|
|
// Normally we expect the play state to be pending but it's possible that,
|
2015-04-21 04:22:09 +03:00
|
|
|
// due to the handling of possibly orphaned animations in Tick(), this
|
|
|
|
// animation got started whilst still being in another document's pending
|
|
|
|
// animation map.
|
2017-11-21 11:10:59 +03:00
|
|
|
if (!Pending()) {
|
2015-01-09 01:57:58 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-09 01:57:58 +03:00
|
|
|
// If aReadyTime.IsNull() we'll detect this in Tick() where we check for
|
2015-04-21 04:22:09 +03:00
|
|
|
// orphaned animations and trigger this animation anyway
|
2015-01-09 01:57:58 +03:00
|
|
|
mPendingReadyTime = aReadyTime;
|
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
void Animation::TriggerNow() {
|
2015-06-09 05:13:53 +03:00
|
|
|
// Normally we expect the play state to be pending but when an animation
|
|
|
|
// is cancelled and its rendered document can't be reached, we can end up
|
|
|
|
// with the animation still in a pending player tracker even after it is
|
|
|
|
// no longer pending.
|
2017-11-21 11:10:59 +03:00
|
|
|
if (!Pending()) {
|
2015-06-09 05:13:53 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-04-28 06:49:12 +03:00
|
|
|
|
|
|
|
// If we don't have an active timeline we can't trigger the animation.
|
|
|
|
// However, this is a test-only method that we don't expect to be used in
|
|
|
|
// conjunction with animations without an active timeline so generate
|
|
|
|
// a warning if we do find ourselves in that situation.
|
2018-12-07 01:16:48 +03:00
|
|
|
if (!mTimeline || mTimeline->GetCurrentTimeAsDuration().IsNull()) {
|
2015-04-28 06:49:12 +03:00
|
|
|
NS_WARNING("Failed to trigger an animation with an active timeline");
|
|
|
|
return;
|
|
|
|
}
|
2014-12-18 02:42:40 +03:00
|
|
|
|
2018-12-07 01:16:48 +03:00
|
|
|
FinishPendingAt(mTimeline->GetCurrentTimeAsDuration().Value());
|
2014-12-04 19:28:38 +03:00
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
Nullable<TimeDuration> Animation::GetCurrentOrPendingStartTime() const {
|
2015-02-03 08:08:37 +03:00
|
|
|
Nullable<TimeDuration> result;
|
|
|
|
|
2018-02-13 09:04:18 +03:00
|
|
|
// If we have a pending playback rate, work out what start time we will use
|
|
|
|
// when we come to updating that playback rate.
|
|
|
|
//
|
|
|
|
// This logic roughly shadows that in ResumeAt but is just different enough
|
|
|
|
// that it is difficult to extract out the common functionality (and
|
|
|
|
// extracting that functionality out would make it harder to match ResumeAt up
|
|
|
|
// against the spec).
|
|
|
|
if (mPendingPlaybackRate && !mPendingReadyTime.IsNull() &&
|
|
|
|
!mStartTime.IsNull()) {
|
|
|
|
// If we have a hold time, use it as the current time to match.
|
|
|
|
TimeDuration currentTimeToMatch =
|
|
|
|
!mHoldTime.IsNull()
|
|
|
|
? mHoldTime.Value()
|
|
|
|
: CurrentTimeFromTimelineTime(mPendingReadyTime.Value(),
|
|
|
|
mStartTime.Value(), mPlaybackRate);
|
|
|
|
|
|
|
|
result = StartTimeFromTimelineTime(
|
|
|
|
mPendingReadyTime.Value(), currentTimeToMatch, *mPendingPlaybackRate);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-02-03 08:08:37 +03:00
|
|
|
if (!mStartTime.IsNull()) {
|
|
|
|
result = mStartTime;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPendingReadyTime.IsNull() || mHoldTime.IsNull()) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the equivalent start time from the pending ready time.
|
2018-02-13 09:04:18 +03:00
|
|
|
result = StartTimeFromTimelineTime(mPendingReadyTime.Value(),
|
|
|
|
mHoldTime.Value(), mPlaybackRate);
|
2016-10-14 13:14:01 +03:00
|
|
|
|
2015-02-03 08:08:37 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-11-18 03:50:00 +03:00
|
|
|
TimeStamp Animation::AnimationTimeToTimeStamp(
|
|
|
|
const StickyTimeDuration& aTime) const {
|
|
|
|
// Initializes to null. Return the same object every time to benefit from
|
|
|
|
// return-value-optimization.
|
|
|
|
TimeStamp result;
|
|
|
|
|
|
|
|
// We *don't* check for mTimeline->TracksWallclockTime() here because that
|
|
|
|
// method only tells us if the timeline times can be converted to
|
|
|
|
// TimeStamps that can be compared to TimeStamp::Now() or not, *not*
|
|
|
|
// whether the timelines can be converted to TimeStamp values at all.
|
|
|
|
//
|
|
|
|
// Furthermore, we want to be able to use this method when the refresh driver
|
|
|
|
// is under test control (in which case TracksWallclockTime() will return
|
|
|
|
// false).
|
|
|
|
//
|
|
|
|
// Once we introduce timelines that are not time-based we will need to
|
|
|
|
// differentiate between them here and determine how to sort their events.
|
|
|
|
if (!mTimeline) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the time is convertible to a timestamp
|
|
|
|
if (aTime == TimeDuration::Forever() || mPlaybackRate == 0.0 ||
|
|
|
|
mStartTime.IsNull()) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invert the standard relation:
|
2018-02-13 09:04:18 +03:00
|
|
|
// current time = (timeline time - start time) * playback rate
|
2015-11-18 03:50:00 +03:00
|
|
|
TimeDuration timelineTime =
|
|
|
|
TimeDuration(aTime).MultDouble(1.0 / mPlaybackRate) + mStartTime.Value();
|
|
|
|
|
|
|
|
result = mTimeline->ToTimeStamp(timelineTime);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-10-19 09:16:52 +03:00
|
|
|
TimeStamp Animation::ElapsedTimeToTimeStamp(
|
|
|
|
const StickyTimeDuration& aElapsedTime) const {
|
2016-12-20 10:03:29 +03:00
|
|
|
TimeDuration delay =
|
2017-06-22 06:12:43 +03:00
|
|
|
mEffect ? mEffect->SpecifiedTiming().Delay() : TimeDuration();
|
2016-12-20 10:03:29 +03:00
|
|
|
return AnimationTimeToTimeStamp(aElapsedTime + delay);
|
2016-10-19 09:16:52 +03:00
|
|
|
}
|
|
|
|
|
2017-12-15 23:55:08 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#silently-set-the-current-time
|
2015-04-27 04:05:46 +03:00
|
|
|
void Animation::SilentlySetCurrentTime(const TimeDuration& aSeekTime) {
|
|
|
|
if (!mHoldTime.IsNull() || mStartTime.IsNull() || !mTimeline ||
|
2018-12-07 01:16:48 +03:00
|
|
|
mTimeline->GetCurrentTimeAsDuration().IsNull() || mPlaybackRate == 0.0) {
|
2015-04-27 04:05:46 +03:00
|
|
|
mHoldTime.SetValue(aSeekTime);
|
2018-12-07 01:16:48 +03:00
|
|
|
if (!mTimeline || mTimeline->GetCurrentTimeAsDuration().IsNull()) {
|
2015-04-27 04:05:46 +03:00
|
|
|
mStartTime.SetNull();
|
|
|
|
}
|
|
|
|
} else {
|
2018-12-07 01:16:48 +03:00
|
|
|
mStartTime =
|
|
|
|
StartTimeFromTimelineTime(mTimeline->GetCurrentTimeAsDuration().Value(),
|
|
|
|
aSeekTime, mPlaybackRate);
|
2015-04-27 04:05:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mPreviousCurrentTime.SetNull();
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:13:06 +03:00
|
|
|
bool Animation::ShouldBeSynchronizedWithMainThread(
|
2019-03-02 00:13:03 +03:00
|
|
|
const nsCSSPropertyIDSet& aPropertySet, const nsIFrame* aFrame,
|
2016-12-02 04:13:06 +03:00
|
|
|
AnimationPerformanceWarning::Type& aPerformanceWarning) const {
|
|
|
|
// Only synchronize playing animations
|
|
|
|
if (!IsPlaying()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Currently only transform animations need to be synchronized
|
2019-03-02 00:13:03 +03:00
|
|
|
if (!aPropertySet.Intersects(nsCSSPropertyIDSet::TransformLikeProperties())) {
|
2016-12-02 04:13:06 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
KeyframeEffect* keyframeEffect =
|
|
|
|
mEffect ? mEffect->AsKeyframeEffect() : nullptr;
|
2016-12-02 04:13:06 +03:00
|
|
|
if (!keyframeEffect) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:19:10 +03:00
|
|
|
// Are we starting at the same time as other geometric animations?
|
|
|
|
// We check this before calling ShouldBlockAsyncTransformAnimations, partly
|
|
|
|
// because it's cheaper, but also because it's often the most useful thing
|
|
|
|
// to know when you're debugging performance.
|
|
|
|
if (mSyncWithGeometricAnimations &&
|
2019-02-20 05:14:39 +03:00
|
|
|
keyframeEffect->HasAnimationOfPropertySet(
|
|
|
|
nsCSSPropertyIDSet::TransformLikeProperties())) {
|
2016-12-02 04:19:10 +03:00
|
|
|
aPerformanceWarning =
|
|
|
|
AnimationPerformanceWarning::Type::TransformWithSyncGeometricAnimations;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:13:06 +03:00
|
|
|
return keyframeEffect->ShouldBlockAsyncTransformAnimations(
|
|
|
|
aFrame, aPerformanceWarning);
|
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
void Animation::UpdateRelevance() {
|
2015-03-14 08:34:40 +03:00
|
|
|
bool wasRelevant = mIsRelevant;
|
2015-04-15 02:48:21 +03:00
|
|
|
mIsRelevant = HasCurrentEffect() || IsInEffect();
|
2015-03-14 08:34:40 +03:00
|
|
|
|
|
|
|
// Notify animation observers.
|
|
|
|
if (wasRelevant && !mIsRelevant) {
|
|
|
|
nsNodeUtils::AnimationRemoved(this);
|
|
|
|
} else if (!wasRelevant && mIsRelevant) {
|
|
|
|
nsNodeUtils::AnimationAdded(this);
|
|
|
|
}
|
2015-03-14 08:34:40 +03:00
|
|
|
}
|
|
|
|
|
2015-06-09 05:13:53 +03:00
|
|
|
bool Animation::HasLowerCompositeOrderThan(const Animation& aOther) const {
|
2016-01-14 04:24:24 +03:00
|
|
|
// 0. Object-equality case
|
|
|
|
if (&aOther == this) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 1. CSS Transitions sort lowest
|
|
|
|
{
|
|
|
|
auto asCSSTransitionForSorting =
|
|
|
|
[](const Animation& anim) -> const CSSTransition* {
|
|
|
|
const CSSTransition* transition = anim.AsCSSTransition();
|
|
|
|
return transition && transition->IsTiedToMarkup() ? transition : nullptr;
|
|
|
|
};
|
|
|
|
auto thisTransition = asCSSTransitionForSorting(*this);
|
|
|
|
auto otherTransition = asCSSTransitionForSorting(aOther);
|
|
|
|
if (thisTransition && otherTransition) {
|
|
|
|
return thisTransition->HasLowerCompositeOrderThan(*otherTransition);
|
|
|
|
}
|
|
|
|
if (thisTransition || otherTransition) {
|
2016-12-20 10:03:29 +03:00
|
|
|
// Cancelled transitions no longer have an owning element. To be strictly
|
|
|
|
// correct we should store a strong reference to the owning element
|
|
|
|
// so that if we arrive here while sorting cancel events, we can sort
|
|
|
|
// them in the correct order.
|
|
|
|
//
|
|
|
|
// However, given that cancel events are almost always queued
|
|
|
|
// synchronously in some deterministic manner, we can be fairly sure
|
|
|
|
// that cancel events will be dispatched in a deterministic order
|
|
|
|
// (which is our only hard requirement until specs say otherwise).
|
|
|
|
// Furthermore, we only reach here when we have events with equal
|
|
|
|
// timestamps so this is an edge case we can probably ignore for now.
|
2016-01-14 04:24:24 +03:00
|
|
|
return thisTransition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2. CSS Animations sort next
|
|
|
|
{
|
|
|
|
auto asCSSAnimationForSorting =
|
|
|
|
[](const Animation& anim) -> const CSSAnimation* {
|
|
|
|
const CSSAnimation* animation = anim.AsCSSAnimation();
|
|
|
|
return animation && animation->IsTiedToMarkup() ? animation : nullptr;
|
|
|
|
};
|
|
|
|
auto thisAnimation = asCSSAnimationForSorting(*this);
|
|
|
|
auto otherAnimation = asCSSAnimationForSorting(aOther);
|
|
|
|
if (thisAnimation && otherAnimation) {
|
|
|
|
return thisAnimation->HasLowerCompositeOrderThan(*otherAnimation);
|
|
|
|
}
|
|
|
|
if (thisAnimation || otherAnimation) {
|
|
|
|
return thisAnimation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Subclasses of Animation repurpose mAnimationIndex to implement their
|
|
|
|
// own brand of composite ordering. However, by this point we should have
|
|
|
|
// handled any such custom composite ordering so we should now have unique
|
|
|
|
// animation indices.
|
|
|
|
MOZ_ASSERT(mAnimationIndex != aOther.mAnimationIndex,
|
2015-09-15 05:20:26 +03:00
|
|
|
"Animation indices should be unique");
|
2015-06-09 05:13:53 +03:00
|
|
|
|
2016-01-14 04:24:24 +03:00
|
|
|
// 3. Finally, generic animations sort by their position in the global
|
|
|
|
// animation array.
|
2015-09-15 05:20:26 +03:00
|
|
|
return mAnimationIndex < aOther.mAnimationIndex;
|
2015-06-09 05:13:53 +03:00
|
|
|
}
|
|
|
|
|
2017-03-08 23:20:17 +03:00
|
|
|
void Animation::WillComposeStyle() {
|
|
|
|
mFinishedAtLastComposeStyle = (PlayState() == AnimationPlayState::Finished);
|
|
|
|
|
|
|
|
MOZ_ASSERT(mEffect);
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
KeyframeEffect* keyframeEffect = mEffect->AsKeyframeEffect();
|
2017-03-08 23:20:17 +03:00
|
|
|
if (keyframeEffect) {
|
|
|
|
keyframeEffect->WillComposeStyle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-09 14:15:59 +03:00
|
|
|
void Animation::ComposeStyle(RawServoAnimationValueMap& aComposeResult,
|
2016-10-05 08:42:56 +03:00
|
|
|
const nsCSSPropertyIDSet& aPropertiesToSkip) {
|
2015-08-07 06:29:35 +03:00
|
|
|
if (!mEffect) {
|
2014-10-20 08:55:46 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-01 06:23:25 +03:00
|
|
|
// In order to prevent flicker, there are a few cases where we want to use
|
|
|
|
// a different time for rendering that would otherwise be returned by
|
2018-12-07 01:16:48 +03:00
|
|
|
// GetCurrentTimeAsDuration. These are:
|
2015-04-01 06:23:25 +03:00
|
|
|
//
|
|
|
|
// (a) For animations that are pausing but which are still running on the
|
|
|
|
// compositor. In this case we send a layer transaction that removes the
|
|
|
|
// animation but which also contains the animation values calculated on
|
|
|
|
// the main thread. To prevent flicker when this occurs we want to ensure
|
|
|
|
// the timeline time used to calculate the main thread animation values
|
|
|
|
// does not lag far behind the time used on the compositor. Ideally we
|
|
|
|
// would like to use the "animation ready time" calculated at the end of
|
|
|
|
// the layer transaction as the timeline time but it will be too late to
|
|
|
|
// update the style rule at that point so instead we just use the current
|
|
|
|
// wallclock time.
|
|
|
|
//
|
|
|
|
// (b) For animations that are pausing that we have already taken off the
|
|
|
|
// compositor. In this case we record a pending ready time but we don't
|
|
|
|
// apply it until the next tick. However, while waiting for the next tick,
|
|
|
|
// we should still use the pending ready time as the timeline time. If we
|
|
|
|
// use the regular timeline time the animation may appear jump backwards
|
|
|
|
// if the main thread's timeline time lags behind the compositor.
|
|
|
|
//
|
|
|
|
// (c) For animations that are play-pending due to an aborted pause operation
|
|
|
|
// (i.e. a pause operation that was interrupted before we entered the
|
|
|
|
// paused state). When we cancel a pending pause we might momentarily take
|
|
|
|
// the animation off the compositor, only to re-add it moments later. In
|
|
|
|
// that case the compositor might have been ahead of the main thread so we
|
|
|
|
// should use the current wallclock time to ensure the animation doesn't
|
|
|
|
// temporarily jump backwards.
|
|
|
|
//
|
|
|
|
// To address each of these cases we temporarily tweak the hold time
|
|
|
|
// immediately before updating the style rule and then restore it immediately
|
|
|
|
// afterwards. This is purely to prevent visual flicker. Other behavior
|
|
|
|
// such as dispatching events continues to rely on the regular timeline time.
|
2017-11-21 11:10:59 +03:00
|
|
|
bool pending = Pending();
|
2015-04-01 06:23:25 +03:00
|
|
|
{
|
|
|
|
AutoRestore<Nullable<TimeDuration>> restoreHoldTime(mHoldTime);
|
2015-04-02 06:30:17 +03:00
|
|
|
|
2017-11-21 11:10:59 +03:00
|
|
|
if (pending && mHoldTime.IsNull() && !mStartTime.IsNull()) {
|
2015-04-01 06:23:25 +03:00
|
|
|
Nullable<TimeDuration> timeToUse = mPendingReadyTime;
|
2015-04-28 05:17:10 +03:00
|
|
|
if (timeToUse.IsNull() && mTimeline && mTimeline->TracksWallclockTime()) {
|
2015-04-01 06:23:25 +03:00
|
|
|
timeToUse = mTimeline->ToTimelineTime(TimeStamp::Now());
|
|
|
|
}
|
|
|
|
if (!timeToUse.IsNull()) {
|
2018-02-13 09:04:18 +03:00
|
|
|
mHoldTime = CurrentTimeFromTimelineTime(
|
|
|
|
timeToUse.Value(), mStartTime.Value(), mPlaybackRate);
|
2015-04-01 06:23:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
KeyframeEffect* keyframeEffect = mEffect->AsKeyframeEffect();
|
2016-07-25 11:56:34 +03:00
|
|
|
if (keyframeEffect) {
|
2018-04-09 14:15:59 +03:00
|
|
|
keyframeEffect->ComposeStyle(aComposeResult, aPropertiesToSkip);
|
2016-07-25 11:56:34 +03:00
|
|
|
}
|
2015-09-28 06:38:41 +03:00
|
|
|
}
|
2015-04-01 06:23:25 +03:00
|
|
|
|
2017-11-21 11:10:59 +03:00
|
|
|
MOZ_ASSERT(
|
|
|
|
pending == Pending(),
|
|
|
|
"Pending state should not change during the course of compositing");
|
2014-10-20 08:55:46 +04:00
|
|
|
}
|
|
|
|
|
2015-08-17 21:28:00 +03:00
|
|
|
void Animation::NotifyEffectTimingUpdated() {
|
|
|
|
MOZ_ASSERT(mEffect,
|
|
|
|
"We should only update timing effect when we have a target "
|
|
|
|
"effect");
|
|
|
|
UpdateTiming(Animation::SeekFlag::NoSeek, Animation::SyncNotifyFlag::Async);
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:19:10 +03:00
|
|
|
void Animation::NotifyGeometricAnimationsStartingThisFrame() {
|
|
|
|
if (!IsNewlyStarted() || !mEffect) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mSyncWithGeometricAnimations = true;
|
|
|
|
}
|
|
|
|
|
2017-12-15 23:55:08 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#play-an-animation
|
2016-05-31 03:42:37 +03:00
|
|
|
void Animation::PlayNoUpdate(ErrorResult& aRv, LimitBehavior aLimitBehavior) {
|
2015-10-22 09:16:18 +03:00
|
|
|
AutoMutationBatchForAnimation mb(*this);
|
|
|
|
|
2015-04-01 06:23:25 +03:00
|
|
|
bool abortedPause = mPendingState == PendingState::PausePending;
|
|
|
|
|
2018-02-13 09:04:18 +03:00
|
|
|
double effectivePlaybackRate = CurrentOrPendingPlaybackRate();
|
|
|
|
|
2018-12-07 01:16:48 +03:00
|
|
|
Nullable<TimeDuration> currentTime = GetCurrentTimeAsDuration();
|
2018-02-13 09:04:18 +03:00
|
|
|
if (effectivePlaybackRate > 0.0 &&
|
2015-03-18 16:22:11 +03:00
|
|
|
(currentTime.IsNull() || (aLimitBehavior == LimitBehavior::AutoRewind &&
|
2016-08-27 10:53:33 +03:00
|
|
|
(currentTime.Value() < TimeDuration() ||
|
2015-04-15 02:48:21 +03:00
|
|
|
currentTime.Value() >= EffectEnd())))) {
|
2014-12-04 19:28:37 +03:00
|
|
|
mHoldTime.SetValue(TimeDuration(0));
|
2018-02-13 09:04:18 +03:00
|
|
|
} else if (effectivePlaybackRate < 0.0 &&
|
2015-03-18 16:22:11 +03:00
|
|
|
(currentTime.IsNull() ||
|
|
|
|
(aLimitBehavior == LimitBehavior::AutoRewind &&
|
2016-08-27 10:53:33 +03:00
|
|
|
(currentTime.Value() <= TimeDuration() ||
|
2015-04-15 02:48:21 +03:00
|
|
|
currentTime.Value() > EffectEnd())))) {
|
2015-05-19 08:00:48 +03:00
|
|
|
if (EffectEnd() == TimeDuration::Forever()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2015-04-15 02:48:21 +03:00
|
|
|
mHoldTime.SetValue(TimeDuration(EffectEnd()));
|
2018-02-13 09:04:18 +03:00
|
|
|
} else if (effectivePlaybackRate == 0.0 && currentTime.IsNull()) {
|
2015-03-13 23:10:45 +03:00
|
|
|
mHoldTime.SetValue(TimeDuration(0));
|
|
|
|
}
|
|
|
|
|
2015-05-19 08:00:48 +03:00
|
|
|
bool reuseReadyPromise = false;
|
|
|
|
if (mPendingState != PendingState::NotPending) {
|
|
|
|
CancelPendingTasks();
|
|
|
|
reuseReadyPromise = true;
|
|
|
|
}
|
|
|
|
|
2018-02-13 09:04:18 +03:00
|
|
|
// If the hold time is null then we're already playing normally and,
|
|
|
|
// typically, we can bail out here.
|
|
|
|
//
|
|
|
|
// However, there are two cases where we can't do that:
|
|
|
|
//
|
|
|
|
// (a) If we just aborted a pause. In this case, for consistency, we need to
|
|
|
|
// go through the motions of doing an asynchronous start.
|
|
|
|
//
|
|
|
|
// (b) If we have timing changes (specifically a change to the playbackRate)
|
|
|
|
// that should be applied asynchronously.
|
|
|
|
//
|
|
|
|
if (mHoldTime.IsNull() && !abortedPause && !mPendingPlaybackRate) {
|
2014-11-17 07:46:01 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-08 10:17:13 +03:00
|
|
|
// Clear the start time until we resolve a new one. We do this except
|
|
|
|
// for the case where we are aborting a pause and don't have a hold time.
|
|
|
|
//
|
|
|
|
// If we're aborting a pause and *do* have a hold time (e.g. because
|
|
|
|
// the animation is finished or we just applied the auto-rewind behavior
|
|
|
|
// above) we should respect it by clearing the start time. If we *don't*
|
|
|
|
// have a hold time we should keep the current start time so that the
|
|
|
|
// the animation continues moving uninterrupted by the aborted pause.
|
|
|
|
//
|
|
|
|
// (If we're not aborting a pause, mHoldTime must be resolved by now
|
|
|
|
// or else we would have returned above.)
|
|
|
|
if (!mHoldTime.IsNull()) {
|
2015-04-01 06:23:25 +03:00
|
|
|
mStartTime.SetNull();
|
|
|
|
}
|
2015-03-24 03:21:08 +03:00
|
|
|
|
2015-03-27 09:56:45 +03:00
|
|
|
if (!reuseReadyPromise) {
|
|
|
|
// Clear ready promise. We'll create a new one lazily.
|
|
|
|
mReady = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-03-27 09:56:45 +03:00
|
|
|
mPendingState = PendingState::PlayPending;
|
2014-12-25 10:28:24 +03:00
|
|
|
|
2016-12-02 04:19:10 +03:00
|
|
|
// Clear flag that causes us to sync transform animations with the main
|
|
|
|
// thread for now. We'll set this when we go to set up compositor
|
|
|
|
// animations if it applies.
|
|
|
|
mSyncWithGeometricAnimations = false;
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
if (Document* doc = GetRenderedDocument()) {
|
2015-06-09 05:13:53 +03:00
|
|
|
PendingAnimationTracker* tracker =
|
|
|
|
doc->GetOrCreatePendingAnimationTracker();
|
|
|
|
tracker->AddPlayPending(*this);
|
|
|
|
} else {
|
2015-03-27 09:56:45 +03:00
|
|
|
TriggerOnNextTick(Nullable<TimeDuration>());
|
2014-12-25 10:28:24 +03:00
|
|
|
}
|
|
|
|
|
2015-07-30 00:21:00 +03:00
|
|
|
UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async);
|
2015-10-22 09:16:18 +03:00
|
|
|
if (IsRelevant()) {
|
|
|
|
nsNodeUtils::AnimationChanged(this);
|
|
|
|
}
|
2014-11-17 07:46:01 +03:00
|
|
|
}
|
|
|
|
|
2017-12-15 23:55:08 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#pause-an-animation
|
2018-03-07 05:48:35 +03:00
|
|
|
void Animation::Pause(ErrorResult& aRv) {
|
2015-04-14 03:07:41 +03:00
|
|
|
if (IsPausedOrPausing()) {
|
2015-04-01 06:23:25 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-22 09:16:18 +03:00
|
|
|
AutoMutationBatchForAnimation mb(*this);
|
|
|
|
|
2015-05-19 08:55:26 +03:00
|
|
|
// If we are transitioning from idle, fill in the current time
|
2018-12-07 01:16:48 +03:00
|
|
|
if (GetCurrentTimeAsDuration().IsNull()) {
|
2015-05-19 08:55:26 +03:00
|
|
|
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()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-01 06:23:25 +03:00
|
|
|
bool reuseReadyPromise = false;
|
2015-03-27 09:56:45 +03:00
|
|
|
if (mPendingState == PendingState::PlayPending) {
|
2015-03-27 09:56:45 +03:00
|
|
|
CancelPendingTasks();
|
2015-04-01 06:23:25 +03:00
|
|
|
reuseReadyPromise = true;
|
2014-11-17 07:46:01 +03:00
|
|
|
}
|
2014-12-18 02:42:41 +03:00
|
|
|
|
2015-04-01 06:23:25 +03:00
|
|
|
if (!reuseReadyPromise) {
|
|
|
|
// Clear ready promise. We'll create a new one lazily.
|
|
|
|
mReady = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPendingState = PendingState::PausePending;
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
if (Document* doc = GetRenderedDocument()) {
|
2015-06-09 05:13:53 +03:00
|
|
|
PendingAnimationTracker* tracker =
|
|
|
|
doc->GetOrCreatePendingAnimationTracker();
|
|
|
|
tracker->AddPausePending(*this);
|
|
|
|
} else {
|
2015-04-01 06:23:25 +03:00
|
|
|
TriggerOnNextTick(Nullable<TimeDuration>());
|
|
|
|
}
|
|
|
|
|
2015-07-30 00:21:00 +03:00
|
|
|
UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async);
|
2015-10-22 09:16:18 +03:00
|
|
|
if (IsRelevant()) {
|
|
|
|
nsNodeUtils::AnimationChanged(this);
|
|
|
|
}
|
2018-03-07 05:48:35 +03:00
|
|
|
|
|
|
|
PostUpdate();
|
2014-11-17 07:46:01 +03:00
|
|
|
}
|
|
|
|
|
2018-02-13 09:04:18 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#play-an-animation
|
2015-04-21 04:22:09 +03:00
|
|
|
void Animation::ResumeAt(const TimeDuration& aReadyTime) {
|
2015-04-21 04:22:09 +03:00
|
|
|
// This method is only expected to be called for an animation that is
|
2015-01-09 01:57:58 +03:00
|
|
|
// waiting to play. We can easily adapt it to handle other states
|
|
|
|
// but it's currently not necessary.
|
2015-03-27 09:56:45 +03:00
|
|
|
MOZ_ASSERT(mPendingState == PendingState::PlayPending,
|
2015-04-21 04:22:09 +03:00
|
|
|
"Expected to resume a play-pending animation");
|
2017-10-05 04:50:38 +03:00
|
|
|
MOZ_ASSERT(!mHoldTime.IsNull() || !mStartTime.IsNull(),
|
2015-04-21 04:22:09 +03:00
|
|
|
"An animation in the play-pending state should have either a"
|
2017-10-05 04:50:38 +03:00
|
|
|
" resolved hold time or resolved start time");
|
2015-01-09 01:57:58 +03:00
|
|
|
|
2018-02-13 09:04:18 +03:00
|
|
|
AutoMutationBatchForAnimation mb(*this);
|
|
|
|
bool hadPendingPlaybackRate = mPendingPlaybackRate.isSome();
|
|
|
|
|
|
|
|
if (!mHoldTime.IsNull()) {
|
|
|
|
// The hold time is set, so we don't need any special handling to preserve
|
|
|
|
// the current time.
|
|
|
|
ApplyPendingPlaybackRate();
|
2018-02-13 09:04:18 +03:00
|
|
|
mStartTime =
|
|
|
|
StartTimeFromTimelineTime(aReadyTime, mHoldTime.Value(), mPlaybackRate);
|
2015-04-01 06:23:25 +03:00
|
|
|
if (mPlaybackRate != 0) {
|
|
|
|
mHoldTime.SetNull();
|
|
|
|
}
|
2018-02-13 09:04:18 +03:00
|
|
|
} else if (!mStartTime.IsNull() && mPendingPlaybackRate) {
|
|
|
|
// Apply any pending playback rate, preserving the current time.
|
|
|
|
TimeDuration currentTimeToMatch = CurrentTimeFromTimelineTime(
|
|
|
|
aReadyTime, mStartTime.Value(), mPlaybackRate);
|
|
|
|
ApplyPendingPlaybackRate();
|
|
|
|
mStartTime = StartTimeFromTimelineTime(aReadyTime, currentTimeToMatch,
|
|
|
|
mPlaybackRate);
|
|
|
|
if (mPlaybackRate == 0) {
|
|
|
|
mHoldTime.SetValue(currentTimeToMatch);
|
|
|
|
}
|
2015-03-13 23:10:45 +03:00
|
|
|
}
|
2018-02-13 09:04:18 +03:00
|
|
|
|
2015-03-27 09:56:45 +03:00
|
|
|
mPendingState = PendingState::NotPending;
|
2015-01-09 01:57:58 +03:00
|
|
|
|
2015-07-30 00:21:00 +03:00
|
|
|
UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async);
|
2015-01-09 01:57:58 +03:00
|
|
|
|
2018-02-13 09:04:18 +03:00
|
|
|
// If we had a pending playback rate, we will have now applied it so we need
|
|
|
|
// to notify observers.
|
|
|
|
if (hadPendingPlaybackRate && IsRelevant()) {
|
|
|
|
nsNodeUtils::AnimationChanged(this);
|
|
|
|
}
|
|
|
|
|
2015-01-09 01:57:58 +03:00
|
|
|
if (mReady) {
|
|
|
|
mReady->MaybeResolve(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
void Animation::PauseAt(const TimeDuration& aReadyTime) {
|
2015-04-01 06:23:24 +03:00
|
|
|
MOZ_ASSERT(mPendingState == PendingState::PausePending,
|
2015-04-21 04:22:09 +03:00
|
|
|
"Expected to pause a pause-pending animation");
|
2015-04-01 06:23:24 +03:00
|
|
|
|
2015-11-02 02:33:58 +03:00
|
|
|
if (!mStartTime.IsNull() && mHoldTime.IsNull()) {
|
2018-02-13 09:04:18 +03:00
|
|
|
mHoldTime = CurrentTimeFromTimelineTime(aReadyTime, mStartTime.Value(),
|
|
|
|
mPlaybackRate);
|
2015-04-01 06:23:24 +03:00
|
|
|
}
|
2018-02-13 09:04:18 +03:00
|
|
|
ApplyPendingPlaybackRate();
|
2015-04-01 06:23:24 +03:00
|
|
|
mStartTime.SetNull();
|
|
|
|
mPendingState = PendingState::NotPending;
|
|
|
|
|
2015-07-30 00:21:00 +03:00
|
|
|
UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async);
|
2015-04-01 06:23:24 +03:00
|
|
|
|
|
|
|
if (mReady) {
|
|
|
|
mReady->MaybeResolve(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-30 00:21:00 +03:00
|
|
|
void Animation::UpdateTiming(SeekFlag aSeekFlag,
|
|
|
|
SyncNotifyFlag aSyncNotifyFlag) {
|
2015-04-15 02:48:21 +03:00
|
|
|
// We call UpdateFinishedState before UpdateEffect because the former
|
2015-03-18 16:22:11 +03:00
|
|
|
// can change the current time, which is used by the latter.
|
2015-07-30 00:21:00 +03:00
|
|
|
UpdateFinishedState(aSeekFlag, aSyncNotifyFlag);
|
2019-04-18 09:49:25 +03:00
|
|
|
UpdateEffect(PostRestyleMode::IfNeeded);
|
2015-06-15 05:05:43 +03:00
|
|
|
|
|
|
|
if (mTimeline) {
|
Bug 1195180 part 6 - Lazily remove animations from timelines; r=heycam
Now that DocumentTimeline observes the refresh driver we can use regular
ticks to remove unnecessary animations.
We do this because in a subsequent patch, in order to provide deterministic
enumeration order when ticking animations, we will store animations in an array.
Removing an arbitrary element from an nsTArray is O(n) since we have to search
for the array index first, or O(log n) if we keep the array sorted. If we
destroy a subtree containing n animations, the operation effectively becomes
O(n^2), or, if we keep the array sorted, O(n log n). By destroying during a
tick when we are already iterating over the array, however, we will be able
to do this much more efficiently.
Whether an animation is newly associated with a timeline, or is disassociated
from a timeline, or if it merely has its timing updated, the behavior
implemented in this patch is to simply make sure we are observing the refresh
driver and deal with the animation on the next tick.
It might seem that we could be a lot more clever about this and, for example, if
an animation reports NeedsTicks() == false, not start observing the refresh
driver. There are various edge cases however that need to be taken into account.
For example, if a CSS animation is finished (IsRelevant() == false so that
animation will have been removed from the timeline), and paused
(NeedsTicks() == false), and we seek it back to the point where it is relevant
again, we actually need to observe the refresh driver so that it can dispatch an
animationstart event on the next tick. A test case in a subsequent patch tests
this specific situation.
We could possibly add logic to detect if we need to fire events on the next tick
but the complexity does not seem warranted given that even if we unnecessarily
start observing the refresh driver, we will stop watching it on the next tick.
This patch removes some rather lengthy comments from
AnimationTiming::UpdateTiming. This is, in part, because of the behavior
described above that makes these comments no longer relevant. Other parts are
removed because the Web Animations specification has been updated such that a
timeline becoming inactive now pauses the animation[1] so that the issue
regarding detecting timelines becoming active/inactive no longer applies
since animations attached to an inactive timeline remain "relevant".
[1] https://w3c.github.io/web-animations/#responding-to-a-newly-inactive-timeline
2015-09-28 06:38:41 +03:00
|
|
|
mTimeline->NotifyAnimationUpdated(*this);
|
2015-06-15 05:05:43 +03:00
|
|
|
}
|
2015-03-18 16:22:11 +03:00
|
|
|
}
|
|
|
|
|
2017-12-15 23:55:08 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#update-an-animations-finished-state
|
2015-07-30 00:21:00 +03:00
|
|
|
void Animation::UpdateFinishedState(SeekFlag aSeekFlag,
|
|
|
|
SyncNotifyFlag aSyncNotifyFlag) {
|
2018-12-07 01:16:48 +03:00
|
|
|
Nullable<TimeDuration> currentTime = GetCurrentTimeAsDuration();
|
2015-04-15 02:48:21 +03:00
|
|
|
TimeDuration effectEnd = TimeDuration(EffectEnd());
|
2015-03-18 16:22:11 +03:00
|
|
|
|
|
|
|
if (!mStartTime.IsNull() && mPendingState == PendingState::NotPending) {
|
|
|
|
if (mPlaybackRate > 0.0 && !currentTime.IsNull() &&
|
2015-04-15 02:48:21 +03:00
|
|
|
currentTime.Value() >= effectEnd) {
|
2015-05-11 11:17:06 +03:00
|
|
|
if (aSeekFlag == SeekFlag::DidSeek) {
|
2015-03-18 16:22:11 +03:00
|
|
|
mHoldTime = currentTime;
|
|
|
|
} else if (!mPreviousCurrentTime.IsNull()) {
|
2015-04-15 02:48:21 +03:00
|
|
|
mHoldTime.SetValue(std::max(mPreviousCurrentTime.Value(), effectEnd));
|
2015-03-18 16:22:11 +03:00
|
|
|
} else {
|
2015-04-15 02:48:21 +03:00
|
|
|
mHoldTime.SetValue(effectEnd);
|
2015-03-18 16:22:11 +03:00
|
|
|
}
|
|
|
|
} else if (mPlaybackRate < 0.0 && !currentTime.IsNull() &&
|
2016-08-27 10:53:33 +03:00
|
|
|
currentTime.Value() <= TimeDuration()) {
|
2015-05-11 11:17:06 +03:00
|
|
|
if (aSeekFlag == SeekFlag::DidSeek) {
|
2015-03-18 16:22:11 +03:00
|
|
|
mHoldTime = currentTime;
|
2016-08-19 05:35:16 +03:00
|
|
|
} else if (!mPreviousCurrentTime.IsNull()) {
|
|
|
|
mHoldTime.SetValue(
|
|
|
|
std::min(mPreviousCurrentTime.Value(), TimeDuration(0)));
|
2015-03-18 16:22:11 +03:00
|
|
|
} else {
|
|
|
|
mHoldTime.SetValue(0);
|
|
|
|
}
|
|
|
|
} else if (mPlaybackRate != 0.0 && !currentTime.IsNull() && mTimeline &&
|
2018-12-07 01:16:48 +03:00
|
|
|
!mTimeline->GetCurrentTimeAsDuration().IsNull()) {
|
2015-05-11 11:17:06 +03:00
|
|
|
if (aSeekFlag == SeekFlag::DidSeek && !mHoldTime.IsNull()) {
|
2018-12-07 01:16:48 +03:00
|
|
|
mStartTime = StartTimeFromTimelineTime(
|
|
|
|
mTimeline->GetCurrentTimeAsDuration().Value(), mHoldTime.Value(),
|
|
|
|
mPlaybackRate);
|
2015-03-18 16:22:11 +03:00
|
|
|
}
|
|
|
|
mHoldTime.SetNull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-19 02:51:13 +03:00
|
|
|
bool currentFinishedState = PlayState() == AnimationPlayState::Finished;
|
2015-07-30 00:21:00 +03:00
|
|
|
if (currentFinishedState && !mFinishedIsResolved) {
|
|
|
|
DoFinishNotification(aSyncNotifyFlag);
|
|
|
|
} else if (!currentFinishedState && mFinishedIsResolved) {
|
|
|
|
ResetFinishedPromise();
|
2015-03-18 16:22:11 +03:00
|
|
|
}
|
2015-03-23 16:23:19 +03:00
|
|
|
// We must recalculate the current time to take account of any mHoldTime
|
|
|
|
// changes the code above made.
|
2018-12-07 01:16:48 +03:00
|
|
|
mPreviousCurrentTime = GetCurrentTimeAsDuration();
|
2015-03-18 16:22:11 +03:00
|
|
|
}
|
|
|
|
|
2019-04-18 09:49:25 +03:00
|
|
|
void Animation::UpdateEffect(PostRestyleMode aPostRestyle) {
|
2015-04-15 02:48:21 +03:00
|
|
|
if (mEffect) {
|
2015-03-14 08:34:40 +03:00
|
|
|
UpdateRelevance();
|
2016-07-13 13:44:19 +03:00
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
KeyframeEffect* keyframeEffect = mEffect->AsKeyframeEffect();
|
2016-07-13 13:44:19 +03:00
|
|
|
if (keyframeEffect) {
|
2019-04-18 09:49:25 +03:00
|
|
|
keyframeEffect->NotifyAnimationTimingUpdated(aPostRestyle);
|
2016-07-13 13:44:19 +03:00
|
|
|
}
|
2014-12-22 03:35:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 12:01:14 +03:00
|
|
|
void Animation::FlushUnanimatedStyle() const {
|
2019-01-02 16:05:23 +03:00
|
|
|
if (Document* doc = GetRenderedDocument()) {
|
2018-04-11 12:01:14 +03:00
|
|
|
doc->FlushPendingNotifications(
|
|
|
|
ChangesToFlush(FlushType::Style, false /* flush animations */));
|
2014-10-20 08:55:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
void Animation::PostUpdate() {
|
2016-07-25 11:56:34 +03:00
|
|
|
if (!mEffect) {
|
2016-01-13 01:54:54 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
KeyframeEffect* keyframeEffect = mEffect->AsKeyframeEffect();
|
2016-07-25 11:56:34 +03:00
|
|
|
if (!keyframeEffect) {
|
2016-07-12 06:42:49 +03:00
|
|
|
return;
|
|
|
|
}
|
2017-03-14 19:33:22 +03:00
|
|
|
keyframeEffect->RequestRestyle(EffectCompositor::RestyleType::Layer);
|
2014-11-17 07:45:59 +03:00
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
void Animation::CancelPendingTasks() {
|
2015-03-27 09:56:45 +03:00
|
|
|
if (mPendingState == PendingState::NotPending) {
|
2014-12-18 02:42:41 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
if (Document* doc = GetRenderedDocument()) {
|
2015-04-21 04:22:09 +03:00
|
|
|
PendingAnimationTracker* tracker = doc->GetPendingAnimationTracker();
|
2014-12-18 02:42:41 +03:00
|
|
|
if (tracker) {
|
2015-03-27 09:56:45 +03:00
|
|
|
if (mPendingState == PendingState::PlayPending) {
|
|
|
|
tracker->RemovePlayPending(*this);
|
|
|
|
} else {
|
|
|
|
tracker->RemovePausePending(*this);
|
|
|
|
}
|
2014-12-18 02:42:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-27 09:56:45 +03:00
|
|
|
mPendingState = PendingState::NotPending;
|
2015-01-09 01:57:58 +03:00
|
|
|
mPendingReadyTime.SetNull();
|
2014-12-18 02:42:41 +03:00
|
|
|
}
|
|
|
|
|
2017-12-15 23:55:08 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#reset-an-animations-pending-tasks
|
2016-07-15 12:17:25 +03:00
|
|
|
void Animation::ResetPendingTasks() {
|
|
|
|
if (mPendingState == PendingState::NotPending) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CancelPendingTasks();
|
2018-02-13 09:04:18 +03:00
|
|
|
ApplyPendingPlaybackRate();
|
|
|
|
|
2016-07-15 12:17:25 +03:00
|
|
|
if (mReady) {
|
|
|
|
mReady->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
|
2017-06-12 04:45:48 +03:00
|
|
|
mReady = nullptr;
|
2016-07-15 12:17:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-12 11:05:13 +03:00
|
|
|
void Animation::ReschedulePendingTasks() {
|
2018-07-12 11:05:34 +03:00
|
|
|
if (mPendingState == PendingState::NotPending) {
|
2018-07-12 11:05:13 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPendingReadyTime.SetNull();
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
if (Document* doc = GetRenderedDocument()) {
|
2018-07-12 11:05:13 +03:00
|
|
|
PendingAnimationTracker* tracker =
|
|
|
|
doc->GetOrCreatePendingAnimationTracker();
|
2018-07-12 11:05:34 +03:00
|
|
|
if (mPendingState == PendingState::PlayPending &&
|
|
|
|
!tracker->IsWaitingToPlay(*this)) {
|
2018-07-12 11:05:13 +03:00
|
|
|
tracker->AddPlayPending(*this);
|
2018-07-12 11:05:34 +03:00
|
|
|
} else if (mPendingState == PendingState::PausePending &&
|
|
|
|
!tracker->IsWaitingToPause(*this)) {
|
2018-07-12 11:05:13 +03:00
|
|
|
tracker->AddPausePending(*this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
bool Animation::IsPossiblyOrphanedPendingAnimation() const {
|
2015-01-09 01:57:58 +03:00
|
|
|
// Check if we are pending but might never start because we are not being
|
|
|
|
// tracked.
|
|
|
|
//
|
|
|
|
// This covers the following cases:
|
|
|
|
//
|
2015-04-15 02:48:21 +03:00
|
|
|
// * We started playing but our effect's target element was orphaned
|
2015-01-09 01:57:58 +03:00
|
|
|
// or bound to a different document.
|
2015-04-15 02:48:21 +03:00
|
|
|
// (note that for the case of our effect changing we should handle
|
|
|
|
// that in SetEffect)
|
2015-01-09 01:57:58 +03:00
|
|
|
// * We started playing but our timeline became inactive.
|
2015-04-21 04:22:09 +03:00
|
|
|
// In this case the pending animation tracker will drop us from its hashmap
|
2015-01-09 01:57:58 +03:00
|
|
|
// when we have been painted.
|
2015-04-21 04:22:09 +03:00
|
|
|
// * When we started playing we couldn't find a PendingAnimationTracker to
|
2015-04-15 02:48:21 +03:00
|
|
|
// register with (perhaps the effect had no document) so we simply
|
2016-05-31 03:42:37 +03:00
|
|
|
// set mPendingState in PlayNoUpdate and relied on this method to catch us
|
|
|
|
// on the next tick.
|
2015-01-09 01:57:58 +03:00
|
|
|
|
|
|
|
// If we're not pending we're ok.
|
2015-03-27 09:56:45 +03:00
|
|
|
if (mPendingState == PendingState::NotPending) {
|
2015-01-09 01:57:58 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have a pending ready time then we will be started on the next
|
|
|
|
// tick.
|
|
|
|
if (!mPendingReadyTime.IsNull()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we don't have an active timeline then we shouldn't start until
|
|
|
|
// we do.
|
2018-12-07 01:16:48 +03:00
|
|
|
if (!mTimeline || mTimeline->GetCurrentTimeAsDuration().IsNull()) {
|
2015-01-09 01:57:58 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have no rendered document, or we're not in our rendered document's
|
2015-04-21 04:22:09 +03:00
|
|
|
// PendingAnimationTracker then there's a good chance no one is tracking us.
|
2015-01-09 01:57:58 +03:00
|
|
|
//
|
|
|
|
// If we're wrong and another document is tracking us then, at worst, we'll
|
2015-03-27 09:56:45 +03:00
|
|
|
// simply start/pause the animation one tick too soon. That's better than
|
|
|
|
// never starting/pausing the animation and is unlikely.
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = GetRenderedDocument();
|
2015-03-27 09:56:45 +03:00
|
|
|
if (!doc) {
|
2015-04-28 09:47:45 +03:00
|
|
|
return true;
|
2015-03-27 09:56:45 +03:00
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
PendingAnimationTracker* tracker = doc->GetPendingAnimationTracker();
|
2015-03-27 09:56:45 +03:00
|
|
|
return !tracker || (!tracker->IsWaitingToPlay(*this) &&
|
|
|
|
!tracker->IsWaitingToPause(*this));
|
2015-01-09 01:57:58 +03:00
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
StickyTimeDuration Animation::EffectEnd() const {
|
2015-04-15 02:48:21 +03:00
|
|
|
if (!mEffect) {
|
2014-10-20 08:55:45 +04:00
|
|
|
return StickyTimeDuration(0);
|
|
|
|
}
|
|
|
|
|
2016-04-14 13:39:44 +03:00
|
|
|
return mEffect->SpecifiedTiming().EndTime();
|
2014-10-20 08:55:45 +04:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* Animation::GetRenderedDocument() const {
|
2016-07-25 11:56:34 +03:00
|
|
|
if (!mEffect || !mEffect->AsKeyframeEffect()) {
|
2014-11-17 07:45:58 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2015-11-06 04:51:00 +03:00
|
|
|
|
2016-07-25 11:56:34 +03:00
|
|
|
return mEffect->AsKeyframeEffect()->GetRenderedDocument();
|
2014-11-17 07:45:58 +03:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* Animation::GetTimelineDocument() const {
|
2018-07-03 05:05:23 +03:00
|
|
|
return mTimeline ? mTimeline->GetDocument() : nullptr;
|
|
|
|
}
|
|
|
|
|
2017-11-17 06:01:27 +03:00
|
|
|
class AsyncFinishNotification : public MicroTaskRunnable {
|
|
|
|
public:
|
|
|
|
explicit AsyncFinishNotification(Animation* aAnimation)
|
|
|
|
: MicroTaskRunnable(), mAnimation(aAnimation) {}
|
|
|
|
|
|
|
|
virtual void Run(AutoSlowOperation& aAso) override {
|
|
|
|
mAnimation->DoFinishNotificationImmediately(this);
|
|
|
|
mAnimation = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Suppressed() override {
|
|
|
|
nsIGlobalObject* global = mAnimation->GetOwnerGlobal();
|
|
|
|
return global && global->IsInSyncOperation();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<Animation> mAnimation;
|
|
|
|
};
|
|
|
|
|
2015-07-30 00:21:00 +03:00
|
|
|
void Animation::DoFinishNotification(SyncNotifyFlag aSyncNotifyFlag) {
|
2016-09-14 16:47:32 +03:00
|
|
|
CycleCollectedJSContext* context = CycleCollectedJSContext::Get();
|
2016-03-24 18:12:00 +03:00
|
|
|
|
2015-07-30 00:21:00 +03:00
|
|
|
if (aSyncNotifyFlag == SyncNotifyFlag::Sync) {
|
2015-07-31 00:25:00 +03:00
|
|
|
DoFinishNotificationImmediately();
|
2017-11-17 06:01:27 +03:00
|
|
|
} else if (!mFinishNotificationTask) {
|
|
|
|
RefPtr<MicroTaskRunnable> runnable = new AsyncFinishNotification(this);
|
2016-09-14 16:47:32 +03:00
|
|
|
context->DispatchToMicroTask(do_AddRef(runnable));
|
2016-07-06 01:49:06 +03:00
|
|
|
mFinishNotificationTask = runnable.forget();
|
2015-07-30 00:21:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::ResetFinishedPromise() {
|
|
|
|
mFinishedIsResolved = false;
|
|
|
|
mFinished = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::MaybeResolveFinishedPromise() {
|
2015-07-31 00:25:00 +03:00
|
|
|
if (mFinished) {
|
|
|
|
mFinished->MaybeResolve(this);
|
|
|
|
}
|
|
|
|
mFinishedIsResolved = true;
|
|
|
|
}
|
|
|
|
|
2017-11-17 06:01:27 +03:00
|
|
|
void Animation::DoFinishNotificationImmediately(MicroTaskRunnable* aAsync) {
|
|
|
|
if (aAsync && aAsync != mFinishNotificationTask) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mFinishNotificationTask = nullptr;
|
2015-07-30 00:21:00 +03:00
|
|
|
|
|
|
|
if (PlayState() != AnimationPlayState::Finished) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:25:00 +03:00
|
|
|
MaybeResolveFinishedPromise();
|
|
|
|
|
2018-07-03 05:05:23 +03:00
|
|
|
QueuePlaybackEvent(NS_LITERAL_STRING("finish"),
|
|
|
|
AnimationTimeToTimeStamp(EffectEnd()));
|
2015-07-31 00:25:00 +03:00
|
|
|
}
|
|
|
|
|
2018-07-03 05:05:23 +03:00
|
|
|
void Animation::QueuePlaybackEvent(const nsAString& aName,
|
|
|
|
TimeStamp&& aScheduledEventTime) {
|
|
|
|
// Use document for timing.
|
|
|
|
// https://drafts.csswg.org/web-animations-1/#document-for-timing
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = GetTimelineDocument();
|
2018-07-03 05:05:23 +03:00
|
|
|
if (!doc) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext* presContext = doc->GetPresContext();
|
|
|
|
if (!presContext) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:25:00 +03:00
|
|
|
AnimationPlaybackEventInit init;
|
|
|
|
|
2015-07-31 00:26:00 +03:00
|
|
|
if (aName.EqualsLiteral("finish")) {
|
|
|
|
init.mCurrentTime = GetCurrentTimeAsDouble();
|
|
|
|
}
|
2015-07-31 00:25:00 +03:00
|
|
|
if (mTimeline) {
|
|
|
|
init.mTimelineTime = mTimeline->GetCurrentTimeAsDouble();
|
2015-07-30 00:21:00 +03:00
|
|
|
}
|
2015-07-31 00:25:00 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AnimationPlaybackEvent> event =
|
2015-07-31 00:25:00 +03:00
|
|
|
AnimationPlaybackEvent::Constructor(this, aName, init);
|
|
|
|
event->SetTrusted(true);
|
|
|
|
|
2018-07-03 05:05:23 +03:00
|
|
|
presContext->AnimationEventDispatcher()->QueueEvent(AnimationEventInfo(
|
|
|
|
aName, std::move(event), std::move(aScheduledEventTime), this));
|
2015-07-30 00:21:00 +03:00
|
|
|
}
|
|
|
|
|
2015-09-16 17:05:00 +03:00
|
|
|
bool Animation::IsRunningOnCompositor() const {
|
2016-07-25 11:56:34 +03:00
|
|
|
return mEffect && mEffect->AsKeyframeEffect() &&
|
|
|
|
mEffect->AsKeyframeEffect()->IsRunningOnCompositor();
|
2015-09-16 17:05:00 +03:00
|
|
|
}
|
|
|
|
|
2014-08-10 11:06:44 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|