@@ -69,6 +69,8 @@ urlPrefix: https://drafts.csswg.org/css-sizing/#; type: dfn
69
69
text: intrinsic sizes
70
70
urlPrefix: https://drafts.csswg.org/css-break/#; type: dfn
71
71
text: fragmentation break
72
+ urlPrefix: https://www.w3.org/TR/CSS21/box.html#; type: dfn
73
+ url: box-dimensions; text: box model edges
72
74
</pre>
73
75
74
76
Introduction {#intro}
@@ -297,20 +299,11 @@ registerLayout('block-like', class extends Layout {
297
299
static blockifyChildren = true;
298
300
static inputProperties = super.inputProperties;
299
301
300
- *layout(space, children, styleMap) {
302
+ *layout(space, children, styleMap, edges ) {
301
303
const inlineSize = resolveInlineSize(space, styleMap);
302
304
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;
314
307
315
308
const childFragments = [];
316
309
const childConstraintSpace = new ConstraintSpace({
@@ -319,7 +312,7 @@ registerLayout('block-like', class extends Layout {
319
312
});
320
313
321
314
let maxChildInlineSize = 0;
322
- let blockOffset = bordersAndPadding .blockStart;
315
+ let blockOffset = edges.all .blockStart;
323
316
324
317
for (let child of children) {
325
318
const fragment = yield child.layoutNextFragment(childConstraintSpace);
@@ -328,15 +321,15 @@ registerLayout('block-like', class extends Layout {
328
321
// inline direction.
329
322
fragment.blockOffset = blockOffset;
330
323
fragment.inlineOffset = Math.max(
331
- bordersAndPadding .inlineStart,
324
+ edges.all .inlineStart,
332
325
(availableInlineSize - fragment.inlineSize) / 2);
333
326
334
327
maxChildInlineSize =
335
328
Math.max(maxChildInlineSize, childFragments.inlineSize);
336
329
blockOffset += fragment.blockSize;
337
330
}
338
331
339
- const contentSize = blockOffset + bordersAndPadding .blockEnd;
332
+ const contentSize = blockOffset + edges.all .blockEnd;
340
333
const blockSize = resolveBlockSize(
341
334
constraintSpace, styleMap, contentSize);
342
335
@@ -422,20 +415,12 @@ creates child constraint spaces which specify that a child should be a fixed inl
422
415
423
416
<pre class="lang-javascript">
424
417
registerLayout('flex-distribution-like' , class {
425
- *layout(space, children, styleMap, breakToken) {
418
+ *layout(space, children, styleMap, edges, breakToken) {
426
419
const inlineSize = resolveInlineSize(space, styleMap);
427
420
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;
439
424
440
425
const unconstrainedSizes = [];
441
426
const childConstraintSpace = new ConstraintSpace({
@@ -549,23 +534,14 @@ resume the layout.
549
534
registerLayout('basic-inline' , class extends Layout {
550
535
static inputProperties = super.inputProperties;
551
536
552
- *layout(constraintSpace, children, styleMap, breakToken) {
537
+ *layout(constraintSpace, children, styleMap, edges, breakToken) {
553
538
// Resolve our inline size.
554
539
const inlineSize = resolveInlineSize(constraintSpace, styleMap);
555
540
556
541
// 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;
569
545
570
546
const childFragments = [];
571
547
@@ -658,9 +634,7 @@ registerLayout('basic-inline', class extends Layout {
658
634
659
635
// Determine our block size.
660
636
nextLine();
661
- const contentSize = lineOffset +
662
- bordersAndPadding.blockStart +
663
- bordersAndPadding.blockEnd;
637
+ const contentSize = lineOffset + edges.all.block;
664
638
const blockSize = resolveBlockSize(constraintSpace,
665
639
styleMap,
666
640
contentSize);
@@ -684,44 +658,98 @@ registerLayout('basic-inline', class extends Layout {
684
658
</pre>
685
659
</div>
686
660
687
- Utility Functions {#utility-functions }
688
- --------------------------------------
661
+ Edges {#edges }
662
+ --------------
689
663
690
664
<pre class='idl'>
691
665
[Exposed=LayoutWorklet]
692
- interface LayoutStrut {
666
+ interface LayoutEdgeSizes {
693
667
readonly attribute double inlineStart;
694
668
readonly attribute double inlineEnd;
695
669
696
670
readonly attribute double blockStart;
697
671
readonly attribute double blockEnd;
698
- };
699
672
700
- [Exposed=LayoutWorklet]
701
- interface LayoutSize {
673
+ // Convenience attributes for the sum in one direction.
702
674
readonly attribute double inline;
703
675
readonly attribute double block;
704
676
};
705
677
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
+ <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
+ </style>
723
+
724
+ <div class="container">
725
+ <div class="box"></div>
726
+ </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]
706
746
partial interface LayoutWorkletGlobalScope {
707
747
double resolveInlineSize(ConstraintSpace constraintSpace,
708
748
StylePropertyMapReadOnly styleMap);
709
749
710
750
double resolveBlockSize(ConstraintSpace constraintSpace,
711
751
StylePropertyMapReadOnly styleMap,
712
752
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<DOMString> inputProperties;
724
- readonly attribute sequence<DOMString> childInputProperties;
725
753
};
726
754
</pre>
727
755
@@ -730,12 +758,22 @@ Issue: Specify the behaviour of these functions.
730
758
Interactions with other Modules {#interactions-with-other-modules}
731
759
==================================================================
732
760
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
+ --------------------------------
734
771
735
- Sizing {#sizing }
736
- ----------------
772
+ Fragmentation {#interaction-fragmentation }
773
+ ------------------------------------------
737
774
738
- TODO
775
+ Alignment {#interaction-alignment}
776
+ ----------------------------------
739
777
740
778
Layout {#layout}
741
779
================
@@ -1006,7 +1044,7 @@ is called, the user agent <em>must</em> run the following steps:
1006
1044
// Intrinsic sizes code goes here.
1007
1045
}
1008
1046
1009
- *layout(constraintSpace, children, styleMap, breakToken) {
1047
+ *layout(constraintSpace, children, styleMap, edges, breakToken) {
1010
1048
// Layout code goes here.
1011
1049
}
1012
1050
}
@@ -1326,34 +1364,37 @@ following steps:
1326
1364
7. Let |constraintSpace| be a new {{ConstraintSpace}} populated with the appropriate information
1327
1365
from |internalConstraintSpace|.
1328
1366
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
1330
1371
|internalBreakToken|.
1331
1372
1332
1373
If |internalBreakToken| is null, let |breakToken| be null.
1333
1374
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
1335
1376
|children|, |styleMap|, |constraintSpace|, |breakToken| are equivalent to that previous
1336
1377
invocation. If so let the fragment output be that cached fragment and abort all these steps.
1337
1378
1338
- 10 . Let |layoutGeneratorFunction| be |definition|'s <a>layout generator function</a> .
1379
+ 11 . Let |layoutGeneratorFunction| be |definition|'s <a>layout generator function</a> .
1339
1380
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|»).
1342
1383
1343
1384
If an exception is <a>thrown</a> the let |box| fallback to the <a>flow layout</a> and abort
1344
1385
all these steps.
1345
1386
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
1347
1388
<code> "layout"</code> .
1348
1389
1349
1390
If <a>run a generator</a> returned failure, then let |box| fallback to the <a>flow
1350
1391
layout</a> and abort all these steps.
1351
1392
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
1353
1394
{{FragmentResultOptions}} . If an exception is <a>thrown</a> , let |box| fallback to the
1354
1395
<a>flow layout</a> and abort all these steps.
1355
1396
1356
- 14 . Create a <a>fragment</a> for |box| with:
1397
+ 15 . Create a <a>fragment</a> for |box| with:
1357
1398
1358
1399
- The <a>inline size</a> set to |fragment|'s {{FragmentResultOptions/inlineSize}} .
1359
1400
0 commit comments