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 AnimationEffect_h | 31 #ifndef AnimationEffect_h |
32 #define AnimationEffect_h | 32 #define AnimationEffect_h |
33 | 33 |
34 #include "bindings/core/v8/ScriptWrappable.h" | 34 #include "bindings/core/v8/ScriptWrappable.h" |
35 #include "core/CSSPropertyNames.h" | |
36 #include "core/CoreExport.h" | 35 #include "core/CoreExport.h" |
37 #include "core/animation/PropertyHandle.h" | 36 #include "core/animation/Timing.h" |
38 #include "platform/heap/Handle.h" | 37 #include "platform/heap/Handle.h" |
39 #include "wtf/HashMap.h" | 38 #include "wtf/OwnPtr.h" |
40 #include "wtf/PassOwnPtr.h" | 39 #include "wtf/PassOwnPtr.h" |
41 #include "wtf/RefCounted.h" | 40 #include "wtf/RefCounted.h" |
42 | 41 |
43 namespace blink { | 42 namespace blink { |
44 | 43 |
45 class Interpolation; | 44 class Animation; |
| 45 class AnimationEffect; |
| 46 class AnimationEffectTiming; |
| 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 } |
46 | 63 |
47 class CORE_EXPORT AnimationEffect : public RefCountedWillBeGarbageCollectedFinal
ized<AnimationEffect>, public ScriptWrappable { | 64 class CORE_EXPORT AnimationEffect : public RefCountedWillBeGarbageCollectedFinal
ized<AnimationEffect>, public ScriptWrappable { |
48 DEFINE_WRAPPERTYPEINFO(); | 65 DEFINE_WRAPPERTYPEINFO(); |
| 66 friend class Animation; // Calls attach/detach, updateInheritedTime. |
49 public: | 67 public: |
50 enum CompositeOperation { | 68 // Note that logic in CSSAnimations depends on the order of these values. |
51 CompositeReplace, | 69 enum Phase { |
52 CompositeAdd, | 70 PhaseBefore, |
| 71 PhaseActive, |
| 72 PhaseAfter, |
| 73 PhaseNone, |
53 }; | 74 }; |
54 | 75 |
55 AnimationEffect() { } | 76 class EventDelegate : public NoBaseWillBeGarbageCollectedFinalized<EventDele
gate> { |
| 77 public: |
| 78 virtual ~EventDelegate() { } |
| 79 virtual bool requiresIterationEvents(const AnimationEffect&) = 0; |
| 80 virtual void onEventCondition(const AnimationEffect&) = 0; |
| 81 DEFINE_INLINE_VIRTUAL_TRACE() { } |
| 82 }; |
| 83 |
56 virtual ~AnimationEffect() { } | 84 virtual ~AnimationEffect() { } |
57 virtual void sample(int iteration, double fraction, double iterationDuration
, OwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpolation>>>&) cons
t = 0; | |
58 | 85 |
59 virtual bool affects(PropertyHandle) const { return false; }; | 86 virtual bool isAnimation() const { return false; } |
60 virtual bool isKeyframeEffectModel() const { return false; } | |
61 | 87 |
62 DEFINE_INLINE_VIRTUAL_TRACE() { } | 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 Animation* animation() const { return m_animation; } |
| 103 Animation* animation() { return m_animation; } |
| 104 const Timing& specifiedTiming() const { return m_timing; } |
| 105 PassRefPtrWillBeRawPtr<AnimationEffectTiming> 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 AnimationEffect(const Timing&, PassOwnPtrWillBeRawPtr<EventDelegate
> = nullptr); |
| 118 |
| 119 // When AnimationEffect receives a new inherited time via updateInheritedTim
e |
| 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(Animation* animation) |
| 128 { |
| 129 m_animation = animation; |
| 130 } |
| 131 |
| 132 virtual void detach() |
| 133 { |
| 134 ASSERT(m_animation); |
| 135 m_animation = 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<AnimationEffect> m_parent; |
| 147 const double m_startTime; |
| 148 RawPtrWillBeMember<Animation> m_animation; |
| 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; |
63 }; | 168 }; |
64 | 169 |
65 } // namespace blink | 170 } // namespace blink |
66 | 171 |
67 #endif // AnimationEffect_h | 172 #endif // AnimationEffect_h |
OLD | NEW |