Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(448)

Unified Diff: Source/core/animation/Animation.cpp

Issue 1162253005: Animations: Add the effect clipping primitive to web animations (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/animation/Animation.h ('k') | Source/core/animation/Animation.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/animation/Animation.cpp
diff --git a/Source/core/animation/Animation.cpp b/Source/core/animation/Animation.cpp
index 8e1e3d64816ef2671ff01bfd0e8e3761ac3d8b53..4702e5fa73fc629bd20a0b275340e543fb886eae 100644
--- a/Source/core/animation/Animation.cpp
+++ b/Source/core/animation/Animation.cpp
@@ -82,6 +82,8 @@ Animation::Animation(ExecutionContext* executionContext, AnimationTimeline& time
, m_playbackRate(1)
, m_startTime(nullValue())
, m_holdTime(0)
+ , m_startClip(-std::numeric_limits<double>::infinity())
+ , m_endClip(std::numeric_limits<double>::infinity())
, m_sequenceNumber(nextSequenceNumber())
, m_content(content)
, m_timeline(&timeline)
@@ -438,6 +440,12 @@ void Animation::setStartTimeInternal(double newStartTime)
}
}
+bool Animation::clipped(double time)
+{
+ ASSERT(!isNull(time));
+ return time <= m_startClip || time > m_endClip + sourceEnd();
+}
+
void Animation::setSource(AnimationEffect* newSource)
{
if (m_content == newSource)
@@ -783,7 +791,14 @@ bool Animation::update(TimingUpdateReason reason)
bool idle = playStateInternal() == Idle;
if (m_content) {
- double inheritedTime = idle || isNull(m_timeline->currentTimeInternal()) ? nullValue() : currentTimeInternal();
+ double inheritedTime = idle || isNull(m_timeline->currentTimeInternal())
+ ? nullValue()
+ : currentTimeInternal();
+
+ // When the animation is limited, is held but we need to use the calculated current time.
+ // When the start time is null, the held time needs to be used, which is in inherited time.
+ if (!isNull(inheritedTime) && clipped(m_held && (!limited(inheritedTime) || isNull(m_startTime)) ? inheritedTime : calculateCurrentTime()))
dstockwell 2015/06/04 01:32:06 This might be better: if (!isNull(inheritedTime))
samli 2015/06/09 01:23:53 Done.
+ inheritedTime = nullValue();
// Special case for end-exclusivity when playing backwards.
if (inheritedTime == 0 && m_playbackRate < 0)
inheritedTime = -1;
dstockwell 2015/06/04 01:32:06 this probably breaks clipping when clipStart is be
samli 2015/06/09 01:23:53 Yay, this isn't a problem.
@@ -804,22 +819,52 @@ bool Animation::update(TimingUpdateReason reason)
}
}
ASSERT(!m_outdated);
- return !m_finished;
+ return !m_finished || std::isfinite(timeToEffectChange());
}
double Animation::timeToEffectChange()
{
ASSERT(!m_outdated);
- if (m_held || !hasStartTime())
+ if (!hasStartTime())
+ return std::numeric_limits<double>::infinity();
+
+ double currentTime = calculateCurrentTime();
+ if (m_held) {
+ if (limited(currentTime)) {
+ if (m_playbackRate > 0 && m_endClip + sourceEnd() > currentTime)
+ return m_endClip + sourceEnd() - currentTime;
+ if (m_playbackRate < 0 && m_startClip <= currentTime)
+ return m_startClip - currentTime;
+ }
return std::numeric_limits<double>::infinity();
+ }
+
if (!m_content)
return -currentTimeInternal() / m_playbackRate;
double result = m_playbackRate > 0
? m_content->timeToForwardsEffectChange() / m_playbackRate
: m_content->timeToReverseEffectChange() / -m_playbackRate;
+
return !hasActiveAnimationsOnCompositor() && m_content->phase() == AnimationEffect::PhaseActive
? 0
- : result;
+ : clipTimeToEffectChange(result);
+}
+
+double Animation::clipTimeToEffectChange(double result)
dstockwell 2015/06/04 01:32:06 const?
samli 2015/06/09 01:23:53 Done.
+{
+ double currentTime = calculateCurrentTime();
+ if (m_playbackRate > 0) {
+ if (currentTime <= m_startClip)
+ result = std::min(result, (m_startClip - currentTime) / m_playbackRate);
+ else if (currentTime < m_endClip + sourceEnd())
+ result = std::min(result, (m_endClip + sourceEnd() - currentTime) / m_playbackRate);
dstockwell 2015/06/04 01:32:06 This might prevent firing the finish event.
samli 2015/06/09 01:23:53 It shouldn't. This function always returns as smal
+ } else {
+ if (currentTime >= m_endClip + sourceEnd())
+ result = std::min(result, (currentTime - m_endClip + sourceEnd()) / -m_playbackRate);
+ else if (currentTime > m_startClip)
+ result = std::min(result, (currentTime - m_startClip) / -m_playbackRate);
+ }
+ return result;
}
void Animation::cancel()
« no previous file with comments | « Source/core/animation/Animation.h ('k') | Source/core/animation/Animation.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698