| 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 16 matching lines...) Expand all Loading... |
| 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 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/animation/TimedItem.h" | 32 #include "core/animation/TimedItem.h" |
| 33 #include "core/animation/TimedItemCalculations.h" | 33 #include "core/animation/TimedItemCalculations.h" |
| 34 | 34 |
| 35 namespace WebCore { | 35 namespace WebCore { |
| 36 | 36 |
| 37 TimedItem::TimedItem(const Timing& timing, PassOwnPtr<TimedItemEventDelegate> ev
entDelegate) | 37 TimedItem::TimedItem(const Timing& timing, PassOwnPtr<EventDelegate> eventDelega
te) |
| 38 : m_parent(0) | 38 : m_parent(0) |
| 39 , m_player(0) | 39 , m_player(0) |
| 40 , m_startTime(0) | 40 , m_startTime(0) |
| 41 , m_specified(timing) | 41 , m_specified(timing) |
| 42 , m_calculated() | 42 , m_calculated() |
| 43 , m_eventDelegate(eventDelegate) | 43 , m_eventDelegate(eventDelegate) |
| 44 , m_isFirstSample(true) |
| 44 { | 45 { |
| 45 timing.assertValid(); | 46 timing.assertValid(); |
| 46 } | 47 } |
| 47 | 48 |
| 48 void TimedItem::updateInheritedTime(double inheritedTime) const | 49 void TimedItem::updateInheritedTime(double inheritedTime) const |
| 49 { | 50 { |
| 50 const double localTime = inheritedTime - m_startTime; | 51 const double localTime = inheritedTime - m_startTime; |
| 51 const double iterationDuration = m_specified.hasIterationDuration | 52 const double iterationDuration = m_specified.hasIterationDuration |
| 52 ? m_specified.iterationDuration | 53 ? m_specified.iterationDuration |
| 53 : intrinsicIterationDuration(); | 54 : intrinsicIterationDuration(); |
| 54 | 55 |
| 55 const double repeatedDuration = iterationDuration * m_specified.iterationCou
nt; | 56 const double repeatedDuration = iterationDuration * m_specified.iterationCou
nt; |
| 56 const double activeDuration = m_specified.playbackRate | 57 const double activeDuration = m_specified.playbackRate |
| 57 ? repeatedDuration / abs(m_specified.playbackRate) | 58 ? repeatedDuration / abs(m_specified.playbackRate) |
| 58 : std::numeric_limits<double>::infinity(); | 59 : std::numeric_limits<double>::infinity(); |
| 59 | 60 |
| 60 const TimedItem::Phase phase = calculatePhase(activeDuration, localTime, m_s
pecified); | 61 const Phase currentPhase = calculatePhase(activeDuration, localTime, m_speci
fied); |
| 61 // FIXME: parentPhase depends on groups being implemented. | 62 // FIXME: parentPhase depends on groups being implemented. |
| 62 const TimedItem::Phase parentPhase = TimedItem::PhaseActive; | 63 const TimedItem::Phase parentPhase = TimedItem::PhaseActive; |
| 63 const double activeTime = calculateActiveTime(activeDuration, localTime, par
entPhase, phase, m_specified); | 64 const double activeTime = calculateActiveTime(activeDuration, localTime, par
entPhase, currentPhase, m_specified); |
| 64 | 65 |
| 65 double currentIteration = nullValue(); | 66 double currentIteration = nullValue(); |
| 66 double timeFraction = nullValue(); | 67 double timeFraction = nullValue(); |
| 67 ASSERT(iterationDuration >= 0); | 68 ASSERT(iterationDuration >= 0); |
| 68 if (iterationDuration) { | 69 if (iterationDuration) { |
| 69 const double startOffset = m_specified.iterationStart * iterationDuratio
n; | 70 const double startOffset = m_specified.iterationStart * iterationDuratio
n; |
| 70 const double scaledActiveTime = calculateScaledActiveTime(activeDuration
, activeTime, startOffset, m_specified); | 71 const double scaledActiveTime = calculateScaledActiveTime(activeDuration
, activeTime, startOffset, m_specified); |
| 71 const double iterationTime = calculateIterationTime(iterationDuration, r
epeatedDuration, scaledActiveTime, startOffset, m_specified); | 72 const double iterationTime = calculateIterationTime(iterationDuration, r
epeatedDuration, scaledActiveTime, startOffset, m_specified); |
| 72 | 73 |
| 73 currentIteration = calculateCurrentIteration(iterationDuration, iteratio
nTime, scaledActiveTime, m_specified); | 74 currentIteration = calculateCurrentIteration(iterationDuration, iteratio
nTime, scaledActiveTime, m_specified); |
| 74 timeFraction = calculateTransformedTime(currentIteration, iterationDurat
ion, iterationTime, m_specified) / iterationDuration; | 75 timeFraction = calculateTransformedTime(currentIteration, iterationDurat
ion, iterationTime, m_specified) / iterationDuration; |
| 75 } else { | 76 } else { |
| 76 const double iterationDuration = 1; | 77 const double iterationDuration = 1; |
| 77 const double repeatedDuration = iterationDuration * m_specified.iteratio
nCount; | 78 const double repeatedDuration = iterationDuration * m_specified.iteratio
nCount; |
| 78 const double activeDuration = m_specified.playbackRate ? repeatedDuratio
n / abs(m_specified.playbackRate) : std::numeric_limits<double>::infinity(); | 79 const double activeDuration = m_specified.playbackRate ? repeatedDuratio
n / abs(m_specified.playbackRate) : std::numeric_limits<double>::infinity(); |
| 79 const double newLocalTime = localTime < m_specified.startDelay ? m_speci
fied.startDelay - 1 : activeDuration + m_specified.startDelay; | 80 const double newLocalTime = localTime < m_specified.startDelay ? m_speci
fied.startDelay - 1 : activeDuration + m_specified.startDelay; |
| 80 const TimedItem::Phase phase = calculatePhase(activeDuration, newLocalTi
me, m_specified); | 81 const TimedItem::Phase localPhase = calculatePhase(activeDuration, newLo
calTime, m_specified); |
| 81 const double activeTime = calculateActiveTime(activeDuration, newLocalTi
me, parentPhase, phase, m_specified); | 82 const double activeTime = calculateActiveTime(activeDuration, newLocalTi
me, parentPhase, localPhase, m_specified); |
| 82 const double startOffset = m_specified.iterationStart * iterationDuratio
n; | 83 const double startOffset = m_specified.iterationStart * iterationDuratio
n; |
| 83 const double scaledActiveTime = calculateScaledActiveTime(activeDuration
, activeTime, startOffset, m_specified); | 84 const double scaledActiveTime = calculateScaledActiveTime(activeDuration
, activeTime, startOffset, m_specified); |
| 84 const double iterationTime = calculateIterationTime(iterationDuration, r
epeatedDuration, scaledActiveTime, startOffset, m_specified); | 85 const double iterationTime = calculateIterationTime(iterationDuration, r
epeatedDuration, scaledActiveTime, startOffset, m_specified); |
| 85 | 86 |
| 86 currentIteration = calculateCurrentIteration(iterationDuration, iteratio
nTime, scaledActiveTime, m_specified); | 87 currentIteration = calculateCurrentIteration(iterationDuration, iteratio
nTime, scaledActiveTime, m_specified); |
| 87 timeFraction = calculateTransformedTime(currentIteration, iterationDurat
ion, iterationTime, m_specified); | 88 timeFraction = calculateTransformedTime(currentIteration, iterationDurat
ion, iterationTime, m_specified); |
| 88 } | 89 } |
| 89 | 90 |
| 90 const double lastIteration = m_calculated.currentIteration; | 91 const double previousIteration = m_calculated.currentIteration; |
| 91 m_calculated.currentIteration = currentIteration; | 92 m_calculated.currentIteration = currentIteration; |
| 92 m_calculated.activeDuration = activeDuration; | 93 m_calculated.activeDuration = activeDuration; |
| 93 m_calculated.timeFraction = timeFraction; | 94 m_calculated.timeFraction = timeFraction; |
| 94 | 95 |
| 96 const Phase previousPhase = m_calculated.phase; |
| 95 const bool wasInEffect = m_calculated.isInEffect; | 97 const bool wasInEffect = m_calculated.isInEffect; |
| 96 const bool wasInPlay = m_calculated.isInPlay; | 98 m_calculated.phase = currentPhase; |
| 97 m_calculated.isInEffect = !isNull(activeTime); | 99 m_calculated.isInEffect = !isNull(activeTime); |
| 98 m_calculated.isInPlay = phase == PhaseActive && (!m_parent || m_parent->isIn
Play()); | 100 m_calculated.isInPlay = phase() == PhaseActive && (!m_parent || m_parent->is
InPlay()); |
| 99 m_calculated.isCurrent = phase == PhaseBefore || isInPlay() || (m_parent &&
m_parent->isCurrent()); | 101 m_calculated.isCurrent = phase() == PhaseBefore || isInPlay() || (m_parent &
& m_parent->isCurrent()); |
| 100 | 102 |
| 101 // This logic is specific to CSS events and assumes that all animations | 103 // This logic is specific to CSS animation events and assumes that all |
| 102 // start after the DocumentTimeline has started. | 104 // animations start after the DocumentTimeline has started. |
| 103 if (m_eventDelegate && (isInPlay() != wasInPlay || (isInPlay() && lastIterat
ion != currentIteration))) | 105 if (m_eventDelegate && (m_isFirstSample || previousPhase != phase() || (phas
e() == PhaseActive && previousIteration != currentIteration))) |
| 104 m_eventDelegate->onEventCondition(wasInPlay, isInPlay(), lastIteration,
currentIteration); | 106 m_eventDelegate->onEventCondition(m_isFirstSample, previousPhase, phase(
), previousIteration, currentIteration); |
| 107 m_isFirstSample = false; |
| 105 | 108 |
| 106 // FIXME: This probably shouldn't be recursive. | 109 // FIXME: This probably shouldn't be recursive. |
| 107 updateChildrenAndEffects(wasInEffect); | 110 updateChildrenAndEffects(wasInEffect); |
| 108 } | 111 } |
| 109 | 112 |
| 110 TimedItem::CalculatedTiming::CalculatedTiming() | |
| 111 : activeDuration(nullValue()) | |
| 112 , currentIteration(nullValue()) | |
| 113 , timeFraction(nullValue()) | |
| 114 , isCurrent(false) | |
| 115 , isInEffect(false) | |
| 116 , isInPlay(false) | |
| 117 { | |
| 118 } | |
| 119 | |
| 120 } // namespace WebCore | 113 } // namespace WebCore |
| OLD | NEW |