Skip to content

Commit a3e0854

Browse files
committed
[css-variables] Specify how variables interact with shorthand expansion/serialization.
1 parent 82a2eca commit a3e0854

File tree

2 files changed

+62
-7
lines changed

2 files changed

+62
-7
lines changed

css-variables/Overview.html

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</a></p>
1313
<h1 class="p-name no-ref" id=title>CSS Custom Properties for Cascading Variables Module Level 1</h1>
1414
<h2 class="no-num no-toc no-ref heading settled heading" id=subtitle><span class=content>Editor’s Draft,
15-
<span class=dt-updated><span class=value-title title=20130828>28 August 2013</span></span></span></h2>
15+
<span class=dt-updated><span class=value-title title=20130829>29 August 2013</span></span></span></h2>
1616
<div data-fill-with=spec-metadata><dl><dt>This version:<dd><a class=u-url href=http://dev.w3.org/csswg/css-variables/>http://dev.w3.org/csswg/css-variables/</a><dt>Latest version:<dd><a href=http://www.w3.org/TR/css-variables-1/>http://www.w3.org/TR/css-variables-1/</a><dt>Editor’s Draft:<dd><a href=http://dev.w3.org/csswg/css-variables/>http://dev.w3.org/csswg/css-variables/</a><dt>Previous Versions:<dd><a href=http://www.w3.org/TR/2013/WD-css-variables-20130312/ rel=previous>http://www.w3.org/TR/2013/WD-css-variables-20130312/</a><dd><a href=http://www.w3.org/TR/2012/WD-css-variables-20120410/ rel=previous>http://www.w3.org/TR/2012/WD-css-variables-20120410/</a>
1717
<dt>Feedback:</dt>
1818
<dd><a href="mailto:www-style@w3.org?subject=%5Bcss-variables%5D%20feedback">www-style@w3.org</a>
@@ -72,7 +72,8 @@ <h2 class="no-num no-toc no-ref heading settled heading" id=contents><span class
7272
Using Custom Properties</a><li><a href=#cycles><span class=secno>2.3</span>
7373
Resolving Dependency Cycles</a></ul><li><a href=#using-variables><span class=secno>3</span>
7474
Using Cascading Variables: the <span class=css data-link-type=maybe>var()</span> notation</a><ul class=toc><li><a href=#invalid-variables><span class=secno>3.1</span>
75-
Invalid Variables</a></ul><li><a href=#cssom><span class=secno>4</span>
75+
Invalid Variables</a><li><a href=#variables-in-shorthands><span class=secno>3.2</span>
76+
Variables in Shorthand Properties</a></ul><li><a href=#cssom><span class=secno>4</span>
7677
APIs</a><ul class=toc><li><a href=#the-cssstyledeclaration-interface><span class=secno>4.1</span>
7778
Extensions to the <code>CSSStyleDeclaration</code> Interface</a><ul class=toc><li><a href=#serializing-custom-props><span class=secno>4.1.1</span>
7879
Serializing Custom Properties</a></ul><li><a href=#the-CSSVariablesMap-interface><span class=secno>4.2</span>
@@ -232,12 +233,12 @@ <h3 class="heading settled heading" data-level=2.1 id=syntax><span class=secno>2
232233
like the enclosing style rule,
233234
when reserialized.
234235

235-
<p class=note> Note: Custom properties can contain a trailing <span class=css data-link-type=maybe>!important</span>,
236+
<p class=note> Note: Custom properties can contain a trailing <a class=css data-link-type=maybe href=http://dev.w3.org/csswg/css-cascade-3/#important>!important</a>,
236237
but this is automatically removed from the property’s value by the CSS parser,
237238
and makes the custom property "important" in the CSS cascade.
238239
In other words, the prohibition on top-level "!" characters
239-
does not prevent <span class=css data-link-type=maybe>!important</span> from being used,
240-
as the <span class=css data-link-type=maybe>!important</span> is removed before syntax checking happens.
240+
does not prevent <a class=css data-link-type=maybe href=http://dev.w3.org/csswg/css-cascade-3/#important>!important</a> from being used,
241+
as the <a class=css data-link-type=maybe href=http://dev.w3.org/csswg/css-cascade-3/#important>!important</a> is removed before syntax checking happens.
241242

