Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 18 matching lines...) Expand all Loading... | |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef CSSAnimations_h | 31 #ifndef CSSAnimations_h |
| 32 #define CSSAnimations_h | 32 #define CSSAnimations_h |
| 33 | 33 |
| 34 #include "core/animation/Animation.h" | 34 #include "core/animation/Animation.h" |
| 35 #include "core/animation/AnimationPlayer.h" | 35 #include "core/animation/AnimationPlayer.h" |
| 36 #include "core/animation/InertAnimation.h" | 36 #include "core/animation/InertAnimation.h" |
| 37 #include "core/animation/Interpolation.h" | 37 #include "core/animation/Interpolation.h" |
| 38 #include "core/animation/css/CSSAnimationData.h" | 38 #include "core/animation/css/CSSAnimationData.h" |
| 39 #include "core/css/CSSKeyframesRule.h" | |
| 39 #include "core/css/StylePropertySet.h" | 40 #include "core/css/StylePropertySet.h" |
| 40 #include "core/dom/Document.h" | 41 #include "core/dom/Document.h" |
| 41 #include "core/rendering/style/RenderStyleConstants.h" | 42 #include "core/rendering/style/RenderStyleConstants.h" |
| 42 #include "wtf/HashMap.h" | 43 #include "wtf/HashMap.h" |
| 43 #include "wtf/Vector.h" | 44 #include "wtf/Vector.h" |
| 44 #include "wtf/text/AtomicString.h" | 45 #include "wtf/text/AtomicString.h" |
| 45 | 46 |
| 46 namespace blink { | 47 namespace blink { |
| 47 | 48 |
| 48 class CSSTransitionData; | 49 class CSSTransitionData; |
| 49 class Element; | 50 class Element; |
| 50 class StylePropertyShorthand; | 51 class StylePropertyShorthand; |
| 51 class StyleResolver; | 52 class StyleResolver; |
| 52 class StyleRuleKeyframes; | |
| 53 | 53 |
| 54 // This class stores the CSS Animations/Transitions information we use during a style recalc. | 54 // This class stores the CSS Animations/Transitions information we use during a style recalc. |
| 55 // This includes updates to animations/transitions as well as the Interpolations to be applied. | 55 // This includes updates to animations/transitions as well as the Interpolations to be applied. |
| 56 class CSSAnimationUpdate final : public NoBaseWillBeGarbageCollectedFinalized<CS SAnimationUpdate> { | 56 class CSSAnimationUpdate final : public NoBaseWillBeGarbageCollectedFinalized<CS SAnimationUpdate> { |
| 57 public: | 57 public: |
| 58 void startAnimation(const AtomicString& animationName, PassRefPtrWillBeRawPt r<InertAnimation> animation) | 58 void startAnimation(const AtomicString& animationName, PassRefPtrWillBeRawPt r<InertAnimation> animation, const Timing& timing, PassRefPtrWillBeRawPtr<StyleR uleKeyframes> styleRule) |
| 59 { | 59 { |
| 60 animation->setName(animationName); | 60 animation->setName(animationName); |
| 61 NewAnimation newAnimation; | 61 NewAnimation newAnimation; |
| 62 newAnimation.name = animationName; | 62 newAnimation.name = animationName; |
| 63 newAnimation.animation = animation; | 63 newAnimation.animation = animation; |
| 64 newAnimation.timing = timing; | |
| 65 newAnimation.styleChangeCounter = styleRule->styleChangeCounter(); | |
| 66 newAnimation.styleRule = styleRule; | |
| 64 m_newAnimations.append(newAnimation); | 67 m_newAnimations.append(newAnimation); |
| 65 } | 68 } |
| 66 // Returns whether player has been suppressed and should be filtered during style application. | 69 // Returns whether player has been suppressed and should be filtered during style application. |
| 67 bool isSuppressedAnimation(const AnimationPlayer* player) const { return m_s uppressedAnimationPlayers.contains(player); } | 70 bool isSuppressedAnimation(const AnimationPlayer* player) const { return m_s uppressedAnimationPlayers.contains(player); } |
| 68 void cancelAnimation(const AtomicString& name, AnimationPlayer& player) | 71 void cancelAnimation(const AtomicString& name, AnimationPlayer& player) |
| 69 { | 72 { |
| 70 m_cancelledAnimationNames.append(name); | 73 m_cancelledAnimationNames.append(name); |
| 71 m_suppressedAnimationPlayers.add(&player); | 74 m_suppressedAnimationPlayers.add(&player); |
| 72 } | 75 } |
| 73 void toggleAnimationPaused(const AtomicString& name) | 76 void toggleAnimationPaused(const AtomicString& name) |
| 74 { | 77 { |
| 75 m_animationsWithPauseToggled.append(name); | 78 m_animationsWithPauseToggled.append(name); |
| 76 } | 79 } |
| 77 void updateAnimationTiming(AnimationPlayer* player, PassRefPtrWillBeRawPtr<I nertAnimation> animation, const Timing& timing) | 80 void updateAnimation(const AtomicString& name, AnimationPlayer* player, Pass RefPtrWillBeRawPtr<InertAnimation> animation, const Timing& specifiedTiming, Pas sRefPtrWillBeRawPtr<StyleRuleKeyframes> styleRule) |
| 78 { | 81 { |
| 79 UpdatedAnimationTiming updatedAnimation; | 82 UpdatedAnimation updatedAnimation; |
| 83 updatedAnimation.name = name; | |
| 80 updatedAnimation.player = player; | 84 updatedAnimation.player = player; |
| 81 updatedAnimation.animation = animation; | 85 updatedAnimation.animation = animation; |
| 82 updatedAnimation.newTiming = timing; | 86 updatedAnimation.specifiedTiming = specifiedTiming; |
|
shans
2015/01/14 00:26:19
just 'timing' for consistency with InertAnimations
shend
2015/01/14 00:42:04
The 'timing' in InertAnimations isn't actually the
shans
2015/01/15 00:29:52
Could InertAnimations have the easing from the CSS
shend
2015/01/15 01:51:28
I originally talked to Sam about this, but we thou
| |
| 83 m_animationsWithTimingUpdates.append(updatedAnimation); | 87 updatedAnimation.styleChangeCounter = styleRule->styleChangeCounter(); |
| 88 updatedAnimation.styleRule = styleRule; | |
| 89 m_animationsWithUpdates.append(updatedAnimation); | |
| 84 m_suppressedAnimationPlayers.add(player); | 90 m_suppressedAnimationPlayers.add(player); |
| 85 } | 91 } |
| 86 | 92 |
| 87 void startTransition(CSSPropertyID id, CSSPropertyID eventId, const Animatab leValue* from, const AnimatableValue* to, PassRefPtrWillBeRawPtr<InertAnimation> animation) | 93 void startTransition(CSSPropertyID id, CSSPropertyID eventId, const Animatab leValue* from, const AnimatableValue* to, PassRefPtrWillBeRawPtr<InertAnimation> animation) |
| 88 { | 94 { |
| 89 animation->setName(getPropertyName(id)); | 95 animation->setName(getPropertyName(id)); |
| 90 NewTransition newTransition; | 96 NewTransition newTransition; |
| 91 newTransition.id = id; | 97 newTransition.id = id; |
| 92 newTransition.eventId = eventId; | 98 newTransition.eventId = eventId; |
| 93 newTransition.from = from; | 99 newTransition.from = from; |
| 94 newTransition.to = to; | 100 newTransition.to = to; |
| 95 newTransition.animation = animation; | 101 newTransition.animation = animation; |
| 96 m_newTransitions.set(id, newTransition); | 102 m_newTransitions.set(id, newTransition); |
| 97 } | 103 } |
| 98 bool isCancelledTransition(CSSPropertyID id) const { return m_cancelledTrans itions.contains(id); } | 104 bool isCancelledTransition(CSSPropertyID id) const { return m_cancelledTrans itions.contains(id); } |
| 99 void cancelTransition(CSSPropertyID id) { m_cancelledTransitions.add(id); } | 105 void cancelTransition(CSSPropertyID id) { m_cancelledTransitions.add(id); } |
| 100 | 106 |
| 101 struct NewAnimation { | 107 struct NewAnimation { |
| 102 ALLOW_ONLY_INLINE_ALLOCATION(); | 108 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 103 public: | 109 public: |
| 104 void trace(Visitor* visitor) | 110 void trace(Visitor* visitor) |
| 105 { | 111 { |
| 106 visitor->trace(animation); | 112 visitor->trace(animation); |
| 107 } | 113 } |
| 108 | 114 |
| 109 AtomicString name; | 115 AtomicString name; |
| 110 RefPtrWillBeMember<InertAnimation> animation; | 116 RefPtrWillBeMember<InertAnimation> animation; |
| 117 Timing timing; | |
| 118 RefPtrWillBeMember<StyleRuleKeyframes> styleRule; | |
| 119 unsigned styleChangeCounter; | |
| 111 }; | 120 }; |
| 112 | 121 |
| 113 struct UpdatedAnimationTiming { | 122 struct UpdatedAnimation { |
| 114 ALLOW_ONLY_INLINE_ALLOCATION(); | 123 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 115 public: | 124 public: |
| 116 void trace(Visitor* visitor) | 125 void trace(Visitor* visitor) |
| 117 { | 126 { |
| 118 visitor->trace(player); | 127 visitor->trace(player); |
| 119 visitor->trace(animation); | 128 visitor->trace(animation); |
| 120 } | 129 } |
| 121 | 130 |
| 131 AtomicString name; | |
| 122 RawPtrWillBeMember<AnimationPlayer> player; | 132 RawPtrWillBeMember<AnimationPlayer> player; |
| 123 RefPtrWillBeMember<InertAnimation> animation; | 133 RefPtrWillBeMember<InertAnimation> animation; |
| 124 Timing newTiming; | 134 Timing specifiedTiming; |
| 135 RefPtrWillBeMember<StyleRuleKeyframes> styleRule; | |
| 136 unsigned styleChangeCounter; | |
| 125 }; | 137 }; |
| 126 | 138 |
| 127 const WillBeHeapVector<NewAnimation>& newAnimations() const { return m_newAn imations; } | 139 const WillBeHeapVector<NewAnimation>& newAnimations() const { return m_newAn imations; } |
| 128 const Vector<AtomicString>& cancelledAnimationNames() const { return m_cance lledAnimationNames; } | 140 const Vector<AtomicString>& cancelledAnimationNames() const { return m_cance lledAnimationNames; } |
| 129 const WillBeHeapHashSet<RawPtrWillBeMember<const AnimationPlayer>>& suppress edAnimationAnimationPlayers() const { return m_suppressedAnimationPlayers; } | 141 const WillBeHeapHashSet<RawPtrWillBeMember<const AnimationPlayer>>& suppress edAnimationAnimationPlayers() const { return m_suppressedAnimationPlayers; } |
| 130 const Vector<AtomicString>& animationsWithPauseToggled() const { return m_an imationsWithPauseToggled; } | 142 const Vector<AtomicString>& animationsWithPauseToggled() const { return m_an imationsWithPauseToggled; } |
| 131 const WillBeHeapVector<UpdatedAnimationTiming>& animationsWithTimingUpdates( ) const { return m_animationsWithTimingUpdates; } | 143 const WillBeHeapVector<UpdatedAnimation>& animationsWithUpdates() const { re turn m_animationsWithUpdates; } |
| 132 | 144 |
| 133 struct NewTransition { | 145 struct NewTransition { |
| 134 ALLOW_ONLY_INLINE_ALLOCATION(); | 146 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 135 public: | 147 public: |
| 136 void trace(Visitor* visitor) | 148 void trace(Visitor* visitor) |
| 137 { | 149 { |
| 138 visitor->trace(from); | 150 visitor->trace(from); |
| 139 visitor->trace(to); | 151 visitor->trace(to); |
| 140 visitor->trace(animation); | 152 visitor->trace(animation); |
| 141 } | 153 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 155 const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>>& a ctiveInterpolationsForAnimations() const { return m_activeInterpolationsForAnima tions; } | 167 const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>>& a ctiveInterpolationsForAnimations() const { return m_activeInterpolationsForAnima tions; } |
| 156 const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>>& a ctiveInterpolationsForTransitions() const { return m_activeInterpolationsForTran sitions; } | 168 const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>>& a ctiveInterpolationsForTransitions() const { return m_activeInterpolationsForTran sitions; } |
| 157 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>>& activeI nterpolationsForAnimations() { return m_activeInterpolationsForAnimations; } | 169 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>>& activeI nterpolationsForAnimations() { return m_activeInterpolationsForAnimations; } |
| 158 | 170 |
| 159 bool isEmpty() const | 171 bool isEmpty() const |
| 160 { | 172 { |
| 161 return m_newAnimations.isEmpty() | 173 return m_newAnimations.isEmpty() |
| 162 && m_cancelledAnimationNames.isEmpty() | 174 && m_cancelledAnimationNames.isEmpty() |
| 163 && m_suppressedAnimationPlayers.isEmpty() | 175 && m_suppressedAnimationPlayers.isEmpty() |
| 164 && m_animationsWithPauseToggled.isEmpty() | 176 && m_animationsWithPauseToggled.isEmpty() |
| 165 && m_animationsWithTimingUpdates.isEmpty() | 177 && m_animationsWithUpdates.isEmpty() |
| 166 && m_newTransitions.isEmpty() | 178 && m_newTransitions.isEmpty() |
| 167 && m_cancelledTransitions.isEmpty() | 179 && m_cancelledTransitions.isEmpty() |
| 168 && m_activeInterpolationsForAnimations.isEmpty() | 180 && m_activeInterpolationsForAnimations.isEmpty() |
| 169 && m_activeInterpolationsForTransitions.isEmpty(); | 181 && m_activeInterpolationsForTransitions.isEmpty(); |
| 170 } | 182 } |
| 171 | 183 |
| 172 void trace(Visitor*); | 184 void trace(Visitor*); |
| 173 | 185 |
| 174 private: | 186 private: |
| 175 // Order is significant since it defines the order in which new animations | 187 // Order is significant since it defines the order in which new animations |
| 176 // will be started. Note that there may be multiple animations present | 188 // will be started. Note that there may be multiple animations present |
| 177 // with the same name, due to the way in which we split up animations with | 189 // with the same name, due to the way in which we split up animations with |
| 178 // incomplete keyframes. | 190 // incomplete keyframes. |
| 179 WillBeHeapVector<NewAnimation> m_newAnimations; | 191 WillBeHeapVector<NewAnimation> m_newAnimations; |
| 180 Vector<AtomicString> m_cancelledAnimationNames; | 192 Vector<AtomicString> m_cancelledAnimationNames; |
| 181 WillBeHeapHashSet<RawPtrWillBeMember<const AnimationPlayer>> m_suppressedAni mationPlayers; | 193 WillBeHeapHashSet<RawPtrWillBeMember<const AnimationPlayer>> m_suppressedAni mationPlayers; |
| 182 Vector<AtomicString> m_animationsWithPauseToggled; | 194 Vector<AtomicString> m_animationsWithPauseToggled; |
| 183 WillBeHeapVector<UpdatedAnimationTiming> m_animationsWithTimingUpdates; | 195 WillBeHeapVector<UpdatedAnimation> m_animationsWithUpdates; |
| 184 | 196 |
| 185 NewTransitionMap m_newTransitions; | 197 NewTransitionMap m_newTransitions; |
| 186 HashSet<CSSPropertyID> m_cancelledTransitions; | 198 HashSet<CSSPropertyID> m_cancelledTransitions; |
| 187 | 199 |
| 188 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>> m_active InterpolationsForAnimations; | 200 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>> m_active InterpolationsForAnimations; |
| 189 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>> m_active InterpolationsForTransitions; | 201 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>> m_active InterpolationsForTransitions; |
| 190 }; | 202 }; |
| 191 | 203 |
| 192 class CSSAnimations final { | 204 class CSSAnimations final { |
| 193 WTF_MAKE_NONCOPYABLE(CSSAnimations); | 205 WTF_MAKE_NONCOPYABLE(CSSAnimations); |
| 194 DISALLOW_ALLOCATION(); | 206 DISALLOW_ALLOCATION(); |
| 195 public: | 207 public: |
| 196 CSSAnimations(); | 208 CSSAnimations(); |
| 197 | 209 |
| 198 const AtomicString getAnimationNameForInspector(const AnimationPlayer&); | 210 const AtomicString getAnimationNameForInspector(const AnimationPlayer&); |
| 199 | 211 |
| 200 static const StylePropertyShorthand& animatableProperties(); | 212 static const StylePropertyShorthand& animatableProperties(); |
| 201 static bool isAllowedAnimation(CSSPropertyID); | 213 static bool isAllowedAnimation(CSSPropertyID); |
| 202 static PassOwnPtrWillBeRawPtr<CSSAnimationUpdate> calculateUpdate(const Elem ent* animatingElement, Element&, const RenderStyle&, RenderStyle* parentStyle, S tyleResolver*); | 214 static PassOwnPtrWillBeRawPtr<CSSAnimationUpdate> calculateUpdate(const Elem ent* animatingElement, Element&, const RenderStyle&, RenderStyle* parentStyle, S tyleResolver*); |
| 203 | 215 |
| 204 void setPendingUpdate(PassOwnPtrWillBeRawPtr<CSSAnimationUpdate> update) { m _pendingUpdate = update; } | 216 void setPendingUpdate(PassOwnPtrWillBeRawPtr<CSSAnimationUpdate> update) { m _pendingUpdate = update; } |
| 205 void maybeApplyPendingUpdate(Element*); | 217 void maybeApplyPendingUpdate(Element*); |
| 206 bool isEmpty() const { return m_animations.isEmpty() && m_transitions.isEmpt y() && !m_pendingUpdate; } | 218 bool isEmpty() const { return m_animations.isEmpty() && m_transitions.isEmpt y() && !m_pendingUpdate; } |
| 207 void cancel(); | 219 void cancel(); |
| 208 | 220 |
| 209 void trace(Visitor*); | 221 void trace(Visitor*); |
| 210 | 222 |
| 211 private: | 223 private: |
| 224 struct RunningAnimation { | |
| 225 ALLOW_ONLY_INLINE_ALLOCATION(); | |
| 226 public: | |
| 227 void trace(Visitor* visitor) | |
| 228 { | |
| 229 visitor->trace(player); | |
| 230 } | |
| 231 | |
| 232 RefPtrWillBeMember<AnimationPlayer> player; | |
| 233 Timing specifiedTiming; | |
| 234 RefPtrWillBeMember<StyleRuleKeyframes> styleRule; | |
| 235 unsigned styleChangeCounter; | |
| 236 }; | |
| 237 | |
| 212 struct RunningTransition { | 238 struct RunningTransition { |
| 213 ALLOW_ONLY_INLINE_ALLOCATION(); | 239 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 214 public: | 240 public: |
| 215 void trace(Visitor* visitor) | 241 void trace(Visitor* visitor) |
| 216 { | 242 { |
| 217 visitor->trace(player); | 243 visitor->trace(player); |
| 218 visitor->trace(from); | 244 visitor->trace(from); |
| 219 visitor->trace(to); | 245 visitor->trace(to); |
| 220 } | 246 } |
| 221 | 247 |
| 222 RefPtrWillBeMember<AnimationPlayer> player; | 248 RefPtrWillBeMember<AnimationPlayer> player; |
| 223 RawPtrWillBeMember<const AnimatableValue> from; | 249 RawPtrWillBeMember<const AnimatableValue> from; |
| 224 RawPtrWillBeMember<const AnimatableValue> to; | 250 RawPtrWillBeMember<const AnimatableValue> to; |
| 225 }; | 251 }; |
| 226 | 252 |
| 227 using AnimationMap = WillBeHeapHashMap<AtomicString, RefPtrWillBeMember<Anim ationPlayer>>; | 253 using AnimationMap = WillBeHeapHashMap<AtomicString, RunningAnimation>; |
| 228 AnimationMap m_animations; | 254 AnimationMap m_animations; |
| 229 | 255 |
| 230 using TransitionMap = WillBeHeapHashMap<CSSPropertyID, RunningTransition>; | 256 using TransitionMap = WillBeHeapHashMap<CSSPropertyID, RunningTransition>; |
| 231 TransitionMap m_transitions; | 257 TransitionMap m_transitions; |
| 232 | 258 |
| 233 OwnPtrWillBeMember<CSSAnimationUpdate> m_pendingUpdate; | 259 OwnPtrWillBeMember<CSSAnimationUpdate> m_pendingUpdate; |
| 234 | 260 |
| 235 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>> m_previo usActiveInterpolationsForAnimations; | 261 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>> m_previo usActiveInterpolationsForAnimations; |
| 236 | 262 |
| 237 static void calculateAnimationUpdate(CSSAnimationUpdate*, const Element* ani matingElement, Element&, const RenderStyle&, RenderStyle* parentStyle, StyleReso lver*); | 263 static void calculateAnimationUpdate(CSSAnimationUpdate*, const Element* ani matingElement, Element&, const RenderStyle&, RenderStyle* parentStyle, StyleReso lver*); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 private: | 303 private: |
| 278 RawPtrWillBeMember<Element> m_target; | 304 RawPtrWillBeMember<Element> m_target; |
| 279 const CSSPropertyID m_property; | 305 const CSSPropertyID m_property; |
| 280 AnimationNode::Phase m_previousPhase; | 306 AnimationNode::Phase m_previousPhase; |
| 281 }; | 307 }; |
| 282 }; | 308 }; |
| 283 | 309 |
| 284 } // namespace blink | 310 } // namespace blink |
| 285 | 311 |
| 286 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::CSSAnimationUpdate::NewAnimation); | 312 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::CSSAnimationUpdate::NewAnimation); |
| 287 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::CSSAnimationUpdate::UpdatedAnimationTim ing); | 313 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::CSSAnimationUpdate::UpdatedAnimation); |
| 288 | 314 |
| 289 #endif | 315 #endif |
| OLD | NEW |