Skip to content

Commit e956a99

Browse files
committed
[css-layout-api] Re-order function arguments. Update examples.
1 parent 82f017f commit e956a99

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

css-layout-api/Overview.bs

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -336,23 +336,23 @@ direction), while centering its children in the inline direction.
336336

337337
<pre class="lang-javascript">
338338
registerLayout('block-like', class {
339-
*intrinsicSizes(styleMap, children) {
339+
*intrinsicSizes(children, edges, styleMap) {
340340
const childrenSizes = yield children.map((child) => {
341341
return child.intrinsicSizes();
342342
});
343343

344344
const maxContentSize = childrenSizes.reduce((max, childSizes) => {
345345
return Math.max(max, childSizes.maxContentContribution);
346-
}, 0);
346+
}, 0) + edges.all.inline;
347347

348348
const minContentSize = childrenSizes.reduce((max, childSizes) => {
349349
return Math.max(max, childSizes.minContentContribution);
350-
}, 0);
350+
}, 0) + edges.all.inline;
351351

352352
return {maxContentSize, minContentSize};
353353
}
354354

355-
*layout(constraints, children, styleMap, edges) {
355+
*layout(children, edges, constraints, styleMap) {
356356
const availableInlineSize = constraints.fixedInlineSize - edges.all.inline;
357357
const availableBlockSize = (constraints.fixedBlockSize || Infinity) - edges.all.block;
358358

@@ -464,24 +464,23 @@ creates child layout constraints which specify that a child should be a fixed in
464464

465465
<pre class="lang-javascript">
466466
registerLayout('flex-distribution-like', class {
467-
*intrinsicSizes(styleMap, children) {
468-
// TODO - Fix this example, below is slightly wrong.
467+
*intrinsicSizes(children, edges, styleMap) {
469468
const childrenSizes = yield children.map((child) => {
470469
return child.intrinsicSizes();
471470
});
472471

473472
const maxContentSize = childrenSizes.reduce((sum, childSizes) => {
474473
return sum + childSizes.maxContentContribution;
475-
}, 0);
474+
}, 0) + edges.all.inline;
476475

477476
const minContentSize = childrenSizes.reduce((max, childSizes) => {
478477
return sum + childSizes.minContentContribution;
479-
}, 0);
478+
}, 0) + edges.all.inline;
480479

481480
return {maxContentSize, minContentSize};
482481
}
483482

484-
*layout(constraints, children, styleMap, edges) {
483+
*layout(children, edges, constraints, styleMap) {
485484

486485
const availableInlineSize =
487486
constraints.fixedInlineSize - edges.all.inline;
@@ -596,7 +595,7 @@ registerLayout('indent-lines', class {
596595
static layoutOptions = {childDisplay: 'normal'};
597596
static inputProperties = ['--indent', '--indent-lines'];
598597

599-
*layout(constraints, children, styleMap, edges, breakToken) {
598+
*layout(children, edges, constraints, styleMap, breakToken) {
600599

601600
// Determine our (inner) available size.
602601
const availableInlineSize =
@@ -750,7 +749,7 @@ This example shows an node styled by CSS, and what its respective {{LayoutEdges}
750749

751750
<pre class="lang-javascript">
752751
registerLayout('box-edges', class {
753-
*layout(constraints, children, styleMap, edges, breakToken) {
752+
*layout(children, edges, constraints, styleMap, breakToken) {
754753
edges.padding.inlineStart; // 5 (as 10% * 50px = 5px).
755754
edges.border.blockEnd; // 2
756755
edges.scrollbar.inlineEnd; // UA-dependent, may be 0 or >0 (e.g. 16).
@@ -1238,11 +1237,11 @@ is called, the user agent <em>must</em> run the following steps:
12381237
return {childDisplay: 'normal', sizing: 'block-like'}
12391238
}
12401239

1241-
*intrinsicSizes(children, styleMap) {
1240+
*intrinsicSizes(children, edges, styleMap) {
12421241
// Intrinsic sizes code goes here.
12431242
}
12441243

1245-
*layout(constraints, children, styleMap, edges, breakToken) {
1244+
*layout(children, edges, constraints, styleMap, breakToken) {
12461245
// Layout code goes here.
12471246
}
12481247
}
@@ -1434,41 +1433,44 @@ When the user agent wants to <dfn>invoke a intrinsic sizes callback</dfn> given
14341433
4. Let |childInputProperties| be |definition|'s <a for="layout definition">child input
14351434
properties</a>.
14361435

1437-
5. Let |styleMap| be a new {{StylePropertyMapReadOnly}} populated with <em>only</em> the
1438-
<a>computed value</a>'s for properties listed in |inputProperties| for |box|.
1439-
1440-
6. Let |children| be a new <a>list</a> populated with new {{LayoutChild}} objects which
1436+
5. Let |children| be a new <a>list</a> populated with new {{LayoutChild}} objects which
14411437
represent |childBoxes|.
14421438

14431439
The {{LayoutChild/styleMap}} on each {{LayoutChild}} should be a new
14441440
{{StylePropertyMapReadOnly}} populated with <em>only</em> the <a>computed value</a>'s for
14451441
properties listed in |childInputProperties|.
14461442

1447-
7. At this stage the user agent may re-use the <a>intrinsic sizes</a> from a previous invocation
1443+
6. Let |edges| be a new {{LayoutEdgeSizes}} populated with the <a>computed value</a> for all the
1444+
<a>box model edges</a> for |box|.
1445+
1446+
7. Let |styleMap| be a new {{StylePropertyMapReadOnly}} populated with <em>only</em> the
1447+
<a>computed value</a>'s for properties listed in |inputProperties| for |box|.
1448+
1449+
8. At this stage the user agent may re-use the <a>intrinsic sizes</a> from a previous invocation
14481450
if |children|, |styleMap| are equivalent to that previous invocation. If so let the
14491451
intrinsic sizes the cached intrinsic sizes and abort all these steps.
14501452

1451-
8. Let |intrinsicSizesGeneratorFunction| be |definition|'s <a>intrinsic sizes generator
1453+
9. Let |intrinsicSizesGeneratorFunction| be |definition|'s <a>intrinsic sizes generator
14521454
function</a>.
14531455

1454-
9. Let |intrinsicSizesGenerator| be the result of
1455-
<a>Invoke</a>(|intrinsicSizesGeneratorFunction|, |layoutInstance|, «|styleMap|,
1456-
|children|»).
1456+
10. Let |intrinsicSizesGenerator| be the result of
1457+
<a>Invoke</a>(|intrinsicSizesGeneratorFunction|, |layoutInstance|, «|children|, |edges|,
1458+
|styleMap|»).
14571459

14581460
If an exception is <a>thrown</a> the let |box| fallback to the <a>flow layout</a> and abort
14591461
all these steps.
14601462

1461-
10. Let |intrinsicSizesValue| be the result of <a>run a generator</a> given
1463+
11. Let |intrinsicSizesValue| be the result of <a>run a generator</a> given
14621464
|intrinsicSizesGenerator|, and <code>"intrinsic-sizes"</code>.
14631465

14641466
If <a>run a generator</a> returned failure, then let |box| fallback to the <a>flow
14651467
layout</a> and abort all these steps.
14661468

1467-
11. Let |intrinsicSizes| be the result of <a>converting</a> |intrinsicSizesValue| to a
1469+
12. Let |intrinsicSizes| be the result of <a>converting</a> |intrinsicSizesValue| to a
14681470
{{IntrinsicSizesResultOptions}}. If an exception is <a>thrown</a>, let |box| fallback to the
14691471
<a>flow layout</a> and abort all these steps.
14701472

1471-
12. Set the <a>intrinsic sizes</a> of |box|:
1473+
13. Set the <a>intrinsic sizes</a> of |box|:
14721474

14731475
- Let |intrinsicSizes|'s {{IntrinsicSizesResultOptions/minContentSize}} be the
14741476
<a>min-content size</a> of |box|.
@@ -1551,21 +1553,21 @@ following steps:
15511553
4. Let |childInputProperties| be |definition|'s <a for="layout definition">child input
15521554
properties</a>.
15531555

1554-
5. Let |styleMap| be a new {{StylePropertyMapReadOnly}} populated with <em>only</em> the
1555-
<a>computed value</a>'s for properties listed in |inputProperties| for |box|.
1556-
1557-
6. Let |children| be a new <a>list</a> populated with new {{LayoutChild}} objects which
1556+
5. Let |children| be a new <a>list</a> populated with new {{LayoutChild}} objects which
15581557
represent |childBoxes|.
15591558

15601559
The {{LayoutChild/styleMap}} on each {{LayoutChild}} should be a new
15611560
{{StylePropertyMapReadOnly}} populated with <em>only</em> the <a>computed value</a>'s for
15621561
properties listed in |childInputProperties|.
15631562

1563+
6. Let |edges| be a new {{LayoutEdgeSizes}} populated with the <a>computed value</a> for all the
1564+
<a>box model edges</a> for |box|.
1565+
15641566
7. Let |layoutConstraints| be a new {{LayoutConstraints}} object populated with the appropriate
15651567
information from |internalLayoutConstraints|.
15661568

1567-
8. Let |edges| be a new {{LayoutEdgeSizes}} populated with the <a>computed value</a> for all the
1568-
<a>box model edges</a> for |box|.
1569+
8. Let |styleMap| be a new {{StylePropertyMapReadOnly}} populated with <em>only</em> the
1570+
<a>computed value</a>'s for properties listed in |inputProperties| for |box|.
15691571

15701572
9. Let |breakToken| be a new {{BreakToken}} populated with the appropriate information from
15711573
|internalBreakToken|.
@@ -1579,7 +1581,7 @@ following steps:
15791581
11. Let |layoutGeneratorFunction| be |definition|'s <a>layout generator function</a>.
15801582

15811583
12. Let |layoutGenerator| be the result of <a>Invoke</a>(|layoutGeneratorFunction|,
1582-
|layoutInstance|, «|styleMap|, |children|, |layoutConstraints|, |edges|, |breakToken|»).
1584+
|layoutInstance|, «|children|, |edges|, |layoutConstraints|, |styleMap|, |breakToken|»).
15831585

15841586
If an exception is <a>thrown</a> the let |box| fallback to the <a>flow layout</a> and abort
15851587
all these steps.

0 commit comments

Comments
 (0)