Title: [225927] trunk
Revision
225927
Author
[email protected]
Date
2017-12-14 14:12:37 -0800 (Thu, 14 Dec 2017)

Log Message

[Web Animations] Implement the cancel() method on Animation
https://bugs.webkit.org/show_bug.cgi?id=180830
<rdar://problem/36055816>

Reviewed by Dean Jackson.

Source/WebCore:

We implement the cancel() method on the Animation interface with full spec text defining
the normative behavior of those methods and code matching those steps. Implementing the
cancel() method required implementing the notion of "resetting pending tasks",
which the Web Animations spec defines as well.

* animation/WebAnimation.cpp:
(WebCore::WebAnimation::setEffect):
(WebCore::WebAnimation::cancel):
(WebCore::WebAnimation::resetPendingTasks):
* animation/WebAnimation.h:
* animation/WebAnimation.idl:

LayoutTests:

Rebase some WPT expectations with progressions due to exposing the cancel() method.

* http/wpt/web-animations/interfaces/Animation/idlharness-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (225926 => 225927)


--- trunk/LayoutTests/ChangeLog	2017-12-14 22:08:53 UTC (rev 225926)
+++ trunk/LayoutTests/ChangeLog	2017-12-14 22:12:37 UTC (rev 225927)
@@ -1,5 +1,17 @@
 2017-12-14  Antoine Quint  <[email protected]>
 
+        [Web Animations] Implement the cancel() method on Animation
+        https://bugs.webkit.org/show_bug.cgi?id=180830
+        <rdar://problem/36055816>
+
+        Reviewed by Dean Jackson.
+
+        Rebase some WPT expectations with progressions due to exposing the cancel() method.
+
+        * http/wpt/web-animations/interfaces/Animation/idlharness-expected.txt:
+
+2017-12-14  Antoine Quint  <[email protected]>
+
         [Web Animations] Implement the finish() method on Animation
         https://bugs.webkit.org/show_bug.cgi?id=180822
         <rdar://problem/36053282>

Modified: trunk/LayoutTests/http/wpt/web-animations/interfaces/Animation/idlharness-expected.txt (225926 => 225927)


--- trunk/LayoutTests/http/wpt/web-animations/interfaces/Animation/idlharness-expected.txt	2017-12-14 22:08:53 UTC (rev 225926)
+++ trunk/LayoutTests/http/wpt/web-animations/interfaces/Animation/idlharness-expected.txt	2017-12-14 22:12:37 UTC (rev 225927)
@@ -15,8 +15,8 @@
 PASS Animation interface: attribute ready 
 PASS Animation interface: attribute finished 
 PASS Animation interface: attribute onfinish 
-FAIL Animation interface: attribute oncancel assert_true: The prototype object must have a property "oncancel" expected true got false
-FAIL Animation interface: operation cancel() assert_own_property: interface prototype object missing non-static operation expected property "cancel" missing
+PASS Animation interface: attribute oncancel 
+PASS Animation interface: operation cancel() 
 PASS Animation interface: operation finish() 
 PASS Animation interface: operation play() 
 PASS Animation interface: operation pause() 
@@ -33,8 +33,8 @@
 PASS Animation interface: new Animation() must inherit property "ready" with the proper type 
 PASS Animation interface: new Animation() must inherit property "finished" with the proper type 
 PASS Animation interface: new Animation() must inherit property "onfinish" with the proper type 
-FAIL Animation interface: new Animation() must inherit property "oncancel" with the proper type assert_inherits: property "oncancel" not found in prototype chain
-FAIL Animation interface: new Animation() must inherit property "cancel()" with the proper type assert_inherits: property "cancel" not found in prototype chain
+PASS Animation interface: new Animation() must inherit property "oncancel" with the proper type 
+PASS Animation interface: new Animation() must inherit property "cancel()" with the proper type 
 PASS Animation interface: new Animation() must inherit property "finish()" with the proper type 
 PASS Animation interface: new Animation() must inherit property "play()" with the proper type 
 PASS Animation interface: new Animation() must inherit property "pause()" with the proper type 

