mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 05:15:45 +00:00
Bug 1036287 part 2 - Make GetComputedTimingAt take a nullable local time; r=dholbert
As part of supporting arbitrary timelines, we'd like to pass null times to the function that calculates computed timing. Incidentally, this also provides a means for evaluating calculating timing parameters that are independent of the current time (currently only the active duration) without requiring a valid time. This patch updates the signature of ElementAnimation::GetComputedTimingAt to take a nullable time duration. We use the Nullable wrapper to represent null TimeDurations since, unlike, TimeStamp, TimeDuration does not include a null state.
This commit is contained in:
parent
34ac24b42a
commit
a3a8900375
@ -486,7 +486,7 @@ ElementAnimation::HasAnimationOfProperty(nsCSSProperty aProperty) const
|
||||
}
|
||||
|
||||
ComputedTiming
|
||||
ElementAnimation::GetComputedTimingAt(TimeDuration aLocalTime,
|
||||
ElementAnimation::GetComputedTimingAt(const Nullable<TimeDuration>& aLocalTime,
|
||||
const AnimationTiming& aTiming)
|
||||
{
|
||||
const TimeDuration zeroDuration;
|
||||
@ -494,7 +494,7 @@ ElementAnimation::GetComputedTimingAt(TimeDuration aLocalTime,
|
||||
// Currently we expect negative durations to be picked up during CSS
|
||||
// parsing but when we start receiving timing parameters from other sources
|
||||
// we will need to clamp negative durations here.
|
||||
// For now, if we're hitting this it probably means we've overflowing
|
||||
// For now, if we're hitting this it probably means we're overflowing
|
||||
// integer arithmetic in mozilla::TimeStamp.
|
||||
MOZ_ASSERT(aTiming.mIterationDuration >= zeroDuration,
|
||||
"Expecting iteration duration >= 0");
|
||||
@ -504,6 +504,13 @@ ElementAnimation::GetComputedTimingAt(TimeDuration aLocalTime,
|
||||
|
||||
result.mActiveDuration = ActiveDuration(aTiming);
|
||||
|
||||
// The default constructor for ComputedTiming sets all other members to
|
||||
// values consistent with an animation that has not been sampled.
|
||||
if (aLocalTime.IsNull()) {
|
||||
return result;
|
||||
}
|
||||
const TimeDuration& localTime = aLocalTime.Value();
|
||||
|
||||
// When we finish exactly at the end of an iteration we need to report
|
||||
// the end of the final iteration and not the start of the next iteration
|
||||
// so we set up a flag for that case.
|
||||
@ -511,7 +518,7 @@ ElementAnimation::GetComputedTimingAt(TimeDuration aLocalTime,
|
||||
|
||||
// Get the normalized time within the active interval.
|
||||
TimeDuration activeTime;
|
||||
if (aLocalTime >= aTiming.mDelay + result.mActiveDuration) {
|
||||
if (localTime >= aTiming.mDelay + result.mActiveDuration) {
|
||||
result.mPhase = ComputedTiming::AnimationPhase_After;
|
||||
if (!aTiming.FillsForwards()) {
|
||||
// The animation isn't active or filling at this time.
|
||||
@ -524,7 +531,7 @@ ElementAnimation::GetComputedTimingAt(TimeDuration aLocalTime,
|
||||
isEndOfFinalIteration =
|
||||
aTiming.mIterationCount != 0.0 &&
|
||||
aTiming.mIterationCount == floor(aTiming.mIterationCount);
|
||||
} else if (aLocalTime < aTiming.mDelay) {
|
||||
} else if (localTime < aTiming.mDelay) {
|
||||
result.mPhase = ComputedTiming::AnimationPhase_Before;
|
||||
if (!aTiming.FillsBackwards()) {
|
||||
// The animation isn't active or filling at this time.
|
||||
@ -536,7 +543,7 @@ ElementAnimation::GetComputedTimingAt(TimeDuration aLocalTime,
|
||||
MOZ_ASSERT(result.mActiveDuration != zeroDuration,
|
||||
"How can we be in the middle of a zero-duration interval?");
|
||||
result.mPhase = ComputedTiming::AnimationPhase_Active;
|
||||
activeTime = aLocalTime - aTiming.mDelay;
|
||||
activeTime = localTime - aTiming.mDelay;
|
||||
}
|
||||
|
||||
// Get the position within the current iteration.
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "mozilla/StyleAnimationValue.h"
|
||||
#include "mozilla/dom/AnimationTimeline.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/dom/Nullable.h"
|
||||
#include "nsSMILKeySpline.h"
|
||||
#include "nsStyleStruct.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
@ -379,13 +380,27 @@ public:
|
||||
}
|
||||
|
||||
// This function takes as input the timing parameters of an animation and
|
||||
// returns the computed timing at the specified moment.
|
||||
// returns the computed timing at the specified local time.
|
||||
//
|
||||
// The local time may be null in which case only static parameters such as the
|
||||
// active duration are calculated. All other members of the returned object
|
||||
// are given a null/initial value.
|
||||
//
|
||||
// This function returns ComputedTiming::kNullTimeFraction for the
|
||||
// mTimeFraction member of the return value if the animation should not be
|
||||
// run (because it is not currently active and is not filling at this time).
|
||||
static ComputedTiming GetComputedTimingAt(TimeDuration aLocalTime,
|
||||
const AnimationTiming& aTiming);
|
||||
static ComputedTiming
|
||||
GetComputedTimingAt(const Nullable<mozilla::TimeDuration>& aLocalTime,
|
||||
const AnimationTiming& aTiming);
|
||||
|
||||
// Convenience wrapper method to save changing all call sites. Removed in
|
||||
// a subsequent patch.
|
||||
static ComputedTiming
|
||||
GetComputedTimingAt(mozilla::TimeDuration aLocalTime,
|
||||
const AnimationTiming& aTiming) {
|
||||
return GetComputedTimingAt(Nullable<mozilla::TimeDuration>(aLocalTime),
|
||||
aTiming);
|
||||
}
|
||||
|
||||
// Return the duration of the active interval for the given timing parameters.
|
||||
static mozilla::TimeDuration ActiveDuration(const AnimationTiming& aTiming);
|
||||
|
Loading…
Reference in New Issue
Block a user