@@ -123,6 +123,31 @@ Output fragmentEmptyBox(Tree& tree, Input input) {
123123 }
124124}
125125
126+ void _populateChildSpecifiedSizes (Tree& tree, Box& child, Input& childInput, Au horizontalMargins, Opt<Au> blockInlineSize) {
127+ if (childInput.intrinsic == IntrinsicSize::AUTO or child.style ->display != Display::INLINE) {
128+ if (child.style ->sizing ->width .is <Keywords::Auto>()) {
129+ // https://www.w3.org/TR/css-tables-3/#layout-principles
130+ // Unlike other block-level boxes, tables do not fill their containing block by default.
131+ // When their width computes to auto, they behave as if they had fit-content specified instead.
132+ // This is different from most block-level boxes, which behave as if they had stretch instead.
133+ if (child.style ->display == Display::TABLE_BOX) {
134+ // Do nothing. 'fit-content' is kinda intrinsic size, when we don't populate knownSize.
135+ } else if (blockInlineSize) {
136+ // When the inline size is not known, we cannot enforce it to the child. (?)
137+ childInput.knownSize .width = blockInlineSize.unwrap () - horizontalMargins;
138+ }
139+ } else {
140+ childInput.knownSize .width = computeSpecifiedSize (
141+ tree, child, child.style ->sizing ->width , childInput.containingBlock , true
142+ );
143+ }
144+
145+ childInput.knownSize .height = computeSpecifiedSize (
146+ tree, child, child.style ->sizing ->height , childInput.containingBlock , false
147+ );
148+ }
149+ }
150+
126151// https://www.w3.org/TR/CSS22/visuren.html#normal-flow
127152struct BlockFormatingContext : FormatingContext {
128153 Au _computeCapmin (Tree& tree, Box& box, Input input, Au inlineSize) {
@@ -210,38 +235,7 @@ struct BlockFormatingContext : FormatingContext {
210235 childInput.capmin = _computeCapmin (tree, box, input, inlineSize);
211236 }
212237
213- if (input.intrinsic == IntrinsicSize::AUTO or c.style ->display != Display::INLINE) {
214- if (c.style ->sizing ->width .is <Keywords::Auto>()) {
215- // https://www.w3.org/TR/css-tables-3/#layout-principles
216- // Unlike other block-level boxes, tables do not fill their containing block by default.
217- // When their width computes to auto, they behave as if they had fit-content specified instead.
218- // This is different from most block-level boxes, which behave as if they had stretch instead.
219- if (c.style ->display == Display::TABLE_BOX) {
220- // Do nothing. 'fit-content' is kinda intrinsic size, when we don't populate knownSize.
221- } else if (input.knownSize .x ) {
222- // When the inline size is not known, we cannot enforce it to the child. (?)
223- childInput.knownSize .width = inlineSize - usedSpacings.margin .horizontal ();
224- }
225- } else {
226- // FIXME: computing border box size. content box sizing should be supported later.
227- auto specifiedWidth = computeSpecifiedSize (
228- tree, c, c.style ->sizing ->width , childInput.containingBlock , true
229- );
230-
231- childInput.knownSize .width = specifiedWidth.unwrap ();
232- }
233-
234- if (c.style ->sizing ->height .is <Keywords::Auto>()) {
235- childInput.knownSize .height = NONE;
236- } else {
237- // FIXME: computing border box size. content box sizing should be supported later.
238- auto specifiedHeight = computeSpecifiedSize (
239- tree, c, c.style ->sizing ->height , childInput.containingBlock , false
240- );
241-
242- childInput.knownSize .height = specifiedHeight.unwrap ();
243- }
244- }
238+ _populateChildSpecifiedSizes (tree, c, childInput, usedSpacings.margin .horizontal (), input.knownSize .x );
245239
246240 auto output = input.fragment
247241 ? layoutBorderBox (tree, c, childInput, *input.fragment , usedSpacings)
0 commit comments