| 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 18 matching lines...) Expand all Loading... |
| 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 "wtf/RefCounted.h" | 35 #include "wtf/RefCounted.h" |
| 36 | 36 |
| 37 namespace WebCore { | 37 namespace WebCore { |
| 38 | 38 |
| 39 class Player; |
| 40 |
| 39 static inline bool isNull(double value) | 41 static inline bool isNull(double value) |
| 40 { | 42 { |
| 41 return std::isnan(value); | 43 return std::isnan(value); |
| 42 } | 44 } |
| 43 | 45 |
| 44 static inline double nullValue() | 46 static inline double nullValue() |
| 45 { | 47 { |
| 46 return std::numeric_limits<double>::quiet_NaN(); | 48 return std::numeric_limits<double>::quiet_NaN(); |
| 47 } | 49 } |
| 48 | 50 |
| 49 class TimedItem : public RefCounted<TimedItem> { | 51 class TimedItem : public RefCounted<TimedItem> { |
| 52 friend class Player; // Calls attach/detach, updateInheritedTime. |
| 50 public: | 53 public: |
| 51 virtual ~TimedItem() { } | 54 virtual ~TimedItem() { } |
| 52 | 55 |
| 53 bool isScheduled() const { return ensureCalculated().isScheduled; } | 56 bool isScheduled() const { return ensureCalculated().isScheduled; } |
| 54 bool isActive() const { return ensureCalculated().isActive; } | 57 bool isActive() const { return ensureCalculated().isActive; } |
| 55 bool isCurrent() const { return ensureCalculated().isCurrent; } | 58 bool isCurrent() const { return ensureCalculated().isCurrent; } |
| 56 bool isInEffect() const { return ensureCalculated().isInEffect; } | 59 bool isInEffect() const { return ensureCalculated().isInEffect; } |
| 57 | 60 |
| 58 double startTime() const { return m_startTime; } | 61 double startTime() const { return m_startTime; } |
| 59 | 62 |
| 60 double currentIteration() const { return ensureCalculated().currentIteration
; } | 63 double currentIteration() const { return ensureCalculated().currentIteration
; } |
| 61 double activeDuration() const { return ensureCalculated().activeDuration; } | 64 double activeDuration() const { return ensureCalculated().activeDuration; } |
| 62 double timeFraction() const { return ensureCalculated().timeFraction; } | 65 double timeFraction() const { return ensureCalculated().timeFraction; } |
| 66 Player* player() const { return m_player; } |
| 63 | 67 |
| 64 protected: | 68 protected: |
| 65 TimedItem(const Timing&); | 69 TimedItem(const Timing&); |
| 66 | 70 |
| 67 // When TimedItem receives a new inherited time via updateInheritedTime | 71 // When TimedItem receives a new inherited time via updateInheritedTime |
| 68 // it will (if necessary) recalculate timings and (if necessary) call | 72 // it will (if necessary) recalculate timings and (if necessary) call |
| 69 // updateChildrenAndEffects. | 73 // updateChildrenAndEffects. |
| 70 void updateInheritedTime(double inheritedTime) const; | 74 void updateInheritedTime(double inheritedTime) const; |
| 71 virtual void updateChildrenAndEffects(bool wasActiveOrInEffect) const = 0; | 75 virtual void updateChildrenAndEffects(bool wasActiveOrInEffect) const = 0; |
| 72 virtual double intrinsicIterationDuration() const { return 0; }; | 76 virtual double intrinsicIterationDuration() const { return 0; }; |
| 73 | 77 virtual void willDetach() = 0; |
| 74 friend class Player; // Calls updateInheritedTime. | |
| 75 | 78 |
| 76 private: | 79 private: |
| 80 void attach(Player* player) { m_player = player; }; |
| 81 void detach() |
| 82 { |
| 83 ASSERT(m_player); |
| 84 willDetach(); |
| 85 m_player = 0; |
| 86 }; |
| 87 |
| 77 // FIXME: m_parent and m_startTime are placeholders, they depend on timing g
roups. | 88 // FIXME: m_parent and m_startTime are placeholders, they depend on timing g
roups. |
| 78 TimedItem* const m_parent; | 89 TimedItem* const m_parent; |
| 79 const double m_startTime; | 90 const double m_startTime; |
| 80 | 91 Player* m_player; |
| 81 Timing m_specified; | 92 Timing m_specified; |
| 82 | 93 |
| 83 // FIXME: Should be versioned by monotonic value on player. | 94 // FIXME: Should be versioned by monotonic value on player. |
| 84 mutable struct CalculatedTiming { | 95 mutable struct CalculatedTiming { |
| 85 CalculatedTiming(); | 96 CalculatedTiming(); |
| 86 double activeDuration; | 97 double activeDuration; |
| 87 double currentIteration; | 98 double currentIteration; |
| 88 double timeFraction; | 99 double timeFraction; |
| 89 bool isScheduled; | 100 bool isScheduled; |
| 90 bool isActive; | 101 bool isActive; |
| 91 bool isCurrent; | 102 bool isCurrent; |
| 92 bool isInEffect; | 103 bool isInEffect; |
| 93 } m_calculated; | 104 } m_calculated; |
| 94 | 105 |
| 95 // FIXME: Should check the version and reinherit time if inconsistent. | 106 // FIXME: Should check the version and reinherit time if inconsistent. |
| 96 const CalculatedTiming& ensureCalculated() const { return m_calculated; } | 107 const CalculatedTiming& ensureCalculated() const { return m_calculated; } |
| 97 }; | 108 }; |
| 98 | 109 |
| 99 } // namespace WebCore | 110 } // namespace WebCore |
| 100 | 111 |
| 101 #endif | 112 #endif |
| OLD | NEW |