Bumping manifests a=b2g-bump
[gecko.git] / layout / style / nsAnimationManager.h
blob930e8dfa4f62c20551d18ebc3b32037bca9cd17c
1 /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef nsAnimationManager_h_
6 #define nsAnimationManager_h_
8 #include "mozilla/Attributes.h"
9 #include "mozilla/ContentEvents.h"
10 #include "AnimationCommon.h"
11 #include "nsCSSPseudoElements.h"
12 #include "mozilla/MemoryReporting.h"
13 #include "mozilla/TimeStamp.h"
15 class nsCSSKeyframesRule;
16 class nsStyleContext;
18 namespace mozilla {
19 namespace css {
20 class Declaration;
24 struct AnimationEventInfo {
25 nsRefPtr<mozilla::dom::Element> mElement;
26 mozilla::InternalAnimationEvent mEvent;
28 AnimationEventInfo(mozilla::dom::Element *aElement,
29 const nsSubstring& aAnimationName,
30 uint32_t aMessage, mozilla::TimeDuration aElapsedTime,
31 const nsAString& aPseudoElement)
32 : mElement(aElement), mEvent(true, aMessage)
34 // XXX Looks like nobody initialize WidgetEvent::time
35 mEvent.animationName = aAnimationName;
36 mEvent.elapsedTime = aElapsedTime.ToSeconds();
37 mEvent.pseudoElement = aPseudoElement;
40 // InternalAnimationEvent doesn't support copy-construction, so we need
41 // to ourselves in order to work with nsTArray
42 AnimationEventInfo(const AnimationEventInfo &aOther)
43 : mElement(aOther.mElement), mEvent(true, aOther.mEvent.message)
45 mEvent.AssignAnimationEventData(aOther.mEvent, false);
49 typedef InfallibleTArray<AnimationEventInfo> EventArray;
51 class nsAnimationManager MOZ_FINAL
52 : public mozilla::css::CommonAnimationManager
54 public:
55 explicit nsAnimationManager(nsPresContext *aPresContext)
56 : mozilla::css::CommonAnimationManager(aPresContext)
57 , mObservingRefreshDriver(false)
61 static mozilla::AnimationPlayerCollection*
62 GetAnimationsForCompositor(nsIContent* aContent, nsCSSProperty aProperty)
64 return mozilla::css::CommonAnimationManager::GetAnimationsForCompositor(
65 aContent, nsGkAtoms::animationsProperty, aProperty);
68 // Returns true if aContent or any of its ancestors has an animation.
69 static bool ContentOrAncestorHasAnimation(nsIContent* aContent) {
70 do {
71 if (aContent->GetProperty(nsGkAtoms::animationsProperty)) {
72 return true;
74 } while ((aContent = aContent->GetParent()));
76 return false;
79 void UpdateStyleAndEvents(mozilla::AnimationPlayerCollection* aEA,
80 mozilla::TimeStamp aRefreshTime,
81 mozilla::EnsureStyleRuleFlags aFlags);
82 void GetEventsForCurrentTime(mozilla::AnimationPlayerCollection* aEA,
83 EventArray &aEventsToDispatch);
85 // nsIStyleRuleProcessor (parts)
86 virtual void RulesMatching(ElementRuleProcessorData* aData) MOZ_OVERRIDE;
87 virtual void RulesMatching(PseudoElementRuleProcessorData* aData) MOZ_OVERRIDE;
88 virtual void RulesMatching(AnonBoxRuleProcessorData* aData) MOZ_OVERRIDE;
89 #ifdef MOZ_XUL
90 virtual void RulesMatching(XULTreeRuleProcessorData* aData) MOZ_OVERRIDE;
91 #endif
92 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf)
93 const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
94 virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
95 const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
97 // nsARefreshObserver
98 virtual void WillRefresh(mozilla::TimeStamp aTime) MOZ_OVERRIDE;
100 void FlushAnimations(FlushFlags aFlags);
103 * Return the style rule that RulesMatching should add for
104 * aStyleContext. This might be different from what RulesMatching
105 * actually added during aStyleContext's construction because the
106 * element's animation-name may have changed. (However, this does
107 * return null during the non-animation restyling phase, as
108 * RulesMatching does.)
110 * aStyleContext may be a style context for aElement or for its
111 * :before or :after pseudo-element.
113 nsIStyleRule* CheckAnimationRule(nsStyleContext* aStyleContext,
114 mozilla::dom::Element* aElement);
117 * Dispatch any pending events. We accumulate animationend and
118 * animationiteration events only during refresh driver notifications
119 * (and dispatch them at the end of such notifications), but we
120 * accumulate animationstart events at other points when style
121 * contexts are created.
123 void DispatchEvents() {
124 // Fast-path the common case: no events
125 if (!mPendingEvents.IsEmpty()) {
126 DoDispatchEvents();
130 mozilla::AnimationPlayerCollection*
131 GetAnimationPlayers(mozilla::dom::Element *aElement,
132 nsCSSPseudoElements::Type aPseudoType,
133 bool aCreateIfNeeded);
135 protected:
136 virtual void ElementCollectionRemoved() MOZ_OVERRIDE
138 CheckNeedsRefresh();
140 virtual void
141 AddElementCollection(mozilla::AnimationPlayerCollection* aData) MOZ_OVERRIDE;
144 * Check to see if we should stop or start observing the refresh driver
146 void CheckNeedsRefresh();
148 private:
149 void BuildAnimations(nsStyleContext* aStyleContext,
150 mozilla::dom::AnimationTimeline* aTimeline,
151 mozilla::AnimationPlayerPtrArray& aAnimations);
152 bool BuildSegment(InfallibleTArray<mozilla::AnimationPropertySegment>&
153 aSegments,
154 nsCSSProperty aProperty,
155 const mozilla::StyleAnimation& aAnimation,
156 float aFromKey, nsStyleContext* aFromContext,
157 mozilla::css::Declaration* aFromDeclaration,
158 float aToKey, nsStyleContext* aToContext);
159 nsIStyleRule* GetAnimationRule(mozilla::dom::Element* aElement,
160 nsCSSPseudoElements::Type aPseudoType);
162 // The guts of DispatchEvents
163 void DoDispatchEvents();
165 EventArray mPendingEvents;
167 bool mObservingRefreshDriver;
170 #endif /* !defined(nsAnimationManager_h_) */