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

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

Issue 814083003: Update animation when changes in animation keyframes are detected. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase + Address comments Created 5 years, 10 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
« no previous file with comments | « Source/core/animation/Timing.h ('k') | Source/core/animation/css/CSSAnimations.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CSSAnimationUpdate_h 5 #ifndef CSSAnimationUpdate_h
6 #define CSSAnimationUpdate_h 6 #define CSSAnimationUpdate_h
7 7
8 #include "core/animation/Interpolation.h" 8 #include "core/animation/Interpolation.h"
9 #include "core/css/CSSKeyframesRule.h"
9 #include "wtf/HashMap.h" 10 #include "wtf/HashMap.h"
10 #include "wtf/Vector.h" 11 #include "wtf/Vector.h"
11 #include "wtf/text/AtomicString.h" 12 #include "wtf/text/AtomicString.h"
12 13
13 namespace blink { 14 namespace blink {
14 15
15 class AnimationPlayer; 16 class AnimationPlayer;
16 class InertAnimation; 17 class InertAnimation;
17 18
18 // This class stores the CSS Animations/Transitions information we use during a style recalc. 19 // This class stores the CSS Animations/Transitions information we use during a style recalc.
19 // This includes updates to animations/transitions as well as the Interpolations to be applied. 20 // This includes updates to animations/transitions as well as the Interpolations to be applied.
20 class CSSAnimationUpdate final : public NoBaseWillBeGarbageCollectedFinalized<CS SAnimationUpdate> { 21 class CSSAnimationUpdate final : public NoBaseWillBeGarbageCollectedFinalized<CS SAnimationUpdate> {
21 public: 22 public:
22 void startAnimation(const AtomicString& animationName, PassRefPtrWillBeRawPt r<InertAnimation> animation) 23 class NewAnimation {
24 ALLOW_ONLY_INLINE_ALLOCATION();
25 public:
26 NewAnimation()
27 : styleRuleVersion(0)
28 {
29 }
30
31 NewAnimation(AtomicString name, PassRefPtrWillBeRawPtr<InertAnimation> a nimation, Timing timing, PassRefPtrWillBeRawPtr<StyleRuleKeyframes> styleRule)
32 : name(name)
33 , animation(animation)
34 , timing(timing)
35 , styleRule(styleRule)
36 , styleRuleVersion(this->styleRule->version())
37 {
38 }
39
40 void trace(Visitor* visitor)
41 {
42 visitor->trace(animation);
43 }
44
45 AtomicString name;
46 RefPtrWillBeMember<InertAnimation> animation;
47 Timing timing;
48 RefPtrWillBeMember<StyleRuleKeyframes> styleRule;
49 unsigned styleRuleVersion;
50 };
51
52 class UpdatedAnimation {
53 ALLOW_ONLY_INLINE_ALLOCATION();
54 public:
55 UpdatedAnimation()
56 : styleRuleVersion(0)
57 {
58 }
59
60 UpdatedAnimation(AtomicString name, AnimationPlayer* player, PassRefPtrW illBeRawPtr<InertAnimation> animation, Timing specifiedTiming, PassRefPtrWillBeR awPtr<StyleRuleKeyframes> styleRule)
61 : name(name)
62 , player(player)
63 , animation(animation)
64 , specifiedTiming(specifiedTiming)
65 , styleRule(styleRule)
66 , styleRuleVersion(this->styleRule->version())
67 {
68 }
69
70 void trace(Visitor* visitor)
71 {
72 visitor->trace(player);
73 visitor->trace(animation);
74 visitor->trace(styleRule);
75 }
76
77 AtomicString name;
78 RawPtrWillBeMember<AnimationPlayer> player;
79 RefPtrWillBeMember<InertAnimation> animation;
80 Timing specifiedTiming;
81 RefPtrWillBeMember<StyleRuleKeyframes> styleRule;
82 unsigned styleRuleVersion;
83 };
84
85 void startAnimation(const AtomicString& animationName, PassRefPtrWillBeRawPt r<InertAnimation> animation, const Timing& timing, PassRefPtrWillBeRawPtr<StyleR uleKeyframes> styleRule)
23 { 86 {
24 animation->setName(animationName); 87 animation->setName(animationName);
25 NewAnimation newAnimation; 88 m_newAnimations.append(NewAnimation(animationName, animation, timing, st yleRule));
26 newAnimation.name = animationName;
27 newAnimation.animation = animation;
28 m_newAnimations.append(newAnimation);
29 } 89 }
30 // Returns whether player has been suppressed and should be filtered during style application. 90 // Returns whether player has been suppressed and should be filtered during style application.
31 bool isSuppressedAnimation(const AnimationPlayer* player) const { return m_s uppressedAnimationPlayers.contains(player); } 91 bool isSuppressedAnimation(const AnimationPlayer* player) const { return m_s uppressedAnimationPlayers.contains(player); }
32 void cancelAnimation(const AtomicString& name, AnimationPlayer& player) 92 void cancelAnimation(const AtomicString& name, AnimationPlayer& player)
33 { 93 {
34 m_cancelledAnimationNames.append(name); 94 m_cancelledAnimationNames.append(name);
35 m_suppressedAnimationPlayers.add(&player); 95 m_suppressedAnimationPlayers.add(&player);
36 } 96 }
37 void toggleAnimationPaused(const AtomicString& name) 97 void toggleAnimationPaused(const AtomicString& name)
38 { 98 {
39 m_animationsWithPauseToggled.append(name); 99 m_animationsWithPauseToggled.append(name);
40 } 100 }
41 void updateAnimationTiming(AnimationPlayer* player, PassRefPtrWillBeRawPtr<I nertAnimation> animation, const Timing& timing) 101 void updateAnimation(const AtomicString& name, AnimationPlayer* player, Pass RefPtrWillBeRawPtr<InertAnimation> animation, const Timing& specifiedTiming,
102 PassRefPtrWillBeRawPtr<StyleRuleKeyframes> styleRule)
42 { 103 {
43 UpdatedAnimationTiming updatedAnimation; 104 m_animationsWithUpdates.append(UpdatedAnimation(name, player, animation, specifiedTiming, styleRule));
44 updatedAnimation.player = player;
45 updatedAnimation.animation = animation;
46 updatedAnimation.newTiming = timing;
47 m_animationsWithTimingUpdates.append(updatedAnimation);
48 m_suppressedAnimationPlayers.add(player); 105 m_suppressedAnimationPlayers.add(player);
49 } 106 }
50 107
51 void startTransition(CSSPropertyID id, CSSPropertyID eventId, const Animatab leValue* from, const AnimatableValue* to, PassRefPtrWillBeRawPtr<InertAnimation> animation) 108 void startTransition(CSSPropertyID id, CSSPropertyID eventId, const Animatab leValue* from, const AnimatableValue* to, PassRefPtrWillBeRawPtr<InertAnimation> animation)
52 { 109 {
53 animation->setName(getPropertyName(id)); 110 animation->setName(getPropertyName(id));
54 NewTransition newTransition; 111 NewTransition newTransition;
55 newTransition.id = id; 112 newTransition.id = id;
56 newTransition.eventId = eventId; 113 newTransition.eventId = eventId;
57 newTransition.from = from; 114 newTransition.from = from;
58 newTransition.to = to; 115 newTransition.to = to;
59 newTransition.animation = animation; 116 newTransition.animation = animation;
60 m_newTransitions.set(id, newTransition); 117 m_newTransitions.set(id, newTransition);
61 } 118 }
62 bool isCancelledTransition(CSSPropertyID id) const { return m_cancelledTrans itions.contains(id); } 119 bool isCancelledTransition(CSSPropertyID id) const { return m_cancelledTrans itions.contains(id); }
63 void cancelTransition(CSSPropertyID id) { m_cancelledTransitions.add(id); } 120 void cancelTransition(CSSPropertyID id) { m_cancelledTransitions.add(id); }
64 121
65 struct NewAnimation {
66 ALLOW_ONLY_INLINE_ALLOCATION();
67 public:
68 void trace(Visitor* visitor)
69 {
70 visitor->trace(animation);
71 }
72
73 AtomicString name;
74 RefPtrWillBeMember<InertAnimation> animation;
75 };
76
77 struct UpdatedAnimationTiming {
78 ALLOW_ONLY_INLINE_ALLOCATION();
79 public:
80 void trace(Visitor* visitor)
81 {
82 visitor->trace(player);
83 visitor->trace(animation);
84 }
85
86 RawPtrWillBeMember<AnimationPlayer> player;
87 RefPtrWillBeMember<InertAnimation> animation;
88 Timing newTiming;
89 };
90
91 const WillBeHeapVector<NewAnimation>& newAnimations() const { return m_newAn imations; } 122 const WillBeHeapVector<NewAnimation>& newAnimations() const { return m_newAn imations; }
92 const Vector<AtomicString>& cancelledAnimationNames() const { return m_cance lledAnimationNames; } 123 const Vector<AtomicString>& cancelledAnimationNames() const { return m_cance lledAnimationNames; }
93 const WillBeHeapHashSet<RawPtrWillBeMember<const AnimationPlayer>>& suppress edAnimationAnimationPlayers() const { return m_suppressedAnimationPlayers; } 124 const WillBeHeapHashSet<RawPtrWillBeMember<const AnimationPlayer>>& suppress edAnimationAnimationPlayers() const { return m_suppressedAnimationPlayers; }
94 const Vector<AtomicString>& animationsWithPauseToggled() const { return m_an imationsWithPauseToggled; } 125 const Vector<AtomicString>& animationsWithPauseToggled() const { return m_an imationsWithPauseToggled; }
95 const WillBeHeapVector<UpdatedAnimationTiming>& animationsWithTimingUpdates( ) const { return m_animationsWithTimingUpdates; } 126 const WillBeHeapVector<UpdatedAnimation>& animationsWithUpdates() const { re turn m_animationsWithUpdates; }
96 127
97 struct NewTransition { 128 struct NewTransition {
98 ALLOW_ONLY_INLINE_ALLOCATION(); 129 ALLOW_ONLY_INLINE_ALLOCATION();
99 public: 130 public:
100 void trace(Visitor* visitor) 131 void trace(Visitor* visitor)
101 { 132 {
102 visitor->trace(from); 133 visitor->trace(from);
103 visitor->trace(to); 134 visitor->trace(to);
104 visitor->trace(animation); 135 visitor->trace(animation);
105 } 136 }
(...skipping 13 matching lines...) Expand all
119 const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>>& a ctiveInterpolationsForAnimations() const { return m_activeInterpolationsForAnima tions; } 150 const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>>& a ctiveInterpolationsForAnimations() const { return m_activeInterpolationsForAnima tions; }
120 const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>>& a ctiveInterpolationsForTransitions() const { return m_activeInterpolationsForTran sitions; } 151 const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>>& a ctiveInterpolationsForTransitions() const { return m_activeInterpolationsForTran sitions; }
121 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>>& activeI nterpolationsForAnimations() { return m_activeInterpolationsForAnimations; } 152 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>>& activeI nterpolationsForAnimations() { return m_activeInterpolationsForAnimations; }
122 153
123 bool isEmpty() const 154 bool isEmpty() const
124 { 155 {
125 return m_newAnimations.isEmpty() 156 return m_newAnimations.isEmpty()
126 && m_cancelledAnimationNames.isEmpty() 157 && m_cancelledAnimationNames.isEmpty()
127 && m_suppressedAnimationPlayers.isEmpty() 158 && m_suppressedAnimationPlayers.isEmpty()
128 && m_animationsWithPauseToggled.isEmpty() 159 && m_animationsWithPauseToggled.isEmpty()
129 && m_animationsWithTimingUpdates.isEmpty() 160 && m_animationsWithUpdates.isEmpty()
130 && m_newTransitions.isEmpty() 161 && m_newTransitions.isEmpty()
131 && m_cancelledTransitions.isEmpty() 162 && m_cancelledTransitions.isEmpty()
132 && m_activeInterpolationsForAnimations.isEmpty() 163 && m_activeInterpolationsForAnimations.isEmpty()
133 && m_activeInterpolationsForTransitions.isEmpty(); 164 && m_activeInterpolationsForTransitions.isEmpty();
134 } 165 }
135 166
136 void trace(Visitor*); 167 void trace(Visitor*);
137 168
138 private: 169 private:
139 // Order is significant since it defines the order in which new animations 170 // Order is significant since it defines the order in which new animations
140 // will be started. Note that there may be multiple animations present 171 // will be started. Note that there may be multiple animations present
141 // with the same name, due to the way in which we split up animations with 172 // with the same name, due to the way in which we split up animations with
142 // incomplete keyframes. 173 // incomplete keyframes.
143 WillBeHeapVector<NewAnimation> m_newAnimations; 174 WillBeHeapVector<NewAnimation> m_newAnimations;
144 Vector<AtomicString> m_cancelledAnimationNames; 175 Vector<AtomicString> m_cancelledAnimationNames;
145 WillBeHeapHashSet<RawPtrWillBeMember<const AnimationPlayer>> m_suppressedAni mationPlayers; 176 WillBeHeapHashSet<RawPtrWillBeMember<const AnimationPlayer>> m_suppressedAni mationPlayers;
146 Vector<AtomicString> m_animationsWithPauseToggled; 177 Vector<AtomicString> m_animationsWithPauseToggled;
147 WillBeHeapVector<UpdatedAnimationTiming> m_animationsWithTimingUpdates; 178 WillBeHeapVector<UpdatedAnimation> m_animationsWithUpdates;
148 179
149 NewTransitionMap m_newTransitions; 180 NewTransitionMap m_newTransitions;
150 HashSet<CSSPropertyID> m_cancelledTransitions; 181 HashSet<CSSPropertyID> m_cancelledTransitions;
151 182
152 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>> m_active InterpolationsForAnimations; 183 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>> m_active InterpolationsForAnimations;
153 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>> m_active InterpolationsForTransitions; 184 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>> m_active InterpolationsForTransitions;
154 }; 185 };
155 186
156 } // namespace blink 187 } // namespace blink
157 188
158 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::CSSAnimationUpdate::NewAnimation); 189 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::CSSAnimationUpdate::NewAnimation);
159 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::CSSAnimationUpdate::UpdatedAnimationTim ing); 190 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::CSSAnimationUpdate::UpdatedAnimation);
160 191
161 #endif 192 #endif
OLDNEW
« no previous file with comments | « Source/core/animation/Timing.h ('k') | Source/core/animation/css/CSSAnimations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698