@@ -15,6 +15,10 @@ Editor: Greg Whitworth, gwhit@microsoft.com
15
15
Ignored Terms : boolean, Animatable, Map, Context, isolated worker, SyntaxError,
16
16
Ignored Terms : InvalidModificationError, NotFoundError, StylePropertyMapReadOnly,
17
17
Ignored Terms : processor global scope
18
+ Ignored Terms : Worklet, throw, NotSupportedError, isconstructor, get, iscallable,
19
+ Ignored Terms : construct, name map of inputs, invoke a method on a class inside a worklet
20
+ Ignored Terms : create a worklet global scope, lookup a class instance on a worklet global scope
21
+ Ignored Vars : arguments, methodPropertyKey, inputStyleMap, workletGlobalScope
18
22
Repository : w3c/css-houdini-drafts
19
23
At Risk : the apply hook (<a section href="#the-apply-hook"></a>)
20
24
</pre>
@@ -221,20 +225,29 @@ interface ElementProxy {
221
225
readonly attribute DOMString? pseudo;
222
226
};
223
227
224
- callback ApplyCallback = void (ElementProxy element);
225
-
226
228
dictionary ApplyDescriptor {
227
- ApplyCallback applyHook;
228
229
sequence<DOMString> inputProperties;
229
230
sequence<DOMString> outputProperties;
230
231
};
231
232
232
- partial interface Context {
233
- long registerApplyHook(ApplyDescriptor apply);
234
- void unregisterApplyHook(long hookID);
233
+ callback VoidFunction = void ();
234
+
235
+ interface StyleWorklet : Worklet {
236
+ void registerApplyHook(DOMString name, VoidFunction applyCtor, ApplyDescriptor config);
237
+ void unregisterApplyHook(DOMString name);
235
238
};
236
239
</pre>
237
240
241
+ <div class='note'>
242
+ The applyCtor is a JavaScript class with the following interface:
243
+
244
+ <pre class='idl'>
245
+ callback interface ApplyClass {
246
+ void apply(ElementProxy element);
247
+ };
248
+ </pre>
249
+ </div>
250
+
238
251
The {{ElementProxy}} interface {#the-elementproxy-interface}
239
252
------------------------------------------------------------
240
253
@@ -272,30 +285,112 @@ Issue(2): Should this be available only if explicitly requested in inputProperti
272
285
:: This value defines the properties for which the apply function can modify the used
273
286
value.
274
287
288
+ Apply classes {#apply-class-objects}
289
+ ------------------------------------
290
+
291
+ <dfn>Apply classes</dfn> provide apply hook behavior. Each <a>apply class</a>
292
+ must provide an apply function that will be invoked when apply hooks are
293
+ being processed.
294
+
295
+ The {{StyleWorklet}} interface {#the-styleworklet-interface}
296
+ ------------------------------------------------------------
297
+
298
+ <dfn interface>StyleWorklet</dfn> objects provide the context within which apply hooks
299
+ are invoked. Each {{StyleWorklet}} contains a <dfn>name map of apply hooks</dfn> ,
300
+ a <dfn>name map of inputs</dfn> , a <dfn>name map of outputs</dfn> ,
301
+ and a <dfn>list of affected output properties</dfn> , all of which are
302
+ initially empty.
303
+
275
304
The {{registerApplyHook()}} function {#the-registerapplyhook-function}
276
305
----------------------------------------------------------------------
277
306
278
- If a {{registerApplyHook()}} call is made with a list of outputProperties that contains
279
- properties that have already been registered for output, then an exception is thrown and
280
- the call fails.
307
+ The <dfn method for=StyleWorklet>registerApplyHook(DOMString name, VoidFunction applyCtor, ApplyDescriptor config)</dfn>
308
+ function registers a new apply hook for processing computed style.
309
+
310
+ When {{registerApplyHook(name, applyCtor, config)}} is called, the user agent must run the following steps:
311
+
312
+ 1. If |name| is not a valid <<ident>> , <a>throw</a> a {{NotSupportedError}} and abort
313
+ these steps.
314
+
315
+ 1. If |name| is a key in the <a>name map of apply hooks</a> , <a>throw</a> a
316
+ {{NotSupportedError}} and abort these steps.
317
+
318
+ 1. Let <var> outputProperties</var> be the value of |config|'s
319
+ {{ApplyDescriptor/outputProperties}} .
320
+
321
+ 1. If the |outputProperties| contains a property
322
+ that is in the <a>list of affected output properties</a> , <a>throw</a> a
323
+ {{NotSupportedError}} and abort these steps.
281
324
282
- Issue(49): This is too inflexible. There’s a strong use case around writing to the
283
- same native property for different elements. Maybe throw exception to
284
- window.onError in this case?
325
+ Issue(49): This is too inflexible. There’s a strong use case around writing to the
326
+ same native property for different elements. Maybe throw exception to
327
+ window.onError in this case?
328
+
329
+ 1. If the result of <a>IsConstructor</a> (argument=|applyCtor|) is false,
330
+ <a>throw</a> a {{NotSupportedError}} and abort these steps.
331
+
332
+ 1. Let <var> prototype</var> be the result of <a>Get</a> (O=|applyCtor|, P="prototype").
333
+
334
+ 1. If the result of <a>IsCallable</a> (argument=<a>Get</a> (O=|prototype|, P="apply"))
335
+ is false, <a>throw</a> a {{NotSupportedError}} and abort these steps.
336
+
337
+ 1. Let <var> applyInstance</var> be the result of <a>Construct</a> (|applyCtor|).
338
+
339
+ 1. Add the key-value pair (|name| - |applyInstance|) to the
340
+ <a>name map of apply hooks</a> of the {{StyleWorklet}} .
341
+
342
+ 1. Add each property in |outputProperties| to
343
+ the <a>list of affected output properties</a> of the {{StyleWorklet}} .
344
+
345
+ 1. Add the key-value pair (|name| - |outputProperties|) to the
346
+ <a>name map of outputs</a> of the {{StyleWorklet}} .
347
+
348
+ 1. Let <var> inputProperties</var> be the value of |config|'s
349
+ {{ApplyDescriptor/inputProperties}} .
350
+
351
+ 1. Add the key-value pair (|name| - |inputProperties|) to the
352
+ <a>name map of inputs</a> of the {{StyleWorklet}} .
353
+
354
+ Issue: This is one instance per apply hook. Do we want one instance per invocation?
285
355
286
356
Invoking apply hooks {#invoking-apply-hooks}
287
357
--------------------------------------------
288
358
289
- Each time style is recomputed for an Element, each registered {{ ApplyDescriptor/applyHook}}
359
+ Each time style is recomputed for an Element, each registered ApplyDescriptor/applyHook
290
360
for which any of the matching {{ApplyDescriptor/inputProperties}} changes as a result of
291
361
that recomputation is invoked. This invocation happens after any transitions or animations
292
- registered on the Element have finished applying.
362
+ registered on the Element have finished applying, in the context of a {{StyleWorklet}} .
293
363
294
364
Note: apply hooks are called after transitions/animations so that custom properties
295
365
can be transitioned and still have their effect apply correctly.
296
366
297
- This invocation takes place in an <a>isolated worker</a> .
367
+ This invocation takes place by following these steps for each key <var> name</var>
368
+ in the <a>name map of apply hooks</a> :
369
+
370
+ 1. Let <var> inputs</var> be the result of looking up <var> name</var> on the
371
+ {{StyleWorklet}} 's <a>name map of inputs</a> .
372
+
373
+ 1. Let <var> inputStyleMap</var> be a new {{StylePropertyMapReadOnly}} populated
374
+ with only the <a>computed value</a> s for properties listed in |inputs|.
375
+
376
+ 1. Let <var> proxy</var> be a new {{ElementProxy}} .
377
+
378
+ Issue: Need to fill out the ElementProxy.
379
+
380
+ 1. <a>invoke a method on a class inside a Worklet</a> given "apply" as the
381
+ <var> methodPropertyKey</var> and [|proxy|] as the <var> arguments</var> with
382
+ the following options:
383
+
384
+ * To <a>create a worklet global scope</a> the user agent will return a new
385
+ {{StyleWorklet}}
386
+ * To <a>lookup a class instance on a worklet global scope</a> given a
387
+ <var> workletGlobalScope</var> the user agent will return the result of
388
+ looking up <var> name</var> on the <var> workletGlobalScope</var> 's
389
+ <a>name map of apply hooks</a> .
390
+
391
+ If an exception is thrown then abort these steps.
298
392
393
+ Issue: Need to deal with the output.
299
394
300
395
Examples {#examples}
301
396
====================
0 commit comments