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
|
|
|
#ifndef mozilla_dom_Animation_h
|
|
|
|
#define mozilla_dom_Animation_h
|
2014-08-10 11:06:44 +04:00
|
|
|
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2016-12-02 04:13:06 +03:00
|
|
|
#include "mozilla/AnimationPerformanceWarning.h"
|
2014-08-10 11:06:44 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2017-11-17 06:01:27 +03:00
|
|
|
#include "mozilla/CycleCollectedJSContext.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2016-01-06 05:04:05 +03:00
|
|
|
#include "mozilla/EffectCompositor.h" // For EffectCompositor::CascadeLevel
|
2015-11-16 20:44:55 +03:00
|
|
|
#include "mozilla/LinkedList.h"
|
2014-08-10 11:06:44 +04:00
|
|
|
#include "mozilla/TimeStamp.h" // for TimeStamp, TimeDuration
|
2015-04-21 04:22:09 +03:00
|
|
|
#include "mozilla/dom/AnimationBinding.h" // for AnimationPlayState
|
2018-05-07 05:15:16 +03:00
|
|
|
#include "mozilla/dom/AnimationEffect.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
#include "mozilla/dom/AnimationTimeline.h"
|
|
|
|
#include "mozilla/dom/Promise.h"
|
|
|
|
#include "nsCSSPropertyID.h"
|
2015-04-28 09:48:35 +03:00
|
|
|
#include "nsIGlobalObject.h"
|
2014-08-10 11:06:44 +04:00
|
|
|
|
|
|
|
// X11 has a #define for CurrentTime.
|
|
|
|
#ifdef CurrentTime
|
|
|
|
#undef CurrentTime
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct JSContext;
|
2016-08-17 04:46:58 +03:00
|
|
|
class nsCSSPropertyIDSet;
|
2014-11-17 07:45:58 +03:00
|
|
|
class nsIDocument;
|
2016-12-02 04:13:06 +03:00
|
|
|
class nsIFrame;
|
2014-08-10 11:06:44 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2015-07-29 04:57:39 +03:00
|
|
|
|
2017-01-24 10:19:18 +03:00
|
|
|
struct AnimationRule;
|
2014-10-20 08:55:44 +04:00
|
|
|
|
2015-06-30 04:00:39 +03:00
|
|
|
namespace dom {
|
|
|
|
|
2017-11-17 06:01:27 +03:00
|
|
|
class AsyncFinishNotification;
|
2015-04-21 04:22:10 +03:00
|
|
|
class CSSAnimation;
|
|
|
|
class CSSTransition;
|
2014-10-20 08:55:44 +04:00
|
|
|
|
2015-07-31 00:23:00 +03:00
|
|
|
class Animation : public DOMEventTargetHelper,
|
2015-11-16 20:44:55 +03:00
|
|
|
public LinkedListElement<Animation> {
|
2014-08-10 11:06:44 +04:00
|
|
|
protected:
|
2015-04-21 04:22:09 +03:00
|
|
|
virtual ~Animation() {}
|
2014-08-10 11:06:44 +04:00
|
|
|
|
|
|
|
public:
|
2015-04-28 11:21:58 +03:00
|
|
|
explicit Animation(nsIGlobalObject* aGlobal)
|
2015-07-31 00:23:00 +03:00
|
|
|
: DOMEventTargetHelper(aGlobal),
|
2015-03-13 23:10:45 +03:00
|
|
|
mPlaybackRate(1.0),
|
2015-09-15 05:20:56 +03:00
|
|
|
mAnimationIndex(sNextAnimationIndex++),
|
2018-09-05 00:31:57 +03:00
|
|
|
mCachedChildIndex(-1),
|
2018-09-04 00:58:15 +03:00
|
|
|
mPendingState(PendingState::NotPending),
|
2015-04-02 06:30:17 +03:00
|
|
|
mFinishedAtLastComposeStyle(false),
|
2015-03-14 08:34:40 +03:00
|
|
|
mIsRelevant(false),
|
2015-07-30 00:21:00 +03:00
|
|
|
mFinishedIsResolved(false),
|
2016-12-02 04:19:10 +03:00
|
|
|
mSyncWithGeometricAnimations(false) {}
|
2014-08-10 11:06:44 +04:00
|
|
|
|
2015-07-31 00:23:00 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Animation, DOMEventTargetHelper)
|
2014-08-10 11:06:44 +04:00
|
|
|
|
2016-07-06 03:20:29 +03:00
|
|
|
nsIGlobalObject* GetParentObject() const { return GetOwnerGlobal(); }
|
2015-04-10 04:34:22 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2014-08-10 11:06:44 +04:00
|
|
|
|
2015-04-21 04:22:10 +03:00
|
|
|
virtual CSSAnimation* AsCSSAnimation() { return nullptr; }
|
2015-06-09 05:13:53 +03:00
|
|
|
virtual const CSSAnimation* AsCSSAnimation() const { return nullptr; }
|
2015-04-21 04:22:10 +03:00
|
|
|
virtual CSSTransition* AsCSSTransition() { return nullptr; }
|
2015-06-09 05:13:53 +03:00
|
|
|
virtual const CSSTransition* AsCSSTransition() const { return nullptr; }
|
2014-10-20 08:55:44 +04:00
|
|
|
|
2015-04-27 04:05:47 +03:00
|
|
|
/**
|
|
|
|
* Flag to pass to Play to indicate whether or not it should automatically
|
|
|
|
* rewind the current time to the start point if the animation is finished.
|
|
|
|
* For regular calls to play() from script we should do this, but when a CSS
|
|
|
|
* animation's animation-play-state changes we shouldn't rewind the animation.
|
|
|
|
*/
|
|
|
|
enum class LimitBehavior { AutoRewind, Continue };
|
2015-03-18 16:22:11 +03:00
|
|
|
|
2015-04-27 04:05:46 +03:00
|
|
|
// Animation interface methods
|
2016-01-17 03:02:00 +03:00
|
|
|
static already_AddRefed<Animation> Constructor(
|
|
|
|
const GlobalObject& aGlobal, AnimationEffect* aEffect,
|
2016-05-30 03:01:11 +03:00
|
|
|
const Optional<AnimationTimeline*>& aTimeline, ErrorResult& aRv);
|
2016-01-08 11:17:00 +03:00
|
|
|
void GetId(nsAString& aResult) const { aResult = mId; }
|
|
|
|
void SetId(const nsAString& aId);
|
2018-05-07 05:15:16 +03:00
|
|
|
AnimationEffect* GetEffect() const { return mEffect; }
|
|
|
|
void SetEffect(AnimationEffect* aEffect);
|
2015-04-28 10:25:07 +03:00
|
|
|
AnimationTimeline* GetTimeline() const { return mTimeline; }
|
2015-04-28 11:21:58 +03:00
|
|
|
void SetTimeline(AnimationTimeline* aTimeline);
|
2014-12-04 19:28:38 +03:00
|
|
|
Nullable<TimeDuration> GetStartTime() const { return mStartTime; }
|
2015-02-09 13:26:27 +03:00
|
|
|
void SetStartTime(const Nullable<TimeDuration>& aNewStartTime);
|
2018-12-07 01:16:48 +03:00
|
|
|
// This is deliberately _not_ called GetCurrentTime since that would clash
|
|
|
|
// with a macro defined in winbase.h
|
|
|
|
Nullable<TimeDuration> GetCurrentTimeAsDuration() const {
|
2018-02-13 09:04:18 +03:00
|
|
|
return GetCurrentTimeForHoldTime(mHoldTime);
|
|
|
|
}
|
2015-03-09 19:50:39 +03:00
|
|
|
void SetCurrentTime(const TimeDuration& aNewCurrentTime);
|
2015-03-13 23:10:45 +03:00
|
|
|
double PlaybackRate() const { return mPlaybackRate; }
|
|
|
|
void SetPlaybackRate(double aPlaybackRate);
|
2014-10-20 08:55:45 +04:00
|
|
|
AnimationPlayState PlayState() const;
|
2017-11-21 11:10:59 +03:00
|
|
|
bool Pending() const { return mPendingState != PendingState::NotPending; }
|
2014-12-18 02:42:41 +03:00
|
|
|
virtual Promise* GetReady(ErrorResult& aRv);
|
2017-11-27 01:44:53 +03:00
|
|
|
Promise* GetFinished(ErrorResult& aRv);
|
2015-04-27 02:53:18 +03:00
|
|
|
void Cancel();
|
2017-11-27 01:44:53 +03:00
|
|
|
void Finish(ErrorResult& aRv);
|
2015-05-19 08:00:48 +03:00
|
|
|
virtual void Play(ErrorResult& aRv, LimitBehavior aLimitBehavior);
|
2015-05-19 08:55:26 +03:00
|
|
|
virtual void Pause(ErrorResult& aRv);
|
2017-11-27 01:44:53 +03:00
|
|
|
void Reverse(ErrorResult& aRv);
|
2018-02-13 09:04:18 +03:00
|
|
|
void UpdatePlaybackRate(double aPlaybackRate);
|
2015-09-16 17:05:00 +03:00
|
|
|
bool IsRunningOnCompositor() const;
|
2015-07-31 00:25:00 +03:00
|
|
|
IMPL_EVENT_HANDLER(finish);
|
2015-07-31 00:26:00 +03:00
|
|
|
IMPL_EVENT_HANDLER(cancel);
|
2014-08-10 11:06:44 +04:00
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
// Wrapper functions for Animation DOM methods when called
|
2015-04-27 04:05:46 +03:00
|
|
|
// from script.
|
|
|
|
//
|
|
|
|
// We often use the same methods internally and from script but when called
|
|
|
|
// from script we (or one of our subclasses) perform extra steps such as
|
|
|
|
// flushing style or converting the return type.
|
2014-12-04 19:28:38 +03:00
|
|
|
Nullable<double> GetStartTimeAsDouble() const;
|
2015-02-09 13:26:27 +03:00
|
|
|
void SetStartTimeAsDouble(const Nullable<double>& aStartTime);
|
2014-10-20 08:55:45 +04:00
|
|
|
Nullable<double> GetCurrentTimeAsDouble() const;
|
2015-03-09 19:50:39 +03:00
|
|
|
void SetCurrentTimeAsDouble(const Nullable<double>& aCurrentTime,
|
|
|
|
ErrorResult& aRv);
|
2014-11-17 07:45:58 +03:00
|
|
|
virtual AnimationPlayState PlayStateFromJS() const { return PlayState(); }
|
2017-11-21 11:10:59 +03:00
|
|
|
virtual bool PendingFromJS() const { return Pending(); }
|
2015-05-19 08:00:48 +03:00
|
|
|
virtual void PlayFromJS(ErrorResult& aRv) {
|
|
|
|
Play(aRv, LimitBehavior::AutoRewind);
|
|
|
|
}
|
2015-04-27 04:05:47 +03:00
|
|
|
/**
|
|
|
|
* PauseFromJS is currently only here for symmetry with PlayFromJS but
|
|
|
|
* in future we will likely have to flush style in
|
|
|
|
* CSSAnimation::PauseFromJS so we leave it for now.
|
|
|
|
*/
|
2015-05-19 08:55:26 +03:00
|
|
|
void PauseFromJS(ErrorResult& aRv) { Pause(aRv); }
|
2015-06-09 05:13:53 +03:00
|
|
|
|
2015-04-27 02:53:19 +03:00
|
|
|
// Wrapper functions for Animation DOM methods when called from style.
|
2015-06-09 05:13:53 +03:00
|
|
|
|
2016-05-31 03:42:37 +03:00
|
|
|
virtual void CancelFromStyle() { CancelNoUpdate(); }
|
2016-05-31 03:42:37 +03:00
|
|
|
void SetTimelineNoUpdate(AnimationTimeline* aTimeline);
|
2018-05-07 05:15:16 +03:00
|
|
|
void SetEffectNoUpdate(AnimationEffect* aEffect);
|
2015-04-27 02:53:19 +03:00
|
|
|
|
2015-07-29 04:57:39 +03:00
|
|
|
virtual void Tick();
|
2015-09-28 06:38:40 +03:00
|
|
|
bool NeedsTicks() const {
|
2017-11-21 11:10:59 +03:00
|
|
|
return Pending() || PlayState() == AnimationPlayState::Running;
|
2015-09-28 06:38:40 +03:00
|
|
|
}
|
2014-12-18 02:42:41 +03:00
|
|
|
|
2014-12-25 10:28:24 +03:00
|
|
|
/**
|
2015-04-21 04:22:09 +03:00
|
|
|
* Set the time to use for starting or pausing a pending animation.
|
2015-03-27 09:56:45 +03:00
|
|
|
*
|
2015-04-21 04:22:09 +03:00
|
|
|
* Typically, when an animation is played, it does not start immediately but
|
|
|
|
* is added to a table of pending animations on the document of its effect.
|
2015-01-09 01:57:58 +03:00
|
|
|
* In the meantime it sets its hold time to the time from which playback
|
|
|
|
* should begin.
|
2014-12-25 10:28:24 +03:00
|
|
|
*
|
2015-04-21 04:22:09 +03:00
|
|
|
* When the document finishes painting, any pending animations in its table
|
2018-06-06 03:53:13 +03:00
|
|
|
* are marked as being ready to start by calling TriggerOnNextTick.
|
2015-01-09 01:57:58 +03:00
|
|
|
* The moment when the paint completed is also recorded, converted to a
|
|
|
|
* timeline time, and passed to StartOnTick. This is so that when these
|
2015-04-21 04:22:09 +03:00
|
|
|
* animations do start, they can be timed from the point when painting
|
2015-01-09 01:57:58 +03:00
|
|
|
* completed.
|
|
|
|
*
|
2015-04-21 04:22:09 +03:00
|
|
|
* After calling TriggerOnNextTick, animations remain in the pending state
|
|
|
|
* until the next refresh driver tick. At that time they transition out of
|
|
|
|
* the pending state using the time passed to TriggerOnNextTick as the
|
|
|
|
* effective time at which they resumed.
|
2014-12-25 10:28:24 +03:00
|
|
|
*
|
|
|
|
* This approach means that any setup time required for performing the
|
|
|
|
* initial paint of an animation such as layerization is not deducted from
|
|
|
|
* the running time of the animation. Without this we can easily drop the
|
|
|
|
* first few frames of an animation, or, on slower devices, the whole
|
|
|
|
* animation.
|
2015-01-09 01:57:58 +03:00
|
|
|
*
|
|
|
|
* Furthermore:
|
|
|
|
*
|
2015-04-21 04:22:09 +03:00
|
|
|
* - Starting the animation immediately when painting finishes is problematic
|
|
|
|
* because the start time of the animation will be ahead of its timeline
|
2015-01-09 01:57:58 +03:00
|
|
|
* (since the timeline time is based on the refresh driver time).
|
2015-04-21 04:22:09 +03:00
|
|
|
* That's a problem because the animation is playing but its timing
|
|
|
|
* suggests it starts in the future. We could update the timeline to match
|
|
|
|
* the start time of the animation but then we'd also have to update the
|
|
|
|
* timing and style of all animations connected to that timeline or else be
|
|
|
|
* stuck in an inconsistent state until the next refresh driver tick.
|
2015-01-09 01:57:58 +03:00
|
|
|
*
|
|
|
|
* - If we simply use the refresh driver time on its next tick, the lag
|
|
|
|
* between triggering an animation and its effective start is unacceptably
|
|
|
|
* long.
|
|
|
|
*
|
2015-03-27 09:56:45 +03:00
|
|
|
* For pausing, we apply the same asynchronous approach. This is so that we
|
|
|
|
* synchronize with animations that are running on the compositor. Otherwise
|
|
|
|
* if the main thread lags behind the compositor there will be a noticeable
|
|
|
|
* jump backwards when the main thread takes over. Even though main thread
|
|
|
|
* animations could be paused immediately, we do it asynchronously for
|
|
|
|
* consistency and so that animations paused together end up in step.
|
|
|
|
*
|
2015-04-21 04:22:09 +03:00
|
|
|
* Note that the caller of this method is responsible for removing the
|
|
|
|
* animation from any PendingAnimationTracker it may have been added to.
|
2014-12-25 10:28:24 +03:00
|
|
|
*/
|
2015-03-27 09:56:45 +03:00
|
|
|
void TriggerOnNextTick(const Nullable<TimeDuration>& aReadyTime);
|
2015-04-27 04:05:47 +03:00
|
|
|
/**
|
|
|
|
* Testing only: Start or pause a pending animation using the current
|
|
|
|
* timeline time. This is used to support existing tests that expect
|
|
|
|
* animations to begin immediately. Ideally we would rewrite the those tests
|
|
|
|
* and get rid of this method, but there are a lot of them.
|
|
|
|
*
|
|
|
|
* As with TriggerOnNextTick, the caller of this method is responsible for
|
|
|
|
* removing the animation from any PendingAnimationTracker it may have been
|
|
|
|
* added to.
|
|
|
|
*/
|
2015-03-27 09:56:45 +03:00
|
|
|
void TriggerNow();
|
2015-02-03 08:08:37 +03:00
|
|
|
/**
|
2018-06-06 03:53:13 +03:00
|
|
|
* When TriggerOnNextTick is called, we store the ready time but we don't
|
|
|
|
* apply it until the next tick. In the meantime, GetStartTime() will return
|
|
|
|
* null.
|
2015-02-03 08:08:37 +03:00
|
|
|
*
|
|
|
|
* However, if we build layer animations again before the next tick, we
|
|
|
|
* should initialize them with the start time that GetStartTime() will return
|
|
|
|
* on the next tick.
|
|
|
|
*
|
|
|
|
* If we were to simply set the start time of layer animations to null, their
|
|
|
|
* start time would be updated to the current wallclock time when rendering
|
|
|
|
* finishes, thus making them out of sync with the start time stored here.
|
|
|
|
* This, in turn, will make the animation jump backwards when we build
|
|
|
|
* animations on the next tick and apply the start time stored here.
|
|
|
|
*
|
|
|
|
* This method returns the start time, if resolved. Otherwise, if we have
|
|
|
|
* a pending ready time, it returns the corresponding start time. If neither
|
|
|
|
* of those are available, it returns null.
|
|
|
|
*/
|
|
|
|
Nullable<TimeDuration> GetCurrentOrPendingStartTime() const;
|
|
|
|
|
2018-02-13 09:04:18 +03:00
|
|
|
/**
|
|
|
|
* As with the start time, we should use the pending playback rate when
|
|
|
|
* producing layer animations.
|
|
|
|
*/
|
|
|
|
double CurrentOrPendingPlaybackRate() const {
|
|
|
|
return mPendingPlaybackRate.valueOr(mPlaybackRate);
|
|
|
|
}
|
|
|
|
bool HasPendingPlaybackRate() const { return mPendingPlaybackRate.isSome(); }
|
2018-02-13 09:04:18 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The following relationship from the definition of the 'current time' is
|
|
|
|
* re-used in many algorithms so we extract it here into a static method that
|
|
|
|
* can be re-used:
|
|
|
|
*
|
|
|
|
* current time = (timeline time - start time) * playback rate
|
|
|
|
*
|
|
|
|
* As per https://drafts.csswg.org/web-animations-1/#current-time
|
|
|
|
*/
|
|
|
|
static TimeDuration CurrentTimeFromTimelineTime(
|
|
|
|
const TimeDuration& aTimelineTime, const TimeDuration& aStartTime,
|
|
|
|
float aPlaybackRate) {
|
|
|
|
return (aTimelineTime - aStartTime).MultDouble(aPlaybackRate);
|
|
|
|
}
|
|
|
|
|
2018-02-13 09:04:18 +03:00
|
|
|
/**
|
2018-02-13 09:04:18 +03:00
|
|
|
* As with calculating the current time, we often need to calculate a start
|
|
|
|
* time from a current time. The following method simply inverts the current
|
|
|
|
* time relationship.
|
|
|
|
*
|
|
|
|
* In each case where this is used, the desired behavior for playbackRate ==
|
|
|
|
* 0 is to return the specified timeline time (often referred to as the ready
|
|
|
|
* time).
|
2018-02-13 09:04:18 +03:00
|
|
|
*/
|
2018-02-13 09:04:18 +03:00
|
|
|
static TimeDuration StartTimeFromTimelineTime(
|
|
|
|
const TimeDuration& aTimelineTime, const TimeDuration& aCurrentTime,
|
|
|
|
float aPlaybackRate) {
|
|
|
|
TimeDuration result = aTimelineTime;
|
|
|
|
if (aPlaybackRate == 0) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
result -= aCurrentTime.MultDouble(1.0 / aPlaybackRate);
|
|
|
|
return result;
|
|
|
|
}
|
2016-10-14 13:14:01 +03:00
|
|
|
|
2015-11-18 03:50:00 +03:00
|
|
|
/**
|
|
|
|
* Converts a time in the timescale of this Animation's currentTime, to a
|
|
|
|
* TimeStamp. Returns a null TimeStamp if the conversion cannot be performed
|
|
|
|
* because of the current state of this Animation (e.g. it has no timeline, a
|
|
|
|
* zero playbackRate, an unresolved start time etc.) or the value of the time
|
|
|
|
* passed-in (e.g. an infinite time).
|
|
|
|
*/
|
|
|
|
TimeStamp AnimationTimeToTimeStamp(const StickyTimeDuration& aTime) const;
|
|
|
|
|
2016-10-19 09:16:52 +03:00
|
|
|
// Converts an AnimationEvent's elapsedTime value to an equivalent TimeStamp
|
|
|
|
// that can be used to sort events by when they occurred.
|
|
|
|
TimeStamp ElapsedTimeToTimeStamp(
|
|
|
|
const StickyTimeDuration& aElapsedTime) const;
|
|
|
|
|
2015-03-27 09:56:45 +03:00
|
|
|
bool IsPausedOrPausing() const {
|
2018-03-16 06:49:55 +03:00
|
|
|
return PlayState() == AnimationPlayState::Paused;
|
2015-03-27 09:56:45 +03:00
|
|
|
}
|
2014-10-02 10:14:13 +04:00
|
|
|
|
2015-04-15 02:48:21 +03:00
|
|
|
bool HasCurrentEffect() const {
|
2015-10-07 08:30:27 +03:00
|
|
|
return GetEffect() && GetEffect()->IsCurrent();
|
2014-10-02 10:14:13 +04:00
|
|
|
}
|
2015-04-15 02:48:21 +03:00
|
|
|
bool IsInEffect() const { return GetEffect() && GetEffect()->IsInEffect(); }
|
2014-08-10 11:06:44 +04:00
|
|
|
|
2016-12-02 09:34:13 +03:00
|
|
|
bool IsPlaying() const {
|
|
|
|
return mPlaybackRate != 0.0 && mTimeline &&
|
2018-12-07 01:16:48 +03:00
|
|
|
!mTimeline->GetCurrentTimeAsDuration().IsNull() &&
|
2018-03-16 06:49:55 +03:00
|
|
|
PlayState() == AnimationPlayState::Running;
|
2015-03-27 12:01:00 +03:00
|
|
|
}
|
2016-12-02 09:34:13 +03:00
|
|
|
|
2016-12-02 04:13:06 +03:00
|
|
|
bool ShouldBeSynchronizedWithMainThread(
|
|
|
|
nsCSSPropertyID aProperty, const nsIFrame* aFrame,
|
2018-11-22 07:01:10 +03:00
|
|
|
AnimationPerformanceWarning::Type& aPerformanceWarning /* out */) const;
|
2016-12-02 04:13:06 +03:00
|
|
|
|
2015-03-14 08:34:40 +03:00
|
|
|
bool IsRelevant() const { return mIsRelevant; }
|
|
|
|
void UpdateRelevance();
|
2015-06-09 05:13:53 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this Animation has a lower composite order than aOther.
|
|
|
|
*/
|
2016-01-14 04:24:24 +03:00
|
|
|
bool HasLowerCompositeOrderThan(const Animation& aOther) const;
|
2015-06-09 05:13:53 +03:00
|
|
|
|
2016-01-06 05:04:05 +03:00
|
|
|
/**
|
2016-01-06 05:04:05 +03:00
|
|
|
* Returns the level at which the effect(s) associated with this Animation
|
|
|
|
* are applied to the CSS cascade.
|
2016-01-06 05:04:05 +03:00
|
|
|
*/
|
2016-01-06 05:04:05 +03:00
|
|
|
virtual EffectCompositor::CascadeLevel CascadeLevel() const {
|
|
|
|
return EffectCompositor::CascadeLevel::Animations;
|
|
|
|
}
|
2016-01-06 05:04:05 +03:00
|
|
|
|
2015-04-27 04:05:47 +03:00
|
|
|
/**
|
|
|
|
* Returns true if this animation does not currently need to update
|
|
|
|
* style on the main thread (e.g. because it is empty, or is
|
|
|
|
* running on the compositor).
|
|
|
|
*/
|
2014-10-20 08:55:45 +04:00
|
|
|
bool CanThrottle() const;
|
2017-03-08 23:20:17 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates various bits of state that we need to update as the result of
|
|
|
|
* running ComposeStyle().
|
2018-05-07 05:08:59 +03:00
|
|
|
* See the comment of KeyframeEffect::WillComposeStyle for more detail.
|
2017-03-08 23:20:17 +03:00
|
|
|
*/
|
|
|
|
void WillComposeStyle();
|
|
|
|
|
2015-04-27 04:05:47 +03:00
|
|
|
/**
|
2017-03-17 07:22:13 +03:00
|
|
|
* Updates |aComposeResult| with the animation values of this animation's
|
|
|
|
* effect, if any.
|
2016-10-05 08:42:56 +03:00
|
|
|
* Any properties contained in |aPropertiesToSkip| will not be added or
|
2017-03-17 07:22:13 +03:00
|
|
|
* updated in |aComposeResult|.
|
2015-04-27 04:05:47 +03:00
|
|
|
*/
|
2018-04-09 14:15:59 +03:00
|
|
|
void ComposeStyle(RawServoAnimationValueMap& aComposeResult,
|
2016-10-05 08:42:56 +03:00
|
|
|
const nsCSSPropertyIDSet& aPropertiesToSkip);
|
2015-08-17 21:28:00 +03:00
|
|
|
|
|
|
|
void NotifyEffectTimingUpdated();
|
2016-12-02 04:19:10 +03:00
|
|
|
void NotifyGeometricAnimationsStartingThisFrame();
|
2015-08-17 21:28:00 +03:00
|
|
|
|
2018-07-12 11:05:13 +03:00
|
|
|
/**
|
|
|
|
* Reschedule pending pause or pending play tasks when updating the target
|
|
|
|
* effect.
|
|
|
|
*
|
|
|
|
* If we are pending, we will either be registered in the pending animation
|
|
|
|
* tracker and have a null pending ready time, or, after our effect has been
|
|
|
|
* painted, we will be removed from the tracker and assigned a pending ready
|
|
|
|
* time.
|
|
|
|
*
|
|
|
|
* When the target effect is updated, we'll typically need to repaint so for
|
|
|
|
* the latter case where we already have a pending ready time, clear it and
|
|
|
|
* put ourselves back in the pending animation tracker.
|
|
|
|
*/
|
|
|
|
void ReschedulePendingTasks();
|
|
|
|
|
2016-12-20 10:03:29 +03:00
|
|
|
/**
|
|
|
|
* Used by subclasses to synchronously queue a cancel event in situations
|
|
|
|
* where the Animation may have been cancelled.
|
|
|
|
*
|
|
|
|
* We need to do this synchronously because after a CSS animation/transition
|
|
|
|
* is canceled, it will be released by its owning element and may not still
|
|
|
|
* exist when we would normally go to queue events on the next tick.
|
|
|
|
*/
|
2018-01-17 12:05:03 +03:00
|
|
|
virtual void MaybeQueueCancelEvent(const StickyTimeDuration& aActiveTime){};
|
2016-12-20 10:03:29 +03:00
|
|
|
|
2018-09-05 00:31:57 +03:00
|
|
|
int32_t& CachedChildIndexRef() { return mCachedChildIndex; }
|
|
|
|
|
2014-10-20 08:55:43 +04:00
|
|
|
protected:
|
2015-04-27 04:05:46 +03:00
|
|
|
void SilentlySetCurrentTime(const TimeDuration& aNewCurrentTime);
|
2016-05-31 03:42:37 +03:00
|
|
|
void CancelNoUpdate();
|
|
|
|
void PlayNoUpdate(ErrorResult& aRv, LimitBehavior aLimitBehavior);
|
2015-04-01 06:23:24 +03:00
|
|
|
void ResumeAt(const TimeDuration& aReadyTime);
|
|
|
|
void PauseAt(const TimeDuration& aReadyTime);
|
|
|
|
void FinishPendingAt(const TimeDuration& aReadyTime) {
|
|
|
|
if (mPendingState == PendingState::PlayPending) {
|
|
|
|
ResumeAt(aReadyTime);
|
|
|
|
} else if (mPendingState == PendingState::PausePending) {
|
|
|
|
PauseAt(aReadyTime);
|
|
|
|
} else {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"Can't finish pending if we're not in a pending state");
|
2015-04-01 06:23:24 +03:00
|
|
|
}
|
|
|
|
}
|
2018-02-13 09:04:18 +03:00
|
|
|
void ApplyPendingPlaybackRate() {
|
|
|
|
if (mPendingPlaybackRate) {
|
|
|
|
mPlaybackRate = *mPendingPlaybackRate;
|
|
|
|
mPendingPlaybackRate.reset();
|
|
|
|
}
|
|
|
|
}
|
2014-11-17 07:46:01 +03:00
|
|
|
|
2015-05-11 11:17:06 +03:00
|
|
|
/**
|
|
|
|
* Finishing behavior depends on if changes to timing occurred due
|
|
|
|
* to a seek or regular playback.
|
|
|
|
*/
|
|
|
|
enum class SeekFlag { NoSeek, DidSeek };
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-30 00:21:00 +03:00
|
|
|
enum class SyncNotifyFlag { Sync, Async };
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-09-15 05:20:56 +03:00
|
|
|
virtual void UpdateTiming(SeekFlag aSeekFlag, SyncNotifyFlag aSyncNotifyFlag);
|
2015-07-30 00:21:00 +03:00
|
|
|
void UpdateFinishedState(SeekFlag aSeekFlag, SyncNotifyFlag aSyncNotifyFlag);
|
2015-04-15 02:48:21 +03:00
|
|
|
void UpdateEffect();
|
2018-04-11 12:01:14 +03:00
|
|
|
/**
|
|
|
|
* Flush all pending styles other than throttled animation styles (e.g.
|
|
|
|
* animations running on the compositor).
|
|
|
|
*/
|
|
|
|
void FlushUnanimatedStyle() const;
|
2014-11-17 07:45:59 +03:00
|
|
|
void PostUpdate();
|
2015-07-30 00:21:00 +03:00
|
|
|
void ResetFinishedPromise();
|
|
|
|
void MaybeResolveFinishedPromise();
|
|
|
|
void DoFinishNotification(SyncNotifyFlag aSyncNotifyFlag);
|
2017-11-17 06:01:27 +03:00
|
|
|
friend class AsyncFinishNotification;
|
|
|
|
void DoFinishNotificationImmediately(MicroTaskRunnable* aAsync = nullptr);
|
2018-07-03 05:05:23 +03:00
|
|
|
void QueuePlaybackEvent(const nsAString& aName,
|
|
|
|
TimeStamp&& aScheduledEventTime);
|
2015-05-11 11:17:06 +03:00
|
|
|
|
2015-03-27 09:56:45 +03:00
|
|
|
/**
|
2015-04-21 04:22:09 +03:00
|
|
|
* Remove this animation from the pending animation tracker and reset
|
2015-03-27 09:56:45 +03:00
|
|
|
* mPendingState as necessary. The caller is responsible for resolving or
|
|
|
|
* aborting the mReady promise as necessary.
|
|
|
|
*/
|
|
|
|
void CancelPendingTasks();
|
2015-01-09 01:57:58 +03:00
|
|
|
|
2016-07-15 12:17:25 +03:00
|
|
|
/**
|
|
|
|
* Performs the same steps as CancelPendingTasks and also rejects and
|
|
|
|
* recreates the ready promise if the animation was pending.
|
|
|
|
*/
|
|
|
|
void ResetPendingTasks();
|
|
|
|
|
2016-12-02 04:19:10 +03:00
|
|
|
/**
|
|
|
|
* Returns true if this animation is not only play-pending, but has
|
|
|
|
* yet to be given a pending ready time. This roughly corresponds to
|
|
|
|
* animations that are waiting to be painted (since we set the pending
|
|
|
|
* ready time at the end of painting). Identifying such animations is
|
|
|
|
* useful because in some cases animations that are painted together
|
|
|
|
* may need to be synchronized.
|
2018-02-13 09:04:18 +03:00
|
|
|
*
|
|
|
|
* We don't, however, want to include animations with a fixed start time such
|
|
|
|
* as animations that are simply having their playbackRate updated or which
|
|
|
|
* are resuming from an aborted pause.
|
2016-12-02 04:19:10 +03:00
|
|
|
*/
|
|
|
|
bool IsNewlyStarted() const {
|
|
|
|
return mPendingState == PendingState::PlayPending &&
|
2018-02-13 09:04:18 +03:00
|
|
|
mPendingReadyTime.IsNull() && mStartTime.IsNull();
|
2016-12-02 04:19:10 +03:00
|
|
|
}
|
2015-04-21 04:22:09 +03:00
|
|
|
bool IsPossiblyOrphanedPendingAnimation() const;
|
2015-04-15 02:48:21 +03:00
|
|
|
StickyTimeDuration EffectEnd() const;
|
2014-10-20 08:55:44 +04:00
|
|
|
|
2018-02-13 09:04:18 +03:00
|
|
|
Nullable<TimeDuration> GetCurrentTimeForHoldTime(
|
|
|
|
const Nullable<TimeDuration>& aHoldTime) const;
|
2018-02-13 09:04:18 +03:00
|
|
|
Nullable<TimeDuration> GetUnconstrainedCurrentTime() const {
|
|
|
|
return GetCurrentTimeForHoldTime(Nullable<TimeDuration>());
|
|
|
|
}
|
2018-02-13 09:04:18 +03:00
|
|
|
|
2018-07-03 03:25:02 +03:00
|
|
|
// Earlier side of the elapsed time range reported in CSS Animations and CSS
|
|
|
|
// Transitions events.
|
|
|
|
//
|
|
|
|
// https://drafts.csswg.org/css-animations-2/#interval-start
|
|
|
|
// https://drafts.csswg.org/css-transitions-2/#interval-start
|
|
|
|
StickyTimeDuration IntervalStartTime(
|
|
|
|
const StickyTimeDuration& aActiveDuration) const {
|
|
|
|
MOZ_ASSERT(AsCSSTransition() || AsCSSAnimation(),
|
|
|
|
"Should be called for CSS animations or transitions");
|
|
|
|
static constexpr StickyTimeDuration zeroDuration = StickyTimeDuration();
|
|
|
|
return std::max(
|
|
|
|
std::min(StickyTimeDuration(-mEffect->SpecifiedTiming().Delay()),
|
|
|
|
aActiveDuration),
|
|
|
|
zeroDuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Later side of the elapsed time range reported in CSS Animations and CSS
|
|
|
|
// Transitions events.
|
|
|
|
//
|
|
|
|
// https://drafts.csswg.org/css-animations-2/#interval-end
|
|
|
|
// https://drafts.csswg.org/css-transitions-2/#interval-end
|
|
|
|
StickyTimeDuration IntervalEndTime(
|
|
|
|
const StickyTimeDuration& aActiveDuration) const {
|
|
|
|
MOZ_ASSERT(AsCSSTransition() || AsCSSAnimation(),
|
|
|
|
"Should be called for CSS animations or transitions");
|
|
|
|
|
|
|
|
static constexpr StickyTimeDuration zeroDuration = StickyTimeDuration();
|
|
|
|
return std::max(std::min((EffectEnd() - mEffect->SpecifiedTiming().Delay()),
|
|
|
|
aActiveDuration),
|
|
|
|
zeroDuration);
|
|
|
|
}
|
|
|
|
|
2018-07-05 00:19:12 +03:00
|
|
|
TimeStamp GetTimelineCurrentTimeAsTimeStamp() const {
|
|
|
|
return mTimeline ? mTimeline->GetCurrentTimeAsTimeStamp() : TimeStamp();
|
|
|
|
}
|
|
|
|
|
2014-11-17 07:45:58 +03:00
|
|
|
nsIDocument* GetRenderedDocument() const;
|
2018-07-03 05:05:23 +03:00
|
|
|
nsIDocument* GetTimelineDocument() const;
|
2014-11-17 07:45:58 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AnimationTimeline> mTimeline;
|
2018-05-07 05:15:16 +03:00
|
|
|
RefPtr<AnimationEffect> mEffect;
|
2014-12-04 19:28:38 +03:00
|
|
|
// The beginning of the delay period.
|
|
|
|
Nullable<TimeDuration> mStartTime; // Timeline timescale
|
2015-04-21 04:22:09 +03:00
|
|
|
Nullable<TimeDuration> mHoldTime; // Animation timescale
|
2015-01-09 01:57:58 +03:00
|
|
|
Nullable<TimeDuration> mPendingReadyTime; // Timeline timescale
|
2015-04-21 04:22:09 +03:00
|
|
|
Nullable<TimeDuration> mPreviousCurrentTime; // Animation timescale
|
2015-03-13 23:10:45 +03:00
|
|
|
double mPlaybackRate;
|
2018-02-13 09:04:18 +03:00
|
|
|
Maybe<double> mPendingPlaybackRate;
|
2014-12-18 02:42:40 +03:00
|
|
|
|
2015-05-19 08:55:26 +03:00
|
|
|
// A Promise that is replaced on each call to Play()
|
2014-12-18 02:42:41 +03:00
|
|
|
// and fulfilled when Play() is successfully completed.
|
|
|
|
// This object is lazily created by GetReady.
|
2017-12-15 23:55:08 +03:00
|
|
|
// See http://drafts.csswg.org/web-animations/#current-ready-promise
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> mReady;
|
2014-12-18 02:42:40 +03:00
|
|
|
|
2015-04-15 02:48:21 +03:00
|
|
|
// A Promise that is resolved when we reach the end of the effect, or
|
2015-03-18 16:22:11 +03:00
|
|
|
// 0 when playing backwards. The Promise is replaced if the animation is
|
|
|
|
// finished but then a state change makes it not finished.
|
|
|
|
// This object is lazily created by GetFinished.
|
2017-12-15 23:55:08 +03:00
|
|
|
// See http://drafts.csswg.org/web-animations/#current-finished-promise
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> mFinished;
|
2015-03-18 16:22:11 +03:00
|
|
|
|
2015-09-15 05:20:26 +03:00
|
|
|
static uint64_t sNextAnimationIndex;
|
2015-06-09 05:13:53 +03:00
|
|
|
|
2015-09-15 05:20:26 +03:00
|
|
|
// The relative position of this animation within the global animation list.
|
|
|
|
// This is kNoIndex while the animation is in the idle state and is updated
|
|
|
|
// each time the animation transitions out of the idle state.
|
|
|
|
//
|
|
|
|
// Note that subclasses such as CSSTransition and CSSAnimation may repurpose
|
|
|
|
// this member to implement their own brand of sorting. As a result, it is
|
|
|
|
// possible for two different objects to have the same index.
|
|
|
|
uint64_t mAnimationIndex;
|
2015-06-09 05:13:53 +03:00
|
|
|
|
2018-09-05 00:31:57 +03:00
|
|
|
// While ordering Animation objects for event dispatch, the index of the
|
|
|
|
// target node in its parent may be cached in mCachedChildIndex.
|
|
|
|
int32_t mCachedChildIndex;
|
|
|
|
|
2018-09-04 00:58:15 +03:00
|
|
|
// Indicates if the animation is in the pending state (and what state it is
|
|
|
|
// waiting to enter when it finished pending). We use this rather than
|
|
|
|
// checking if this animation is tracked by a PendingAnimationTracker because
|
|
|
|
// the animation will continue to be pending even after it has been removed
|
|
|
|
// from the PendingAnimationTracker while it is waiting for the next tick
|
|
|
|
// (see TriggerOnNextTick for details).
|
|
|
|
enum class PendingState : uint8_t { NotPending, PlayPending, PausePending };
|
|
|
|
PendingState mPendingState;
|
|
|
|
|
2015-04-02 06:30:17 +03:00
|
|
|
bool mFinishedAtLastComposeStyle;
|
2015-03-20 21:20:37 +03:00
|
|
|
// Indicates that the animation should be exposed in an element's
|
|
|
|
// getAnimations() list.
|
2015-03-14 08:34:40 +03:00
|
|
|
bool mIsRelevant;
|
2015-07-30 00:21:00 +03:00
|
|
|
|
|
|
|
// True if mFinished is resolved or would be resolved if mFinished has
|
|
|
|
// yet to be created. This is not set when mFinished is rejected since
|
|
|
|
// in that case mFinished is immediately reset to represent a new current
|
|
|
|
// finished promise.
|
|
|
|
bool mFinishedIsResolved;
|
2016-01-08 11:17:00 +03:00
|
|
|
|
2016-12-02 04:19:10 +03:00
|
|
|
// True if this animation was triggered at the same time as one or more
|
|
|
|
// geometric animations and hence we should run any transform animations on
|
|
|
|
// the main thread.
|
|
|
|
bool mSyncWithGeometricAnimations;
|
|
|
|
|
2018-09-04 00:58:15 +03:00
|
|
|
RefPtr<MicroTaskRunnable> mFinishNotificationTask;
|
|
|
|
|
2016-01-08 11:17:00 +03:00
|
|
|
nsString mId;
|
2014-08-10 11:06:44 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
#endif // mozilla_dom_Animation_h
|