Commit 626c2bde authored by Koji Ishii's avatar Koji Ishii Committed by Chromium LUCI CQ

Eliminate NGPhysicalTextFragment from NGLineTruncator

When |NGFragmentItem| is enabled, |NGLineTruncator| is the
only user of |NGPhysicalTextFragment| when creating ellipsis.

This patch changes it not to create an intermediate
|NGPhysicalTextFragment|.

This patch has no behavior changes.

Bug: 1154531
Change-Id: Iec86c52b1f54e510c8270df801b7d27d37a061f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2591327
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837015}
parent 71fb503c
......@@ -90,32 +90,46 @@ NGFragmentItem::NGFragmentItem(
}
NGFragmentItem::NGFragmentItem(
const NGInlineItem& inline_item,
const LayoutObject& layout_object,
NGTextType text_type,
NGStyleVariant style_variant,
TextDirection direction,
scoped_refptr<const ShapeResultView> shape_result,
const String& text_content,
const PhysicalSize& size,
bool is_hidden_for_paint)
: layout_object_(inline_item.GetLayoutObject()),
: layout_object_(&layout_object),
generated_text_({std::move(shape_result), text_content}),
rect_({PhysicalOffset(), size}),
type_(kGeneratedText),
sub_type_(static_cast<unsigned>(inline_item.TextType())),
style_variant_(static_cast<unsigned>(inline_item.StyleVariant())),
sub_type_(static_cast<unsigned>(text_type)),
style_variant_(static_cast<unsigned>(style_variant)),
is_hidden_for_paint_(is_hidden_for_paint),
text_direction_(static_cast<unsigned>(inline_item.Direction())),
text_direction_(static_cast<unsigned>(direction)),
ink_overflow_type_(NGInkOverflow::kNotSet),
is_dirty_(false),
is_last_for_node_(true) {
#if DCHECK_IS_ON()
if (text_.shape_result) {
DCHECK_EQ(text_.shape_result->StartIndex(), StartOffset());
DCHECK_EQ(text_.shape_result->EndIndex(), EndOffset());
}
#endif
DCHECK_EQ(TextType(), NGTextType::kLayoutGenerated);
DCHECK(layout_object_);
DCHECK_EQ(TextShapeResult()->StartIndex(), StartOffset());
DCHECK_EQ(TextShapeResult()->EndIndex(), EndOffset());
DCHECK(!IsFormattingContextRoot());
}
NGFragmentItem::NGFragmentItem(
const NGInlineItem& inline_item,
scoped_refptr<const ShapeResultView> shape_result,
const String& text_content,
const PhysicalSize& size,
bool is_hidden_for_paint)
: NGFragmentItem(*inline_item.GetLayoutObject(),
inline_item.TextType(),
inline_item.StyleVariant(),
inline_item.Direction(),
std::move(shape_result),
text_content,
size,
is_hidden_for_paint) {}
NGFragmentItem::NGFragmentItem(const NGPhysicalLineBoxFragment& line)
: layout_object_(line.ContainerLayoutObject()),
line_({&line, /* descendants_count */ 1}),
......@@ -150,11 +164,6 @@ NGFragmentItem::NGFragmentItem(NGLogicalLineItem&& line_item,
WritingMode writing_mode) {
DCHECK(line_item.CanCreateFragmentItem());
if (line_item.text_fragment) {
new (this) NGFragmentItem(*line_item.text_fragment);
return;
}
if (line_item.inline_item) {
if (UNLIKELY(line_item.text_content)) {
new (this) NGFragmentItem(
......@@ -180,6 +189,17 @@ NGFragmentItem::NGFragmentItem(NGLogicalLineItem&& line_item,
return;
}
if (line_item.layout_object) {
const TextDirection direction = line_item.shape_result->Direction();
new (this) NGFragmentItem(
*line_item.layout_object, NGTextType::kLayoutGenerated,
line_item.style_variant, direction, std::move(line_item.shape_result),
line_item.text_content,
ToPhysicalSize(line_item.MarginSize(), writing_mode),
line_item.is_hidden_for_paint);
return;
}
// CanCreateFragmentItem()
NOTREACHED();
CHECK(false);
......
......@@ -404,6 +404,14 @@ class CORE_EXPORT NGFragmentItem {
const String& text_content,
const PhysicalSize& size,
bool is_hidden_for_paint);
NGFragmentItem(const LayoutObject& layout_object,
NGTextType text_type,
NGStyleVariant style_variant,
TextDirection direction,
scoped_refptr<const ShapeResultView> shape_result,
const String& text_content,
const PhysicalSize& size,
bool is_hidden_for_paint);
NGInkOverflow::Type InkOverflowType() const {
return static_cast<NGInkOverflow::Type>(ink_overflow_type_);
......
......@@ -63,7 +63,7 @@ LayoutUnit NGLineTruncator::PlaceEllipsisNextTo(
NGLogicalLineItem* ellipsized_child) {
// Create the ellipsis, associating it with the ellipsized child.
DCHECK(ellipsized_child->HasInFlowFragment());
LayoutObject* ellipsized_layout_object =
const LayoutObject* ellipsized_layout_object =
ellipsized_child->GetMutableLayoutObject();
DCHECK(ellipsized_layout_object);
DCHECK(ellipsized_layout_object->IsInline());
......@@ -85,14 +85,12 @@ LayoutUnit NGLineTruncator::PlaceEllipsisNextTo(
DCHECK(ellipsis_text_);
DCHECK(ellipsis_shape_result_.get());
NGTextFragmentBuilder builder(line_style_->GetWritingMode());
builder.SetText(ellipsized_layout_object, ellipsis_text_, &EllipsisStyle(),
NGStyleVariant::kEllipsis, std::move(ellipsis_shape_result_),
{ellipsis_width_, ellipsis_metrics.LineHeight()});
line_box->AddChild(
builder.ToTextFragment(),
LogicalOffset{ellipsis_inline_offset, -ellipsis_metrics.ascent},
ellipsis_width_, 0);
*ellipsized_layout_object, NGStyleVariant::kEllipsis,
std::move(ellipsis_shape_result_), ellipsis_text_,
LogicalRect(ellipsis_inline_offset, -ellipsis_metrics.ascent,
ellipsis_width_, ellipsis_metrics.LineHeight()),
/* bidi_level */ 0);
return ellipsis_inline_offset;
}
......
......@@ -26,8 +26,8 @@ LayoutObject* NGLogicalLineItem::GetMutableLayoutObject() const {
}
const Node* NGLogicalLineItem::GetNode() const {
if (const LayoutObject* layout_object = GetLayoutObject())
return layout_object->GetNode();
if (const LayoutObject* object = GetLayoutObject())
return object->GetNode();
return nullptr;
}
......
......@@ -77,6 +77,7 @@ struct NGLogicalLineItem {
rect(LayoutUnit(), block_offset, LayoutUnit(), text_height),
inline_size(inline_size),
bidi_level(bidi_level) {}
// Create a generated text.
NGLogicalLineItem(const NGInlineItem& inline_item,
scoped_refptr<const ShapeResultView> shape_result,
const String& text_content,
......@@ -92,6 +93,23 @@ struct NGLogicalLineItem {
rect(LayoutUnit(), block_offset, LayoutUnit(), text_height),
inline_size(inline_size),
bidi_level(bidi_level) {}
// Create an ellipsis item. Ellipsis is a generated text, but does not have
// corresponding |NGInlineItem| as it is generated by layout.
NGLogicalLineItem(const LayoutObject& layout_object,
NGStyleVariant style_variant,
scoped_refptr<const ShapeResultView> shape_result,
const String& text_content,
const LogicalRect& rect,
UBiDiLevel bidi_level)
: shape_result(std::move(shape_result)),
text_offset(
{this->shape_result->StartIndex(), this->shape_result->EndIndex()}),
text_content(text_content),
layout_object(&layout_object),
style_variant(style_variant),
rect(rect),
inline_size(rect.size.inline_size),
bidi_level(bidi_level) {}
NGLogicalLineItem(const NGLogicalLineItem& source_item,
scoped_refptr<const ShapeResultView> shape_result,
const NGTextOffset& text_offset)
......@@ -144,7 +162,7 @@ struct NGLogicalLineItem {
(layout_result && !layout_result->PhysicalFragment().IsFloating());
}
bool HasInFlowOrFloatingFragment() const {
return text_fragment || inline_item || layout_result;
return text_fragment || inline_item || layout_result || layout_object;
}
bool HasOutOfFlowFragment() const { return out_of_flow_positioned_box; }
bool HasFragment() const {
......@@ -162,10 +180,8 @@ struct NGLogicalLineItem {
// Skip all inline boxes. Fragments for inline boxes maybe created earlier
// if they have no children.
if (layout_result) {
const LayoutObject* layout_object =
layout_result->PhysicalFragment().GetLayoutObject();
DCHECK(layout_object);
if (layout_object->IsLayoutInline())
DCHECK(layout_result->PhysicalFragment().GetLayoutObject());
if (layout_result->PhysicalFragment().GetLayoutObject()->IsLayoutInline())
return true;
}
return false;
......@@ -202,6 +218,7 @@ struct NGLogicalLineItem {
scoped_refptr<const NGPhysicalTextFragment> text_fragment;
// Data to create a text fragment from.
// |inline_item| is null only for ellipsis items.
const NGInlineItem* inline_item = nullptr;
scoped_refptr<const ShapeResultView> shape_result;
NGTextOffset text_offset;
......@@ -209,6 +226,12 @@ struct NGLogicalLineItem {
// Data to create a generated text fragment.
String text_content;
// Ellipsis does not have |NGInlineItem|, but built from |LayoutObject| and
// |NGStyleVariant|.
const LayoutObject* layout_object = nullptr;
// Used only when |layout_object_| is not null.
NGStyleVariant style_variant = NGStyleVariant::kStandard;
LayoutObject* out_of_flow_positioned_box = nullptr;
LayoutObject* unpositioned_float = nullptr;
// The offset of the border box, initially in this child coordinate system.
......
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