Commit 23eeef21 authored by Yoichi Osato's avatar Yoichi Osato Committed by Commit Bot

Refactor SelectionTypeAdjuster.

This patch expands ComputeSelectionType at call site
because if selection is none can be caught more early and
logic is now simple.

Change-Id: I6d5c7a7279097fbe0312d29cbf009d7424ff519b
Reviewed-on: https://chromium-review.googlesource.com/1051211
Commit-Queue: Yoichi Osato <yoichio@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557139}
parent 7e4434e5
...@@ -773,16 +773,19 @@ class SelectionTypeAdjuster final { ...@@ -773,16 +773,19 @@ class SelectionTypeAdjuster final {
template <typename Strategy> template <typename Strategy>
static SelectionTemplate<Strategy> AdjustSelection( static SelectionTemplate<Strategy> AdjustSelection(
const SelectionTemplate<Strategy>& selection) { const SelectionTemplate<Strategy>& selection) {
if (selection.IsNone())
return selection;
const EphemeralRangeTemplate<Strategy>& range = selection.ComputeRange(); const EphemeralRangeTemplate<Strategy>& range = selection.ComputeRange();
const SelectionType selection_type = ComputeSelectionType(range); DCHECK(!NeedsLayoutTreeUpdate(range.StartPosition())) << range;
if (selection_type == kCaretSelection) { if (range.IsCollapsed() ||
// TODO(editing-dev): Consider this canonicalization is really needed.
MostBackwardCaretPosition(range.StartPosition()) ==
MostBackwardCaretPosition(range.EndPosition())) {
return typename SelectionTemplate<Strategy>::Builder() return typename SelectionTemplate<Strategy>::Builder()
.Collapse(PositionWithAffinityTemplate<Strategy>( .Collapse(PositionWithAffinityTemplate<Strategy>(
range.StartPosition(), selection.Affinity())) range.StartPosition(), selection.Affinity()))
.Build(); .Build();
} }
DCHECK_EQ(selection_type, kRangeSelection);
// "Constrain" the selection to be the smallest equivalent range of // "Constrain" the selection to be the smallest equivalent range of
// nodes. This is a somewhat arbitrary choice, but experience shows that // nodes. This is a somewhat arbitrary choice, but experience shows that
// it is useful to make to make the selection "canonical" (if only for // it is useful to make to make the selection "canonical" (if only for
...@@ -802,22 +805,6 @@ class SelectionTypeAdjuster final { ...@@ -802,22 +805,6 @@ class SelectionTypeAdjuster final {
.SetAsBackwardSelection(minimal_range) .SetAsBackwardSelection(minimal_range)
.Build(); .Build();
} }
private:
template <typename Strategy>
static SelectionType ComputeSelectionType(
const EphemeralRangeTemplate<Strategy>& range) {
if (range.IsNull())
return kNoSelection;
DCHECK(!NeedsLayoutTreeUpdate(range.StartPosition())) << range;
if (range.IsCollapsed())
return kCaretSelection;
// TODO(editing-dev): Consider this canonicalization is really needed.
if (MostBackwardCaretPosition(range.StartPosition()) ==
MostBackwardCaretPosition(range.EndPosition()))
return kCaretSelection;
return kRangeSelection;
}
}; };
SelectionInDOMTree SelectionAdjuster::AdjustSelectionType( SelectionInDOMTree SelectionAdjuster::AdjustSelectionType(
......
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