Skip to content

Commit 971196b

Browse files
kevers-googleKevin Ellis
andauthored
[web-animation-2] Making currentTime and startTime CSSNumerish (w3c#6479)
The animation attributes currentTime and startTime were nullable doubles and represented times in units of milliseconds. These units do not align well with progress based animations where it is more natural to work in percentages. With this change, progress based animations expect and report times as percentages. When setting current or start time, the value may be expressed as a double with implicit units of milliseconds, or as a CSSNumericValue with duration units ('s' or 'ms') when the animation is associated with a time based timeline. Co-authored-by: Kevin Ellis <kevers@chromium.org>
1 parent 574385b commit 971196b

1 file changed

Lines changed: 104 additions & 22 deletions

File tree

web-animations-2/Overview.bs

Lines changed: 104 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ Add:
171171
> 1. If the [=iteration duration=] is auto, then perform the following steps.
172172
> * Set [=start delay=] and [=end delay=] to 0, as it is not
173173
> possible to mix time and proportions.
174-
>
174+
>
175175
> Note: Future versions may allow these properties to be assigned
176176
> percentages, at which point the delays are only to be ignored if
177177
> their values are expressed as times and not as percentages.
178-
>
178+
>
179179
> Otherwise:
180180
> 1. Let <var>total time</var> be equal to |end time|
181181
> 1. Set [=start delay=] to be the result of evaluating
@@ -256,7 +256,7 @@ follows:
256256

257257
: If |previous play state| is 'paused':
258258

259-
:: If |previous progress| is resolved:
259+
:: If |previous progress| is resolved:
260260

261261
1. Set the flag |reset current time on resume| to true.
262262
1. Set [=start time=] to unresolved.
@@ -338,6 +338,36 @@ descendant effects and custom effects such that the first condition is:
338338
> effect</a> or executing any <a>custom effects</a> associated with an
339339
> <a>animation effect</a>.
340340

341+
<h4 id='validating-a-css-numberish-time'>Validating a CSSNumberish time</h4>
342+
343+
The procedure to <dfn>validate a CSSNumberish time</dfn> for an input
344+
value of <var>time</var> is based on the first condition that matches:
345+
346+
<dl class="switch">
347+
348+
: If <em>all</em> of the following conditions are true:
349+
350+
* The animation is associated with a [=progress-based timeline=], and
351+
* <var>time</var> is not a CSSNumeric value with percent units:
352+
353+
:: <a>throw</a> a <span class="exceptionname">TypeError</span>.
354+
:: return false;
355+
356+
: If <em>all</em> of the following conditions are true:
357+
358+
* The animation is not associated with a [=progress-based timeline=],
359+
and
360+
* <var>time</var> is a CSSNumericValue, and
361+
* the units of time are not <a type lt="<time>">duration units</a>:
362+
363+
:: <a>throw</a> a <span class="exceptionname">TypeError</span>.
364+
:: return false.
365+
366+
: Oterwise
367+
:: return true.
368+
369+
</dl>
370+
341371

342372
<h4 id='setting-the-current-time-of-an-animation'>Setting the current time of an
343373
Animation</h4>
@@ -357,31 +387,39 @@ an animation, <var>animation</var>, to <var>seek time</var> is as follows:
357387

358388
1. Abort these steps.
359389

360-
1. Update either <var>animation</var>'s <a>hold time</a> or
361-
[=start time=] as follows:
390+
1. Let <var>valid seek time</var> be the result of running the
391+
[=validate a CSSNumberish time=] procedure with <var>seek time</var>
392+
as the input.
362393

363-
<dl class="switch">
394+
1. If <var>valid seek time</var> is false, abort this procedure.
364395

365-
: If <em>any</em> of the following conditions are true:
396+
1. Update either <var>animation</var>'s <a>hold time</a> or
397+
[=start time=] as follows:
366398

367-
* <var>animation</var>'s <a>hold time</a> is
368-
<a lt="unresolved">resolved</a>, or
369-
* <var>animation</var>'s [=start time=]
370-
is <a lt="unresolved">unresolved</a>, or
371-
* <var>animation</var> has no associated <a>timeline</a> or the
372-
associated <a>timeline</a> is
373-
<a lt="inactive timeline">inactive</a>, or
374-
* <var>animation</var>'s [=playback rate=] is 0,
399+
<dl class="switch">
375400

376-
:: Set <var>animation</var>'s <a>hold time</a> to <var>seek time</var>.
401+
: If <em>any</em> of the following conditions are true:
377402

378-
: Otherwise,
379-
:: Set <var>animation</var>'s [=start time=] to the result of evaluating
380-
<code>|timeline time| - (|seek time| / [=playback rate=])</code>
381-
where <var>timeline time</var> is the current <a>time value</a>
382-
of <a>timeline</a> associated with <var>animation</var>.
403+
* <var>animation</var>'s <a>hold time</a> is
404+
<a lt="unresolved">resolved</a>, or
405+
* <var>animation</var>'s [=start time=]
406+
is <a lt="unresolved">unresolved</a>, or
407+
* <var>animation</var> has no associated <a>timeline</a> or
408+
the associated <a>timeline</a> is
409+
<a lt="inactive timeline">inactive</a>, or
410+
* <var>animation</var>'s [=playback rate=] is 0,
383411

384-
</dl>
412+
:: Set <var>animation</var>'s <a>hold time</a> to
413+
<var>seek time</var>.
414+
415+
: Otherwise,
416+
:: Set <var>animation</var>'s [=start time=] to the result of
417+
evaluating
418+
<code>|timeline time| - (|seek time| / [=playback rate=])</code>
419+
where <var>timeline time</var> is the current <a>time value</a>
420+
of <a>timeline</a> associated with <var>animation</var>.
421+
422+
</dl>
385423

386424
1. If <var>animation</var> has no associated <a>timeline</a> or the associated
387425
<a>timeline</a> is <a lt="inactive timeline">inactive</a>,
@@ -423,6 +461,12 @@ The procedure to <dfn>set the start time</dfn>
423461
of <a>animation</a>, <var>animation</var>, to <var>new start time</var>,
424462
is as follows:
425463

464+
1. Let <var>valid start time</var> be the result of running the
465+
[=validate a CSSNumberish time=] procedure with
466+
<var>new start time</var> as the input.
467+
468+
1. If <var>valid start time</var> is false, abort this procedure.
469+
426470
1. Let <var>timeline time</var> be the current <a>time value</a> of the
427471
<a>timeline</a> that <var>animation</var> is associated with.
428472
If there is no <a>timeline</a> associated with <var>animation</var> or the
@@ -2018,6 +2062,44 @@ partial interface AnimationTimeline {
20182062

20192063
</div>
20202064

2065+
<h3 id="the-animation-interface">The <code>Animation</code> interface</h3>
2066+
2067+
Update the startTime and currentTime of the Animation interface as follows:
2068+
2069+
<pre class="idl">
2070+
[Exposed=Window]
2071+
partial interface Animation : EventTarget {
2072+
attribute CSSNumberish? startTime;
2073+
attribute CSSNumberish? currentTime;
2074+
};
2075+
</pre>
2076+
2077+
Replace [=start time=] and [=current time=] attribute descriptions with:
2078+
2079+
<div class='attributes'>
2080+
2081+
: <dfn attribute for=Animation>startTime</dfn>
2082+
:: Update the description as:
2083+
2084+
> The [=start time=] of this animation. When associated with a
2085+
> [=progress-based timeline=], [=start time=] must be returned as a
2086+
> {{CSSNumericValue}} with percent units. Otherwise [=start time=] must be
2087+
> returned as a double value, representing the time in units of
2088+
> milliseconds. Setting this attribute updates the [=start time=] using the
2089+
> procedure to <a>set the start time</a> of this object to the new value.
2090+
2091+
: <dfn attribute for=Animation>currentTime</dfn>
2092+
:: update the description as:
2093+
2094+
> The <a>current time</a> of this animation. When associated with a
2095+
> [=progress-based timeline=], <a>current time</a> must be returned as a
2096+
> {{CSSNumericValue}}. with percent units. Otherwise <a>current time</a>
2097+
> must be returned as a double value, representing the time in units of
2098+
> milliseconds. Setting this attribute follows the procedure to
2099+
> <a>set the current time</a> of this object to the new value.
2100+
2101+
</div>
2102+
20212103
<h3 id="the-animationeffect-interface">The <code>AnimationEffect</code> interface</h3>
20222104

20232105
<pre class='idl'>

0 commit comments

Comments
 (0)