2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
34 #include "core/animation/Timing.h"
35 #include "wtf/OwnPtr.h"
36 #include "wtf/PassOwnPtr.h"
37 #include "wtf/RefCounted.h"
44 static inline bool isNull(double value)
46 return std::isnan(value);
49 static inline double nullValue()
51 return std::numeric_limits<double>::quiet_NaN();
54 class TimedItem : public RefCounted<TimedItem> {
55 friend class Player; // Calls attach/detach, updateInheritedTime.
57 // Note that logic in CSSAnimations depends on the order of these values.
67 virtual ~EventDelegate() { };
68 virtual void onEventCondition(const TimedItem*, bool isFirstSample, Phase previousPhase, double previousIteration) = 0;
71 virtual ~TimedItem() { }
73 virtual bool isAnimation() const { return false; }
75 Phase phase() const { return ensureCalculated().phase; }
76 bool isCurrent() const { return ensureCalculated().isCurrent; }
77 bool isInEffect() const { return ensureCalculated().isInEffect; }
78 bool isInPlay() const { return ensureCalculated().isInPlay; }
79 double timeToEffectChange() const { return ensureCalculated().timeToEffectChange; }
81 double currentIteration() const { return ensureCalculated().currentIteration; }
82 double activeDuration() const;
83 double timeFraction() const { return ensureCalculated().timeFraction; }
84 double startTime() const { return m_startTime; }
85 double endTime() const { return startTime() + specified().startDelay + activeDuration(); }
87 const Player* player() const { return m_player; }
88 Player* player() { return m_player; }
89 Player* player(bool& isNull) { isNull = !m_player; return m_player; }
90 const Timing& specified() const { return m_specified; }
93 TimedItem(const Timing&, PassOwnPtr<EventDelegate> = nullptr);
95 // When TimedItem receives a new inherited time via updateInheritedTime
96 // it will (if necessary) recalculate timings and (if necessary) call
97 // updateChildrenAndEffects.
98 // Returns whether style recalc was triggered.
99 bool updateInheritedTime(double inheritedTime) const;
100 void invalidate() const { m_needsUpdate = true; };
103 double iterationDuration() const;
104 double repeatedDuration() const;
106 // Returns whether style recalc was triggered.
107 virtual bool updateChildrenAndEffects() const = 0;
108 virtual double intrinsicIterationDuration() const { return 0; };
109 virtual double calculateTimeToEffectChange(double localTime, double timeToNextIteration) const = 0;
110 virtual void didAttach() { };
111 virtual void willDetach() { };
113 void attach(Player* player)
126 // FIXME: m_parent and m_startTime are placeholders, they depend on timing groups.
127 TimedItem* const m_parent;
128 const double m_startTime;
131 OwnPtr<EventDelegate> m_eventDelegate;
133 // FIXME: Should be versioned by monotonic value on player.
134 mutable struct CalculatedTiming {
136 double currentIteration;
141 double timeToEffectChange;
143 mutable bool m_isFirstSample;
144 mutable bool m_needsUpdate;
145 mutable double m_lastUpdateTime;
147 // FIXME: Should check the version and reinherit time if inconsistent.
148 const CalculatedTiming& ensureCalculated() const { return m_calculated; }
151 } // namespace WebCore