Skip to content

[web-animation-2] Making currentTime and startTime CSSNumerish #6479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Sep 21, 2021

Conversation

kevers-google
Copy link
Contributor

[web-animation-2] Making currentTime and startTime CSSNumerish

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 non-monotonic timeline.

issue #6458

[=validate a CSSNumberish time=] procedure with <var>seek time</var>
as the input.

1. If valid seek time is false, abort this procedure.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, <var>valid seek time</var>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

[=validate a CSSNumberish time=] procedure with
<var>new start time</var> as the input.

1. If valid start time is false, abort this procedure.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: <var>valid start time</var>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

[=progress-based timeline=], [=start time=] must be returned as a
<a href="https://drafts.css-houdini.org/css-typed-om/#cssnumericvalue">
CSSNumericValue</a> with percent units. Otherwise [=start time=] must be
returned as a double value, representing the time in units of milliseconds.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels a little out of place to declare in the interface the types that must be returned. I would have expected these types to be the implicit result of starting an animation on or switching an animation to a progress based timeline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CSSNumerish is naturally ambiguous since it could be a double or a CSSNumericValue, and when expressed as a CSSNumericValue it could have any compatible units (e.g. 's' vs 'ms'). Internally, it doesn't matter how we should express time, but should have a canonical form for API return values. Perhaps this belong in a normalization procedure that is called at the end of "getting the current/start time".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this should be clarified in an addendum to https://www.w3.org/TR/web-animations-1/#time-value-section.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is why Typed OM never uses CSSNumberish for method return types, and when it uses it for an attribute, it's very explicit about what is returned by the getter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, sounds like it is appropriate to be explicit here about the type that should be expected.


: If <em>all</em> of the following conditions are true:
* The animation is not associated with a [=progress-based timeline=],
amd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

* The animation is not associated with a [=progress-based timeline=],
amd
* <var>time</var> is a CSSNumericValue:
* The units of time are not <a href="https://www.w3.org/TR/css3-values/#time">duration units</a>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Links to other specs should use autolinks https://tabatkins.github.io/bikeshed/#autolink-biblio

E.g. This particular case would be [[CSS3-VALUES#time|duration units]]

Copy link
Member

@tabatkins tabatkins Aug 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that would produce a section link, which is only very slightly less fragile than a direct link, as it just protects you against the possibility of the Values 3 url being changed at some point. You probably actually want <a type lt="<time>">duration units</a>, to link to the definition of those units whereever they may be.

(You should be able to write <<time|duration units>>, but I haven't yet landed the fix harmonizing the parsing of all linking shorthands, ugh.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

:: Update the description as:
> The [=start time=] of this animation. When associated with a
> [=progress-based timeline=], [=start time=] must be returned as a
> <a href="https://drafts.css-houdini.org/css-typed-om/#cssnumericvalue">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below, replace with {{CSSNumericValue}}.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


: If <em>all</em> of the following conditions are true:
* The animation is not associated with a [=progress-based timeline=],
and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an incorrect indent. Bikeshed requires a 4-space (or tab) indent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

<div class='attributes'>
: <dfn attribute for=Animation>startTime</dfn>
:: Update the description as:
> The [=start time=] of this animation. When associated with a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is nested in a list this requires more indentation, The '>' needs to be aligned with Update on the line above. There's an example with delay and endDelay below, e.g.

 ::  Update the description as:
     > The [=start time=] of this animation. When associated with a
     > [=progress-based timeline=], [=start time=] must be returned as a
     > {{CSSNumericValue}} with percent units. Otherwise [=start time=] must be

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list as a whole is indented incorrectly - for some reason it has a 1-space indent before each item, which doesn't do anything but does make the subsequent 4-space indents also misaligned. It should be indented one level from the container div, and then yeah, the blockquote would need two levels to nest it under the dd properly.

Just use tab indents; humans can't reliably space-indent to save their lives. ^_^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have much experience with tab indenting specs but I'll take your word that it's simpler. I guess it takes away the temptation to use anything less than a full tab indent ^_^. I take it I should update #6565 (review) or follow up with another PR to do this for the whole spec and then we can update this to match.

> be returned as a double value, representing the time in units of
> milliseconds. Setting this attribute follows the procedure to
> <a>set the current time</a> of this object to the new value.
</div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline before to separate it from the block above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

> <a>set the start time</a> of this object to the new value.
: <dfn attribute for=Animation>currentTime</dfn>
:: update the description as:
> The <a>current time</a> of this animation. When associated with a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same indentation issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor Author

@kevers-google kevers-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent issues should all be resolved now. Formatting glitches with dl.switch have also been addressed.

> be returned as a double value, representing the time in units of
> milliseconds. Setting this attribute follows the procedure to
> <a>set the current time</a> of this object to the new value.
</div>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

dl.switch > dt > ul > li {
text-indent: 0;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tabatkins there seems to be issues with the generated bikeshed css when we switched to dl instead of just the div. You can see the issue at this link which @kevers-google is trying to work around here. Do you know if there's something wrong with the spec formatting or generator?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide more details on what's wrong? I see that the "switch icon" is on its own line (unavoidable given the way it's injected, since the dt contains block elements), but it doesn't look like that's what your CSS is trying to mess with.

Copy link
Contributor

@flackr flackr Sep 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bullets in the list are also incorrectly indented. See https://drafts.csswg.org/web-animations-1/#setting-the-current-time-of-an-animation for comparison. web-animations-1 seems to be using <div class="switch">: https://github.com/w3c/csswg-drafts/blob/main/web-animations-1/Overview.bs#L957

Copy link
Contributor Author

@kevers-google kevers-google Sep 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The switch being on it's own line was resolved by the rule:

dl.switch > [data-md] > p {
display: inline;
}

This aligns with a rule we have in web-animations-1, namely:

div.switch > dl > dt > p {
display: inline;
}

The overlap resulted from the following rules in base.css:

dl.switch > dt {
text-indent: -1.5em;
}

When applied to a paragraph inside a list item, it creates an overlap between the paragraph and the marker.

web-animation-1 controls the indent within a switch via these rules:

div.switch > dl > dt:before {
margin-left: -1.3em;
}

div.switch > dl {
padding-left: 2em;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, huh, I see that base.css is doing some weird text-indent stuff. I... don't understand why it's doing that; it appears to only work well on single-line dts, and makes structured ones like this look weird. @fantasai, I don't remember if this style was imported from Bikeshed's stylesheet or done by you, any idea?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the style changes to a separate PR to unblock the remainder of the changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style changes moved to #6655.

evaluating
<code>|timeline time| - (|seek time| / [=playback rate=])</code>
where <var>timeline time</var> is the current <a>time value</a>
of <a>timeline</a> associated with <var>animation</var>.

</dl>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the indentation level here doesn't match the opening tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@flackr flackr merged commit 971196b into w3c:main Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants