Skip to content

Commit 6a15159

Browse files
committed
[css-layout-api] Firm up LayoutChild definition.
This includes proper internal slots for LayoutChild, LayoutFragmentRequest, IntrinsicSizes request. This also includes proper algorithms for all of LayoutChild.
1 parent 514a2ae commit 6a15159

File tree

1 file changed

+121
-20
lines changed

1 file changed

+121
-20
lines changed

css-layout-api/Overview.bs

+121-20
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ interface LayoutChild {
220220
};
221221
</pre>
222222

223+
The {{LayoutChild}} has internal slot(s):
224+
- <dfn attribute for=LayoutChild>\[[box]]</dfn> a CSS <a>box</a>.
225+
- <dfn attribute for=LayoutChild>\[[styleMap]]</dfn> a {{StylePropertyMapReadOnly}}, this is the
226+
computed style for the child, it is populated with only the properties listed in
227+
<code>childInputProperties</code>.
228+
229+
<hr>
230+
223231
A {{LayoutChild}} represents either a CSS generated <a>box</a> before layout has occured. (The box
224232
or boxes will all have a computed value of 'display' that is not ''none'').
225233

@@ -229,10 +237,6 @@ can be used to generate {{LayoutFragment}}s which do contain layout information.
229237
An author cannot construct a {{LayoutChild}} with this API, this happens at a separate stage of the
230238
rendering engine (post style resolution).
231239

232-
The {{LayoutChild}} has computed style which can be accessed by {{LayoutChild/styleMap}}. The
233-
{{LayoutChild/styleMap}} will only contain properties which are listed in the child input properties
234-
array.
235-
236240
A {{LayoutChild}} could be generated by:
237241

238242
- An <a>element</a>.
@@ -284,17 +288,104 @@ engines to perform text shaping across element boundaries.
284288
</pre>
285289
</div>
286290

287-
Note: In a future level of the specification there may be a way to query the computed style
288-
of <a>inline boxes</a> inside a <a>root inline box</a> represented by a {{LayoutChild}}.
289-
290291
An array of {{LayoutChild}}ren is passed into the layout method which represents the children of the
291292
current box which is being laid out.
292293

