2015-05-03 19:32:37 +00: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 07:06:44 +00: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 01:22:09 +00:00
|
|
|
#include "Animation.h"
|
2014-08-30 06:11:57 +00:00
|
|
|
#include "AnimationUtils.h"
|
2015-04-21 01:22:09 +00:00
|
|
|
#include "mozilla/dom/AnimationBinding.h"
|
2015-04-01 03:23:25 +00:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2015-04-21 01:22:10 +00:00
|
|
|
#include "AnimationCommon.h" // For AnimationCollection,
|
2014-11-17 04:45:59 +00:00
|
|
|
// CommonAnimationManager
|
2014-11-17 04:45:58 +00:00
|
|
|
#include "nsIDocument.h" // For nsIDocument
|
2014-11-17 04:45:58 +00:00
|
|
|
#include "nsIPresShell.h" // For nsIPresShell
|
2014-10-20 04:55:43 +00:00
|
|
|
#include "nsLayoutUtils.h" // For PostRestyleEvent (remove after bug 1073336)
|
2015-04-21 01:22:09 +00:00
|
|
|
#include "PendingAnimationTracker.h" // For PendingAnimationTracker
|
2014-08-10 07:06:44 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-04-21 01:22:09 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Animation, mTimeline,
|
2015-04-14 23:48:21 +00:00
|
|
|
mEffect, mReady, mFinished)
|
2015-04-21 01:22:09 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Animation)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Animation)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Animation)
|
2014-12-17 23:42:40 +00:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
2014-08-10 07:06:44 +00:00
|
|
|
|
|
|
|
JSObject*
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2014-08-10 07:06:44 +00:00
|
|
|
{
|
2015-04-21 01:22:09 +00:00
|
|
|
return dom::AnimationBinding::Wrap(aCx, this, aGivenProto);
|
2014-08-10 07:06:44 +00:00
|
|
|
}
|
|
|
|
|
2015-04-27 01:05:46 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Animation interface:
|
|
|
|
//
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void
|
2015-04-30 13:06:43 +00:00
|
|
|
Animation::SetEffect(KeyframeEffectReadOnly* aEffect)
|
2015-04-27 01:05:46 +00:00
|
|
|
{
|
|
|
|
if (mEffect) {
|
|
|
|
mEffect->SetParentTime(Nullable<TimeDuration>());
|
|
|
|
}
|
|
|
|
mEffect = aEffect;
|
|
|
|
if (mEffect) {
|
|
|
|
mEffect->SetParentTime(GetCurrentTime());
|
|
|
|
}
|
|
|
|
UpdateRelevance();
|
|
|
|
}
|
|
|
|
|
2015-02-09 10:26:27 +00:00
|
|
|
void
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::SetStartTime(const Nullable<TimeDuration>& aNewStartTime)
|
2015-02-09 10:26:27 +00:00
|
|
|
{
|
|
|
|
#if 1
|
|
|
|
// Bug 1096776: once we support inactive/missing timelines we'll want to take
|
|
|
|
// the disabled branch.
|
|
|
|
MOZ_ASSERT(mTimeline && !mTimeline->GetCurrentTime().IsNull(),
|
|
|
|
"We don't support inactive/missing timelines yet");
|
|
|
|
#else
|
|
|
|
Nullable<TimeDuration> timelineTime = mTimeline->GetCurrentTime();
|
|
|
|
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.
|
|
|
|
timelineTime = mTimeline->GetCurrentTime();
|
|
|
|
}
|
|
|
|
if (timelineTime.IsNull() && !aNewStartTime.IsNull()) {
|
|
|
|
mHoldTime.SetNull();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
Nullable<TimeDuration> previousCurrentTime = GetCurrentTime();
|
|
|
|
mStartTime = aNewStartTime;
|
|
|
|
if (!aNewStartTime.IsNull()) {
|
2015-03-13 20:10:45 +00:00
|
|
|
if (mPlaybackRate != 0.0) {
|
|
|
|
mHoldTime.SetNull();
|
|
|
|
}
|
2015-02-09 10:26:27 +00:00
|
|
|
} else {
|
|
|
|
mHoldTime = previousCurrentTime;
|
|
|
|
}
|
|
|
|
|
2015-03-27 06:56:45 +00:00
|
|
|
CancelPendingTasks();
|
2015-02-09 10:26:27 +00: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);
|
|
|
|
}
|
|
|
|
|
2015-05-11 08:17:06 +00:00
|
|
|
UpdateTiming(SeekFlag::NoSeek);
|
2015-02-12 17:56:57 +00:00
|
|
|
PostUpdate();
|
2015-02-09 10:26:27 +00:00
|
|
|
}
|
|
|
|
|
2015-04-27 01:05:46 +00:00
|
|
|
// http://w3c.github.io/web-animations/#current-time
|
2014-10-20 04:55:45 +00:00
|
|
|
Nullable<TimeDuration>
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::GetCurrentTime() const
|
2014-08-10 07:06:44 +00:00
|
|
|
{
|
2014-10-20 04:55:45 +00:00
|
|
|
Nullable<TimeDuration> result;
|
|
|
|
if (!mHoldTime.IsNull()) {
|
|
|
|
result = mHoldTime;
|
2014-12-04 20:13:38 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mStartTime.IsNull()) {
|
2014-10-20 04:55:45 +00:00
|
|
|
Nullable<TimeDuration> timelineTime = mTimeline->GetCurrentTime();
|
2014-12-04 20:13:38 +00:00
|
|
|
if (!timelineTime.IsNull()) {
|
2015-03-13 20:10:45 +00:00
|
|
|
result.SetValue((timelineTime.Value() - mStartTime.Value())
|
|
|
|
.MultDouble(mPlaybackRate));
|
2014-10-20 04:55:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2014-08-10 07:06:44 +00:00
|
|
|
}
|
|
|
|
|
2015-03-09 16:50:39 +00:00
|
|
|
// Implements http://w3c.github.io/web-animations/#set-the-current-time
|
|
|
|
void
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::SetCurrentTime(const TimeDuration& aSeekTime)
|
2015-03-09 16:50:39 +00:00
|
|
|
{
|
|
|
|
SilentlySetCurrentTime(aSeekTime);
|
|
|
|
|
2015-03-27 06:56:45 +00:00
|
|
|
if (mPendingState == PendingState::PausePending) {
|
2015-05-18 02:41:19 +00:00
|
|
|
// Finish the pause operation
|
|
|
|
mHoldTime.SetValue(aSeekTime);
|
|
|
|
mStartTime.SetNull();
|
|
|
|
|
2015-03-27 06:56:45 +00:00
|
|
|
if (mReady) {
|
|
|
|
mReady->MaybeResolve(this);
|
|
|
|
}
|
2015-05-18 02:41:19 +00:00
|
|
|
CancelPendingTasks();
|
2015-03-27 06:56:45 +00:00
|
|
|
}
|
2015-03-09 16:50:39 +00:00
|
|
|
|
2015-05-11 08:17:06 +00:00
|
|
|
UpdateTiming(SeekFlag::DidSeek);
|
2015-03-09 16:50:39 +00:00
|
|
|
PostUpdate();
|
|
|
|
}
|
|
|
|
|
2015-03-13 20:10:45 +00:00
|
|
|
void
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::SetPlaybackRate(double aPlaybackRate)
|
2015-03-13 20:10:45 +00:00
|
|
|
{
|
|
|
|
Nullable<TimeDuration> previousTime = GetCurrentTime();
|
|
|
|
mPlaybackRate = aPlaybackRate;
|
|
|
|
if (!previousTime.IsNull()) {
|
|
|
|
ErrorResult rv;
|
|
|
|
SetCurrentTime(previousTime.Value());
|
|
|
|
MOZ_ASSERT(!rv.Failed(), "Should not assert for non-null time");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-20 04:55:45 +00:00
|
|
|
AnimationPlayState
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::PlayState() const
|
2014-10-20 04:55:45 +00:00
|
|
|
{
|
2015-03-27 06:56:45 +00:00
|
|
|
if (mPendingState != PendingState::NotPending) {
|
2014-12-17 23:42:41 +00:00
|
|
|
return AnimationPlayState::Pending;
|
|
|
|
}
|
|
|
|
|
2014-10-20 04:55:45 +00:00
|
|
|
Nullable<TimeDuration> currentTime = GetCurrentTime();
|
2014-10-20 04:55:45 +00:00
|
|
|
if (currentTime.IsNull()) {
|
|
|
|
return AnimationPlayState::Idle;
|
|
|
|
}
|
|
|
|
|
2014-12-04 16:28:37 +00:00
|
|
|
if (mStartTime.IsNull()) {
|
2014-10-20 04:55:45 +00:00
|
|
|
return AnimationPlayState::Paused;
|
|
|
|
}
|
|
|
|
|
2015-04-14 23:48:21 +00:00
|
|
|
if ((mPlaybackRate > 0.0 && currentTime.Value() >= EffectEnd()) ||
|
2015-03-13 20:10:45 +00:00
|
|
|
(mPlaybackRate < 0.0 && currentTime.Value().ToMilliseconds() <= 0.0)) {
|
2014-10-20 04:55:45 +00:00
|
|
|
return AnimationPlayState::Finished;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AnimationPlayState::Running;
|
|
|
|
}
|
|
|
|
|
2015-03-18 13:22:11 +00:00
|
|
|
static inline already_AddRefed<Promise>
|
2015-04-10 01:34:22 +00:00
|
|
|
CreatePromise(DocumentTimeline* aTimeline, ErrorResult& aRv)
|
2015-03-18 13:22:11 +00:00
|
|
|
{
|
|
|
|
nsIGlobalObject* global = aTimeline->GetParentObject();
|
|
|
|
if (global) {
|
|
|
|
return Promise::Create(global, aRv);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-12-17 23:42:40 +00:00
|
|
|
Promise*
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::GetReady(ErrorResult& aRv)
|
2014-12-17 23:42:40 +00:00
|
|
|
{
|
|
|
|
if (!mReady) {
|
2015-03-18 13:22:11 +00:00
|
|
|
mReady = CreatePromise(mTimeline, aRv); // Lazily create on demand
|
2014-12-17 23:42:40 +00:00
|
|
|
}
|
|
|
|
if (!mReady) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
2015-03-18 13:22:11 +00:00
|
|
|
} else if (PlayState() != AnimationPlayState::Pending) {
|
|
|
|
mReady->MaybeResolve(this);
|
2014-12-17 23:42:40 +00:00
|
|
|
}
|
|
|
|
return mReady;
|
|
|
|
}
|
|
|
|
|
2015-03-18 13:22:11 +00:00
|
|
|
Promise*
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::GetFinished(ErrorResult& aRv)
|
2015-03-18 13:22:11 +00:00
|
|
|
{
|
|
|
|
if (!mFinished) {
|
|
|
|
mFinished = CreatePromise(mTimeline, aRv); // Lazily create on demand
|
|
|
|
}
|
|
|
|
if (!mFinished) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
2015-05-18 23:51:13 +00:00
|
|
|
} else if (PlayState() == AnimationPlayState::Finished) {
|
2015-03-18 13:22:11 +00:00
|
|
|
mFinished->MaybeResolve(this);
|
|
|
|
}
|
|
|
|
return mFinished;
|
|
|
|
}
|
|
|
|
|
2015-04-26 23:53:19 +00:00
|
|
|
void
|
|
|
|
Animation::Cancel()
|
|
|
|
{
|
|
|
|
DoCancel();
|
|
|
|
PostUpdate();
|
|
|
|
}
|
|
|
|
|
2015-04-27 01:05:46 +00:00
|
|
|
// https://w3c.github.io/web-animations/#finish-an-animation
|
2015-04-16 16:15:20 +00:00
|
|
|
void
|
|
|
|
Animation::Finish(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (mPlaybackRate == 0 ||
|
|
|
|
(mPlaybackRate > 0 && EffectEnd() == TimeDuration::Forever())) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeDuration limit =
|
|
|
|
mPlaybackRate > 0 ? TimeDuration(EffectEnd()) : TimeDuration(0);
|
|
|
|
|
|
|
|
SetCurrentTime(limit);
|
|
|
|
|
2015-05-19 01:08:46 +00: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 &&
|
|
|
|
!mTimeline->GetCurrentTime().IsNull()) {
|
|
|
|
mStartTime.SetValue(mTimeline->GetCurrentTime().Value() -
|
|
|
|
limit.MultDouble(1.0 / mPlaybackRate));
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we just resolved the start time for a pause-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 (mPendingState == PendingState::PlayPending &&
|
|
|
|
!mStartTime.IsNull()) {
|
2015-04-16 16:15:20 +00:00
|
|
|
CancelPendingTasks();
|
|
|
|
if (mReady) {
|
|
|
|
mReady->MaybeResolve(this);
|
|
|
|
}
|
|
|
|
}
|
2015-05-11 08:17:06 +00:00
|
|
|
UpdateTiming(SeekFlag::DidSeek);
|
2015-04-16 16:15:20 +00:00
|
|
|
PostUpdate();
|
|
|
|
}
|
|
|
|
|
2014-10-20 04:55:43 +00:00
|
|
|
void
|
2015-05-19 05:00:48 +00:00
|
|
|
Animation::Play(ErrorResult& aRv, LimitBehavior aLimitBehavior)
|
2014-10-20 04:55:43 +00:00
|
|
|
{
|
2015-05-19 05:00:48 +00:00
|
|
|
DoPlay(aRv, aLimitBehavior);
|
2014-11-17 04:46:01 +00:00
|
|
|
PostUpdate();
|
2014-10-20 04:55:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-05-19 05:55:26 +00:00
|
|
|
Animation::Pause(ErrorResult& aRv)
|
2014-10-20 04:55:43 +00:00
|
|
|
{
|
2015-05-19 05:55:26 +00:00
|
|
|
DoPause(aRv);
|
2014-11-17 04:46:01 +00:00
|
|
|
PostUpdate();
|
2014-10-20 04:55:43 +00:00
|
|
|
}
|
|
|
|
|
2015-04-27 01:05:46 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// JS wrappers for Animation interface:
|
|
|
|
//
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2014-12-04 16:28:38 +00:00
|
|
|
Nullable<double>
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::GetStartTimeAsDouble() const
|
2014-12-04 16:28:38 +00:00
|
|
|
{
|
|
|
|
return AnimationUtils::TimeDurationToDouble(mStartTime);
|
|
|
|
}
|
|
|
|
|
2015-02-09 10:26:27 +00:00
|
|
|
void
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::SetStartTimeAsDouble(const Nullable<double>& aStartTime)
|
2015-02-09 10:26:27 +00:00
|
|
|
{
|
|
|
|
return SetStartTime(AnimationUtils::DoubleToTimeDuration(aStartTime));
|
|
|
|
}
|
2015-04-21 01:22:09 +00:00
|
|
|
|
2014-10-20 04:55:45 +00:00
|
|
|
Nullable<double>
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::GetCurrentTimeAsDouble() const
|
2014-10-20 04:55:45 +00:00
|
|
|
{
|
|
|
|
return AnimationUtils::TimeDurationToDouble(GetCurrentTime());
|
|
|
|
}
|
|
|
|
|
2015-03-09 16:50:39 +00:00
|
|
|
void
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::SetCurrentTimeAsDouble(const Nullable<double>& aCurrentTime,
|
2015-03-09 16:50:39 +00:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (aCurrentTime.IsNull()) {
|
|
|
|
if (!GetCurrentTime().IsNull()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SetCurrentTime(TimeDuration::FromMilliseconds(aCurrentTime.Value()));
|
|
|
|
}
|
|
|
|
|
2015-04-27 01:05:46 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2014-08-10 07:06:48 +00:00
|
|
|
|
|
|
|
void
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::Tick()
|
2014-08-10 07:06:48 +00:00
|
|
|
{
|
2015-01-08 22:57:58 +00:00
|
|
|
// Since we are not guaranteed to get only one call per refresh driver tick,
|
|
|
|
// it's possible that mPendingReadyTime is set to a time in the future.
|
|
|
|
// In that case, we should wait until the next refresh driver tick before
|
|
|
|
// resuming.
|
2015-03-27 06:56:45 +00:00
|
|
|
if (mPendingState != PendingState::NotPending &&
|
2015-01-08 22:57:58 +00:00
|
|
|
!mPendingReadyTime.IsNull() &&
|
|
|
|
mPendingReadyTime.Value() <= mTimeline->GetCurrentTime().Value()) {
|
2015-04-01 03:23:24 +00:00
|
|
|
FinishPendingAt(mPendingReadyTime.Value());
|
2015-01-08 22:57:58 +00:00
|
|
|
mPendingReadyTime.SetNull();
|
|
|
|
}
|
|
|
|
|
2015-04-21 01:22:09 +00:00
|
|
|
if (IsPossiblyOrphanedPendingAnimation()) {
|
2015-01-08 22:57:58 +00:00
|
|
|
MOZ_ASSERT(mTimeline && !mTimeline->GetCurrentTime().IsNull(),
|
2015-04-21 01:22:09 +00:00
|
|
|
"Orphaned pending animtaions should have an active timeline");
|
2015-04-01 03:23:24 +00:00
|
|
|
FinishPendingAt(mTimeline->GetCurrentTime().Value());
|
2015-01-08 22:57:58 +00:00
|
|
|
}
|
2014-12-25 07:28:24 +00:00
|
|
|
|
2015-05-11 08:17:06 +00:00
|
|
|
UpdateTiming(SeekFlag::NoSeek);
|
2014-08-10 07:06:47 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 22:57:58 +00:00
|
|
|
void
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::TriggerOnNextTick(const Nullable<TimeDuration>& aReadyTime)
|
2015-01-08 22:57:58 +00:00
|
|
|
{
|
|
|
|
// Normally we expect the play state to be pending but it's possible that,
|
2015-04-21 01:22:09 +00: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.
|
2015-01-08 22:57:58 +00:00
|
|
|
if (PlayState() != AnimationPlayState::Pending) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-08 22:57:58 +00:00
|
|
|
// If aReadyTime.IsNull() we'll detect this in Tick() where we check for
|
2015-04-21 01:22:09 +00:00
|
|
|
// orphaned animations and trigger this animation anyway
|
2015-01-08 22:57:58 +00:00
|
|
|
mPendingReadyTime = aReadyTime;
|
|
|
|
}
|
|
|
|
|
2014-12-04 16:28:38 +00:00
|
|
|
void
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::TriggerNow()
|
2014-12-04 16:28:38 +00:00
|
|
|
{
|
2014-12-25 07:28:24 +00:00
|
|
|
MOZ_ASSERT(PlayState() == AnimationPlayState::Pending,
|
2015-04-21 01:22:09 +00:00
|
|
|
"Expected to start a pending animation");
|
2015-01-08 22:57:58 +00:00
|
|
|
MOZ_ASSERT(mTimeline && !mTimeline->GetCurrentTime().IsNull(),
|
|
|
|
"Expected an active timeline");
|
2014-12-17 23:42:40 +00:00
|
|
|
|
2015-04-01 03:23:24 +00:00
|
|
|
FinishPendingAt(mTimeline->GetCurrentTime().Value());
|
2014-12-04 16:28:38 +00:00
|
|
|
}
|
|
|
|
|
2015-02-03 05:08:37 +00:00
|
|
|
Nullable<TimeDuration>
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::GetCurrentOrPendingStartTime() const
|
2015-02-03 05:08:37 +00:00
|
|
|
{
|
|
|
|
Nullable<TimeDuration> result;
|
|
|
|
|
|
|
|
if (!mStartTime.IsNull()) {
|
|
|
|
result = mStartTime;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPendingReadyTime.IsNull() || mHoldTime.IsNull()) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the equivalent start time from the pending ready time.
|
|
|
|
// This is the same as the calculation performed in ResumeAt and will
|
|
|
|
// need to incorporate the playbackRate when implemented (bug 1127380).
|
|
|
|
result.SetValue(mPendingReadyTime.Value() - mHoldTime.Value());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-04-27 01:05:46 +00:00
|
|
|
// http://w3c.github.io/web-animations/#silently-set-the-current-time
|
|
|
|
void
|
|
|
|
Animation::SilentlySetCurrentTime(const TimeDuration& aSeekTime)
|
|
|
|
{
|
|
|
|
if (!mHoldTime.IsNull() ||
|
|
|
|
mStartTime.IsNull() ||
|
|
|
|
!mTimeline ||
|
|
|
|
mTimeline->GetCurrentTime().IsNull() ||
|
|
|
|
mPlaybackRate == 0.0) {
|
|
|
|
mHoldTime.SetValue(aSeekTime);
|
|
|
|
if (!mTimeline || mTimeline->GetCurrentTime().IsNull()) {
|
|
|
|
mStartTime.SetNull();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mStartTime.SetValue(mTimeline->GetCurrentTime().Value() -
|
|
|
|
(aSeekTime.MultDouble(1 / mPlaybackRate)));
|
|
|
|
}
|
|
|
|
|
|
|
|
mPreviousCurrentTime.SetNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-17 23:42:41 +00:00
|
|
|
void
|
2015-04-26 23:53:19 +00:00
|
|
|
Animation::DoCancel()
|
2014-12-17 23:42:41 +00:00
|
|
|
{
|
2015-03-27 06:56:45 +00:00
|
|
|
if (mPendingState != PendingState::NotPending) {
|
2015-03-27 06:56:45 +00:00
|
|
|
CancelPendingTasks();
|
2014-12-17 23:42:41 +00:00
|
|
|
if (mReady) {
|
|
|
|
mReady->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-18 13:22:11 +00:00
|
|
|
if (mFinished) {
|
|
|
|
mFinished->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
|
|
|
|
}
|
|
|
|
// Clear finished promise. We'll create a new one lazily.
|
|
|
|
mFinished = nullptr;
|
|
|
|
|
2014-12-17 23:42:41 +00:00
|
|
|
mHoldTime.SetNull();
|
|
|
|
mStartTime.SetNull();
|
2015-03-14 05:34:40 +00:00
|
|
|
|
2015-04-14 23:48:21 +00:00
|
|
|
UpdateEffect();
|
2014-12-17 23:42:41 +00:00
|
|
|
}
|
|
|
|
|
2015-03-14 05:34:40 +00:00
|
|
|
void
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::UpdateRelevance()
|
2015-03-14 05:34:40 +00:00
|
|
|
{
|
2015-03-14 05:34:40 +00:00
|
|
|
bool wasRelevant = mIsRelevant;
|
2015-04-14 23:48:21 +00:00
|
|
|
mIsRelevant = HasCurrentEffect() || IsInEffect();
|
2015-03-14 05:34:40 +00:00
|
|
|
|
|
|
|
// Notify animation observers.
|
|
|
|
if (wasRelevant && !mIsRelevant) {
|
|
|
|
nsNodeUtils::AnimationRemoved(this);
|
|
|
|
} else if (!wasRelevant && mIsRelevant) {
|
|
|
|
nsNodeUtils::AnimationAdded(this);
|
|
|
|
}
|
2015-03-14 05:34:40 +00:00
|
|
|
}
|
|
|
|
|
2014-10-20 04:55:45 +00:00
|
|
|
bool
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::CanThrottle() const
|
2014-10-20 04:55:45 +00:00
|
|
|
{
|
2015-04-14 23:48:21 +00:00
|
|
|
if (!mEffect ||
|
|
|
|
mEffect->IsFinishedTransition() ||
|
|
|
|
mEffect->Properties().IsEmpty()) {
|
2014-10-20 04:55:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mIsRunningOnCompositor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PlayState() != AnimationPlayState::Finished) {
|
|
|
|
// Unfinished animations can be throttled.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The animation has finished but, if this is the first sample since
|
|
|
|
// finishing, we need an unthrottled sample so we can apply the correct
|
|
|
|
// end-of-animation behavior on the main thread (either removing the
|
|
|
|
// animation style or applying the fill mode).
|
2015-04-02 03:30:17 +00:00
|
|
|
return mFinishedAtLastComposeStyle;
|
2014-10-20 04:55:45 +00:00
|
|
|
}
|
|
|
|
|
2014-10-20 04:55:46 +00:00
|
|
|
void
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::ComposeStyle(nsRefPtr<css::AnimValuesStyleRule>& aStyleRule,
|
|
|
|
nsCSSPropertySet& aSetProperties,
|
|
|
|
bool& aNeedsRefreshes)
|
2014-10-20 04:55:46 +00:00
|
|
|
{
|
2015-04-14 23:48:21 +00:00
|
|
|
if (!mEffect || mEffect->IsFinishedTransition()) {
|
2014-10-20 04:55:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Bug 1078122 part 6 - Store the previous finished state; r=dholbert
AnimationPlayer::CanThrottle determines if an animation player has just finished
by inspecting the value of mLastNotification. This is problematic for two
reasons:
1. mLastNotification is intended to be used for events (as the XXX comment
notes)
2. mLastNotification is specific to CSS Animations and should be moved to
CSSAnimationPlayer.
To address this, this patch adds an extra member mIsPreviousStateFinished. The
Web Animations spec already defines animation players as having such a member:
http://w3c.github.io/web-animations/#previous-finished-state
We set it to true when we calculate the style for an animation that has
finished. This differs slightly from the code it is replacing as explained
below.
In the case of CSS Animations we perform the following sequence of steps on each
sample.
1. EnsureStyleRuleFor (calls CanThrottle, and maybe ComposeStyle)
2. GetEventsForCurrentTime
In the existing code, we update mLastNotification in (2) which happens on every
sample, even throttled samples.
In this patch, however, we update mIsPreviousStateFinished in (1) during the
ComposeStyle step which only happens for unthrottled samples. So, as of this
patch, in CanThrottle, we ask "have we newly entered the finished state since
the last *unthrottled* sample?", whereas previously we simply looked for
a change since the last sample, throttled or not. However, if the answer to the
question is "yes", then we'll run an unthrottled sample and update
mIsPreviousStateFinished so these should be functionally equivalent.
Another subtle difference is that this patch looks at the player's finished
state rather than the animation phase of its source content, and these will
produce different results in the case where the player is paused. However, since
paused animations are not run on the compositor, this should not matter.
In the case of CSS Transitions, AnimationPlayer::CanThrottle() is not currently
used and so mIsPreviousStateFinished is irrelevant.
Ultimately, both the existing and the new code is somewhat fragile but hopefully
this will be addressed by:
* Replacing mIsPreviousStateFinished with inspecting whether the finished
promise is settled (bug 1074630),
* Merging more of the code in nsAnimationManager and nsTransitionManager and
applying a unified approach to sampling that better accommodates these
considerations.
2014-10-20 04:55:47 +00:00
|
|
|
AnimationPlayState playState = PlayState();
|
2014-12-17 23:42:41 +00:00
|
|
|
if (playState == AnimationPlayState::Running ||
|
|
|
|
playState == AnimationPlayState::Pending) {
|
2014-10-20 04:55:46 +00:00
|
|
|
aNeedsRefreshes = true;
|
|
|
|
}
|
|
|
|
|
2015-04-01 03:23:25 +00: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
|
|
|
|
// GetCurrentTime. These are:
|
|
|
|
//
|
|
|
|
// (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.
|
|
|
|
{
|
|
|
|
AutoRestore<Nullable<TimeDuration>> restoreHoldTime(mHoldTime);
|
|
|
|
bool updatedHoldTime = false;
|
|
|
|
|
2015-04-02 03:30:17 +00:00
|
|
|
AnimationPlayState playState = PlayState();
|
|
|
|
|
|
|
|
if (playState == AnimationPlayState::Pending &&
|
2015-04-01 03:23:25 +00:00
|
|
|
mHoldTime.IsNull() &&
|
|
|
|
!mStartTime.IsNull()) {
|
|
|
|
Nullable<TimeDuration> timeToUse = mPendingReadyTime;
|
|
|
|
if (timeToUse.IsNull() &&
|
|
|
|
mTimeline &&
|
|
|
|
!mTimeline->IsUnderTestControl()) {
|
|
|
|
timeToUse = mTimeline->ToTimelineTime(TimeStamp::Now());
|
|
|
|
}
|
|
|
|
if (!timeToUse.IsNull()) {
|
|
|
|
mHoldTime.SetValue((timeToUse.Value() - mStartTime.Value())
|
|
|
|
.MultDouble(mPlaybackRate));
|
2015-04-14 23:48:21 +00:00
|
|
|
// Push the change down to the effect
|
|
|
|
UpdateEffect();
|
2015-04-01 03:23:25 +00:00
|
|
|
updatedHoldTime = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-14 23:48:21 +00:00
|
|
|
mEffect->ComposeStyle(aStyleRule, aSetProperties);
|
2015-04-01 03:23:25 +00:00
|
|
|
|
|
|
|
if (updatedHoldTime) {
|
2015-05-11 08:17:06 +00:00
|
|
|
UpdateTiming(SeekFlag::NoSeek);
|
2015-04-01 03:23:25 +00:00
|
|
|
}
|
2015-04-02 03:30:17 +00:00
|
|
|
|
|
|
|
mFinishedAtLastComposeStyle = (playState == AnimationPlayState::Finished);
|
2015-04-01 03:23:25 +00:00
|
|
|
}
|
2014-10-20 04:55:46 +00:00
|
|
|
}
|
|
|
|
|
2015-04-27 01:05:46 +00:00
|
|
|
// http://w3c.github.io/web-animations/#play-an-animation
|
2014-11-17 04:46:01 +00:00
|
|
|
void
|
2015-05-19 05:00:48 +00:00
|
|
|
Animation::DoPlay(ErrorResult& aRv, LimitBehavior aLimitBehavior)
|
2014-11-17 04:46:01 +00:00
|
|
|
{
|
2015-04-01 03:23:25 +00:00
|
|
|
bool abortedPause = mPendingState == PendingState::PausePending;
|
|
|
|
|
2014-12-04 16:28:37 +00:00
|
|
|
Nullable<TimeDuration> currentTime = GetCurrentTime();
|
2015-03-13 20:10:45 +00:00
|
|
|
if (mPlaybackRate > 0.0 &&
|
2015-03-18 13:22:11 +00:00
|
|
|
(currentTime.IsNull() ||
|
|
|
|
(aLimitBehavior == LimitBehavior::AutoRewind &&
|
|
|
|
(currentTime.Value().ToMilliseconds() < 0.0 ||
|
2015-04-14 23:48:21 +00:00
|
|
|
currentTime.Value() >= EffectEnd())))) {
|
2014-12-04 16:28:37 +00:00
|
|
|
mHoldTime.SetValue(TimeDuration(0));
|
2015-03-13 20:10:45 +00:00
|
|
|
} else if (mPlaybackRate < 0.0 &&
|
2015-03-18 13:22:11 +00:00
|
|
|
(currentTime.IsNull() ||
|
|
|
|
(aLimitBehavior == LimitBehavior::AutoRewind &&
|
|
|
|
(currentTime.Value().ToMilliseconds() <= 0.0 ||
|
2015-04-14 23:48:21 +00:00
|
|
|
currentTime.Value() > EffectEnd())))) {
|
2015-05-19 05:00:48 +00:00
|
|
|
if (EffectEnd() == TimeDuration::Forever()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2015-04-14 23:48:21 +00:00
|
|
|
mHoldTime.SetValue(TimeDuration(EffectEnd()));
|
2015-03-13 20:10:45 +00:00
|
|
|
} else if (mPlaybackRate == 0.0 && currentTime.IsNull()) {
|
|
|
|
mHoldTime.SetValue(TimeDuration(0));
|
|
|
|
}
|
|
|
|
|
2015-05-19 05:00:48 +00:00
|
|
|
bool reuseReadyPromise = false;
|
|
|
|
if (mPendingState != PendingState::NotPending) {
|
|
|
|
CancelPendingTasks();
|
|
|
|
reuseReadyPromise = true;
|
|
|
|
}
|
|
|
|
|
2015-04-01 03:23:25 +00:00
|
|
|
// 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) {
|
2014-11-17 04:46:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-08 07:17:13 +00: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 03:23:25 +00:00
|
|
|
mStartTime.SetNull();
|
|
|
|
}
|
2015-03-24 00:21:08 +00:00
|
|
|
|
2015-03-27 06:56:45 +00:00
|
|
|
if (!reuseReadyPromise) {
|
|
|
|
// Clear ready promise. We'll create a new one lazily.
|
|
|
|
mReady = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-03-27 06:56:45 +00:00
|
|
|
mPendingState = PendingState::PlayPending;
|
2014-12-25 07:28:24 +00:00
|
|
|
|
|
|
|
nsIDocument* doc = GetRenderedDocument();
|
|
|
|
if (!doc) {
|
2015-03-27 06:56:45 +00:00
|
|
|
TriggerOnNextTick(Nullable<TimeDuration>());
|
2014-12-25 07:28:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-21 01:22:09 +00:00
|
|
|
PendingAnimationTracker* tracker = doc->GetOrCreatePendingAnimationTracker();
|
2014-12-25 07:28:24 +00:00
|
|
|
tracker->AddPlayPending(*this);
|
|
|
|
|
2015-03-18 13:22:11 +00:00
|
|
|
// We may have updated the current time when we set the hold time above.
|
2015-05-11 08:17:06 +00:00
|
|
|
UpdateTiming(SeekFlag::NoSeek);
|
2014-11-17 04:46:01 +00:00
|
|
|
}
|
|
|
|
|
2015-04-27 01:05:46 +00:00
|
|
|
// http://w3c.github.io/web-animations/#pause-an-animation
|
2014-11-17 04:46:01 +00:00
|
|
|
void
|
2015-05-19 05:55:26 +00:00
|
|
|
Animation::DoPause(ErrorResult& aRv)
|
2014-11-17 04:46:01 +00:00
|
|
|
{
|
2015-04-14 00:07:41 +00:00
|
|
|
if (IsPausedOrPausing()) {
|
2015-04-01 03:23:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-19 05:55:26 +00:00
|
|
|
// 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()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-01 03:23:25 +00:00
|
|
|
bool reuseReadyPromise = false;
|
2015-03-27 06:56:45 +00:00
|
|
|
if (mPendingState == PendingState::PlayPending) {
|
2015-03-27 06:56:45 +00:00
|
|
|
CancelPendingTasks();
|
2015-04-01 03:23:25 +00:00
|
|
|
reuseReadyPromise = true;
|
2014-11-17 04:46:01 +00:00
|
|
|
}
|
2014-12-17 23:42:41 +00:00
|
|
|
|
2014-12-04 16:28:37 +00:00
|
|
|
// 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.
|
2014-11-17 04:46:01 +00:00
|
|
|
mIsRunningOnCompositor = false;
|
|
|
|
|
2015-04-01 03:23:25 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-04-21 01:22:09 +00:00
|
|
|
PendingAnimationTracker* tracker = doc->GetOrCreatePendingAnimationTracker();
|
2015-04-01 03:23:25 +00:00
|
|
|
tracker->AddPausePending(*this);
|
2015-03-18 13:22:11 +00:00
|
|
|
|
2015-05-11 08:17:06 +00:00
|
|
|
UpdateTiming(SeekFlag::NoSeek);
|
2014-11-17 04:46:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 22:57:58 +00:00
|
|
|
void
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::ResumeAt(const TimeDuration& aReadyTime)
|
2015-01-08 22:57:58 +00:00
|
|
|
{
|
2015-04-21 01:22:09 +00:00
|
|
|
// This method is only expected to be called for an animation that is
|
2015-01-08 22:57:58 +00:00
|
|
|
// waiting to play. We can easily adapt it to handle other states
|
|
|
|
// but it's currently not necessary.
|
2015-03-27 06:56:45 +00:00
|
|
|
MOZ_ASSERT(mPendingState == PendingState::PlayPending,
|
2015-04-21 01:22:09 +00:00
|
|
|
"Expected to resume a play-pending animation");
|
2015-04-01 03:23:25 +00:00
|
|
|
MOZ_ASSERT(mHoldTime.IsNull() != mStartTime.IsNull(),
|
2015-04-21 01:22:09 +00:00
|
|
|
"An animation in the play-pending state should have either a"
|
2015-04-01 03:23:25 +00:00
|
|
|
" resolved hold time or resolved start time (but not both)");
|
2015-01-08 22:57:58 +00:00
|
|
|
|
2015-04-01 03:23:25 +00:00
|
|
|
// 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) {
|
2015-03-30 15:27:05 +00:00
|
|
|
mStartTime.SetValue(aReadyTime -
|
|
|
|
(mHoldTime.Value().MultDouble(1 / mPlaybackRate)));
|
2015-04-01 03:23:25 +00:00
|
|
|
mHoldTime.SetNull();
|
|
|
|
} else {
|
|
|
|
mStartTime.SetValue(aReadyTime);
|
|
|
|
}
|
2015-03-13 20:10:45 +00:00
|
|
|
}
|
2015-03-27 06:56:45 +00:00
|
|
|
mPendingState = PendingState::NotPending;
|
2015-01-08 22:57:58 +00:00
|
|
|
|
2015-05-11 08:17:06 +00:00
|
|
|
UpdateTiming(SeekFlag::NoSeek);
|
2015-01-08 22:57:58 +00:00
|
|
|
|
|
|
|
if (mReady) {
|
|
|
|
mReady->MaybeResolve(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-01 03:23:24 +00:00
|
|
|
void
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::PauseAt(const TimeDuration& aReadyTime)
|
2015-04-01 03:23:24 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mPendingState == PendingState::PausePending,
|
2015-04-21 01:22:09 +00:00
|
|
|
"Expected to pause a pause-pending animation");
|
2015-04-01 03:23:24 +00:00
|
|
|
|
|
|
|
if (!mStartTime.IsNull()) {
|
|
|
|
mHoldTime.SetValue((aReadyTime - mStartTime.Value())
|
|
|
|
.MultDouble(mPlaybackRate));
|
|
|
|
}
|
|
|
|
mStartTime.SetNull();
|
|
|
|
mPendingState = PendingState::NotPending;
|
|
|
|
|
2015-05-11 08:17:06 +00:00
|
|
|
UpdateTiming(SeekFlag::NoSeek);
|
2015-04-01 03:23:24 +00:00
|
|
|
|
|
|
|
if (mReady) {
|
|
|
|
mReady->MaybeResolve(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-18 13:22:11 +00:00
|
|
|
void
|
2015-05-11 08:17:06 +00:00
|
|
|
Animation::UpdateTiming(SeekFlag aSeekFlag)
|
2015-03-18 13:22:11 +00:00
|
|
|
{
|
2015-04-14 23:48:21 +00:00
|
|
|
// We call UpdateFinishedState before UpdateEffect because the former
|
2015-03-18 13:22:11 +00:00
|
|
|
// can change the current time, which is used by the latter.
|
2015-05-11 08:17:06 +00:00
|
|
|
UpdateFinishedState(aSeekFlag);
|
2015-04-14 23:48:21 +00:00
|
|
|
UpdateEffect();
|
2015-03-18 13:22:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-05-11 08:17:06 +00:00
|
|
|
Animation::UpdateFinishedState(SeekFlag aSeekFlag)
|
2015-03-18 13:22:11 +00:00
|
|
|
{
|
|
|
|
Nullable<TimeDuration> currentTime = GetCurrentTime();
|
2015-04-14 23:48:21 +00:00
|
|
|
TimeDuration effectEnd = TimeDuration(EffectEnd());
|
2015-03-18 13:22:11 +00:00
|
|
|
|
|
|
|
if (!mStartTime.IsNull() &&
|
|
|
|
mPendingState == PendingState::NotPending) {
|
|
|
|
if (mPlaybackRate > 0.0 &&
|
|
|
|
!currentTime.IsNull() &&
|
2015-04-14 23:48:21 +00:00
|
|
|
currentTime.Value() >= effectEnd) {
|
2015-05-11 08:17:06 +00:00
|
|
|
if (aSeekFlag == SeekFlag::DidSeek) {
|
2015-03-18 13:22:11 +00:00
|
|
|
mHoldTime = currentTime;
|
|
|
|
} else if (!mPreviousCurrentTime.IsNull()) {
|
2015-04-14 23:48:21 +00:00
|
|
|
mHoldTime.SetValue(std::max(mPreviousCurrentTime.Value(), effectEnd));
|
2015-03-18 13:22:11 +00:00
|
|
|
} else {
|
2015-04-14 23:48:21 +00:00
|
|
|
mHoldTime.SetValue(effectEnd);
|
2015-03-18 13:22:11 +00:00
|
|
|
}
|
|
|
|
} else if (mPlaybackRate < 0.0 &&
|
|
|
|
!currentTime.IsNull() &&
|
|
|
|
currentTime.Value().ToMilliseconds() <= 0.0) {
|
2015-05-11 08:17:06 +00:00
|
|
|
if (aSeekFlag == SeekFlag::DidSeek) {
|
2015-03-18 13:22:11 +00:00
|
|
|
mHoldTime = currentTime;
|
|
|
|
} else {
|
|
|
|
mHoldTime.SetValue(0);
|
|
|
|
}
|
|
|
|
} else if (mPlaybackRate != 0.0 &&
|
|
|
|
!currentTime.IsNull()) {
|
2015-05-11 08:17:06 +00:00
|
|
|
if (aSeekFlag == SeekFlag::DidSeek && !mHoldTime.IsNull()) {
|
2015-03-18 13:22:11 +00:00
|
|
|
mStartTime.SetValue(mTimeline->GetCurrentTime().Value() -
|
2015-03-30 15:27:05 +00:00
|
|
|
(mHoldTime.Value().MultDouble(1 / mPlaybackRate)));
|
2015-03-18 13:22:11 +00:00
|
|
|
}
|
|
|
|
mHoldTime.SetNull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-18 23:51:13 +00:00
|
|
|
bool currentFinishedState = PlayState() == AnimationPlayState::Finished;
|
2015-03-18 13:22:11 +00:00
|
|
|
if (currentFinishedState && !mIsPreviousStateFinished) {
|
|
|
|
if (mFinished) {
|
|
|
|
mFinished->MaybeResolve(this);
|
|
|
|
}
|
|
|
|
} else if (!currentFinishedState && mIsPreviousStateFinished) {
|
|
|
|
// Clear finished promise. We'll create a new one lazily.
|
|
|
|
mFinished = nullptr;
|
2015-04-06 22:48:55 +00:00
|
|
|
if (mEffect->AsTransition()) {
|
|
|
|
mEffect->SetIsFinishedTransition(false);
|
|
|
|
}
|
2015-03-18 13:22:11 +00:00
|
|
|
}
|
|
|
|
mIsPreviousStateFinished = currentFinishedState;
|
2015-03-23 13:23:19 +00:00
|
|
|
// We must recalculate the current time to take account of any mHoldTime
|
|
|
|
// changes the code above made.
|
|
|
|
mPreviousCurrentTime = GetCurrentTime();
|
2015-03-18 13:22:11 +00:00
|
|
|
}
|
|
|
|
|
2014-12-22 00:35:42 +00:00
|
|
|
void
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::UpdateEffect()
|
2014-12-22 00:35:42 +00:00
|
|
|
{
|
2015-04-14 23:48:21 +00:00
|
|
|
if (mEffect) {
|
|
|
|
mEffect->SetParentTime(GetCurrentTime());
|
2015-03-14 05:34:40 +00:00
|
|
|
UpdateRelevance();
|
2014-12-22 00:35:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-20 04:55:43 +00:00
|
|
|
void
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::FlushStyle() const
|
2014-10-20 04:55:43 +00:00
|
|
|
{
|
2014-11-17 04:45:58 +00:00
|
|
|
nsIDocument* doc = GetRenderedDocument();
|
2014-10-20 04:55:47 +00:00
|
|
|
if (doc) {
|
|
|
|
doc->FlushPendingNotifications(Flush_Style);
|
2014-10-20 04:55:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-17 04:45:59 +00:00
|
|
|
void
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::PostUpdate()
|
2014-11-17 04:45:59 +00:00
|
|
|
{
|
2015-04-21 01:22:10 +00:00
|
|
|
AnimationCollection* collection = GetCollection();
|
2014-11-17 04:45:59 +00:00
|
|
|
if (collection) {
|
2015-04-21 01:22:10 +00:00
|
|
|
collection->NotifyAnimationUpdated();
|
2014-11-17 04:45:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-17 23:42:41 +00:00
|
|
|
void
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::CancelPendingTasks()
|
2014-12-17 23:42:41 +00:00
|
|
|
{
|
2015-03-27 06:56:45 +00:00
|
|
|
if (mPendingState == PendingState::NotPending) {
|
2014-12-17 23:42:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument* doc = GetRenderedDocument();
|
|
|
|
if (doc) {
|
2015-04-21 01:22:09 +00:00
|
|
|
PendingAnimationTracker* tracker = doc->GetPendingAnimationTracker();
|
2014-12-17 23:42:41 +00:00
|
|
|
if (tracker) {
|
2015-03-27 06:56:45 +00:00
|
|
|
if (mPendingState == PendingState::PlayPending) {
|
|
|
|
tracker->RemovePlayPending(*this);
|
|
|
|
} else {
|
|
|
|
tracker->RemovePausePending(*this);
|
|
|
|
}
|
2014-12-17 23:42:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-27 06:56:45 +00:00
|
|
|
mPendingState = PendingState::NotPending;
|
2015-01-08 22:57:58 +00:00
|
|
|
mPendingReadyTime.SetNull();
|
2014-12-17 23:42:41 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 22:57:58 +00:00
|
|
|
bool
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::IsPossiblyOrphanedPendingAnimation() const
|
2015-01-08 22:57:58 +00:00
|
|
|
{
|
|
|
|
// Check if we are pending but might never start because we are not being
|
|
|
|
// tracked.
|
|
|
|
//
|
|
|
|
// This covers the following cases:
|
|
|
|
//
|
2015-04-14 23:48:21 +00:00
|
|
|
// * We started playing but our effect's target element was orphaned
|
2015-01-08 22:57:58 +00:00
|
|
|
// or bound to a different document.
|
2015-04-14 23:48:21 +00:00
|
|
|
// (note that for the case of our effect changing we should handle
|
|
|
|
// that in SetEffect)
|
2015-01-08 22:57:58 +00:00
|
|
|
// * We started playing but our timeline became inactive.
|
2015-04-21 01:22:09 +00:00
|
|
|
// In this case the pending animation tracker will drop us from its hashmap
|
2015-01-08 22:57:58 +00:00
|
|
|
// when we have been painted.
|
2015-04-21 01:22:09 +00:00
|
|
|
// * When we started playing we couldn't find a PendingAnimationTracker to
|
2015-04-14 23:48:21 +00:00
|
|
|
// register with (perhaps the effect had no document) so we simply
|
2015-03-27 06:56:45 +00:00
|
|
|
// set mPendingState in DoPlay and relied on this method to catch us on the
|
2015-01-08 22:57:58 +00:00
|
|
|
// next tick.
|
|
|
|
|
|
|
|
// If we're not pending we're ok.
|
2015-03-27 06:56:45 +00:00
|
|
|
if (mPendingState == PendingState::NotPending) {
|
2015-01-08 22:57:58 +00: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.
|
|
|
|
if (!mTimeline || mTimeline->GetCurrentTime().IsNull()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have no rendered document, or we're not in our rendered document's
|
2015-04-21 01:22:09 +00:00
|
|
|
// PendingAnimationTracker then there's a good chance no one is tracking us.
|
2015-01-08 22:57:58 +00:00
|
|
|
//
|
|
|
|
// If we're wrong and another document is tracking us then, at worst, we'll
|
2015-03-27 06:56:45 +00:00
|
|
|
// simply start/pause the animation one tick too soon. That's better than
|
|
|
|
// never starting/pausing the animation and is unlikely.
|
2015-01-08 22:57:58 +00:00
|
|
|
nsIDocument* doc = GetRenderedDocument();
|
2015-03-27 06:56:45 +00:00
|
|
|
if (!doc) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-21 01:22:09 +00:00
|
|
|
PendingAnimationTracker* tracker = doc->GetPendingAnimationTracker();
|
2015-03-27 06:56:45 +00:00
|
|
|
return !tracker ||
|
|
|
|
(!tracker->IsWaitingToPlay(*this) &&
|
|
|
|
!tracker->IsWaitingToPause(*this));
|
2015-01-08 22:57:58 +00:00
|
|
|
}
|
|
|
|
|
2014-10-20 04:55:45 +00:00
|
|
|
StickyTimeDuration
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::EffectEnd() const
|
2014-10-20 04:55:45 +00:00
|
|
|
{
|
2015-04-14 23:48:21 +00:00
|
|
|
if (!mEffect) {
|
2014-10-20 04:55:45 +00:00
|
|
|
return StickyTimeDuration(0);
|
|
|
|
}
|
|
|
|
|
2015-04-14 23:48:21 +00:00
|
|
|
return mEffect->Timing().mDelay
|
|
|
|
+ mEffect->GetComputedTiming().mActiveDuration;
|
2014-10-20 04:55:45 +00:00
|
|
|
}
|
|
|
|
|
2014-11-17 04:45:58 +00:00
|
|
|
nsIDocument*
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::GetRenderedDocument() const
|
2014-11-17 04:45:58 +00:00
|
|
|
{
|
2015-04-14 23:48:21 +00:00
|
|
|
if (!mEffect) {
|
2014-11-17 04:45:58 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Element* targetElement;
|
|
|
|
nsCSSPseudoElements::Type pseudoType;
|
2015-04-14 23:48:21 +00:00
|
|
|
mEffect->GetTarget(targetElement, pseudoType);
|
2014-11-17 04:45:58 +00:00
|
|
|
if (!targetElement) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return targetElement->GetComposedDoc();
|
|
|
|
}
|
|
|
|
|
2014-11-17 04:45:58 +00:00
|
|
|
nsPresContext*
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::GetPresContext() const
|
2014-11-17 04:45:58 +00:00
|
|
|
{
|
|
|
|
nsIDocument* doc = GetRenderedDocument();
|
|
|
|
if (!doc) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsIPresShell* shell = doc->GetShell();
|
|
|
|
if (!shell) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return shell->GetPresContext();
|
|
|
|
}
|
|
|
|
|
2015-04-21 01:22:10 +00:00
|
|
|
AnimationCollection*
|
2015-04-21 01:22:09 +00:00
|
|
|
Animation::GetCollection() const
|
2014-11-17 04:45:59 +00:00
|
|
|
{
|
|
|
|
css::CommonAnimationManager* manager = GetAnimationManager();
|
|
|
|
if (!manager) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-04-21 01:22:09 +00:00
|
|
|
MOZ_ASSERT(mEffect,
|
|
|
|
"An animation with an animation manager must have an effect");
|
2014-11-17 04:45:59 +00:00
|
|
|
|
|
|
|
Element* targetElement;
|
|
|
|
nsCSSPseudoElements::Type targetPseudoType;
|
2015-04-14 23:48:21 +00:00
|
|
|
mEffect->GetTarget(targetElement, targetPseudoType);
|
2014-11-17 04:45:59 +00:00
|
|
|
MOZ_ASSERT(targetElement,
|
2015-04-21 01:22:09 +00:00
|
|
|
"An animation with an animation manager must have a target");
|
2014-11-17 04:45:59 +00:00
|
|
|
|
2015-03-20 18:20:49 +00:00
|
|
|
return manager->GetAnimations(targetElement, targetPseudoType, false);
|
2014-11-17 04:45:59 +00:00
|
|
|
}
|
|
|
|
|
2014-08-10 07:06:44 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|