Skip to content

Commit 681f896

Browse files
mstenshoChromium LUCI CQ
authored andcommitted
Stretch nested columns to the block-size of the outer fragmentainer.
This is required by the spec. https://www.w3.org/TR/css-break-3/#box-splitting "When a box breaks, its content box extends to fill any remaining fragmentainer extent" We can finally DCHECK that minimal_space_shortage is set, rather than bailing if it isn't. Add a test that demonstrates that this is necessary in order to paint the backgrounds and column rules correctly. It also fixes a problem with offsetLeft and offsetTop, because we confused the legacy code (still used for offsetFoo) when writing back fragmentainer groups that didn't take up all available space. Bug: 829028 Change-Id: Ic23f94d2b9db4d4cc4f8d9036b32676a933f82c9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3144154 Reviewed-by: Ian Kilpatrick <[email protected]> Commit-Queue: Morten Stenshorne <[email protected]> Cr-Commit-Position: refs/heads/main@{#919172}
1 parent 77e5e50 commit 681f896

File tree

4 files changed

+40
-30
lines changed

4 files changed

+40
-30
lines changed

third_party/blink/renderer/core/layout/ng/ng_column_layout_algorithm.cc

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -778,19 +778,25 @@ scoped_refptr<const NGLayoutResult> NGColumnLayoutAlgorithm::LayoutRow(
778778
(!column_break_token || result->ColumnSpanner()))
779779
break;
780780

781-
// We're in a situation where we'd like to stretch the columns, but then we
782-
// need to know the stretch amount (minimal space shortage).
783-
if (minimal_space_shortage == LayoutUnit::Max())
784-
break;
785-
786-
// We also need at least one soft break opportunity. If forced breaks cause
787-
// too many breaks, there's no stretch amount that could prevent the columns
788-
// from overflowing.
789-
if (used_column_count_ <= forced_break_count + 1)
790-
break;
791-
792-
LayoutUnit new_column_block_size = StretchColumnBlockSize(
793-
minimal_space_shortage, column_size.block_size, row_offset);
781+
// Attempt to stretch the columns.
782+
LayoutUnit new_column_block_size;
783+
if (used_column_count_ <= forced_break_count + 1) {
784+
// If we have no soft break opportunities (because forced breaks cause too
785+
// many breaks already), there's no stretch amount that could prevent the
786+
// columns from overflowing. Give up, unless we're nested inside another
787+
// fragmentation context, in which case we'll stretch the columns to take
788+
// up all the space inside the multicol container fragment. A box is
789+
// required to use all the remaining fragmentainer space when something
790+
// inside breaks; see https://www.w3.org/TR/css-break-3/#box-splitting
791+
if (!is_constrained_by_outer_fragmentation_context_)
792+
break;
793+
new_column_block_size = FragmentainerSpaceAtBfcStart(ConstraintSpace());
794+
} else {
795+
DCHECK(minimal_space_shortage != LayoutUnit::Max());
796+
new_column_block_size = column_size.block_size + minimal_space_shortage;
797+
}
798+
new_column_block_size =
799+
ConstrainColumnBlockSize(new_column_block_size, row_offset);
794800

795801
// Give up if we cannot get taller columns. The multicol container may have
796802
// a specified block-size preventing taller columns, for instance.
@@ -1196,15 +1202,6 @@ LayoutUnit NGColumnLayoutAlgorithm::CalculateBalancedColumnBlockSize(
11961202
row_offset);
11971203
}
11981204

1199-
LayoutUnit NGColumnLayoutAlgorithm::StretchColumnBlockSize(
1200-
LayoutUnit minimal_space_shortage,
1201-
LayoutUnit current_column_size,
1202-
LayoutUnit row_offset) const {
1203-
LayoutUnit length = current_column_size + minimal_space_shortage;
1204-
// Honor {,min-,max-}{height,width} properties.
1205-
return ConstrainColumnBlockSize(length, row_offset);
1206-
}
1207-
12081205
// Constrain a balanced column block size to not overflow the multicol
12091206
// container.
12101207
LayoutUnit NGColumnLayoutAlgorithm::ConstrainColumnBlockSize(

third_party/blink/renderer/core/layout/ng/ng_column_layout_algorithm.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ class CORE_EXPORT NGColumnLayoutAlgorithm
7979
LayoutUnit row_offset,
8080
const NGBlockBreakToken* child_break_token);
8181

82-
// Stretch the column length. We do this during column balancing, when we
83-
// discover that the current length isn't large enough to fit all content.
84-
LayoutUnit StretchColumnBlockSize(LayoutUnit minimal_space_shortage,
85-
LayoutUnit current_column_size,
86-
LayoutUnit row_offset) const;
87-
8882
LayoutUnit ConstrainColumnBlockSize(LayoutUnit size,
8983
LayoutUnit row_offset) const;
9084
LayoutUnit CurrentContentBlockOffset(LayoutUnit border_box_row_offset) const {

third_party/blink/web_tests/TestExpectations

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,10 +1274,8 @@ crbug.com/1225630 virtual/layout_ng_block_frag/fast/multicol/insane-column-count
12741274
crbug.com/1066626 virtual/layout_ng_block_frag/fast/multicol/layers-split-across-columns.html [ Failure ]
12751275
crbug.com/1066626 virtual/layout_ng_block_frag/fast/multicol/mixed-opacity-fixed-test.html [ Failure ]
12761276
crbug.com/1079031 virtual/layout_ng_block_frag/fast/multicol/mixed-opacity-test.html [ Crash Failure ]
1277-
crbug.com/829028 virtual/layout_ng_block_frag/fast/multicol/nested-balanced-inner-column-count-1-with-forced-break.html [ Failure ]
12781277
crbug.com/829028 virtual/layout_ng_block_frag/fast/multicol/nested-short-first-row-extra-tall-line.html [ Failure ]
12791278
crbug.com/1225630 virtual/layout_ng_block_frag/fast/multicol/nested-very-tall-inside-short-crash.html [ Skip ]
1280-
crbug.com/829028 virtual/layout_ng_block_frag/fast/multicol/nested-with-forced-breaks-in-eariler-rows.html [ Failure ]
12811279
crbug.com/829028 virtual/layout_ng_block_frag/fast/multicol/nested-with-padding.html [ Failure ]
12821280
crbug.com/829028 virtual/layout_ng_block_frag/fast/multicol/span/outer-column-break-after-inner-spanner-2.html [ Failure ]
12831281
crbug.com/1242348 virtual/layout_ng_block_frag/fast/multicol/tall-line-in-short-block.html [ Failure ]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">
3+
<link rel="help" href="https://www.w3.org/TR/css-multicol-1/#column-gaps-and-rules">
4+
<link rel="match" href="../reference/ref-filled-green-100px-square.xht">
5+
<style>
6+
.mc {
7+
columns: 2;
8+
column-gap: 20px;
9+
column-rule: 20px solid green;
10+
}
11+
</style>
12+
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
13+
<div class="mc" style="column-fill:auto; width:100px; height:100px; background:red;">
14+
<div class="mc">
15+
<div style="background:green;">
16+
<div style="height:10px; break-after:column;"></div>
17+
<div style="height:10px; break-after:column;"></div>
18+
<div style="height:200px;"></div>
19+
</div>
20+
</div>
21+
</div>

0 commit comments

Comments
 (0)