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
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef mozilla_AnimationCollection_h
8 : #define mozilla_AnimationCollection_h
9 :
10 : #include "mozilla/dom/Animation.h"
11 : #include "mozilla/dom/Element.h"
12 : #include "mozilla/Assertions.h"
13 : #include "mozilla/LinkedList.h"
14 : #include "mozilla/RefPtr.h"
15 : #include "nsCSSPseudoElements.h"
16 : #include "nsDOMMutationObserver.h"
17 : #include "nsTArray.h"
18 :
19 : class nsIAtom;
20 : class nsPresContext;
21 :
22 : namespace mozilla {
23 :
24 : // Traits class to define the specific atoms used when storing specializations
25 : // of AnimationCollection as a property on an Element (e.g. which atom
26 : // to use when storing an AnimationCollection<CSSAnimation> for a ::before
27 : // pseudo-element).
28 : template <class AnimationType>
29 : struct AnimationTypeTraits { };
30 :
31 : template <class AnimationType>
32 : class AnimationCollection
33 : : public LinkedListElement<AnimationCollection<AnimationType>>
34 : {
35 : typedef AnimationCollection<AnimationType> SelfType;
36 : typedef AnimationTypeTraits<AnimationType> TraitsType;
37 :
38 2 : AnimationCollection(dom::Element* aElement, nsIAtom* aElementProperty)
39 : : mElement(aElement)
40 : , mElementProperty(aElementProperty)
41 : , mCheckGeneration(0)
42 : #ifdef DEBUG
43 2 : , mCalledPropertyDtor(false)
44 : #endif
45 : {
46 2 : MOZ_COUNT_CTOR(AnimationCollection);
47 2 : }
48 :
49 : public:
50 0 : ~AnimationCollection()
51 : {
52 0 : MOZ_ASSERT(mCalledPropertyDtor,
53 : "must call destructor through element property dtor");
54 0 : MOZ_COUNT_DTOR(AnimationCollection);
55 0 : LinkedListElement<SelfType>::remove();
56 0 : }
57 :
58 0 : void Destroy()
59 : {
60 : // This will call our destructor.
61 0 : mElement->DeleteProperty(mElementProperty);
62 0 : }
63 :
64 : static void PropertyDtor(void *aObject, nsIAtom *aPropertyName,
65 : void *aPropertyValue, void *aData);
66 :
67 : // Get the collection of animations for the given |aElement| and
68 : // |aPseudoType|.
69 : static AnimationCollection<AnimationType>*
70 : GetAnimationCollection(const dom::Element* aElement,
71 : CSSPseudoElementType aPseudoType);
72 :
73 : // Given the frame |aFrame| with possibly animated content, finds its
74 : // associated collection of animations. If |aFrame| is a generated content
75 : // frame, this function may examine the parent frame to search for such
76 : // animations.
77 : static AnimationCollection<AnimationType>* GetAnimationCollection(
78 : const nsIFrame* aFrame);
79 :
80 : // Get the collection of animations for the given |aElement| and
81 : // |aPseudoType| or create it if it does not already exist.
82 : //
83 : // We'll set the outparam |aCreatedCollection| to true if we have
84 : // to create the collection and we successfully do so. Otherwise,
85 : // we'll set it to false.
86 : static AnimationCollection<AnimationType>*
87 : GetOrCreateAnimationCollection(dom::Element* aElement,
88 : CSSPseudoElementType aPseudoType,
89 : bool* aCreatedCollection);
90 :
91 : static nsString PseudoTypeAsString(CSSPseudoElementType aPseudoType);
92 :
93 : dom::Element *mElement;
94 :
95 : // the atom we use in mElement's prop table (must be a static atom,
96 : // i.e., in an atom list)
97 : nsIAtom *mElementProperty;
98 :
99 : InfallibleTArray<RefPtr<AnimationType>> mAnimations;
100 :
101 : // For CSS transitions only, we record the most recent generation
102 : // for which we've done the transition update, so that we avoid doing
103 : // it more than once per style change.
104 : // (Note that we also store an animation generation on each EffectSet in
105 : // order to track when we need to update animations on layers.)
106 : uint64_t mCheckGeneration;
107 :
108 : // Update mCheckGeneration to RestyleManager's count
109 : void UpdateCheckGeneration(nsPresContext* aPresContext);
110 :
111 : private:
112 : static nsIAtom* GetPropertyAtomForPseudoType(
113 : CSSPseudoElementType aPseudoType);
114 :
115 : #ifdef DEBUG
116 : bool mCalledPropertyDtor;
117 : #endif
118 : };
119 :
120 : } // namespace mozilla
121 :
122 : #endif // mozilla_AnimationCollection_h
|