Commit 330aad68 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

Change NGLineTruncator to work on NGLogicalLineItem

|NGLineTruncator| was originally designed to compute and
trunate |NGPhysicalTextFragment|. This patch changes it to
work on |NGLogicalLineItem| instead.

This is yet another effort to reduce the usage of
|NGPhysicalTextFragment|, following r778837 and r779021.
This saves creating intermediate |NGPhysicalTextFragment|
when FragmentItem is enabled, and reduces dependency on
|NGPhysicalTextFragment| for the removal when the switch
to FragmentItem was completed.

Bug: 982194
Change-Id: I3742fa1ea33648e2151f7d3cbf83e977928c6715
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2230583
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779756}
parent 5a9c7e42
......@@ -64,14 +64,15 @@ NGFragmentItem::NGFragmentItem(
const NGInlineItem& inline_item,
scoped_refptr<const ShapeResultView> shape_result,
const NGTextOffset& text_offset,
const PhysicalSize& size)
const PhysicalSize& size,
bool is_hidden_for_paint)
: layout_object_(inline_item.GetLayoutObject()),
text_({std::move(shape_result), text_offset}),
rect_({PhysicalOffset(), size}),
type_(kText),
sub_type_(static_cast<unsigned>(inline_item.TextType())),
style_variant_(static_cast<unsigned>(inline_item.StyleVariant())),
is_hidden_for_paint_(false), // TODO(kojii): not supported yet.
is_hidden_for_paint_(is_hidden_for_paint),
text_direction_(static_cast<unsigned>(inline_item.Direction())),
ink_overflow_computed_(false),
is_dirty_(false),
......@@ -90,14 +91,15 @@ NGFragmentItem::NGFragmentItem(
const NGInlineItem& inline_item,
scoped_refptr<const ShapeResultView> shape_result,
const String& text_content,
const PhysicalSize& size)
const PhysicalSize& size,
bool is_hidden_for_paint)
: layout_object_(inline_item.GetLayoutObject()),
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())),
is_hidden_for_paint_(false), // TODO(kojii): not supported yet.
is_hidden_for_paint_(is_hidden_for_paint),
text_direction_(static_cast<unsigned>(inline_item.Direction())),
ink_overflow_computed_(false),
is_dirty_(false),
......@@ -156,14 +158,16 @@ NGFragmentItem::NGFragmentItem(NGLogicalLineItem&& line_item,
new (this) NGFragmentItem(
*line_item.inline_item, std::move(line_item.shape_result),
line_item.text_content,
ToPhysicalSize(line_item.MarginSize(), writing_mode));
ToPhysicalSize(line_item.MarginSize(), writing_mode),
line_item.is_hidden_for_paint);
return;
}
new (this)
NGFragmentItem(*line_item.inline_item,
std::move(line_item.shape_result), line_item.text_offset,
ToPhysicalSize(line_item.MarginSize(), writing_mode));
ToPhysicalSize(line_item.MarginSize(), writing_mode),
line_item.is_hidden_for_paint);
return;
}
......
......@@ -375,12 +375,14 @@ class CORE_EXPORT NGFragmentItem {
NGFragmentItem(const NGInlineItem& inline_item,
scoped_refptr<const ShapeResultView> shape_result,
const NGTextOffset& text_offset,
const PhysicalSize& size);
const PhysicalSize& size,
bool is_hidden_for_paint);
// Create a generated text item.
NGFragmentItem(const NGInlineItem& inline_item,
scoped_refptr<const ShapeResultView> shape_result,
const String& text_content,
const PhysicalSize& size);
const PhysicalSize& size,
bool is_hidden_for_paint);
const LayoutBox* InkOverflowOwnerBox() const;
LayoutBox* MutableInkOverflowOwnerBox();
......
......@@ -324,13 +324,6 @@ void NGInlineLayoutAlgorithm::CreateLine(
line_info->AvailableWidth() - line_info->TextIndent() &&
node_.GetLayoutBlockFlow()->ShouldTruncateOverflowingText()) ||
ConstraintSpace().LinesUntilClamp() == 1)) {
// TODO(kojii): |NGLineTruncator| does not support |Child|-based truncation
// yet, so create |NGPhysicalTextFragment| first.
if (has_logical_text_items) {
line_box_.CreateTextFragments(ConstraintSpace().GetWritingMode(),
line_info->ItemsData().text_content);
has_logical_text_items = false;
}
NGLineTruncator truncator(*line_info);
auto* input =
DynamicTo<HTMLInputElement>(node_.GetLayoutBlockFlow()->GetNode());
......
......@@ -67,17 +67,22 @@ class CORE_EXPORT NGLineTruncator final {
TextDirection edge,
NGLogicalLineItems* line_box,
NGInlineLayoutStateStack* box_states);
bool EllipsizeChild(
LayoutUnit line_width,
LayoutUnit ellipsis_width,
bool is_first_child,
NGLogicalLineItem*,
scoped_refptr<const NGPhysicalTextFragment>* truncated_fragment);
bool TruncateChild(
LayoutUnit space_for_this_child,
bool is_first_child,
const NGLogicalLineItem& child,
scoped_refptr<const NGPhysicalTextFragment>* truncated_fragment);
bool EllipsizeChild(LayoutUnit line_width,
LayoutUnit ellipsis_width,
bool is_first_child,
NGLogicalLineItem*,
base::Optional<NGLogicalLineItem>* truncated_child);
bool TruncateChild(LayoutUnit space_for_this_child,
bool is_first_child,
const NGLogicalLineItem& child,
base::Optional<NGLogicalLineItem>* truncated_child);
// Create |NGLogicalLineItem| by truncating text |item| at |offset_to_fit|.
// |direction| specifies which side of the text is trimmed; if |kLtr|, it
// keeps the left end and trims the right end.
NGLogicalLineItem TruncateText(const NGLogicalLineItem& item,
const ShapeResult& shape_result,
unsigned offset_to_fit,
TextDirection direction);
void HideChild(NGLogicalLineItem* child);
scoped_refptr<const ComputedStyle> line_style_;
......
......@@ -9,6 +9,28 @@
namespace blink {
const LayoutObject* NGLogicalLineItem::GetLayoutObject() const {
if (inline_item)
return inline_item->GetLayoutObject();
if (const NGPhysicalFragment* fragment = PhysicalFragment())
return fragment->GetLayoutObject();
return nullptr;
}
LayoutObject* NGLogicalLineItem::GetMutableLayoutObject() const {
if (inline_item)
return inline_item->GetLayoutObject();
if (const NGPhysicalFragment* fragment = PhysicalFragment())
return fragment->GetMutableLayoutObject();
return nullptr;
}
const Node* NGLogicalLineItem::GetNode() const {
if (const LayoutObject* layout_object = GetLayoutObject())
return layout_object->GetNode();
return nullptr;
}
const ComputedStyle* NGLogicalLineItem::Style() const {
if (const auto* fragment = PhysicalFragment())
return &fragment->Style();
......@@ -37,6 +59,7 @@ void NGLogicalLineItems::CreateTextFragments(WritingMode writing_mode,
std::move(child.shape_result), child.text_offset,
child.MarginSize());
}
text_builder.SetIsHiddenForPaint(child.is_hidden_for_paint);
DCHECK(!child.fragment);
child.fragment = text_builder.ToTextFragment();
}
......@@ -71,11 +94,6 @@ void NGLogicalLineItems::WillInsertChild(unsigned insert_before) {
}
}
void NGLogicalLineItems::InsertChild(unsigned index) {
WillInsertChild(index);
children_.insert(index, NGLogicalLineItem());
}
void NGLogicalLineItems::MoveInInlineDirection(LayoutUnit delta) {
for (auto& child : children_)
child.rect.offset.inline_offset += delta;
......
......@@ -75,6 +75,16 @@ struct NGLogicalLineItem {
rect(LayoutUnit(), block_offset, LayoutUnit(), text_height),
inline_size(inline_size),
bidi_level(bidi_level) {}
NGLogicalLineItem(const NGLogicalLineItem& source_item,
scoped_refptr<const ShapeResultView> shape_result,
const NGTextOffset& text_offset)
: inline_item(source_item.inline_item),
shape_result(std::move(shape_result)),
text_offset(text_offset),
text_content(source_item.text_content),
rect(source_item.rect),
inline_size(this->shape_result->SnappedWidth()),
bidi_level(source_item.bidi_level) {}
NGLogicalLineItem(scoped_refptr<const NGPhysicalTextFragment> fragment,
LogicalOffset offset,
LayoutUnit inline_size,
......@@ -109,6 +119,9 @@ struct NGLogicalLineItem {
bfc_offset(bfc_offset),
bidi_level(bidi_level) {}
bool IsInlineBox() const {
return layout_result && layout_result->PhysicalFragment().IsInlineBox();
}
bool HasInFlowFragment() const {
return fragment || inline_item ||
(layout_result && !layout_result->PhysicalFragment().IsFloating());
......@@ -147,21 +160,27 @@ struct NGLogicalLineItem {
LayoutUnit BlockEndOffset() const { return rect.BlockEndOffset(); }
const LogicalSize& Size() const { return rect.size; }
LogicalSize MarginSize() const { return {inline_size, Size().block_size}; }
const NGPhysicalFragment* PhysicalFragment() const {
if (layout_result)
return &layout_result->PhysicalFragment();
return fragment.get();
}
const LayoutObject* GetLayoutObject() const;
LayoutObject* GetMutableLayoutObject() const;
const Node* GetNode() const;
const ComputedStyle* Style() const;
unsigned StartOffset() const { return text_offset.start; }
unsigned EndOffset() const { return text_offset.end; }
TextDirection ResolvedDirection() const {
// Inline boxes are not leaves that they don't have directions.
DCHECK(HasBidiLevel() || layout_result->PhysicalFragment().IsInlineBox());
DCHECK(HasBidiLevel() || IsInlineBox());
return HasBidiLevel() ? DirectionFromLevel(bidi_level)
: TextDirection::kLtr;
}
const ComputedStyle* Style() const;
scoped_refptr<const NGLayoutResult> layout_result;
scoped_refptr<const NGPhysicalTextFragment> fragment;
......@@ -194,6 +213,8 @@ struct NGLogicalLineItem {
UBiDiLevel bidi_level = 0xff;
// The current text direction for OOF positioned items.
TextDirection container_direction = TextDirection::kLtr;
bool is_hidden_for_paint = false;
};
// A vector of Child.
......@@ -243,7 +264,10 @@ class NGLogicalLineItems {
void AddChild(Args&&... args) {
children_.emplace_back(std::forward<Args>(args)...);
}
void InsertChild(unsigned index);
void InsertChild(unsigned index, NGLogicalLineItem&& item) {
WillInsertChild(index);
children_.insert(index, item);
}
void InsertChild(unsigned index,
scoped_refptr<const NGLayoutResult> layout_result,
const LogicalRect& rect,
......
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