Skip to content

Commit d911b36

Browse files
committed
[css-layout-api] Remove the LayoutEdgeSizes objects.
1 parent ed1f5b6 commit d911b36

File tree

2 files changed

+55
-76
lines changed

2 files changed

+55
-76
lines changed

css-layout-api/EXPLAINER.md

+16-22
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ below. You should read the code below with its explanatory section.
6868
registerLayout('centering', class {
6969
async layout(children, edges, constraints, styleMap) {
7070
// (1) Determine our (inner) available size.
71-
const availableInlineSize = constraints.fixedInlineSize - edges.all.inline;
71+
const availableInlineSize = constraints.fixedInlineSize - edges.inline;
7272
const availableBlockSize = constraints.fixedBlockSize ?
73-
constraints.fixedBlockSize - edges.all.block :
73+
constraints.fixedBlockSize - edges.block :
7474
null;
7575

7676
let maxChildBlockSize = 0;
@@ -87,16 +87,16 @@ registerLayout('centering', class {
8787
maxChildBlockSize = Math.max(maxChildBlockSize, fragment.blockSize);
8888

8989
// Position our child fragment.
90-
fragment.inlineOffset = edges.all.inlineStart +
90+
fragment.inlineOffset = edges.inlineStart +
9191
(constraints.fixedInlineSize - fragment.inlineSize) / 2;
92-
fragment.blockOffset = edges.all.blockStart +
92+
fragment.blockOffset = edges.blockStart +
9393
Math.max(0, (constraints.fixedBlockSize - fragment.blockSize) / 2);
9494

9595
childFragments.push(fragment);
9696
}
9797

9898
// (3) Determine our "auto" block size.
99-
const autoBlockSize = maxChildBlockSize + edges.all.block;
99+
const autoBlockSize = maxChildBlockSize + edges.block;
100100

101101
// (4) Return our fragment.
102102
return {
@@ -140,9 +140,9 @@ The `edges` object represents the border, scrollbar, and padding of your element
140140
determine our "inner" size we subtract the `edges.all` from our calculated sizes. For example:
141141

142142
```js
143-
const availableInlineSize = constraints.fixedInlineSize - edges.all.inline;
143+
const availableInlineSize = constraints.fixedInlineSize - edges.inline;
144144
const availableBlockSize = constraints.fixedBlockSize ?
145-
constraints.fixedBlockSize - edges.all.block :
145+
constraints.fixedBlockSize - edges.block :
146146
null;
147147
```
148148

@@ -188,9 +188,9 @@ Now that we know how large our biggest child is going to be, we can calculate ou
188188
This is the size the element will be if there are no other block-size constraints (e.g. `height:
189189
100px`).
190190

191-
In this layout algorithm, we just add the `edges.all.block` size to the largest child we found:
191+
In this layout algorithm, we just add the `edges.block` size to the largest child we found:
192192
```js
193-
const autoBlockSize = maxChildBlockSize + edges.all.block;
193+
const autoBlockSize = maxChildBlockSize + edges.block;
194194
```
195195

196196
### Step (4) - Return our fragment ###
@@ -309,9 +309,9 @@ registerLayout('basic-inline', class {
309309

310310
async layout(children, edges, constraints, styleMap) {
311311
// Determine our (inner) available size.
312-
const availableInlineSize = constraints.fixedInlineSize - edges.all.inline;
312+
const availableInlineSize = constraints.fixedInlineSize - edges.inline;
313313
const availableBlockSize = constraints.fixedBlockSize !== null ?
314-
constraints.fixedBlockSize - edges.all.block : null;
314+
constraints.fixedBlockSize - edges.block : null;
315315

316316
const constraints = {
317317
availableInlineSize,
@@ -320,7 +320,7 @@ registerLayout('basic-inline', class {
320320

321321
const childFragments = [];
322322

323-
let blockOffset = edges.all.blockStart;
323+
let blockOffset = edges.blockStart;
324324
let child = children.shift();
325325
let childBreakToken = null;
326326
while (child) {
@@ -332,7 +332,7 @@ registerLayout('basic-inline', class {
332332

333333
// Position the fragment, note we coulld do something special here, like
334334
// placing all the lines on a "rythimic grid", or similar.
335-
fragment.inlineOffset = edges.all.inlineStart;
335+
fragment.inlineOffset = edges.inlineStart;
336336
fragment.blockOffset = blockOffset;
337337

338338
blockOffset += fragment.blockSize;
@@ -348,7 +348,7 @@ registerLayout('basic-inline', class {
348348
}
349349

350350
// Determine our "auto" block size.
351-
const autoBlockSize = blockOffset + edges.all.blockEnd;
351+
const autoBlockSize = blockOffset + edges.blockEnd;
352352

353353
// Return our fragment.
354354
return {
@@ -373,14 +373,8 @@ Scrolling
373373

374374
We have been handling scrolling in the above example but we haven't talked about it yet.
375375

376-
```js
377-
const scrollbarEdgeSizes = edges.scrollbar;
378-
scrollbarEdgeSizes.inline;
379-
scrollbarEdgeSizes.block;
380-
```
381-
382-
The above code snippet queries the size of the scrollbar, and respects the `overflow` property.
383-
For example if we are `overflow: hidden`, `edges.scrollbar` will report 0 for all directions.
376+
The `edges` object passed into `layout()` respects the `overflow` property.
377+
For example if we are `overflow: hidden`, `edges` object won't include the scrollbar width.
384378

385379
For `overflow: auto` the engine will typically perform a layout without a scrollbar, then if it
386380
detects overflow, with a scrollbar. As long as you respect the layout "edges" your layout algorithm

css-layout-api/Overview.bs

+39-54
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,8 @@ registerLayout('example-layout-fragment', class {
785785

786786
// You can set the position of the fragment, e.g. this will set it to the
787787
// top-left corner:
788-
fragment.inlineOffset = edges.all.inlineStart;
789-
fragment.blockOffset = edges.all.blockStart;
788+
fragment.inlineOffset = edges.inlineStart;
789+
fragment.blockOffset = edges.blockStart;
790790

791791
// Data may be passed from the child layout:
792792
console.log(fragment.data);
@@ -938,9 +938,9 @@ registerLayout('layout-constraints-example', class {
938938
async layout(children, edges, constraints, styleMap) {
939939

940940
// Calculate the available size.
941-
const availableInlineSize = constraints.fixedInlineSize - edges.all.inline;
941+
const availableInlineSize = constraints.fixedInlineSize - edges.inline;
942942
const availableBlockSize = constraints.fixedBlockSize ?
943-
constraints.fixedBlockSize - edges.all.inline : null;
943+
constraints.fixedBlockSize - edges.inline : null;
944944

945945
// Web developers should resolve any percentages against the percentage sizes.
946946
const value = constraints.percentageInlineSize * 0.5;
@@ -1093,7 +1093,7 @@ Edges {#edges}
10931093

10941094
<pre class='idl'>
10951095
[Exposed=LayoutWorklet]
1096-
interface LayoutEdgeSizes {
1096+
interface LayoutEdges {
10971097
readonly attribute double inlineStart;
10981098
readonly attribute double inlineEnd;
10991099

@@ -1104,33 +1104,17 @@ interface LayoutEdgeSizes {
11041104
readonly attribute double inline;
11051105
readonly attribute double block;
11061106
};
1107-
1108-
[Exposed=LayoutWorklet]
1109-
interface LayoutEdges {
1110-
readonly attribute LayoutEdgeSizes border;
1111-
readonly attribute LayoutEdgeSizes scrollbar;
1112-
readonly attribute LayoutEdgeSizes padding;
1113-
1114-
readonly attribute LayoutEdgeSizes all;
1115-
};
11161107
</pre>
11171108

1118-
A {{LayoutEdges}} object is passed into the layout method. This represents the size of the [=box
1119-
model edges=] for the current box which is being laid out.
1120-
1121-
The {{LayoutEdges}} has {{LayoutEdges/border}}, {{LayoutEdges/scrollbar}}, and
1122-
{{LayoutEdges/padding}} attributes. Each of these represent the width of their respective edge.
1123-
1124-
The {{LayoutEdges}} has the {{LayoutEdges/all}} attribute. This is a convenience attribute which
1125-
represents the sum of the {{LayoutEdges/border}}, {{LayoutEdges/scrollbar}}, {{LayoutEdges/padding}}
1126-
edges.
1109+
A {{LayoutEdges}} object is passed into the layout method. This represents the sum of all the [=box
1110+
model edges=] (border, scrollbar, padding), for the current box which is being laid out.
11271111

1128-
The {{LayoutEdgeSizes}} object represents the width in CSS pixels of an edge in each of the
1129-
[=abstract dimensions=] ({{LayoutEdgeSizes/inlineStart}}, {{LayoutEdgeSizes/inlineEnd}},
1130-
{{LayoutEdgeSizes/blockStart}}, {{LayoutEdgeSizes/blockEnd}}).
1112+
Each of the accessors represents the width in CSS pixels of an edge in each of the [=abstract
1113+
dimensions=] ({{LayoutEdges/inlineStart}}, {{LayoutEdges/inlineEnd}}, {{LayoutEdges/blockStart}},
1114+
{{LayoutEdges/blockEnd}}).
11311115

1132-
The {{LayoutEdgeSizes/inline}}, and {{LayoutEdgeSizes/block}} on the {{LayoutEdgeSizes}} object are
1133-
convenience attributes which represent the sum in that direction.
1116+
The {{LayoutEdges/inline}}, and {{LayoutEdges/block}} on the {{LayoutEdges}} object are convenience
1117+
attributes which represent the sum in that direction.
11341118

11351119
<div class="example">
11361120
This example shows an node styled by CSS, and what its respective {{LayoutEdges}} could contain.
@@ -1159,10 +1143,11 @@ This example shows an node styled by CSS, and what its respective {{LayoutEdges}
11591143
<pre class="lang-javascript">
11601144
registerLayout('box-edges', class {
11611145
async layout(children, edges, constraints, styleMap, breakToken) {
1162-
edges.padding.inlineStart; // 5 (as 10% * 50px = 5px).
1163-
edges.border.blockEnd; // 2
1164-
edges.scrollbar.inlineEnd; // UA-dependent, may be 0 or >0 (e.g. 16).
1165-
edges.all.block; // 14 (2 + 5 + 5 + 2).
1146+
edges.inlineStart; // 2 + 5 (as 10% * 50px = 5px).
1147+
edges.blockEnd; // 7 (2 + 5)
1148+
edges.inlineEnd; // UA-dependent, due to scrollbar.
1149+
// Could be 2 + 5 + 0 or 2 + 5 + 16 for example.
1150+
edges.block; // 14 (2 + 5 + 5 + 2).
11661151
}
11671152
}
11681153
</pre>
@@ -1527,8 +1512,8 @@ When the user agent wants to <dfn>invoke a intrinsic sizes callback</dfn> given
15271512

15281513
2. [=list/Append=] |layoutChild| to |children|.
15291514

1530-
6. Let |edges| be a new {{LayoutEdgeSizes}} populated with the [=computed value=] for all the
1531-
[=box model edges=] for |box|.
1515+
6. Let |edges| be a new {{LayoutEdges}} populated with the [=computed value=] for all the [=box
1516+
model edges=] for |box|.
15321517

15331518
7. Let |styleMap| be the result of [=get a style map=] given |box|, and |inputProperties|.
15341519

@@ -1644,8 +1629,8 @@ following steps:
16441629

16451630
2. <a for=list>Append</a> |layoutChild| to |children|.
16461631

1647-
8. Let |edges| be a new {{LayoutEdgeSizes}} populated with the [=computed value=] for all the
1648-
[=box model edges=] for |box|.
1632+
8. Let |edges| be a new {{LayoutEdges}} populated with the [=computed value=] for all the [=box
1633+
model edges=] for |box|.
16491634

16501635
9. Let |layoutConstraints| be the result of [=create a layout constraints object=] given
16511636
|internalLayoutConstraints|, |box|, and |sizingMode|.
@@ -1900,20 +1885,20 @@ registerLayout('block-like', class {
19001885

19011886
const maxContentSize = childrenSizes.reduce((max, childSizes) => {
19021887
return Math.max(max, childSizes.maxContentSize);
1903-
}, 0) + edges.all.inline;
1888+
}, 0) + edges.inline;
19041889

19051890
const minContentSize = childrenSizes.reduce((max, childSizes) => {
19061891
return Math.max(max, childSizes.minContentSize);
1907-
}, 0) + edges.all.inline;
1892+
}, 0) + edges.inline;
19081893

19091894
return {maxContentSize, minContentSize};
19101895
}
19111896

19121897
async layout(children, edges, constraints, styleMap) {
19131898
// Determine our (inner) available size.
1914-
const availableInlineSize = constraints.fixedInlineSize - edges.all.inline;
1899+
const availableInlineSize = constraints.fixedInlineSize - edges.inline;
19151900
const availableBlockSize = constraints.fixedBlockSize ?
1916-
constraints.fixedBlockSize - edges.all.block : null;
1901+
constraints.fixedBlockSize - edges.block : null;
19171902

19181903
const childFragments = [];
19191904
const childConstraints = { availableInlineSize, availableBlockSize };
@@ -1922,19 +1907,19 @@ registerLayout('block-like', class {
19221907
return child.layoutNextFragment(childConstraints);
19231908
}));
19241909

1925-
let blockOffset = edges.all.blockStart;
1910+
let blockOffset = edges.blockStart;
19261911
for (let fragment of childFragments) {
19271912
// Position the fragment in a block like manner, centering it in the
19281913
// inline direction.
19291914
fragment.blockOffset = blockOffset;
19301915
fragment.inlineOffset = Math.max(
1931-
edges.all.inlineStart,
1916+
edges.inlineStart,
19321917
(availableInlineSize - fragment.inlineSize) / 2);
19331918

19341919
blockOffset += fragment.blockSize;
19351920
}
19361921

1937-
const autoBlockSize = blockOffset + edges.all.blockEnd;
1922+
const autoBlockSize = blockOffset + edges.blockEnd;
19381923

19391924
return {
19401925
autoBlockSize,
@@ -1958,21 +1943,21 @@ registerLayout('flex-distribution-like', class {
19581943

19591944
const maxContentSize = childrenSizes.reduce((sum, childSizes) => {
19601945
return sum + childSizes.maxContentSize;
1961-
}, 0) + edges.all.inline;
1946+
}, 0) + edges.inline;
19621947

19631948
const minContentSize = childrenSizes.reduce((max, childSizes) => {
19641949
return sum + childSizes.minContentSize;
1965-
}, 0) + edges.all.inline;
1950+
}, 0) + edges.inline;
19661951

19671952
return {maxContentSize, minContentSize};
19681953
}
19691954

19701955
async layout(children, edges, constraints, styleMap) {
19711956
// Determine our (inner) available size.
19721957
const availableInlineSize =
1973-
constraints.fixedInlineSize - edges.all.inline;
1958+
constraints.fixedInlineSize - edges.inline;
19741959
const availableBlockSize = constraints.fixedBlockSize ?
1975-
constraints.fixedBlockSize - edges.all.block : null;
1960+
constraints.fixedBlockSize - edges.block : null;
19761961

19771962
const childConstraints = { availableInlineSize, availableBlockSize };
19781963

@@ -2002,14 +1987,14 @@ registerLayout('flex-distribution-like', class {
20021987
let maxChildBlockSize = 0;
20031988
for (let fragment of childFragments) {
20041989
fragment.inlineOffset = inlineOffset;
2005-
fragment.blockOffset = edges.all.blockStart;
1990+
fragment.blockOffset = edges.blockStart;
20061991

20071992
inlineOffset += fragment.inlineSize;
20081993
maxChildBlockSize = Math.max(maxChildBlockSize, fragment.blockSize);
20091994
}
20101995

20111996
return {
2012-
autoBlockSize: maxChildBlockSize + edges.all.block,
1997+
autoBlockSize: maxChildBlockSize + edges.block,
20131998
childFragments,
20141999
};
20152000
}
@@ -2037,9 +2022,9 @@ registerLayout('indent-lines', class {
20372022
async layout(children, edges, constraints, styleMap, breakToken) {
20382023
// Determine our (inner) available size.
20392024
const availableInlineSize =
2040-
constraints.fixedInlineSize - edges.all.inline;
2025+
constraints.fixedInlineSize - edges.inline;
20412026
const availableBlockSize = constraints.fixedBlockSize ?
2042-
constraints.fixedBlockSize - edges.all.block : null;
2027+
constraints.fixedBlockSize - edges.block : null;
20432028

20442029
// Detrermine the number of lines to indent, and the indent amount.
20452030
const indent = resolveLength(constraints, styleMap.get('--indent'));
@@ -2055,7 +2040,7 @@ registerLayout('indent-lines', class {
20552040
children.splice(0, children.indexOf(childBreakToken.child));
20562041
}
20572042

2058-
let blockOffset = edges.all.blockStart;
2043+
let blockOffset = edges.blockStart;
20592044
let child = children.shift();
20602045
while (child) {
20612046
const shouldIndent = lines-- > 0;
@@ -2077,7 +2062,7 @@ registerLayout('indent-lines', class {
20772062

20782063
// Position the fragment.
20792064
fragment.inlineOffset = shouldIndent ?
2080-
edges.all.inlineStart + indent : edges.all.inlineStart;
2065+
edges.inlineStart + indent : edges.inlineStart;
20812066
fragment.blockOffset = blockOffset;
20822067
blockOffset += fragment.blockSize;
20832068

@@ -2097,7 +2082,7 @@ registerLayout('indent-lines', class {
20972082
}
20982083
}
20992084

2100-
const autoBlockSize = blockOffset + edges.all.blockEnd;
2085+
const autoBlockSize = blockOffset + edges.blockEnd;
21012086

21022087
// Return our fragment.
21032088
const result = {

0 commit comments

Comments
 (0)