242243
<p class=note> Note: While <a class=production data-link-type=type href=#typedef-any-value>&lt;any-value&gt;</a> must represent at least one token,
243244
that one token may be whitespace.
@@ -612,6 +613,39 @@ <h3 class="heading settled heading" data-level=3.1 id=invalid-variables><span cl
612613
so by the time the user agent realizes a property value is invalid,
613614
it’s already thrown away the other cascaded values.
614615

616+
<h3 class="heading settled heading" data-level=3.2 id=variables-in-shorthands><span class=secno>3.2 </span><span class=content>
617+
Variables in Shorthand Properties</span><a class=self-link href=#variables-in-shorthands></a></h3>
618+
619+
<p> The use of <a href=#cascading-variable>variables</a> in <a href=http://dev.w3.org/csswg/css-cascade-3/#shorthand-properties>shorthand properties</a> presents some unique difficulties.
620+
621+
<p> Ordinarily, the value of a shorthand property is separated out into its component <a href=http://dev.w3.org/csswg/css-cascade-3/#longhand-sub-properties>longhand properties</a> at parse time,
622+
and then the longhands themselves participate in the <a href=http://dev.w3.org/csswg/css-cascade-3/#cascade>cascade</a>,
623+
with the shorthand more-or-less discarded.
624+
If a <a href=#cascading-variable>variable</a> is used in a shorthand, however,
625+
one can’t tell what values are meant to go where;
626+
it may in fact be impossible to separate it out at parse time,
627+
as a single <a href=#cascading-variable>variable</a> may substitute in the value of several longhands at once.
628+
629+
<p> To get around this,
630+
implementations must fill in longhands with a special, unobservable-to-authors <dfn data-dfn-type=dfn data-export="" id=pending-variable-substitution-value>pending variable-substitution value<a class=self-link href=#pending-variable-substitution-value></a></dfn>
631+
that indicates the shorthand contains a variable,
632+
and thus the longhand’s value is pending variable substitution.
633+
This value must then be cascaded as normal,
634+
and at computed-value time,
635+
after <a href=#cascading-variable>variables</a> are finally substituted in,
636+
the shorthand must be parsed and the longhands must be given their appropriate values at that point.
637+
638+
<p> <a href=#pending-variable-substitution-value>Pending variable-substitution values</a> must be serialized as the empty string,
639+
if an API allows them to be observed.
640+
641+
<p> Similarly,
642+
while <a data-biblio-type=informative data-link-type=biblio href=#cssom title=CSSOM>[CSSOM]</a> defines that shorthand properties are serialized
643+
by appropriately concatenating the values of their corresponding longhands,
644+
shorthands containing <a href=#cascading-variable>variables</a> must instead retain their original, <a class=css data-link-type=maybe href=#funcdef-var>var()</a>-containing, value.
645+
If serializing a shorthand’s value would involve serializing a <a href=#pending-variable-substitution-value>pending variable-substitution value</a>,
646+
the shorthand must instead be serialized by serializing its original value.
647+
648+
615649
<!--
616650
AAA PPPPPPPPPPPPPPPPP IIIIIIIIII
617651
A:::A P::::::::::::::::P I::::::::I
@@ -946,7 +980,7 @@ <h3 class="no-num no-ref heading settled heading" id=normative><span class=conte
946980

