Line data Source code
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 LinkedListElement<DocumentTimeline>
33 : {
34 : public:
35 22 : DocumentTimeline(nsIDocument* aDocument, const TimeDuration& aOriginTime)
36 22 : : AnimationTimeline(aDocument->GetParentObject())
37 : , mDocument(aDocument)
38 : , mIsObservingRefreshDriver(false)
39 22 : , mOriginTime(aOriginTime)
40 : {
41 22 : if (mDocument) {
42 22 : mDocument->Timelines().insertBack(this);
43 : }
44 22 : }
45 :
46 : protected:
47 0 : virtual ~DocumentTimeline()
48 0 : {
49 0 : MOZ_ASSERT(!mIsObservingRefreshDriver, "Timeline should have disassociated"
50 : " from the refresh driver before being destroyed");
51 0 : if (isInList()) {
52 0 : remove();
53 : }
54 0 : }
55 :
56 : public:
57 : NS_DECL_ISUPPORTS_INHERITED
58 22 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(DocumentTimeline,
59 : AnimationTimeline)
60 :
61 : virtual JSObject* WrapObject(JSContext* aCx,
62 : JS::Handle<JSObject*> aGivenProto) override;
63 :
64 : static already_AddRefed<DocumentTimeline>
65 : Constructor(const GlobalObject& aGlobal,
66 : const DocumentTimelineOptions& aOptions,
67 : ErrorResult& aRv);
68 :
69 : // AnimationTimeline methods
70 : virtual Nullable<TimeDuration> GetCurrentTime() const override;
71 :
72 2 : bool TracksWallclockTime() const override
73 : {
74 2 : nsRefreshDriver* refreshDriver = GetRefreshDriver();
75 4 : return !refreshDriver ||
76 4 : !refreshDriver->IsTestControllingRefreshesEnabled();
77 : }
78 : Nullable<TimeDuration> ToTimelineTime(const TimeStamp& aTimeStamp) const
79 : override;
80 : TimeStamp ToTimeStamp(const TimeDuration& aTimelineTime) const override;
81 :
82 : void NotifyAnimationUpdated(Animation& aAnimation) override;
83 :
84 : void RemoveAnimation(Animation* aAnimation) override;
85 :
86 : // nsARefreshObserver methods
87 : void WillRefresh(TimeStamp aTime) override;
88 :
89 : void NotifyRefreshDriverCreated(nsRefreshDriver* aDriver);
90 : void NotifyRefreshDriverDestroying(nsRefreshDriver* aDriver);
91 :
92 : protected:
93 : TimeStamp GetCurrentTimeStamp() const;
94 : nsRefreshDriver* GetRefreshDriver() const;
95 : void UnregisterFromRefreshDriver();
96 :
97 : nsCOMPtr<nsIDocument> mDocument;
98 :
99 : // The most recently used refresh driver time. This is used in cases where
100 : // we don't have a refresh driver (e.g. because we are in a display:none
101 : // iframe).
102 : mutable TimeStamp mLastRefreshDriverTime;
103 : bool mIsObservingRefreshDriver;
104 :
105 : TimeDuration mOriginTime;
106 : };
107 :
108 : } // namespace dom
109 : } // namespace mozilla
110 :
111 : #endif // mozilla_dom_DocumentTimeline_h
|