ScrollTimelineAnimationTracker.h (1664B)
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_ScrollTimelineAnimationTracker_h 8 #define mozilla_ScrollTimelineAnimationTracker_h 9 10 #include "mozilla/dom/Animation.h" 11 #include "nsCycleCollectionParticipant.h" 12 #include "nsTHashSet.h" 13 14 namespace mozilla { 15 16 namespace dom { 17 class Document; 18 } 19 20 /** 21 * Handle the pending animations which use scroll timeline while playing or 22 * pausing. 23 */ 24 class ScrollTimelineAnimationTracker final { 25 public: 26 explicit ScrollTimelineAnimationTracker(dom::Document* aDocument) 27 : mDocument(aDocument) {} 28 29 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING( 30 ScrollTimelineAnimationTracker) 31 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(ScrollTimelineAnimationTracker) 32 33 void AddPending(dom::Animation& aAnimation) { 34 mPendingSet.Insert(&aAnimation); 35 } 36 37 void RemovePending(dom::Animation& aAnimation) { 38 mPendingSet.Remove(&aAnimation); 39 } 40 41 bool HasPendingAnimations() const { return mPendingSet.Count() > 0; } 42 43 bool IsWaiting(const dom::Animation& aAnimation) const { 44 return mPendingSet.Contains(const_cast<dom::Animation*>(&aAnimation)); 45 } 46 47 void TriggerPendingAnimations(); 48 49 private: 50 ~ScrollTimelineAnimationTracker() = default; 51 52 nsTHashSet<nsRefPtrHashKey<dom::Animation>> mPendingSet; 53 RefPtr<dom::Document> mDocument; 54 }; 55 56 } // namespace mozilla 57 58 #endif // mozilla_ScrollTimelineAnimationTracker_h