Commit 404ec376 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Stop using VisiblePosition in FrameSelection::SelectWordAroundCaret

This patch changes FrameSelection::SelectWordAroundCaret to use
VisiblePosition-free versions of word boundary algorithms to reduce
usage of VisiblePosition.

Bug: 657237
Change-Id: I1605f77a86332fa20caa7966454fbf1307c10cea
Reviewed-on: https://chromium-review.googlesource.com/c/1330752
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608089}
parent 7488f368
...@@ -1085,33 +1085,34 @@ bool FrameSelection::SelectWordAroundCaret() { ...@@ -1085,33 +1085,34 @@ bool FrameSelection::SelectWordAroundCaret() {
// http://crbug.com/657237 for more details. // http://crbug.com/657237 for more details.
if (!selection.IsCaret()) if (!selection.IsCaret())
return false; return false;
const VisiblePosition& position = selection.VisibleStart(); const Position position = selection.Start();
static const EWordSide kWordSideList[2] = {kNextWordIfOnBoundary, static const EWordSide kWordSideList[2] = {kNextWordIfOnBoundary,
kPreviousWordIfOnBoundary}; kPreviousWordIfOnBoundary};
for (EWordSide word_side : kWordSideList) { for (EWordSide word_side : kWordSideList) {
// TODO(yoichio): We should have Position version of |start/endOfWord| Position start = StartOfWordPosition(position, word_side);
// for avoiding unnecessary canonicalization. Position end = EndOfWordPosition(position, word_side);
VisiblePosition start = StartOfWord(position, word_side);
VisiblePosition end = EndOfWord(position, word_side);
// TODO(editing-dev): |StartOfWord()| and |EndOfWord()| should not make null // TODO(editing-dev): |StartOfWord()| and |EndOfWord()| should not make null
// for non-null parameter. // for non-null parameter.
// See http://crbug.com/872443 // See http://crbug.com/872443
if (start.DeepEquivalent().IsNull() || end.DeepEquivalent().IsNull()) if (start.IsNull() || end.IsNull())
continue; continue;
String text = if (start > end) {
PlainText(EphemeralRange(start.DeepEquivalent(), end.DeepEquivalent())); // Since word boundaries are computed on flat tree, they can be reversed
// when mapped back to DOM.
std::swap(start, end);
}
String text = PlainText(EphemeralRange(start, end));
if (!text.IsEmpty() && !IsSeparator(text.CharacterStartingAt(0))) { if (!text.IsEmpty() && !IsSeparator(text.CharacterStartingAt(0))) {
SetSelection(SelectionInDOMTree::Builder() SetSelection(
.Collapse(start.ToPositionWithAffinity()) SelectionInDOMTree::Builder().Collapse(start).Extend(end).Build(),
.Extend(end.DeepEquivalent()) SetSelectionOptions::Builder()
.Build(), .SetShouldCloseTyping(true)
SetSelectionOptions::Builder() .SetShouldClearTypingStyle(true)
.SetShouldCloseTyping(true) .SetGranularity(TextGranularity::kWord)
.SetShouldClearTypingStyle(true) .Build());
.SetGranularity(TextGranularity::kWord)
.Build());
return true; return true;
} }
} }
......
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