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/. */
7 #ifndef mozilla_dom_PendingAnimationTracker_h
8 #define mozilla_dom_PendingAnimationTracker_h
10 #include "mozilla/dom/Animation.h"
11 #include "mozilla/TypedEnumBits.h"
12 #include "nsCycleCollectionParticipant.h"
13 #include "nsTHashSet.h"
23 class PendingAnimationTracker final
{
25 explicit PendingAnimationTracker(dom::Document
* aDocument
);
27 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(PendingAnimationTracker
)
28 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(PendingAnimationTracker
)
30 void AddPlayPending(dom::Animation
& aAnimation
) {
31 // We'd like to assert here that IsWaitingToPause(aAnimation) is false but
32 // if |aAnimation| was tracked here as a pause-pending animation when it was
33 // removed from |mDocument|, then re-attached to |mDocument|, and then
34 // played again, we could end up here with IsWaitingToPause returning true.
36 // However, that should be harmless since all it means is that we'll call
37 // Animation::TriggerOnNextTick or Animation::TriggerNow twice, both of
38 // which will handle the redundant call gracefully.
39 AddPending(aAnimation
, mPlayPendingSet
);
40 mHasPlayPendingGeometricAnimations
= CheckState::Indeterminate
;
42 void RemovePlayPending(dom::Animation
& aAnimation
) {
43 RemovePending(aAnimation
, mPlayPendingSet
);
44 mHasPlayPendingGeometricAnimations
= CheckState::Indeterminate
;
46 bool IsWaitingToPlay(const dom::Animation
& aAnimation
) const {
47 return IsWaiting(aAnimation
, mPlayPendingSet
);
50 void AddPausePending(dom::Animation
& aAnimation
) {
51 // As with AddPausePending, we'd like to assert that
52 // IsWaitingToPlay(aAnimation) is false but there are some circumstances
53 // where this can be true. Fortunately adding the animation to both pending
54 // sets should be harmless.
55 AddPending(aAnimation
, mPausePendingSet
);
57 void RemovePausePending(dom::Animation
& aAnimation
) {
58 RemovePending(aAnimation
, mPausePendingSet
);
60 bool IsWaitingToPause(const dom::Animation
& aAnimation
) const {
61 return IsWaiting(aAnimation
, mPausePendingSet
);
64 void TriggerPendingAnimationsOnNextTick(const TimeStamp
& aReadyTime
);
65 void TriggerPendingAnimationsNow();
66 bool HasPendingAnimations() const {
67 return mPlayPendingSet
.Count() > 0 || mPausePendingSet
.Count() > 0;
71 * Looks amongst the set of play-pending animations, and, if there are
72 * animations that affect geometric properties, notifies all play-pending
73 * animations so that they can be synchronized, if needed.
75 void MarkAnimationsThatMightNeedSynchronization();
78 ~PendingAnimationTracker() = default;
80 void EnsurePaintIsScheduled();
82 using AnimationSet
= nsTHashSet
<nsRefPtrHashKey
<dom::Animation
>>;
84 void AddPending(dom::Animation
& aAnimation
, AnimationSet
& aSet
);
85 void RemovePending(dom::Animation
& aAnimation
, AnimationSet
& aSet
);
86 bool IsWaiting(const dom::Animation
& aAnimation
,
87 const AnimationSet
& aSet
) const;
89 AnimationSet mPlayPendingSet
;
90 AnimationSet mPausePendingSet
;
91 RefPtr
<dom::Document
> mDocument
;
94 enum class CheckState
{
97 AnimationsPresent
= 1 << 1,
98 TransitionsPresent
= 1 << 2,
102 CheckState mHasPlayPendingGeometricAnimations
= CheckState::Indeterminate
;
105 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(PendingAnimationTracker::CheckState
)
107 } // namespace mozilla
109 #endif // mozilla_dom_PendingAnimationTracker_h