Skip to content

Commit f5bf7ca

Browse files
author
Simon Pieters
committed
[cssom] Handle shorthands in setProperty and getPropertyValue. Serialization still needs fixing though.
1 parent 4a08c3c commit f5bf7ca

2 files changed

Lines changed: 63 additions & 17 deletions

File tree

cssom/Overview.html

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,7 +2246,6 @@ <h4 id="the-cssstyledeclaration-interface"><span class="secno">6.5.1 </span>The
22462246
<p>The <dfn id="dom-cssstyledeclaration-setproperty" title="dom-CSSStyleDeclaration-setProperty"><code>setProperty(<var>property</var>, <var>value</var>,
22472247
<var>priority</var>)</code></dfn> method must run these steps:</p>
22482248
<ol>
2249-
<!-- XXX handle shorthands better -->
22502249
<li><p>If the <a href="#concept-css-declaration-block-readonly-flag" title="concept-css-declaration-block-readonly-flag">readonly flag</a> is set, <a class="external" data-anolis-spec="dom" href="http://dom.spec.whatwg.org/#concept-throw" title="concept-throw">throw</a>
22512250
an <code class="external" data-anolis-spec="dom"><a href="http://dom.spec.whatwg.org/#nomodificationallowederror">NoModificationAllowedError</a></code> exception and terminate these steps.</li>
22522251
<li><p>Let <var>property</var> be <var>property</var> <a class="external" data-anolis-spec="dom" href="http://dom.spec.whatwg.org/#converted-to-ascii-lowercase">converted to ASCII lowercase</a>.
@@ -2257,11 +2256,29 @@ <h4 id="the-cssstyledeclaration-interface"><span class="secno">6.5.1 </span>The
22572256
<li><p>If <var>priority</var> is neither an <a class="external" data-anolis-spec="dom" href="http://dom.spec.whatwg.org/#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">important</code>"
22582257
nor the empty string terminate this algorithm.</li>
22592258
<li>
2260-
<p>If <a href="#parse-a-css-value" title="parse a CSS value">parsing</a> <var>value</var> returns null terminate this algorithm.
2261-
<p class="note"><var>value</var> can not include "<code title="">!important</code>".</p>
2259+
<p>Let <var>component value list</var> be the result of <a href="#parse-a-css-value" title="parse a CSS value">parsing</a> <var>value</var>.
2260+
<p class="note"><var>value</var> can not include "<code title="">!important</code>".</p>
22622261
</li>
2263-
<li><p>Finally, set <var>property</var> to <var>value</var> with the <i>important</i> flag set if <var>priority</var> is not the empty
2264-
string, and unset otherwise.</li>
2262+
<li><p>If <var>component value list</var> is null terminate these steps.
2263+
<li><p>If <var>property</var> is a shorthand property, then for each longhand property <var>longhand</var> that <var>property</var> maps to, in canonical
2264+
order, <a href="#set-a-css-property" title="set a CSS property">set the CSS property</a> <var>longhand</var> to the appropriate value(s) from <var>component value list</var>, with
2265+
the <var>important</var> flag set if <var>priority</var> is not the empty string, and with the list of declarations being the
2266+
<a href="#concept-css-declaration-block-declarations" title="concept-css-declaration-block-declarations">declarations</a>.
2267+
<li><p>Otherwise, <a href="#set-a-css-property" title="set a CSS property">set the CSS property</a> <var>property</var> to <var>component value list</var>, with
2268+
the <var>important</var> flag set if <var>priority</var> is not the empty string, and with the list of declarations being the
2269+
<a href="#concept-css-declaration-block-declarations" title="concept-css-declaration-block-declarations">declarations</a>.
2270+
</ol>
2271+
2272+
<p>To <dfn id="set-a-css-property">set a CSS property</dfn> <var>property</var> to a value <var>component value list</var> and optionally with an <var>important</var> flag set, in a
2273+
list of declarations <var>declarations</var>, follow these steps:
2274+
2275+
<ol>
2276+
<li><p>If <var>property</var> is a <a class="external" data-anolis-spec="dom" href="http://dom.spec.whatwg.org/#case-sensitive">case-sensitive</a> match for a property of a declaration in
2277+
<var>declarations</var>, let <var>declaration</var> be that declaration.
2278+
<li><p>Otherwise, append a new declaration with the property name <var>property</var> to <var>declarations</var> and let <var>declaration</var> be that
2279+
declaration.
2280+
<li><p>Set <var>declaration</var>'s value to <var>component value list</var>.
2281+
<li><p>Set the declaration's <i>important</i> flag if <var>important</var> is set, or unset it otherwise.
22652282
</ol>
22662283

