Commit a1cb0a9d authored by Yoichi Osato's avatar Yoichi Osato Committed by Commit Bot

Replace VisibleSelection in Layoutselection::CalcSelection with VisiblePosition

This is preparation to split LayoutSelection start/end calculation w/o 
canonicalization.
This CL also fixes issue that Selection API consider editable boundary incorrectly

Bug: 739062
Change-Id: I84623287faebcb3bc5c497abf1d9560a54f5d751
Reviewed-on: https://chromium-review.googlesource.com/566208Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Yoichi Osato <yoichio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485920}
parent 5f72b7fb
...@@ -114,34 +114,52 @@ enum class SelectionMode { ...@@ -114,34 +114,52 @@ enum class SelectionMode {
kRange, kRange,
kBlockCursor, kBlockCursor,
}; };
static SelectionMode ComputeSelectionMode( static SelectionMode ComputeSelectionMode(
const FrameSelection& frame_selection, const FrameSelection& frame_selection) {
const VisibleSelectionInFlatTree& selection) { const SelectionInDOMTree& selection_in_dom =
if (selection.IsRange()) frame_selection.GetSelectionInDOMTree();
if (selection_in_dom.IsRange())
return SelectionMode::kRange; return SelectionMode::kRange;
DCHECK(selection_in_dom.IsCaret());
if (!frame_selection.ShouldShowBlockCursor()) if (!frame_selection.ShouldShowBlockCursor())
return SelectionMode::kNone; return SelectionMode::kNone;
if (IsLogicalEndOfLine(selection.VisibleStart())) if (IsLogicalEndOfLine(CreateVisiblePosition(selection_in_dom.Base())))
return SelectionMode::kNone; return SelectionMode::kNone;
return SelectionMode::kBlockCursor; return SelectionMode::kBlockCursor;
} }
static EphemeralRangeInFlatTree CalcSelection( static EphemeralRangeInFlatTree CalcSelection(
const FrameSelection& frame_selection) { const FrameSelection& frame_selection) {
const VisibleSelectionInFlatTree& original_selection = const SelectionInDOMTree& selection_in_dom =
frame_selection.ComputeVisibleSelectionInFlatTree(); frame_selection.GetSelectionInDOMTree();
switch (ComputeSelectionMode(frame_selection, original_selection)) { switch (ComputeSelectionMode(frame_selection)) {
case SelectionMode::kNone: case SelectionMode::kNone:
return {}; return {};
case SelectionMode::kRange: case SelectionMode::kRange: {
return {original_selection.Start(), original_selection.End()}; const PositionInFlatTree& base =
CreateVisiblePosition(ToPositionInFlatTree(selection_in_dom.Base()))
.DeepEquivalent();
const PositionInFlatTree& extent =
CreateVisiblePosition(ToPositionInFlatTree(selection_in_dom.Extent()))
.DeepEquivalent();
if (base.IsNull() || extent.IsNull() || base == extent)
return {};
const bool base_is_first = base.CompareTo(extent) <= 0;
const PositionInFlatTree& start = base_is_first ? base : extent;
const PositionInFlatTree& end = base_is_first ? extent : base;
return {MostForwardCaretPosition(start), MostBackwardCaretPosition(end)};
}
case SelectionMode::kBlockCursor: { case SelectionMode::kBlockCursor: {
const PositionInFlatTree end_position = NextPositionOf( const PositionInFlatTree& base =
original_selection.Start(), PositionMoveType::kGraphemeCluster); CreateVisiblePosition(ToPositionInFlatTree(selection_in_dom.Base()))
const VisibleSelectionInFlatTree& block_cursor = CreateVisibleSelection( .DeepEquivalent();
SelectionInFlatTree::Builder() const PositionInFlatTree end_position =
.SetBaseAndExtent(original_selection.Start(), end_position) NextPositionOf(base, PositionMoveType::kGraphemeCluster);
.Build()); const VisibleSelectionInFlatTree& block_cursor =
CreateVisibleSelection(SelectionInFlatTree::Builder()
.SetBaseAndExtent(base, end_position)
.Build());
return {block_cursor.Start(), block_cursor.End()}; return {block_cursor.Start(), block_cursor.End()};
} }
} }
......
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