Skip to content

Commit e56e77f

Browse files
Anders Hartvoll Ruudbirtles
Anders Hartvoll Ruud
authored andcommitted
[web-animations-1] Specify how to compute property values
When it comes to the term "computed value", the spec is currently very confused. It appears to be making several references to "the" computed value (as in [1]), when in reality the intention is (I believe) to apply the *process* that calculates the computed value ([1]) to the value specified (locally) in the keyframe. This process is not described in a reusable way anywhere (I think), so I've added the algorithm "compute a property value" for this. I'm using the term "property value", since it's already extensively used in this spec. Possibly it would be more suited for css-cascade, but I'm proposing it for this spec until we need it somewhere else. In general I want to maintain a clear distinction between when we mean the actual computed value [1], and when we mean some value that has undergone the "compute a property value" process. Hence, I think we should avoid referring to a value that has undergone the "compute a property value" process as "a" computed value, as it's too easily confused with *the* computed value. I've included some text and an examples that hopefully clarify the expected interpolation behavior a little bit. It seemed somewhat natural to place this in the "Computing property values" section, since resolving dependencies is part of the process when computing values. [1] https://drafts.csswg.org/css-cascade/#computed
1 parent 1387399 commit e56e77f

File tree

1 file changed

+66
-16
lines changed

1 file changed

+66
-16
lines changed

web-animations-1/Overview.bs

+66-16
Original file line numberDiff line numberDiff line change
@@ -3297,13 +3297,49 @@ If the <a>keyframe-specific composite operation</a> for a <a>keyframe</a>
32973297
is not set, the <a>composite operation</a> specified for the
32983298
<a>keyframe effect</a> as a whole is used for values specified in that keyframe.
32993299

3300+
### Computing property values ### {#computing-property-values}
3301+
3302+
<div algorithm>
3303+
To <dfn>compute a property value</dfn> given a property <var>property</var>,
3304+
a value <var>value</var>, and an {{Element}} <var>element</var>:
3305+
resolve <var>value</var> according to the "Computed Value" line of the
3306+
<var>property</var>'s definition table, using the <a>computed values</a> of
3307+
<var>element</var> as the context for resolving dependencies, and return the
3308+
result.
3309+
3310+
Note: The <a>computed values</a> on <var>element</var> are not affected by
3311+
this algorithm.
3312+
3313+
This algorithm implies that property values specified in keyframes can
3314+
establish order dependencies. When <a>computing a property value</a>, the
3315+
<a>computed values</a> of dependencies held by <var>value</var> must be
3316+
calculated <em>first</em>.
3317+
3318+
<div class="example">
3319+
<pre class="lang-javascript">
3320+
var animation = elem.animate([{ fontSize: '10px', width: '10em' },
3321+
{ fontSize: '20px', width: '20em' }], 1000);
3322+
animation.currentTime = 500;
3323+
console.log(getComputedStyle(elem).fontSize); // Should be 15px
3324+
console.log(getComputedStyle(elem).width); // Should be 225px
3325+
</pre>
3326+
In this example, in order to <a>compute a property value</a> for
3327+
<code>10em</code>, we must know the <a>computed value</a> of
3328+
'font-size' on the <a>target element</a>, which in turn is determined
3329+
by the <a>effect value</a> for 'font-size', which in turn requires that we
3330+
compute property values for 'font-size'. Hence, computing property
3331+
values are subject to ordering constraints.
3332+
</div>
3333+
3334+
</div>
3335+
33003336
### Calculating computed keyframes ### {#calculating-computed-keyframes}
33013337

33023338
Before calculating the <a>effect value</a> of a <a>keyframe effect</a>,
3303-
the property values specified on its <a>keyframes</a> are resolved to
3304-
<a>computed values</a>, and the offset to use for any keyframes with a null
3305-
<a>keyframe offset</a> is computed. The result of resolving these values is
3306-
a set of <dfn>computed keyframes</dfn>.
3339+
the property values on its <a>keyframes</a> are
3340+
<a href="#computing-property-values">computed</a>, and the offset to use for any
3341+
keyframes with a null <a>keyframe offset</a> is computed. The result of
3342+
resolving these values is a set of <dfn>computed keyframes</dfn>.
33073343

