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

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

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

Powered by Google App Engine
This is Rietveld 408576698