@@ -758,85 +758,55 @@ interface LayoutFragment {
758
758
};
759
759
</pre>
760
760
761
- A {{LayoutFragment}} represents a CSS <a> fragment</a> of a {{LayoutChild}} after layout has occurred
762
- on that child. This is produced by the {{LayoutChild/layoutNextFragment()}} method.
761
+ A {{LayoutFragment}} represents a CSS [= fragment=] of a {{LayoutChild}} after layout has occurred on
762
+ that child. This is produced by the {{LayoutChild/layoutNextFragment()}} method.
763
763
764
764
The {{LayoutFragment}} has {{LayoutFragment/inlineSize}} and {{LayoutFragment/blockSize}}
765
765
attributes, which are set by the respective child's layout algorithm. They represent the <b> border
766
- box</b> size of the CSS <a>fragment</a> , and are relative to the <a>current layout's</a> writing
767
- mode.
766
+ box</b> size of the CSS [=fragment=] , and are relative to the [=current layout's=] writing mode.
768
767
769
768
The {{LayoutFragment/inlineSize}} and {{LayoutFragment/blockSize}} attributes cannot be changed. If
770
- the <a> current layout</a> requires a different {{LayoutFragment/inlineSize}} or
769
+ the [= current layout=] requires a different {{LayoutFragment/inlineSize}} or
771
770
{{LayoutFragment/blockSize}} the author must perform {{LayoutChild/layoutNextFragment()}} again with
772
771
different arguments in order to get different results.
773
772
774
773
The author inside the current layout can position a resulting {{LayoutFragment}} by setting its
775
774
{{LayoutFragment/inlineOffset}} and {{LayoutFragment/blockOffset}} attributes. If not set by the
776
775
author they default to zero. The {{LayoutFragment/inlineOffset}} and {{LayoutFragment/blockOffset}}
777
776
attributes represent the position of the {{LayoutFragment}} relative to its parent's <b> border
778
- box</b> , before transform or positioning (e.g. if a fragment is <a> relatively positioned</a> ) has
777
+ box</b> , before transform or positioning (e.g. if a fragment is [= relatively positioned=] ) has
779
778
been applied.
780
779
781
- <div class="example">
782
- The layout algorithm performs a block-like layout (positioning fragments sequentially in the block
783
- direction), while centering its children in the inline direction.
784
-
785
- <pre class="lang-javascript">
786
- registerLayout('block-like' , class {
787
- async intrinsicSizes(children, edges, styleMap) {
788
- const childrenSizes = await Promise.all(children.map((child) => {
789
- return child.intrinsicSizes();
790
- }));
791
-
792
- const maxContentSize = childrenSizes.reduce((max, childSizes) => {
793
- return Math.max(max, childSizes.maxContentSize);
794
- }, 0) + edges.all.inline;
795
-
796
- const minContentSize = childrenSizes.reduce((max, childSizes) => {
797
- return Math.max(max, childSizes.minContentSize);
798
- }, 0) + edges.all.inline;
799
-
800
- return {maxContentSize, minContentSize};
801
- }
802
-
803
- async layout(children, edges, constraints, styleMap) {
804
- // Determine our (inner) available size.
805
- const availableInlineSize = constraints.fixedInlineSize - edges.all.inline;
806
- const availableBlockSize = constraints.fixedBlockSize ?
807
- constraints.fixedBlockSize - edges.all.block : null;
808
-
809
- const childFragments = [];
810
- const childConstraints = { availableInlineSize, availableBlockSize };
780
+ <div class=example>
781
+ The example below shows the basic usage of a {{LayoutFragment}} .
782
+ <pre class='lang-javascript'>
783
+ registerLayout('example-layout-fragment' , class {
784
+ async layout(children, edges, constraints, styleMap) {
811
785
812
- const childFragments = await Promise.all(children.map((child) => {
813
- return child.layoutNextFragment(childConstraints);
814
- }));
786
+ // You must perform layout to generate a fragment.
787
+ const fragment = await child.layoutNextFragment({});
815
788
816
- let blockOffset = edges.all.blockStart;
817
- for (let fragment of childFragments) {
818
- // Position the fragment in a block like manner, centering it in the
819
- // inline direction.
820
- fragment.blockOffset = blockOffset;
821
- fragment.inlineOffset = Math.max(
822
- edges.all.inlineStart,
823
- (availableInlineSize - fragment.inlineSize) / 2);
789
+ // You can query the size of the fragment produced:
790
+ console.log(fragment.inlineSize);
791
+ console.log(fragment.blockSize);
824
792
825
- blockOffset += fragment.blockSize;
826
- }
793
+ // You can set the position of the fragment, e.g. this will set it to the
794
+ // top-left corner:
795
+ fragment.inlineOffset = edges.all.inlineStart;
796
+ fragment.blockOffset = edges.all.blockStart;
827
797
828
- const autoBlockSize = blockOffset + edges.all.blockEnd;
798
+ // Data may be passed from the child layout:
799
+ console.log(fragment.data);
829
800
830
- return {
831
- autoBlockSize,
832
- childFragments,
833
- };
834
- }
801
+ // If the child fragmented, you can use the breakToken to produce the next
802
+ // fragment in the chain.
803
+ const nextFragment = await child.layoutNextFragment({}, fragment.breakToken);
804
+ }
835
805
});
836
806
</pre>
837
807
</div>
838
808
839
- A <a> layout API container</a> can communicate with other <a> layout API containers</a> by using the
809
+ A [= layout API container=] can communicate with other [= layout API containers=] by using the
840
810
{{LayoutFragment/data}} attribute. This is set by the {{FragmentResultOptions/data}} member in the
841
811
{{FragmentResultOptions}} dictionary.
842
812
@@ -845,7 +815,7 @@ fragmented. If the {{LayoutFragment/breakToken}} is null the {{LayoutChild}} won
845
815
{{LayoutFragment}} s for that token chain. The {{LayoutFragment/breakToken}} can be passed to the
846
816
{{LayoutChild/layoutNextFragment()}} function to produce the next {{LayoutFragment}} for a
847
817
particular child. The {{LayoutFragment/breakToken}} cannot be changed.
848
- If the <a> current layout</a> requires a different {{LayoutFragment/breakToken}} the author must perform
818
+ If the [= current layout=] requires a different {{LayoutFragment/breakToken}} the author must perform
849
819
{{LayoutChild/layoutNextFragment()}} again with different arguments.
850
820
851
821
Intrinsic Sizes {#intrinsic-sizes}
@@ -859,11 +829,11 @@ interface IntrinsicSizes {
859
829
};
860
830
</pre>
861
831
862
- A {{IntrinsicSizes}} object represents the <a> min-content size</a> and <a> max-content size</a> of a
863
- CSS <a> box</a> . It has {{IntrinsicSizes/minContentSize}} and {{IntrinsicSizes/maxContentSize}}
864
- attributes which represent the <b> border box</b> min/max-content contribution of the {{LayoutChild}}
865
- for the <a> current layout</a> . The attributes are relative to the inline direction of the <a> current
866
- layout's</a> writing mode.
832
+ A {{IntrinsicSizes}} object represents the [= min-content size=] and [= max-content size=] of a CSS
833
+ [= box=] . It has {{IntrinsicSizes/minContentSize}} and {{IntrinsicSizes/maxContentSize}} attributes
834
+ which represent the <b> border box</b> min/max-content contribution of the {{LayoutChild}} for the
835
+ [= current layout=] . The attributes are relative to the inline direction of the [= current layout's=]
836
+ writing mode.
867
837
868
838
The {{IntrinsicSizes/minContentSize}} and {{IntrinsicSizes/maxContentSize}} cannot be changed. They
869
839
must not change for a {{LayoutChild}} within the current layout pass.
@@ -954,21 +924,21 @@ enum BlockFragmentationType { "none", "page", "column", "region" };
954
924
</pre>
955
925
956
926
A {{LayoutConstraints}} object is passed into the layout method which represents the all the
957
- constraints for the <a> current layout</a> to perform layout inside. It is also used to pass
958
- information about the available space into a <a> child layout</a> .
927
+ constraints for the [= current layout=] to perform layout inside. It is also used to pass information
928
+ about the available space into a [= child layout=] .
959
929
960
930
The {{LayoutConstraints}} object has {{LayoutConstraints/availableInlineSize}} and
961
- {{LayoutConstraints/availableBlockSize}} attributes. This represents the <a> available space</a> for
962
- a {{LayoutFragment}} which the layout should respect.
931
+ {{LayoutConstraints/availableBlockSize}} attributes. This represents the [= available space=] for a
932
+ {{LayoutFragment}} which the layout should respect.
963
933
964
934
Note: Some layouts may need to produce a {{LayoutFragment}} which exceed this size. For example a
965
- <a> replaced element</a> . The <a> parent layout</a> should expect this to occur and deal with it
935
+ [= replaced element=] . The [= parent layout=] should expect this to occur and deal with it
966
936
appropriately.
967
937
968
- A <a> parent layout</a> may require the <a> current layout</a> to be exactly a particular size. If
969
- the {{LayoutConstraints/fixedInlineSize}} or {{LayoutConstraints/fixedBlockSize}} are specified the
970
- <a> current layout</a> should produce a {{LayoutFragment}} with a the specified size in the
971
- appropriate direction.
938
+ A [= parent layout=] may require the [= current layout=] to be exactly a particular size. If the
939
+ {{LayoutConstraints/fixedInlineSize}} or {{LayoutConstraints/fixedBlockSize}} are specified the
940
+ [= current layout=] should produce a {{LayoutFragment}} with a the specified size in the appropriate
941
+ direction.
972
942
973
943
<div class="example">
974
944
The layout algorithm performs a flexbox-like distribution of spare space in the inline direction. It
@@ -1982,6 +1952,67 @@ When the user agent wants to <dfn>get a layout class instance</dfn> given |box|,
1982
1952
4. Return |layoutInstance|.
1983
1953
</div>
1984
1954
1955
+ Examples {#examples}
1956
+ ====================
1957
+
1958
+ <div class="example">
1959
+ The layout algorithm below performs a block-like layout (positioning fragments sequentially in the
1960
+ block direction), while centering its children in the inline direction.
1961
+
1962
+ <pre class="lang-javascript">
1963
+ registerLayout('block-like' , class {
1964
+ async intrinsicSizes(children, edges, styleMap) {
1965
+ const childrenSizes = await Promise.all(children.map((child) => {
1966
+ return child.intrinsicSizes();
1967
+ }));
1968
+
1969
+ const maxContentSize = childrenSizes.reduce((max, childSizes) => {
1970
+ return Math.max(max, childSizes.maxContentSize);
1971
+ }, 0) + edges.all.inline;
1972
+
1973
+ const minContentSize = childrenSizes.reduce((max, childSizes) => {
1974
+ return Math.max(max, childSizes.minContentSize);
1975
+ }, 0) + edges.all.inline;
1976
+
1977
+ return {maxContentSize, minContentSize};
1978
+ }
1979
+
1980
+ async layout(children, edges, constraints, styleMap) {
1981
+ // Determine our (inner) available size.
1982
+ const availableInlineSize = constraints.fixedInlineSize - edges.all.inline;
1983
+ const availableBlockSize = constraints.fixedBlockSize ?
1984
+ constraints.fixedBlockSize - edges.all.block : null;
1985
+
1986
+ const childFragments = [];
1987
+ const childConstraints = { availableInlineSize, availableBlockSize };
1988
+
1989
+ const childFragments = await Promise.all(children.map((child) => {
1990
+ return child.layoutNextFragment(childConstraints);
1991
+ }));
1992
+
1993
+ let blockOffset = edges.all.blockStart;
1994
+ for (let fragment of childFragments) {
1995
+ // Position the fragment in a block like manner, centering it in the
1996
+ // inline direction.
1997
+ fragment.blockOffset = blockOffset;
1998
+ fragment.inlineOffset = Math.max(
1999
+ edges.all.inlineStart,
2000
+ (availableInlineSize - fragment.inlineSize) / 2);
2001
+
2002
+ blockOffset += fragment.blockSize;
2003
+ }
2004
+
2005
+ const autoBlockSize = blockOffset + edges.all.blockEnd;
2006
+
2007
+ return {
2008
+ autoBlockSize,
2009
+ childFragments,
2010
+ };
2011
+ }
2012
+ });
2013
+ </pre>
2014
+ </div>
2015
+
1985
2016
Security Considerations {#security-considerations}
1986
2017
==================================================
1987
2018
0 commit comments