Skip to content

Commit 9d70d32

Browse files
committed
Merge remote-tracking branch 'origin/paint-arguments' and address comments.
2 parents 1d186e5 + cf3fabc commit 9d70d32

File tree

1 file changed

+83
-25
lines changed

1 file changed

+83
-25
lines changed

css-paint-api/Overview.bs

+83-25
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Editor: Dean Jackson, dino@apple.com
1414

1515
<pre class="link-defaults">
1616
spec:css-break-3; type:dfn; text:fragment
17+
spec:css-ui-3; type:property; text:cursor
1718
</pre>
1819

1920
<pre class="anchors">
@@ -50,6 +51,8 @@ urlPrefix: https://infra.spec.whatwg.org/#; type: dfn;
5051
urlPrefix: map-
5152
url: exists; text: exist
5253
url: set; text: set
54+
urlPrefix: list-
55+
url: iterate; text: for each
5356
</pre>
5457

5558
Introduction {#intro}
@@ -70,6 +73,9 @@ Paint Invalidation {#paint-invalidation}
7073
A <a>document</a> has a <a>map</a> of <dfn>paint input properties</dfn>. Initially it is empty and
7174
is populated when {{registerPaint(name, paintCtor)}} is called.
7275

76+
A <a>document</a> has a <a>map</a> of <dfn>paint input argument types</dfn>. Initially it is empty
77+
and is populated when {{registerPaint(name, paintCtor)}} is called.
78+
7379
Each <<paint()>> function for a box has an associated <dfn>paint valid flag</dfn>. It may be either
7480
<dfn>paint-valid</dfn> or <dfn>paint-invalid</dfn>. It is initially set to <a>paint-invalid</a>.
7581

@@ -124,8 +130,9 @@ interface PaintWorkletGlobalScope : WorkletGlobalScope {
124130
Note: The shape of the class should be:
125131
<pre class='lang-javascript'>
126132
class MyPaint {
127-
static get inputProperties() { return ['--foo']; }
128133
static get alpha() { return true; }
134+
static get inputArguments() { return ['<color>']; }
135+
static get inputProperties() { return ['--foo']; }
129136
paint(ctx, size, styleMap) {
130137
// Paint code goes here.
131138
}
@@ -143,12 +150,14 @@ the <<paint()>> function. It consists of:
143150

144151
- A <dfn>paint class constructor</dfn> which is the class <a>constructor</a>.
145152

146-
- A <dfn>paint function</dfn> which is the paint <a>function</a> callback.
153+
- A <dfn>paint function callback</dfn> which is the paint <a>function</a> callback.
147154

148155
- A <dfn>paint constructor valid flag</dfn>.
149156

150157
- A <dfn>paint input property list</dfn>.
151158

159+
- A <dfn>paint input argument types</dfn> <a>list</a>.
160+
152161
- A <dfn>paint context alpha flag</dfn>.
153162

154163
Registering Custom Paint {#registering-custom-paint}
@@ -191,49 +200,74 @@ called, the user agent <em>must</em> run the following steps:
191200
also contains currently invalid properties for the user agent. For example
192201
<code>margin-bikeshed-property</code>.
193202

194-
7. Let |alphaValue| be the result of <a>Get</a>(|paintCtor|, "alpha").
203+
7. Let |inputArguments| be an empty <code>sequence&lt;DOMString></code>.
204+
205+
8. Let |inputArgumentsIterable| be the result of <a>Get</a>(|paintCtor|, "inputArguments").
206+
207+
9. If |inputArgumentsIterable| is not undefined, then set |inputArguments| to the result of
208+
<a>converting</a> |inputArgumentsIterable| to a <code>sequence&lt;DOMString></code>. If an
209+
execption is thrown, rethrow the execption and abort all these steps.
195210

196-
8. Let |alpha| be <code>true</code> if |alphaValue| is undefined, otherwise let it be the result
211+
10. Let |inputArgumentTypes| be an empty <a>list</a>.
212+
213+
11. <a>For each</a> |item| in |inputArguments| perform the following substeps:
214+
215+
1. Let |parsedItem| be the result of parsing |item| according to the rules in
216+
[[css-properties-values-api-1#supported-syntax-strings]]. If it fails to parse
217+
<a>throw</a> a <a>TypeError</a> and abort all these steps.
218+
219+
2. <a>Append</a> |parsedItem| to |inputArgumentTypes|.
220+
221+
12. Let |alphaValue| be the result of <a>Get</a>(|paintCtor|, "alpha").
222+
223+
13. Let |alpha| be <code>true</code> if |alphaValue| is undefined, otherwise let it be the result
197224
of <a>converting</a> |alphaValue| to a <a>boolean</a>. If an exception is thrown, rethrow
198225
the exception and abort all these steps.
199226

200227
Note: Setting <code>alpha</code> is <code>false</code> allows user agents to anti-alias text
201228
an addition to performing "visibility" optimizations, e.g. not painting an image behind
202229
the paint image as the paint image is opaque.
203230

204-
9. If the result of <a>IsConstructor</a>(|paintCtor|) is false, <a>throw</a> a <a>TypeError</a>
231+
14. If the result of <a>IsConstructor</a>(|paintCtor|) is false, <a>throw</a> a <a>TypeError</a>
205232
and abort all these steps.
206233

207-
10. Let |prototype| be the result of <a>Get</a>(|paintCtor|, "prototype").
234+
15. Let |prototype| be the result of <a>Get</a>(|paintCtor|, "prototype").
208235

209-
11. If the result of <a>Type</a>(|prototype|) is not Object, <a>throw</a> a <a>TypeError</a> and
236+
16. If the result of <a>Type</a>(|prototype|) is not Object, <a>throw</a> a <a>TypeError</a> and
210237
abort all these steps.
211238

212-
12. Let |paint| be the result of <a>Get</a>(|prototype|, "paint").
239+
17. Let |paint| be the result of <a>Get</a>(|prototype|, "paint").
213240

214-
13. If the result of <a>IsCallable</a>(|paint|) is false, <a>throw</a> a <a>TypeError</a> and
241+
18. If the result of <a>IsCallable</a>(|paint|) is false, <a>throw</a> a <a>TypeError</a> and
215242
abort all these steps.
216243

217-
14. Let |definition| be a new <a>paint image definition</a> with:
244+
19. Let |definition| be a new <a>paint image definition</a> with:
218245

219246
- <a>paint image name</a> being |name|
220247

221248
- <a>paint class constructor</a> being |paintCtor|
222249

223-
- <a>paint function</a> being |paint|
250+
- <a>paint function callback</a> being |paint|
224251

225252
- <a>paint constructor valid flag</a> being true
226253

227254
- <a>paint input property list</a> being |inputProperties|.
228255

256+
- <a>paint input argument types</a> being |inputArgumentTypes|.
257+
229258
- <a>paint context alpha flag</a> being |alpha|.
230259

231-
15. <a>Set</a> |paintImageDefinitionMap|[|name|] to |definition|.
260+
20. <a>Set</a> |paintImageDefinitionMap|[|name|] to |definition|.
232261

233-
16. Let |paintInputPropertiesMap| be the associated <a>document</a>'s <a>paint input
262+
21. Let |paintInputPropertiesMap| be the associated <a>document</a>'s <a>paint input
234263
properties</a> map.
235264

236-
17. <a>Set</a> |paintInputPropertiesMap|[|name|] to |inputProperties|.
265+
22. <a>Set</a> |paintInputPropertiesMap|[|name|] to |inputProperties|.
266+
267+
23. Let |paintInputArgumentsMap| be the associated <a>document</a>'s <a>paint input argument
268+
types</a> map.
269+
270+
24. <a>Set</a> |paintInputArgumentsMap|[|name|] to |inputArgumentTypes|.
237271

238272
Note: The list of input properties should only be looked up once, the class doesn't have the
239273
opportunity to dynamically change its input properties.
@@ -247,23 +281,32 @@ Paint Notation {#paint-notation}
247281
================================
248282

249283
<pre class='prod'>
250-
<dfn>paint()</dfn> = paint( <<ident>> )
284+
<dfn>paint()</dfn> = paint( <<ident>> [, <<custom-value>>]* )
251285
</pre>
252286

253287
The <<paint()>> function is an additional notation to be supported by the <<image>> type.
254288

255289
<div class="example">
256290
<pre>background-image: paint(my_logo);</pre>
291+
<pre>border-image: paint(gradient, 100);</pre>
257292
</div>
258293

294+
<<custom-value>> is the set of types listed in
295+
[[css-properties-values-api-1#supported-syntax-strings]].
296+
297+
When computing the <a>declared value</a> of the <<paint()>> function the user agent must lookup the
298+
<a>document</a>'s <a>paint input argument types</a> map and validate that the syntax of the
299+
<<paint()>> function matches the syntax described by the author. If it doesn't the user agent should
300+
treat it as an invalid property value.
301+
302+
When the <a>current global object's</a> associated <a>document</a>'s <a>paint input argument
303+
types</a> map changes a previously syntactically invalid property values can become valid and vice
304+
versa. This can change the set of <a>declared values</a> which requires the <a>cascade</a> to be
305+
recomputed.
306+
259307
For the 'cursor' property, the <<paint()>> function should be treated as an <a>invalid image</a> and
260308
fallback to the next supported <<image>>.
261309

262-
Issue(w3c/css-houdini-drafts#100): Support additional arbitrary arguments for the paint function.
263-
This is difficult to specify, as you need to define a sane grammar. A better way would be to
264-
expose a token stream which you can parse into Typed OM objects. This would allow a full
265-
arbitrary set of function arguments, and be future proof.
266-
267310
The 2D rendering context {#2d-rendering-context}
268311
================================================
269312

@@ -430,16 +473,31 @@ following steps:
430473
12. Let |paintSize| be a new {{PaintSize}} initialized to the width and height defined by
431474
|concreteObjectSize|.
432475

433-
13. Let |paintFunctionCallback| be |definition|'s <a>paint function</a>.
476+
13. Let |inputArgumentTypes| be |definition|'s <a>paint input argument types</a>.
477+
478+
14. Let |inputArguments| be an empty <a>list</a>.
479+
480+
15. For each argument of the |paintFunction| after the "paint name" argument run the
481+
[[css-typed-om-1#stylevalue-normalization]] to construct the appropriate {{CSSStyleValue}}.
482+
483+
The syntax to use is given by the parsed syntax object in the corresponding position of the
484+
|inputArgumentTypes| list.
485+
486+
The resulting {{CSSStyleValue}} should be appended to the |inputArguments| array.
487+
488+
Note: This step should succeed as an invalid argument should have been rejected when
489+
computing the <a>declared value</a> of the |paintFunction|.
490+
491+
16. Let |paintFunctionCallback| be |definition|'s <a>paint function callback</a>.
434492

435-
14. <a>Invoke</a> |paintFunctionCallback| with arguments «|renderingContext|, |paintSize|,
436-
|styleMap|», and with |paintInstance| as the <a>callback this value</a>.
493+
17. <a>Invoke</a> |paintFunctionCallback| with arguments «|renderingContext|, |paintSize|,
494+
|styleMap|, |arguments|», and with |paintInstance| as the <a>callback this value</a>.
437495

438-
15. The image output is to be produced from the |renderingContext| given to the method.
496+
18. The image output is to be produced from the |renderingContext| given to the method.
439497

440498
If an exception is <a>thrown</a> the let the image output be an <a>invalid image</a>.
441499

442-
16. Set the <a>paint valid flag</a> for the |paintFunction| to <a>paint-valid</a>.
500+
19. Set the <a>paint valid flag</a> for the |paintFunction| to <a>paint-valid</a>.
443501

444502
Note: The user agent <em>should</em> consider long running paint functions similar to long running
445503
script in the main execution context. For example, they <em>should</em> show a "unresponsive

0 commit comments

Comments
 (0)