Skip to content

Commit 3ada9ba

Browse files
committed
[css-layout-api] Rework LayoutConstraints args, update examples.
1 parent b910d70 commit 3ada9ba

File tree

1 file changed

+52
-98
lines changed

1 file changed

+52
-98
lines changed

css-layout-api/Overview.bs

Lines changed: 52 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -349,17 +349,11 @@ registerLayout('block-like', class {
349349
}
350350

351351
*layout(constraints, children, styleMap, edges) {
352-
const inlineSize = resolveInlineSize(constraints, styleMap);
353-
354-
const availableInlineSize = inlineSize - edges.all.inline;
355-
const availableBlockSize =
356-
resolveBlockSize(constraints, styleMap) - edges.all.block;
352+
const availableInlineSize = constraints.fixedInlineSize - edges.all.inline;
353+
const availableBlockSize = (constraints.fixedBlockSize || Infinity) - edges.all.block;
357354

358355
const childFragments = [];
359-
const childConstraints = new LayoutConstraints({
360-
inlineSize: availableInlineSize,
361-
blockSize: availableBlockSize,
362-
});
356+
const childConstraints = { availableInlineSize, availableBlockSize };
363357

364358
const childFragments = yield children.map((child) => {
365359
return child.layoutNextFragment(childConstraints);
@@ -409,11 +403,11 @@ Layout Constraints {#layout-constraints}
409403
<pre class='idl'>
410404
[Constructor(optional LayoutConstraintsOptions options),Exposed=LayoutWorklet]
411405
interface LayoutConstraints {
412-
readonly attribute double inlineSize;
413-
readonly attribute double blockSize;
406+
readonly attribute double availableInlineSize;
407+
readonly attribute double availableBlockSize;
414408

415-
readonly attribute boolean inlineSizeFixed;
416-
readonly attribute boolean blockSizeFixed;
409+
readonly attribute double? fixedInlineSize;
410+
readonly attribute double? fixedBlockSize;
417411

418412
readonly attribute double percentageInlineSize;
419413
readonly attribute double percentageBlockSize;
@@ -425,67 +419,40 @@ interface LayoutConstraints {
425419
};
426420

427421
dictionary LayoutConstraintsOptions {
428-
double inlineSize = Infinity;
429-
double blockSize = Infinity;
422+
double availableInlineSize = 0;
423+
double availableBlockSize = 0;
430424

431-
boolean inlineSizeFixed = false;
432-
boolean blockSizeFixed = false;
425+
double fixedInlineSize;
426+
double fixedBlockSize;
433427

434-
double? percentageInlineSize = null;
435-
double? percentageBlockSize = null;
428+
double percentageInlineSize;
429+
double percentageBlockSize;
436430

437-
double? blockFragmentationOffset = null;
431+
double blockFragmentationOffset;
438432
BlockFragmentationType blockFragmentationType = "none";
439433

440-
any data = null;
434+
any data;
441435
};
442436

443437
enum BlockFragmentationType { "none", "page", "column", "region" };
444438
</pre>
445439

446-
<div class="issue">
447-
Issue: Should {{LayoutConstraintsOptions}} be instead:
448-
449-
<pre class="lang-javascript">
450-
const options = {
451-
availableInlineSize: 100,
452-
availableBlockSize: Infinity,
453-
454-
fixedInlineSize: 150, // This makes the engine ignore availableInlineSize.
455-
fixedBlockSize: 150, // This makes the engine ignore availableBlockSize.
456-
457-
percentageInlineSize: 100, // This defaults to fixedInlineSize,
458-
// then availableInlineSize if not set.
459-
percentageBlockSize: 100, // This defaults to fixedBlockSize,
460-
// then availableBlockSize if not set.
461-
462-
blockFragmentationOffset: 200,
463-
blockFragmentationType: 'column',
464-
465-
data: {floatPositions: [{x: 20, y: 30}]}, // Author data.
466-
};
467-
</pre>
440+
A {{LayoutConstraints}} object is passed into the layout method which represents the all the
441+
constraints for the <a>current layout</a> to perform layout inside. It is also used to pass
442+
information about the available space into a <a>child layout</a>.
468443

469-
The layout constraints object would mirror this, additionally with the blockSize, and inlineSize
470-
attributes which represent the resolved inline and block sizes for the fragment.
471-
472-
</div>
473-
474-
A {{LayoutConstraints}} object is passed into the layout method which represents the available space
475-
for the <a>current layout</a> to perform layout inside. It is also used to pass information about
476-
the available space into a <a>child layout</a>.
477-
478-
The {{LayoutConstraints}} object has {{LayoutConstraints/inlineSize}} and
479-
{{LayoutConstraints/blockSize}} attributes. This represents the <a>available space</a> for a
480-
{{Fragment}} which the layout should respect.
444+
The {{LayoutConstraints}} object has {{LayoutConstraints/availableInlineSize}} and
445+
{{LayoutConstraints/availableBlockSize}} attributes. This represents the <a>available space</a> for
446+
a {{Fragment}} which the layout should respect.
481447

482448
Note: Some layouts may need to produce a {{Fragment}} which exceed this size. For example a
483449
<a>replaced element</a>. The <a>parent layout</a> should expect this to occur and deal with it
484450
appropriately.
485451

486452
A <a>parent layout</a> may require the <a>current layout</a> to be exactly a particular size. If
487-
the {{LayoutConstraints/inlineSizeFixed}} or {{LayoutConstraints/blockSizeFixed}} are true the
488-
<a>current layout</a> should produce a {{Fragment}} with a fixed size in the appropriate direction.
453+
the {{LayoutConstraints/fixedInlineSize}} or {{LayoutConstraints/fixedBlockSize}} are specified the
454+
<a>current layout</a> should produce a {{Fragment}} with a the specified size in the appropriate
455+
direction.
489456

490457
<div class="example">
491458
The layout algorithm performs a flexbox-like distribution of spare space in the inline direction. It
@@ -494,6 +461,7 @@ creates child layout constraints which specify that a child should be a fixed in
494461
<pre class="lang-javascript">
495462
registerLayout('flex-distribution-like', class {
496463
*intrinsicSizes(styleMap, children) {
464+
// TODO - Fix this example, below is slightly wrong.
497465
const childrenSizes = yield children.map((child) => {
498466
return child.intrinsicSizes();
499467
});
@@ -509,17 +477,14 @@ registerLayout('flex-distribution-like', class {
509477
return {maxContentSize, minContentSize};
510478
}
511479

512-
*layout(constraints, children, styleMap, edges, breakToken) {
513-
const inlineSize = resolveInlineSize(constraints, styleMap);
480+
*layout(constraints, children, styleMap, edges) {
514481

515-
const availableInlineSize = inlineSize - edges.all.inline;
482+
const availableInlineSize =
483+
constraints.fixedInlineSize - edges.all.inline;
516484
const availableBlockSize =
517-
resolveBlockSize(constraints, styleMap) - edges.all.block;
485+
(constraints.fixedInlineSize || Infinity) - edges.all.block;
518486

519-
const childConstraints = new LayoutConstraints({
520-
inlineSize: availableInlineSize,
521-
blockSize: availableBlockSize,
522-
});
487+
const childConstraints = { availableInlineSize, availableBlockSize };
523488

524489
const unconstrainedChildFragments = yield children.map((child) => {
525490
return child.layoutNextFragment(childConstraints);
@@ -536,11 +501,10 @@ registerLayout('flex-distribution-like', class {
536501
const extraSpace = remainingSpace / children.length;
537502

538503
const childFragments = yield children.map((child, i) => {
539-
return child.layoutNextFragment(new LayoutConstraints({
540-
inlineSize: unconstrainedSizes[i] + extraSpace,
541-
inlineSizeFixed: true,
542-
blockSize: availableBlockSize
543-
}));
504+
return child.layoutNextFragment({
505+
fixedInlineSize: unconstrainedSizes[i] + extraSpace,
506+
availableBlockSize
507+
});
544508
});
545509

546510
// Position the fragments.
@@ -554,13 +518,9 @@ registerLayout('flex-distribution-like', class {
554518
maxChildBlockSize = Math.max(maxChildBlockSize, fragment.blockSize);
555519
}
556520

557-
// Resolve our block size.
558-
const blockSize = resolveBlockSize(constraints, styleMap, maxChildBlockSize);
559-
560521
return {
561-
inlineSize: inlineSize,
562-
blockSize: blockSize,
563-
childFragments: childFragments,
522+
autoBlockSize: maxChildBlockSize + edges.all.block,
523+
childFragments,
564524
};
565525
}
566526
});
@@ -573,9 +533,9 @@ percentages should be resolved against while performing layout.
573533

574534
The {{LayoutConstraints}} has a {{LayoutConstraints/blockFragmentationType}} attribute. The
575535
<a>current layout</a> should produce a {{Fragment}} which fragments at the
576-
{{LayoutConstraints/blockSize}} if possible.
536+
{{LayoutConstraints/blockFragmentationOffset}} if possible.
577537

578-
The <a>current layout</a> may choose not to fragment a {{LayoutChild}} based on the
538+
The <a>current layout</a> can choose not to fragment a {{LayoutChild}} based on the
579539
{{LayoutConstraints/blockFragmentationType}}, for example if the child has a property like
580540
''break-inside: avoid-page;''.
581541

@@ -633,13 +593,12 @@ registerLayout('indent-lines', class {
633593
static inputProperties = ['--indent', '--indent-lines'];
634594

635595
*layout(constraints, children, styleMap, edges, breakToken) {
636-
// Resolve our inline size.
637-
const inlineSize = resolveInlineSize(constraints, styleMap);
638596

639597
// Determine our (inner) available size.
640-
const availableInlineSize = inlineSize - edges.all.inline;
598+
const availableInlineSize =
599+
constraints.fixedInlineSize - edges.all.inline;
641600
const availableBlockSize =
642-
resolveBlockSize(constraints, styleMap) - edges.all.block;
601+
(constraints.fixedBlockSize || Infinity) - edges.all.block;
643602

644603
// Detrermine the number of lines to indent, and the indent amount.
645604
const indent = resolveLength(constraints, styleMap.get('--indent'));
@@ -664,12 +623,12 @@ registerLayout('indent-lines', class {
664623
const childAvailableInlineSize = shouldIndent ?
665624
availableInlineSize - indent : availableInlineSize;
666625

667-
const childConstraints = new LayoutConstraints({
668-
inlineSize: childAvailableInlineSize,
669-
blockSize: availableBlockSize,
626+
const childConstraints = {
627+
availableInlineSize: childAvailableInlineSize,
628+
availableBlockSize,
670629
percentageInlineSize: availableInlineSize,
671630
blockFragmentationType: constraints.blockFragmentationType,
672-
});
631+
};
673632

674633
const fragment = yield child.layoutNextFragment(childConstraints,
675634
childBreakToken);
@@ -698,14 +657,10 @@ registerLayout('indent-lines', class {
698657
}
699658

700659
const autoBlockSize = blockOffset + edges.all.blockEnd;
701-
const blockSize = resolveBlockSize(constraints,
702-
styleMap,
703-
autoBlockSize);
704660

705661
// Return our fragment.
706662
const result = {
707-
inlineSize: inlineSize,
708-
blockSize: blockSize,
663+
autoBlockSize,
709664
childFragments: childFragments,
710665
}
711666

@@ -813,10 +768,9 @@ User agents must use the {{LayoutConstraints}} object to communicate to the <a>c
813768
the size they would like the fragment to be.
814769

815770
If the user agent wishes to force a size on the box, it can use the
816-
{{LayoutConstraints/inlineSizeFixed}} and {{LayoutConstraints/blockSizeFixed}} attributes to do so.
771+
{{LayoutConstraints/fixedInlineSize}} and {{LayoutConstraints/fixedBlockSize}} attributes to do so.
817772

818-
Issue: Do we want the inlineSize to always be fixed? This would remove the resolveInlineSize call,
819-
and just rely on the pre-defined behaviour by the user agent.
773+
Issue: Do we want the inlineSize to always be fixed?
820774

821775
The downside to this is that we won't be able to things like MathML in the initial version of
822776
the specifcation, which is able to "bubble" up inline sizes to its parent.
@@ -825,8 +779,8 @@ Issue: Do we want the inlineSize to always be fixed? This would remove the resol
825779
fragment which is undergoing fragmentation, isn't able to be automatically resolved.
826780

827781
If the <a>layout API container</a> is within a <a>block formatting context</a>, is inflow, and has
828-
an ''width/auto'' inline size, the user agent <em>must</em> set the {{LayoutConstraints/inlineSize}}
829-
to the <a>stretch-fit inline size</a>.
782+
an ''width/auto'' inline size, the user agent <em>must</em> set the
783+
{{LayoutConstraints/fixedInlineSize}} to the <a>stretch-fit inline size</a>.
830784

831785
<div class="note">
832786
Note: In the example below the <a>layout API container</a> has its inline size set to 50.
@@ -854,8 +808,8 @@ to the <a>stretch-fit inline size</a>.
854808

855809
If a <a>layout API container</a> is out-of-flow positioned the user agent <em>must</em> solve the
856810
positioned size equations ([[css-position-3#abs-non-replaced-width]],
857-
[[css-position-3#abs-non-replaced-height]]), and set the appropriate fixed
858-
{{LayoutConstraints/inlineSize}} and {{LayoutConstraints/blockSize}}.
811+
[[css-position-3#abs-non-replaced-height]]), and set the appropriate
812+
{{LayoutConstraints/fixedInlineSize}} and {{LayoutConstraints/fixedBlockSize}}.
859813

860814
<div class="note">
861815
Note: In the example below the <a>layout API container</a> has its inline and block size fixed

0 commit comments

Comments
 (0)