Changeset 224163 in webkit


Ignore:
Timestamp:
Oct 29, 2017 1:22:34 PM (6 years ago)
Author:
graouts@webkit.org
Message:

[Web Animations] Expose the currentTime property on Animation
https://bugs.webkit.org/show_bug.cgi?id=178988

Reviewed by Dean Jackson.

Source/WebCore:

We now expose the currentTime property on Animation objects, our first
step in implementing the Web Animations timing model, specifically section
3.5.4. "The current time of an animation" and section 3.5.5. "Setting the
current time of an animation". Setting the startTime has implications on
currentTime and vice-versa.

Test: webanimations/animation-current-time.html

  • animation/WebAnimation.cpp:

(WebCore::WebAnimation::setBindingsStartTime):
(WebCore::WebAnimation::startTime const):
(WebCore::WebAnimation::setStartTime):
(WebCore::WebAnimation::bindingsCurrentTime const):
(WebCore::WebAnimation::setBindingsCurrentTime):
(WebCore::WebAnimation::currentTime const):
(WebCore::WebAnimation::setCurrentTime):

  • animation/WebAnimation.h:
  • animation/WebAnimation.idl:

LayoutTests:

Add a new test that checks that the currentTime property is set
correctly based on the startTime value and the document timeline
currentTime, and that setting the property may raise an exception
and otherwise update the animation startTime.

  • webanimations/animation-current-time-expected.txt: Added.
  • webanimations/animation-current-time.html: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r224158 r224163  
     12017-10-29  Antoine Quint  <graouts@apple.com>
     2
     3        [Web Animations] Expose the currentTime property on Animation
     4        https://bugs.webkit.org/show_bug.cgi?id=178988
     5
     6        Reviewed by Dean Jackson.
     7
     8        Add a new test that checks that the currentTime property is set
     9        correctly based on the startTime value and the document timeline
     10        currentTime, and that setting the property may raise an exception
     11        and otherwise update the animation startTime.
     12
     13        * webanimations/animation-current-time-expected.txt: Added.
     14        * webanimations/animation-current-time.html: Added.
     15
    1162017-10-28  Dean Jackson  <dino@apple.com>
    217
  • trunk/Source/WebCore/ChangeLog

    r224159 r224163  
     12017-10-29  Antoine Quint  <graouts@apple.com>
     2
     3        [Web Animations] Expose the currentTime property on Animation
     4        https://bugs.webkit.org/show_bug.cgi?id=178988
     5
     6        Reviewed by Dean Jackson.
     7
     8        We now expose the currentTime property on Animation objects, our first
     9        step in implementing the Web Animations timing model, specifically section
     10        3.5.4. "The current time of an animation" and section 3.5.5. "Setting the
     11        current time of an animation". Setting the startTime has implications on
     12        currentTime and vice-versa.
     13
     14        Test: webanimations/animation-current-time.html
     15
     16        * animation/WebAnimation.cpp:
     17        (WebCore::WebAnimation::setBindingsStartTime):
     18        (WebCore::WebAnimation::startTime const):
     19        (WebCore::WebAnimation::setStartTime):
     20        (WebCore::WebAnimation::bindingsCurrentTime const):
     21        (WebCore::WebAnimation::setBindingsCurrentTime):
     22        (WebCore::WebAnimation::currentTime const):
     23        (WebCore::WebAnimation::setCurrentTime):
     24        * animation/WebAnimation.h:
     25        * animation/WebAnimation.idl:
     26
    1272017-10-29  Ryosuke Niwa  <rniwa@webkit.org>
    228
  • trunk/Source/WebCore/animation/WebAnimation.cpp

    r224127 r224163  
    6969{
    7070    if (startTime == std::nullopt)
    71         m_startTime = std::nullopt;
     71        setStartTime(std::nullopt);
    7272    else
    73         m_startTime = Seconds(startTime.value());
     73        setStartTime(Seconds(startTime.value()));
     74}
     75
     76std::optional<Seconds> WebAnimation::startTime() const
     77{
     78    return m_startTime;
     79}
     80
     81void WebAnimation::setStartTime(std::optional<Seconds> startTime)
     82{
     83    if (startTime == m_startTime)
     84        return;
     85
     86    m_startTime = startTime;
     87}
     88
     89std::optional<double> WebAnimation::bindingsCurrentTime() const
     90{
     91    auto time = currentTime();
     92    if (!time)
     93        return std::nullopt;
     94    return time->value();
     95}
     96
     97ExceptionOr<void> WebAnimation::setBindingsCurrentTime(std::optional<double> currentTime)
     98{
     99    if (!currentTime)
     100        return Exception { TypeError };
     101    setCurrentTime(Seconds(currentTime.value()));
     102    return { };
     103}
     104
     105std::optional<Seconds> WebAnimation::currentTime() const
     106{
     107    // FIXME: return the hold time when we support pausing (webkit.org/b/178932).
     108
     109    if (!m_timeline || !m_startTime)
     110        return std::nullopt;
     111
     112    auto timelineTime = m_timeline->currentTime();
     113    if (!timelineTime)
     114        return std::nullopt;
     115
     116    // FIXME: account for playback rate when we support it (webkit.org/b/178931).
     117    return timelineTime.value() - m_startTime.value();
     118}
     119
     120void WebAnimation::setCurrentTime(std::optional<Seconds> seekTime)
     121{
     122    // FIXME: account for hold time when we support it (webkit.org/b/178932).
     123
     124    if (!m_timeline) {
     125        setStartTime(std::nullopt);
     126        return;
     127    }
     128
     129    std::optional<Seconds> timelineTime = m_timeline->currentTime();
     130    if (timelineTime == std::nullopt) {
     131        setStartTime(std::nullopt);
     132        return;
     133    }
     134
     135    // FIXME: account for playback rate when we support it (webkit.org/b/178931).
     136    setStartTime(timelineTime.value() - seekTime.value());
    74137}
    75138
  • trunk/Source/WebCore/animation/WebAnimation.h

    r224127 r224163  
    2626#pragma once
    2727
     28#include "ExceptionOr.h"
    2829#include <wtf/Forward.h>
    2930#include <wtf/Optional.h>
     
    4647    void setEffect(RefPtr<AnimationEffect>&&);
    4748    AnimationTimeline* timeline() const { return m_timeline.get(); }
     49
    4850    std::optional<double> bindingsStartTime() const;
    4951    void setBindingsStartTime(std::optional<double>);
    50     std::optional<Seconds> startTime() const { return m_startTime; }
    51     void setStartTime(Seconds startTime) { m_startTime = startTime; }
     52    std::optional<Seconds> startTime() const;
     53    void setStartTime(std::optional<Seconds>);
     54
     55    std::optional<double> bindingsCurrentTime() const;
     56    ExceptionOr<void> setBindingsCurrentTime(std::optional<double>);
     57    std::optional<Seconds> currentTime() const;
     58    void setCurrentTime(std::optional<Seconds>);
    5259
    5360    String description();
     
    5562private:
    5663    WebAnimation(AnimationTimeline*);
     64
    5765    RefPtr<AnimationEffect> m_effect;
    5866    RefPtr<AnimationTimeline> m_timeline;
  • trunk/Source/WebCore/animation/WebAnimation.idl

    r223883 r224163  
    3333    readonly attribute AnimationTimeline? timeline;
    3434    [ImplementedAs=bindingsStartTime] attribute double? startTime;
     35    [MayThrowException, ImplementedAs=bindingsCurrentTime] attribute double? currentTime;
    3536};
Note: See TracChangeset for help on using the changeset viewer.