Commit e6b12333 authored by yoichio's avatar yoichio Committed by Commit Bot

Introduce LayoutSelection::SelectionStart()/End() to TouchAdjustment.

Since integers returned by SelectionStartEnd() don't relate 
each other if start LayoutObject != end LayoutObject.
To emphasize that for readability, we should split it.

Bug: 739062
Change-Id: I9609262fe2aeb63a49fa95a4d17de66c167d92f8
Reviewed-on: https://chromium-review.googlesource.com/566268
Commit-Queue: Yoichi Osato <yoichio@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486695}
parent 47449c20
...@@ -1163,6 +1163,13 @@ std::pair<int, int> FrameSelection::LayoutSelectionStartEnd() { ...@@ -1163,6 +1163,13 @@ std::pair<int, int> FrameSelection::LayoutSelectionStartEnd() {
return layout_selection_->SelectionStartEnd(); return layout_selection_->SelectionStartEnd();
} }
base::Optional<int> FrameSelection::LayoutSelectionStart() const {
return layout_selection_->SelectionStart();
}
base::Optional<int> FrameSelection::LayoutSelectionEnd() const {
return layout_selection_->SelectionEnd();
}
void FrameSelection::ClearLayoutSelection() { void FrameSelection::ClearLayoutSelection() {
layout_selection_->ClearSelection(); layout_selection_->ClearSelection();
} }
......
...@@ -244,6 +244,8 @@ class CORE_EXPORT FrameSelection final ...@@ -244,6 +244,8 @@ class CORE_EXPORT FrameSelection final
FrameCaret& FrameCaretForTesting() const { return *frame_caret_; } FrameCaret& FrameCaretForTesting() const { return *frame_caret_; }
std::pair<int, int> LayoutSelectionStartEnd(); std::pair<int, int> LayoutSelectionStartEnd();
base::Optional<int> LayoutSelectionStart() const;
base::Optional<int> LayoutSelectionEnd() const;
void ClearLayoutSelection(); void ClearLayoutSelection();
DECLARE_TRACE(); DECLARE_TRACE();
......
...@@ -297,6 +297,20 @@ std::pair<int, int> LayoutSelection::SelectionStartEnd() { ...@@ -297,6 +297,20 @@ std::pair<int, int> LayoutSelection::SelectionStartEnd() {
return std::make_pair(paint_range_.StartOffset(), paint_range_.EndOffset()); return std::make_pair(paint_range_.StartOffset(), paint_range_.EndOffset());
} }
base::Optional<int> LayoutSelection::SelectionStart() const {
DCHECK(!HasPendingSelection());
if (paint_range_.IsNull())
return {};
return paint_range_.StartOffset();
}
base::Optional<int> LayoutSelection::SelectionEnd() const {
DCHECK(!HasPendingSelection());
if (paint_range_.IsNull())
return {};
return paint_range_.EndOffset();
}
void LayoutSelection::ClearSelection() { void LayoutSelection::ClearSelection() {
// For querying Layer::compositingState() // For querying Layer::compositingState()
// This is correct, since destroying layout objects needs to cause eager paint // This is correct, since destroying layout objects needs to cause eager paint
......
...@@ -100,7 +100,10 @@ class LayoutSelection final : public GarbageCollected<LayoutSelection> { ...@@ -100,7 +100,10 @@ class LayoutSelection final : public GarbageCollected<LayoutSelection> {
void InvalidatePaintForSelection(); void InvalidatePaintForSelection();
void ClearSelection(); void ClearSelection();
// TODO(yoiciho): Replace SelectionStartEnd with SelectionStart/End.
std::pair<int, int> SelectionStartEnd(); std::pair<int, int> SelectionStartEnd();
base::Optional<int> SelectionStart() const;
base::Optional<int> SelectionEnd() const;
void OnDocumentShutdown(); void OnDocumentShutdown();
DECLARE_TRACE(); DECLARE_TRACE();
......
...@@ -204,6 +204,8 @@ static inline void AppendContextSubtargetsForNode( ...@@ -204,6 +204,8 @@ static inline void AppendContextSubtargetsForNode(
} else { } else {
if (text_layout_object->GetSelectionState() == SelectionState::kNone) if (text_layout_object->GetSelectionState() == SelectionState::kNone)
return AppendBasicSubtargetsForNode(node, subtargets); return AppendBasicSubtargetsForNode(node, subtargets);
const FrameSelection& frame_selection =
text_layout_object->GetFrame()->Selection();
// If selected, make subtargets out of only the selected part of the text. // If selected, make subtargets out of only the selected part of the text.
int start_pos, end_pos; int start_pos, end_pos;
switch (text_layout_object->GetSelectionState()) { switch (text_layout_object->GetSelectionState()) {
...@@ -212,15 +214,16 @@ static inline void AppendContextSubtargetsForNode( ...@@ -212,15 +214,16 @@ static inline void AppendContextSubtargetsForNode(
end_pos = text_layout_object->TextLength(); end_pos = text_layout_object->TextLength();
break; break;
case SelectionState::kStart: case SelectionState::kStart:
std::tie(start_pos, end_pos) = text_layout_object->SelectionStartEnd(); start_pos = frame_selection.LayoutSelectionStart().value();
end_pos = text_layout_object->TextLength(); end_pos = text_layout_object->TextLength();
break; break;
case SelectionState::kEnd: case SelectionState::kEnd:
std::tie(start_pos, end_pos) = text_layout_object->SelectionStartEnd();
start_pos = 0; start_pos = 0;
end_pos = frame_selection.LayoutSelectionEnd().value();
break; break;
case SelectionState::kStartAndEnd: case SelectionState::kStartAndEnd:
std::tie(start_pos, end_pos) = text_layout_object->SelectionStartEnd(); start_pos = frame_selection.LayoutSelectionStart().value();
end_pos = frame_selection.LayoutSelectionEnd().value();
break; break;
default: default:
NOTREACHED(); NOTREACHED();
......
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