| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 static inline bool isNull(double value) | 42 static inline bool isNull(double value) |
| 43 { | 43 { |
| 44 return std::isnan(value); | 44 return std::isnan(value); |
| 45 } | 45 } |
| 46 | 46 |
| 47 static inline double nullValue() | 47 static inline double nullValue() |
| 48 { | 48 { |
| 49 return std::numeric_limits<double>::quiet_NaN(); | 49 return std::numeric_limits<double>::quiet_NaN(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 class TimedItemEventDelegate { | |
| 53 public: | |
| 54 virtual ~TimedItemEventDelegate() { }; | |
| 55 virtual void onEventCondition(bool wasInPlay, bool isInPlay, double previous
Iteration, double currentIteration) = 0; | |
| 56 }; | |
| 57 | |
| 58 class TimedItem : public RefCounted<TimedItem> { | 52 class TimedItem : public RefCounted<TimedItem> { |
| 59 friend class Player; // Calls attach/detach, updateInheritedTime. | 53 friend class Player; // Calls attach/detach, updateInheritedTime. |
| 60 public: | 54 public: |
| 55 // Note that logic in CSSAnimations depends on the order of these values. |
| 56 enum Phase { |
| 57 PhaseBefore, |
| 58 PhaseActive, |
| 59 PhaseAfter, |
| 60 PhaseNone, |
| 61 }; |
| 62 |
| 63 class EventDelegate { |
| 64 public: |
| 65 virtual ~EventDelegate() { }; |
| 66 virtual void onEventCondition(bool isFirstSample, Phase previousPhase, P
hase currentPhase, double previousIteration, double currentIteration) = 0; |
| 67 }; |
| 68 |
| 61 virtual ~TimedItem() { } | 69 virtual ~TimedItem() { } |
| 62 | 70 |
| 71 Phase phase() const { return ensureCalculated().phase; } |
| 63 bool isCurrent() const { return ensureCalculated().isCurrent; } | 72 bool isCurrent() const { return ensureCalculated().isCurrent; } |
| 64 bool isInEffect() const { return ensureCalculated().isInEffect; } | 73 bool isInEffect() const { return ensureCalculated().isInEffect; } |
| 65 bool isInPlay() const { return ensureCalculated().isInPlay; } | 74 bool isInPlay() const { return ensureCalculated().isInPlay; } |
| 66 | 75 |
| 67 double startTime() const { return m_startTime; } | 76 double startTime() const { return m_startTime; } |
| 68 | 77 |
| 69 double currentIteration() const { return ensureCalculated().currentIteration
; } | 78 double currentIteration() const { return ensureCalculated().currentIteration
; } |
| 70 double activeDuration() const { return ensureCalculated().activeDuration; } | 79 double activeDuration() const { return ensureCalculated().activeDuration; } |
| 71 double timeFraction() const { return ensureCalculated().timeFraction; } | 80 double timeFraction() const { return ensureCalculated().timeFraction; } |
| 72 Player* player() const { return m_player; } | 81 Player* player() const { return m_player; } |
| 73 | 82 |
| 74 enum Phase { | |
| 75 PhaseBefore, | |
| 76 PhaseActive, | |
| 77 PhaseAfter, | |
| 78 PhaseNone, | |
| 79 }; | |
| 80 | |
| 81 protected: | 83 protected: |
| 82 TimedItem(const Timing&, PassOwnPtr<TimedItemEventDelegate> = nullptr); | 84 TimedItem(const Timing&, PassOwnPtr<EventDelegate> = nullptr); |
| 83 | 85 |
| 84 // When TimedItem receives a new inherited time via updateInheritedTime | 86 // When TimedItem receives a new inherited time via updateInheritedTime |
| 85 // it will (if necessary) recalculate timings and (if necessary) call | 87 // it will (if necessary) recalculate timings and (if necessary) call |
| 86 // updateChildrenAndEffects. | 88 // updateChildrenAndEffects. |
| 87 void updateInheritedTime(double inheritedTime) const; | 89 void updateInheritedTime(double inheritedTime) const; |
| 88 virtual void updateChildrenAndEffects(bool wasInEffect) const = 0; | 90 virtual void updateChildrenAndEffects(bool wasInEffect) const = 0; |
| 89 virtual double intrinsicIterationDuration() const { return 0; }; | 91 virtual double intrinsicIterationDuration() const { return 0; }; |
| 90 virtual void willDetach() = 0; | 92 virtual void willDetach() = 0; |
| 91 | 93 |
| 92 private: | 94 private: |
| 93 void attach(Player* player) { m_player = player; }; | 95 void attach(Player* player) { m_player = player; }; |
| 94 void detach() | 96 void detach() |
| 95 { | 97 { |
| 96 ASSERT(m_player); | 98 ASSERT(m_player); |
| 97 willDetach(); | 99 willDetach(); |
| 98 m_player = 0; | 100 m_player = 0; |
| 99 }; | 101 }; |
| 100 | 102 |
| 101 // FIXME: m_parent and m_startTime are placeholders, they depend on timing g
roups. | 103 // FIXME: m_parent and m_startTime are placeholders, they depend on timing g
roups. |
| 102 TimedItem* const m_parent; | 104 TimedItem* const m_parent; |
| 103 const double m_startTime; | 105 const double m_startTime; |
| 104 Player* m_player; | 106 Player* m_player; |
| 105 Timing m_specified; | 107 Timing m_specified; |
| 106 OwnPtr<TimedItemEventDelegate> m_eventDelegate; | 108 OwnPtr<EventDelegate> m_eventDelegate; |
| 107 | 109 |
| 108 // FIXME: Should be versioned by monotonic value on player. | 110 // FIXME: Should be versioned by monotonic value on player. |
| 109 mutable struct CalculatedTiming { | 111 mutable struct CalculatedTiming { |
| 110 CalculatedTiming(); | |
| 111 double activeDuration; | 112 double activeDuration; |
| 113 Phase phase; |
| 112 double currentIteration; | 114 double currentIteration; |
| 113 double timeFraction; | 115 double timeFraction; |
| 114 bool isCurrent; | 116 bool isCurrent; |
| 115 bool isInEffect; | 117 bool isInEffect; |
| 116 bool isInPlay; | 118 bool isInPlay; |
| 117 } m_calculated; | 119 } m_calculated; |
| 120 mutable bool m_isFirstSample; |
| 118 | 121 |
| 119 // FIXME: Should check the version and reinherit time if inconsistent. | 122 // FIXME: Should check the version and reinherit time if inconsistent. |
| 120 const CalculatedTiming& ensureCalculated() const { return m_calculated; } | 123 const CalculatedTiming& ensureCalculated() const { return m_calculated; } |
| 121 }; | 124 }; |
| 122 | 125 |
| 123 } // namespace WebCore | 126 } // namespace WebCore |
| 124 | 127 |
| 125 #endif | 128 #endif |
| OLD | NEW |