DocumentTimeline.h (2804B)
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 "AnimationTimeline.h" 11 #include "mozilla/LinkedList.h" 12 #include "mozilla/TimeStamp.h" 13 #include "mozilla/dom/Document.h" 14 #include "mozilla/dom/DocumentTimelineBinding.h" 15 #include "nsDOMNavigationTiming.h" // for DOMHighResTimeStamp 16 #include "nsRefreshDriver.h" 17 18 struct JSContext; 19 20 namespace mozilla::dom { 21 22 class DocumentTimeline final : public AnimationTimeline, 23 public LinkedListElement<DocumentTimeline> { 24 public: 25 DocumentTimeline(Document* aDocument, const TimeDuration& aOriginTime); 26 27 protected: 28 virtual ~DocumentTimeline(); 29 30 public: 31 NS_DECL_ISUPPORTS_INHERITED 32 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(DocumentTimeline, 33 AnimationTimeline) 34 35 JSObject* WrapObject(JSContext*, JS::Handle<JSObject*> aGivenProto) override; 36 37 static already_AddRefed<DocumentTimeline> Constructor( 38 const GlobalObject& aGlobal, const DocumentTimelineOptions& aOptions, 39 ErrorResult& aRv); 40 41 // AnimationTimeline methods 42 43 // This is deliberately _not_ called GetCurrentTime since that would clash 44 // with a macro defined in winbase.h 45 Nullable<TimeDuration> GetCurrentTimeAsDuration() const override; 46 47 bool TracksWallclockTime() const override; 48 Nullable<TimeDuration> ToTimelineTime( 49 const TimeStamp& aTimeStamp) const override; 50 TimeStamp ToTimeStamp(const TimeDuration& aTimelineTime) const override; 51 52 void NotifyAnimationUpdated(Animation& aAnimation) override; 53 54 void NotifyAnimationContentVisibilityChanged(Animation* aAnimation, 55 bool aIsVisible) override; 56 57 void TriggerAllPendingAnimationsNow(); 58 59 void WillRefresh(); 60 61 Document* GetDocument() const override { return mDocument; } 62 63 void UpdateLastRefreshDriverTime(); 64 65 bool IsMonotonicallyIncreasing() const override { return true; } 66 67 protected: 68 TimeStamp GetCurrentTimeStamp() const; 69 nsRefreshDriver* GetRefreshDriver() const; 70 71 RefPtr<Document> mDocument; 72 73 // The most recently used refresh driver time. This is used in cases where 74 // we don't have a refresh driver (e.g. because we are in a display:none 75 // iframe). 76 TimeStamp mLastRefreshDriverTime; 77 TimeDuration mOriginTime; 78 79 private: 80 TimeStamp EnsureValidTimestamp(const TimeStamp& aTimestamp) const; 81 }; 82 83 } // namespace mozilla::dom 84 85 #endif // mozilla_dom_DocumentTimeline_h