22672284
<p>The <dfn id="dom-cssstyledeclaration-removeproperty" title="dom-CSSStyleDeclaration-removeProperty"><code>removeProperty(<var>property</var>)</code></dfn> method must run these steps:</p>

cssom/Overview.src.html

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,13 +2131,23 @@ <h4>The <code title>CSSStyleDeclaration</code> Interface</h4>
21312131

21322132
<p>The <dfn title=dom-CSSStyleDeclaration-getPropertyValue><code>getPropertyValue(<var>property</var>)</code></dfn> method must run these steps:</p>
21332133
<ol>
2134-
<!-- XXX handle shorthands better -->
21352134
<li><p>Let <var>property</var> be <var>property</var> <span data-anolis-spec=dom>converted to ASCII lowercase</span>.
2135+
<li><p>If <var>property</var> is a shorthand property, then follow these substeps:
2136+
<ol>
2137+
<li><p>Let <var>list</var> be a new empty array.
2138+
<li><p>For each longhand property <var>longhand</var> that <var>property</var> maps to, in canonical order, follow these substeps:
2139+
<ol>
2140+
<li><p>If <var>longhand</var> is a <span data-anolis-spec=dom>case-sensitive</span> match for a property of a declaration in the
2141+
<span title=concept-css-declaration-block-declarations>declarations</span>, let <var>declaration</var> be that declaration, or null otherwise.
2142+
<li><p>If <var>declaration</var> is null, return the empty string and terminate these steps.
2143+
<li><p>Append the <var>declaration</var> to <var>list</var>.
2144+
</ol>
2145+
<li><p>Return the <span title='serialize a CSS value'>serialization</span> of <var>list</var> and terminate these steps.
2146+
</ol>
21362147
<li><p>If <var>property</var> is a <span data-anolis-spec=dom>case-sensitive</span>
21372148
match for a property of a declaration in the
2138-
<span title=concept-css-declaration-block-declarations>declarations</span>, return the
2139-
<span title='serialize a CSS value'>serialization</span> of that declaration's
2140-
value.
2149+
<span title=concept-css-declaration-block-declarations>declarations</span>, return the result of invoking
2150+
<span>serialize a CSS value</span> of that declaration and terminate these steps.
21412151
<li><p>Return the empty string.
21422152
</ol>
21432153

