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