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

Use |NGTextOffset| in |NGInlineItemResult|

This patch has no behavior changes.

Bug: 982194
Change-Id: Id4318d42c90bc4aee277c8ca167067664cabe6fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2154629
Auto-Submit: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#776811}
parent b570aec5
...@@ -10,20 +10,17 @@ ...@@ -10,20 +10,17 @@
namespace blink { namespace blink {
NGInlineItemResult::NGInlineItemResult() NGInlineItemResult::NGInlineItemResult() : item(nullptr), item_index(0) {}
: item(nullptr), item_index(0), start_offset(0), end_offset(0) {}
NGInlineItemResult::NGInlineItemResult(const NGInlineItem* item, NGInlineItemResult::NGInlineItemResult(const NGInlineItem* item,
unsigned index, unsigned index,
unsigned start, const NGTextOffset& text_offset,
unsigned end,
bool break_anywhere_if_overflow, bool break_anywhere_if_overflow,
bool should_create_line_box, bool should_create_line_box,
bool has_unpositioned_floats) bool has_unpositioned_floats)
: item(item), : item(item),
item_index(index), item_index(index),
start_offset(start), text_offset(text_offset),
end_offset(end),
break_anywhere_if_overflow(break_anywhere_if_overflow), break_anywhere_if_overflow(break_anywhere_if_overflow),
should_create_line_box(should_create_line_box), should_create_line_box(should_create_line_box),
has_unpositioned_floats(has_unpositioned_floats) {} has_unpositioned_floats(has_unpositioned_floats) {}
...@@ -87,13 +84,13 @@ bool NGLineInfo::ComputeNeedsAccurateEndPosition() const { ...@@ -87,13 +84,13 @@ bool NGLineInfo::ComputeNeedsAccurateEndPosition() const {
void NGInlineItemResult::CheckConsistency(bool allow_null_shape_result) const { void NGInlineItemResult::CheckConsistency(bool allow_null_shape_result) const {
DCHECK(item); DCHECK(item);
if (item->Type() == NGInlineItem::kText) { if (item->Type() == NGInlineItem::kText) {
DCHECK_LT(start_offset, end_offset); text_offset.AssertNotEmpty();
if (allow_null_shape_result && !shape_result) if (allow_null_shape_result && !shape_result)
return; return;
DCHECK(shape_result); DCHECK(shape_result);
DCHECK_EQ(end_offset - start_offset, shape_result->NumCharacters()); DCHECK_EQ(Length(), shape_result->NumCharacters());
DCHECK_EQ(start_offset, shape_result->StartIndex()); DCHECK_EQ(StartOffset(), shape_result->StartIndex());
DCHECK_EQ(end_offset, shape_result->EndIndex()); DCHECK_EQ(EndOffset(), shape_result->EndIndex());
} }
} }
#endif #endif
...@@ -107,7 +104,7 @@ unsigned NGLineInfo::InflowEndOffset() const { ...@@ -107,7 +104,7 @@ unsigned NGLineInfo::InflowEndOffset() const {
if (item.Type() == NGInlineItem::kText || if (item.Type() == NGInlineItem::kText ||
item.Type() == NGInlineItem::kControl || item.Type() == NGInlineItem::kControl ||
item.Type() == NGInlineItem::kAtomicInline) item.Type() == NGInlineItem::kAtomicInline)
return item_result.end_offset; return item_result.EndOffset();
} }
return StartOffset(); return StartOffset();
} }
...@@ -179,18 +176,18 @@ LayoutUnit NGLineInfo::ComputeTrailingSpaceWidth( ...@@ -179,18 +176,18 @@ LayoutUnit NGLineInfo::ComputeTrailingSpaceWidth(
// The last text item may contain trailing spaces if this is a last line, // The last text item may contain trailing spaces if this is a last line,
// has a forced break, or is 'white-space: pre'. // has a forced break, or is 'white-space: pre'.
unsigned end_offset = item_result.end_offset; unsigned end_offset = item_result.EndOffset();
DCHECK(end_offset); DCHECK(end_offset);
if (item.Type() == NGInlineItem::kText) { if (item.Type() == NGInlineItem::kText) {
const String& text = items_data_->text_content; const String& text = items_data_->text_content;
if (end_offset && text[end_offset - 1] == kSpaceCharacter) { if (end_offset && text[end_offset - 1] == kSpaceCharacter) {
do { do {
--end_offset; --end_offset;
} while (end_offset > item_result.start_offset && } while (end_offset > item_result.StartOffset() &&
text[end_offset - 1] == kSpaceCharacter); text[end_offset - 1] == kSpaceCharacter);
// If all characters in this item_result are spaces, check next item. // If all characters in this item_result are spaces, check next item.
if (end_offset == item_result.start_offset) { if (end_offset == item_result.StartOffset()) {
trailing_spaces_width += item_result.inline_size; trailing_spaces_width += item_result.inline_size;
continue; continue;
} }
......
...@@ -32,11 +32,10 @@ struct CORE_EXPORT NGInlineItemResult { ...@@ -32,11 +32,10 @@ struct CORE_EXPORT NGInlineItemResult {
DISALLOW_NEW(); DISALLOW_NEW();
public: public:
NGTextOffset TextOffset() const { return {start_offset, end_offset}; } const NGTextOffset& TextOffset() const { return text_offset; }
unsigned Length() const { unsigned StartOffset() const { return text_offset.start; }
DCHECK_GT(end_offset, start_offset); unsigned EndOffset() const { return text_offset.end; }
return end_offset - start_offset; unsigned Length() const { return text_offset.Length(); }
}
LayoutUnit HyphenInlineSize() const { LayoutUnit HyphenInlineSize() const {
return hyphen_shape_result->SnappedWidth().ClampNegativeToZero(); return hyphen_shape_result->SnappedWidth().ClampNegativeToZero();
...@@ -52,8 +51,7 @@ struct CORE_EXPORT NGInlineItemResult { ...@@ -52,8 +51,7 @@ struct CORE_EXPORT NGInlineItemResult {
unsigned item_index; unsigned item_index;
// The range of text content for this item. // The range of text content for this item.
unsigned start_offset; NGTextOffset text_offset;
unsigned end_offset;
// Inline size of this item. // Inline size of this item.
LayoutUnit inline_size; LayoutUnit inline_size;
...@@ -133,8 +131,7 @@ struct CORE_EXPORT NGInlineItemResult { ...@@ -133,8 +131,7 @@ struct CORE_EXPORT NGInlineItemResult {
NGInlineItemResult(); NGInlineItemResult();
NGInlineItemResult(const NGInlineItem*, NGInlineItemResult(const NGInlineItem*,
unsigned index, unsigned index,
unsigned start, const NGTextOffset& text_offset,
unsigned end,
bool break_anywhere_if_overflow, bool break_anywhere_if_overflow,
bool should_create_line_box, bool should_create_line_box,
bool has_unpositioned_floats); bool has_unpositioned_floats);
......
...@@ -854,10 +854,9 @@ base::Optional<LayoutUnit> NGInlineLayoutAlgorithm::ApplyJustify( ...@@ -854,10 +854,9 @@ base::Optional<LayoutUnit> NGInlineLayoutAlgorithm::ApplyJustify(
if (item_result.shape_result) { if (item_result.shape_result) {
scoped_refptr<ShapeResult> shape_result = scoped_refptr<ShapeResult> shape_result =
item_result.shape_result->CreateShapeResult(); item_result.shape_result->CreateShapeResult();
DCHECK_GE(item_result.start_offset, line_info->StartOffset()); DCHECK_GE(item_result.StartOffset(), line_info->StartOffset());
DCHECK_EQ(shape_result->NumCharacters(), DCHECK_EQ(shape_result->NumCharacters(), item_result.Length());
item_result.end_offset - item_result.start_offset); shape_result->ApplySpacing(spacing, item_result.StartOffset() -
shape_result->ApplySpacing(spacing, item_result.start_offset -
line_info->StartOffset() - line_info->StartOffset() -
shape_result->StartIndex()); shape_result->StartIndex());
item_result.inline_size = shape_result->SnappedWidth(); item_result.inline_size = shape_result->SnappedWidth();
...@@ -866,9 +865,9 @@ base::Optional<LayoutUnit> NGInlineLayoutAlgorithm::ApplyJustify( ...@@ -866,9 +865,9 @@ base::Optional<LayoutUnit> NGInlineLayoutAlgorithm::ApplyJustify(
item_result.shape_result = ShapeResultView::Create(shape_result.get()); item_result.shape_result = ShapeResultView::Create(shape_result.get());
} else if (item_result.item->Type() == NGInlineItem::kAtomicInline) { } else if (item_result.item->Type() == NGInlineItem::kAtomicInline) {
float offset = 0.f; float offset = 0.f;
DCHECK_LE(line_info->StartOffset(), item_result.start_offset); DCHECK_LE(line_info->StartOffset(), item_result.StartOffset());
unsigned line_text_offset = unsigned line_text_offset =
item_result.start_offset - line_info->StartOffset(); item_result.StartOffset() - line_info->StartOffset();
DCHECK_EQ(kObjectReplacementCharacter, line_text[line_text_offset]); DCHECK_EQ(kObjectReplacementCharacter, line_text[line_text_offset]);
float space = spacing.ComputeSpacing(line_text_offset, offset); float space = spacing.ComputeSpacing(line_text_offset, offset);
item_result.inline_size += space; item_result.inline_size += space;
......
...@@ -94,7 +94,7 @@ inline void ComputeCanBreakAfter(NGInlineItemResult* item_result, ...@@ -94,7 +94,7 @@ inline void ComputeCanBreakAfter(NGInlineItemResult* item_result,
bool auto_wrap, bool auto_wrap,
const LazyLineBreakIterator& break_iterator) { const LazyLineBreakIterator& break_iterator) {
item_result->can_break_after = item_result->can_break_after =
auto_wrap && break_iterator.IsBreakable(item_result->end_offset); auto_wrap && break_iterator.IsBreakable(item_result->EndOffset());
} }
inline void RemoveLastItem(NGLineInfo* line_info) { inline void RemoveLastItem(NGLineInfo* line_info) {
...@@ -236,8 +236,9 @@ inline NGInlineItemResult* NGLineBreaker::AddItem(const NGInlineItem& item, ...@@ -236,8 +236,9 @@ inline NGInlineItemResult* NGLineBreaker::AddItem(const NGInlineItem& item,
DCHECK_LE(end_offset, item.EndOffset()); DCHECK_LE(end_offset, item.EndOffset());
NGInlineItemResults* item_results = line_info->MutableResults(); NGInlineItemResults* item_results = line_info->MutableResults();
return &item_results->emplace_back( return &item_results->emplace_back(
&item, item_index_, offset_, end_offset, break_anywhere_if_overflow_, &item, item_index_, NGTextOffset(offset_, end_offset),
ShouldCreateLineBox(*item_results), HasUnpositionedFloats(*item_results)); break_anywhere_if_overflow_, ShouldCreateLineBox(*item_results),
HasUnpositionedFloats(*item_results));
} }
inline NGInlineItemResult* NGLineBreaker::AddItem(const NGInlineItem& item, inline NGInlineItemResult* NGLineBreaker::AddItem(const NGInlineItem& item,
...@@ -444,7 +445,7 @@ void NGLineBreaker::BreakLine( ...@@ -444,7 +445,7 @@ void NGLineBreaker::BreakLine(
// determine the break opportunity. // determine the break opportunity.
NGInlineItemResult* item_result = AddItem(item, line_info); NGInlineItemResult* item_result = AddItem(item, line_info);
item_result->can_break_after = item_result->can_break_after =
break_iterator_.IsBreakable(item_result->end_offset); break_iterator_.IsBreakable(item_result->EndOffset());
MoveToNextOf(item); MoveToNextOf(item);
} else if (item.Type() == NGInlineItem::kListMarker) { } else if (item.Type() == NGInlineItem::kListMarker) {
NGInlineItemResult* item_result = AddItem(item, line_info); NGInlineItemResult* item_result = AddItem(item, line_info);
...@@ -481,23 +482,23 @@ bool NGLineBreaker::ShouldForceCanBreakAfter( ...@@ -481,23 +482,23 @@ bool NGLineBreaker::ShouldForceCanBreakAfter(
DCHECK(auto_wrap_); DCHECK(auto_wrap_);
DCHECK_EQ(item_result.item->Type(), NGInlineItem::kText); DCHECK_EQ(item_result.item->Type(), NGInlineItem::kText);
const String& text = Text(); const String& text = Text();
DCHECK_GE(text.length(), item_result.end_offset); DCHECK_GE(text.length(), item_result.EndOffset());
if (text.length() <= item_result.end_offset || if (text.length() <= item_result.EndOffset() ||
text[item_result.end_offset] != kObjectReplacementCharacter) text[item_result.EndOffset()] != kObjectReplacementCharacter)
return false; return false;
// This kObjectReplacementCharacter can be any objects, such as a floating or // This kObjectReplacementCharacter can be any objects, such as a floating or
// an OOF object. Check if it's really an atomic inline. // an OOF object. Check if it's really an atomic inline.
const Vector<NGInlineItem>& items = Items(); const Vector<NGInlineItem>& items = Items();
for (const NGInlineItem* item = std::next(item_result.item); for (const NGInlineItem* item = std::next(item_result.item);
item != items.end(); ++item) { item != items.end(); ++item) {
DCHECK_EQ(item->StartOffset(), item_result.end_offset); DCHECK_EQ(item->StartOffset(), item_result.EndOffset());
if (item->Type() == NGInlineItem::kAtomicInline) { if (item->Type() == NGInlineItem::kAtomicInline) {
// Except when sticky images quirk was applied. // Except when sticky images quirk was applied.
if (UNLIKELY(text[item->StartOffset()] == kNoBreakSpaceCharacter)) if (UNLIKELY(text[item->StartOffset()] == kNoBreakSpaceCharacter))
return false; return false;
return true; return true;
} }
if (item->EndOffset() > item_result.end_offset) if (item->EndOffset() > item_result.EndOffset())
break; break;
} }
return false; return false;
...@@ -589,7 +590,7 @@ void NGLineBreaker::HandleText(const NGInlineItem& item, ...@@ -589,7 +590,7 @@ void NGLineBreaker::HandleText(const NGInlineItem& item,
// If the break is at the middle of a text item, we know no trailable // If the break is at the middle of a text item, we know no trailable
// items follow, only trailable spaces if any. This is very common that // items follow, only trailable spaces if any. This is very common that
// shortcut to handling trailing spaces. // shortcut to handling trailing spaces.
if (item_result->end_offset < item.EndOffset()) if (item_result->EndOffset() < item.EndOffset())
return HandleTrailingSpaces(item, shape_result, line_info); return HandleTrailingSpaces(item, shape_result, line_info);
// The break point found at the end of this text item. Continue looking // The break point found at the end of this text item. Continue looking
...@@ -615,8 +616,8 @@ void NGLineBreaker::HandleText(const NGInlineItem& item, ...@@ -615,8 +616,8 @@ void NGLineBreaker::HandleText(const NGInlineItem& item,
// If this is all trailable spaces, this item is trailable, and next item // If this is all trailable spaces, this item is trailable, and next item
// maybe too. Don't go to |HandleOverflow()| yet. // maybe too. Don't go to |HandleOverflow()| yet.
if (IsAllBreakableSpaces(Text(), item_result->start_offset, if (IsAllBreakableSpaces(Text(), item_result->StartOffset(),
item_result->end_offset)) item_result->EndOffset()))
return; return;
HandleOverflow(line_info); HandleOverflow(line_info);
...@@ -625,8 +626,8 @@ void NGLineBreaker::HandleText(const NGInlineItem& item, ...@@ -625,8 +626,8 @@ void NGLineBreaker::HandleText(const NGInlineItem& item,
// Add until the end of the item if !auto_wrap. In most cases, it's the whole // Add until the end of the item if !auto_wrap. In most cases, it's the whole
// item. // item.
DCHECK_EQ(item_result->end_offset, item.EndOffset()); DCHECK_EQ(item_result->EndOffset(), item.EndOffset());
if (item_result->start_offset == item.StartOffset()) { if (item_result->StartOffset() == item.StartOffset()) {
item_result->inline_size = item_result->inline_size =
shape_result.SnappedWidth().ClampNegativeToZero(); shape_result.SnappedWidth().ClampNegativeToZero();
item_result->shape_result = ShapeResultView::Create(&shape_result); item_result->shape_result = ShapeResultView::Create(&shape_result);
...@@ -634,9 +635,9 @@ void NGLineBreaker::HandleText(const NGInlineItem& item, ...@@ -634,9 +635,9 @@ void NGLineBreaker::HandleText(const NGInlineItem& item,
// <wbr> can wrap even if !auto_wrap. Spaces after that will be leading // <wbr> can wrap even if !auto_wrap. Spaces after that will be leading
// spaces and thus be collapsed. // spaces and thus be collapsed.
DCHECK(trailing_whitespace_ == WhitespaceState::kLeading && DCHECK(trailing_whitespace_ == WhitespaceState::kLeading &&
item_result->start_offset >= item.StartOffset()); item_result->StartOffset() >= item.StartOffset());
item_result->shape_result = ShapeResultView::Create( item_result->shape_result = ShapeResultView::Create(
&shape_result, item_result->start_offset, item_result->end_offset); &shape_result, item_result->StartOffset(), item_result->EndOffset());
item_result->inline_size = item_result->inline_size =
item_result->shape_result->SnappedWidth().ClampNegativeToZero(); item_result->shape_result->SnappedWidth().ClampNegativeToZero();
} }
...@@ -659,7 +660,7 @@ NGLineBreaker::BreakResult NGLineBreaker::BreakText( ...@@ -659,7 +660,7 @@ NGLineBreaker::BreakResult NGLineBreaker::BreakText(
(item.Type() == NGInlineItem::kControl && (item.Type() == NGInlineItem::kControl &&
Text()[item.StartOffset()] == kTabulationCharacter)); Text()[item.StartOffset()] == kTabulationCharacter));
DCHECK(&item_shape_result); DCHECK(&item_shape_result);
item.AssertOffset(item_result->start_offset); item.AssertOffset(item_result->StartOffset());
DCHECK_EQ(item_shape_result.StartIndex(), item.StartOffset()); DCHECK_EQ(item_shape_result.StartIndex(), item.StartOffset());
DCHECK_EQ(item_shape_result.EndIndex(), item.EndOffset()); DCHECK_EQ(item_shape_result.EndIndex(), item.EndOffset());
...@@ -683,7 +684,7 @@ NGLineBreaker::BreakResult NGLineBreaker::BreakText( ...@@ -683,7 +684,7 @@ NGLineBreaker::BreakResult NGLineBreaker::BreakText(
// Use kStartShouldBeSafe if at the beginning of a line. // Use kStartShouldBeSafe if at the beginning of a line.
unsigned options = ShapingLineBreaker::kDefaultOptions; unsigned options = ShapingLineBreaker::kDefaultOptions;
if (item_result->start_offset != line_info->StartOffset()) if (item_result->StartOffset() != line_info->StartOffset())
options |= ShapingLineBreaker::kDontReshapeStart; options |= ShapingLineBreaker::kDontReshapeStart;
// Reshaping between the last character and trailing spaces is needed only // Reshaping between the last character and trailing spaces is needed only
...@@ -709,7 +710,7 @@ NGLineBreaker::BreakResult NGLineBreaker::BreakText( ...@@ -709,7 +710,7 @@ NGLineBreaker::BreakResult NGLineBreaker::BreakText(
DCHECK_LE(try_count, 2u); DCHECK_LE(try_count, 2u);
#endif #endif
scoped_refptr<const ShapeResultView> shape_result = breaker.ShapeLine( scoped_refptr<const ShapeResultView> shape_result = breaker.ShapeLine(
item_result->start_offset, available_width.ClampNegativeToZero(), item_result->StartOffset(), available_width.ClampNegativeToZero(),
options, &result); options, &result);
// If this item overflows and 'break-word' is set, this line will be // If this item overflows and 'break-word' is set, this line will be
...@@ -717,14 +718,15 @@ NGLineBreaker::BreakResult NGLineBreaker::BreakText( ...@@ -717,14 +718,15 @@ NGLineBreaker::BreakResult NGLineBreaker::BreakText(
if (!shape_result) { if (!shape_result) {
DCHECK(options & ShapingLineBreaker::kNoResultIfOverflow); DCHECK(options & ShapingLineBreaker::kNoResultIfOverflow);
item_result->inline_size = available_width_with_hyphens + 1; item_result->inline_size = available_width_with_hyphens + 1;
item_result->end_offset = item.EndOffset(); item_result->text_offset.end = item.EndOffset();
item_result->text_offset.AssertNotEmpty();
return kOverflow; return kOverflow;
} }
DCHECK_EQ(shape_result->NumCharacters(), DCHECK_EQ(shape_result->NumCharacters(),
result.break_offset - item_result->start_offset); result.break_offset - item_result->StartOffset());
// It is critical to move the offset forward, or NGLineBreaker may keep // It is critical to move the offset forward, or NGLineBreaker may keep
// adding NGInlineItemResult until all the memory is consumed. // adding NGInlineItemResult until all the memory is consumed.
CHECK_GT(result.break_offset, item_result->start_offset); CHECK_GT(result.break_offset, item_result->StartOffset());
inline_size = shape_result->SnappedWidth().ClampNegativeToZero(); inline_size = shape_result->SnappedWidth().ClampNegativeToZero();
if (UNLIKELY(result.is_hyphenated)) { if (UNLIKELY(result.is_hyphenated)) {
...@@ -748,7 +750,8 @@ NGLineBreaker::BreakResult NGLineBreaker::BreakText( ...@@ -748,7 +750,8 @@ NGLineBreaker::BreakResult NGLineBreaker::BreakText(
item_result->hyphen_string = String(); item_result->hyphen_string = String();
} }
item_result->inline_size = inline_size; item_result->inline_size = inline_size;
item_result->end_offset = result.break_offset; item_result->text_offset.end = result.break_offset;
item_result->text_offset.AssertNotEmpty();
item_result->shape_result = std::move(shape_result); item_result->shape_result = std::move(shape_result);
break; break;
} }
...@@ -761,7 +764,7 @@ NGLineBreaker::BreakResult NGLineBreaker::BreakText( ...@@ -761,7 +764,7 @@ NGLineBreaker::BreakResult NGLineBreaker::BreakText(
// * If width > available_width: The first break opportunity does not fit. // * If width > available_width: The first break opportunity does not fit.
// offset is the first break opportunity, either inside, at the end, or // offset is the first break opportunity, either inside, at the end, or
// beyond the end. // beyond the end.
if (item_result->end_offset < item.EndOffset()) { if (item_result->EndOffset() < item.EndOffset()) {
item_result->can_break_after = true; item_result->can_break_after = true;
if (UNLIKELY(break_iterator_.BreakType() == if (UNLIKELY(break_iterator_.BreakType() ==
...@@ -771,9 +774,9 @@ NGLineBreaker::BreakResult NGLineBreaker::BreakText( ...@@ -771,9 +774,9 @@ NGLineBreaker::BreakResult NGLineBreaker::BreakText(
trailing_whitespace_ = WhitespaceState::kNone; trailing_whitespace_ = WhitespaceState::kNone;
} }
} else { } else {
DCHECK_EQ(item_result->end_offset, item.EndOffset()); DCHECK_EQ(item_result->EndOffset(), item.EndOffset());
item_result->can_break_after = item_result->can_break_after =
break_iterator_.IsBreakable(item_result->end_offset); break_iterator_.IsBreakable(item_result->EndOffset());
if (!item_result->can_break_after && item.Type() == NGInlineItem::kText && if (!item_result->can_break_after && item.Type() == NGInlineItem::kText &&
ShouldForceCanBreakAfter(*item_result)) ShouldForceCanBreakAfter(*item_result))
item_result->can_break_after = true; item_result->can_break_after = true;
...@@ -790,7 +793,7 @@ NGLineBreaker::BreakResult NGLineBreaker::BreakText( ...@@ -790,7 +793,7 @@ NGLineBreaker::BreakResult NGLineBreaker::BreakText(
} }
// Breaks the text item at the previous break opportunity from // Breaks the text item at the previous break opportunity from
// |item_result->end_offset|. Returns false if there were no previous break // |item_result->text_offset.end|. Returns false if there were no previous break
// opportunities. // opportunities.
bool NGLineBreaker::BreakTextAtPreviousBreakOpportunity( bool NGLineBreaker::BreakTextAtPreviousBreakOpportunity(
NGInlineItemResult* item_result) { NGInlineItemResult* item_result) {
...@@ -801,13 +804,14 @@ bool NGLineBreaker::BreakTextAtPreviousBreakOpportunity( ...@@ -801,13 +804,14 @@ bool NGLineBreaker::BreakTextAtPreviousBreakOpportunity(
DCHECK(item.Style() && item.Style()->AutoWrap()); DCHECK(item.Style() && item.Style()->AutoWrap());
unsigned break_opportunity = break_iterator_.PreviousBreakOpportunity( unsigned break_opportunity = break_iterator_.PreviousBreakOpportunity(
item_result->end_offset - 1, item_result->start_offset); item_result->EndOffset() - 1, item_result->StartOffset());
if (break_opportunity <= item_result->start_offset) if (break_opportunity <= item_result->StartOffset())
return false; return false;
item_result->end_offset = break_opportunity; item_result->text_offset.end = break_opportunity;
item_result->shape_result = item_result->text_offset.AssertNotEmpty();
ShapeResultView::Create(item.TextShapeResult(), item_result->start_offset, item_result->shape_result = ShapeResultView::Create(
item_result->end_offset); item.TextShapeResult(), item_result->StartOffset(),
item_result->EndOffset());
item_result->inline_size = item_result->inline_size =
item_result->shape_result->SnappedWidth().ClampNegativeToZero(); item_result->shape_result->SnappedWidth().ClampNegativeToZero();
item_result->can_break_after = true; item_result->can_break_after = true;
...@@ -839,7 +843,7 @@ bool NGLineBreaker::HandleTextForFastMinContent(NGInlineItemResult* item_result, ...@@ -839,7 +843,7 @@ bool NGLineBreaker::HandleTextForFastMinContent(NGInlineItemResult* item_result,
// If this is the first part of the text, it may form a word with the previous // If this is the first part of the text, it may form a word with the previous
// item. Fallback to |HandleText()|. // item. Fallback to |HandleText()|.
unsigned start_offset = item_result->start_offset; unsigned start_offset = item_result->StartOffset();
DCHECK_LT(start_offset, item.EndOffset()); DCHECK_LT(start_offset, item.EndOffset());
if (start_offset != line_info->StartOffset() && if (start_offset != line_info->StartOffset() &&
start_offset == item.StartOffset()) start_offset == item.StartOffset())
...@@ -902,7 +906,8 @@ bool NGLineBreaker::HandleTextForFastMinContent(NGInlineItemResult* item_result, ...@@ -902,7 +906,8 @@ bool NGLineBreaker::HandleTextForFastMinContent(NGInlineItemResult* item_result,
return false; return false;
// Create an NGInlineItemResult that has the max of widths of all words. // Create an NGInlineItemResult that has the max of widths of all words.
item_result->end_offset = last_end_offset; item_result->text_offset.end = last_end_offset;
item_result->text_offset.AssertNotEmpty();
item_result->inline_size = LayoutUnit::FromFloatCeil(min_width); item_result->inline_size = LayoutUnit::FromFloatCeil(min_width);
item_result->can_break_after = true; item_result->can_break_after = true;
...@@ -952,7 +957,7 @@ scoped_refptr<ShapeResultView> NGLineBreaker::TruncateLineEndResult( ...@@ -952,7 +957,7 @@ scoped_refptr<ShapeResultView> NGLineBreaker::TruncateLineEndResult(
const NGInlineItem& item = *item_result.item; const NGInlineItem& item = *item_result.item;
// Check given offsets require to truncate |item_result.shape_result|. // Check given offsets require to truncate |item_result.shape_result|.
const unsigned start_offset = item_result.start_offset; const unsigned start_offset = item_result.StartOffset();
const ShapeResultView* source_result = item_result.shape_result.get(); const ShapeResultView* source_result = item_result.shape_result.get();
DCHECK(source_result); DCHECK(source_result);
DCHECK_GE(start_offset, source_result->StartIndex()); DCHECK_GE(start_offset, source_result->StartIndex());
...@@ -985,7 +990,7 @@ void NGLineBreaker::UpdateShapeResult(const NGLineInfo& line_info, ...@@ -985,7 +990,7 @@ void NGLineBreaker::UpdateShapeResult(const NGLineInfo& line_info,
NGInlineItemResult* item_result) { NGInlineItemResult* item_result) {
DCHECK(item_result); DCHECK(item_result);
item_result->shape_result = item_result->shape_result =
TruncateLineEndResult(line_info, *item_result, item_result->end_offset); TruncateLineEndResult(line_info, *item_result, item_result->EndOffset());
DCHECK(item_result->shape_result); DCHECK(item_result->shape_result);
item_result->inline_size = item_result->shape_result->SnappedWidth(); item_result->inline_size = item_result->shape_result->SnappedWidth();
} }
...@@ -1045,8 +1050,8 @@ void NGLineBreaker::HandleTrailingSpaces(const NGInlineItem& item, ...@@ -1045,8 +1050,8 @@ void NGLineBreaker::HandleTrailingSpaces(const NGInlineItem& item,
NGInlineItemResult* item_result = AddItem(item, end, line_info); NGInlineItemResult* item_result = AddItem(item, end, line_info);
item_result->has_only_trailing_spaces = true; item_result->has_only_trailing_spaces = true;
item_result->shape_result = ShapeResultView::Create(&shape_result); item_result->shape_result = ShapeResultView::Create(&shape_result);
if (item_result->start_offset == item.StartOffset() && if (item_result->StartOffset() == item.StartOffset() &&
item_result->end_offset == item.EndOffset()) item_result->EndOffset() == item.EndOffset())
item_result->inline_size = item_result->shape_result->SnappedWidth(); item_result->inline_size = item_result->shape_result->SnappedWidth();
else else
UpdateShapeResult(*line_info, item_result); UpdateShapeResult(*line_info, item_result);
...@@ -1086,7 +1091,7 @@ void NGLineBreaker::RemoveTrailingCollapsibleSpace(NGLineInfo* line_info) { ...@@ -1086,7 +1091,7 @@ void NGLineBreaker::RemoveTrailingCollapsibleSpace(NGLineInfo* line_info) {
if (end_index < item_results.size()) { if (end_index < item_results.size()) {
const NGInlineItemResult& end_item_result = item_results[end_index]; const NGInlineItemResult& end_item_result = item_results[end_index];
unsigned end_item_index = end_item_result.item_index; unsigned end_item_index = end_item_result.item_index;
unsigned end_offset = end_item_result.start_offset; unsigned end_offset = end_item_result.StartOffset();
ResetRewindLoopDetector(); ResetRewindLoopDetector();
Rewind(end_index, line_info); Rewind(end_index, line_info);
item_index_ = end_item_index; item_index_ = end_item_index;
...@@ -1107,8 +1112,8 @@ void NGLineBreaker::RemoveTrailingCollapsibleSpace(NGLineInfo* line_info) { ...@@ -1107,8 +1112,8 @@ void NGLineBreaker::RemoveTrailingCollapsibleSpace(NGLineInfo* line_info) {
position_ -= item_result->inline_size; position_ -= item_result->inline_size;
if (scoped_refptr<const ShapeResultView>& collapsed_shape_result = if (scoped_refptr<const ShapeResultView>& collapsed_shape_result =
trailing_collapsible_space_->collapsed_shape_result) { trailing_collapsible_space_->collapsed_shape_result) {
DCHECK_GE(item_result->end_offset, item_result->start_offset + 2); --item_result->text_offset.end;
--item_result->end_offset; item_result->text_offset.AssertNotEmpty();
item_result->shape_result = collapsed_shape_result; item_result->shape_result = collapsed_shape_result;
item_result->inline_size = item_result->shape_result->SnappedWidth(); item_result->inline_size = item_result->shape_result->SnappedWidth();
position_ += item_result->inline_size; position_ += item_result->inline_size;
...@@ -1159,9 +1164,9 @@ void NGLineBreaker::ComputeTrailingCollapsibleSpace(NGLineInfo* line_info) { ...@@ -1159,9 +1164,9 @@ void NGLineBreaker::ComputeTrailingCollapsibleSpace(NGLineInfo* line_info) {
if (item.EndCollapseType() == NGInlineItem::kOpaqueToCollapsing) if (item.EndCollapseType() == NGInlineItem::kOpaqueToCollapsing)
continue; continue;
if (item.Type() == NGInlineItem::kText) { if (item.Type() == NGInlineItem::kText) {
DCHECK_GT(item_result.end_offset, 0u); DCHECK_GT(item_result.EndOffset(), 0u);
DCHECK(item.Style()); DCHECK(item.Style());
if (!IsBreakableSpace(text[item_result.end_offset - 1])) if (!IsBreakableSpace(text[item_result.EndOffset() - 1]))
break; break;
if (!item.Style()->CollapseWhiteSpace()) { if (!item.Style()->CollapseWhiteSpace()) {
trailing_whitespace_ = WhitespaceState::kPreserved; trailing_whitespace_ = WhitespaceState::kPreserved;
...@@ -1176,10 +1181,10 @@ void NGLineBreaker::ComputeTrailingCollapsibleSpace(NGLineInfo* line_info) { ...@@ -1176,10 +1181,10 @@ void NGLineBreaker::ComputeTrailingCollapsibleSpace(NGLineInfo* line_info) {
trailing_collapsible_space_->item_result != &item_result) { trailing_collapsible_space_->item_result != &item_result) {
trailing_collapsible_space_.emplace(); trailing_collapsible_space_.emplace();
trailing_collapsible_space_->item_result = &item_result; trailing_collapsible_space_->item_result = &item_result;
if (item_result.end_offset - 1 > item_result.start_offset) { if (item_result.EndOffset() - 1 > item_result.StartOffset()) {
trailing_collapsible_space_->collapsed_shape_result = trailing_collapsible_space_->collapsed_shape_result =
TruncateLineEndResult(*line_info, item_result, TruncateLineEndResult(*line_info, item_result,
item_result.end_offset - 1); item_result.EndOffset() - 1);
} }
} }
trailing_whitespace_ = WhitespaceState::kCollapsible; trailing_whitespace_ = WhitespaceState::kCollapsible;
...@@ -1663,8 +1668,8 @@ void NGLineBreaker::HandleCloseTag(const NGInlineItem& item, ...@@ -1663,8 +1668,8 @@ void NGLineBreaker::HandleCloseTag(const NGInlineItem& item,
// iterator cannot compute this because it considers break opportunities are // iterator cannot compute this because it considers break opportunities are
// before a run of spaces. // before a run of spaces.
const String& text = Text(); const String& text = Text();
if (item_result->end_offset < text.length() && if (item_result->EndOffset() < text.length() &&
IsBreakableSpace(text[item_result->end_offset])) { IsBreakableSpace(text[item_result->EndOffset()])) {
item_result->can_break_after = true; item_result->can_break_after = true;
return; return;
} }
...@@ -1743,7 +1748,7 @@ void NGLineBreaker::HandleOverflow(NGLineInfo* line_info) { ...@@ -1743,7 +1748,7 @@ void NGLineBreaker::HandleOverflow(NGLineInfo* line_info) {
BreakText(item_result, item, *item.TextShapeResult(), BreakText(item_result, item, *item.TextShapeResult(),
std::min(item_available_width, min_available_width), std::min(item_available_width, min_available_width),
item_available_width, line_info); item_available_width, line_info);
DCHECK_LE(item_result->end_offset, item_result_before.end_offset); DCHECK_LE(item_result->EndOffset(), item_result_before.EndOffset());
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
item_result->CheckConsistency(true); item_result->CheckConsistency(true);
#endif #endif
...@@ -1751,8 +1756,8 @@ void NGLineBreaker::HandleOverflow(NGLineInfo* line_info) { ...@@ -1751,8 +1756,8 @@ void NGLineBreaker::HandleOverflow(NGLineInfo* line_info) {
// If BreakText() changed this item small enough to fit, break here. // If BreakText() changed this item small enough to fit, break here.
if (item_result->can_break_after && if (item_result->can_break_after &&
item_result->inline_size <= item_available_width && item_result->inline_size <= item_available_width &&
item_result->end_offset < item_result_before.end_offset) { item_result->EndOffset() < item_result_before.EndOffset()) {
DCHECK_LT(item_result->end_offset, item.EndOffset()); DCHECK_LT(item_result->EndOffset(), item.EndOffset());
// If this is the last item, adjust it to accommodate the change. // If this is the last item, adjust it to accommodate the change.
const unsigned new_end = i + 1; const unsigned new_end = i + 1;
...@@ -1762,7 +1767,7 @@ void NGLineBreaker::HandleOverflow(NGLineInfo* line_info) { ...@@ -1762,7 +1767,7 @@ void NGLineBreaker::HandleOverflow(NGLineInfo* line_info) {
available_width + width_to_rewind + item_result->inline_size; available_width + width_to_rewind + item_result->inline_size;
DCHECK_EQ(position_, line_info->ComputeWidth()); DCHECK_EQ(position_, line_info->ComputeWidth());
item_index_ = item_result->item_index; item_index_ = item_result->item_index;
offset_ = item_result->end_offset; offset_ = item_result->EndOffset();
items_data_.AssertOffset(item_index_, offset_); items_data_.AssertOffset(item_index_, offset_);
HandleTrailingSpaces(item, line_info); HandleTrailingSpaces(item, line_info);
return; return;
...@@ -1841,11 +1846,11 @@ void NGLineBreaker::RewindOverflow(unsigned new_end, NGLineInfo* line_info) { ...@@ -1841,11 +1846,11 @@ void NGLineBreaker::RewindOverflow(unsigned new_end, NGLineInfo* line_info) {
const EWhiteSpace white_space = item.Style()->WhiteSpace(); const EWhiteSpace white_space = item.Style()->WhiteSpace();
if (ComputedStyle::AutoWrap(white_space) && if (ComputedStyle::AutoWrap(white_space) &&
white_space != EWhiteSpace::kBreakSpaces && white_space != EWhiteSpace::kBreakSpaces &&
IsBreakableSpace(text[item_result.start_offset])) { IsBreakableSpace(text[item_result.StartOffset()])) {
// If all characters are trailable spaces, check the next item. // If all characters are trailable spaces, check the next item.
if (item_result.shape_result && if (item_result.shape_result &&
IsAllBreakableSpaces(text, item_result.start_offset + 1, IsAllBreakableSpaces(text, item_result.StartOffset() + 1,
item_result.end_offset)) { item_result.EndOffset())) {
continue; continue;
} }
// If this item starts with spaces followed by non-space characters, // If this item starts with spaces followed by non-space characters,
...@@ -1865,7 +1870,7 @@ void NGLineBreaker::RewindOverflow(unsigned new_end, NGLineInfo* line_info) { ...@@ -1865,7 +1870,7 @@ void NGLineBreaker::RewindOverflow(unsigned new_end, NGLineInfo* line_info) {
// All control characters except newline are trailable if auto_wrap. We // All control characters except newline are trailable if auto_wrap. We
// should not have rewound if there was a newline, so safe to assume all // should not have rewound if there was a newline, so safe to assume all
// controls are trailable. // controls are trailable.
DCHECK_NE(text[item_result.start_offset], kNewlineCharacter); DCHECK_NE(text[item_result.StartOffset()], kNewlineCharacter);
DCHECK(item.Style()); DCHECK(item.Style());
EWhiteSpace white_space = item.Style()->WhiteSpace(); EWhiteSpace white_space = item.Style()->WhiteSpace();
if (ComputedStyle::AutoWrap(white_space) && if (ComputedStyle::AutoWrap(white_space) &&
...@@ -1976,7 +1981,7 @@ void NGLineBreaker::Rewind(unsigned new_end, NGLineInfo* line_info) { ...@@ -1976,7 +1981,7 @@ void NGLineBreaker::Rewind(unsigned new_end, NGLineInfo* line_info) {
// When rewinding all items, use |results[0].start_offset|. // When rewinding all items, use |results[0].start_offset|.
const NGInlineItemResult& first_remove = item_results[new_end]; const NGInlineItemResult& first_remove = item_results[new_end];
item_index_ = first_remove.item_index; item_index_ = first_remove.item_index;
offset_ = first_remove.start_offset; offset_ = first_remove.StartOffset();
trailing_whitespace_ = WhitespaceState::kLeading; trailing_whitespace_ = WhitespaceState::kLeading;
maybe_have_end_overhang_ = false; maybe_have_end_overhang_ = false;
} }
...@@ -2101,7 +2106,7 @@ void NGLineBreaker::MoveToNextOf(const NGInlineItem& item) { ...@@ -2101,7 +2106,7 @@ void NGLineBreaker::MoveToNextOf(const NGInlineItem& item) {
} }
void NGLineBreaker::MoveToNextOf(const NGInlineItemResult& item_result) { void NGLineBreaker::MoveToNextOf(const NGInlineItemResult& item_result) {
offset_ = item_result.end_offset; offset_ = item_result.EndOffset();
item_index_ = item_result.item_index; item_index_ = item_result.item_index;
DCHECK(item_result.item); DCHECK(item_result.item);
if (offset_ == item_result.item->EndOffset()) if (offset_ == item_result.item->EndOffset())
......
...@@ -22,8 +22,7 @@ String ToString(NGInlineItemResults line, NGInlineNode node) { ...@@ -22,8 +22,7 @@ String ToString(NGInlineItemResults line, NGInlineNode node) {
const String& text = node.ItemsData(false).text_content; const String& text = node.ItemsData(false).text_content;
for (const auto& item_result : line) { for (const auto& item_result : line) {
builder.Append( builder.Append(
StringView(text, item_result.start_offset, StringView(text, item_result.StartOffset(), item_result.Length()));
item_result.end_offset - item_result.start_offset));
} }
return builder.ToString(); return builder.ToString();
} }
......
...@@ -23,6 +23,7 @@ struct CORE_EXPORT NGTextOffset { ...@@ -23,6 +23,7 @@ struct CORE_EXPORT NGTextOffset {
} }
void AssertValid() const { DCHECK_GE(end, start); } void AssertValid() const { DCHECK_GE(end, start); }
void AssertNotEmpty() const { DCHECK_GT(end, start); }
unsigned start; unsigned start;
unsigned end; unsigned end;
......
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