Commit d48f877e authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[LayoutNG] Stop ellipsizing inline boxes

Ellipsis fragments have associated LayoutObject indicating
the object it truncated. This is normally LayoutText or
atomic inline, but sometimes it can be LayoutInline.

This is very rare while it requiers special casing in several
places. Running tests hit some DCHECK failures in paint and
hit-testing. This patch stops generating such fragments, so
that ellipsis fragments always have text or atomic inlines.

DCHECK in NGLineTruncator is changed to check the condition
accordingly.

Bug: 988541
Change-Id: I4787091512cb8b330824952e97fa9481cf7905fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1725629Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682347}
parent e9f00606
...@@ -126,6 +126,38 @@ TEST_F(NGInlineLayoutAlgorithmTest, GenerateEllipsis) { ...@@ -126,6 +126,38 @@ TEST_F(NGInlineLayoutAlgorithmTest, GenerateEllipsis) {
EXPECT_EQ(line1.Children()[0]->GetLayoutObject(), ellipsis.GetLayoutObject()); EXPECT_EQ(line1.Children()[0]->GetLayoutObject(), ellipsis.GetLayoutObject());
} }
TEST_F(NGInlineLayoutAlgorithmTest, EllipsisInlineBoxOnly) {
LoadAhem();
SetBodyInnerHTML(R"HTML(
<!DOCTYPE html>
<style>
html, body { margin: 0; }
#container {
font: 10px/1 Ahem;
width: 5ch;
overflow: hidden;
text-overflow: ellipsis;
}
span {
border: solid 10ch blue;
}
</style>
<div id=container><span></span></div>
)HTML");
scoped_refptr<const NGPhysicalBoxFragment> block =
GetBoxFragmentByElementId("container");
EXPECT_EQ(1u, block->Children().size());
const auto& line1 =
To<NGPhysicalLineBoxFragment>(*block->Children()[0].get());
// There should not be ellipsis in this line.
for (const auto& child : line1.Children()) {
if (const auto* text = DynamicTo<NGPhysicalTextFragment>(child.get())) {
EXPECT_FALSE(text->IsEllipsis());
}
}
}
// This test ensures box fragments are generated when necessary, even when the // This test ensures box fragments are generated when necessary, even when the
// line is empty. One such case is when the line contains a containing box of an // line is empty. One such case is when the line contains a containing box of an
// out-of-flow object. // out-of-flow object.
......
...@@ -97,7 +97,9 @@ LayoutUnit NGLineTruncator::TruncateLine( ...@@ -97,7 +97,9 @@ LayoutUnit NGLineTruncator::TruncateLine(
// Create the ellipsis, associating it with the ellipsized child. // Create the ellipsis, associating it with the ellipsized child.
LayoutObject* ellipsized_layout_object = LayoutObject* ellipsized_layout_object =
ellpisized_child->PhysicalFragment()->GetMutableLayoutObject(); ellpisized_child->PhysicalFragment()->GetMutableLayoutObject();
DCHECK(ellipsized_layout_object && ellipsized_layout_object->IsInline()); DCHECK(ellipsized_layout_object && ellipsized_layout_object->IsInline() &&
(ellipsized_layout_object->IsText() ||
ellipsized_layout_object->IsAtomicInlineLevel()));
NGTextFragmentBuilder builder(line_style_->GetWritingMode()); NGTextFragmentBuilder builder(line_style_->GetWritingMode());
builder.SetText(ellipsized_layout_object, ellipsis_text, ellipsis_style, builder.SetText(ellipsized_layout_object, ellipsis_text, ellipsis_style,
true /* is_ellipsis_style */, true /* is_ellipsis_style */,
...@@ -171,6 +173,12 @@ bool NGLineTruncator::EllipsizeChild( ...@@ -171,6 +173,12 @@ bool NGLineTruncator::EllipsizeChild(
if (!child->HasInFlowFragment()) if (!child->HasInFlowFragment())
return false; return false;
// Inline boxes should not be ellipsized. Usually they will be created in the
// later phase, but empty inline box are already created.
if (child->layout_result &&
child->layout_result->PhysicalFragment().IsInlineBox())
return false;
// Can't place ellipsis if this child is completely outside of the box. // Can't place ellipsis if this child is completely outside of the box.
LayoutUnit child_inline_offset = LayoutUnit child_inline_offset =
IsLtr(line_direction_) IsLtr(line_direction_)
......
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