33083344
The calculated <a>keyframe offsets</a> of a set of <a>keyframe</a> that
33093345
includes suitable values for each null <a>keyframe offset</a> are referred
@@ -3367,24 +3403,25 @@ an <a>effect target</a> for which computed property values can be calculated.
33673403
1. Add a new empty <a>keyframe</a>, <var>computed keyframe</var>, to
33683404
<var>computed keyframes</var>.
33693405

3370-
1. For each property specified in <var>keyframe</var>, calculate the
3371-
computed value specified on <var>keyframe</var> using the <a>effect
3372-
target</a> as the context for computing values and add the
3373-
corresponding property and computed value to <var>computed
3374-
keyframe</var>.
3375-
For shorthand properties, add the equivalent longhand properties.
3376-
For logical properties [[!CSS-LOGICAL-1]], add the [=equivalent physical
3377-
properties=] [[!CSS-WRITING-MODES-4]] based on the computed value of
3378-
'writing-mode' and/or 'direction' for the <a>effect target</a>.
3406+
1. For each property specified in <var>keyframe</var>:
3407+
- <a>Compute a property value</a> using the value specified on
3408+
<var>keyframe</var> as the value, and the <a>target element</a> as
3409+
the element; then add the property and resulting value to
3410+
<var>computed keyframe</var>.
3411+
- For shorthand properties, add the equivalent longhand properties.
3412+
- For logical properties [[!CSS-LOGICAL-1]], add the [=equivalent physical
3413+
properties=] [[!CSS-WRITING-MODES-4]] based on the computed value of
3414+
'writing-mode' and/or 'direction' for the <a>effect target</a>.
33793415

33803416
For example, if <var>keyframe</var> has a value of &lsquo;12pt&rsquo;
3381-
for the 'border-width' property, the user agent may produce a computed
3382-
value of &lsquo;16px&rsquo; for each of the longhand properties:
3417+
for the 'border-width' property, the user agent may
3418+
<a>compute a property value</a>
3419+
of &lsquo;16px&rsquo; for each of the longhand properties:
33833420
'border-bottom-width', 'border-left-width', 'border-right-width', and
33843421
'border-top-width'.
33853422
As a result, <var>computed keyframe</var> would <em>not</em> have a
33863423
value for the 'border-width' property, but would instead include
3387-
each of the longhand properties, and each with the computed value,
3424+
each of the longhand properties, and each with the value
33883425
&lsquo;16px&rsquo;.
33893426

33903427
If conflicts arise when expanding shorthand properties or replacing
@@ -3568,6 +3605,19 @@ Note: this procedure permits overlapping <a>keyframes</a>.
35683605
or equal to 1 is the value of the first <a>keyframe</a> or the last
35693606
<a>keyframe</a> in <var>keyframes</var> respectively.
35703607

3608+
<div class="note">
3609+
Note that <a>computed keyframes</a> are "live": user-agents must behave
3610+
as if they are recreated every time the <a>effect value</a> is calculated.
3611+
3612+
For example, if there is an ongoing transition on the 'font-size' property
3613+
from <code>10px</code> to <code>20px</code>, a property value specified as
3614+
<code>1em</code> in a <a>keyframe</a> would during
3615+
<a href="#calculating-computed-keyframes">keyframe computation</a>
3616+
resolve against the <a>computed value</a> in the range
3617+
[<code>10px</code>, <code>20px</code>] produced by the transition on
3618+
'font-size'.
3619+
</div>
3620+
35713621
<div class="issue">
35723622
In the presence of certain timing functions, the input iteration
35733623
progress to an animation effect is not limited to the range [0, 1].

0 commit comments

Comments
 (0)