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

Side by Side Diff: sky/engine/core/animation/AnimationNode.h

Issue 1229273004: Remove Animations and Transitions. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 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
(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 SKY_ENGINE_CORE_ANIMATION_ANIMATIONNODE_H_
32 #define SKY_ENGINE_CORE_ANIMATION_ANIMATIONNODE_H_
33
34 #include "sky/engine/tonic/dart_wrappable.h"
35 #include "sky/engine/core/animation/Timing.h"
36 #include "sky/engine/wtf/OwnPtr.h"
37 #include "sky/engine/wtf/PassOwnPtr.h"
38 #include "sky/engine/wtf/RefCounted.h"
39
40 namespace blink {
41
42 class AnimationPlayer;
43 class AnimationNode;
44 class AnimationNodeTiming;
45
46 enum TimingUpdateReason {
47 TimingUpdateOnDemand,
48 TimingUpdateForAnimationFrame
49 };
50
51 static inline bool isNull(double value)
52 {
53 return std::isnan(value);
54 }
55
56 static inline double nullValue()
57 {
58 return std::numeric_limits<double>::quiet_NaN();
59 }
60
61 class AnimationNode : public RefCounted<AnimationNode>, public DartWrappable {
62 DEFINE_WRAPPERTYPEINFO();
63 friend class AnimationPlayer; // Calls attach/detach, updateInheritedTime.
64 public:
65 // Note that logic in CSSAnimations depends on the order of these values.
66 enum Phase {
67 PhaseBefore,
68 PhaseActive,
69 PhaseAfter,
70 PhaseNone,
71 };
72
73 class EventDelegate {
74 public:
75 virtual ~EventDelegate() { }
76 virtual void onEventCondition(const AnimationNode*) = 0;
77 };
78
79 virtual ~AnimationNode() { }
80
81 virtual bool isAnimation() const { return false; }
82
83 Phase phase() const { return ensureCalculated().phase; }
84 bool isCurrent() const { return ensureCalculated().isCurrent; }
85 bool isInEffect() const { return ensureCalculated().isInEffect; }
86 bool isInPlay() const { return ensureCalculated().isInPlay; }
87 double timeToForwardsEffectChange() const { return ensureCalculated().timeTo ForwardsEffectChange; }
88 double timeToReverseEffectChange() const { return ensureCalculated().timeToR everseEffectChange; }
89
90 double currentIteration() const { return ensureCalculated().currentIteration ; }
91 double iterationDuration() const;
92
93 // This method returns time in ms as it is unused except via the API.
94 double duration() const { return iterationDuration() * 1000; }
95
96 double activeDuration() const { return activeDurationInternal() * 1000; }
97 double activeDurationInternal() const;
98 double timeFraction() const { return ensureCalculated().timeFraction; }
99 double startTime() const { return m_startTime * 1000; }
100 double startTimeInternal() const { return m_startTime; }
101 double endTime() const { return endTimeInternal() * 1000; }
102 double endTimeInternal() const { return startTime() + specifiedTiming().star tDelay + activeDurationInternal() + specifiedTiming().endDelay; }
103
104 const AnimationPlayer* player() const { return m_player; }
105 AnimationPlayer* player() { return m_player; }
106 const Timing& specifiedTiming() const { return m_timing; }
107 PassRefPtr<AnimationNodeTiming> timing();
108 void updateSpecifiedTiming(const Timing&);
109
110 // This method returns time in ms as it is unused except via the API.
111 double localTime(bool& isNull) const { isNull = !m_player; return ensureCalc ulated().localTime * 1000; }
112 double currentIteration(bool& isNull) const { isNull = !ensureCalculated().i sInEffect; return ensureCalculated().currentIteration; }
113
114 protected:
115 explicit AnimationNode(const Timing&, PassOwnPtr<EventDelegate> = nullptr);
116
117 // When AnimationNode receives a new inherited time via updateInheritedTime
118 // it will (if necessary) recalculate timings and (if necessary) call
119 // updateChildrenAndEffects.
120 void updateInheritedTime(double inheritedTime, TimingUpdateReason) const;
121 void invalidate() const { m_needsUpdate = true; };
122 bool hasEvents() const { return m_eventDelegate; }
123 void clearEventDelegate() { m_eventDelegate = nullptr; }
124
125 virtual void attach(AnimationPlayer* player)
126 {
127 m_player = player;
128 }
129
130 virtual void detach()
131 {
132 ASSERT(m_player);
133 m_player = nullptr;
134 }
135
136 double repeatedDuration() const;
137
138 virtual void updateChildrenAndEffects() const = 0;
139 virtual double intrinsicIterationDuration() const { return 0; };
140 virtual double calculateTimeToEffectChange(bool forwards, double localTime, double timeToNextIteration) const = 0;
141 virtual void specifiedTimingChanged() { }
142
143 // FIXME: m_parent and m_startTime are placeholders, they depend on timing g roups.
144 RawPtr<AnimationNode> m_parent;
145 const double m_startTime;
146 RawPtr<AnimationPlayer> m_player;
147 Timing m_timing;
148 OwnPtr<EventDelegate> m_eventDelegate;
149
150 mutable struct CalculatedTiming {
151 Phase phase;
152 double currentIteration;
153 double timeFraction;
154 bool isCurrent;
155 bool isInEffect;
156 bool isInPlay;
157 double localTime;
158 double timeToForwardsEffectChange;
159 double timeToReverseEffectChange;
160 } m_calculated;
161 mutable bool m_needsUpdate;
162 mutable double m_lastUpdateTime;
163
164 const CalculatedTiming& ensureCalculated() const;
165 };
166
167 } // namespace blink
168
169 #endif // SKY_ENGINE_CORE_ANIMATION_ANIMATIONNODE_H_
OLDNEW
« no previous file with comments | « sky/engine/core/animation/AnimationHelpersTest.cpp ('k') | sky/engine/core/animation/AnimationNode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698