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 10 matching lines...) Expand all Loading... |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef TimedItem_h | 31 #ifndef AnimationSource_h |
32 #define TimedItem_h | 32 #define AnimationSource_h |
33 | 33 |
34 #include "core/animation/Timing.h" | 34 #include "core/animation/Timing.h" |
35 #include "platform/heap/Handle.h" | 35 #include "platform/heap/Handle.h" |
36 #include "wtf/OwnPtr.h" | 36 #include "wtf/OwnPtr.h" |
37 #include "wtf/PassOwnPtr.h" | 37 #include "wtf/PassOwnPtr.h" |
38 #include "wtf/RefCounted.h" | 38 #include "wtf/RefCounted.h" |
39 | 39 |
40 namespace WebCore { | 40 namespace WebCore { |
41 | 41 |
42 class AnimationPlayer; | 42 class AnimationPlayer; |
43 class TimedItem; | 43 class AnimationSource; |
44 class TimedItemTiming; | 44 class AnimationSourceTiming; |
45 | 45 |
46 enum TimingUpdateReason { | 46 enum TimingUpdateReason { |
47 TimingUpdateOnDemand, | 47 TimingUpdateOnDemand, |
48 TimingUpdateForAnimationFrame | 48 TimingUpdateForAnimationFrame |
49 }; | 49 }; |
50 | 50 |
51 static inline bool isNull(double value) | 51 static inline bool isNull(double value) |
52 { | 52 { |
53 return std::isnan(value); | 53 return std::isnan(value); |
54 } | 54 } |
55 | 55 |
56 static inline double nullValue() | 56 static inline double nullValue() |
57 { | 57 { |
58 return std::numeric_limits<double>::quiet_NaN(); | 58 return std::numeric_limits<double>::quiet_NaN(); |
59 } | 59 } |
60 | 60 |
61 class TimedItem : public RefCountedWillBeGarbageCollectedFinalized<TimedItem> { | 61 class AnimationSource : public RefCountedWillBeGarbageCollectedFinalized<Animati
onSource> { |
62 friend class AnimationPlayer; // Calls attach/detach, updateInheritedTime. | 62 friend class AnimationPlayer; // Calls attach/detach, updateInheritedTime. |
63 public: | 63 public: |
64 // Note that logic in CSSAnimations depends on the order of these values. | 64 // Note that logic in CSSAnimations depends on the order of these values. |
65 enum Phase { | 65 enum Phase { |
66 PhaseBefore, | 66 PhaseBefore, |
67 PhaseActive, | 67 PhaseActive, |
68 PhaseAfter, | 68 PhaseAfter, |
69 PhaseNone, | 69 PhaseNone, |
70 }; | 70 }; |
71 | 71 |
72 class EventDelegate { | 72 class EventDelegate { |
73 public: | 73 public: |
74 virtual ~EventDelegate() { }; | 74 virtual ~EventDelegate() { }; |
75 virtual void onEventCondition(const TimedItem*) = 0; | 75 virtual void onEventCondition(const AnimationSource*) = 0; |
76 }; | 76 }; |
77 | 77 |
78 virtual ~TimedItem() { } | 78 virtual ~AnimationSource() { } |
79 | 79 |
80 virtual bool isAnimation() const { return false; } | 80 virtual bool isAnimation() const { return false; } |
81 | 81 |
82 Phase phase() const { return ensureCalculated().phase; } | 82 Phase phase() const { return ensureCalculated().phase; } |
83 bool isCurrent() const { return ensureCalculated().isCurrent; } | 83 bool isCurrent() const { return ensureCalculated().isCurrent; } |
84 bool isInEffect() const { return ensureCalculated().isInEffect; } | 84 bool isInEffect() const { return ensureCalculated().isInEffect; } |
85 bool isInPlay() const { return ensureCalculated().isInPlay; } | 85 bool isInPlay() const { return ensureCalculated().isInPlay; } |
86 double timeToForwardsEffectChange() const { return ensureCalculated().timeTo
ForwardsEffectChange; } | 86 double timeToForwardsEffectChange() const { return ensureCalculated().timeTo
ForwardsEffectChange; } |
87 double timeToReverseEffectChange() const { return ensureCalculated().timeToR
everseEffectChange; } | 87 double timeToReverseEffectChange() const { return ensureCalculated().timeToR
everseEffectChange; } |
88 | 88 |
89 double currentIteration() const { return ensureCalculated().currentIteration
; } | 89 double currentIteration() const { return ensureCalculated().currentIteration
; } |
90 double iterationDuration() const; | 90 double iterationDuration() const; |
91 | 91 |
92 // This method returns time in ms as it is unused except via the API. | 92 // This method returns time in ms as it is unused except via the API. |
93 double duration() const { return iterationDuration() * 1000; } | 93 double duration() const { return iterationDuration() * 1000; } |
94 | 94 |
95 double activeDuration() const { return activeDurationInternal() * 1000; } | 95 double activeDuration() const { return activeDurationInternal() * 1000; } |
96 double activeDurationInternal() const; | 96 double activeDurationInternal() const; |
97 double timeFraction() const { return ensureCalculated().timeFraction; } | 97 double timeFraction() const { return ensureCalculated().timeFraction; } |
98 double startTime() const { return m_startTime * 1000; } | 98 double startTime() const { return m_startTime * 1000; } |
99 double startTimeInternal() const { return m_startTime; } | 99 double startTimeInternal() const { return m_startTime; } |
100 double endTime() const { return endTimeInternal() * 1000; } | 100 double endTime() const { return endTimeInternal() * 1000; } |
101 double endTimeInternal() const { return startTime() + specifiedTiming().star
tDelay + activeDurationInternal() + specifiedTiming().endDelay; } | 101 double endTimeInternal() const { return startTime() + specifiedTiming().star
tDelay + activeDurationInternal() + specifiedTiming().endDelay; } |
102 | 102 |
103 const AnimationPlayer* player() const { return m_player; } | 103 const AnimationPlayer* player() const { return m_player; } |
104 AnimationPlayer* player() { return m_player; } | 104 AnimationPlayer* player() { return m_player; } |
105 AnimationPlayer* player(bool& isNull) { isNull = !m_player; return m_player;
} | 105 AnimationPlayer* player(bool& isNull) { isNull = !m_player; return m_player;
} |
106 const Timing& specifiedTiming() const { return m_timing; } | 106 const Timing& specifiedTiming() const { return m_timing; } |
107 PassRefPtrWillBeRawPtr<TimedItemTiming> timing(); | 107 PassRefPtrWillBeRawPtr<AnimationSourceTiming> timing(); |
108 void updateSpecifiedTiming(const Timing&); | 108 void updateSpecifiedTiming(const Timing&); |
109 | 109 |
110 // This method returns time in ms as it is unused except via the API. | 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; } | 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; } | 112 double currentIteration(bool& isNull) const { isNull = !ensureCalculated().i
sInEffect; return ensureCalculated().currentIteration; } |
113 | 113 |
114 virtual void trace(Visitor*); | 114 virtual void trace(Visitor*); |
115 | 115 |
116 protected: | 116 protected: |
117 explicit TimedItem(const Timing&, PassOwnPtr<EventDelegate> = nullptr); | 117 explicit AnimationSource(const Timing&, PassOwnPtr<EventDelegate> = nullptr)
; |
118 | 118 |
119 // When TimedItem receives a new inherited time via updateInheritedTime | 119 // When AnimationSource receives a new inherited time via updateInheritedTim
e |
120 // it will (if necessary) recalculate timings and (if necessary) call | 120 // it will (if necessary) recalculate timings and (if necessary) call |
121 // updateChildrenAndEffects. | 121 // updateChildrenAndEffects. |
122 void updateInheritedTime(double inheritedTime, TimingUpdateReason) const; | 122 void updateInheritedTime(double inheritedTime, TimingUpdateReason) const; |
123 void invalidate() const { m_needsUpdate = true; }; | 123 void invalidate() const { m_needsUpdate = true; }; |
124 bool hasEvents() const { return m_eventDelegate; } | 124 bool hasEvents() const { return m_eventDelegate; } |
125 void clearEventDelegate() { m_eventDelegate = nullptr; } | 125 void clearEventDelegate() { m_eventDelegate = nullptr; } |
126 | 126 |
127 virtual void attach(AnimationPlayer* player) | 127 virtual void attach(AnimationPlayer* player) |
128 { | 128 { |
129 m_player = player; | 129 m_player = player; |
130 } | 130 } |
131 | 131 |
132 virtual void detach() | 132 virtual void detach() |
133 { | 133 { |
134 ASSERT(m_player); | 134 ASSERT(m_player); |
135 m_player = nullptr; | 135 m_player = nullptr; |
136 } | 136 } |
137 | 137 |
138 double repeatedDuration() const; | 138 double repeatedDuration() const; |
139 | 139 |
140 virtual void updateChildrenAndEffects() const = 0; | 140 virtual void updateChildrenAndEffects() const = 0; |
141 virtual double intrinsicIterationDuration() const { return 0; }; | 141 virtual double intrinsicIterationDuration() const { return 0; }; |
142 virtual double calculateTimeToEffectChange(bool forwards, double localTime,
double timeToNextIteration) const = 0; | 142 virtual double calculateTimeToEffectChange(bool forwards, double localTime,
double timeToNextIteration) const = 0; |
143 virtual void specifiedTimingChanged() { } | 143 virtual void specifiedTimingChanged() { } |
144 | 144 |
145 // FIXME: m_parent and m_startTime are placeholders, they depend on timing g
roups. | 145 // FIXME: m_parent and m_startTime are placeholders, they depend on timing g
roups. |
146 RawPtrWillBeMember<TimedItem> m_parent; | 146 RawPtrWillBeMember<AnimationSource> m_parent; |
147 const double m_startTime; | 147 const double m_startTime; |
148 RawPtrWillBeMember<AnimationPlayer> m_player; | 148 RawPtrWillBeMember<AnimationPlayer> m_player; |
149 Timing m_timing; | 149 Timing m_timing; |
150 OwnPtr<EventDelegate> m_eventDelegate; | 150 OwnPtr<EventDelegate> m_eventDelegate; |
151 | 151 |
152 mutable struct CalculatedTiming { | 152 mutable struct CalculatedTiming { |
153 Phase phase; | 153 Phase phase; |
154 double currentIteration; | 154 double currentIteration; |
155 double timeFraction; | 155 double timeFraction; |
156 bool isCurrent; | 156 bool isCurrent; |
157 bool isInEffect; | 157 bool isInEffect; |
158 bool isInPlay; | 158 bool isInPlay; |
159 double localTime; | 159 double localTime; |
160 double timeToForwardsEffectChange; | 160 double timeToForwardsEffectChange; |
161 double timeToReverseEffectChange; | 161 double timeToReverseEffectChange; |
162 } m_calculated; | 162 } m_calculated; |
163 mutable bool m_needsUpdate; | 163 mutable bool m_needsUpdate; |
164 mutable double m_lastUpdateTime; | 164 mutable double m_lastUpdateTime; |
165 | 165 |
166 const CalculatedTiming& ensureCalculated() const; | 166 const CalculatedTiming& ensureCalculated() const; |
167 }; | 167 }; |
168 | 168 |
169 } // namespace WebCore | 169 } // namespace WebCore |
170 | 170 |
171 #endif | 171 #endif |
OLD | NEW |