Commit 65f87ce1 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[LayoutNG] Include close tags after forced break for min-max

r684910 (crrev.com/c/1742250) changed LayoutNG to include
close tags after a forced break. This broke an assumption in
|NGInlineNode::ComputeMinMaxSize| that there are no objects
after a forced break.

This patch fixes the min-content size for the situation by
applying the same rule to |NGInlineNode::ComputeMinMaxSize|.

The test hits DCHECK failure without the fix because the fast
code path computes the different max-content from the slow
code path.

Bug: 991320
Change-Id: I3e9106fddc1fce5a2a7576fc4f75b77b5d4b8b61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1768486
Commit-Queue: Emil A Eklund <eae@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690293}
parent a8fc58a9
......@@ -1177,11 +1177,11 @@ static LayoutUnit ComputeContentSize(
}
}
void ForceLineBreak(const NGInlineItem& item) {
// Add all text up to the forced break. There may be spaces that were
void ForceLineBreak(const NGLineInfo& line_info) {
// Add all text up to the end of the line. There may be spaces that were
// removed during the line breaking.
AddTextUntil(&item);
next_item = std::next(&item);
CHECK_LE(line_info.EndItemIndex(), items_data.items.size());
AddTextUntil(items_data.items.begin() + line_info.EndItemIndex());
max_size = floats->ComputeMaxSizeForLine(position.ClampNegativeToZero(),
max_size);
position = LayoutUnit();
......@@ -1215,6 +1215,7 @@ static LayoutUnit ComputeContentSize(
is_after_break = false;
}
bool has_forced_break = false;
for (const NGInlineItemResult& result : line_info.Results()) {
const NGInlineItem& item = *result.item;
if (item.Type() == NGInlineItem::kText) {
......@@ -1232,7 +1233,11 @@ static LayoutUnit ComputeContentSize(
if (item.Type() == NGInlineItem::kControl) {
UChar c = items_data.text_content[item.StartOffset()];
if (c == kNewlineCharacter) {
ForceLineBreak(item);
// Compute the forced break after all results were handled, because
// when close tags appear after a forced break, they are included in
// the line, and they may have inline sizes. crbug.com/991320.
DCHECK(!has_forced_break);
has_forced_break = true;
continue;
}
// Tabulation characters change the widths by their positions, so
......@@ -1245,6 +1250,8 @@ static LayoutUnit ComputeContentSize(
}
position += result.inline_size;
}
if (has_forced_break)
ForceLineBreak(line_info);
}
};
FloatsMaxSize floats_max_size(input);
......
......@@ -502,6 +502,25 @@ TEST_F(NGInlineNodeTest, MinMaxSizeFloats) {
EXPECT_EQ(130, sizes.max_size);
}
TEST_F(NGInlineNodeTest, MinMaxSizeCloseTagAfterForcedBreak) {
LoadAhem();
SetupHtml("t", R"HTML(
<style>
span { border: 30px solid blue; }
</style>
<div id=t style="font: 10px Ahem">
<span>12<br></span>
</div>
)HTML");
NGInlineNodeForTest node = CreateInlineNode();
MinMaxSize sizes = ComputeMinMaxSize(node);
// The right border of the `</span>` is included in the line even if it
// appears after `<br>`. crbug.com/991320.
EXPECT_EQ(80, sizes.min_size);
EXPECT_EQ(80, sizes.max_size);
}
TEST_F(NGInlineNodeTest, MinMaxSizeFloatsClearance) {
LoadAhem();
SetupHtml("t", R"HTML(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment