Changeset 225927 in webkit


Ignore:
Timestamp:
Dec 14, 2017 2:12:37 PM (6 years ago)
Author:
graouts@webkit.org
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:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r225917 r225927  
     12017-12-14  Antoine Quint  <graouts@apple.com>
     2
     3        [Web Animations] Implement the cancel() method on Animation
     4        https://bugs.webkit.org/show_bug.cgi?id=180830
     5        <rdar://problem/36055816>
     6
     7        Reviewed by Dean Jackson.
     8
     9        Rebase some WPT expectations with progressions due to exposing the cancel() method.
     10
     11        * http/wpt/web-animations/interfaces/Animation/idlharness-expected.txt:
     12
    1132017-12-14  Antoine Quint  <graouts@apple.com>
    214
  • trunk/LayoutTests/http/wpt/web-animations/interfaces/Animation/idlharness-expected.txt

    r225917 r225927  
    1616PASS Animation interface: attribute finished
    1717PASS Animation interface: attribute onfinish
    18 FAIL Animation interface: attribute oncancel assert_true: The prototype object must have a property "oncancel" expected true got false
    19 FAIL Animation interface: operation cancel() assert_own_property: interface prototype object missing non-static operation expected property "cancel" missing
     18PASS Animation interface: attribute oncancel
     19PASS Animation interface: operation cancel()
    2020PASS Animation interface: operation finish()
    2121PASS Animation interface: operation play()
     
    3434PASS Animation interface: new Animation() must inherit property "finished" with the proper type
    3535PASS Animation interface: new Animation() must inherit property "onfinish" with the proper type
    36 FAIL Animation interface: new Animation() must inherit property "oncancel" with the proper type assert_inherits: property "oncancel" not found in prototype chain
    37 FAIL Animation interface: new Animation() must inherit property "cancel()" with the proper type assert_inherits: property "cancel" not found in prototype chain
     36PASS Animation interface: new Animation() must inherit property "oncancel" with the proper type
     37PASS Animation interface: new Animation() must inherit property "cancel()" with the proper type
    3838PASS Animation interface: new Animation() must inherit property "finish()" with the proper type
    3939PASS Animation interface: new Animation() must inherit property "play()" with the proper type
  • trunk/Source/WebCore/ChangeLog

    r225923 r225927  
     12017-12-14  Antoine Quint  <graouts@apple.com>
     2
     3        [Web Animations] Implement the cancel() method on Animation
     4        https://bugs.webkit.org/show_bug.cgi?id=180830
     5        <rdar://problem/36055816>
     6
     7        Reviewed by Dean Jackson.
     8
     9        We implement the cancel() method on the Animation interface with full spec text defining
     10        the normative behavior of those methods and code matching those steps. Implementing the
     11        cancel() method required implementing the notion of "resetting pending tasks",
     12        which the Web Animations spec defines as well.
     13
     14        * animation/WebAnimation.cpp:
     15        (WebCore::WebAnimation::setEffect):
     16        (WebCore::WebAnimation::cancel):
     17        (WebCore::WebAnimation::resetPendingTasks):
     18        * animation/WebAnimation.h:
     19        * animation/WebAnimation.idl:
     20
    1212017-12-14  Jer Noble  <jer.noble@apple.com>
    222
  • trunk/Source/WebCore/animation/WebAnimation.cpp

    r225917 r225927  
    6868void WebAnimation::setEffect(RefPtr<AnimationEffect>&& effect)
    6969{
     70    // 3.4.3. Setting the target effect of an animation
     71    // https://drafts.csswg.org/web-animations-1/#setting-the-target-effect
     72
     73    // 2. If new effect is the same object as old effect, abort this procedure.
    7074    if (effect == m_effect)
    7175        return;
     76
     77    // 3. If new effect is null and old effect is not null, run the procedure to reset an animation's pending tasks on animation.
     78    if (!effect && m_effect)
     79        resetPendingTasks();
    7280
    7381    if (m_effect) {
     
    317325}
    318326
     327void WebAnimation::cancel()
     328{
     329    // 3.4.16. Canceling an animation
     330    // https://drafts.csswg.org/web-animations-1/#canceling-an-animation-section
     331    //
     332    // An animation can be canceled which causes the current time to become unresolved hence removing any effects caused by the target effect.
     333    //
     334    // The procedure to cancel an animation for animation is as follows:
     335    //
     336    // 1. If animation's play state is not idle, perform the following steps:
     337    if (playState() != PlayState::Idle) {
     338        // 1. Run the procedure to reset an animation's pending tasks on animation.
     339        resetPendingTasks();
     340
     341        // 2. Reject the current finished promise with a DOMException named "AbortError".
     342        m_finishedPromise.reject(Exception { AbortError });
     343
     344        // 3. Let current finished promise be a new (pending) Promise object.
     345        m_finishedPromise.clear();
     346
     347        // 4. Create an AnimationPlaybackEvent, cancelEvent.
     348        // 5. Set cancelEvent's type attribute to cancel.
     349        // 6. Set cancelEvent's currentTime to null.
     350        // 7. Let timeline time be the current time of the timeline with which animation is associated. If animation is not associated with an
     351        //    active timeline, let timeline time be n unresolved time value.
     352        // 8. Set cancelEvent's timelineTime to timeline time. If timeline time is unresolved, set it to null.
     353        // 9. If animation has a document for timing, then append cancelEvent to its document for timing's pending animation event queue along
     354        //    with its target, animation. If animation is associated with an active timeline that defines a procedure to convert timeline times
     355        //    to origin-relative time, let the scheduled event time be the result of applying that procedure to timeline time. Otherwise, the
     356        //    scheduled event time is an unresolved time value.
     357        // Otherwise, queue a task to dispatch cancelEvent at animation. The task source for this task is the DOM manipulation task source.
     358        enqueueAnimationPlaybackEvent(eventNames().cancelEvent, std::nullopt, m_timeline ? m_timeline->currentTime() : std::nullopt);
     359    }
     360
     361    // 2. Make animation's hold time unresolved.
     362    m_holdTime = std::nullopt;
     363
     364    // 3. Make animation's start time unresolved.
     365    setStartTime(std::nullopt);
     366}
     367
    319368void WebAnimation::enqueueAnimationPlaybackEvent(const AtomicString& type, std::optional<Seconds> currentTime, std::optional<Seconds> timelineTime)
    320369{
     
    335384        });
    336385    }
     386}
     387
     388void WebAnimation::resetPendingTasks()
     389{
     390    // The procedure to reset an animation's pending tasks for animation is as follows:
     391    // https://drafts.csswg.org/web-animations-1/#reset-an-animations-pending-tasks
     392    //
     393    // 1. If animation does not have a pending play task or a pending pause task, abort this procedure.
     394    if (!pending())
     395        return;
     396
     397    // 2. If animation has a pending play task, cancel that task.
     398    if (hasPendingPlayTask())
     399        setTimeToRunPendingPlayTask(TimeToRunPendingTask::NotScheduled);
     400
     401    // 3. If animation has a pending pause task, cancel that task.
     402    if (hasPendingPauseTask())
     403        setTimeToRunPendingPauseTask(TimeToRunPendingTask::NotScheduled);
     404
     405    // 4. Reject animation's current ready promise with a DOMException named "AbortError".
     406    m_readyPromise.reject(Exception { AbortError });
     407
     408    // 5. Let animation's current ready promise be the result of creating a new resolved Promise object.
     409    m_readyPromise.clear();
     410    m_readyPromise.resolve(*this);
    337411}
    338412
  • trunk/Source/WebCore/animation/WebAnimation.h

    r225917 r225927  
    7979    FinishedPromise& finished() { return m_finishedPromise; }
    8080
     81    void cancel();
    8182    ExceptionOr<void> finish();
    8283    ExceptionOr<void> play();
     
    121122    void runPendingPauseTask();
    122123    void runPendingPlayTask();
     124    void resetPendingTasks();
    123125   
    124126    RefPtr<AnimationEffect> m_effect;
  • trunk/Source/WebCore/animation/WebAnimation.idl

    r225917 r225927  
    4747    readonly attribute boolean pending;
    4848    attribute EventHandler onfinish;
     49    attribute EventHandler oncancel;
    4950    readonly attribute Promise<WebAnimation> ready;
    5051    readonly attribute Promise<WebAnimation> finished;
     52    void cancel();
    5153    [MayThrowException] void finish();
    5254    [MayThrowException] void play();
Note: See TracChangeset for help on using the changeset viewer.