Modified: trunk/Source/WebCore/ChangeLog (225926 => 225927)


--- trunk/Source/WebCore/ChangeLog	2017-12-14 22:08:53 UTC (rev 225926)
+++ trunk/Source/WebCore/ChangeLog	2017-12-14 22:12:37 UTC (rev 225927)
@@ -1,3 +1,23 @@
+2017-12-14  Antoine Quint  <[email protected]>
+
+        [Web Animations] Implement the cancel() method on Animation
+        https://bugs.webkit.org/show_bug.cgi?id=180830
+        <rdar://problem/36055816>
+
+        Reviewed by Dean Jackson.
+
+        We implement the cancel() method on the Animation interface with full spec text defining
+        the normative behavior of those methods and code matching those steps. Implementing the
+        cancel() method required implementing the notion of "resetting pending tasks",
+        which the Web Animations spec defines as well.
+
+        * animation/WebAnimation.cpp:
+        (WebCore::WebAnimation::setEffect):
+        (WebCore::WebAnimation::cancel):
+        (WebCore::WebAnimation::resetPendingTasks):
+        * animation/WebAnimation.h:
+        * animation/WebAnimation.idl:
+
 2017-12-14  Jer Noble  <[email protected]>
 
         "Click to exit fullscreen" text not legible on High Sierra

Modified: trunk/Source/WebCore/animation/WebAnimation.cpp (225926 => 225927)


--- trunk/Source/WebCore/animation/WebAnimation.cpp	2017-12-14 22:08:53 UTC (rev 225926)
+++ trunk/Source/WebCore/animation/WebAnimation.cpp	2017-12-14 22:12:37 UTC (rev 225927)
@@ -67,9 +67,17 @@
 
 void WebAnimation::setEffect(RefPtr<AnimationEffect>&& effect)
 {
+    // 3.4.3. Setting the target effect of an animation
+    // https://drafts.csswg.org/web-animations-1/#setting-the-target-effect
+
+    // 2. If new effect is the same object as old effect, abort this procedure.
     if (effect == m_effect)
         return;
 
+    // 3. If new effect is null and old effect is not null, run the procedure to reset an animation's pending tasks on animation.
+    if (!effect && m_effect)
+        resetPendingTasks();
+
     if (m_effect) {
         m_effect->setAnimation(nullptr);
 
@@ -316,6 +324,47 @@
     return m_effect ? m_effect->timing()->duration() : 0_s;
 }
 
+void WebAnimation::cancel()
+{
+    // 3.4.16. Canceling an animation
+    // https://drafts.csswg.org/web-animations-1/#canceling-an-animation-section
+    //
+    // An animation can be canceled which causes the current time to become unresolved hence removing any effects caused by the target effect.
+    //
+    // The procedure to cancel an animation for animation is as follows:
+    //
+    // 1. If animation's play state is not idle, perform the following steps:
+    if (playState() != PlayState::Idle) {
+        // 1. Run the procedure to reset an animation's pending tasks on animation.
+        resetPendingTasks();
+
+        // 2. Reject the current finished promise with a DOMException named "AbortError".
+        m_finishedPromise.reject(Exception { AbortError });
+
+        // 3. Let current finished promise be a new (pending) Promise object.
+        m_finishedPromise.clear();
+
+        // 4. Create an AnimationPlaybackEvent, cancelEvent.
+        // 5. Set cancelEvent's type attribute to cancel.
+        // 6. Set cancelEvent's currentTime to null.
+        // 7. Let timeline time be the current time of the timeline with which animation is associated. If animation is not associated with an
+        //    active timeline, let timeline time be n unresolved time value.
+        // 8. Set cancelEvent's timelineTime to timeline time. If timeline time is unresolved, set it to null.
+        // 9. If animation has a document for timing, then append cancelEvent to its document for timing's pending animation event queue along
+        //    with its target, animation. If animation is associated with an active timeline that defines a procedure to convert timeline times
+        //    to origin-relative time, let the scheduled event time be the result of applying that procedure to timeline time. Otherwise, the
+        //    scheduled event time is an unresolved time value.
+        // Otherwise, queue a task to dispatch cancelEvent at animation. The task source for this task is the DOM manipulation task source.
+        enqueueAnimationPlaybackEvent(eventNames().cancelEvent, std::nullopt, m_timeline ? m_timeline->currentTime() : std::nullopt);
+    }
+
+    // 2. Make animation's hold time unresolved.
+    m_holdTime = std::nullopt;
+
+    // 3. Make animation's start time unresolved.
+    setStartTime(std::nullopt);
+}
+
 void WebAnimation::enqueueAnimationPlaybackEvent(const AtomicString& type, std::optional<Seconds> currentTime, std::optional<Seconds> timelineTime)
 {
     auto event = AnimationPlaybackEvent::create(type, currentTime, timelineTime);
@@ -336,6 +385,31 @@
     }
 }
 
