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 14 matching lines...) Expand all Loading... |
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 TimedItem_h |
32 #define TimedItem_h | 32 #define TimedItem_h |
33 | 33 |
34 #include "core/animation/Timing.h" | 34 #include "core/animation/Timing.h" |
| 35 #include "platform/heap/Handle.h" |
35 #include "wtf/OwnPtr.h" | 36 #include "wtf/OwnPtr.h" |
36 #include "wtf/PassOwnPtr.h" | 37 #include "wtf/PassOwnPtr.h" |
37 #include "wtf/RefCounted.h" | 38 #include "wtf/RefCounted.h" |
38 | 39 |
39 namespace WebCore { | 40 namespace WebCore { |
40 | 41 |
41 class AnimationPlayer; | 42 class AnimationPlayer; |
42 class TimedItem; | 43 class TimedItem; |
43 class TimedItemTiming; | 44 class TimedItemTiming; |
44 | 45 |
45 static inline bool isNull(double value) | 46 static inline bool isNull(double value) |
46 { | 47 { |
47 return std::isnan(value); | 48 return std::isnan(value); |
48 } | 49 } |
49 | 50 |
50 static inline double nullValue() | 51 static inline double nullValue() |
51 { | 52 { |
52 return std::numeric_limits<double>::quiet_NaN(); | 53 return std::numeric_limits<double>::quiet_NaN(); |
53 } | 54 } |
54 | 55 |
55 class TimedItem : public RefCounted<TimedItem> { | 56 class TimedItem : public RefCountedWillBeGarbageCollectedFinalized<TimedItem> { |
56 friend class AnimationPlayer; // Calls attach/detach, updateInheritedTime. | 57 friend class AnimationPlayer; // Calls attach/detach, updateInheritedTime. |
57 public: | 58 public: |
58 // Note that logic in CSSAnimations depends on the order of these values. | 59 // Note that logic in CSSAnimations depends on the order of these values. |
59 enum Phase { | 60 enum Phase { |
60 PhaseBefore, | 61 PhaseBefore, |
61 PhaseActive, | 62 PhaseActive, |
62 PhaseAfter, | 63 PhaseAfter, |
63 PhaseNone, | 64 PhaseNone, |
64 }; | 65 }; |
65 | 66 |
(...skipping 18 matching lines...) Expand all Loading... |
84 double duration() const { return iterationDuration(); } | 85 double duration() const { return iterationDuration(); } |
85 double activeDuration() const; | 86 double activeDuration() const; |
86 double timeFraction() const { return ensureCalculated().timeFraction; } | 87 double timeFraction() const { return ensureCalculated().timeFraction; } |
87 double startTime() const { return m_startTime; } | 88 double startTime() const { return m_startTime; } |
88 double endTime() const { return startTime() + specifiedTiming().startDelay +
activeDuration() + specifiedTiming().endDelay; } | 89 double endTime() const { return startTime() + specifiedTiming().startDelay +
activeDuration() + specifiedTiming().endDelay; } |
89 | 90 |
90 const AnimationPlayer* player() const { return m_player; } | 91 const AnimationPlayer* player() const { return m_player; } |
91 AnimationPlayer* player() { return m_player; } | 92 AnimationPlayer* player() { return m_player; } |
92 AnimationPlayer* player(bool& isNull) { isNull = !m_player; return m_player;
} | 93 AnimationPlayer* player(bool& isNull) { isNull = !m_player; return m_player;
} |
93 const Timing& specifiedTiming() const { return m_specified; } | 94 const Timing& specifiedTiming() const { return m_specified; } |
94 PassRefPtr<TimedItemTiming> specified(); | 95 PassRefPtrWillBeRawPtr<TimedItemTiming> specified(); |
95 void updateSpecifiedTiming(const Timing&); | 96 void updateSpecifiedTiming(const Timing&); |
96 | 97 |
97 double localTime(bool& isNull) const { isNull = !m_player; return ensureCalc
ulated().localTime; } | 98 double localTime(bool& isNull) const { isNull = !m_player; return ensureCalc
ulated().localTime; } |
98 double currentIteration(bool& isNull) const { isNull = !ensureCalculated().i
sInEffect; return ensureCalculated().currentIteration; } | 99 double currentIteration(bool& isNull) const { isNull = !ensureCalculated().i
sInEffect; return ensureCalculated().currentIteration; } |
99 | 100 |
| 101 virtual void trace(Visitor*); |
| 102 |
100 protected: | 103 protected: |
101 TimedItem(const Timing&, PassOwnPtr<EventDelegate> = nullptr); | 104 explicit TimedItem(const Timing&, PassOwnPtr<EventDelegate> = nullptr); |
102 | 105 |
103 // When TimedItem receives a new inherited time via updateInheritedTime | 106 // When TimedItem receives a new inherited time via updateInheritedTime |
104 // it will (if necessary) recalculate timings and (if necessary) call | 107 // it will (if necessary) recalculate timings and (if necessary) call |
105 // updateChildrenAndEffects. | 108 // updateChildrenAndEffects. |
106 void updateInheritedTime(double inheritedTime) const; | 109 void updateInheritedTime(double inheritedTime) const; |
107 void invalidate() const { m_needsUpdate = true; }; | 110 void invalidate() const { m_needsUpdate = true; }; |
108 bool hasEvents() const { return m_eventDelegate; } | 111 bool hasEvents() const { return m_eventDelegate; } |
109 | 112 |
| 113 virtual void attach(AnimationPlayer* player) |
| 114 { |
| 115 m_player = player; |
| 116 } |
| 117 |
| 118 virtual void detach() |
| 119 { |
| 120 ASSERT(m_player); |
| 121 m_player = nullptr; |
| 122 } |
| 123 |
110 private: | 124 private: |
111 | |
112 double iterationDuration() const; | 125 double iterationDuration() const; |
113 double repeatedDuration() const; | 126 double repeatedDuration() const; |
114 | 127 |
115 virtual void updateChildrenAndEffects() const = 0; | 128 virtual void updateChildrenAndEffects() const = 0; |
116 virtual double intrinsicIterationDuration() const { return 0; }; | 129 virtual double intrinsicIterationDuration() const { return 0; }; |
117 virtual double calculateTimeToEffectChange(bool forwards, double localTime,
double timeToNextIteration) const = 0; | 130 virtual double calculateTimeToEffectChange(bool forwards, double localTime,
double timeToNextIteration) const = 0; |
118 virtual void didAttach() { }; | 131 virtual void specifiedTimingChanged() { } |
119 virtual void willDetach() { }; | |
120 virtual void specifiedTimingChanged() { }; | |
121 | |
122 void attach(AnimationPlayer* player) | |
123 { | |
124 m_player = player; | |
125 didAttach(); | |
126 }; | |
127 | |
128 void detach() | |
129 { | |
130 ASSERT(m_player); | |
131 willDetach(); | |
132 m_player = 0; | |
133 }; | |
134 | 132 |
135 // FIXME: m_parent and m_startTime are placeholders, they depend on timing g
roups. | 133 // FIXME: m_parent and m_startTime are placeholders, they depend on timing g
roups. |
136 TimedItem* const m_parent; | 134 RawPtrWillBeMember<TimedItem> m_parent; |
137 const double m_startTime; | 135 const double m_startTime; |
138 AnimationPlayer* m_player; | 136 RawPtrWillBeMember<AnimationPlayer> m_player; |
139 Timing m_specified; | 137 Timing m_specified; |
140 OwnPtr<EventDelegate> m_eventDelegate; | 138 OwnPtr<EventDelegate> m_eventDelegate; |
141 | 139 |
142 mutable struct CalculatedTiming { | 140 mutable struct CalculatedTiming { |
143 Phase phase; | 141 Phase phase; |
144 double currentIteration; | 142 double currentIteration; |
145 double timeFraction; | 143 double timeFraction; |
146 bool isCurrent; | 144 bool isCurrent; |
147 bool isInEffect; | 145 bool isInEffect; |
148 bool isInPlay; | 146 bool isInPlay; |
149 double localTime; | 147 double localTime; |
150 double timeToForwardsEffectChange; | 148 double timeToForwardsEffectChange; |
151 double timeToReverseEffectChange; | 149 double timeToReverseEffectChange; |
152 } m_calculated; | 150 } m_calculated; |
153 mutable bool m_isFirstSample; | 151 mutable bool m_isFirstSample; |
154 mutable bool m_needsUpdate; | 152 mutable bool m_needsUpdate; |
155 mutable double m_lastUpdateTime; | 153 mutable double m_lastUpdateTime; |
156 | 154 |
157 const CalculatedTiming& ensureCalculated() const; | 155 const CalculatedTiming& ensureCalculated() const; |
158 }; | 156 }; |
159 | 157 |
160 } // namespace WebCore | 158 } // namespace WebCore |
161 | 159 |
162 #endif | 160 #endif |
OLD | NEW |