Chromium Code Reviews| 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 previousPhase = m_calculated.phase; |
| 62 m_calculated.phase = calculatePhase(activeDuration, localTime, m_specified); | |
|
dstockwell
2013/08/21 06:18:02
Can you mirror the pattern of other calculated val
| |
| 61 // FIXME: parentPhase depends on groups being implemented. | 63 // FIXME: parentPhase depends on groups being implemented. |
| 62 const TimedItem::Phase parentPhase = TimedItem::PhaseActive; | 64 const TimedItem::Phase parentPhase = TimedItem::PhaseActive; |
| 63 const double activeTime = calculateActiveTime(activeDuration, localTime, par entPhase, phase, m_specified); | 65 const double activeTime = calculateActiveTime(activeDuration, localTime, par entPhase, phase(), m_specified); |
| 64 | 66 |
| 65 double currentIteration = nullValue(); | 67 double currentIteration = nullValue(); |
| 66 double timeFraction = nullValue(); | 68 double timeFraction = nullValue(); |
| 67 ASSERT(iterationDuration >= 0); | 69 ASSERT(iterationDuration >= 0); |
| 68 if (iterationDuration) { | 70 if (iterationDuration) { |
| 69 const double startOffset = m_specified.iterationStart * iterationDuratio n; | 71 const double startOffset = m_specified.iterationStart * iterationDuratio n; |
| 70 const double scaledActiveTime = calculateScaledActiveTime(activeDuration , activeTime, startOffset, m_specified); | 72 const double scaledActiveTime = calculateScaledActiveTime(activeDuration , activeTime, startOffset, m_specified); |
| 71 const double iterationTime = calculateIterationTime(iterationDuration, r epeatedDuration, scaledActiveTime, startOffset, m_specified); | 73 const double iterationTime = calculateIterationTime(iterationDuration, r epeatedDuration, scaledActiveTime, startOffset, m_specified); |
| 72 | 74 |
| 73 currentIteration = calculateCurrentIteration(iterationDuration, iteratio nTime, scaledActiveTime, m_specified); | 75 currentIteration = calculateCurrentIteration(iterationDuration, iteratio nTime, scaledActiveTime, m_specified); |
| 74 timeFraction = calculateTransformedTime(currentIteration, iterationDurat ion, iterationTime, m_specified) / iterationDuration; | 76 timeFraction = calculateTransformedTime(currentIteration, iterationDurat ion, iterationTime, m_specified) / iterationDuration; |
| 75 } else { | 77 } else { |
| 76 const double iterationDuration = 1; | 78 const double iterationDuration = 1; |
| 77 const double repeatedDuration = iterationDuration * m_specified.iteratio nCount; | 79 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(); | 80 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; | 81 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); | 82 const TimedItem::Phase localPhase = calculatePhase(activeDuration, newLo calTime, m_specified); |
| 81 const double activeTime = calculateActiveTime(activeDuration, newLocalTi me, parentPhase, phase, m_specified); | 83 const double activeTime = calculateActiveTime(activeDuration, newLocalTi me, parentPhase, localPhase, m_specified); |
| 82 const double startOffset = m_specified.iterationStart * iterationDuratio n; | 84 const double startOffset = m_specified.iterationStart * iterationDuratio n; |
| 83 const double scaledActiveTime = calculateScaledActiveTime(activeDuration , activeTime, startOffset, m_specified); | 85 const double scaledActiveTime = calculateScaledActiveTime(activeDuration , activeTime, startOffset, m_specified); |
| 84 const double iterationTime = calculateIterationTime(iterationDuration, r epeatedDuration, scaledActiveTime, startOffset, m_specified); | 86 const double iterationTime = calculateIterationTime(iterationDuration, r epeatedDuration, scaledActiveTime, startOffset, m_specified); |
| 85 | 87 |
| 86 currentIteration = calculateCurrentIteration(iterationDuration, iteratio nTime, scaledActiveTime, m_specified); | 88 currentIteration = calculateCurrentIteration(iterationDuration, iteratio nTime, scaledActiveTime, m_specified); |
| 87 timeFraction = calculateTransformedTime(currentIteration, iterationDurat ion, iterationTime, m_specified); | 89 timeFraction = calculateTransformedTime(currentIteration, iterationDurat ion, iterationTime, m_specified); |
| 88 } | 90 } |
| 89 | 91 |
| 90 const double lastIteration = m_calculated.currentIteration; | 92 const double previousIteration = m_calculated.currentIteration; |
| 91 m_calculated.currentIteration = currentIteration; | 93 m_calculated.currentIteration = currentIteration; |
| 92 m_calculated.activeDuration = activeDuration; | 94 m_calculated.activeDuration = activeDuration; |
| 93 m_calculated.timeFraction = timeFraction; | 95 m_calculated.timeFraction = timeFraction; |
| 94 | 96 |
| 95 const bool wasInEffect = m_calculated.isInEffect; | 97 const bool wasInEffect = m_calculated.isInEffect; |
| 96 const bool wasInPlay = m_calculated.isInPlay; | |
| 97 m_calculated.isInEffect = !isNull(activeTime); | 98 m_calculated.isInEffect = !isNull(activeTime); |
| 98 m_calculated.isInPlay = phase == PhaseActive && (!m_parent || m_parent->isIn Play()); | 99 m_calculated.isInPlay = phase() == PhaseActive && (!m_parent || m_parent->is InPlay()); |
| 99 m_calculated.isCurrent = phase == PhaseBefore || isInPlay() || (m_parent && m_parent->isCurrent()); | 100 m_calculated.isCurrent = phase() == PhaseBefore || isInPlay() || (m_parent & & m_parent->isCurrent()); |
| 100 | 101 |
| 101 // This logic is specific to CSS events and assumes that all animations | 102 // This logic is specific to CSS animation events and assumes that all |
| 102 // start after the DocumentTimeline has started. | 103 // animations start after the DocumentTimeline has started. |
| 103 if (m_eventDelegate && (isInPlay() != wasInPlay || (isInPlay() && lastIterat ion != currentIteration))) | 104 if (m_eventDelegate && (m_isFirstSample || previousPhase != phase() || (phas e() == PhaseActive && previousIteration != currentIteration))) |
| 104 m_eventDelegate->onEventCondition(wasInPlay, isInPlay(), lastIteration, currentIteration); | 105 m_eventDelegate->onEventCondition(m_isFirstSample, previousPhase, phase( ), previousIteration, currentIteration); |
| 106 m_isFirstSample = false; | |
| 105 | 107 |
| 106 // FIXME: This probably shouldn't be recursive. | 108 // FIXME: This probably shouldn't be recursive. |
| 107 updateChildrenAndEffects(wasInEffect); | 109 updateChildrenAndEffects(wasInEffect); |
| 108 } | 110 } |
| 109 | 111 |
| 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 | 112 } // namespace WebCore |
| OLD | NEW |