Bug 1286476 part 2 - Respect the playback rate when calculating phase boundaries; r=hiro

This implements the spec change in 21de090dac

The spec change refers to a binary 'animation direction' flag. Instead of that,
however, we just pass the playback rate along and use it inside
GetComputedTimingAt since this seems simpler.

Also, this patch moves the implementation of
KeyframeEffectReadOnly::GetComputedTiming from the header file into the .cpp
file. This is because with this change, GetComputedTiming needs to call
mAnimation->PlaybackRate() and so mozilla::dom::Animation needs to be a complete
type. However, simply including Animation.h doesn't work because of a cyclic
dependency between KeyframeEffect.h and Animation.h. We might be able to fix
this later but since yet-to-land bug 1049975 moves this code around a lot, I'd
rather not touch it too much just now.

MozReview-Commit-ID: 1h6XRh4xmfI
This commit is contained in:
Brian Birtles 2016-08-17 08:28:41 +09:00
Родитель aa305e6111
Коммит eac25e3163
5 изменённых файлов: 32 добавлений и 20 удалений

Просмотреть файл

@ -221,9 +221,11 @@ void
KeyframeEffectReadOnly::GetComputedTimingAsDict(
ComputedTimingProperties& aRetVal) const
{
double playbackRate = mAnimation ? mAnimation->PlaybackRate() : 1;
const Nullable<TimeDuration> currentTime = GetLocalTime();
GetComputedTimingDictionary(GetComputedTimingAt(currentTime,
SpecifiedTiming()),
SpecifiedTiming(),
playbackRate),
currentTime,
SpecifiedTiming(),
aRetVal);
@ -232,7 +234,8 @@ KeyframeEffectReadOnly::GetComputedTimingAsDict(
ComputedTiming
KeyframeEffectReadOnly::GetComputedTimingAt(
const Nullable<TimeDuration>& aLocalTime,
const TimingParams& aTiming)
const TimingParams& aTiming,
double aPlaybackRate)
{
const StickyTimeDuration zeroDuration;
@ -271,9 +274,15 @@ KeyframeEffectReadOnly::GetComputedTimingAt(
// Calculate the time within the active interval.
// https://w3c.github.io/web-animations/#active-time
StickyTimeDuration activeTime;
if (localTime >=
std::min(StickyTimeDuration(aTiming.mDelay + result.mActiveDuration),
result.mEndTime)) {
StickyTimeDuration beforeActiveBoundary =
std::min(StickyTimeDuration(aTiming.mDelay), result.mEndTime);
StickyTimeDuration activeAfterBoundary =
std::min(StickyTimeDuration(aTiming.mDelay + result.mActiveDuration),
result.mEndTime);
if (localTime > activeAfterBoundary ||
(aPlaybackRate >= 0 && localTime == activeAfterBoundary)) {
result.mPhase = ComputedTiming::AnimationPhase::After;
if (!result.FillsForwards()) {
// The animation isn't active or filling at this time.
@ -282,8 +291,8 @@ KeyframeEffectReadOnly::GetComputedTimingAt(
activeTime = std::max(std::min(result.mActiveDuration,
result.mActiveDuration + aTiming.mEndDelay),
zeroDuration);
} else if (localTime <
std::min(StickyTimeDuration(aTiming.mDelay), result.mEndTime)) {
} else if (localTime < beforeActiveBoundary ||
(aPlaybackRate < 0 && localTime == beforeActiveBoundary)) {
result.mPhase = ComputedTiming::AnimationPhase::Before;
if (!result.FillsBackwards()) {
// The animation isn't active or filling at this time.
@ -391,6 +400,15 @@ KeyframeEffectReadOnly::GetComputedTimingAt(
return result;
}
ComputedTiming
KeyframeEffectReadOnly::GetComputedTiming(const TimingParams* aTiming) const
{
double playbackRate = mAnimation ? mAnimation->PlaybackRate() : 1;
return GetComputedTimingAt(GetLocalTime(),
aTiming ? *aTiming : SpecifiedTiming(),
playbackRate);
}
// https://w3c.github.io/web-animations/#in-play
bool
KeyframeEffectReadOnly::IsInPlay() const

Просмотреть файл

@ -264,16 +264,13 @@ public:
// (because it is not currently active and is not filling at this time).
static ComputedTiming
GetComputedTimingAt(const Nullable<TimeDuration>& aLocalTime,
const TimingParams& aTiming);
const TimingParams& aTiming,
double aPlaybackRate);
// Shortcut for that gets the computed timing using the current local time as
// calculated from the timeline time.
ComputedTiming
GetComputedTiming(const TimingParams* aTiming = nullptr) const
{
return GetComputedTimingAt(GetLocalTime(),
aTiming ? *aTiming : SpecifiedTiming());
}
GetComputedTiming(const TimingParams* aTiming = nullptr) const;
void
GetComputedTimingAsDict(ComputedTimingProperties& aRetVal) const override;

Просмотреть файл

@ -652,7 +652,8 @@ SampleAnimations(Layer* aLayer, TimeStamp aPoint)
ComputedTiming computedTiming =
dom::KeyframeEffectReadOnly::GetComputedTimingAt(
Nullable<TimeDuration>(elapsedDuration), timing);
Nullable<TimeDuration>(elapsedDuration), timing,
animation.playbackRate());
MOZ_ASSERT(!computedTiming.mProgress.IsNull(),
"iteration progress should not be null");

Просмотреть файл

@ -91,7 +91,8 @@ ElementPropertyTransition::UpdateStartValueFromReplacedTransition()
TimeStamp::Now(),
mReplacedTransition->mStartTime,
mReplacedTransition->mPlaybackRate),
mReplacedTransition->mTiming);
mReplacedTransition->mTiming,
mReplacedTransition->mPlaybackRate);
if (!computedTiming.mProgress.IsNull()) {
double valuePosition =

Просмотреть файл

@ -1,5 +0,0 @@
[phases-and-states.html]
type: testharness
[Phase calculation for a simple animation effect with negative playback rate]
expected: FAIL
bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1286476