Bug 1923208 - Store animation index into AnimationEventDispatcher. r=layout-reviewers,birtles,jwatt,emilio

We need this information when comparing the cancelled transitions/animations
in the following patches.

Note that we have to reorder the calling of `Animation::Cancel()` and
the update of `mAnimationIndex` to make sure we enqueue the cancel event
with the correct `mAnimationIndex`.

Differential Revision: https://phabricator.services.mozilla.com/D227110
This commit is contained in:
Boris Chiou 2024-11-13 20:56:22 +00:00
parent c160b9197b
commit 4f7823a1f0
5 changed files with 26 additions and 10 deletions

View File

@ -29,6 +29,12 @@ struct AnimationEventInfo {
OwningAnimationTarget mTarget;
const EventMessage mMessage;
const double mElapsedTime;
// The transition generation or animation relative position in the global
// animation list. We use this information to determine the order of
// cancelled transitions or animations. (i.e. We override the animation
// index of the cancelled transitions/animations because their animation
// indexes have been changed.)
const uint64_t mAnimationIndex;
// FIXME(emilio): is this needed? This preserves behavior from before
// bug 1847200, but it's unclear what the timeStamp of the event should be.
// See also https://github.com/w3c/csswg-drafts/issues/9167
@ -73,13 +79,14 @@ struct AnimationEventInfo {
AnimationEventInfo(RefPtr<nsAtom> aAnimationName,
const NonOwningAnimationTarget& aTarget,
EventMessage aMessage, double aElapsedTime,
uint64_t aAnimationIndex,
const TimeStamp& aScheduledEventTimeStamp,
dom::Animation* aAnimation)
: mAnimation(aAnimation),
mScheduledEventTimeStamp(aScheduledEventTimeStamp),
mData(CssAnimationData{
{OwningAnimationTarget(aTarget.mElement, aTarget.mPseudoType),
aMessage, aElapsedTime},
aMessage, aElapsedTime, aAnimationIndex},
std::move(aAnimationName)}) {
if (profiler_thread_is_being_profiled_for_markers()) {
MaybeAddMarker();
@ -90,13 +97,14 @@ struct AnimationEventInfo {
AnimationEventInfo(const AnimatedPropertyID& aProperty,
const NonOwningAnimationTarget& aTarget,
EventMessage aMessage, double aElapsedTime,
uint64_t aTransitionGeneration,
const TimeStamp& aScheduledEventTimeStamp,
dom::Animation* aAnimation)
: mAnimation(aAnimation),
mScheduledEventTimeStamp(aScheduledEventTimeStamp),
mData(CssTransitionData{
{OwningAnimationTarget(aTarget.mElement, aTarget.mPseudoType),
aMessage, aElapsedTime},
aMessage, aElapsedTime, aTransitionGeneration},
aProperty}) {
if (profiler_thread_is_being_profiled_for_markers()) {
MaybeAddMarker();

View File

@ -230,9 +230,9 @@ void CSSAnimation::QueueEvents(const StickyTimeDuration& aActiveTime) {
elapsedTime = nsRFPService::ReduceTimePrecisionAsSecsRFPOnly(
elapsedTime, 0, mRTPCallerType);
}
events.AppendElement(
AnimationEventInfo(mAnimationName, mOwningElement.Target(), aMessage,
elapsedTime, aScheduledEventTimeStamp, this));
events.AppendElement(AnimationEventInfo(
mAnimationName, mOwningElement.Target(), aMessage, elapsedTime,
mAnimationIndex, aScheduledEventTimeStamp, this));
};
// Handle cancel event first

View File

@ -84,6 +84,8 @@ class CSSAnimation final : public Animation {
void PlayFromStyle();
void PauseFromStyle();
void CancelFromStyle(PostRestyleMode aPostRestyle) {
Animation::Cancel(aPostRestyle);
// When an animation is disassociated with style it enters an odd state
// where its composite order is undefined until it first transitions
// out of the idle state.
@ -94,11 +96,13 @@ class CSSAnimation final : public Animation {
// if it had been added to the end of the global animation list so that
// its sort order is defined. We'll update this index again once the
// animation leaves the idle state.
//
// Note: We have to update |mAnimationIndex| after calling
// Animation::Cancel(), which enqueues animationcancel event, to make sure
// we have the correct |mAnimationIndex| in AnimationEventInfo.
mAnimationIndex = sNextAnimationIndex++;
mNeedsNewAnimationIndexWhenRun = true;
Animation::Cancel(aPostRestyle);
// We need to do this *after* calling Cancel() since
// Cancel() might synchronously trigger a cancel event for which
// we need an owning element to target the event at.

View File

@ -120,7 +120,7 @@ void CSSTransition::QueueEvents(const StickyTimeDuration& aActiveTime) {
}
events.AppendElement(AnimationEventInfo(
TransitionProperty(), mOwningElement.Target(), aMessage, elapsedTime,
aScheduledEventTimeStamp, this));
mAnimationIndex, aScheduledEventTimeStamp, this));
};
// Handle cancel events first

View File

@ -51,17 +51,21 @@ class CSSTransition final : public Animation {
}
void CancelFromStyle(PostRestyleMode aPostRestyle) {
Animation::Cancel(aPostRestyle);
// The animation index to use for compositing will be established when
// this transition next transitions out of the idle state but we still
// update it now so that the sort order of this transition remains
// defined until that moment.
//
// See longer explanation in CSSAnimation::CancelFromStyle.
//
// Note: We have to update |mAnimationIndex| after calling
// Animation::Cancel(), which enqueues transitioncancel event, to make sure
// we have the correct |mAnimationIndex| in AnimationEventInfo.
mAnimationIndex = sNextAnimationIndex++;
mNeedsNewAnimationIndexWhenRun = true;
Animation::Cancel(aPostRestyle);
// It is important we do this *after* calling Cancel().
// This is because Cancel() will end up posting a restyle and
// that restyle should target the *transitions* level of the cascade.