Commit 0a7509de authored by yoichio's avatar yoichio Committed by Commit Bot

Use LayoutSelection::SelectionStart()/End() instead of SelectionStartEnd in InlineTextBox.

Since integers returned by SelectionStartEnd() don't relate 
each other except start LayoutObject == end LayoutObject.
To emphasize that for readability, we should split SelectionStartEnd
 to each SelectionStart and SelectionEnd.

Bug: 739062
Change-Id: Iacb552ea21ea36fc1769d295eaaadec59b8b20b4
Reviewed-on: https://chromium-review.googlesource.com/577986Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Commit-Queue: Yoichi Osato <yoichio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488585}
parent 6edea8b7
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
#include "core/layout/line/InlineTextBox.h" #include "core/layout/line/InlineTextBox.h"
#include "core/dom/Document.h"
#include "core/editing/FrameSelection.h"
#include "core/frame/LocalFrame.h"
#include "core/layout/HitTestResult.h" #include "core/layout/HitTestResult.h"
#include "core/layout/api/LineLayoutBR.h" #include "core/layout/api/LineLayoutBR.h"
#include "core/layout/api/LineLayoutBox.h" #include "core/layout/api/LineLayoutBox.h"
...@@ -175,8 +178,6 @@ SelectionState InlineTextBox::GetSelectionState() const { ...@@ -175,8 +178,6 @@ SelectionState InlineTextBox::GetSelectionState() const {
SelectionState state = GetLineLayoutItem().GetSelectionState(); SelectionState state = GetLineLayoutItem().GetSelectionState();
if (state == SelectionState::kStart || state == SelectionState::kEnd || if (state == SelectionState::kStart || state == SelectionState::kEnd ||
state == SelectionState::kStartAndEnd) { state == SelectionState::kStartAndEnd) {
int start_pos, end_pos;
std::tie(start_pos, end_pos) = GetLineLayoutItem().SelectionStartEnd();
// The position after a hard line break is considered to be past its end. // The position after a hard line break is considered to be past its end.
// See the corresponding code in InlineTextBox::isSelected. // See the corresponding code in InlineTextBox::isSelected.
int last_selectable = Start() + Len() - (IsLineBreak() ? 1 : 0); int last_selectable = Start() + Len() - (IsLineBreak() ? 1 : 0);
...@@ -187,19 +188,26 @@ SelectionState InlineTextBox::GetSelectionState() const { ...@@ -187,19 +188,26 @@ SelectionState InlineTextBox::GetSelectionState() const {
LineBreak::kAfterWhiteSpace LineBreak::kAfterWhiteSpace
? -1 ? -1
: 0; : 0;
bool start = (state != SelectionState::kEnd && start_pos >= start_ && const FrameSelection& selection =
start_pos <= start_ + len_ + GetLineLayoutItem().GetDocument().GetFrame()->Selection();
end_of_line_adjustment_for_css_line_break); bool start =
bool end = (state != SelectionState::kStart && end_pos > start_ && (state != SelectionState::kEnd &&
end_pos <= last_selectable); selection.LayoutSelectionStart().value() >= start_ &&
selection.LayoutSelectionStart().value() <=
start_ + len_ + end_of_line_adjustment_for_css_line_break);
bool end = (state != SelectionState::kStart &&
selection.LayoutSelectionEnd().value() > start_ &&
selection.LayoutSelectionEnd().value() <= last_selectable);
if (start && end) if (start && end)
state = SelectionState::kStartAndEnd; state = SelectionState::kStartAndEnd;
else if (start) else if (start)
state = SelectionState::kStart; state = SelectionState::kStart;
else if (end) else if (end)
state = SelectionState::kEnd; state = SelectionState::kEnd;
else if ((state == SelectionState::kEnd || start_pos < start_) && else if ((state == SelectionState::kEnd ||
(state == SelectionState::kStart || end_pos > last_selectable)) selection.LayoutSelectionStart().value() < start_) &&
(state == SelectionState::kStart ||
selection.LayoutSelectionEnd().value() > last_selectable))
state = SelectionState::kInside; state = SelectionState::kInside;
else if (state == SelectionState::kStartAndEnd) else if (state == SelectionState::kStartAndEnd)
state = SelectionState::kNone; state = SelectionState::kNone;
...@@ -532,11 +540,21 @@ void InlineTextBox::SelectionStartEnd(int& s_pos, int& e_pos) const { ...@@ -532,11 +540,21 @@ void InlineTextBox::SelectionStartEnd(int& s_pos, int& e_pos) const {
start_pos = 0; start_pos = 0;
end_pos = GetLineLayoutItem().TextLength(); end_pos = GetLineLayoutItem().TextLength();
} else { } else {
std::tie(start_pos, end_pos) = GetLineLayoutItem().SelectionStartEnd(); const FrameSelection& selection =
if (GetLineLayoutItem().GetSelectionState() == SelectionState::kStart) GetLineLayoutItem().GetDocument().GetFrame()->Selection();
if (GetLineLayoutItem().GetSelectionState() == SelectionState::kStart) {
start_pos = selection.LayoutSelectionStart().value();
end_pos = GetLineLayoutItem().TextLength(); end_pos = GetLineLayoutItem().TextLength();
else if (GetLineLayoutItem().GetSelectionState() == SelectionState::kEnd) } else if (GetLineLayoutItem().GetSelectionState() ==
SelectionState::kEnd) {
start_pos = 0; start_pos = 0;
end_pos = selection.LayoutSelectionEnd().value();
} else {
DCHECK(GetLineLayoutItem().GetSelectionState() ==
SelectionState::kStartAndEnd);
start_pos = selection.LayoutSelectionStart().value();
end_pos = selection.LayoutSelectionEnd().value();
}
} }
s_pos = std::max(start_pos - start_, 0); s_pos = std::max(start_pos - start_, 0);
......
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