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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_AnimationCollection_h
8 #define mozilla_AnimationCollection_h
10 #include "mozilla/Assertions.h"
11 #include "mozilla/LinkedList.h"
12 #include "mozilla/RefPtr.h"
13 #include "nsCSSPseudoElements.h"
14 #include "nsTArrayForwardDeclare.h"
25 // Traits class to define the specific atoms used when storing specializations
26 // of AnimationCollection as a property on an Element (e.g. which atom
27 // to use when storing an AnimationCollection<CSSAnimation> for a ::before
29 template <class AnimationType
>
30 struct AnimationTypeTraits
{};
32 template <class AnimationType
>
33 class AnimationCollection
34 : public LinkedListElement
<AnimationCollection
<AnimationType
>> {
35 typedef AnimationCollection
<AnimationType
> SelfType
;
36 typedef AnimationTypeTraits
<AnimationType
> TraitsType
;
38 AnimationCollection(dom::Element
* aElement
, nsAtom
* aElementProperty
)
39 : mElement(aElement
), mElementProperty(aElementProperty
) {
40 MOZ_COUNT_CTOR(AnimationCollection
);
44 ~AnimationCollection() {
45 MOZ_ASSERT(mCalledPropertyDtor
,
46 "must call destructor through element property dtor");
47 MOZ_COUNT_DTOR(AnimationCollection
);
48 LinkedListElement
<SelfType
>::remove();
53 static void PropertyDtor(void* aObject
, nsAtom
* aPropertyName
,
54 void* aPropertyValue
, void* aData
);
56 // Get the collection of animations for the given |aElement| and
58 static AnimationCollection
<AnimationType
>* GetAnimationCollection(
59 const dom::Element
* aElement
, PseudoStyleType aPseudoType
);
61 // Given the frame |aFrame| with possibly animated content, finds its
62 // associated collection of animations. If |aFrame| is a generated content
63 // frame, this function may examine the parent frame to search for such
65 static AnimationCollection
<AnimationType
>* GetAnimationCollection(
66 const nsIFrame
* aFrame
);
68 // Get the collection of animations for the given |aElement| and
69 // |aPseudoType| or create it if it does not already exist.
71 // We'll set the outparam |aCreatedCollection| to true if we have
72 // to create the collection and we successfully do so. Otherwise,
73 // we'll set it to false.
74 static AnimationCollection
<AnimationType
>* GetOrCreateAnimationCollection(
75 dom::Element
* aElement
, PseudoStyleType aPseudoType
,
76 bool* aCreatedCollection
);
78 dom::Element
* mElement
;
80 // the atom we use in mElement's prop table (must be a static atom,
81 // i.e., in an atom list)
82 nsAtom
* mElementProperty
;
84 nsTArray
<RefPtr
<AnimationType
>> mAnimations
;
87 static nsAtom
* GetPropertyAtomForPseudoType(PseudoStyleType aPseudoType
);
89 // We distinguish between destroying this by calling Destroy() vs directly
90 // calling RemoveProperty on an element.
92 // The former case represents regular updating due to style changes and should
93 // trigger subsequent restyles.
95 // The latter case represents document tear-down or other DOM surgery in
96 // which case we should not trigger restyles.
97 bool mCalledDestroy
= false;
100 bool mCalledPropertyDtor
= false;
104 } // namespace mozilla
106 #endif // mozilla_AnimationCollection_h