@@ -455,22 +455,40 @@ is called, the user agent <em>must</em> run the following steps:
455
455
4. Otherwise, [=map/set=] |documentLayoutDefinitionMap|[|name|] to |documentDefinition|.
456
456
</div>
457
457
458
- Layout API Model and Terminology {#layout-api-model-and- terminology}
459
- ====================================================================
458
+ Terminology {#terminology}
459
+ --------------------------
460
460
461
- This section gives an overview of the Layout API given to authors.
461
+ We define the following terms to be clear about which layout algorithm (formatting context) we are
462
+ talking about.
462
463
463
- The <dfn>current layout</dfn> is the layout algorithm for the <a> box</a> we are currently performing
464
+ The <dfn>current layout</dfn> is the layout algorithm for the [= box=] we are currently performing
464
465
layout for.
465
466
466
- The <dfn>parent layout</dfn> is the layout algorithm for the <a>box's</a> direct parent, (the layout
467
- algorithm which is requesting the <a>current layout</a> to be performed).
467
+ The <dfn>parent layout</dfn> is the layout algorithm for the [=box's=] direct parent, (the layout
468
+ algorithm which is requesting the [=current layout=] to be performed).
469
+
470
+ A <dfn>child layout</dfn> is the layout algorithm for a {{LayoutChild}} of the [=current layout=] .
468
471
469
- A <dfn>child layout</dfn> is the layout algorithm for a {{LayoutChild}} of the <a>current layout</a> .
472
+ Layout API {#layout-api}
473
+ ========================
474
+
475
+ This section gives an overview of the Layout API given to authors.
470
476
471
477
Layout Children {#layout-children}
472
478
----------------------------------
473
479
480
+ A {{LayoutChild}} represents either a CSS generated [=box=] before layout has occurred. (The box
481
+ or boxes will all have a computed value of 'display' that is not ''none'' ).
482
+
483
+ The {{LayoutChild}} does not contain any layout information itself (like inline or block size) but
484
+ can be used to generate {{LayoutFragment}} s which do contain layout information.
485
+
486
+ An author cannot construct a {{LayoutChild}} with this API, this happens at a separate stage of the
487
+ user agent rendering engine (post style resolution).
488
+
489
+ An array of {{LayoutChild}} ren is passed into the layout/intrinsicSizes methods which represents the
490
+ children of the current box which is being laid out.
491
+
474
492
<pre class='idl'>
475
493
[Exposed=LayoutWorklet]
476
494
interface LayoutChild {
@@ -482,38 +500,57 @@ interface LayoutChild {
482
500
</pre>
483
501
484
502
The {{LayoutChild}} has internal slot(s):
485
- - <dfn attribute for=LayoutChild>\[[box]]</dfn> a CSS <a> box</a> .
503
+ - <dfn attribute for=LayoutChild>\[[box]]</dfn> a CSS [= box=] .
486
504
- <dfn attribute for=LayoutChild>\[[styleMap]]</dfn> a {{StylePropertyMapReadOnly}} , this is the
487
505
computed style for the child, it is populated with only the properties listed in
488
506
<code> childInputProperties</code> .
489
507
490
- <hr>
508
+ <div class=example>
509
+ The example below shows the basic usage of a {{LayoutChild}} .
510
+ <pre class='lang-javascript'>
511
+ registerLayout('example-layout-child' , class {
512
+ static get childInputProperties() { return ['--foo'] ; }
491
513
492
- A {{LayoutChild}} represents either a CSS generated <a>box</a> before layout has occured. (The box
493
- or boxes will all have a computed value of 'display' that is not ''none'' ).
514
+ async layout(children, edges, constraints, styleMap) {
494
515
495
- The {{LayoutChild}} does not contain any layout information itself (like inline or block size) but
496
- can be used to generate {{LayoutFragment}} s which do contain layout information.
516
+ // An array of LayoutChildren is passed into both the layout function,
517
+ // and intrinsic sizes function below.
518
+ const child = children[0] ;
497
519
498
- An author cannot construct a {{LayoutChild}} with this API, this happens at a separate stage of the
499
- rendering engine (post style resolution).
520
+ // You can query the any properties listed in "childInputProperties".
521
+ const fooValue = child.styleMap.get('--foo' );
522
+
523
+ // And perform layout!
524
+ const fragment = await child.layoutNextFragment({});
525
+
526
+ }
527
+
528
+ async intrinsicSizes(children, edges, styleMap) {
529
+
530
+ // Or request the intrinsic size!
531
+ const childIntrinsicSize = await children[0] .intrinsicSizes();
532
+
533
+ }
534
+ });
535
+ </pre>
536
+ </div>
500
537
501
538
A {{LayoutChild}} could be generated by:
502
539
503
- - An <a> element</a> .
540
+ - An [= element=] .
504
541
505
- - A <a> root inline box</a> .
542
+ - A [= root inline box=] .
506
543
507
544
- A <a>::before</a> or <a>::after</a> pseudo-element.
508
545
509
- Note: Other pseudo-elements such as <a>::first-letter</a> or <a>::first-line</a> do not generate
510
- a {{LayoutChild}} for layout purposes. They are additional styling information for a text
511
- node.
546
+ Note: Other pseudo-elements such as <a>::first-letter</a> or <a>::first-line</a> do not
547
+ generate a {{LayoutChild}} for layout purposes. They are additional
548
+ styling information for a text node.
512
549
513
- - An <a> anonymous box</a> . For example an anonymous box may be inserted as a result of:
550
+ - An [= anonymous box=] . For example an anonymous box may be inserted as a result of:
514
551
515
- - A text node which has undergone <a> blockification</a> . (Or more generally a <a> root inline
516
- box</a> which has undergone <a> blockification</a> ).
552
+ - A text node which has undergone [= blockification=] . (Or more generally a [= root inline box=]
553
+ which has undergone [= blockification=] ).
517
554
518
555
- An element with ''display: table-cell'' which doesn't have a parent with ''display: table'' .
519
556
@@ -531,27 +568,24 @@ A {{LayoutChild}} could be generated by:
531
568
532
569
<div class="note">
533
570
Note: As an example the following would be placed into a single {{LayoutChild}} as they share a
534
- <a> root inline box</a> :
571
+ [= root inline box=] :
535
572
<pre class="lang-html">
536
573
This is a next node, <span>with some additional styling,
537
574
that may</span> break over<br>multiple lines.
538
575
</pre>
539
576
</div>
540
577
541
- Multiple non-<a> atomic inlines</a> are placed within the same {{LayoutChild}} to allow rendering
578
+ Multiple non-[= atomic inlines=] are placed within the same {{LayoutChild}} to allow rendering
542
579
engines to perform text shaping across element boundaries.
543
580
544
581
<div class="note">
545
582
Note: As an example the following should produce one {{LayoutFragment}} but is from
546
- three non-<a> atomic inlines</a> :
583
+ three non-[= atomic inlines=] :
547
584
<pre class="lang-html">
548
585
ع<span style="color: blue">ع</span>ع
549
586
</pre>
550
587
</div>
551
588
552
- An array of {{LayoutChild}} ren is passed into the layout method which represents the children of the
553
- current box which is being laid out.
554
-
555
589
<div algorithm>
556
590
The <dfn attribute for=LayoutChild>styleMap</dfn> , on getting from a {{LayoutChild}} |this|, the
557
591
user agent must perform the following steps:
@@ -586,8 +620,8 @@ Note: Both {{LayoutChild/layoutNextFragment()}} and {{LayoutChild/intrinsicSizes
586
620
587
621
### LayoutChildren and the Box Tree ### {#layout-child-box-tree}
588
622
589
- Each <a> box</a> has a <dfn attribute for=box>\[[layoutChildMap]]</dfn> internal slot, which is a
590
- <a> map</a> of {{LayoutWorkletGlobalScope}} s to {{LayoutChild}} ren.
623
+ Each [= box=] has a <dfn attribute for=box>\[[layoutChildMap]]</dfn> internal slot, which is a
624
+ [= map=] of {{LayoutWorkletGlobalScope}} s to {{LayoutChild}} ren.
591
625
592
626
<div algorithm="get a layout child">
593
627
When the user agent wants to <dfn>get a layout child</dfn> given |workletGlobalScope|, |name|, and
0 commit comments