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 25 matching lines...) Expand all Loading... | |
91 double timeFraction() const { return ensureCalculated().timeFraction; } | 92 double timeFraction() const { return ensureCalculated().timeFraction; } |
92 double startTime() const { return m_startTime * 1000; } | 93 double startTime() const { return m_startTime * 1000; } |
93 double startTimeInternal() const { return m_startTime; } | 94 double startTimeInternal() const { return m_startTime; } |
94 double endTime() const { return endTimeInternal() * 1000; } | 95 double endTime() const { return endTimeInternal() * 1000; } |
95 double endTimeInternal() const { return startTime() + specifiedTiming().star tDelay + activeDurationInternal() + specifiedTiming().endDelay; } | 96 double endTimeInternal() const { return startTime() + specifiedTiming().star tDelay + activeDurationInternal() + specifiedTiming().endDelay; } |
96 | 97 |
97 const AnimationPlayer* player() const { return m_player; } | 98 const AnimationPlayer* player() const { return m_player; } |
98 AnimationPlayer* player() { return m_player; } | 99 AnimationPlayer* player() { return m_player; } |
99 AnimationPlayer* player(bool& isNull) { isNull = !m_player; return m_player; } | 100 AnimationPlayer* player(bool& isNull) { isNull = !m_player; return m_player; } |
100 const Timing& specifiedTiming() const { return m_timing; } | 101 const Timing& specifiedTiming() const { return m_timing; } |
101 PassRefPtr<TimedItemTiming> timing(); | 102 PassRefPtrWillBeRawPtr<TimedItemTiming> timing(); |
102 void updateSpecifiedTiming(const Timing&); | 103 void updateSpecifiedTiming(const Timing&); |
103 | 104 |
104 // This method returns time in ms as it is unused except via the API. | 105 // This method returns time in ms as it is unused except via the API. |
105 double localTime(bool& isNull) const { isNull = !m_player; return ensureCalc ulated().localTime * 1000; } | 106 double localTime(bool& isNull) const { isNull = !m_player; return ensureCalc ulated().localTime * 1000; } |
106 double currentIteration(bool& isNull) const { isNull = !ensureCalculated().i sInEffect; return ensureCalculated().currentIteration; } | 107 double currentIteration(bool& isNull) const { isNull = !ensureCalculated().i sInEffect; return ensureCalculated().currentIteration; } |
107 | 108 |
109 virtual void trace(Visitor*); | |
110 void processWeakMembers(Visitor*); | |
111 | |
108 protected: | 112 protected: |
109 TimedItem(const Timing&, PassOwnPtr<EventDelegate> = nullptr); | 113 explicit TimedItem(const Timing&, PassOwnPtr<EventDelegate> = nullptr); |
110 | 114 |
111 // When TimedItem receives a new inherited time via updateInheritedTime | 115 // When TimedItem receives a new inherited time via updateInheritedTime |
112 // it will (if necessary) recalculate timings and (if necessary) call | 116 // it will (if necessary) recalculate timings and (if necessary) call |
113 // updateChildrenAndEffects. | 117 // updateChildrenAndEffects. |
114 void updateInheritedTime(double inheritedTime) const; | 118 void updateInheritedTime(double inheritedTime) const; |
115 void invalidate() const { m_needsUpdate = true; }; | 119 void invalidate() const { m_needsUpdate = true; }; |
116 bool hasEvents() const { return m_eventDelegate; } | 120 bool hasEvents() const { return m_eventDelegate; } |
117 void clearEventDelegate() { m_eventDelegate = nullptr; } | 121 void clearEventDelegate() { m_eventDelegate = nullptr; } |
118 | 122 |
119 private: | 123 virtual void attach(AnimationPlayer* player) |
124 { | |
125 m_player = player; | |
126 } | |
127 | |
128 virtual void detach() | |
129 { | |
130 ASSERT(m_player); | |
131 m_player = nullptr; | |
132 } | |
120 | 133 |
121 double repeatedDuration() const; | 134 double repeatedDuration() const; |
122 | 135 |
123 virtual void updateChildrenAndEffects() const = 0; | 136 virtual void updateChildrenAndEffects() const = 0; |
124 virtual double intrinsicIterationDuration() const { return 0; }; | 137 virtual double intrinsicIterationDuration() const { return 0; }; |
125 virtual double calculateTimeToEffectChange(bool forwards, double localTime, double timeToNextIteration) const = 0; | 138 virtual double calculateTimeToEffectChange(bool forwards, double localTime, double timeToNextIteration) const = 0; |
126 virtual void didAttach() { }; | 139 virtual void specifiedTimingChanged() { } |
127 virtual void willDetach() { }; | |
128 virtual void specifiedTimingChanged() { }; | |
129 | |
130 void attach(AnimationPlayer* player) | |
131 { | |
132 m_player = player; | |
133 didAttach(); | |
134 }; | |
135 | |
136 void detach() | |
137 { | |
138 ASSERT(m_player); | |
139 willDetach(); | |
140 m_player = 0; | |
141 }; | |
142 | 140 |
143 // FIXME: m_parent and m_startTime are placeholders, they depend on timing g roups. | 141 // FIXME: m_parent and m_startTime are placeholders, they depend on timing g roups. |
144 TimedItem* const m_parent; | 142 RawPtrWillBeMember<TimedItem> m_parent; |
145 const double m_startTime; | 143 const double m_startTime; |
146 AnimationPlayer* m_player; | 144 RawPtrWillBeWeakMember<AnimationPlayer> m_player; |
haraken
2014/04/29 04:47:35
Actually I don't fully understand this pointer.
-
Mads Ager (chromium)
2014/04/29 10:29:41
I don't understand the lifetime of these objects w
dstockwell
2014/05/01 14:06:54
This is correct. We accept wrong behavior currentl
| |
147 Timing m_timing; | 145 Timing m_timing; |
148 OwnPtr<EventDelegate> m_eventDelegate; | 146 OwnPtr<EventDelegate> m_eventDelegate; |
149 | 147 |
150 mutable struct CalculatedTiming { | 148 mutable struct CalculatedTiming { |
151 Phase phase; | 149 Phase phase; |
152 double currentIteration; | 150 double currentIteration; |
153 double timeFraction; | 151 double timeFraction; |
154 bool isCurrent; | 152 bool isCurrent; |
155 bool isInEffect; | 153 bool isInEffect; |
156 bool isInPlay; | 154 bool isInPlay; |
157 double localTime; | 155 double localTime; |
158 double timeToForwardsEffectChange; | 156 double timeToForwardsEffectChange; |
159 double timeToReverseEffectChange; | 157 double timeToReverseEffectChange; |
160 } m_calculated; | 158 } m_calculated; |
161 mutable bool m_isFirstSample; | 159 mutable bool m_isFirstSample; |
162 mutable bool m_needsUpdate; | 160 mutable bool m_needsUpdate; |
163 mutable double m_lastUpdateTime; | 161 mutable double m_lastUpdateTime; |
164 | 162 |
165 const CalculatedTiming& ensureCalculated() const; | 163 const CalculatedTiming& ensureCalculated() const; |
166 }; | 164 }; |
167 | 165 |
168 } // namespace WebCore | 166 } // namespace WebCore |
169 | 167 |
170 #endif | 168 #endif |
OLD | NEW |