Skip to content

Commit 3326345

Browse files
committed
[css-layout-api] Move LayoutChild around, add usage example.
1 parent bd0a88e commit 3326345

File tree

1 file changed

+65
-31
lines changed

1 file changed

+65
-31
lines changed

css-layout-api/Overview.bs

+65-31
Original file line numberDiff line numberDiff line change
@@ -455,22 +455,40 @@ is called, the user agent <em>must</em> run the following steps:
455455
4. Otherwise, [=map/set=] |documentLayoutDefinitionMap|[|name|] to |documentDefinition|.
456456
</div>
457457

458-
Layout API Model and Terminology {#layout-api-model-and-terminology}
459-
====================================================================
458+
Terminology {#terminology}
459+
--------------------------
460460

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.
462463

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
464465
layout for.
465466

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=].
468471

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.
470476

471477
Layout Children {#layout-children}
472478
----------------------------------
473479

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+
474492
<pre class='idl'>
475493
[Exposed=LayoutWorklet]
476494
interface LayoutChild {
@@ -482,38 +500,57 @@ interface LayoutChild {
482500
</pre>
483501

484502
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=].
486504
- <dfn attribute for=LayoutChild>\[[styleMap]]</dfn> a {{StylePropertyMapReadOnly}}, this is the
487505
computed style for the child, it is populated with only the properties listed in
488506
<code>childInputProperties</code>.
489507

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']; }
491513

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) {
494515

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];
497519

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>
500537

501538
A {{LayoutChild}} could be generated by:
502539

503-
- An <a>element</a>.
540+
- An [=element=].
504541

505-
- A <a>root inline box</a>.
542+
- A [=root inline box=].
506543

507544
- A <a>::before</a> or <a>::after</a> pseudo-element.
508545

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.
512549

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:
514551

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=]).
517554

518555
- An element with ''display: table-cell'' which doesn't have a parent with ''display: table''.
519556

@@ -531,27 +568,24 @@ A {{LayoutChild}} could be generated by:
531568

532569
<div class="note">
533570
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=]:
535572
<pre class="lang-html">
536573
This is a next node, &lt;span>with some additional styling,
537574
that may&lt;/span> break over&lt;br>multiple lines.
538575
</pre>
539576
</div>
540577

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
542579
engines to perform text shaping across element boundaries.
543580

544581
<div class="note">
545582
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=]:
547584
<pre class="lang-html">
548585
&#x639;&lt;span style="color: blue">&#x639;&lt;/span>&#x639;
549586
</pre>
550587
</div>
551588

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-
555589
<div algorithm>
556590
The <dfn attribute for=LayoutChild>styleMap</dfn>, on getting from a {{LayoutChild}} |this|, the
557591
user agent must perform the following steps:
@@ -586,8 +620,8 @@ Note: Both {{LayoutChild/layoutNextFragment()}} and {{LayoutChild/intrinsicSizes
586620

587621
### LayoutChildren and the Box Tree ### {#layout-child-box-tree}
588622

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.
591625

592626
<div algorithm="get a layout child">
593627
When the user agent wants to <dfn>get a layout child</dfn> given |workletGlobalScope|, |name|, and

0 commit comments

Comments
 (0)