Commit 686d2e68 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Stop using VisiblePosition in SkipToStart/EndOfEditingBoundary

This patch stops passing VisiblePosition to the functions, and hoists
creation of VisiblePosition to the callers, to decrease the usage of
VisiblePosition.

This is a preparation for a VP-free version of Previous/NextPositionOf()

Bug: 657237
Change-Id: I46fe45f9c28458e1dbffddf26b106372ff433fd1
Reviewed-on: https://chromium-review.googlesource.com/c/1309142Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604146}
parent 2be6c3e2
...@@ -1053,16 +1053,14 @@ bool IsVisuallyEquivalentCandidate(const PositionInFlatTree& position) { ...@@ -1053,16 +1053,14 @@ bool IsVisuallyEquivalentCandidate(const PositionInFlatTree& position) {
} }
template <typename Strategy> template <typename Strategy>
static VisiblePositionTemplate<Strategy> SkipToEndOfEditingBoundary( static PositionTemplate<Strategy> SkipToEndOfEditingBoundary(
const VisiblePositionTemplate<Strategy>& pos, const PositionTemplate<Strategy>& pos,
const PositionTemplate<Strategy>& anchor) { const PositionTemplate<Strategy>& anchor) {
DCHECK(pos.IsValid()) << pos;
if (pos.IsNull()) if (pos.IsNull())
return pos; return pos;
ContainerNode* highest_root = HighestEditableRoot(anchor); ContainerNode* highest_root = HighestEditableRoot(anchor);
ContainerNode* highest_root_of_pos = ContainerNode* highest_root_of_pos = HighestEditableRoot(pos);
HighestEditableRoot(pos.DeepEquivalent());
// Return |pos| itself if the two are from the very same editable region, // Return |pos| itself if the two are from the very same editable region,
// or both are non-editable. // or both are non-editable.
...@@ -1070,17 +1068,16 @@ static VisiblePositionTemplate<Strategy> SkipToEndOfEditingBoundary( ...@@ -1070,17 +1068,16 @@ static VisiblePositionTemplate<Strategy> SkipToEndOfEditingBoundary(
return pos; return pos;
// If this is not editable but |pos| has an editable root, skip to the end // If this is not editable but |pos| has an editable root, skip to the end
if (!highest_root && highest_root_of_pos) if (!highest_root && highest_root_of_pos) {
return CreateVisiblePosition( return PositionTemplate<Strategy>(highest_root_of_pos,
PositionTemplate<Strategy>(highest_root_of_pos, PositionAnchorType::kAfterAnchor)
PositionAnchorType::kAfterAnchor) .ParentAnchoredEquivalent();
.ParentAnchoredEquivalent()); }
// That must mean that |pos| is not editable. Return the next position after // That must mean that |pos| is not editable. Return the next position after
// |pos| that is in the same editable region as this position // |pos| that is in the same editable region as this position
DCHECK(highest_root); DCHECK(highest_root);
return CreateVisiblePosition(FirstEditablePositionAfterPositionInRoot( return FirstEditablePositionAfterPositionInRoot(pos, *highest_root);
pos.DeepEquivalent(), *highest_root));
} }
template <typename Strategy> template <typename Strategy>
...@@ -1144,7 +1141,8 @@ static VisiblePositionTemplate<Strategy> NextPositionOfAlgorithm( ...@@ -1144,7 +1141,8 @@ static VisiblePositionTemplate<Strategy> NextPositionOfAlgorithm(
return AdjustForwardPositionToAvoidCrossingEditingBoundaries( return AdjustForwardPositionToAvoidCrossingEditingBoundaries(
next, position.GetPosition()); next, position.GetPosition());
case kCanSkipOverEditingBoundary: case kCanSkipOverEditingBoundary:
return SkipToEndOfEditingBoundary(next, position.GetPosition()); return CreateVisiblePosition(SkipToEndOfEditingBoundary(
next.DeepEquivalent(), position.GetPosition()));
} }
NOTREACHED(); NOTREACHED();
return AdjustForwardPositionToAvoidCrossingEditingBoundaries( return AdjustForwardPositionToAvoidCrossingEditingBoundaries(
...@@ -1167,16 +1165,14 @@ VisiblePositionInFlatTree NextPositionOf( ...@@ -1167,16 +1165,14 @@ VisiblePositionInFlatTree NextPositionOf(
} }
template <typename Strategy> template <typename Strategy>
static VisiblePositionTemplate<Strategy> SkipToStartOfEditingBoundary( static PositionTemplate<Strategy> SkipToStartOfEditingBoundary(
const VisiblePositionTemplate<Strategy>& pos, const PositionTemplate<Strategy>& pos,
const PositionTemplate<Strategy>& anchor) { const PositionTemplate<Strategy>& anchor) {
DCHECK(pos.IsValid()) << pos;
if (pos.IsNull()) if (pos.IsNull())
return pos; return pos;
ContainerNode* highest_root = HighestEditableRoot(anchor); ContainerNode* highest_root = HighestEditableRoot(anchor);
ContainerNode* highest_root_of_pos = ContainerNode* highest_root_of_pos = HighestEditableRoot(pos);
HighestEditableRoot(pos.DeepEquivalent());
// Return |pos| itself if the two are from the very same editable region, or // Return |pos| itself if the two are from the very same editable region, or
// both are non-editable. // both are non-editable.
...@@ -1184,17 +1180,17 @@ static VisiblePositionTemplate<Strategy> SkipToStartOfEditingBoundary( ...@@ -1184,17 +1180,17 @@ static VisiblePositionTemplate<Strategy> SkipToStartOfEditingBoundary(
return pos; return pos;
// If this is not editable but |pos| has an editable root, skip to the start // If this is not editable but |pos| has an editable root, skip to the start
if (!highest_root && highest_root_of_pos) if (!highest_root && highest_root_of_pos) {
return CreateVisiblePosition(PreviousVisuallyDistinctCandidate( return PreviousVisuallyDistinctCandidate(
PositionTemplate<Strategy>(highest_root_of_pos, PositionTemplate<Strategy>(highest_root_of_pos,
PositionAnchorType::kBeforeAnchor) PositionAnchorType::kBeforeAnchor)
.ParentAnchoredEquivalent())); .ParentAnchoredEquivalent());
}
// That must mean that |pos| is not editable. Return the last position // That must mean that |pos| is not editable. Return the last position
// before |pos| that is in the same editable region as this position // before |pos| that is in the same editable region as this position
DCHECK(highest_root); DCHECK(highest_root);
return CreateVisiblePosition(LastEditablePositionBeforePositionInRoot( return LastEditablePositionBeforePositionInRoot(pos, *highest_root);
pos.DeepEquivalent(), *highest_root));
} }
template <typename Strategy> template <typename Strategy>
...@@ -1224,7 +1220,8 @@ static VisiblePositionTemplate<Strategy> PreviousPositionOfAlgorithm( ...@@ -1224,7 +1220,8 @@ static VisiblePositionTemplate<Strategy> PreviousPositionOfAlgorithm(
return AdjustBackwardPositionToAvoidCrossingEditingBoundaries(prev, return AdjustBackwardPositionToAvoidCrossingEditingBoundaries(prev,
position); position);
case kCanSkipOverEditingBoundary: case kCanSkipOverEditingBoundary:
return SkipToStartOfEditingBoundary(prev, position); return CreateVisiblePosition(
SkipToStartOfEditingBoundary(prev.DeepEquivalent(), position));
} }
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