293-
To perform layout on a box the author can invoke the {{LayoutChild/layoutNextFragment()}} method.
294-
This will produce a {{LayoutFragment}} which contains layout information.
294+
<div algorithm>
295+
The <dfn attribute for=LayoutChild>styleMap</dfn>, on getting from a {{LayoutChild}} |this|, the
296+
user agent must perform the following steps:
297+
298+
1. Return |this|' {{StylePropertyMapReadOnly}} contained in the {{[[styleMap]]}} internal slot.
299+
</div>
300+
301+
<div algorithm>
302+
When the <dfn method for=LayoutChild>layoutNextFragment(|constraints|, |breakToken|)</dfn> method is
303+
called on a {{LayoutChild}} |this|, the user agent must perform the following steps:
304+
305+
1. Let |request| be a new {{LayoutFragmentRequest}} with internal slot(s):
306+
- {{LayoutFragmentRequest/[[layoutChild]]}} set to |this|.
307+
- {{[[layoutConstraints]]}} set to |constraints|.
308+
- {{[[breakToken]]}} set to |breakToken|.
309+
310+
2. Return |request|.
311+
</div>
312+
313+
<div algorithm>
314+
When the <dfn method for=LayoutChild>intrinsicSizes()</dfn> method is called on a {{LayoutChild}}
315+
|this|, the user agent must perform the following steps:
316+
317+
1. Let |request| be a new {{IntrinsicSizesRequest}} with internal slot(s):
318+
- {{IntrinsicSizesRequest/[[layoutChild]]}} set to |this|.
319+
320+
2. Return |request|.
321+
</div>
322+
323+
Note: Both {{LayoutChild/layoutNextFragment()}} and {{LayoutChild/intrinsicSizes()}} don't
324+
synchronously run. See [[#request-objects]] for a full description.
325+
326+
### LayoutChildren and the Box Tree ### {#layout-child-box-tree}
327+
328+
Each <a>box</a> has a <dfn attribute for=box>\[[layoutChildMap]]</dfn> internal slot, which is a <a>map</a> of
329+
{{LayoutWorkletGlobalScope}}s to {{LayoutChild}}ren.
330+
331+
<div algorithm="get a layout child">
332+
When the user agent wants to <dfn>get a layout child</dfn> given |workletGlobalScope|, |name|, and
333+
|box|, it <em>must</em> run the following steps:
334+
335+
1. Assert that:
336+
- |box| is currently attached to the <a>box tree</a>.
337+
- |box|'s <a>containing block</a> is a <a>layout API container</a>.
338+
- The <a>containing block</a>'s ''layout()'' function's first argument is |name|.
339+
340+
2. Let |layoutChildMap| be |box|'s {{[[layoutChildMap]]}}.
341+
342+
3. If |layoutChildMap|[|workletGlobalScope|] does not <a for=map>exist</a>, run the following
343+
steps:
295344

296-
The {{LayoutChild/layoutNextFragment()}} method may be invoked multiple times with different
297-
arguments to query the {{LayoutChild}} for different layout information.
345+
1. Let |definition| be the result of <a>get a layout definition</a> given |name|, and
346+
|workletGlobalScope|.
347+
348+
2. Let |childInputProperties| be |definition|'s <a for="layout definition">child input
349+
properties</a>.
350+
351+
3. Let |layoutChild| be a new {{LayoutChild}} with internal slot(s):
352+
- {{[[box]]}} set to |box|.
353+
- {{[[styleMap]]}} set to a new {{StylePropertyMapReadOnly}} populated with
354+
<em>only</em> the <a>computed values</a> for properties listed in
355+
|childInputProperties|.
356+
357+
4. <a for=map>Set</a> |layoutChildMap|[|workletGlobalScope|] to |layoutChild|.
358+
359+
4. Return the result of <a for=map>get</a> |layoutChildMap|[|workletGlobalScope|]
360+
</div>
361+
362+
When a <a>box</a> is inserted into the <a>box tree</a> the user agent <em>may</em> pre-populate the
363+
{{[[layoutChildMap]]}} for all {{LayoutWorkletGlobalScope}}s.
364+
365+
When a <a>box</a> is removed from the <a>box tree</a> the user agent <em>must</em> clear the
366+
{{[[layoutChildMap]]}}.
367+
368+
<div algorithm="update a layout child style">
369+
When the user agent wants to <dfn>update a layout child style</dfn> given |box|, it <em>must</em>
370+
run the following steps:
371+
372+
1. Assert that:
373+
- |box| is currently attached to the <a>box tree</a>.
374+
375+
2. If |box|'s <a>containing block</a> is not a <a>layout API container</a>, abort all these
376+
steps.
377+
378+
3. Let |layoutChildMap| be |box|'s {{[[layoutChildMap]]}}.
379+
380+
4. <a for=map>For each</a> |layoutChild| in |layoutChildMap|:
381+
382+
1. Let |styleMap| be |layoutChild|'s {{[[styleMap]]}}.
383+
384+
2. Update |styleMap|'s <a>declarations</a> based on the |box|'s new computed style.
385+
</div>
386+
387+
When the computed style of a <a>box</a> changes the user agent must run the <a>update a layout child
388+
style</a> algorithm.
298389

299390
Layout Fragments {#layout-fragments}
300391
------------------------------------
@@ -1047,7 +1138,7 @@ Concepts {#concepts}
10471138
--------------------
10481139

10491140
A <dfn>layout definition</dfn> is a <a>struct</a> which describes the information needed by the
1050-
{{LayoutWorkletGlobalScope}} about hte author defined layout (which can be referenced by the
1141+
{{LayoutWorkletGlobalScope}} about the author defined layout (which can be referenced by the
10511142
''layout()'' function). It consists of:
10521143

10531144
- <dfn for="layout definition">class constructor</dfn> which is the class <a>constructor</a>.
@@ -1371,23 +1462,33 @@ Layout Engine {#layout-engine}
13711462
- Potentially better bindings overhead.
13721463
</div>
13731464

1465+
### Request Objects ### {#request-objects}
13741466

13751467
<pre class="idl">
13761468
[Exposed=LayoutWorklet]
1377-
interface LayoutFragmentRequest {
1378-
// Has internal slots:
1379-
// [[layoutChild]] - The layout child to generate the fragment for.
1380-
// [[layoutConstraints]] - The layout constraints object to perform layout in.
1381-
// [[breakToken]] - The break token to resume the layout with.
1469+
interface IntrinsicSizesRequest {
13821470
};
13831471

13841472
[Exposed=LayoutWorklet]
1385-
interface IntrinsicSizesRequest {
1386-
// Has internal slots:
1387-
// [[layoutChild]] - The layout child to calculate the intrinsic sizes for.
1473+
interface LayoutFragmentRequest {
13881474
};
13891475
</pre>
13901476

1477+
The {{IntrinsicSizesRequest}} has internal slot(s):
1478+
- <dfn attribute for=IntrinsicSizesRequest>\[[layoutChild]]</dfn> a {{LayoutChild}}, this is the
1479+
child which the intrinsic sizes must be calculated for.
1480+
1481+
The {{LayoutFragmentRequest}} has internal slot(s):
1482+
- <dfn attribute for=LayoutFragmentRequest>\[[layoutChild]]</dfn> a {{LayoutChild}}, this is the
1483+
child which the fragment must be generated for.
1484+
- <dfn attribute for=LayoutFragmentRequest>\[[layoutConstraints]]</dfn> a
1485+
{{LayoutConstraintsOptions}} dictionary, these are the input constraints to the
1486+
{{LayoutChild}}'s layout algorithm.
1487+
- <dfn attribute for=LayoutFragmentRequest>\[[breakToken]]</dfn> a {{ChildBreakToken}} object,
1488+
which is the break token the layout must be resumed with.
1489+
1490+
<hr>
1491+
13911492
The layout method and intrinsic sizes method on the author supplied layout class is a generator
13921493
function instead of a regular javascript function. This is for user-agents to be able to support
13931494
asynchronous and parallel layout engines.

0 commit comments

Comments
 (0)