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,33 +114,51 @@ enum class SelectionMode {
kRange,
kBlockCursor,
};
static SelectionMode ComputeSelectionMode(
const FrameSelection& frame_selection,
const VisibleSelectionInFlatTree& selection) {
if (selection.IsRange())
const FrameSelection& frame_selection) {
const SelectionInDOMTree& selection_in_dom =
frame_selection.GetSelectionInDOMTree();
if (selection_in_dom.IsRange())
return SelectionMode::kRange;
DCHECK(selection_in_dom.IsCaret());
if (!frame_selection.ShouldShowBlockCursor())
return SelectionMode::kNone;
if (IsLogicalEndOfLine(selection.VisibleStart()))
if (IsLogicalEndOfLine(CreateVisiblePosition(selection_in_dom.Base())))
return SelectionMode::kNone;
return SelectionMode::kBlockCursor;
}
static EphemeralRangeInFlatTree CalcSelection(
const FrameSelection& frame_selection) {
const VisibleSelectionInFlatTree& original_selection =
frame_selection.ComputeVisibleSelectionInFlatTree();
switch (ComputeSelectionMode(frame_selection, original_selection)) {
const SelectionInDOMTree& selection_in_dom =
frame_selection.GetSelectionInDOMTree();
switch (ComputeSelectionMode(frame_selection)) {
case SelectionMode::kNone:
return {};
case SelectionMode::kRange:
return {original_selection.Start(), original_selection.End()};
case SelectionMode::kRange: {
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: {
const PositionInFlatTree end_position = NextPositionOf(
original_selection.Start(), PositionMoveType::kGraphemeCluster);
const VisibleSelectionInFlatTree& block_cursor = CreateVisibleSelection(
SelectionInFlatTree::Builder()
.SetBaseAndExtent(original_selection.Start(), end_position)
const PositionInFlatTree& base =
CreateVisiblePosition(ToPositionInFlatTree(selection_in_dom.Base()))
.DeepEquivalent();
const PositionInFlatTree end_position =
NextPositionOf(base, PositionMoveType::kGraphemeCluster);
const VisibleSelectionInFlatTree& block_cursor =
CreateVisibleSelection(SelectionInFlatTree::Builder()
.SetBaseAndExtent(base, end_position)
.Build());
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