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-05-13 11:22:12 +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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_AnimationTimeline_h
|
|
|
|
#define mozilla_dom_AnimationTimeline_h
|
|
|
|
|
2015-04-10 04:34:22 +03:00
|
|
|
#include "nsISupports.h"
|
2014-05-13 11:22:12 +04:00
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2015-04-28 10:41:09 +03:00
|
|
|
#include "js/TypeDecls.h"
|
2015-04-10 04:34:22 +03:00
|
|
|
#include "mozilla/AnimationUtils.h"
|
2014-05-13 11:22:12 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2015-04-28 10:41:09 +03:00
|
|
|
#include "nsHashKeys.h"
|
2015-01-26 20:08:51 +03:00
|
|
|
#include "nsIGlobalObject.h"
|
2015-04-28 10:41:09 +03:00
|
|
|
#include "nsTHashtable.h"
|
2014-05-13 11:22:12 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-07-11 03:49:32 +03:00
|
|
|
class Animation;
|
2019-01-02 16:05:23 +03:00
|
|
|
class Document;
|
2015-07-11 03:49:32 +03:00
|
|
|
|
2015-04-10 04:34:22 +03:00
|
|
|
class AnimationTimeline : public nsISupports, public nsWrapperCache {
|
2014-05-13 11:22:12 +04:00
|
|
|
public:
|
2015-04-10 04:34:22 +03:00
|
|
|
explicit AnimationTimeline(nsIGlobalObject* aWindow) : mWindow(aWindow) {
|
2015-01-26 20:08:51 +03:00
|
|
|
MOZ_ASSERT(mWindow);
|
2014-05-13 11:22:12 +04:00
|
|
|
}
|
|
|
|
|
2014-12-18 02:42:41 +03:00
|
|
|
protected:
|
2018-12-26 05:35:30 +03:00
|
|
|
virtual ~AnimationTimeline();
|
2014-12-18 02:42:41 +03:00
|
|
|
|
|
|
|
public:
|
2015-04-10 04:34:22 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(AnimationTimeline)
|
2014-05-13 11:22:12 +04:00
|
|
|
|
2015-04-10 04:34:22 +03:00
|
|
|
nsIGlobalObject* GetParentObject() const { return mWindow; }
|
2014-05-13 11:22:12 +04:00
|
|
|
|
2014-10-20 08:55:45 +04:00
|
|
|
// AnimationTimeline methods
|
2018-12-07 01:16:48 +03:00
|
|
|
virtual Nullable<TimeDuration> GetCurrentTimeAsDuration() const = 0;
|
2014-05-13 11:22:12 +04:00
|
|
|
|
2014-10-20 08:55:45 +04:00
|
|
|
// Wrapper functions for AnimationTimeline DOM methods when called from
|
|
|
|
// script.
|
2015-04-10 04:34:22 +03:00
|
|
|
Nullable<double> GetCurrentTimeAsDouble() const {
|
2018-12-07 01:16:48 +03:00
|
|
|
return AnimationUtils::TimeDurationToDouble(GetCurrentTimeAsDuration());
|
2015-01-09 01:57:58 +03:00
|
|
|
}
|
2014-12-22 03:35:42 +03:00
|
|
|
|
2018-07-05 00:19:12 +03:00
|
|
|
TimeStamp GetCurrentTimeAsTimeStamp() const {
|
2018-12-07 01:16:48 +03:00
|
|
|
Nullable<TimeDuration> currentTime = GetCurrentTimeAsDuration();
|
2018-07-05 00:19:12 +03:00
|
|
|
return !currentTime.IsNull() ? ToTimeStamp(currentTime.Value())
|
|
|
|
: TimeStamp();
|
|
|
|
}
|
|
|
|
|
2015-04-28 05:17:10 +03:00
|
|
|
/**
|
2018-12-07 01:16:48 +03:00
|
|
|
* Returns true if the times returned by GetCurrentTimeAsDuration() are
|
|
|
|
* convertible to and from wallclock-based TimeStamp (e.g. from
|
|
|
|
* TimeStamp::Now()) values using ToTimelineTime() and ToTimeStamp().
|
2015-04-28 05:17:10 +03:00
|
|
|
*
|
|
|
|
* Typically this is true, but it will be false in the case when this
|
|
|
|
* timeline has no refresh driver or is tied to a refresh driver under test
|
|
|
|
* control.
|
|
|
|
*/
|
|
|
|
virtual bool TracksWallclockTime() const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a TimeStamp to the equivalent value in timeline time.
|
|
|
|
* Note that when TracksWallclockTime() is false, there is no correspondence
|
|
|
|
* between timeline time and wallclock time. In such a case, passing a
|
|
|
|
* timestamp from TimeStamp::Now() to this method will not return a
|
|
|
|
* meaningful result.
|
|
|
|
*/
|
|
|
|
virtual Nullable<TimeDuration> ToTimelineTime(
|
|
|
|
const TimeStamp& aTimeStamp) const = 0;
|
|
|
|
|
|
|
|
virtual TimeStamp ToTimeStamp(const TimeDuration& aTimelineTime) const = 0;
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Inform this timeline that |aAnimation| which is or was observing the
|
|
|
|
* timeline, has been updated. This serves as both the means to associate
|
|
|
|
* AND disassociate animations with a timeline. The timeline itself will
|
|
|
|
* determine if it needs to begin, continue or stop tracking this animation.
|
|
|
|
*/
|
|
|
|
virtual void NotifyAnimationUpdated(Animation& aAnimation);
|
2015-04-28 10:41:09 +03:00
|
|
|
|
2016-02-22 16:05:20 +03:00
|
|
|
/**
|
|
|
|
* Returns true if any CSS animations, CSS transitions or Web animations are
|
|
|
|
* currently associated with this timeline. As soon as an animation is
|
|
|
|
* applied to an element it is associated with the timeline even if it has a
|
|
|
|
* delayed start, so this includes animations that may not be active for some
|
|
|
|
* time.
|
|
|
|
*/
|
|
|
|
bool HasAnimations() const { return !mAnimations.IsEmpty(); }
|
|
|
|
|
2016-06-23 07:09:03 +03:00
|
|
|
virtual void RemoveAnimation(Animation* aAnimation);
|
2015-11-16 20:44:55 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
virtual Document* GetDocument() const = 0;
|
2018-07-03 05:05:23 +03:00
|
|
|
|
2014-08-30 10:11:57 +04:00
|
|
|
protected:
|
2015-01-26 20:08:51 +03:00
|
|
|
nsCOMPtr<nsIGlobalObject> mWindow;
|
2015-04-28 10:41:09 +03:00
|
|
|
|
|
|
|
// Animations observing this timeline
|
2015-09-28 06:38:41 +03:00
|
|
|
//
|
|
|
|
// We store them in (a) a hashset for quick lookup, and (b) an array
|
|
|
|
// to maintain a fixed sampling order.
|
|
|
|
//
|
2015-11-16 20:44:55 +03:00
|
|
|
// The hashset keeps a strong reference to each animation since
|
|
|
|
// dealing with addref/release with LinkedList is difficult.
|
|
|
|
typedef nsTHashtable<nsRefPtrHashKey<dom::Animation>> AnimationSet;
|
|
|
|
AnimationSet mAnimations;
|
|
|
|
LinkedList<dom::Animation> mAnimationOrder;
|
2014-05-13 11:22:12 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_AnimationTimeline_h
|