947981
<h3 class="no-num no-ref heading settled heading" id=informative><span class=content>
948982
Informative References</span><a class=self-link href=#informative></a></h3>
949-
<div data-fill-with=informative-references><dl><dt id=css3color title=CSS3COLOR><a class=self-link href=#css3color></a>[CSS3COLOR]<dd>Tantek Çelik; Chris Lilley; L. David Baron. <a href=http://www.w3.org/TR/2011/REC-css3-color-20110607>CSS Color Module Level 3</a>. 7 June 2011. W3C Recommendation. URL: <a href=http://www.w3.org/TR/2011/REC-css3-color-20110607>http://www.w3.org/TR/2011/REC-css3-color-20110607</a></dl></div>
983+
<div data-fill-with=informative-references><dl><dt id=css3color title=CSS3COLOR><a class=self-link href=#css3color></a>[CSS3COLOR]<dd>Tantek Çelik; Chris Lilley; L. David Baron. <a href=http://www.w3.org/TR/2011/REC-css3-color-20110607>CSS Color Module Level 3</a>. 7 June 2011. W3C Recommendation. URL: <a href=http://www.w3.org/TR/2011/REC-css3-color-20110607>http://www.w3.org/TR/2011/REC-css3-color-20110607</a><dt id=cssom title=CSSOM><a class=self-link href=#cssom></a>[CSSOM]<dd>Anne van Kesteren. <a href=http://www.w3.org/TR/2011/WD-cssom-20110712/>CSSOM</a>. 12 July 2011. W3C Working Draft. (Work in progress.) URL: <a href=http://www.w3.org/TR/2011/WD-cssom-20110712/>http://www.w3.org/TR/2011/WD-cssom-20110712/</a></dl></div>
950984

951985
<h2 class="no-num no-ref heading settled heading" id=index><span class=content>
952986
Index</span><a class=self-link href=#index></a></h2>
@@ -960,6 +994,7 @@ <h2 class="no-num no-ref heading settled heading" id=index><span class=content>
960994
<li>custom property, <a href=#custom-property title="section 2">2</a>
961995
<li>invalid at computed-value time, <a href=#invalid-at-computed-value-time title="section 3.1">3.1</a>
962996
<li>invalid variable, <a href=#invalid-variable title="section 3.1">3.1</a>
997+
<li>pending variable-substitution value, <a href=#pending-variable-substitution-value title="section 3.2">3.2</a>
963998
<li>resolve a variable, <a href=#resolve-a-variable title="section 3">3</a>
964999
<li>var(), <a href=#funcdef-var title="section 3">3</a>
9651000
<li>variable, <a href=#cascading-variable title="section 2.2">2.2</a>

css-variables/Overview.src.html

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,14 +576,34 @@ <h3 id=variables-in-shorthands>
576576

577577
The use of <a>variables</a> in <a>shorthand properties</a> presents some unique difficulties.
578578

579-
Ordinarily, the value of a shorthand property is separated out into its component longhands at parse time,
579+
Ordinarily, the value of a shorthand property is separated out into its component <a>longhand properties</a> at parse time,
580580
and then the longhands themselves participate in the <a>cascade</a>,
581581
with the shorthand more-or-less discarded.
582582
If a <a>variable</a> is used in a shorthand, however,
583583
one can't tell what values are meant to go where;
584584
it may in fact be impossible to separate it out at parse time,
585585
as a single <a>variable</a> may substitute in the value of several longhands at once.
586586

587+
To get around this,
588+
implementations must fill in longhands with a special, unobservable-to-authors <dfn export>pending variable-substitution value</dfn>
589+
that indicates the shorthand contains a variable,
590+
and thus the longhand's value is pending variable substitution.
591+
This value must then be cascaded as normal,
592+
and at computed-value time,
593+
after <a>variables</a> are finally substituted in,
594+
the shorthand must be parsed and the longhands must be given their appropriate values at that point.
595+
596+
<a>Pending variable-substitution values</a> must be serialized as the empty string,
597+
if an API allows them to be observed.
598+
599+
Similarly,
600+
while [[CSSOM]] defines that shorthand properties are serialized
601+
by appropriately concatenating the values of their corresponding longhands,
602+
shorthands containing <a>variables</a> must instead retain their original, ''var()''-containing, value.
603+
If serializing a shorthand's value would involve serializing a <a>pending variable-substitution value</a>,
604+
the shorthand must instead be serialized by serializing its original value.
605+
606+
587607
<!--
588608
AAA PPPPPPPPPPPPPPPPP IIIIIIIIII
589609
A:::A P::::::::::::::::P I::::::::I

0 commit comments

Comments
 (0)