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( ...@@ -90,32 +90,46 @@ NGFragmentItem::NGFragmentItem(
} }
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, scoped_refptr<const ShapeResultView> shape_result,
const String& text_content, const String& text_content,
const PhysicalSize& size, const PhysicalSize& size,
bool is_hidden_for_paint) bool is_hidden_for_paint)
: layout_object_(inline_item.GetLayoutObject()), : layout_object_(&layout_object),
generated_text_({std::move(shape_result), text_content}), generated_text_({std::move(shape_result), text_content}),
rect_({PhysicalOffset(), size}), rect_({PhysicalOffset(), size}),
type_(kGeneratedText), type_(kGeneratedText),
sub_type_(static_cast<unsigned>(inline_item.TextType())), sub_type_(static_cast<unsigned>(text_type)),
style_variant_(static_cast<unsigned>(inline_item.StyleVariant())), style_variant_(static_cast<unsigned>(style_variant)),
is_hidden_for_paint_(is_hidden_for_paint), 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), ink_overflow_type_(NGInkOverflow::kNotSet),
is_dirty_(false), is_dirty_(false),
is_last_for_node_(true) { is_last_for_node_(true) {
#if DCHECK_IS_ON() DCHECK(layout_object_);
if (text_.shape_result) { DCHECK_EQ(TextShapeResult()->StartIndex(), StartOffset());
DCHECK_EQ(text_.shape_result->StartIndex(), StartOffset()); DCHECK_EQ(TextShapeResult()->EndIndex(), EndOffset());
DCHECK_EQ(text_.shape_result->EndIndex(), EndOffset());
}
#endif
DCHECK_EQ(TextType(), NGTextType::kLayoutGenerated);
DCHECK(!IsFormattingContextRoot()); 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) NGFragmentItem::NGFragmentItem(const NGPhysicalLineBoxFragment& line)
: layout_object_(line.ContainerLayoutObject()), : layout_object_(line.ContainerLayoutObject()),
line_({&line, /* descendants_count */ 1}), line_({&line, /* descendants_count */ 1}),
...@@ -150,11 +164,6 @@ NGFragmentItem::NGFragmentItem(NGLogicalLineItem&& line_item, ...@@ -150,11 +164,6 @@ NGFragmentItem::NGFragmentItem(NGLogicalLineItem&& line_item,
WritingMode writing_mode) { WritingMode writing_mode) {
DCHECK(line_item.CanCreateFragmentItem()); DCHECK(line_item.CanCreateFragmentItem());
if (line_item.text_fragment) {
new (this) NGFragmentItem(*line_item.text_fragment);
return;
}
if (line_item.inline_item) { if (line_item.inline_item) {
if (UNLIKELY(line_item.text_content)) { if (UNLIKELY(line_item.text_content)) {
new (this) NGFragmentItem( new (this) NGFragmentItem(
...@@ -180,6 +189,17 @@ NGFragmentItem::NGFragmentItem(NGLogicalLineItem&& line_item, ...@@ -180,6 +189,17 @@ NGFragmentItem::NGFragmentItem(NGLogicalLineItem&& line_item,
return; 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() // CanCreateFragmentItem()
NOTREACHED(); NOTREACHED();
CHECK(false); CHECK(false);
......
...@@ -404,6 +404,14 @@ class CORE_EXPORT NGFragmentItem { ...@@ -404,6 +404,14 @@ class CORE_EXPORT NGFragmentItem {
const String& text_content, const String& text_content,
const PhysicalSize& size, const PhysicalSize& size,
bool is_hidden_for_paint); 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 { NGInkOverflow::Type InkOverflowType() const {
return static_cast<NGInkOverflow::Type>(ink_overflow_type_); return static_cast<NGInkOverflow::Type>(ink_overflow_type_);
......
...@@ -63,7 +63,7 @@ LayoutUnit NGLineTruncator::PlaceEllipsisNextTo( ...@@ -63,7 +63,7 @@ LayoutUnit NGLineTruncator::PlaceEllipsisNextTo(
NGLogicalLineItem* ellipsized_child) { NGLogicalLineItem* ellipsized_child) {
// Create the ellipsis, associating it with the ellipsized child. // Create the ellipsis, associating it with the ellipsized child.
DCHECK(ellipsized_child->HasInFlowFragment()); DCHECK(ellipsized_child->HasInFlowFragment());
LayoutObject* ellipsized_layout_object = const LayoutObject* ellipsized_layout_object =
ellipsized_child->GetMutableLayoutObject(); ellipsized_child->GetMutableLayoutObject();
DCHECK(ellipsized_layout_object); DCHECK(ellipsized_layout_object);
DCHECK(ellipsized_layout_object->IsInline()); DCHECK(ellipsized_layout_object->IsInline());
...@@ -85,14 +85,12 @@ LayoutUnit NGLineTruncator::PlaceEllipsisNextTo( ...@@ -85,14 +85,12 @@ LayoutUnit NGLineTruncator::PlaceEllipsisNextTo(
DCHECK(ellipsis_text_); DCHECK(ellipsis_text_);
DCHECK(ellipsis_shape_result_.get()); 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( line_box->AddChild(
builder.ToTextFragment(), *ellipsized_layout_object, NGStyleVariant::kEllipsis,
LogicalOffset{ellipsis_inline_offset, -ellipsis_metrics.ascent}, std::move(ellipsis_shape_result_), ellipsis_text_,
ellipsis_width_, 0); LogicalRect(ellipsis_inline_offset, -ellipsis_metrics.ascent,
ellipsis_width_, ellipsis_metrics.LineHeight()),
/* bidi_level */ 0);
return ellipsis_inline_offset; return ellipsis_inline_offset;
} }
......
...@@ -26,8 +26,8 @@ LayoutObject* NGLogicalLineItem::GetMutableLayoutObject() const { ...@@ -26,8 +26,8 @@ LayoutObject* NGLogicalLineItem::GetMutableLayoutObject() const {
} }
const Node* NGLogicalLineItem::GetNode() const { const Node* NGLogicalLineItem::GetNode() const {
if (const LayoutObject* layout_object = GetLayoutObject()) if (const LayoutObject* object = GetLayoutObject())
return layout_object->GetNode(); return object->GetNode();
return nullptr; return nullptr;
} }
......
...@@ -77,6 +77,7 @@ struct NGLogicalLineItem { ...@@ -77,6 +77,7 @@ struct NGLogicalLineItem {
rect(LayoutUnit(), block_offset, LayoutUnit(), text_height), rect(LayoutUnit(), block_offset, LayoutUnit(), text_height),
inline_size(inline_size), inline_size(inline_size),
bidi_level(bidi_level) {} bidi_level(bidi_level) {}
// Create a generated text.
NGLogicalLineItem(const NGInlineItem& inline_item, NGLogicalLineItem(const NGInlineItem& inline_item,
scoped_refptr<const ShapeResultView> shape_result, scoped_refptr<const ShapeResultView> shape_result,
const String& text_content, const String& text_content,
...@@ -92,6 +93,23 @@ struct NGLogicalLineItem { ...@@ -92,6 +93,23 @@ struct NGLogicalLineItem {
rect(LayoutUnit(), block_offset, LayoutUnit(), text_height), rect(LayoutUnit(), block_offset, LayoutUnit(), text_height),
inline_size(inline_size), inline_size(inline_size),
bidi_level(bidi_level) {} 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, NGLogicalLineItem(const NGLogicalLineItem& source_item,
scoped_refptr<const ShapeResultView> shape_result, scoped_refptr<const ShapeResultView> shape_result,
const NGTextOffset& text_offset) const NGTextOffset& text_offset)
...@@ -144,7 +162,7 @@ struct NGLogicalLineItem { ...@@ -144,7 +162,7 @@ struct NGLogicalLineItem {
(layout_result && !layout_result->PhysicalFragment().IsFloating()); (layout_result && !layout_result->PhysicalFragment().IsFloating());
} }
bool HasInFlowOrFloatingFragment() const { 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 HasOutOfFlowFragment() const { return out_of_flow_positioned_box; }
bool HasFragment() const { bool HasFragment() const {
...@@ -162,10 +180,8 @@ struct NGLogicalLineItem { ...@@ -162,10 +180,8 @@ struct NGLogicalLineItem {
// Skip all inline boxes. Fragments for inline boxes maybe created earlier // Skip all inline boxes. Fragments for inline boxes maybe created earlier
// if they have no children. // if they have no children.
if (layout_result) { if (layout_result) {
const LayoutObject* layout_object = DCHECK(layout_result->PhysicalFragment().GetLayoutObject());
layout_result->PhysicalFragment().GetLayoutObject(); if (layout_result->PhysicalFragment().GetLayoutObject()->IsLayoutInline())
DCHECK(layout_object);
if (layout_object->IsLayoutInline())
return true; return true;
} }
return false; return false;
...@@ -202,6 +218,7 @@ struct NGLogicalLineItem { ...@@ -202,6 +218,7 @@ struct NGLogicalLineItem {
scoped_refptr<const NGPhysicalTextFragment> text_fragment; scoped_refptr<const NGPhysicalTextFragment> text_fragment;
// Data to create a text fragment from. // Data to create a text fragment from.
// |inline_item| is null only for ellipsis items.
const NGInlineItem* inline_item = nullptr; const NGInlineItem* inline_item = nullptr;
scoped_refptr<const ShapeResultView> shape_result; scoped_refptr<const ShapeResultView> shape_result;
NGTextOffset text_offset; NGTextOffset text_offset;
...@@ -209,6 +226,12 @@ struct NGLogicalLineItem { ...@@ -209,6 +226,12 @@ struct NGLogicalLineItem {
// Data to create a generated text fragment. // Data to create a generated text fragment.
String text_content; 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* out_of_flow_positioned_box = nullptr;
LayoutObject* unpositioned_float = nullptr; LayoutObject* unpositioned_float = nullptr;
// The offset of the border box, initially in this child coordinate system. // 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