Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Side by Side Diff: sky/engine/core/animation/css/CSSAnimations.h

Issue 1229273004: Remove Animations and Transitions. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef SKY_ENGINE_CORE_ANIMATION_CSS_CSSANIMATIONS_H_
32 #define SKY_ENGINE_CORE_ANIMATION_CSS_CSSANIMATIONS_H_
33
34 #include "sky/engine/core/animation/Animation.h"
35 #include "sky/engine/core/animation/AnimationPlayer.h"
36 #include "sky/engine/core/animation/InertAnimation.h"
37 #include "sky/engine/core/animation/Interpolation.h"
38 #include "sky/engine/core/css/StylePropertySet.h"
39 #include "sky/engine/core/dom/Document.h"
40 #include "sky/engine/core/rendering/style/RenderStyleConstants.h"
41 #include "sky/engine/wtf/HashMap.h"
42 #include "sky/engine/wtf/Vector.h"
43 #include "sky/engine/wtf/text/AtomicString.h"
44
45 namespace blink {
46
47 class CSSTransitionData;
48 class Element;
49 class StylePropertyShorthand;
50
51 // This class stores the CSS Animations/Transitions information we use during a style recalc.
52 // This includes updates to animations/transitions as well as the Interpolations to be applied.
53 class CSSAnimationUpdate final {
54 public:
55 void startAnimation(AtomicString& animationName, PassRefPtr<InertAnimation> animation)
56 {
57 NewAnimation newAnimation;
58 newAnimation.name = animationName;
59 newAnimation.animation = animation;
60 m_newAnimations.append(newAnimation);
61 }
62 // Returns whether player has been cancelled and should be filtered during s tyle application.
63 bool isCancelledAnimation(const AnimationPlayer* player) const { return m_ca ncelledAnimationPlayers.contains(player); }
64 void cancelAnimation(const AtomicString& name, AnimationPlayer& player)
65 {
66 m_cancelledAnimationNames.append(name);
67 m_cancelledAnimationPlayers.add(&player);
68 }
69 void toggleAnimationPaused(const AtomicString& name)
70 {
71 m_animationsWithPauseToggled.append(name);
72 }
73
74 void startTransition(CSSPropertyID id, CSSPropertyID eventId, const Animatab leValue* from, const AnimatableValue* to, PassRefPtr<InertAnimation> animation)
75 {
76 NewTransition newTransition;
77 newTransition.id = id;
78 newTransition.eventId = eventId;
79 newTransition.from = from;
80 newTransition.to = to;
81 newTransition.animation = animation;
82 m_newTransitions.set(id, newTransition);
83 }
84 bool isCancelledTransition(CSSPropertyID id) const { return m_cancelledTrans itions.contains(id); }
85 void cancelTransition(CSSPropertyID id) { m_cancelledTransitions.add(id); }
86
87 struct NewAnimation {
88 ALLOW_ONLY_INLINE_ALLOCATION();
89 public:
90 AtomicString name;
91 RefPtr<InertAnimation> animation;
92 };
93 const Vector<NewAnimation>& newAnimations() const { return m_newAnimations; }
94 const Vector<AtomicString>& cancelledAnimationNames() const { return m_cance lledAnimationNames; }
95 const HashSet<RawPtr<const AnimationPlayer> >& cancelledAnimationAnimationPl ayers() const { return m_cancelledAnimationPlayers; }
96 const Vector<AtomicString>& animationsWithPauseToggled() const { return m_an imationsWithPauseToggled; }
97
98 struct NewTransition {
99 ALLOW_ONLY_INLINE_ALLOCATION();
100 public:
101 CSSPropertyID id;
102 CSSPropertyID eventId;
103 RawPtr<const AnimatableValue> from;
104 RawPtr<const AnimatableValue> to;
105 RefPtr<InertAnimation> animation;
106 };
107 typedef HashMap<CSSPropertyID, NewTransition> NewTransitionMap;
108 const NewTransitionMap& newTransitions() const { return m_newTransitions; }
109 const HashSet<CSSPropertyID>& cancelledTransitions() const { return m_cancel ledTransitions; }
110
111 void adoptActiveInterpolationsForAnimations(HashMap<CSSPropertyID, RefPtr<In terpolation> >& newMap) { newMap.swap(m_activeInterpolationsForAnimations); }
112 void adoptActiveInterpolationsForTransitions(HashMap<CSSPropertyID, RefPtr<I nterpolation> >& newMap) { newMap.swap(m_activeInterpolationsForTransitions); }
113 const HashMap<CSSPropertyID, RefPtr<Interpolation> >& activeInterpolationsFo rAnimations() const { return m_activeInterpolationsForAnimations; }
114 const HashMap<CSSPropertyID, RefPtr<Interpolation> >& activeInterpolationsFo rTransitions() const { return m_activeInterpolationsForTransitions; }
115 HashMap<CSSPropertyID, RefPtr<Interpolation> >& activeInterpolationsForAnima tions() { return m_activeInterpolationsForAnimations; }
116
117 bool isEmpty() const
118 {
119 return m_newAnimations.isEmpty()
120 && m_cancelledAnimationNames.isEmpty()
121 && m_cancelledAnimationPlayers.isEmpty()
122 && m_animationsWithPauseToggled.isEmpty()
123 && m_newTransitions.isEmpty()
124 && m_cancelledTransitions.isEmpty()
125 && m_activeInterpolationsForAnimations.isEmpty()
126 && m_activeInterpolationsForTransitions.isEmpty();
127 }
128
129 private:
130 // Order is significant since it defines the order in which new animations
131 // will be started. Note that there may be multiple animations present
132 // with the same name, due to the way in which we split up animations with
133 // incomplete keyframes.
134 Vector<NewAnimation> m_newAnimations;
135 Vector<AtomicString> m_cancelledAnimationNames;
136 HashSet<RawPtr<const AnimationPlayer> > m_cancelledAnimationPlayers;
137 Vector<AtomicString> m_animationsWithPauseToggled;
138
139 NewTransitionMap m_newTransitions;
140 HashSet<CSSPropertyID> m_cancelledTransitions;
141
142 HashMap<CSSPropertyID, RefPtr<Interpolation> > m_activeInterpolationsForAnim ations;
143 HashMap<CSSPropertyID, RefPtr<Interpolation> > m_activeInterpolationsForTran sitions;
144 };
145
146 class CSSAnimations final {
147 WTF_MAKE_NONCOPYABLE(CSSAnimations);
148 DISALLOW_ALLOCATION();
149 public:
150 CSSAnimations();
151
152 static const StylePropertyShorthand& animatableProperties();
153 static bool isAllowedAnimation(CSSPropertyID);
154 // FIXME: We should change the Element* to a const Element*
155 static PassOwnPtr<CSSAnimationUpdate> calculateUpdate(Element*, const Elemen t& parentElement, const RenderStyle&, RenderStyle* parentStyle);
156
157 void setPendingUpdate(PassOwnPtr<CSSAnimationUpdate> update) { m_pendingUpda te = update; }
158 void maybeApplyPendingUpdate(Element*);
159 bool isEmpty() const { return m_animations.isEmpty() && m_transitions.isEmpt y() && !m_pendingUpdate; }
160 void cancel();
161
162 private:
163 struct RunningTransition {
164 ALLOW_ONLY_INLINE_ALLOCATION();
165 public:
166 RefPtr<AnimationPlayer> player;
167 RawPtr<const AnimatableValue> from;
168 RawPtr<const AnimatableValue> to;
169 };
170
171 typedef HashMap<AtomicString, RefPtr<AnimationPlayer> > AnimationMap;
172 AnimationMap m_animations;
173
174 typedef HashMap<CSSPropertyID, RunningTransition> TransitionMap;
175 TransitionMap m_transitions;
176
177 OwnPtr<CSSAnimationUpdate> m_pendingUpdate;
178
179 HashMap<CSSPropertyID, RefPtr<Interpolation> > m_previousActiveInterpolation sForAnimations;
180
181 static void calculateTransitionUpdate(CSSAnimationUpdate*, const Element*, c onst RenderStyle&);
182 static void calculateTransitionUpdateForProperty(CSSPropertyID, CSSPropertyI D eventId, const CSSTransitionData&, size_t transitionIndex, const RenderStyle& oldStyle, const RenderStyle&, const TransitionMap* activeTransitions, CSSAnimati onUpdate*, const Element*);
183
184 static void calculateAnimationActiveInterpolations(CSSAnimationUpdate*, cons t Element*, double timelineCurrentTime);
185 static void calculateTransitionActiveInterpolations(CSSAnimationUpdate*, con st Element*, double timelineCurrentTime);
186
187 class AnimationEventDelegate final : public AnimationNode::EventDelegate {
188 public:
189 AnimationEventDelegate(Element* target, const AtomicString& name)
190 : m_target(target)
191 , m_name(name)
192 , m_previousPhase(AnimationNode::PhaseNone)
193 , m_previousIteration(nullValue())
194 {
195 }
196 virtual void onEventCondition(const AnimationNode*) override;
197
198 private:
199 void maybeDispatch(Document::ListenerType, const AtomicString& eventName , double elapsedTime);
200 RawPtr<Element> m_target;
201 const AtomicString m_name;
202 AnimationNode::Phase m_previousPhase;
203 double m_previousIteration;
204 };
205
206 class TransitionEventDelegate final : public AnimationNode::EventDelegate {
207 public:
208 TransitionEventDelegate(Element* target, CSSPropertyID property)
209 : m_target(target)
210 , m_property(property)
211 , m_previousPhase(AnimationNode::PhaseNone)
212 {
213 }
214 virtual void onEventCondition(const AnimationNode*) override;
215
216 private:
217 RawPtr<Element> m_target;
218 const CSSPropertyID m_property;
219 AnimationNode::Phase m_previousPhase;
220 };
221 };
222
223 } // namespace blink
224
225 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::CSSAnimationUpdate::NewAnimation);
226
227 #endif // SKY_ENGINE_CORE_ANIMATION_CSS_CSSANIMATIONS_H_
OLDNEW
« no previous file with comments | « sky/engine/core/animation/css/CSSAnimationData.cpp ('k') | sky/engine/core/animation/css/CSSAnimations.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698