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

Side by Side Diff: Source/core/animation/css/CSSAnimations.h

Issue 214603002: CSS Animations: Generate a single player for each keyframe animation. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/core/animation/css/CSSAnimations.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 class Element; 48 class Element;
49 class StylePropertyShorthand; 49 class StylePropertyShorthand;
50 class StyleResolver; 50 class StyleResolver;
51 class StyleRuleKeyframes; 51 class StyleRuleKeyframes;
52 52
53 // This class stores the CSS Animations/Transitions information we use during a style recalc. 53 // This class stores the CSS Animations/Transitions information we use during a style recalc.
54 // This includes updates to animations/transitions as well as the Interpolations to be applied. 54 // This includes updates to animations/transitions as well as the Interpolations to be applied.
55 class CSSAnimationUpdate FINAL : public NoBaseWillBeGarbageCollectedFinalized<CS SAnimationUpdate> { 55 class CSSAnimationUpdate FINAL : public NoBaseWillBeGarbageCollectedFinalized<CS SAnimationUpdate> {
56 public: 56 public:
57 void startAnimation(AtomicString& animationName, const HashSet<RefPtr<InertA nimation> >& animations) 57 void startAnimation(AtomicString& animationName, PassRefPtr<InertAnimation> animation)
58 { 58 {
59 NewAnimation newAnimation; 59 NewAnimation newAnimation;
60 newAnimation.name = animationName; 60 newAnimation.name = animationName;
61 newAnimation.animations = animations; 61 newAnimation.animation = animation;
62 m_newAnimations.append(newAnimation); 62 m_newAnimations.append(newAnimation);
63 } 63 }
64 // Returns whether player has been cancelled and should be filtered during s tyle application. 64 // Returns whether player has been cancelled and should be filtered during s tyle application.
65 bool isCancelledAnimation(const AnimationPlayer* player) const { return m_ca ncelledAnimationAnimationPlayers.contains(player); } 65 bool isCancelledAnimation(const AnimationPlayer* player) const { return m_ca ncelledAnimationPlayers.contains(player); }
66 void cancelAnimation(const AtomicString& name, const HashSet<RefPtr<Animatio nPlayer> >& players) 66 void cancelAnimation(const AtomicString& name, AnimationPlayer& player)
67 { 67 {
68 m_cancelledAnimationNames.append(name); 68 m_cancelledAnimationNames.append(name);
69 for (HashSet<RefPtr<AnimationPlayer> >::const_iterator iter = players.be gin(); iter != players.end(); ++iter) 69 m_cancelledAnimationPlayers.add(&player);
70 m_cancelledAnimationAnimationPlayers.add(iter->get());
71 } 70 }
72 void toggleAnimationPaused(const AtomicString& name) 71 void toggleAnimationPaused(const AtomicString& name)
73 { 72 {
74 m_animationsWithPauseToggled.append(name); 73 m_animationsWithPauseToggled.append(name);
75 } 74 }
76 75
77 void startTransition(CSSPropertyID id, const AnimatableValue* from, const An imatableValue* to, PassRefPtr<InertAnimation> animation) 76 void startTransition(CSSPropertyID id, const AnimatableValue* from, const An imatableValue* to, PassRefPtr<InertAnimation> animation)
78 { 77 {
79 NewTransition newTransition; 78 NewTransition newTransition;
80 newTransition.id = id; 79 newTransition.id = id;
81 newTransition.from = from; 80 newTransition.from = from;
82 newTransition.to = to; 81 newTransition.to = to;
83 newTransition.animation = animation; 82 newTransition.animation = animation;
84 m_newTransitions.set(id, newTransition); 83 m_newTransitions.set(id, newTransition);
85 } 84 }
86 bool isCancelledTransition(CSSPropertyID id) const { return m_cancelledTrans itions.contains(id); } 85 bool isCancelledTransition(CSSPropertyID id) const { return m_cancelledTrans itions.contains(id); }
87 void cancelTransition(CSSPropertyID id) { m_cancelledTransitions.add(id); } 86 void cancelTransition(CSSPropertyID id) { m_cancelledTransitions.add(id); }
88 87
89 struct NewAnimation { 88 struct NewAnimation {
90 AtomicString name; 89 AtomicString name;
91 HashSet<RefPtr<InertAnimation> > animations; 90 RefPtr<InertAnimation> animation;
92 }; 91 };
93 const Vector<NewAnimation>& newAnimations() const { return m_newAnimations; } 92 const Vector<NewAnimation>& newAnimations() const { return m_newAnimations; }
94 const Vector<AtomicString>& cancelledAnimationNames() const { return m_cance lledAnimationNames; } 93 const Vector<AtomicString>& cancelledAnimationNames() const { return m_cance lledAnimationNames; }
95 const HashSet<const AnimationPlayer*>& cancelledAnimationAnimationPlayers() const { return m_cancelledAnimationAnimationPlayers; } 94 const HashSet<const AnimationPlayer*>& cancelledAnimationAnimationPlayers() const { return m_cancelledAnimationPlayers; }
96 const Vector<AtomicString>& animationsWithPauseToggled() const { return m_an imationsWithPauseToggled; } 95 const Vector<AtomicString>& animationsWithPauseToggled() const { return m_an imationsWithPauseToggled; }
97 96
98 struct NewTransition { 97 struct NewTransition {
99 ALLOW_ONLY_INLINE_ALLOCATION(); 98 ALLOW_ONLY_INLINE_ALLOCATION();
100 public: 99 public:
101 void trace(Visitor* visitor) 100 void trace(Visitor* visitor)
102 { 101 {
103 visitor->trace(from); 102 visitor->trace(from);
104 visitor->trace(to); 103 visitor->trace(to);
105 } 104 }
(...skipping 10 matching lines...) Expand all
116 void adoptActiveInterpolationsForAnimations(WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> >& newMap) { newMap.swap(m_activeInterpolatio nsForAnimations); } 115 void adoptActiveInterpolationsForAnimations(WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> >& newMap) { newMap.swap(m_activeInterpolatio nsForAnimations); }
117 void adoptActiveInterpolationsForTransitions(WillBeHeapHashMap<CSSPropertyID , RefPtrWillBeMember<Interpolation> >& newMap) { newMap.swap(m_activeInterpolati onsForTransitions); } 116 void adoptActiveInterpolationsForTransitions(WillBeHeapHashMap<CSSPropertyID , RefPtrWillBeMember<Interpolation> >& newMap) { newMap.swap(m_activeInterpolati onsForTransitions); }
118 const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> >& activeInterpolationsForAnimations() const { return m_activeInterpolationsForAnim ations; } 117 const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> >& activeInterpolationsForAnimations() const { return m_activeInterpolationsForAnim ations; }
119 const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> >& activeInterpolationsForTransitions() const { return m_activeInterpolationsForTra nsitions; } 118 const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> >& activeInterpolationsForTransitions() const { return m_activeInterpolationsForTra nsitions; }
120 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> >& active InterpolationsForAnimations() { return m_activeInterpolationsForAnimations; } 119 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> >& active InterpolationsForAnimations() { return m_activeInterpolationsForAnimations; }
121 120
122 bool isEmpty() const 121 bool isEmpty() const
123 { 122 {
124 return m_newAnimations.isEmpty() 123 return m_newAnimations.isEmpty()
125 && m_cancelledAnimationNames.isEmpty() 124 && m_cancelledAnimationNames.isEmpty()
126 && m_cancelledAnimationAnimationPlayers.isEmpty() 125 && m_cancelledAnimationPlayers.isEmpty()
127 && m_animationsWithPauseToggled.isEmpty() 126 && m_animationsWithPauseToggled.isEmpty()
128 && m_newTransitions.isEmpty() 127 && m_newTransitions.isEmpty()
129 && m_cancelledTransitions.isEmpty() 128 && m_cancelledTransitions.isEmpty()
130 && m_activeInterpolationsForAnimations.isEmpty() 129 && m_activeInterpolationsForAnimations.isEmpty()
131 && m_activeInterpolationsForTransitions.isEmpty(); 130 && m_activeInterpolationsForTransitions.isEmpty();
132 } 131 }
133 132
134 void trace(Visitor*); 133 void trace(Visitor*);
135 134
136 private: 135 private:
137 // Order is significant since it defines the order in which new animations 136 // Order is significant since it defines the order in which new animations
138 // will be started. Note that there may be multiple animations present 137 // will be started. Note that there may be multiple animations present
139 // with the same name, due to the way in which we split up animations with 138 // with the same name, due to the way in which we split up animations with
140 // incomplete keyframes. 139 // incomplete keyframes.
141 Vector<NewAnimation> m_newAnimations; 140 Vector<NewAnimation> m_newAnimations;
142 Vector<AtomicString> m_cancelledAnimationNames; 141 Vector<AtomicString> m_cancelledAnimationNames;
143 HashSet<const AnimationPlayer*> m_cancelledAnimationAnimationPlayers; 142 HashSet<const AnimationPlayer*> m_cancelledAnimationPlayers;
144 Vector<AtomicString> m_animationsWithPauseToggled; 143 Vector<AtomicString> m_animationsWithPauseToggled;
145 144
146 NewTransitionMap m_newTransitions; 145 NewTransitionMap m_newTransitions;
147 HashSet<CSSPropertyID> m_cancelledTransitions; 146 HashSet<CSSPropertyID> m_cancelledTransitions;
148 147
149 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> > m_activ eInterpolationsForAnimations; 148 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> > m_activ eInterpolationsForAnimations;
150 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> > m_activ eInterpolationsForTransitions; 149 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> > m_activ eInterpolationsForTransitions;
151 }; 150 };
152 151
153 class CSSAnimations FINAL : public NoBaseWillBeGarbageCollectedFinalized<CSSAnim ations> { 152 class CSSAnimations FINAL : public NoBaseWillBeGarbageCollectedFinalized<CSSAnim ations> {
(...skipping 10 matching lines...) Expand all
164 static PassOwnPtrWillBeRawPtr<CSSAnimationUpdate> calculateUpdate(Element*, const Element& parentElement, const RenderStyle&, RenderStyle* parentStyle, Styl eResolver*); 163 static PassOwnPtrWillBeRawPtr<CSSAnimationUpdate> calculateUpdate(Element*, const Element& parentElement, const RenderStyle&, RenderStyle* parentStyle, Styl eResolver*);
165 164
166 void setPendingUpdate(PassOwnPtrWillBeRawPtr<CSSAnimationUpdate> update) { m _pendingUpdate = update; } 165 void setPendingUpdate(PassOwnPtrWillBeRawPtr<CSSAnimationUpdate> update) { m _pendingUpdate = update; }
167 void maybeApplyPendingUpdate(Element*); 166 void maybeApplyPendingUpdate(Element*);
168 bool isEmpty() const { return m_animations.isEmpty() && m_transitions.isEmpt y() && !m_pendingUpdate; } 167 bool isEmpty() const { return m_animations.isEmpty() && m_transitions.isEmpt y() && !m_pendingUpdate; }
169 void cancel(); 168 void cancel();
170 169
171 void trace(Visitor*); 170 void trace(Visitor*);
172 171
173 private: 172 private:
174 // Note that a single animation name may map to multiple players due to
175 // the way in which we split up animations with incomplete keyframes.
176 // FIXME: Once the Web Animations model supports groups, we could use a
177 // ParGroup to drive multiple animations from a single AnimationPlayer.
178 typedef HashMap<AtomicString, HashSet<RefPtr<AnimationPlayer> > > AnimationM ap;
179 struct RunningTransition { 173 struct RunningTransition {
180 ALLOW_ONLY_INLINE_ALLOCATION(); 174 ALLOW_ONLY_INLINE_ALLOCATION();
181 public: 175 public:
182 void trace(Visitor* visitor) 176 void trace(Visitor* visitor)
183 { 177 {
184 visitor->trace(from); 178 visitor->trace(from);
185 visitor->trace(to); 179 visitor->trace(to);
186 } 180 }
187 181
188 Animation* transition; // The TransitionTimeline keeps the AnimationPlay ers alive 182 Animation* transition; // The TransitionTimeline keeps the AnimationPlay ers alive
189 RawPtrWillBeMember<const AnimatableValue> from; 183 RawPtrWillBeMember<const AnimatableValue> from;
190 RawPtrWillBeMember<const AnimatableValue> to; 184 RawPtrWillBeMember<const AnimatableValue> to;
191 }; 185 };
186
187 typedef HashMap<AtomicString, RefPtr<AnimationPlayer> > AnimationMap;
188 AnimationMap m_animations;
189
192 typedef WillBeHeapHashMap<CSSPropertyID, RunningTransition> TransitionMap; 190 typedef WillBeHeapHashMap<CSSPropertyID, RunningTransition> TransitionMap;
193 AnimationMap m_animations;
194 TransitionMap m_transitions; 191 TransitionMap m_transitions;
192
195 OwnPtrWillBeMember<CSSAnimationUpdate> m_pendingUpdate; 193 OwnPtrWillBeMember<CSSAnimationUpdate> m_pendingUpdate;
196 194
197 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> > m_previ ousActiveInterpolationsForAnimations; 195 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> > m_previ ousActiveInterpolationsForAnimations;
198 196
199 static void calculateAnimationUpdate(CSSAnimationUpdate*, Element*, const El ement& parentElement, const RenderStyle&, RenderStyle* parentStyle, StyleResolve r*); 197 static void calculateAnimationUpdate(CSSAnimationUpdate*, Element*, const El ement& parentElement, const RenderStyle&, RenderStyle* parentStyle, StyleResolve r*);
200 static void calculateTransitionUpdate(CSSAnimationUpdate*, const Element*, c onst RenderStyle&); 198 static void calculateTransitionUpdate(CSSAnimationUpdate*, const Element*, c onst RenderStyle&);
201 static void calculateTransitionUpdateForProperty(CSSPropertyID, const CSSAni mationData*, const RenderStyle& oldStyle, const RenderStyle&, const TransitionMa p* activeTransitions, CSSAnimationUpdate*, const Element*); 199 static void calculateTransitionUpdateForProperty(CSSPropertyID, const CSSAni mationData*, const RenderStyle& oldStyle, const RenderStyle&, const TransitionMa p* activeTransitions, CSSAnimationUpdate*, const Element*);
202 200
203 static void calculateAnimationActiveInterpolations(CSSAnimationUpdate*, cons t Element*); 201 static void calculateAnimationActiveInterpolations(CSSAnimationUpdate*, cons t Element*);
204 static void calculateTransitionActiveInterpolations(CSSAnimationUpdate*, con st Element*); 202 static void calculateTransitionActiveInterpolations(CSSAnimationUpdate*, con st Element*);
(...skipping 22 matching lines...) Expand all
227 virtual void onEventCondition(const TimedItem*, bool isFirstSample, Time dItem::Phase previousPhase, double previousIteration) OVERRIDE; 225 virtual void onEventCondition(const TimedItem*, bool isFirstSample, Time dItem::Phase previousPhase, double previousIteration) OVERRIDE;
228 private: 226 private:
229 Element* m_target; 227 Element* m_target;
230 const CSSPropertyID m_property; 228 const CSSPropertyID m_property;
231 }; 229 };
232 }; 230 };
233 231
234 } // namespace WebCore 232 } // namespace WebCore
235 233
236 #endif 234 #endif
OLDNEW
« no previous file with comments | « no previous file | Source/core/animation/css/CSSAnimations.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698