/src/mozilla-central/dom/animation/DocumentTimeline.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
5 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_dom_DocumentTimeline_h |
8 | | #define mozilla_dom_DocumentTimeline_h |
9 | | |
10 | | #include "mozilla/dom/DocumentTimelineBinding.h" |
11 | | #include "mozilla/LinkedList.h" |
12 | | #include "mozilla/TimeStamp.h" |
13 | | #include "AnimationTimeline.h" |
14 | | #include "nsIDocument.h" |
15 | | #include "nsDOMNavigationTiming.h" // for DOMHighResTimeStamp |
16 | | #include "nsRefreshDriver.h" |
17 | | |
18 | | struct JSContext; |
19 | | |
20 | | // GetCurrentTime is defined in winbase.h as zero argument macro forwarding to |
21 | | // GetTickCount(). |
22 | | #ifdef GetCurrentTime |
23 | | #undef GetCurrentTime |
24 | | #endif |
25 | | |
26 | | namespace mozilla { |
27 | | namespace dom { |
28 | | |
29 | | class DocumentTimeline final |
30 | | : public AnimationTimeline |
31 | | , public nsARefreshObserver |
32 | | , public nsATimerAdjustmentObserver |
33 | | , public LinkedListElement<DocumentTimeline> |
34 | | { |
35 | | public: |
36 | | DocumentTimeline(nsIDocument* aDocument, const TimeDuration& aOriginTime) |
37 | | : AnimationTimeline(aDocument->GetParentObject()) |
38 | | , mDocument(aDocument) |
39 | | , mIsObservingRefreshDriver(false) |
40 | | , mOriginTime(aOriginTime) |
41 | 0 | { |
42 | 0 | if (mDocument) { |
43 | 0 | mDocument->Timelines().insertBack(this); |
44 | 0 | } |
45 | 0 | } |
46 | | |
47 | | protected: |
48 | | virtual ~DocumentTimeline() |
49 | 0 | { |
50 | 0 | MOZ_ASSERT(!mIsObservingRefreshDriver, "Timeline should have disassociated" |
51 | 0 | " from the refresh driver before being destroyed"); |
52 | 0 | if (isInList()) { |
53 | 0 | remove(); |
54 | 0 | } |
55 | 0 | } |
56 | | |
57 | | public: |
58 | | NS_DECL_ISUPPORTS_INHERITED |
59 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(DocumentTimeline, |
60 | | AnimationTimeline) |
61 | | |
62 | | virtual JSObject* WrapObject(JSContext* aCx, |
63 | | JS::Handle<JSObject*> aGivenProto) override; |
64 | | |
65 | | static already_AddRefed<DocumentTimeline> |
66 | | Constructor(const GlobalObject& aGlobal, |
67 | | const DocumentTimelineOptions& aOptions, |
68 | | ErrorResult& aRv); |
69 | | |
70 | | // AnimationTimeline methods |
71 | | virtual Nullable<TimeDuration> GetCurrentTime() const override; |
72 | | |
73 | | bool TracksWallclockTime() const override |
74 | 0 | { |
75 | 0 | nsRefreshDriver* refreshDriver = GetRefreshDriver(); |
76 | 0 | return !refreshDriver || |
77 | 0 | !refreshDriver->IsTestControllingRefreshesEnabled(); |
78 | 0 | } |
79 | | Nullable<TimeDuration> ToTimelineTime(const TimeStamp& aTimeStamp) const |
80 | | override; |
81 | | TimeStamp ToTimeStamp(const TimeDuration& aTimelineTime) const override; |
82 | | |
83 | | void NotifyAnimationUpdated(Animation& aAnimation) override; |
84 | | |
85 | | void RemoveAnimation(Animation* aAnimation) override; |
86 | | |
87 | | // nsARefreshObserver methods |
88 | | void WillRefresh(TimeStamp aTime) override; |
89 | | // nsATimerAdjustmentObserver methods |
90 | | void NotifyTimerAdjusted(TimeStamp aTime) override; |
91 | | |
92 | | void NotifyRefreshDriverCreated(nsRefreshDriver* aDriver); |
93 | | void NotifyRefreshDriverDestroying(nsRefreshDriver* aDriver); |
94 | | |
95 | 0 | nsIDocument* GetDocument() const override { return mDocument; } |
96 | | |
97 | | protected: |
98 | | TimeStamp GetCurrentTimeStamp() const; |
99 | | nsRefreshDriver* GetRefreshDriver() const; |
100 | | void UnregisterFromRefreshDriver(); |
101 | | void MostRecentRefreshTimeUpdated(); |
102 | | void ObserveRefreshDriver(nsRefreshDriver* aDriver); |
103 | | void DisconnectRefreshDriver(nsRefreshDriver* aDriver); |
104 | | |
105 | | nsCOMPtr<nsIDocument> mDocument; |
106 | | |
107 | | // The most recently used refresh driver time. This is used in cases where |
108 | | // we don't have a refresh driver (e.g. because we are in a display:none |
109 | | // iframe). |
110 | | mutable TimeStamp mLastRefreshDriverTime; |
111 | | bool mIsObservingRefreshDriver; |
112 | | |
113 | | TimeDuration mOriginTime; |
114 | | }; |
115 | | |
116 | | } // namespace dom |
117 | | } // namespace mozilla |
118 | | |
119 | | #endif // mozilla_dom_DocumentTimeline_h |