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

Side by Side Diff: Source/core/animation/AnimationNode.h

Issue 1113173003: Web Animations: Update naming to reflect spec changes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: No, really. Created 5 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef AnimationNode_h
32 #define AnimationNode_h
33
34 #include "bindings/core/v8/ScriptWrappable.h"
35 #include "core/CoreExport.h"
36 #include "core/animation/Timing.h"
37 #include "platform/heap/Handle.h"
38 #include "wtf/OwnPtr.h"
39 #include "wtf/PassOwnPtr.h"
40 #include "wtf/RefCounted.h"
41
42 namespace blink {
43
44 class AnimationPlayer;
45 class AnimationNode;
46 class AnimationNodeTiming;
47 class ComputedTimingProperties;
48
49 enum TimingUpdateReason {
50 TimingUpdateOnDemand,
51 TimingUpdateForAnimationFrame
52 };
53
54 static inline bool isNull(double value)
55 {
56 return std::isnan(value);
57 }
58
59 static inline double nullValue()
60 {
61 return std::numeric_limits<double>::quiet_NaN();
62 }
63
64 class CORE_EXPORT AnimationNode : public RefCountedWillBeGarbageCollectedFinaliz ed<AnimationNode>, public ScriptWrappable {
65 DEFINE_WRAPPERTYPEINFO();
66 friend class AnimationPlayer; // Calls attach/detach, updateInheritedTime.
67 public:
68 // Note that logic in CSSAnimations depends on the order of these values.
69 enum Phase {
70 PhaseBefore,
71 PhaseActive,
72 PhaseAfter,
73 PhaseNone,
74 };
75
76 class EventDelegate : public NoBaseWillBeGarbageCollectedFinalized<EventDele gate> {
77 public:
78 virtual ~EventDelegate() { }
79 virtual bool requiresIterationEvents(const AnimationNode&) = 0;
80 virtual void onEventCondition(const AnimationNode&) = 0;
81 DEFINE_INLINE_VIRTUAL_TRACE() { }
82 };
83
84 virtual ~AnimationNode() { }
85
86 virtual bool isAnimation() const { return false; }
87
88 Phase phase() const { return ensureCalculated().phase; }
89 bool isCurrent() const { return ensureCalculated().isCurrent; }
90 bool isInEffect() const { return ensureCalculated().isInEffect; }
91 bool isInPlay() const { return ensureCalculated().isInPlay; }
92 double currentIteration() const { return ensureCalculated().currentIteration ; }
93 double timeFraction() const { return ensureCalculated().timeFraction; }
94 double timeToForwardsEffectChange() const { return ensureCalculated().timeTo ForwardsEffectChange; }
95 double timeToReverseEffectChange() const { return ensureCalculated().timeToR everseEffectChange; }
96
97 double iterationDuration() const;
98 double activeDurationInternal() const;
99 double startTimeInternal() const { return m_startTime; }
100 double endTimeInternal() const { return std::max(startTimeInternal(), startT imeInternal() + specifiedTiming().startDelay + activeDurationInternal() + specif iedTiming().endDelay); }
101
102 const AnimationPlayer* player() const { return m_player; }
103 AnimationPlayer* player() { return m_player; }
104 const Timing& specifiedTiming() const { return m_timing; }
105 PassRefPtrWillBeRawPtr<AnimationNodeTiming> timing();
106 void updateSpecifiedTiming(const Timing&);
107
108 void computedTiming(ComputedTimingProperties&);
109 ComputedTimingProperties computedTiming();
110
111 void setName(const String& name) { m_name = name; }
112 const String& name() const { return m_name; }
113
114 DECLARE_VIRTUAL_TRACE();
115
116 protected:
117 explicit AnimationNode(const Timing&, PassOwnPtrWillBeRawPtr<EventDelegate> = nullptr);
118
119 // When AnimationNode receives a new inherited time via updateInheritedTime
120 // it will (if necessary) recalculate timings and (if necessary) call
121 // updateChildrenAndEffects.
122 void updateInheritedTime(double inheritedTime, TimingUpdateReason) const;
123 void invalidate() const { m_needsUpdate = true; };
124 bool requiresIterationEvents() const { return m_eventDelegate && m_eventDele gate->requiresIterationEvents(*this); }
125 void clearEventDelegate() { m_eventDelegate = nullptr; }
126
127 virtual void attach(AnimationPlayer* player)
128 {
129 m_player = player;
130 }
131
132 virtual void detach()
133 {
134 ASSERT(m_player);
135 m_player = nullptr;
136 }
137
138 double repeatedDuration() const;
139
140 virtual void updateChildrenAndEffects() const = 0;
141 virtual double intrinsicIterationDuration() const { return 0; };
142 virtual double calculateTimeToEffectChange(bool forwards, double localTime, double timeToNextIteration) const = 0;
143 virtual void specifiedTimingChanged() { }
144
145 // FIXME: m_parent and m_startTime are placeholders, they depend on timing g roups.
146 RawPtrWillBeMember<AnimationNode> m_parent;
147 const double m_startTime;
148 RawPtrWillBeMember<AnimationPlayer> m_player;
149 Timing m_timing;
150 OwnPtrWillBeMember<EventDelegate> m_eventDelegate;
151
152 mutable struct CalculatedTiming {
153 Phase phase;
154 double currentIteration;
155 double timeFraction;
156 bool isCurrent;
157 bool isInEffect;
158 bool isInPlay;
159 double localTime;
160 double timeToForwardsEffectChange;
161 double timeToReverseEffectChange;
162 } m_calculated;
163 mutable bool m_needsUpdate;
164 mutable double m_lastUpdateTime;
165 String m_name;
166
167 const CalculatedTiming& ensureCalculated() const;
168 };
169
170 } // namespace blink
171
172 #endif // AnimationNode_h
OLDNEW
« no previous file with comments | « Source/core/animation/AnimationEffectTiming.idl ('k') | Source/core/animation/AnimationNode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698