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;
......
...@@ -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