diff options
author | Moonchild <mcwerewolf@gmail.com> | 2018-04-29 18:48:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-29 18:48:43 +0200 |
commit | b83c51a1a51f58a7a68d1a4877b0f0a8f03a939e (patch) | |
tree | 8ba5cabbaa5390ce5bffb1af3b31a4e49a8def09 /dom/animation/Animation.cpp | |
parent | 3fe37f6ae848f7d88e2316857a1a95d9c2abae14 (diff) | |
parent | 35c61a027dc6f4d58ca9d33e06da79adf2503ebd (diff) | |
download | UXP-b83c51a1a51f58a7a68d1a4877b0f0a8f03a939e.tar UXP-b83c51a1a51f58a7a68d1a4877b0f0a8f03a939e.tar.gz UXP-b83c51a1a51f58a7a68d1a4877b0f0a8f03a939e.tar.lz UXP-b83c51a1a51f58a7a68d1a4877b0f0a8f03a939e.tar.xz UXP-b83c51a1a51f58a7a68d1a4877b0f0a8f03a939e.zip |
Merge pull request #296 from janekptacijarabaci/js_dom_animationcancel_1
DOM - implement animationcancel event
Diffstat (limited to 'dom/animation/Animation.cpp')
-rw-r--r-- | dom/animation/Animation.cpp | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/dom/animation/Animation.cpp b/dom/animation/Animation.cpp index 6dd583ed1..bd318f79e 100644 --- a/dom/animation/Animation.cpp +++ b/dom/animation/Animation.cpp @@ -230,6 +230,10 @@ Animation::SetTimelineNoUpdate(AnimationTimeline* aTimeline) return; } + StickyTimeDuration activeTime = mEffect + ? mEffect->GetComputedTiming().mActiveTime + : StickyTimeDuration(); + RefPtr<AnimationTimeline> oldTimeline = mTimeline; if (oldTimeline) { oldTimeline->RemoveAnimation(this); @@ -240,6 +244,9 @@ Animation::SetTimelineNoUpdate(AnimationTimeline* aTimeline) mHoldTime.SetNull(); } + if (!aTimeline) { + MaybeQueueCancelEvent(activeTime); + } UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async); } @@ -722,8 +729,10 @@ TimeStamp Animation::ElapsedTimeToTimeStamp( const StickyTimeDuration& aElapsedTime) const { - return AnimationTimeToTimeStamp(aElapsedTime + - mEffect->SpecifiedTiming().mDelay); + TimeDuration delay = mEffect + ? mEffect->SpecifiedTiming().mDelay + : TimeDuration(); + return AnimationTimeToTimeStamp(aElapsedTime + delay); } @@ -771,14 +780,28 @@ Animation::CancelNoUpdate() DispatchPlaybackEvent(NS_LITERAL_STRING("cancel")); + StickyTimeDuration activeTime = mEffect + ? mEffect->GetComputedTiming().mActiveTime + : StickyTimeDuration(); + mHoldTime.SetNull(); mStartTime.SetNull(); - UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async); - if (mTimeline) { mTimeline->RemoveAnimation(this); } + MaybeQueueCancelEvent(activeTime); + + // When an animation is cancelled it no longer needs further ticks from the + // timeline. However, if we queued a cancel event and this was the last + // animation attached to the timeline, the timeline will stop observing the + // refresh driver and there may be no subsequent refresh driver tick for + // dispatching the queued event. + // + // By calling UpdateTiming *after* removing ourselves from our timeline, we + // ensure the timeline will register with the refresh driver for at least one + // more tick. + UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async); } void @@ -819,6 +842,17 @@ Animation::HasLowerCompositeOrderThan(const Animation& aOther) const return thisTransition->HasLowerCompositeOrderThan(*otherTransition); } if (thisTransition || otherTransition) { + // Cancelled transitions no longer have an owning element. To be strictly + // correct we should store a strong reference to the owning element + // so that if we arrive here while sorting cancel events, we can sort + // them in the correct order. + // + // However, given that cancel events are almost always queued + // synchronously in some deterministic manner, we can be fairly sure + // that cancel events will be dispatched in a deterministic order + // (which is our only hard requirement until specs say otherwise). + // Furthermore, we only reach here when we have events with equal + // timestamps so this is an edge case we can probably ignore for now. return thisTransition; } } |