@@ -2168,7 +2178,6 @@ <h4>The <code title>CSSStyleDeclaration</code> Interface</h4>
21682178
<p>The <dfn title=dom-CSSStyleDeclaration-setProperty><code>setProperty(<var>property</var>, <var>value</var>,
21692179
<var>priority</var>)</code></dfn> method must run these steps:</p>
21702180
<ol>
2171-
<!-- XXX handle shorthands better -->
21722181
<li><p>If the <span title=concept-css-declaration-block-readonly-flag>readonly flag</span> is set, <span data-anolis-spec=dom title=concept-throw>throw</span>
21732182
an <code data-anolis-spec=dom>NoModificationAllowedError</code> exception and terminate these steps.</li>
21742183
<li><p>Let <var>property</var> be <var>property</var> <span data-anolis-spec=dom>converted to ASCII lowercase</span>.
@@ -2179,11 +2188,29 @@ <h4>The <code title>CSSStyleDeclaration</code> Interface</h4>
21792188
<li><p>If <var>priority</var> is neither an <span data-anolis-spec=dom>ASCII case-insensitive</span> match for the string "<code title>important</code>"
21802189
nor the empty string terminate this algorithm.</p></li>
21812190
<li>
2182-
<p>If <span title='parse a CSS value'>parsing</span> <var>value</var> returns null terminate this algorithm.
2183-
<p class='note'><var>value</var> can not include "<code title>!important</code>".</p>
2191+
<p>Let <var>component value list</var> be the result of <span title='parse a CSS value'>parsing</span> <var>value</var>.
2192+
<p class='note'><var>value</var> can not include "<code title>!important</code>".</p>
21842193
</li>
2185-
<li><p>Finally, set <var>property</var> to <var>value</var> with the <i>important</i> flag set if <var>priority</var> is not the empty
2186-
string, and unset otherwise.</p></li>
2194+
<li><p>If <var>component value list</var> is null terminate these steps.
2195+
<li><p>If <var>property</var> is a shorthand property, then for each longhand property <var>longhand</var> that <var>property</var> maps to, in canonical
2196+
order, <span title="set a CSS property">set the CSS property</span> <var>longhand</var> to the appropriate value(s) from <var>component value list</var>, with
2197+
the <var>important</var> flag set if <var>priority</var> is not the empty string, and with the list of declarations being the
2198+
<span title=concept-css-declaration-block-declarations>declarations</span>.
2199+
<li><p>Otherwise, <span title="set a CSS property">set the CSS property</span> <var>property</var> to <var>component value list</var>, with
2200+
the <var>important</var> flag set if <var>priority</var> is not the empty string, and with the list of declarations being the
2201+
<span title=concept-css-declaration-block-declarations>declarations</span>.
2202+
</ol>
2203+
2204+
<p>To <dfn>set a CSS property</dfn> <var>property</var> to a value <var>component value list</var> and optionally with an <var>important</var> flag set, in a
2205+
list of declarations <var>declarations</var>, follow these steps:
2206+
2207+
<ol>
2208+
<li><p>If <var>property</var> is a <span data-anolis-spec=dom>case-sensitive</span> match for a property of a declaration in
2209+
<var>declarations</var>, let <var>declaration</var> be that declaration.
2210+
<li><p>Otherwise, append a new declaration with the property name <var>property</var> to <var>declarations</var> and let <var>declaration</var> be that
2211+
declaration.
2212+
<li><p>Set <var>declaration</var>'s value to <var>component value list</var>.
2213+
<li><p>Set the declaration's <i>important</i> flag if <var>important</var> is set, or unset it otherwise.
21872214
</ol>
21882215

21892216
<p>The <dfn title=dom-CSSStyleDeclaration-removeProperty><code>removeProperty(<var>property</var>)</code></dfn> method must run these steps:</p>
@@ -2328,12 +2355,14 @@ <h4>Serializing CSS Values</h4>
23282355

23292356
<!-- based on http://damowmow.com/playground/canon.txt -->
23302357

2331-
<p>To <dfn>serialize a CSS value</dfn> follow
2358+
<p>To <dfn>serialize a CSS value</dfn> of a declaration <var>declaration</var> or a list of longhand declarations <var>list</var>, follow
23322359
these rules:</p>
23332360

23342361
<ul>
2335-
<li><p><span title="Serialize a CSS component value">Serialize</span> any
2336-
CSS component values in the value.</p></li>
2362+
<li><p>If this algorithm is invoked with a list <var>list</var>, <span title class=issue>...</span>
2363+
2364+
<li><p><span title="Serialize a CSS component value">Serialize</span> the
2365+
CSS component values in <var>declaration</var>'s value.</p></li>
23372366

23382367
<li><p>Where multiple CSS component values can appear in any order
23392368
without changing the meaning of the value (typically represented by a

0 commit comments

Comments
 (0)