Commit e9b6af0d authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

[LayoutNG] Simplify NG text node handling in TextIteratorTextNodeHandler

This is a followup of crrev.com/c/1436464. With the previous patch,
callers of NGOffsetMapping::GetMappingUnitsForDOMRange() no longer need
to clamp out-of-range portions of the units by themselves.

As a followup, this patch removes the code handling partially out of
range units.

Change-Id: I5a7452d995365939509ba7a763de20ee2acf47a4
Reviewed-on: https://chromium-review.googlesource.com/c/1437193Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626438}
parent 60a3d761
...@@ -53,18 +53,16 @@ struct StringAndOffsetRange { ...@@ -53,18 +53,16 @@ struct StringAndOffsetRange {
StringAndOffsetRange ComputeTextAndOffsetsForEmission( StringAndOffsetRange ComputeTextAndOffsetsForEmission(
const NGOffsetMapping& mapping, const NGOffsetMapping& mapping,
const NGOffsetMappingUnit& unit, const NGOffsetMappingUnit& unit,
unsigned run_start,
unsigned run_end,
const TextIteratorBehavior& behavior) { const TextIteratorBehavior& behavior) {
// TODO(xiaochengh): Handle EmitsOriginalText. // TODO(xiaochengh): Handle EmitsOriginalText.
unsigned text_content_start = unit.ConvertDOMOffsetToTextContent(run_start);
unsigned text_content_end = unit.ConvertDOMOffsetToTextContent(run_end);
unsigned length = text_content_end - text_content_start;
if (behavior.EmitsSpaceForNbsp()) { if (behavior.EmitsSpaceForNbsp()) {
String string = mapping.GetText().Substring(text_content_start, length); String string = mapping.GetText().Substring(
unit.TextContentStart(),
unit.TextContentEnd() - unit.TextContentStart());
// TODO(xiaochengh): This seems wrong... Add real handling.
return {string, 0, 0}; return {string, 0, 0};
} }
return {mapping.GetText(), text_content_start, text_content_end}; return {mapping.GetText(), unit.TextContentStart(), unit.TextContentEnd()};
} }
} // namespace } // namespace
...@@ -113,25 +111,21 @@ void TextIteratorTextNodeHandler::HandleTextNodeWithLayoutNG() { ...@@ -113,25 +111,21 @@ void TextIteratorTextNodeHandler::HandleTextNodeWithLayoutNG() {
const unsigned initial_offset = offset_; const unsigned initial_offset = offset_;
for (const NGOffsetMappingUnit& unit : for (const NGOffsetMappingUnit& unit :
mapping->GetMappingUnitsForDOMRange(range_to_emit)) { mapping->GetMappingUnitsForDOMRange(range_to_emit)) {
const unsigned run_start = std::max(offset_, unit.DOMStart()); if (unit.TextContentEnd() == unit.TextContentStart() ||
const unsigned run_end = std::min(end_offset_, unit.DOMEnd()); ShouldSkipInvisibleTextAt(*text_node_, unit.DOMStart(),
if (run_start >= run_end ||
unit.ConvertDOMOffsetToTextContent(run_start) ==
unit.ConvertDOMOffsetToTextContent(run_end) ||
ShouldSkipInvisibleTextAt(*text_node_, run_start,
IgnoresStyleVisibility())) { IgnoresStyleVisibility())) {
offset_ = run_end; offset_ = unit.DOMEnd();
continue; continue;
} }
auto string_and_offsets = ComputeTextAndOffsetsForEmission( auto string_and_offsets =
*mapping, unit, run_start, run_end, behavior_); ComputeTextAndOffsetsForEmission(*mapping, unit, behavior_);
const String& string = string_and_offsets.string; const String& string = string_and_offsets.string;
const unsigned text_content_start = string_and_offsets.start; const unsigned text_content_start = string_and_offsets.start;
const unsigned text_content_end = string_and_offsets.end; const unsigned text_content_end = string_and_offsets.end;
text_state_.EmitText(*text_node_, run_start, run_end, string, text_state_.EmitText(*text_node_, unit.DOMStart(), unit.DOMEnd(), string,
text_content_start, text_content_end); text_content_start, text_content_end);
offset_ = run_end; offset_ = unit.DOMEnd();
return; return;
} }
......
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