Commit 19db0b8e authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Make LayoutText::GetTextBoxInfo() to use NGInlineCursor

This patch changes |LayoutText::GetTextBoxInfo()| to use |NGInlineCursor|
to reduce usage of |NGPaintFragment| for preparation of migrating
|NGFragmentItem|.

Bug: 982194
Change-Id: Ib37fae0241efaca73184710cc0af3050a041bde5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1880890
Commit-Queue: Koji Ishii <kojii@chromium.org>
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709410}
parent 528bbebb
...@@ -292,15 +292,14 @@ void LayoutText::InLayoutNGInlineFormattingContextWillChange(bool new_value) { ...@@ -292,15 +292,14 @@ void LayoutText::InLayoutNGInlineFormattingContextWillChange(bool new_value) {
Vector<LayoutText::TextBoxInfo> LayoutText::GetTextBoxInfo() const { Vector<LayoutText::TextBoxInfo> LayoutText::GetTextBoxInfo() const {
Vector<TextBoxInfo> results; Vector<TextBoxInfo> results;
if (const NGOffsetMapping* mapping = GetNGOffsetMapping()) { if (const NGOffsetMapping* mapping = GetNGOffsetMapping()) {
auto fragments = NGPaintFragment::InlineFragmentsFor(this);
bool in_hidden_for_paint = false; bool in_hidden_for_paint = false;
for (const NGPaintFragment* fragment : fragments) { NGInlineCursor cursor;
const auto& text_fragment = cursor.MoveTo(*this);
To<NGPhysicalTextFragment>(fragment->PhysicalFragment()); for (; cursor; cursor.MoveToNextForSameLayoutObject()) {
// TODO(yosin): We should introduce // TODO(yosin): We should introduce
// |NGPhysicalTextFragment::IsTruncated()| to skip them instead of using // |NGPhysicalTextFragment::IsTruncated()| to skip them instead of using
// |IsHiddenForPaint()| with ordering of fragments. // |IsHiddenForPaint()| with ordering of fragments.
if (text_fragment.IsHiddenForPaint()) { if (cursor.IsHiddenForPaint()) {
in_hidden_for_paint = true; in_hidden_for_paint = true;
} else if (in_hidden_for_paint) { } else if (in_hidden_for_paint) {
// Because of we finished original fragments (not painted), we should // Because of we finished original fragments (not painted), we should
...@@ -309,7 +308,7 @@ Vector<LayoutText::TextBoxInfo> LayoutText::GetTextBoxInfo() const { ...@@ -309,7 +308,7 @@ Vector<LayoutText::TextBoxInfo> LayoutText::GetTextBoxInfo() const {
} }
// We don't put generated texts, e.g. ellipsis, hyphen, etc. not in text // We don't put generated texts, e.g. ellipsis, hyphen, etc. not in text
// content, into results. Note: CSS "content" aren't categorized this. // content, into results. Note: CSS "content" aren't categorized this.
if (text_fragment.TextType() == NGPhysicalTextFragment::kGeneratedText) if (cursor.IsGeneratedTextType())
continue; continue;
// When the corresponding DOM range contains collapsed whitespaces, NG // When the corresponding DOM range contains collapsed whitespaces, NG
// produces one fragment but legacy produces multiple text boxes broken at // produces one fragment but legacy produces multiple text boxes broken at
...@@ -317,22 +316,23 @@ Vector<LayoutText::TextBoxInfo> LayoutText::GetTextBoxInfo() const { ...@@ -317,22 +316,23 @@ Vector<LayoutText::TextBoxInfo> LayoutText::GetTextBoxInfo() const {
// to match the legacy output. // to match the legacy output.
for (const NGOffsetMappingUnit& unit : for (const NGOffsetMappingUnit& unit :
mapping->GetMappingUnitsForTextContentOffsetRange( mapping->GetMappingUnitsForTextContentOffsetRange(
text_fragment.StartOffset(), text_fragment.EndOffset())) { cursor.CurrentTextStartOffset(),
cursor.CurrentTextEndOffset())) {
DCHECK_EQ(unit.GetLayoutObject(), this); DCHECK_EQ(unit.GetLayoutObject(), this);
if (unit.GetType() == NGOffsetMappingUnitType::kCollapsed) if (unit.GetType() == NGOffsetMappingUnitType::kCollapsed)
continue; continue;
// [clamped_start, clamped_end] of |fragment| matches a legacy text box. // [clamped_start, clamped_end] of |fragment| matches a legacy text box.
const unsigned clamped_start = const unsigned clamped_start =
std::max(unit.TextContentStart(), text_fragment.StartOffset()); std::max(unit.TextContentStart(), cursor.CurrentTextStartOffset());
const unsigned clamped_end = const unsigned clamped_end =
std::min(unit.TextContentEnd(), text_fragment.EndOffset()); std::min(unit.TextContentEnd(), cursor.CurrentTextEndOffset());
DCHECK_LT(clamped_start, clamped_end); DCHECK_LT(clamped_start, clamped_end);
const unsigned box_length = clamped_end - clamped_start; const unsigned box_length = clamped_end - clamped_start;
// Compute rect of the legacy text box. // Compute rect of the legacy text box.
LayoutRect rect = LayoutRect rect =
text_fragment.LocalRect(clamped_start, clamped_end).ToLayoutRect(); cursor.CurrentLocalRect(clamped_start, clamped_end).ToLayoutRect();
rect.MoveBy(fragment->InlineOffsetToContainerBox().ToLayoutPoint()); rect.MoveBy(cursor.CurrentOffset().ToLayoutPoint());
// Compute start of the legacy text box. // Compute start of the legacy text box.
if (unit.AssociatedNode()) { if (unit.AssociatedNode()) {
......
...@@ -153,6 +153,21 @@ bool NGInlineCursor::IsGeneratedText() const { ...@@ -153,6 +153,21 @@ bool NGInlineCursor::IsGeneratedText() const {
return false; return false;
} }
bool NGInlineCursor::IsGeneratedTextType() const {
if (current_paint_fragment_) {
if (auto* text_fragment = DynamicTo<NGPhysicalTextFragment>(
current_paint_fragment_->PhysicalFragment())) {
return text_fragment->TextType() ==
NGPhysicalTextFragment::kGeneratedText;
}
return false;
}
if (current_item_)
return current_item_->Type() == NGFragmentItem::kGeneratedText;
NOTREACHED();
return false;
}
bool NGInlineCursor::IsHiddenForPaint() const { bool NGInlineCursor::IsHiddenForPaint() const {
if (current_paint_fragment_) if (current_paint_fragment_)
return current_paint_fragment_->PhysicalFragment().IsHiddenForPaint(); return current_paint_fragment_->PhysicalFragment().IsHiddenForPaint();
...@@ -393,6 +408,22 @@ unsigned NGInlineCursor::CurrentTextEndOffset() const { ...@@ -393,6 +408,22 @@ unsigned NGInlineCursor::CurrentTextEndOffset() const {
return 0u; return 0u;
} }
PhysicalRect NGInlineCursor::CurrentLocalRect(unsigned start_offset,
unsigned end_offset) const {
DCHECK(IsText());
if (current_paint_fragment_) {
return To<NGPhysicalTextFragment>(
current_paint_fragment_->PhysicalFragment())
.LocalRect(start_offset, end_offset);
}
if (current_item_) {
return current_item_->LocalRect(current_item_->Text(*fragment_items_),
start_offset, end_offset);
}
NOTREACHED();
return PhysicalRect();
}
void NGInlineCursor::MakeNull() { void NGInlineCursor::MakeNull() {
if (root_paint_fragment_) { if (root_paint_fragment_) {
current_paint_fragment_ = nullptr; current_paint_fragment_ = nullptr;
......
...@@ -98,6 +98,11 @@ class CORE_EXPORT NGInlineCursor { ...@@ -98,6 +98,11 @@ class CORE_EXPORT NGInlineCursor {
// end. // end.
bool IsGeneratedText() const; bool IsGeneratedText() const;
// True if fragment is |NGFragmentItem::kGeneratedText| or
// |NGPhysicalTextFragment::kGeneratedText|.
// TODO(yosin): We should rename |IsGeneratedTextType()| to another name.
bool IsGeneratedTextType() const;
// True if the current position is hidden for paint. It is error to call at // True if the current position is hidden for paint. It is error to call at
// end. // end.
bool IsHiddenForPaint() const; bool IsHiddenForPaint() const;
...@@ -144,6 +149,12 @@ class CORE_EXPORT NGInlineCursor { ...@@ -144,6 +149,12 @@ class CORE_EXPORT NGInlineCursor {
unsigned CurrentTextStartOffset() const; unsigned CurrentTextStartOffset() const;
unsigned CurrentTextEndOffset() const; unsigned CurrentTextEndOffset() const;
// The layout box of text in (start, end) range in local coordinate.
// Start and end offsets must be between |CurrentTextStartOffset()| and
// |CurrentTextEndOffset()|. It is error to call other than text.
PhysicalRect CurrentLocalRect(unsigned start_offset,
unsigned end_offset) const;
// //
// Functions to move the current position. // Functions to move the current position.
// //
......
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