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: */
|
2015-04-10 04:34:22 +03: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_DocumentTimeline_h
|
|
|
|
#define mozilla_dom_DocumentTimeline_h
|
|
|
|
|
2019-01-08 09:45:18 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2016-09-28 10:56:24 +03:00
|
|
|
#include "mozilla/dom/DocumentTimelineBinding.h"
|
2016-10-09 16:36:56 +03:00
|
|
|
#include "mozilla/LinkedList.h"
|
2015-04-10 04:34:22 +03:00
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "AnimationTimeline.h"
|
2016-06-29 05:13:45 +03:00
|
|
|
#include "nsDOMNavigationTiming.h" // for DOMHighResTimeStamp
|
2020-10-15 13:05:07 +03:00
|
|
|
#include "nsRefreshDriver.h"
|
2020-08-05 00:17:50 +03:00
|
|
|
#include "nsRefreshObservers.h"
|
2015-04-10 04:34:22 +03:00
|
|
|
|
|
|
|
struct JSContext;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-09-28 06:38:40 +03:00
|
|
|
class DocumentTimeline final : public AnimationTimeline,
|
|
|
|
public nsARefreshObserver,
|
2018-07-03 04:59:55 +03:00
|
|
|
public nsATimerAdjustmentObserver,
|
2016-10-09 16:36:56 +03:00
|
|
|
public LinkedListElement<DocumentTimeline> {
|
2015-04-10 04:34:22 +03:00
|
|
|
public:
|
2020-11-23 19:07:43 +03:00
|
|
|
DocumentTimeline(Document* aDocument, const TimeDuration& aOriginTime);
|
2015-04-10 04:34:22 +03:00
|
|
|
|
|
|
|
protected:
|
2020-11-23 19:07:43 +03:00
|
|
|
virtual ~DocumentTimeline();
|
2015-04-10 04:34:22 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(DocumentTimeline,
|
|
|
|
AnimationTimeline)
|
|
|
|
|
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
2016-06-29 05:13:45 +03:00
|
|
|
static already_AddRefed<DocumentTimeline> Constructor(
|
2016-09-28 10:56:24 +03:00
|
|
|
const GlobalObject& aGlobal, const DocumentTimelineOptions& aOptions,
|
2016-06-29 05:13:45 +03:00
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2015-04-28 05:17:10 +03:00
|
|
|
// AnimationTimeline methods
|
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
|
|
|
|
virtual Nullable<TimeDuration> GetCurrentTimeAsDuration() const override;
|
2015-04-10 04:34:22 +03:00
|
|
|
|
2020-08-05 00:17:50 +03:00
|
|
|
bool TracksWallclockTime() const override;
|
2015-04-28 05:17:10 +03:00
|
|
|
Nullable<TimeDuration> ToTimelineTime(
|
|
|
|
const TimeStamp& aTimeStamp) const override;
|
|
|
|
TimeStamp ToTimeStamp(const TimeDuration& aTimelineTime) const override;
|
2015-04-10 04:34:22 +03:00
|
|
|
|
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
|
|
|
void NotifyAnimationUpdated(Animation& aAnimation) override;
|
|
|
|
|
2016-06-23 07:09:03 +03:00
|
|
|
void RemoveAnimation(Animation* aAnimation) override;
|
|
|
|
|
2015-09-28 06:38:40 +03:00
|
|
|
// nsARefreshObserver methods
|
|
|
|
void WillRefresh(TimeStamp aTime) override;
|
2018-07-03 04:59:55 +03:00
|
|
|
// nsATimerAdjustmentObserver methods
|
|
|
|
void NotifyTimerAdjusted(TimeStamp aTime) override;
|
2015-09-28 06:38:40 +03:00
|
|
|
|
2015-09-28 06:38:40 +03:00
|
|
|
void NotifyRefreshDriverCreated(nsRefreshDriver* aDriver);
|
|
|
|
void NotifyRefreshDriverDestroying(nsRefreshDriver* aDriver);
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* GetDocument() const override { return mDocument; }
|
2018-07-03 05:05:23 +03:00
|
|
|
|
2015-04-10 04:34:22 +03:00
|
|
|
protected:
|
|
|
|
TimeStamp GetCurrentTimeStamp() const;
|
2015-04-28 05:17:10 +03:00
|
|
|
nsRefreshDriver* GetRefreshDriver() const;
|
2016-08-17 03:53:22 +03:00
|
|
|
void UnregisterFromRefreshDriver();
|
2018-07-03 04:59:55 +03:00
|
|
|
void MostRecentRefreshTimeUpdated();
|
|
|
|
void ObserveRefreshDriver(nsRefreshDriver* aDriver);
|
|
|
|
void DisconnectRefreshDriver(nsRefreshDriver* aDriver);
|
2015-04-10 04:34:22 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
RefPtr<Document> mDocument;
|
2015-04-10 04:34:22 +03:00
|
|
|
|
|
|
|
// The most recently used refresh driver time. This is used in cases where
|
|
|
|
// we don't have a refresh driver (e.g. because we are in a display:none
|
|
|
|
// iframe).
|
2020-12-17 04:22:33 +03:00
|
|
|
mutable TimeStamp mLastRefreshDriverTime;
|
2015-09-28 06:38:40 +03:00
|
|
|
bool mIsObservingRefreshDriver;
|
2016-06-29 04:59:35 +03:00
|
|
|
|
|
|
|
TimeDuration mOriginTime;
|
2015-04-10 04:34:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_DocumentTimeline_h
|