Skip to content

Commit 5f21336

Browse files
committed
[cssom-1] Replace steps of set a CSS declaration with some constraints
1 parent 1023f92 commit 5f21336

File tree

1 file changed

+91
-16
lines changed

1 file changed

+91
-16
lines changed

cssom-1/Overview.bs

Lines changed: 91 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ spec:html; type:dfn; text:ascii case-insensitive
118118
spec:html; type:dfn; text:case-sensitive
119119
spec:infra; type:dfn; text:list
120120
spec:css-logical; type:property; text:inline-size
121+
spec:css-logical; type:dfn; text:logical property group
122+
spec:css-logical; type:dfn; text:logical kind
121123
spec:css-variables-1; type:dfn; text:custom property
122124
spec:selectors-3; type:selector; text:::before
123125
spec:selectors-3; type:selector; text:::after
@@ -2190,28 +2192,101 @@ The <dfn method for=CSSStyleDeclaration>setProperty(<var>property</var>, <var>va
21902192
Note: <var>value</var> can not include "<code>!important</code>".
21912193

21922194
<li>If <var>component value list</var> is null, then return.
2195+
<li>Let <var>updated</var> be false.
21932196
<li>If <var>property</var> is a shorthand property, then for each longhand property <var>longhand</var> that <var>property</var> maps to, in canonical
2194-
order, <a lt="set a CSS declaration">set the CSS declaration</a> <var>longhand</var> with the appropriate value(s) from <var>component value
2195-
list</var>, with the <i>important</i> flag set if <var>priority</var> is not the empty string, and unset otherwise, and with the list of declarations being the
2196-
<a for="CSSStyleDeclaration">declarations</a>.
2197-
<li>Otherwise, <a lt="set a CSS declaration">set the CSS declaration</a> <var>property</var> with value <var>component value list</var>, with
2198-
the <i>important</i> flag set if <var>priority</var> is not the empty string, and unset otherwise, and with the list of declarations being the
2197+
order, follow these substeps:
2198+
<ol>
2199+
<li>Let <var>longhand result</var> be the result of <a lt="set a CSS declaration">set the CSS declaration</a>
2200+
<var>longhand</var> with the appropriate value(s) from <var>component value list</var>, with the <i>important</i>
2201+
flag set if <var>priority</var> is not the empty string, and unset otherwise, and with the list of declarations
2202+
being the <a for="CSSStyleDeclaration">declarations</a>.
2203+
<li>If <var>longhand result</var> is true, let <var>updated</var> be true.
2204+
</ol>
2205+
<li>Otherwise, let <var>updated</var> be the result of <a lt="set a CSS declaration">set the CSS declaration</a>
2206+
<var>property</var> with value <var>component value list</var>, with the <i>important</i> flag set if
2207+
<var>priority</var> is not the empty string, and unset otherwise, and with the list of declarations being the
21992208
<a for="CSSStyleDeclaration">declarations</a>.
2200-
<li><a>Update style attribute for</a> the <a>CSS declaration block</a>.
2209+
<li>If <var>updated</var> is true, <a>update style attribute for</a> the <a>CSS declaration block</a>.
22012210
</ol>
22022211

22032212
To <dfn export>set a CSS declaration</dfn> <var>property</var> with a value <var>component value list</var> and optionally with an <i>important</i> flag set, in
2204-
a list of declarations <var>declarations</var>, follow these steps:
2213+
a list of declarations <var>declarations</var>, the user agent must ensure the following constraints hold after its steps:
22052214

2206-
<ol>
2207-
<li>If <var>property</var> is a <a>case-sensitive</a> match for a <a for="CSS declaration">property
2208-
name</a> of a <a>CSS declaration</a> in <var>declarations</var>, remove that <a>CSS declaration</a>.
2209-
<li>Append a new <a>CSS declaration</a> with the <a for="CSS declaration">property name</a> <var>property</var>
2210-
to <var>declarations</var> and let <var>declaration</var> be that <a>CSS declaration</a>.
2211-
<li>Set <var>declaration</var>'s <a for="CSS declaration">value</a> to <var>component value list</var>.
2212-
<li>If the <i>important</i> flag is set, set <var>declaration</var>'s <a for="CSS declaration">important flag</a>.
2213-
Otherwise, unset <var>declaration</var>'s <a for="CSS declaration">important flag</a>.
2214-
</ol>
2215+
<ul>
2216+
<li>
2217+
Exactly one <a>CSS declaration</a> whose <a for="CSS declaration">property name</a> is a
2218+
<a>case-sensitive</a> match of <var>property</var> must exist in <var>declarations</var>.
2219+
Such declaration is referenced as the <var>target declaration</var> below.
2220+
2221+
<li>
2222+
The <var>target declaration</var> must have value being <var>component value list</var>,
2223+
and <var>target declaration</var>'s <a for="CSS declaration">important flag</a> must be
2224+
<a>set</a> if <i>important</i> flag is set, and <a>unset</a> otherwise.
2225+
2226+
<li>
2227+
Any <a>CSS declaration</a> which is not the <var>target declaration</var> must not be changed, inserted,
2228+
or removed from <var>declarations</var>.
2229+
2230+
<li>
2231+
If there are <a>CSS declarations</a> in <var>declarations</var> whose
2232+
<a for="CSS declaration">property name</a> is in the same <a>logical property group</a> as
2233+
<var>property</var>, but has a different <a>logical kind</a>, <var>target declaration</var> must be
2234+
at an index after all of those <a>CSS declarations</a>.
2235+
2236+
<li>
2237+
The steps must return true if the serialization of <var>declarations</var> was changed as result
2238+
of the steps. It may return false otherwise.
2239+
</ul>
2240+
2241+
Issue: Should we add something like "Any observable side effect must not be made outside
2242+
<var>declarations</var>"? The current constraints sound like a hole for undefined behavior.
2243+
2244+
Note: The steps of <a>set a CSS declaration</a> are not defined in this level of CSSOM. The user agent may
2245+
use different algorithm as far as the constraints above hold.
2246+
2247+
<div class="example">
2248+
The simplest way to conform with the constraints would be to always remove any existing declaration
2249+
matching <var>property</var>, and append the new declaration to the end. But based on implementation
2250+
feedback, this approach would likely regress performance.
2251+
2252+
Another possible algorithm is:
2253+
<ol>
2254+
<li>If <var>property</var> is a <a>case-sensitive</a> match for a <a for="CSS declaration">property name</a>
2255+
of a <a>CSS declaration</a> in <var>declarations</var>, follow these substeps:
2256+
<ol>
2257+
<li>Let <var>target declaration</var> be such <a>CSS declaration</a>.
2258+
<li>Let <var>needs append</var> be false.
2259+
<li><a for="list">For each</a> <var>declaration</var> in <var>declarations</var> after
2260+
<var>target declaration</var>:
2261+
<ol>
2262+
<li>If <var>declaration</var>'s <a for="CSS declaration">property name</a> is not in the same
2263+
<a>logical property group</a> as <var>property</var>, then <a>continue</a>.
2264+
<li>If <var>declaration</var>' <a for="CSS declaration">property name</a> has the same
2265+
<a>logical kind</a> as <var>property</var>, then <a>continue</a>.
2266+
<li>Let <var>needs append</var> be true.
2267+
<li><a>Break</a>.
2268+
</ol>
2269+
<li>If <var>needs append</var> is false, then:
2270+
<ol>
2271+
<li>Let <var>needs update</var> be false.
2272+
<li>If <var>target declaration</var>'s <a for="CSS declaration">value</a> is not equal to <var>component
2273+
value list</var>, then let <var>needs update</var> be true.
2274+
<li>If <var>target declaration</var>'s <a for="CSS declaration">important flag</a> is not equal to
2275+
whether <i>important</i> flag is set, then let <var>needs update</var> be true.
2276+
<li>If <var>needs update</var> is false, then return false.
2277+
<li>Set <var>target declaration</var>'s <a for="CSS declaration">value</a> to <var>component value list</var>.
2278+
<li>If <i>important</i> flag is set, then set <var>target declaration</var>'s
2279+
<a for="CSS declaration">important flag</a>, otherwise unset it.
2280+
<li>Return true.
2281+
</ol>
2282+
<li>Otherwise, remove <var>target declaration</var> from <var>declarations</var>.
2283+
</ol>
2284+
<li>Append a new <a>CSS declaration</a> with <a for="CSS declaration">property name</a> <var>property</var>,
2285+
<a for="CSS declaration">value</a> <var>component value list</var>, and <a for="CSS declaration">important flag</a>
2286+
set if <i>important</i> flag is set to <var>declarations</var>.
2287+
<li>Return true.
2288+
</ol>
2289+
</div>
22152290

22162291
The <dfn method for=CSSStyleDeclaration>removeProperty(<var>property</var>)</dfn> method must run these steps:
22172292
<ol>

0 commit comments

Comments
 (0)