Skip to content

Commit 783df4e

Browse files
Ahmad-S792Ahmad Saleem
authored andcommitted
[Multicolumn] Guard against zero or negative space shortage
[Multicolumn] Guard against zero or negative space shortage https://bugs.webkit.org/show_bug.cgi?id=250282 Reviewed by Alan Baradlay. Merge - https://src.chromium.org/viewvc/blink?view=revision&revision=174088 We need positive values in order to get anywhere when stretching columns in order to balance them, and we may get called with zero or negative values when there's zero-height content at column boundaries, so we set an early break in order to honor widows in the next column. * Source/WebCore/rendering/RenderMultiColumnFlow.cpp: (RenderMultiColumnFlow::initialLogicalWidth): Add early return for "spaceShortage" to get positive values * LayoutTests/fast/multicol/windows.html: Add Test Case * LayoutTests/fast/multicol/windows2.html: Ditto * LayoutTests/fast/multicol/windows-expected.txt: Add Test Case Expectation * LayoutTests/fast/multicol/windows2-expected.txt: Ditto Canonical link: https://commits.webkit.org/258647@main
1 parent 8a6b809 commit 783df4e

File tree

5 files changed

+107
-1
lines changed

5 files changed

+107
-1
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Test column balancer behavior when widows requirements are high, and there's need for an early break to honor widows
2+
3+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4+
5+
6+
PASS mc.offsetHeight is 250
7+
PASS first.offsetTop is inFirstColumn.offsetTop
8+
PASS first.offsetLeft is > inFirstColumn.offsetLeft
9+
PASS last.offsetLeft is first.offsetLeft
10+
PASS successfullyParsed is true
11+
12+
TEST COMPLETE
13+
The 5 lines should all be in the second column.
14+
15+
16+
line
17+
line
18+
line
19+
line
20+
line
21+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<script src="../../resources/js-test.js"></script>
3+
<script>
4+
description("Test column balancer behavior when widows requirements are high, and there's need for an early break to honor widows");
5+
</script>
6+
<p>The 5 lines should all be in the second column.</p>
7+
<div id="mc" style="-webkit-columns:3; columns:3; -webkit-column-rule:solid; line-height:50px; orphans:1; widows:5;">
8+
<span id="inFirstColumn"><br></span>
9+
<span id="first">line<br></span>
10+
line<br>
11+
line<br>
12+
line<br>
13+
<span id="last">line<br></span>
14+
</div>
15+
<script>
16+
shouldBe("mc.offsetHeight", "250");
17+
shouldBe("first.offsetTop", "inFirstColumn.offsetTop");
18+
shouldBeGreaterThan("first.offsetLeft", "inFirstColumn.offsetLeft");
19+
shouldBe("last.offsetLeft", "first.offsetLeft");
20+
</script>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Test column balancer behavior when widows requirements are high, and there are so many lines that there's no need for early breaks to honor widows
2+
3+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4+
5+
6+
PASS mc.offsetHeight is 300
7+
PASS successfullyParsed is true
8+
9+
TEST COMPLETE
10+
There should be 6 lines in the first column, 5 in the second and 5 in the last one.
11+
12+
line
13+
line
14+
line
15+
line
16+
line
17+
line
18+
line
19+
line
20+
line
21+
line
22+
line
23+
line
24+
line
25+
line
26+
line
27+
line
28+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<script src="../../resources/js-test.js"></script>
3+
<script>
4+
description("Test column balancer behavior when widows requirements are high, and there are so many lines that there's no need for early breaks to honor widows");
5+
</script>
6+
<p>There should be 6 lines in the first column, 5 in the second and 5 in the last one.</p>
7+
<div id="mc" style="-webkit-columns:3; columns:3; -webkit-column-rule:solid; line-height:50px;">
8+
<div style="orphans:1; widows:5;">
9+
line<br>
10+
line<br>
11+
line<br>
12+
line<br>
13+
line<br>
14+
line<br>
15+
line<br>
16+
line<br>
17+
line<br>
18+
line<br>
19+
line<br>
20+
line<br>
21+
line<br>
22+
line<br>
23+
line<br>
24+
line<br>
25+
</div>
26+
</div>
27+
<script>
28+
shouldBe("mc.offsetHeight", "300");
29+
</script>

Source/WebCore/rendering/RenderMultiColumnFlow.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
* Copyright (C) 2012 Apple Inc. All rights reserved.
2+
* Copyright (C) 2012-2023 Apple Inc. All rights reserved.
3+
* Copyright (C) 2014 Google Inc. All rights reserved.
34
*
45
* Redistribution and use in source and binary forms, with or without
56
* modification, are permitted provided that the following conditions
@@ -184,6 +185,13 @@ LayoutUnit RenderMultiColumnFlow::initialLogicalWidth() const
184185

185186
void RenderMultiColumnFlow::setPageBreak(const RenderBlock* block, LayoutUnit offset, LayoutUnit spaceShortage)
186187
{
188+
// Only positive values are interesting (and allowed) here. Zero space shortage may be reported
189+
// when we're at the top of a column and the element has zero height. Ignore this, and also
190+
// ignore any negative values, which may occur when we set an early break in order to honor
191+
// widows in the next column.
192+
if (spaceShortage <= 0)
193+
return;
194+
187195
if (auto* multicolSet = downcast<RenderMultiColumnSet>(fragmentAtBlockOffset(block, offset)))
188196
multicolSet->recordSpaceShortage(spaceShortage);
189197
}

0 commit comments

Comments
 (0)