Commit 956820a1 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Simplify TextIteratorTextNodeHandler::FixLeadingWhiteSpaceForReplacedElement()

This patch simplifies |FixLeadingWhiteSpaceForReplacedElement()| of
|TextIteratorTextNodeHandler| by moving conditional expression into another
function for improving code health.

Change-Id: I6d83dd5e78696c808b87ce2998bccbd9b1edaa9c
Reviewed-on: https://chromium-review.googlesource.com/1025675Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553449}
parent cac45cb4
......@@ -521,28 +521,29 @@ void TextIteratorTextNodeHandler::HandleTextNodeFirstLetter(
text_box_ = first_letter_text_->FirstTextBox();
}
bool TextIteratorTextNodeHandler::FixLeadingWhiteSpaceForReplacedElement(
const Node* parent) {
bool TextIteratorTextNodeHandler::ShouldFixLeadingWhiteSpaceForReplacedElement()
const {
// This is a hacky way for white space fixup in legacy layout. With LayoutNG,
// we can get rid of this function.
if (uses_layout_ng_)
return false;
if (behavior_.CollapseTrailingSpace()) {
if (text_node_) {
String str = text_node_->GetLayoutObject()->GetText();
if (last_text_node_ended_with_collapsed_space_ && offset_ > 0 &&
str[offset_ - 1] == ' ') {
SpliceBuffer(kSpaceCharacter, parent, text_node_, 1, 1);
return true;
}
}
} else if (last_text_node_ended_with_collapsed_space_) {
SpliceBuffer(kSpaceCharacter, parent, text_node_, 1, 1);
if (!last_text_node_ended_with_collapsed_space_)
return false;
if (!behavior_.CollapseTrailingSpace())
return true;
}
if (!text_node_)
return false;
const String str = text_node_->GetLayoutObject()->GetText();
return offset_ > 0 && str[offset_ - 1] == ' ';
}
return false;
bool TextIteratorTextNodeHandler::FixLeadingWhiteSpaceForReplacedElement(
const Node* parent) {
if (!ShouldFixLeadingWhiteSpaceForReplacedElement())
return false;
text_state_.SpliceBuffer(kSpaceCharacter, parent, text_node_, 1, 1);
ResetCollapsedWhiteSpaceFixup();
return true;
}
void TextIteratorTextNodeHandler::ResetCollapsedWhiteSpaceFixup() {
......
......@@ -63,6 +63,9 @@ class TextIteratorTextNodeHandler {
return behavior_.IgnoresStyleVisibility();
}
bool ShouldFixLeadingWhiteSpaceForReplacedElement() const;
// Emit a character before |offset| of characters in |text_node_|.
void SpliceBuffer(UChar,
const Node* text_node,
const Node* offset_base_node,
......
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