Skip to content

Commit 760094f

Browse files
committed
[css-layout-api] Add LayoutEdges
1 parent 04b9807 commit 760094f

File tree

1 file changed

+115
-74
lines changed

1 file changed

+115
-74
lines changed

css-layout-api/Overview.bs

Lines changed: 115 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ urlPrefix: https://drafts.csswg.org/css-sizing/#; type: dfn
6969
text: intrinsic sizes
7070
urlPrefix: https://drafts.csswg.org/css-break/#; type: dfn
7171
text: fragmentation break
72+
urlPrefix: https://www.w3.org/TR/CSS21/box.html#; type: dfn
73+
url: box-dimensions; text: box model edges
7274
</pre>
7375

7476
Introduction {#intro}
@@ -297,20 +299,11 @@ registerLayout('block-like', class extends Layout {
297299
static blockifyChildren = true;
298300
static inputProperties = super.inputProperties;
299301

300-
*layout(space, children, styleMap) {
302+
*layout(space, children, styleMap, edges) {
301303
const inlineSize = resolveInlineSize(space, styleMap);
302304

303-
const bordersAndPadding = resolveBordersAndPadding(constraintSpace, styleMap);
304-
const scrollbarSize = resolveScrollbarSize(constraintSpace, styleMap);
305-
const availableInlineSize = inlineSize -
306-
bordersAndPadding.inlineStart -
307-
bordersAndPadding.inlineEnd -
308-
scrollbarSize.inline;
309-
310-
const availableBlockSize = resolveBlockSize(constraintSpace, styleMap) -
311-
bordersAndPadding.blockStart -
312-
bordersAndPadding.blockEnd -
313-
scrollbarSize.block;
305+
const availableInlineSize = inlineSize - edges.all.inline;
306+
const availableBlockSize = resolveBlockSize(constraintSpace, styleMap) - edges.all.block;
314307

315308
const childFragments = [];
316309
const childConstraintSpace = new ConstraintSpace({
@@ -319,7 +312,7 @@ registerLayout('block-like', class extends Layout {
319312
});
320313

321314
let maxChildInlineSize = 0;
322-
let blockOffset = bordersAndPadding.blockStart;
315+
let blockOffset = edges.all.blockStart;
323316

324317
for (let child of children) {
325318
const fragment = yield child.layoutNextFragment(childConstraintSpace);
@@ -328,15 +321,15 @@ registerLayout('block-like', class extends Layout {
328321
// inline direction.
329322
fragment.blockOffset = blockOffset;
330323
fragment.inlineOffset = Math.max(
331-
bordersAndPadding.inlineStart,
324+
edges.all.inlineStart,
332325
(availableInlineSize - fragment.inlineSize) / 2);
333326

334327
maxChildInlineSize =
335328
Math.max(maxChildInlineSize, childFragments.inlineSize);
336329
blockOffset += fragment.blockSize;
337330
}
338331

339-
const contentSize = blockOffset + bordersAndPadding.blockEnd;
332+
const contentSize = blockOffset + edges.all.blockEnd;
340333
const blockSize = resolveBlockSize(
341334
constraintSpace, styleMap, contentSize);
342335

@@ -422,20 +415,12 @@ creates child constraint spaces which specify that a child should be a fixed inl
422415

423416
<pre class="lang-javascript">
424417
registerLayout('flex-distribution-like', class {
425-
*layout(space, children, styleMap, breakToken) {
418+
*layout(space, children, styleMap, edges, breakToken) {
426419
const inlineSize = resolveInlineSize(space, styleMap);
427420

428-
const bordersAndPadding = resolveBordersAndPadding(constraintSpace, styleMap);
429-
const scrollbarSize = resolveScrollbarSize(constraintSpace, styleMap);
430-
const availableInlineSize = inlineSize -
431-
bordersAndPadding.inlineStart -
432-
bordersAndPadding.inlineEnd -
433-
scrollbarSize.inline;
434-
435-
const availableBlockSize = resolveBlockSize(constraintSpace, styleMap) -
436-
bordersAndPadding.blockStart -
437-
bordersAndPadding.blockEnd -
438-
scrollbarSize.block;
421+
const availableInlineSize = inlineSize - edges.all.inline;
422+
const availableBlockSize =
423+
resolveBlockSize(constraintSpace, styleMap) - edges.all.block;
439424

440425
const unconstrainedSizes = [];
441426
const childConstraintSpace = new ConstraintSpace({
@@ -549,23 +534,14 @@ resume the layout.
549534
registerLayout('basic-inline', class extends Layout {
550535
static inputProperties = super.inputProperties;
551536

552-
*layout(constraintSpace, children, styleMap, breakToken) {
537+
*layout(constraintSpace, children, styleMap, edges, breakToken) {
553538
// Resolve our inline size.
554539
const inlineSize = resolveInlineSize(constraintSpace, styleMap);
555540

556541
// Determine our (inner) available size.
557-
const bordersAndPadding =
558-
resolveBordersAndPadding(constraintSpace, styleMap);
559-
const scrollbarSize = resolveScrollbarSize(constraintSpace, styleMap);
560-
const availableInlineSize = inlineSize -
561-
bordersAndPadding.inlineStart -
562-
bordersAndPadding.inlineEnd -
563-
scrollbarSize.inline;
564-
565-
const availableBlockSize = resolveBlockSize(constraintSpace, styleMap) -
566-
bordersAndPadding.blockStart -
567-
bordersAndPadding.blockEnd -
568-
scrollbarSize.block;
542+
const availableInlineSize = inlineSize - edges.all.inline;
543+
const availableBlockSize =
544+
resolveBlockSize(constraintSpace, styleMap) - edges.all.block;
569545

570546
const childFragments = [];
571547

@@ -658,9 +634,7 @@ registerLayout('basic-inline', class extends Layout {
658634

659635
// Determine our block size.
660636
nextLine();
661-
const contentSize = lineOffset +
662-
bordersAndPadding.blockStart +
663-
bordersAndPadding.blockEnd;
637+
const contentSize = lineOffset + edges.all.block;
664638
const blockSize = resolveBlockSize(constraintSpace,
665639
styleMap,
666640
contentSize);
@@ -684,44 +658,98 @@ registerLayout('basic-inline', class extends Layout {
684658
</pre>
685659
</div>
686660

687-
Utility Functions {#utility-functions}
688-
--------------------------------------
661+
Edges {#edges}
662+
--------------
689663

690664
<pre class='idl'>
691665
[Exposed=LayoutWorklet]
692-
interface LayoutStrut {
666+
interface LayoutEdgeSizes {
693667
readonly attribute double inlineStart;
694668
readonly attribute double inlineEnd;
695669

696670
readonly attribute double blockStart;
697671
readonly attribute double blockEnd;
698-
};
699672

700-
[Exposed=LayoutWorklet]
701-
interface LayoutSize {
673+
// Convenience attributes for the sum in one direction.
702674
readonly attribute double inline;
703675
readonly attribute double block;
704676
};
705677

678+
[Exposed=LayoutWorklet]
679+
interface LayoutEdges {
680+
readonly attribute LayoutEdgeSizes border;
681+
readonly attribute LayoutEdgeSizes scrollbar;
682+
readonly attribute LayoutEdgeSizes padding;
683+
684+
readonly attribute LayoutEdgeSizes all;
685+
};
686+
</pre>
687+
688+
A {{LayoutEdges}} object is passed into the layout method. This represents size of the <a>box
689+
model edges</a> for the current box which is being laid out.
690+
691+
The {{LayoutEdges}} has {{LayoutEdges/border}}, {{LayoutEdges/scrollbar}}, and
692+
{{LayoutEdges/padding}} attributes. Each of these represent the width of their respective edge.
693+
694+
The {{LayoutEdges}} has the {{LayoutEdges/all}} attribute. This is a convenience attribute which
695+
represents the sum of the {{LayoutEdges/border}}, {{LayoutEdges/scrollbar}}, {{LayoutEdges/padding}}
696+
edges.
697+
698+
The {{LayoutEdgeSizes}} object represents the width in CSS pixels of an edge in each of the
699+
<a>abstract dimensions</a> ({{LayoutEdgeSizes/inlineStart}}, {{LayoutEdgeSizes/inlineEnd}},
700+
{{LayoutEdgeSizes/blockStart}}, {{LayoutEdgeSizes/blockEnd}}).
701+
702+
The {{LayoutEdgeSizes/inline}}, and {{LayoutEdgeSizes/block}} on the {{LayoutEdgeSizes}} object are
703+
convenience attributes which represent the sum in that direction.
704+
705+
<div class="example">
706+
This example shows an node styled by CSS, and what its respective {{LayoutEdges}} could contain.
707+
708+
<pre class="lang-html">
709+
&lt;style>
710+
.container {
711+
width: 50px;
712+
height: 50px;
713+
}
714+
715+
.box {
716+
display: layout(box-edges);
717+
718+
padding: 10%;
719+
border: solid 2px;
720+
overflow-y: scroll;
721+
}
722+
&lt;/style>
723+
724+
&lt;div class="container">
725+
&lt;div class="box">&lt;/div>
726+
&lt;/div>
727+
</pre>
728+
729+
<pre class="lang-javascript">
730+
registerLayout('box-edges', class extends Layout {
731+
*layout(constraintSpace, children, styleMap, edges, breakToken) {
732+
edges.padding.inlineStart; // 5 (as 10% * 50px = 5px).
733+
edges.border.blockEnd; // 2
734+
edges.scrollbar.inlineEnd; // UA-dependent, may be 0 or >0 (e.g. 16).
735+
edges.all.block; // 14 (2 + 5 + 5 + 2).
736+
}
737+
}
738+
</pre>
739+
</div>
740+
741+
Utility Functions {#utility-functions}
742+
--------------------------------------
743+
744+
<pre class='idl'>
745+
[Exposed=LayoutWorklet]
706746
partial interface LayoutWorkletGlobalScope {
707747
double resolveInlineSize(ConstraintSpace constraintSpace,
708748
StylePropertyMapReadOnly styleMap);
709749

710750
double resolveBlockSize(ConstraintSpace constraintSpace,
711751
StylePropertyMapReadOnly styleMap,
712752
optional double contentSize);
713-
714-
LayoutStrut resolveBordersAndPadding(ConstraintSpace constraintSpace,
715-
StylePropertyMapReadOnly styleMap);
716-
717-
LayoutSize resolveScrollbarSize(ConstraintSpace constraintSpace,
718-
StylePropertyMapReadOnly styleMap);
719-
};
720-
721-
[Exposed=LayoutWorklet]
722-
interface Layout {
723-
readonly attribute sequence&lt;DOMString> inputProperties;
724-
readonly attribute sequence&lt;DOMString> childInputProperties;
725753
};
726754
</pre>
727755

@@ -730,12 +758,22 @@ Issue: Specify the behaviour of these functions.
730758
Interactions with other Modules {#interactions-with-other-modules}
731759
==================================================================
732760

733-
This section describes how other css modules interact with the CSS Layout API.
761+
This section describes how other CSS modules interact with the CSS Layout API.
762+
763+
Sizing {#interaction-sizing}
764+
----------------------------
765+
766+
Positioning {#interaction-positioning}
767+
--------------------------------------
768+
769+
Overflow {#interaction-overflow}
770+
--------------------------------
734771

735-
Sizing {#sizing}
736-
----------------
772+
Fragmentation {#interaction-fragmentation}
773+
------------------------------------------
737774

738-
TODO
775+
Alignment {#interaction-alignment}
776+
----------------------------------
739777

740778
Layout {#layout}
741779
================
@@ -1006,7 +1044,7 @@ is called, the user agent <em>must</em> run the following steps:
10061044
// Intrinsic sizes code goes here.
10071045
}
10081046

1009-
*layout(constraintSpace, children, styleMap, breakToken) {
1047+
*layout(constraintSpace, children, styleMap, edges, breakToken) {
10101048
// Layout code goes here.
10111049
}
10121050
}
@@ -1326,34 +1364,37 @@ following steps:
13261364
7. Let |constraintSpace| be a new {{ConstraintSpace}} populated with the appropriate information
13271365
from |internalConstraintSpace|.
13281366

1329-
8. Let |breakToken| be a new {{BreakToken}} populated with the appropriate information from
1367+
8. Let |edges| be a new {{LayoutEdgeSizes}} populated with the <a>computed value</a> for all the
1368+
<a>box model edges</a> for |box|.
1369+
1370+
9. Let |breakToken| be a new {{BreakToken}} populated with the appropriate information from
13301371
|internalBreakToken|.
13311372

13321373
If |internalBreakToken| is null, let |breakToken| be null.
13331374

1334-
9. At this stage the user agent may re-use a <a>fragment</a> from a previous invocation if
1375+
10. At this stage the user agent may re-use a <a>fragment</a> from a previous invocation if
13351376
|children|, |styleMap|, |constraintSpace|, |breakToken| are equivalent to that previous
13361377
invocation. If so let the fragment output be that cached fragment and abort all these steps.
13371378

1338-
10. Let |layoutGeneratorFunction| be |definition|'s <a>layout generator function</a>.
1379+
11. Let |layoutGeneratorFunction| be |definition|'s <a>layout generator function</a>.
13391380

1340-
11. Let |layoutGenerator| be the result of <a>Invoke</a>(|layoutGeneratorFunction|,
1341-
|layoutInstance|, «|styleMap|, |children|, |constraintSpace|, |breakToken|»).
1381+
12. Let |layoutGenerator| be the result of <a>Invoke</a>(|layoutGeneratorFunction|,
1382+
|layoutInstance|, «|styleMap|, |children|, |constraintSpace|, |edges|, |breakToken|»).
13421383

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

1346-
12. Let |fragmentValue| be the result of <a>run a generator</a> given |layoutGenerator|, and
1387+
13. Let |fragmentValue| be the result of <a>run a generator</a> given |layoutGenerator|, and
13471388
<code>"layout"</code>.
13481389

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

1352-
13. Let |fragment| be the result of <a>converting</a> |fragmentValue| to a
1393+
14. Let |fragment| be the result of <a>converting</a> |fragmentValue| to a
13531394
{{FragmentResultOptions}}. If an exception is <a>thrown</a>, let |box| fallback to the
13541395
<a>flow layout</a> and abort all these steps.
13551396

1356-
14. Create a <a>fragment</a> for |box| with:
1397+
15. Create a <a>fragment</a> for |box| with:
13571398

13581399
- The <a>inline size</a> set to |fragment|'s {{FragmentResultOptions/inlineSize}}.
13591400

0 commit comments

Comments
 (0)