| 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 26 matching lines...) Expand all Loading... |
| 37 #include "core/css/StylePropertySet.h" | 37 #include "core/css/StylePropertySet.h" |
| 38 #include "core/dom/Document.h" | 38 #include "core/dom/Document.h" |
| 39 #include "core/platform/animation/CSSAnimationData.h" | 39 #include "core/platform/animation/CSSAnimationData.h" |
| 40 #include "core/rendering/style/RenderStyleConstants.h" | 40 #include "core/rendering/style/RenderStyleConstants.h" |
| 41 #include "wtf/HashMap.h" | 41 #include "wtf/HashMap.h" |
| 42 #include "wtf/Vector.h" | 42 #include "wtf/Vector.h" |
| 43 #include "wtf/text/AtomicString.h" | 43 #include "wtf/text/AtomicString.h" |
| 44 | 44 |
| 45 namespace WebCore { | 45 namespace WebCore { |
| 46 | 46 |
| 47 class CSSAnimationDataList; | 47 class CandidateTransition; |
| 48 class Element; | 48 class Element; |
| 49 class RenderObject; | 49 class StylePropertyShorthand; |
| 50 class StyleResolver; | 50 class StyleResolver; |
| 51 | 51 |
| 52 // Applied to scopes where an animation update will be added as pending and shou
ld then be applied (eg. Element style recalc). | 52 // Applied to scopes where an animation update will be added as pending and shou
ld then be applied (eg. Element style recalc). |
| 53 class CSSAnimationUpdateScope FINAL { | 53 class CSSAnimationUpdateScope FINAL { |
| 54 public: | 54 public: |
| 55 CSSAnimationUpdateScope(Element*); | 55 CSSAnimationUpdateScope(Element*); |
| 56 ~CSSAnimationUpdateScope(); | 56 ~CSSAnimationUpdateScope(); |
| 57 private: | 57 private: |
| 58 Element* m_target; | 58 Element* m_target; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 class CSSAnimationUpdate FINAL { | 61 class CSSAnimationUpdate FINAL { |
| 62 public: | 62 public: |
| 63 void startAnimation(AtomicString& animationName, const HashSet<RefPtr<InertA
nimation> >& animations) | 63 void startAnimation(AtomicString& animationName, const HashSet<RefPtr<InertA
nimation> >& animations) |
| 64 { | 64 { |
| 65 NewAnimation newAnimation; | 65 NewAnimation newAnimation; |
| 66 newAnimation.name = animationName; | 66 newAnimation.name = animationName; |
| 67 newAnimation.animations = animations; | 67 newAnimation.animations = animations; |
| 68 m_newAnimations.append(newAnimation); | 68 m_newAnimations.append(newAnimation); |
| 69 } | 69 } |
| 70 // Returns whether player has been cancelled and should be filtered during s
tyle application. | 70 // Returns whether player has been cancelled and should be filtered during s
tyle application. |
| 71 bool isCancelled(const Player* player) const { return m_cancelledAnimationPl
ayers.contains(player); } | 71 bool isCancelledAnimation(const Player* player) const { return m_cancelledAn
imationPlayers.contains(player); } |
| 72 void cancelAnimation(const AtomicString& name, const HashSet<RefPtr<Player>
>& players) | 72 void cancelAnimation(const AtomicString& name, const HashSet<RefPtr<Player>
>& players) |
| 73 { | 73 { |
| 74 m_cancelledAnimationNames.append(name); | 74 m_cancelledAnimationNames.append(name); |
| 75 for (HashSet<RefPtr<Player> >::const_iterator iter = players.begin(); it
er != players.end(); ++iter) | 75 for (HashSet<RefPtr<Player> >::const_iterator iter = players.begin(); it
er != players.end(); ++iter) |
| 76 m_cancelledAnimationPlayers.add(iter->get()); | 76 m_cancelledAnimationPlayers.add(iter->get()); |
| 77 } | 77 } |
| 78 |
| 79 void startTransition(CSSPropertyID id, const AnimatableValue* from, const An
imatableValue* to, PassRefPtr<InertAnimation> animation) |
| 80 { |
| 81 NewTransition newTransition; |
| 82 newTransition.id = id; |
| 83 newTransition.from = from; |
| 84 newTransition.to = to; |
| 85 newTransition.animation = animation; |
| 86 m_newTransitions.append(newTransition); |
| 87 } |
| 88 void cancelTransition(CSSPropertyID id) { m_cancelledTransitions.add(id); } |
| 89 |
| 78 struct NewAnimation { | 90 struct NewAnimation { |
| 79 AtomicString name; | 91 AtomicString name; |
| 80 HashSet<RefPtr<InertAnimation> > animations; | 92 HashSet<RefPtr<InertAnimation> > animations; |
| 81 }; | 93 }; |
| 82 const Vector<NewAnimation>& newAnimations() const { return m_newAnimations;
} | 94 const Vector<NewAnimation>& newAnimations() const { return m_newAnimations;
} |
| 83 const Vector<AtomicString>& cancelledAnimationNames() const { return m_cance
lledAnimationNames; } | 95 const Vector<AtomicString>& cancelledAnimationNames() const { return m_cance
lledAnimationNames; } |
| 96 |
| 97 struct NewTransition { |
| 98 CSSPropertyID id; |
| 99 const AnimatableValue* from; |
| 100 const AnimatableValue* to; |
| 101 RefPtr<InertAnimation> animation; |
| 102 }; |
| 103 const Vector<NewTransition>& newTransitions() const { return m_newTransition
s; } |
| 104 const HashSet<CSSPropertyID>& cancelledTransitions() const { return m_cancel
ledTransitions; } |
| 105 |
| 106 bool isEmpty() const |
| 107 { |
| 108 return m_newAnimations.isEmpty() |
| 109 && m_cancelledAnimationNames.isEmpty() |
| 110 && m_cancelledAnimationPlayers.isEmpty() |
| 111 && m_newTransitions.isEmpty() |
| 112 && m_cancelledTransitions.isEmpty(); |
| 113 } |
| 84 private: | 114 private: |
| 85 // Order is significant since it defines the order in which new animations | 115 // Order is significant since it defines the order in which new animations |
| 86 // will be started. Note that there may be multiple animations present | 116 // will be started. Note that there may be multiple animations present |
| 87 // with the same name, due to the way in which we split up animations with | 117 // with the same name, due to the way in which we split up animations with |
| 88 // incomplete keyframes. | 118 // incomplete keyframes. |
| 89 Vector<NewAnimation> m_newAnimations; | 119 Vector<NewAnimation> m_newAnimations; |
| 90 Vector<AtomicString> m_cancelledAnimationNames; | 120 Vector<AtomicString> m_cancelledAnimationNames; |
| 91 HashSet<const Player*> m_cancelledAnimationPlayers; | 121 HashSet<const Player*> m_cancelledAnimationPlayers; |
| 122 |
| 123 Vector<NewTransition> m_newTransitions; |
| 124 HashSet<CSSPropertyID> m_cancelledTransitions; |
| 92 }; | 125 }; |
| 93 | 126 |
| 94 class CSSAnimations FINAL { | 127 class CSSAnimations FINAL { |
| 95 public: | 128 public: |
| 96 static bool isAnimatableProperty(CSSPropertyID); | 129 static bool isAnimatableProperty(CSSPropertyID); |
| 97 static bool needsUpdate(const Element*, const RenderStyle*); | 130 static const StylePropertyShorthand& animatableProperties(); |
| 98 static PassOwnPtr<CSSAnimationUpdate> calculateUpdate(Element*, const Render
Style*, const CSSAnimations*, const CSSAnimationDataList*, StyleResolver*); | 131 // FIXME: This should take a const ScopedStyleTree instead of a StyleResolve
r. |
| 132 // We should also change the Element* to a const Element* |
| 133 static PassOwnPtr<CSSAnimationUpdate> calculateUpdate(Element*, const Render
Style*, StyleResolver*); |
| 134 |
| 99 void setPendingUpdate(PassOwnPtr<CSSAnimationUpdate> update) { m_pendingUpda
te = update; } | 135 void setPendingUpdate(PassOwnPtr<CSSAnimationUpdate> update) { m_pendingUpda
te = update; } |
| 100 void maybeApplyPendingUpdate(Element*); | 136 void maybeApplyPendingUpdate(Element*); |
| 101 bool isEmpty() const { return m_animations.isEmpty() && !m_pendingUpdate; } | 137 bool isEmpty() const { return m_animations.isEmpty() && m_transitions.isEmpt
y() && !m_pendingUpdate; } |
| 102 void cancel(); | 138 void cancel(); |
| 103 private: | 139 private: |
| 104 // Note that a single animation name may map to multiple players due to | 140 // Note that a single animation name may map to multiple players due to |
| 105 // the way in which we split up animations with incomplete keyframes. | 141 // the way in which we split up animations with incomplete keyframes. |
| 106 // FIXME: Once the Web Animations model supports groups, we could use a | 142 // FIXME: Once the Web Animations model supports groups, we could use a |
| 107 // ParGroup to drive multiple animations from a single Player. | 143 // ParGroup to drive multiple animations from a single Player. |
| 108 typedef HashMap<AtomicString, HashSet<RefPtr<Player> > > AnimationMap; | 144 typedef HashMap<AtomicString, HashSet<RefPtr<Player> > > AnimationMap; |
| 145 struct RunningTransition { |
| 146 RefPtr<Player> player; |
| 147 const AnimatableValue* from; |
| 148 const AnimatableValue* to; |
| 149 }; |
| 150 typedef HashMap<CSSPropertyID, RunningTransition > TransitionMap; |
| 109 AnimationMap m_animations; | 151 AnimationMap m_animations; |
| 152 TransitionMap m_transitions; |
| 110 OwnPtr<CSSAnimationUpdate> m_pendingUpdate; | 153 OwnPtr<CSSAnimationUpdate> m_pendingUpdate; |
| 111 class EventDelegate FINAL : public TimedItem::EventDelegate { | 154 |
| 155 static void calculateAnimationUpdate(CSSAnimationUpdate*, Element*, const Re
nderStyle*, StyleResolver*); |
| 156 static void calculateTransitionUpdate(CSSAnimationUpdate*, const Element*, c
onst RenderStyle*); |
| 157 static void calculateTransitionUpdateForProperty(CSSAnimationUpdate*, CSSPro
pertyID, const CandidateTransition&, const TransitionMap*); |
| 158 |
| 159 class AnimationEventDelegate FINAL : public TimedItem::EventDelegate { |
| 112 public: | 160 public: |
| 113 EventDelegate(Element* target, const AtomicString& name) | 161 AnimationEventDelegate(Element* target, const AtomicString& name) |
| 114 : m_target(target) | 162 : m_target(target) |
| 115 , m_name(name) | 163 , m_name(name) |
| 116 { | 164 { |
| 117 } | 165 } |
| 118 virtual void onEventCondition(const TimedItem*, bool isFirstSample, Time
dItem::Phase previousPhase, double previousIteration) OVERRIDE; | 166 virtual void onEventCondition(const TimedItem*, bool isFirstSample, Time
dItem::Phase previousPhase, double previousIteration) OVERRIDE; |
| 119 private: | 167 private: |
| 120 void maybeDispatch(Document::ListenerType, const AtomicString& eventName
, double elapsedTime); | 168 void maybeDispatch(Document::ListenerType, const AtomicString& eventName
, double elapsedTime); |
| 121 Element* m_target; | 169 Element* m_target; |
| 122 const AtomicString m_name; | 170 const AtomicString m_name; |
| 123 }; | 171 }; |
| 172 |
| 173 class TransitionEventDelegate FINAL : public TimedItem::EventDelegate { |
| 174 public: |
| 175 TransitionEventDelegate(Element* target, CSSPropertyID property) |
| 176 : m_target(target) |
| 177 , m_property(property) |
| 178 { |
| 179 } |
| 180 virtual void onEventCondition(const TimedItem*, bool isFirstSample, Time
dItem::Phase previousPhase, double previousIteration) OVERRIDE; |
| 181 private: |
| 182 Element* m_target; |
| 183 const CSSPropertyID m_property; |
| 184 }; |
| 124 }; | 185 }; |
| 125 | 186 |
| 126 } // namespace WebCore | 187 } // namespace WebCore |
| 127 | 188 |
| 128 #endif | 189 #endif |
| OLD | NEW |