Bug 1183461 part 4 - Add CSSAnimation::ElapsedTimeToTimeStamp; r=heycam

The elapsedTime member reported on AnimationEvents measures the time from
the *end* of the delay phase (i.e. the beginning of the active interval) to
when the event occurred. However, the AnimationTimeToTimeStamp method
introduced in the previous patch expects a time relative to the animation's
start time (i.e. the *start* of the delay phase). This patch adds a method
that performs the necessary conversion from an elapsedTime to an animation
time before calling AnimationTimeToTimeStamp. It also provides extra handling
for cases such as when the animation's start time has not yet been resolved or
when animation effect has disappeared.
This commit is contained in:
Brian Birtles 2015-09-15 14:04:08 +09:00
parent cfd6ae6920
commit aa5953069f
2 changed files with 28 additions and 0 deletions

View File

@ -309,6 +309,30 @@ CSSAnimation::UpdateTiming(SeekFlag aSeekFlag, SyncNotifyFlag aSyncNotifyFlag)
Animation::UpdateTiming(aSeekFlag, aSyncNotifyFlag);
}
TimeStamp
CSSAnimation::ElapsedTimeToTimeStamp(const StickyTimeDuration&
aElapsedTime) const
{
// Initializes to null. We always return this object to benefit from
// return-value-optimization.
TimeStamp result;
// Currently we may dispatch animationstart events before resolving
// mStartTime if we have a delay <= 0. This will change in bug 1134163
// but until then we should just use the latest refresh driver time as
// the event timestamp in that case.
if (!mEffect || mStartTime.IsNull()) {
nsPresContext* presContext = GetPresContext();
if (presContext) {
result = presContext->RefreshDriver()->MostRecentRefresh();
}
return result;
}
result = AnimationTimeToTimeStamp(aElapsedTime + mEffect->Timing().mDelay);
return result;
}
////////////////////////// nsAnimationManager ////////////////////////////
NS_IMPL_CYCLE_COLLECTION(nsAnimationManager, mEventDispatcher)

View File

@ -176,6 +176,10 @@ protected:
std::max(TimeDuration(), mEffect->Timing().mDelay * -1) :
TimeDuration();
}
// Converts an AnimationEvent's elapsedTime value to an equivalent TimeStamp
// that can be used to sort events by when they occurred.
TimeStamp ElapsedTimeToTimeStamp(const StickyTimeDuration& aElapsedTime)
const;
nsString mAnimationName;