Bug 1472900 - Use timestamp associated with the timeline for animation cancel events. r=birtles

Before this change, the test in this commit fails.  The received events order
is;

 1) cancel
 2) transitioncancel
 3) transitionstart
 4) finish

MozReview-Commit-ID: 8liTFXime6e

--HG--
extra : rebase_source : 3c68ef330b1f263afa2fad9670a30b351b8dbf28
This commit is contained in:
Hiroyuki Ikezoe 2018-07-05 06:19:12 +09:00
parent 84b3da673c
commit 1609fd1ef0
7 changed files with 49 additions and 7 deletions

View File

@ -874,8 +874,8 @@ Animation::CancelNoUpdate()
}
ResetFinishedPromise();
// FIXME: Bug 1472900 - Use the timestamp associated with the timeline.
QueuePlaybackEvent(NS_LITERAL_STRING("cancel"), TimeStamp());
QueuePlaybackEvent(NS_LITERAL_STRING("cancel"),
GetTimelineCurrentTimeAsTimeStamp());
}
StickyTimeDuration activeTime = mEffect

View File

@ -522,6 +522,11 @@ protected:
zeroDuration);
}
TimeStamp GetTimelineCurrentTimeAsTimeStamp() const
{
return mTimeline ? mTimeline->GetCurrentTimeAsTimeStamp() : TimeStamp();
}
nsIDocument* GetRenderedDocument() const;
nsIDocument* GetTimelineDocument() const;

View File

@ -62,6 +62,13 @@ public:
return AnimationUtils::TimeDurationToDouble(GetCurrentTime());
}
TimeStamp GetCurrentTimeAsTimeStamp() const {
Nullable<TimeDuration> currentTime = GetCurrentTime();
return !currentTime.IsNull()
? ToTimeStamp(currentTime.Value())
: TimeStamp();
}
/**
* Returns true if the times returned by GetCurrentTime() are convertible
* to and from wallclock-based TimeStamp (e.g. from TimeStamp::Now()) values

View File

@ -254,8 +254,9 @@ CSSAnimation::QueueEvents(const StickyTimeDuration& aActiveTime)
if ((mPreviousPhase != AnimationPhase::Idle &&
mPreviousPhase != AnimationPhase::After) &&
currentPhase == AnimationPhase::Idle) {
TimeStamp activeTimeStamp = ElapsedTimeToTimeStamp(aActiveTime);
appendAnimationEvent(eAnimationCancel, aActiveTime, activeTimeStamp);
appendAnimationEvent(eAnimationCancel,
aActiveTime,
GetTimelineCurrentTimeAsTimeStamp());
}
switch (mPreviousPhase) {

View File

@ -255,8 +255,9 @@ CSSTransition::QueueEvents(const StickyTimeDuration& aActiveTime)
if ((mPreviousTransitionPhase != TransitionPhase::Idle &&
mPreviousTransitionPhase != TransitionPhase::After) &&
currentPhase == TransitionPhase::Idle) {
TimeStamp activeTimeStamp = ElapsedTimeToTimeStamp(aActiveTime);
appendTransitionEvent(eTransitionCancel, aActiveTime, activeTimeStamp);
appendTransitionEvent(eTransitionCancel,
aActiveTime,
GetTimelineCurrentTimeAsTimeStamp());
}
// All other events

View File

@ -619346,7 +619346,7 @@
"testharness"
],
"web-animations/timing-model/timelines/update-and-send-events.html": [
"6ef855775c8fbb7220b0fd7f909b23cc8a64aebe",
"22947e732cd1b879118b0379302132c097960970",
"testharness"
],
"web-nfc/OWNERS": [

View File

@ -178,4 +178,32 @@ promise_test(async t => {
'The cancel event should be dispatched in a later frame');
}, 'Queues a cancel event in transitionstart event callback');
promise_test(async t => {
const div = createDiv(t);
getComputedStyle(div).marginLeft;
div.style = 'transition: margin-left 100s; margin-left: 100px;';
const anim = div.getAnimations()[0];
let receivedEvents = [];
anim.oncancel = event => receivedEvents.push(event);
anim.onfinish = event => receivedEvents.push(event);
div.ontransitionstart = event => receivedEvents.push(event);
div.ontransitioncancel = event => receivedEvents.push(event);
await anim.ready;
anim.finish();
anim.cancel();
await waitForAnimationFrames(1);
assert_array_equals(receivedEvents.map(event => event.type),
[ 'transitionstart',
'finish',
'cancel',
'transitioncancel' ],
'Playback and CSS events for the same transition should be sorted by ' +
'schedule event time and composite order');
}, 'Sorts events for the same transition');
</script>