Skip to content

Commit 514a2ae

Browse files
committed
[css-layout-api] Firm up IntrinsicSizes description.
1 parent 9d98895 commit 514a2ae

File tree

1 file changed

+78
-23
lines changed

1 file changed

+78
-23
lines changed

css-layout-api/Overview.bs

+78-23
Original file line numberDiff line numberDiff line change
@@ -318,17 +318,21 @@ A {{LayoutFragment}} represents a CSS <a>fragment</a> of a {{LayoutChild}} after
318318
on that child. This is produced by the {{LayoutChild/layoutNextFragment()}} method.
319319

320320
The {{LayoutFragment}} has {{LayoutFragment/inlineSize}} and {{LayoutFragment/blockSize}}
321-
attributes, which are set by the respective child's layout algorithm. They cannot be changed. If the
322-
<a>current layout</a> requires a different {{LayoutFragment/inlineSize}} or
321+
attributes, which are set by the respective child's layout algorithm. They represent the <b>border
322+
box</b> size of the CSS <a>fragment</a>, and are relative to the <a>current layout's</a> writing
323+
mode.
324+
325+
The {{LayoutFragment/inlineSize}} and {{LayoutFragment/blockSize}} attributes cannot be changed. If
326+
the <a>current layout</a> requires a different {{LayoutFragment/inlineSize}} or
323327
{{LayoutFragment/blockSize}} the author must perform {{LayoutChild/layoutNextFragment()}} again with
324328
different arguments in order to get different results.
325329

326330
The author inside the current layout can position a resulting {{LayoutFragment}} by setting its
327331
{{LayoutFragment/inlineOffset}} and {{LayoutFragment/blockOffset}} attributes. If not set by the
328332
author they default to zero. The {{LayoutFragment/inlineOffset}} and {{LayoutFragment/blockOffset}}
329-
attributes represent the position of the {{LayoutFragment}} relative to its parent's border box,
330-
before transform or positioning (e.g. if a fragment is <a>relatively positioned</a>) has been
331-
applied.
333+
attributes represent the position of the {{LayoutFragment}} relative to its parent's <b>border
334+
box</b>, before transform or positioning (e.g. if a fragment is <a>relatively positioned</a>) has
335+
been applied.
332336

