| OLD | NEW |
| 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/animation/KeyframeEffectModel.h" |
| 10 #include "core/animation/css/CSSAnimatableValueFactory.h" |
| 11 #include "core/animation/css/CSSPropertyEquality.h" |
| 9 #include "core/css/CSSKeyframesRule.h" | 12 #include "core/css/CSSKeyframesRule.h" |
| 13 #include "core/layout/LayoutObject.h" |
| 10 #include "wtf/HashMap.h" | 14 #include "wtf/HashMap.h" |
| 11 #include "wtf/Vector.h" | 15 #include "wtf/Vector.h" |
| 12 #include "wtf/text/AtomicString.h" | 16 #include "wtf/text/AtomicString.h" |
| 13 | 17 |
| 14 namespace blink { | 18 namespace blink { |
| 15 | 19 |
| 16 class AnimationPlayer; | 20 class AnimationPlayer; |
| 17 class InertAnimation; | 21 class InertAnimation; |
| 18 | 22 |
| 19 // This class stores the CSS Animations/Transitions information we use during a
style recalc. | 23 // This class stores the CSS Animations/Transitions information we use during a
style recalc. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 80 } |
| 77 | 81 |
| 78 AtomicString name; | 82 AtomicString name; |
| 79 RawPtrWillBeMember<AnimationPlayer> player; | 83 RawPtrWillBeMember<AnimationPlayer> player; |
| 80 RefPtrWillBeMember<InertAnimation> animation; | 84 RefPtrWillBeMember<InertAnimation> animation; |
| 81 Timing specifiedTiming; | 85 Timing specifiedTiming; |
| 82 RefPtrWillBeMember<StyleRuleKeyframes> styleRule; | 86 RefPtrWillBeMember<StyleRuleKeyframes> styleRule; |
| 83 unsigned styleRuleVersion; | 87 unsigned styleRuleVersion; |
| 84 }; | 88 }; |
| 85 | 89 |
| 90 class UpdatedAnimationStyle { |
| 91 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 92 public: |
| 93 struct CompositableStyleSnapshot { |
| 94 RefPtrWillBeMember<AnimatableValue> opacity; |
| 95 RefPtrWillBeMember<AnimatableValue> transform; |
| 96 RefPtrWillBeMember<AnimatableValue> webkitFilter; |
| 97 }; |
| 98 |
| 99 UpdatedAnimationStyle() |
| 100 { |
| 101 } |
| 102 |
| 103 UpdatedAnimationStyle(AnimationPlayer* player, KeyframeEffectModelBase*
effect, const UpdatedAnimationStyle::CompositableStyleSnapshot& snapshot) |
| 104 : player(player) |
| 105 , effect(effect) |
| 106 , snapshot(snapshot) |
| 107 { |
| 108 } |
| 109 |
| 110 void trace(Visitor* visitor) |
| 111 { |
| 112 visitor->trace(player); |
| 113 visitor->trace(effect); |
| 114 } |
| 115 |
| 116 RawPtrWillBeMember<AnimationPlayer> player; |
| 117 RawPtrWillBeMember<KeyframeEffectModelBase> effect; |
| 118 CompositableStyleSnapshot snapshot; |
| 119 }; |
| 120 |
| 86 void startAnimation(const AtomicString& animationName, PassRefPtrWillBeRawPt
r<InertAnimation> animation, const Timing& timing, PassRefPtrWillBeRawPtr<StyleR
uleKeyframes> styleRule) | 121 void startAnimation(const AtomicString& animationName, PassRefPtrWillBeRawPt
r<InertAnimation> animation, const Timing& timing, PassRefPtrWillBeRawPtr<StyleR
uleKeyframes> styleRule) |
| 87 { | 122 { |
| 88 animation->setName(animationName); | 123 animation->setName(animationName); |
| 89 m_newAnimations.append(NewAnimation(animationName, animation, timing, st
yleRule)); | 124 m_newAnimations.append(NewAnimation(animationName, animation, timing, st
yleRule)); |
| 90 } | 125 } |
| 91 // Returns whether player has been suppressed and should be filtered during
style application. | 126 // Returns whether player has been suppressed and should be filtered during
style application. |
| 92 bool isSuppressedAnimation(const AnimationPlayer* player) const { return m_s
uppressedAnimationPlayers.contains(player); } | 127 bool isSuppressedAnimation(const AnimationPlayer* player) const { return m_s
uppressedAnimationPlayers.contains(player); } |
| 93 void cancelAnimation(const AtomicString& name, AnimationPlayer& player) | 128 void cancelAnimation(const AtomicString& name, AnimationPlayer& player) |
| 94 { | 129 { |
| 95 m_cancelledAnimationNames.append(name); | 130 m_cancelledAnimationNames.append(name); |
| 96 m_suppressedAnimationPlayers.add(&player); | 131 m_suppressedAnimationPlayers.add(&player); |
| 97 } | 132 } |
| 98 void toggleAnimationPaused(const AtomicString& name) | 133 void toggleAnimationPaused(const AtomicString& name) |
| 99 { | 134 { |
| 100 m_animationsWithPauseToggled.append(name); | 135 m_animationsWithPauseToggled.append(name); |
| 101 } | 136 } |
| 102 void updateAnimation(const AtomicString& name, AnimationPlayer* player, Pass
RefPtrWillBeRawPtr<InertAnimation> animation, const Timing& specifiedTiming, | 137 void updateAnimation(const AtomicString& name, AnimationPlayer* player, Pass
RefPtrWillBeRawPtr<InertAnimation> animation, const Timing& specifiedTiming, |
| 103 PassRefPtrWillBeRawPtr<StyleRuleKeyframes> styleRule) | 138 PassRefPtrWillBeRawPtr<StyleRuleKeyframes> styleRule) |
| 104 { | 139 { |
| 105 m_animationsWithUpdates.append(UpdatedAnimation(name, player, animation,
specifiedTiming, styleRule)); | 140 m_animationsWithUpdates.append(UpdatedAnimation(name, player, animation,
specifiedTiming, styleRule)); |
| 106 m_suppressedAnimationPlayers.add(player); | 141 m_suppressedAnimationPlayers.add(player); |
| 107 } | 142 } |
| 143 void updateAnimationStyle(AnimationPlayer* player, KeyframeEffectModelBase*
effect, LayoutObject* renderer, const LayoutStyle& newStyle) |
| 144 { |
| 145 UpdatedAnimationStyle::CompositableStyleSnapshot snapshot; |
| 146 if (renderer) { |
| 147 const LayoutStyle& oldStyle = renderer->styleRef(); |
| 148 if (!CSSPropertyEquality::propertiesEqual(CSSPropertyOpacity, oldSty
le, newStyle) && effect->affects(CSSPropertyOpacity)) |
| 149 snapshot.opacity = CSSAnimatableValueFactory::create(CSSProperty
Opacity, newStyle); |
| 150 if (!CSSPropertyEquality::propertiesEqual(CSSPropertyTransform, oldS
tyle, newStyle) && effect->affects(CSSPropertyTransform)) |
| 151 snapshot.transform = CSSAnimatableValueFactory::create(CSSProper
tyTransform, newStyle); |
| 152 if (!CSSPropertyEquality::propertiesEqual(CSSPropertyWebkitFilter, o
ldStyle, newStyle) && effect->affects(CSSPropertyWebkitFilter)) |
| 153 snapshot.webkitFilter = CSSAnimatableValueFactory::create(CSSPro
pertyWebkitFilter, newStyle); |
| 154 } |
| 155 |
| 156 m_animationsWithStyleUpdates.append(UpdatedAnimationStyle(player, effect
, snapshot)); |
| 157 } |
| 108 | 158 |
| 109 void startTransition(CSSPropertyID id, CSSPropertyID eventId, const Animatab
leValue* from, const AnimatableValue* to, PassRefPtrWillBeRawPtr<InertAnimation>
animation) | 159 void startTransition(CSSPropertyID id, CSSPropertyID eventId, const Animatab
leValue* from, const AnimatableValue* to, PassRefPtrWillBeRawPtr<InertAnimation>
animation) |
| 110 { | 160 { |
| 111 animation->setName(getPropertyName(id)); | 161 animation->setName(getPropertyName(id)); |
| 112 NewTransition newTransition; | 162 NewTransition newTransition; |
| 113 newTransition.id = id; | 163 newTransition.id = id; |
| 114 newTransition.eventId = eventId; | 164 newTransition.eventId = eventId; |
| 115 newTransition.from = from; | 165 newTransition.from = from; |
| 116 newTransition.to = to; | 166 newTransition.to = to; |
| 117 newTransition.animation = animation; | 167 newTransition.animation = animation; |
| 118 m_newTransitions.set(id, newTransition); | 168 m_newTransitions.set(id, newTransition); |
| 119 } | 169 } |
| 120 bool isCancelledTransition(CSSPropertyID id) const { return m_cancelledTrans
itions.contains(id); } | 170 bool isCancelledTransition(CSSPropertyID id) const { return m_cancelledTrans
itions.contains(id); } |
| 121 void cancelTransition(CSSPropertyID id) { m_cancelledTransitions.add(id); } | 171 void cancelTransition(CSSPropertyID id) { m_cancelledTransitions.add(id); } |
| 122 | 172 |
| 123 const WillBeHeapVector<NewAnimation>& newAnimations() const { return m_newAn
imations; } | 173 const WillBeHeapVector<NewAnimation>& newAnimations() const { return m_newAn
imations; } |
| 124 const Vector<AtomicString>& cancelledAnimationNames() const { return m_cance
lledAnimationNames; } | 174 const Vector<AtomicString>& cancelledAnimationNames() const { return m_cance
lledAnimationNames; } |
| 125 const WillBeHeapHashSet<RawPtrWillBeMember<const AnimationPlayer>>& suppress
edAnimationAnimationPlayers() const { return m_suppressedAnimationPlayers; } | 175 const WillBeHeapHashSet<RawPtrWillBeMember<const AnimationPlayer>>& suppress
edAnimationAnimationPlayers() const { return m_suppressedAnimationPlayers; } |
| 126 const Vector<AtomicString>& animationsWithPauseToggled() const { return m_an
imationsWithPauseToggled; } | 176 const Vector<AtomicString>& animationsWithPauseToggled() const { return m_an
imationsWithPauseToggled; } |
| 127 const WillBeHeapVector<UpdatedAnimation>& animationsWithUpdates() const { re
turn m_animationsWithUpdates; } | 177 const WillBeHeapVector<UpdatedAnimation>& animationsWithUpdates() const { re
turn m_animationsWithUpdates; } |
| 178 const WillBeHeapVector<UpdatedAnimationStyle>& animationsWithStyleUpdates()
const { return m_animationsWithStyleUpdates; } |
| 128 | 179 |
| 129 struct NewTransition { | 180 struct NewTransition { |
| 130 ALLOW_ONLY_INLINE_ALLOCATION(); | 181 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 131 public: | 182 public: |
| 132 void trace(Visitor* visitor) | 183 void trace(Visitor* visitor) |
| 133 { | 184 { |
| 134 visitor->trace(from); | 185 visitor->trace(from); |
| 135 visitor->trace(to); | 186 visitor->trace(to); |
| 136 visitor->trace(animation); | 187 visitor->trace(animation); |
| 137 } | 188 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 152 const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>>& a
ctiveInterpolationsForTransitions() const { return m_activeInterpolationsForTran
sitions; } | 203 const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>>& a
ctiveInterpolationsForTransitions() const { return m_activeInterpolationsForTran
sitions; } |
| 153 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>>& activeI
nterpolationsForAnimations() { return m_activeInterpolationsForAnimations; } | 204 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>>& activeI
nterpolationsForAnimations() { return m_activeInterpolationsForAnimations; } |
| 154 | 205 |
| 155 bool isEmpty() const | 206 bool isEmpty() const |
| 156 { | 207 { |
| 157 return m_newAnimations.isEmpty() | 208 return m_newAnimations.isEmpty() |
| 158 && m_cancelledAnimationNames.isEmpty() | 209 && m_cancelledAnimationNames.isEmpty() |
| 159 && m_suppressedAnimationPlayers.isEmpty() | 210 && m_suppressedAnimationPlayers.isEmpty() |
| 160 && m_animationsWithPauseToggled.isEmpty() | 211 && m_animationsWithPauseToggled.isEmpty() |
| 161 && m_animationsWithUpdates.isEmpty() | 212 && m_animationsWithUpdates.isEmpty() |
| 213 && m_animationsWithStyleUpdates.isEmpty() |
| 162 && m_newTransitions.isEmpty() | 214 && m_newTransitions.isEmpty() |
| 163 && m_cancelledTransitions.isEmpty() | 215 && m_cancelledTransitions.isEmpty() |
| 164 && m_activeInterpolationsForAnimations.isEmpty() | 216 && m_activeInterpolationsForAnimations.isEmpty() |
| 165 && m_activeInterpolationsForTransitions.isEmpty(); | 217 && m_activeInterpolationsForTransitions.isEmpty(); |
| 166 } | 218 } |
| 167 | 219 |
| 168 void trace(Visitor*); | 220 void trace(Visitor*); |
| 169 | 221 |
| 170 private: | 222 private: |
| 171 // Order is significant since it defines the order in which new animations | 223 // Order is significant since it defines the order in which new animations |
| 172 // will be started. Note that there may be multiple animations present | 224 // will be started. Note that there may be multiple animations present |
| 173 // with the same name, due to the way in which we split up animations with | 225 // with the same name, due to the way in which we split up animations with |
| 174 // incomplete keyframes. | 226 // incomplete keyframes. |
| 175 WillBeHeapVector<NewAnimation> m_newAnimations; | 227 WillBeHeapVector<NewAnimation> m_newAnimations; |
| 176 Vector<AtomicString> m_cancelledAnimationNames; | 228 Vector<AtomicString> m_cancelledAnimationNames; |
| 177 WillBeHeapHashSet<RawPtrWillBeMember<const AnimationPlayer>> m_suppressedAni
mationPlayers; | 229 WillBeHeapHashSet<RawPtrWillBeMember<const AnimationPlayer>> m_suppressedAni
mationPlayers; |
| 178 Vector<AtomicString> m_animationsWithPauseToggled; | 230 Vector<AtomicString> m_animationsWithPauseToggled; |
| 179 WillBeHeapVector<UpdatedAnimation> m_animationsWithUpdates; | 231 WillBeHeapVector<UpdatedAnimation> m_animationsWithUpdates; |
| 232 WillBeHeapVector<UpdatedAnimationStyle> m_animationsWithStyleUpdates; |
| 180 | 233 |
| 181 NewTransitionMap m_newTransitions; | 234 NewTransitionMap m_newTransitions; |
| 182 HashSet<CSSPropertyID> m_cancelledTransitions; | 235 HashSet<CSSPropertyID> m_cancelledTransitions; |
| 183 | 236 |
| 184 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>> m_active
InterpolationsForAnimations; | 237 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>> m_active
InterpolationsForAnimations; |
| 185 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>> m_active
InterpolationsForTransitions; | 238 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>> m_active
InterpolationsForTransitions; |
| 186 }; | 239 }; |
| 187 | 240 |
| 188 } // namespace blink | 241 } // namespace blink |
| 189 | 242 |
| 190 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::CSSAnimationUpdate::NewAnimation); | 243 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::CSSAnimationUpdate::NewAnimation); |
| 191 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::CSSAnimationUpdate::UpdatedAnimation); | 244 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::CSSAnimationUpdate::UpdatedAnimation); |
| 192 | 245 |
| 193 #endif | 246 #endif |
| OLD | NEW |