Bumping manifests a=b2g-bump
[gecko.git] / layout / style / nsTransitionManager.h
blobe2450fafafb7a54253de0411af98ddaa1f693418
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/. */
6 /* Code to start and animate CSS transitions. */
8 #ifndef nsTransitionManager_h_
9 #define nsTransitionManager_h_
11 #include "mozilla/Attributes.h"
12 #include "mozilla/MemoryReporting.h"
13 #include "mozilla/dom/Animation.h"
14 #include "mozilla/dom/AnimationPlayer.h"
15 #include "AnimationCommon.h"
16 #include "nsCSSPseudoElements.h"
18 class nsStyleContext;
19 class nsPresContext;
20 class nsCSSPropertySet;
21 struct ElementDependentRuleProcessorData;
23 namespace mozilla {
24 struct StyleTransition;
27 /*****************************************************************************
28 * Per-Element data *
29 *****************************************************************************/
31 namespace mozilla {
33 struct ElementPropertyTransition : public dom::Animation
35 ElementPropertyTransition(nsIDocument* aDocument,
36 dom::Element* aTarget,
37 nsCSSPseudoElements::Type aPseudoType,
38 const AnimationTiming &aTiming)
39 : dom::Animation(aDocument, aTarget, aPseudoType, aTiming, EmptyString())
40 { }
42 virtual ElementPropertyTransition* AsTransition() { return this; }
43 virtual const ElementPropertyTransition* AsTransition() const { return this; }
45 // This is the start value to be used for a check for whether a
46 // transition is being reversed. Normally the same as
47 // mProperties[0].mSegments[0].mFromValue, except when this transition
48 // started as the reversal of another in-progress transition.
49 // Needed so we can handle two reverses in a row.
50 mozilla::StyleAnimationValue mStartForReversingTest;
51 // Likewise, the portion (in value space) of the "full" reversed
52 // transition that we're actually covering. For example, if a :hover
53 // effect has a transition that moves the element 10px to the right
54 // (by changing 'left' from 0px to 10px), and the mouse moves in to
55 // the element (starting the transition) but then moves out after the
56 // transition has advanced 4px, the second transition (from 10px/4px
57 // to 0px) will have mReversePortion of 0.4. (If the mouse then moves
58 // in again when the transition is back to 2px, the mReversePortion
59 // for the third transition (from 0px/2px to 10px) will be 0.8.
60 double mReversePortion;
62 // Compute the portion of the *value* space that we should be through
63 // at the current time. (The input to the transition timing function
64 // has time units, the output has value units.)
65 double CurrentValuePortion() const;
68 class CSSTransitionPlayer MOZ_FINAL : public dom::AnimationPlayer
70 public:
71 explicit CSSTransitionPlayer(dom::AnimationTimeline* aTimeline)
72 : dom::AnimationPlayer(aTimeline)
76 virtual CSSTransitionPlayer*
77 AsCSSTransitionPlayer() MOZ_OVERRIDE { return this; }
79 virtual dom::AnimationPlayState PlayStateFromJS() const MOZ_OVERRIDE;
80 virtual void PlayFromJS() MOZ_OVERRIDE;
82 // A variant of Play() that avoids posting style updates since this method
83 // is expected to be called whilst already updating style.
84 void PlayFromStyle() { DoPlay(); }
86 protected:
87 virtual ~CSSTransitionPlayer() { }
89 virtual css::CommonAnimationManager* GetAnimationManager() const MOZ_OVERRIDE;
92 } // namespace mozilla
94 class nsTransitionManager MOZ_FINAL
95 : public mozilla::css::CommonAnimationManager
97 public:
98 explicit nsTransitionManager(nsPresContext *aPresContext)
99 : mozilla::css::CommonAnimationManager(aPresContext)
100 , mInAnimationOnlyStyleUpdate(false)
104 typedef mozilla::AnimationPlayerCollection AnimationPlayerCollection;
106 static AnimationPlayerCollection*
107 GetAnimationsForCompositor(nsIContent* aContent, nsCSSProperty aProperty)
109 return mozilla::css::CommonAnimationManager::GetAnimationsForCompositor(
110 aContent, nsGkAtoms::transitionsProperty, aProperty);
114 * StyleContextChanged
116 * To be called from nsFrameManager::ReResolveStyleContext when the
117 * style of an element has changed, to initiate transitions from
118 * that style change. For style contexts with :before and :after
119 * pseudos, aElement is expected to be the generated before/after
120 * element.
122 * It may return a "cover rule" (see CoverTransitionStartStyleRule) to
123 * cover up some of the changes for the duration of the restyling of
124 * descendants. If it does, this function will take care of causing
125 * the necessary restyle afterwards, but the caller must restyle the
126 * element *again* with the original sequence of rules plus the
127 * returned cover rule as the most specific rule.
129 already_AddRefed<nsIStyleRule>
130 StyleContextChanged(mozilla::dom::Element *aElement,
131 nsStyleContext *aOldStyleContext,
132 nsStyleContext *aNewStyleContext);
134 void SetInAnimationOnlyStyleUpdate(bool aInAnimationOnlyUpdate) {
135 mInAnimationOnlyStyleUpdate = aInAnimationOnlyUpdate;
138 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
139 MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
140 virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
141 MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
143 // nsARefreshObserver
144 virtual void WillRefresh(mozilla::TimeStamp aTime) MOZ_OVERRIDE;
146 void FlushTransitions(FlushFlags aFlags);
148 protected:
149 virtual nsIAtom* GetAnimationsAtom() MOZ_OVERRIDE {
150 return nsGkAtoms::transitionsProperty;
152 virtual nsIAtom* GetAnimationsBeforeAtom() MOZ_OVERRIDE {
153 return nsGkAtoms::transitionsOfBeforeProperty;
155 virtual nsIAtom* GetAnimationsAfterAtom() MOZ_OVERRIDE {
156 return nsGkAtoms::transitionsOfAfterProperty;
159 private:
160 void
161 ConsiderStartingTransition(nsCSSProperty aProperty,
162 const mozilla::StyleTransition& aTransition,
163 mozilla::dom::Element* aElement,
164 AnimationPlayerCollection*& aElementTransitions,
165 nsStyleContext* aOldStyleContext,
166 nsStyleContext* aNewStyleContext,
167 bool* aStartedAny,
168 nsCSSPropertySet* aWhichStarted);
170 bool mInAnimationOnlyStyleUpdate;
173 #endif /* !defined(nsTransitionManager_h_) */