Skip to content

Commit d2feee6

Browse files
committed
[css-paint-api] Finalize plubming for input arguments.
Fixes w3c#219, fixes w3c#100.
1 parent 1d2b03a commit d2feee6

File tree

1 file changed

+65
-76
lines changed

1 file changed

+65
-76
lines changed

css-paint-api/Overview.bs

Lines changed: 65 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ A <dfn>paint definition</dfn> is a <a>struct</a> which describes the information
161161
- <dfn for="paint definition">input properties</dfn> which is a <a>list</a> of
162162
<code>DOMStrings</code>.
163163

164-
- A <dfn for="paint definition">input argument syntaxes</dfn> which is a <a>list</a> of parsed
165-
[[css-properties-values-api-1#supported-syntax-strings]].
166-
167164
- A <dfn for="paint definition">context alpha flag</dfn>.
168165

169166
A <dfn>document paint definition</dfn> is a <a>struct</a> which describes the information
@@ -272,8 +269,6 @@ called, the user agent <em>must</em> run the following steps:
272269

273270
- <a for="paint definition">input properties</a> being |inputProperties|.
274271

275-
- <a for="paint definition">input argument syntaxes</a> being |inputArgumentSyntaxes|.
276-
277272
- <a for="paint definition">context alpha flag</a> being |alpha|.
278273

279274
20. <a for=map>Set</a> |paintDefinitionMap|[|name|] to |definition|.
@@ -326,22 +321,26 @@ Paint Notation {#paint-notation}
326321
================================
327322

328323
<pre class='prod'>
329-
<dfn>paint()</dfn> = paint( <<ident>> )
324+
<dfn>paint()</dfn> = paint( <<ident>>, <<declaration-value>>? )
330325
</pre>
331326

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

334329
<div class="example">
335-
<pre>background-image: paint(my-logo);</pre>
330+
<pre class=lang-markup>
331+
&ltstyle>
332+
.logo { background-image: paint(company-logo); }
333+
.chat-bubble { background-image: paint(chat-bubble, blue); }
334+
&lt/style>
335+
</pre>
336336
</div>
337337

338338
For the 'cursor' property, the <<paint()>> function should be treated as an <a>invalid image</a> and
339339
fallback to the next supported <<image>>.
340340

341-
Issue(w3c/css-houdini-drafts#100): Support additional arbitrary arguments for the paint function.
342-
This is difficult to specify, as you need to define a sane grammar. A better way would be to
343-
expose a token stream which you can parse into Typed OM objects. This would allow a full
344-
arbitrary set of function arguments, and be future proof.
341+
At <a>computed value</a> time the <<paint()>> function does <em>not</em> need to match the grammar
342+
registered by {{registerPaint()}}. Instead this will result in an <a>invalid image</a> when the
343+
parsing occurs inside <a>draw a paint image</a>.
345344

346345
The 2D rendering context {#2d-rendering-context}
347346
================================================
@@ -462,10 +461,56 @@ following steps:
462461
6. If |documentPaintDefinitionMap|[|name|] does not <a for=map>exist</a>, let the image output
463462
be an <a>invalid image</a> and abort all these steps.
464463

465-
7. If the result of <a>get</a> |documentPaintDefinitionMap|[|name|] is <code>"invalid"</code>,
464+
7. Let |documentDefinition| be the result of <a for=map>get</a>
465+
|documentPaintDefinitionMap|[|name|].
466+
467+
8. If |documentDefinition| is <code>"invalid"</code>, let the image output be an <a>invalid
468+
image</a> and abort all these steps.
469+
470+
9. Let |inputArgumentSyntaxes| be |documentDefinition|'s <a for="document paint
471+
definition">input argument syntaxes</a>.
472+
473+
10. Let |inputArguments| be the <a>list</a> of all the |paintFunction| arguments <em>after</em>
474+
the "paint name" argument.
475+
476+
11. If |inputArguments| do not match the registered grammar given by |inputArgumentSyntaxes|,
466477
let the image output be an <a>invalid image</a> and abort all these steps.
467478

468-
8. Let |workletGlobalScope| be a {{PaintWorkletGlobalScope}} from the list of <a>worklet's
479+
<div class=example>
480+
This step may fail in the following cases:
481+
482+
<pre class=lang-javascript>
483+
// paint.js
484+
registerPaint('failing-argument-syntax', class {
485+
static get inputArguments() { return ['&lt;length>']; }
486+
paint(ctx, size, styleMap, args) { /* paint code here. */ }
487+
});
488+
</pre>
489+
490+
<pre class=lang-markup>
491+
&lt;style>
492+
.example-1 {
493+
background-image: paint(failing-argument-syntax, red);
494+
}
495+
.example-2 {
496+
background-image: paint(failing-argument-syntax, 1px, 2px);
497+
}
498+
&lt;/style>
499+
&lt;div class=example-1>&lt;/div>
500+
&lt;div class=example-2>&lt;/div>
501+
&lt;script>
502+
CSS.paintWorklet.import('paint.js');
503+
&lt;/script>
504+
</pre>
505+
506+
<code>example-1</code> produces an <a>invalid image</a> as <code>"red"</code> does not
507+
match the registered grammar.
508+
509+
<code>example-2</code> produces an <a>invalid image</a> as there are too many function
510+
arguments.
511+
</div>
512+
513+
12. Let |workletGlobalScope| be a {{PaintWorkletGlobalScope}} from the list of <a>worklet's
469514
WorkletGlobalScopes</a> from the paint {{Worklet}}.
470515

471516
The user agent <em>may</em> also <a>create a WorkletGlobalScope</a> given the paint
@@ -475,18 +520,15 @@ following steps:
475520
select or create. It may use a single {{PaintWorkletGlobalScope}} or multiple and
476521
randomly assign between them.
477522

478-
9. Let |functionArguments| be a <a>list</a> of all the |paintFunction| arguments <em>after</em>
479-
the "paint name" argument.
480-
481-
10. Run <a>invoke a paint callback</a> given |name|, |functionArguments|, |concreteObjectSize|,
523+
13. Run <a>invoke a paint callback</a> given |name|, |inputArguments|, |concreteObjectSize|,
482524
|workletGlobalScope| optionally <a>in parallel</a>.
483525

484526
Note: If the user agent runs <a>invoke a paint callback</a> on a thread <a>in parallel</a>,
485527
it should select a paint worklet global scope which can be used on that thread.
486528
</div>
487529

488530
<div algorithm>
489-
When the user agent wants to <dfn>invoke a paint callback</dfn> given |name|, |functionArguments|,
531+
When the user agent wants to <dfn>invoke a paint callback</dfn> given |name|, |inputArguments|,
490532
|concreteObjectSize|, and |workletGlobalScope|, it <em>must</em> run the following steps:
491533

492534
1. Let |paintDefinitionMap| be |workletGlobalScope|'s <a>paint definitions</a> map.
@@ -535,60 +577,7 @@ When the user agent wants to <dfn>invoke a paint callback</dfn> given |name|, |f
535577
7. Let |styleMap| be a new {{StylePropertyMapReadOnly}} populated with <em>only</em> the
536578
<a>computed value</a>'s for properties listed in |inputProperties|.
537579

538-
8. Let |inputArgumentSyntaxes| be |definition|'s <a for="paint definition">input argument
539-
syntaxes</a>.
540-
541-
9. Let |inputArguments| be a new <a for=list>empty</a> <a>list</a>.
542-
543-
10. Let |length| be <a for=list>size</a> of |inputArguments| - 1.
544-
545-
10. <a for=list>For each</a> |index| in the range 0 to |length|, run the following steps:
546-
547-
1. Let |inputArgumentSyntax| be |inputArgumentSyntaxes|[|index|].
548-
549-
2. If |functionArguments|[|index|] does not <a for=list>exist</a>, let the image output be
550-
an <a>invalid image</a> and abort all these steps.
551-
552-
4. Let |functionArgument| be |functionArguments|[|index|].
553-
554-
3. Let |inputArgument| by the result of running [[css-typed-om-1#stylevalue-normalization]]
555-
on |functionArgument| with |inputArgumentSyntax| being the syntax to use to construct
556-
the appropriate {{CSSStyleValue}} object.
557-
558-
If this steps fails, let the image output be an <a>invalid image</a> and abort all these
559-
steps.
560-
561-
<div class=example>
562-
This step may fail in the following case:
563-
564-
<pre class=lang-javascript>
565-
// paint.js
566-
registerPaint('failing-argument-syntax', class {
567-
static get inputArguments() { return ['&lt;length>']; }
568-
paint(ctx, size, styleMap, args) { /* paint code here. */ }
569-
});
570-
</pre>
571-
572-
<pre class=lang-markup>
573-
&lt;style>
574-
.example {
575-
background-image: paint(failing-argument-syntax, red);
576-
}
577-
&lt;/style>
578-
&lt;div class=example>&lt;/div>
579-
&lt;script>
580-
CSS.paintWorklet.import('paint.js');
581-
&lt;/script>
582-
</pre>
583-
584-
As <code>red</code> cannot be normalized to a <<length>> syntax, the background
585-
image is an <a>invalid image</a>.
586-
</div>
587-
588-
5. <a for=list>Append</a> |inputArgument| to |inputArguments|.
589-
590-
11. Let |renderingContext| be the result of <a>create a PaintRenderingContext2D object</a>
591-
given:
580+
8. Let |renderingContext| be the result of <a>create a PaintRenderingContext2D object</a> given:
592581
- "width" - The width given by |concreteObjectSize|.
593582
- "height" - The height given by |concreteObjectSize|.
594583
- "alpha" - The <a for="paint definition">context alpha flag</a> given by |definition|.
@@ -603,15 +592,15 @@ When the user agent wants to <dfn>invoke a paint callback</dfn> given |name|, |f
603592
invoke methods on it, but this will have no effect on the current image, or subsequent
604593
images.
605594

606-
12. Let |paintSize| be a new {{PaintSize}} initialized to the width and height defined by
595+
9. Let |paintSize| be a new {{PaintSize}} initialized to the width and height defined by
607596
|concreteObjectSize|.
608597

609-
13. Let |paintFunctionCallback| be |definition|'s <a>paint function</a>.
598+
10. Let |paintFunctionCallback| be |definition|'s <a>paint function</a>.
610599

611-
14. <a>Invoke</a> |paintFunctionCallback| with arguments «|renderingContext|, |paintSize|,
600+
11. <a>Invoke</a> |paintFunctionCallback| with arguments «|renderingContext|, |paintSize|,
612601
|styleMap|, |inputArguments|», and with |paintInstance| as the <a>callback this value</a>.
613602

614-
15. The image output is to be produced from the |renderingContext| given to the method.
603+
12. The image output is to be produced from the |renderingContext| given to the method.
615604

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

0 commit comments

Comments
 (0)