Skip to content

Commit d7cf0ed

Browse files
committed
Infra-ify all the StylePropertyMap methods.
1 parent a4f9927 commit d7cf0ed

File tree

1 file changed

+55
-66
lines changed

1 file changed

+55
-66
lines changed

css-typed-om/Overview.bs

Lines changed: 55 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,15 @@ Issue(305): appropriate failure indicators for this algorithm
194194
The {{StylePropertyMap}} {#the-stylepropertymap}
195195
================================================
196196

197-
<pre class='idl'>
197+
<xmp class='idl'>
198198
interface StylePropertyMapReadOnly {
199-
CSSStyleValue? get(DOMString property);
200-
sequence&lt;CSSStyleValue> getAll(DOMString property);
199+
any get(DOMString property);
200+
/* 'any' means (undefined or CSSStyleValue) here,
201+
see https://github.com/heycam/webidl/issues/60 */
202+
sequence<CSSStyleValue> getAll(DOMString property);
201203
boolean has(DOMString property);
202-
iterable&lt;DOMString, (CSSStyleValue or sequence&lt;CSSStyleValue>)>;
203-
sequence&lt;DOMString> getProperties();
204+
iterable<DOMString, (CSSStyleValue or sequence<CSSStyleValue>)>;
205+
sequence<DOMString> getProperties();
204206
stringifier;
205207
};
206208

@@ -212,7 +214,7 @@ interface StylePropertyMap : StylePropertyMapReadOnly {
212214
void set(DOMString property, (CSSStyleValue or DOMString)... values);
213215
void update(DOMString property, UpdateFunction updateFunction);
214216
};
215-
</pre>
217+
</xmp>
216218

217219
A {{StylePropertyMapReadOnly}} object has an associated <dfn export for="StylePropertyMapReadonly, StylePropertyMap">contained properties map</dfn>,
218220
which is a [=map=] of property name ([=string=]) → values ([=list=] of {{CSSStyleValue}} objects) pairs.
@@ -284,16 +286,18 @@ probably in an appendix.
284286
</div>
285287

286288
<div algorithm>
287-
To <dfn>delete a StylePropertyMap</dfn> given a <var>property</var>, run these steps:
289+
The <dfn method for=StylePropertyMap>delete(|property|)</dfn> method,
290+
when called on a {{StylePropertyMap}} |this|,
291+
must perform the following steps:
288292

289-
1. If |property| does not start with two dashes (U+002D HYPHEN),
293+
1. If |property| is not a [=custom property name string=],
290294
let |property| be |property| [=ASCII lowercased=].
291295

292296
2. If |property| is not a [=supported property name=],
293297
[=throw=] a {{TypeError}} and exit this algorithm.
294298

295-
3. If {{StylePropertyMap}}’s [=contained properties map=] contains an entry for |property|,
296-
remove that entry from the [=contained properties map=].
299+
3. If |this|’s [=contained properties map=] [=contains=] |property|,
300+
[=map/remove=] it.
297301
</div>
298302

299303
<div algorithm>
@@ -307,109 +311,94 @@ probably in an appendix.
307311
Otherwise, return the |value|.
308312

309313
: If |value| is a {{DOMString}},
310-
:: [=Parse a CSSStyleValue=] with property |property|, value |value|, and |parseMultiple| set to `false`,
314+
:: [=Parse a CSSStyleValue=] with property |property|, value |value|, and parseMultiple set to `false`,
311315
and return the result.
312316

313317
Note: This can throw a {{TypeError}} instead.
314318
</div>
315319

316320
<div algorithm>
317-
To <dfn>get a value from a StylePropertyMap</dfn>, run these steps:
321+
The <dfn method for="StylePropertyMapReadonly, StylePropertyMap">get(|property|)</dfn> method,
322+
when called on a {{StylePropertyMap}} |this|,
323+
must perform the following steps:
318324

319325
1. If |property| does not start with two dashes (U+002D HYPHEN),
320326
let |property| be |property| [=ASCII lowercased=].
321327

322328
2. If |property| is not a [=supported property name=],
323329
[=throw=] a {{TypeError}} and exit this algorithm.
324330

325-
3. If {{StylePropertyMap}}’s [=contained properties map=] contains an entry for |property|,
326-
return the first value found in that entry.
331+
3. Let |props| be |this|’s [=contained properties map=].
332+
333+
4. If |props|[|property|] [=map/exists=],
334+
return |props|[|property|][0].
327335

328-
4. Else, return `null`.
336+
Otherwise, return `undefined`.
329337
</div>
330338

331339
<div algorithm>
332-
To <dfn>get all values from a StylePropertyMap</dfn>, run these steps:
340+
The <dfn method for="StylePropertyMapReadonly, StylePropertyMap">getAll(|property|)</dfn> method,
341+
when called on a {{StylePropertyMap}} |this|,
342+
must perform the following steps:
333343

334344
1. If |property| does not start with two dashes (U+002D HYPHEN),
335345
let |property| be |property| [=ASCII lowercased=].
336346

337347
2. If |property| is not a [=supported property name=],
338348
[=throw=] a {{TypeError}} and exit this algorithm.
339-
340-
3. If {{StylePropertyMap}}’s [=contained properties map=] contains an entry for |property|:
341-
342-
1. If |property| is a [=list-valued property=],
343-
return the list of |values| assigned to that property.
344-
345-
2. If |property| is not a [=list-valued property=],
346-
let |values| initially be the empty [=list=] and append
347-
the |value| assigned to the |property| to this list
348-
and return |values|.
349-
350-
4. Else, return an empty [=list=].
351-
352-
</div>
353-
354-
<div algorithm>
355-
To <dfn>check if StylePropertyMap has a property</dfn>, run these steps:
356-
357-
1. Run the algorithm to [=get a value from a StylePropertyMap=] with property <var>property</var>,
358-
1. If the algorithm returns a {{CSSStyleValue}} return true.
359349

360-
2. If the algorithm returns `null` return false.
350+
3. Let |props| be |this|’s [=contained properties map=].
361351

352+
4. If |props|[|property|] [=map/exists=],
353+
return |props|[|property|].
354+
Otherwise, return an empty [=list=].
362355
</div>
363356

364-
365357
<div algorithm>
366-
To <dfn>set a value on a StylePropertyMap</dfn>,
367-
given a [=string=] |property|
368-
and a [=list=] of {{CSSStyleValue}} objects |value|,
369-
run these steps:
358+
The <dfn method for=StylePropertyMap>set(|property|, ...|values|)</dfn> method,
359+
when called on a {{StylePropertyMap}} |this|,
360+
must perform the following steps:
370361

371362
1. If |property| does not start with two dashes (U+002D HYPHEN),
372363
let |property| be |property| [=ASCII lowercased=].
373364

374365
2. If |property| is not a [=supported property name=],
375366
[=throw=] a {{TypeError}} and exit this algorithm.
376367

377-
3. If {{StylePropertyMap}}’s [=contained properties map=] contains an entry for |property|,
378-
let |entry| be that entry.
379-
Otherwise, exit the algorithm.
368+
3. Let |props| be |this|’s [=contained properties map=].
380369

381-
4. Empty the list of |values| currently stored on the |entry|.
370+
4. If |props|[|property|] [=map/exists=],
371+
[=map/remove=] it.
382372

383-
5. Let |values to set| be an empty list.
373+
5. Let |values to set| be an empty [=list=].
384374

385-
6. For each |value| in |values| if the [=algorithm that coerces value into an appropriate type for a given property=] does not throw an error, append the returned object to |values to set|.
375+
6. For each |value| in |values|:
376+
1. [=Normalize a style value=] for |property| and |value|,
377+
and append the result to |values to set|.
386378

387-
7. Set |values to set| to be |entry|’s list.
388-
</div>
379+
7. Set |props|[|property|] to |values to set|.
389380

390-
The <dfn method for=StylePropertyMap>update(DOMString <var>property</var>,
391-
UpdateFunction <var>updateFunction</var>)</dfn> method, when invoked, must
392-
[=update a value in a StylePropertyMap=] with property name
393-
<var>property</var>, update function <var>updateFunction</var>, and property
394-
map set to the object this method was invoked on .
381+
Note: The property is deleted then added back
382+
so that it gets put at the end of the [=ordered map=],
383+
which gives the expected behavior in the face of [=shorthand properties=].
384+
</div>
395385

396386
<div algorithm>
397-
To <dfn>update a value in a StylePropertyMap</dfn> given a <var>property
398-
name</var>, <var>update function</var>, and <var>property map</var>, run these
399-
steps:
400-
401-
1. Let <var>old value</var> be the result of running the algorithm to
402-
[=get a value from a StylePropertyMap=] with property name <var>property
403-
name</var> and property map <var>property map</var>.
387+
The <dfn method for=StylePropertyMap>update(|property|, |updateFn|)</dfn> method,
388+
when called on a {{StylePropertyMap}} |this|,
389+
must perform the following steps:
404390

405-
2. Let <var>new value</var> be the return value given by [=invoking=] the callback
406-
<var>update function</var> with a single input of <var>old value</var>.
391+
1. Let |old value| be the result of calling |this|.get(|property|)
392+
(using the original value of {{StylePropertyMap/get()}}).
407393

408-
3. Run the algorithm to [=set a value on a StylePropertyMap=] with property name <var>property name</var>,
409-
value <var>new value</var>, and property map <var>property map</var>.
394+
2. Let |new value| be the result of [=invoking=] |updateFn| with |old value|.
410395

396+
3. Call |this|.set(|property|, |new value|)
397+
(using the original value of {{StylePropertyMap/set()}}).
411398
</div>
412399

400+
Issue: Do we need an updateAll() method that gets and sets a list?
401+
413402
The <dfn method for=StylePropertyMap>getProperties()</dfn> method returns all of the contained properties maped in
414403
the [=contained properties map=]. This list of properties is sorted in the following manner:
415404

0 commit comments

Comments
 (0)