This source file includes following definitions.
- resolvedFillMode
- m_lastUpdateTime
- iterationDuration
- repeatedDuration
- activeDuration
- updateSpecifiedTiming
- updateInheritedTime
- ensureCalculated
- specified
#include "config.h"
#include "core/animation/TimedItem.h"
#include "core/animation/AnimationPlayer.h"
#include "core/animation/TimedItemCalculations.h"
#include "core/animation/TimedItemTiming.h"
namespace WebCore {
namespace {
Timing::FillMode resolvedFillMode(Timing::FillMode fillMode, bool isAnimation)
{
if (fillMode != Timing::FillModeAuto)
return fillMode;
if (isAnimation)
return Timing::FillModeNone;
return Timing::FillModeBoth;
}
}
TimedItem::TimedItem(const Timing& timing, PassOwnPtr<EventDelegate> eventDelegate)
: m_parent(0)
, m_startTime(0)
, m_player(0)
, m_specified(timing)
, m_eventDelegate(eventDelegate)
, m_calculated()
, m_isFirstSample(true)
, m_needsUpdate(true)
, m_lastUpdateTime(nullValue())
{
m_specified.assertValid();
}
double TimedItem::iterationDuration() const
{
double result = std::isnan(m_specified.iterationDuration) ? intrinsicIterationDuration() : m_specified.iterationDuration;
ASSERT(result >= 0);
return result;
}
double TimedItem::repeatedDuration() const
{
const double result = multiplyZeroAlwaysGivesZero(iterationDuration(), m_specified.iterationCount);
ASSERT(result >= 0);
return result;
}
double TimedItem::activeDuration() const
{
const double result = m_specified.playbackRate
? repeatedDuration() / std::abs(m_specified.playbackRate)
: std::numeric_limits<double>::infinity();
ASSERT(result >= 0);
return result;
}
void TimedItem::updateSpecifiedTiming(const Timing& timing)
{
m_specified = timing;
invalidate();
if (m_player)
m_player->setOutdated();
}
void TimedItem::updateInheritedTime(double inheritedTime) const
{
bool needsUpdate = m_needsUpdate || (m_lastUpdateTime != inheritedTime && !(isNull(m_lastUpdateTime) && isNull(inheritedTime)));
m_needsUpdate = false;
m_lastUpdateTime = inheritedTime;
const double previousIteration = m_calculated.currentIteration;
const Phase previousPhase = m_calculated.phase;
const double localTime = inheritedTime - m_startTime;
double timeToNextIteration = std::numeric_limits<double>::infinity();
if (needsUpdate) {
const double activeDuration = this->activeDuration();
const Phase currentPhase = calculatePhase(activeDuration, localTime, m_specified);
const TimedItem::Phase parentPhase = TimedItem::PhaseActive;
const double activeTime = calculateActiveTime(activeDuration, resolvedFillMode(m_specified.fillMode, isAnimation()), localTime, parentPhase, currentPhase, m_specified);
double currentIteration;
double timeFraction;
if (const double iterationDuration = this->iterationDuration()) {
const double startOffset = multiplyZeroAlwaysGivesZero(m_specified.iterationStart, iterationDuration);
ASSERT(startOffset >= 0);
const double scaledActiveTime = calculateScaledActiveTime(activeDuration, activeTime, startOffset, m_specified);
const double iterationTime = calculateIterationTime(iterationDuration, repeatedDuration(), scaledActiveTime, startOffset, m_specified);
currentIteration = calculateCurrentIteration(iterationDuration, iterationTime, scaledActiveTime, m_specified);
timeFraction = calculateTransformedTime(currentIteration, iterationDuration, iterationTime, m_specified) / iterationDuration;
if (!isNull(iterationTime)) {
timeToNextIteration = (iterationDuration - iterationTime) / std::abs(m_specified.playbackRate);
if (activeDuration - activeTime < timeToNextIteration)
timeToNextIteration = std::numeric_limits<double>::infinity();
}
} else {
const double localIterationDuration = 1;
const double localRepeatedDuration = localIterationDuration * m_specified.iterationCount;
ASSERT(localRepeatedDuration >= 0);
const double localActiveDuration = m_specified.playbackRate ? localRepeatedDuration / std::abs(m_specified.playbackRate) : std::numeric_limits<double>::infinity();
ASSERT(localActiveDuration >= 0);
const double localLocalTime = localTime < m_specified.startDelay ? localTime : localActiveDuration + m_specified.startDelay;
const TimedItem::Phase localCurrentPhase = calculatePhase(localActiveDuration, localLocalTime, m_specified);
const double localActiveTime = calculateActiveTime(localActiveDuration, resolvedFillMode(m_specified.fillMode, isAnimation()), localLocalTime, parentPhase, localCurrentPhase, m_specified);
const double startOffset = m_specified.iterationStart * localIterationDuration;
ASSERT(startOffset >= 0);
const double scaledActiveTime = calculateScaledActiveTime(localActiveDuration, localActiveTime, startOffset, m_specified);
const double iterationTime = calculateIterationTime(localIterationDuration, localRepeatedDuration, scaledActiveTime, startOffset, m_specified);
currentIteration = calculateCurrentIteration(localIterationDuration, iterationTime, scaledActiveTime, m_specified);
timeFraction = calculateTransformedTime(currentIteration, localIterationDuration, iterationTime, m_specified);
}
m_calculated.currentIteration = currentIteration;
m_calculated.timeFraction = timeFraction;
m_calculated.phase = currentPhase;
m_calculated.isInEffect = !isNull(activeTime);
m_calculated.isInPlay = phase() == PhaseActive && (!m_parent || m_parent->isInPlay());
m_calculated.isCurrent = phase() == PhaseBefore || isInPlay() || (m_parent && m_parent->isCurrent());
m_calculated.localTime = m_lastUpdateTime - m_startTime;
}
if (!m_player || m_player->hasStartTime()) {
if (m_eventDelegate && (m_isFirstSample || previousPhase != phase() || (phase() == PhaseActive && previousIteration != m_calculated.currentIteration)))
m_eventDelegate->onEventCondition(this, m_isFirstSample, previousPhase, previousIteration);
m_isFirstSample = false;
}
if (needsUpdate) {
updateChildrenAndEffects();
m_calculated.timeToForwardsEffectChange = calculateTimeToEffectChange(true, localTime, timeToNextIteration);
m_calculated.timeToReverseEffectChange = calculateTimeToEffectChange(false, localTime, timeToNextIteration);
}
}
const TimedItem::CalculatedTiming& TimedItem::ensureCalculated() const
{
if (!m_player)
return m_calculated;
if (m_player->outdated())
m_player->update(AnimationPlayer::UpdateOnDemand);
ASSERT(!m_player->outdated());
return m_calculated;
}
PassRefPtr<TimedItemTiming> TimedItem::specified()
{
return TimedItemTiming::create(this);
}
}