333337
<div class="example">
334338
The layout algorithm performs a block-like layout (positioning fragments sequentially in the block
@@ -342,11 +346,11 @@ registerLayout('block-like', class {
342346
});
343347

344348
const maxContentSize = childrenSizes.reduce((max, childSizes) => {
345-
return Math.max(max, childSizes.maxContentContribution);
349+
return Math.max(max, childSizes.maxContentSize);
346350
}, 0) + edges.all.inline;
347351

348352
const minContentSize = childrenSizes.reduce((max, childSizes) => {
349-
return Math.max(max, childSizes.minContentContribution);
353+
return Math.max(max, childSizes.minContentSize);
350354
}, 0) + edges.all.inline;
351355

352356
return {maxContentSize, minContentSize};
@@ -398,8 +402,70 @@ particular child. The {{LayoutFragment/breakToken}} cannot be changed.
398402
If the <a>current layout</a> requires a different {{LayoutFragment/breakToken}} the author must perform
399403
{{LayoutChild/layoutNextFragment()}} again with different arguments.
400404

401-
Note: In a future level of the specification there may be a way to query for additional baseline
402-
information, for example where the alphabetic or center baseline is positioned.
405+
Intrinsic Sizes {#intrinsic-sizes}
406+
----------------------------------
407+
408+
<pre class='idl'>
409+
[Exposed=LayoutWorklet]
410+
interface IntrinsicSizes {
411+
readonly attribute double minContentSize;
412+
readonly attribute double maxContentSize;
413+
};
414+
</pre>
415+
416+
A {{IntrinsicSizes}} object represents the <a>min-content size</a> and <a>max-content size</a> of a
417+
CSS <a>box</a>. It has {{IntrinsicSizes/minContentSize}} and {{IntrinsicSizes/maxContentSize}}
418+
attributes which represent the <b>border box</b> min/max-content contribution of the {{LayoutChild}}
419+
for the <a>current layout</a>. The attributes are relative to the inline direction of the <a>current
420+
layout's</a> writing mode.
421+
422+
The {{IntrinsicSizes/minContentSize}} and {{IntrinsicSizes/maxContentSize}} cannot be changed. They
423+
must not change for a {{LayoutChild}} within the current layout pass.
424+
425+
<div class="example">
426+
The example below shows the border-box intrinsic sizes of two children.
427+
428+
<pre class="lang-html">
429+
&lt;style>
430+
.child-0 {
431+
width: 380px;
432+
border: solid 10px;
433+
}
434+
435+
.child-1 {
436+
border: solid 5px;
437+
}
438+
439+
.box {
440+
display: layout(intrinsic-sizes-example);
441+
font: 25px/1 Ahem;
442+
}
443+
&lt;/style>
444+
445+
&lt;div class="box">
446+
&lt;div class="child-0">&lt;/div>
447+
&lt;div class="child-1">XXX XXXX&lt;/div>
448+
&lt;/div>
449+
</pre>
450+
451+
<pre class="lang-javascript">
452+
registerLayout('intrinsic-sizes-example', class {
453+
*intrinsicSizes(children, edges, styleMap) {
454+
const childrenSizes = yield children.map((child) => {
455+
return child.intrinsicSizes();
456+
});
457+
458+
childrenSizes[0].minContentSize; // 400, (380+10+10) child has a fixed size.
459+
childrenSizes[0].maxContentSize; // 400, (380+10+10) child has a fixed size.
460+
461+
childrenSizes[1].minContentSize; // 100, size of "XXXX".
462+
childrenSizes[1].maxContentSize; // 200, size of "XXX XXXX".
463+
}
464+
465+
*layout() {}
466+
});
467+
</pre>
468+
</div>
403469

404470
Layout Constraints {#layout-constraints}
405471
----------------------------------------
@@ -470,11 +536,11 @@ registerLayout('flex-distribution-like', class {
470536
});
471537

472538
const maxContentSize = childrenSizes.reduce((sum, childSizes) => {
473-
return sum + childSizes.maxContentContribution;
539+
return sum + childSizes.maxContentSize;
474540
}, 0) + edges.all.inline;
475541

476542
const minContentSize = childrenSizes.reduce((max, childSizes) => {
477-
return sum + childSizes.minContentContribution;
543+
return sum + childSizes.minContentSize;
478544
}, 0) + edges.all.inline;
479545

480546
return {maxContentSize, minContentSize};
@@ -937,12 +1003,11 @@ child to fragment.
9371003
Alignment {#interaction-alignment}
9381004
----------------------------------
9391005

940-
The first/last baseline sets of a <a>layout API contrainer</a> is generated exactly like block
1006+
The first/last baseline sets of a <a>layout API container</a> is generated exactly like block
9411007
containers do (see [[css-align-3#baseline-export]]). Except that the order of the in-flow children
9421008
should be determined by the in which they are returned form the layout method (via
9431009
{{FragmentResultOptions/childFragments}}) instead of the document order.
9441010

945-
9461011
<div class="note">
9471012
Note: In a future level of the specification there will be the ability for the author to define the
9481013
baselines themselves. This will be of the form:
@@ -1403,18 +1468,8 @@ dictionary IntrinsicSizesResultOptions {
14031468
double maxContentSize;
14041469
double minContentSize;
14051470
};
1406-
1407-
interface IntrinsicSizes {
1408-
readonly attribute double minContentSize;
1409-
readonly attribute double maxContentSize;
1410-
};
14111471
</pre>
14121472

1413-
Issue: Should {{IntrinsicSizes/minContentSize}} and {{IntrinsicSizes/maxContentSize}} be content
1414-
contributions instead? E.g. minContentContribution, maxContentContribution. Should
1415-
{{IntrinsicSizesResultOptions/minContentSize}} and
1416-
{{IntrinsicSizesResultOptions/maxContentSize}} be content contributions as well?
1417-
14181473
### Determining Intrinsic Sizes ### {#determining-intrinsic-sizes}
14191474

14201475
The <a>determine the intrinsic sizes</a> algorithm defines how a user agent is to query the author

0 commit comments

Comments
 (0)