+void WebAnimation::resetPendingTasks()
+{
+    // The procedure to reset an animation's pending tasks for animation is as follows:
+    // https://drafts.csswg.org/web-animations-1/#reset-an-animations-pending-tasks
+    //
+    // 1. If animation does not have a pending play task or a pending pause task, abort this procedure.
+    if (!pending())
+        return;
+
+    // 2. If animation has a pending play task, cancel that task.
+    if (hasPendingPlayTask())
+        setTimeToRunPendingPlayTask(TimeToRunPendingTask::NotScheduled);
+
+    // 3. If animation has a pending pause task, cancel that task.
+    if (hasPendingPauseTask())
+        setTimeToRunPendingPauseTask(TimeToRunPendingTask::NotScheduled);
+
+    // 4. Reject animation's current ready promise with a DOMException named "AbortError".
+    m_readyPromise.reject(Exception { AbortError });
+
+    // 5. Let animation's current ready promise be the result of creating a new resolved Promise object.
+    m_readyPromise.clear();
+    m_readyPromise.resolve(*this);
+}
+
 ExceptionOr<void> WebAnimation::finish()
 {
     // 3.4.15. Finishing an animation

Modified: trunk/Source/WebCore/animation/WebAnimation.h (225926 => 225927)


--- trunk/Source/WebCore/animation/WebAnimation.h	2017-12-14 22:08:53 UTC (rev 225926)
+++ trunk/Source/WebCore/animation/WebAnimation.h	2017-12-14 22:12:37 UTC (rev 225927)
@@ -78,6 +78,7 @@
     using FinishedPromise = DOMPromiseProxyWithResolveCallback<IDLInterface<WebAnimation>>;
     FinishedPromise& finished() { return m_finishedPromise; }
 
+    void cancel();
     ExceptionOr<void> finish();
     ExceptionOr<void> play();
     ExceptionOr<void> pause();
@@ -120,6 +121,7 @@
     ExceptionOr<void> play(AutoRewind);
     void runPendingPauseTask();
     void runPendingPlayTask();
+    void resetPendingTasks();
     
     RefPtr<AnimationEffect> m_effect;
     RefPtr<AnimationTimeline> m_timeline;

Modified: trunk/Source/WebCore/animation/WebAnimation.idl (225926 => 225927)


--- trunk/Source/WebCore/animation/WebAnimation.idl	2017-12-14 22:08:53 UTC (rev 225926)
+++ trunk/Source/WebCore/animation/WebAnimation.idl	2017-12-14 22:12:37 UTC (rev 225927)
@@ -46,8 +46,10 @@
     readonly attribute AnimationPlayState playState;
     readonly attribute boolean pending;
     attribute EventHandler onfinish;
+    attribute EventHandler oncancel;
     readonly attribute Promise<WebAnimation> ready;
     readonly attribute Promise<WebAnimation> finished;
+    void cancel();
     [MayThrowException] void finish();
     [MayThrowException] void play();
     [MayThrowException] void pause();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to