Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp b/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp |
| index 4865ae1f326479ae4f5724416bb678f876cd1a63..5a727b27497f60f149dd6bc5f10104408abf017e 100644 |
| --- a/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp |
| +++ b/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp |
| @@ -134,6 +134,32 @@ static EphemeralRange expandRangeToSentenceBoundary( |
| range.endPosition())); |
| } |
| +SelectionInDOMTree selectionFromBaseAndExtent(const VisiblePosition& base, |
|
Xiaocheng
2016/10/21 11:18:36
We should use setBaseAndExtentDeprecated. Though t
yosin_UTC9
2016/10/24 06:19:44
Done.
|
| + const VisiblePosition& extent) { |
| + if (base.isNotNull() && extent.isNotNull()) { |
| + return SelectionInDOMTree::Builder() |
| + .collapse(base.toPositionWithAffinity()) |
| + .extend(extent.deepEquivalent()) |
| + .build(); |
| + } |
| + if (base.isNotNull()) { |
| + return SelectionInDOMTree::Builder() |
| + .collapse(base.toPositionWithAffinity()) |
| + .build(); |
| + } |
| + if (extent.isNotNull()) { |
| + return SelectionInDOMTree::Builder() |
| + .collapse(extent.toPositionWithAffinity()) |
| + .build(); |
| + } |
| + return SelectionInDOMTree(); |
| +} |
| + |
| +SelectionInDOMTree selectWord(const VisiblePosition& position) { |
| + return selectionFromBaseAndExtent(startOfWord(position, LeftWordIfOnBoundary), |
| + endOfWord(position, RightWordIfOnBoundary)); |
| +} |
| + |
| } // namespace |
| SpellChecker* SpellChecker::create(LocalFrame& frame) { |
| @@ -444,8 +470,8 @@ void SpellChecker::markMisspellingsAfterTypingCommand( |
| if (cmd.commandTypeOfOpenCommand() == |
| TypingCommand::InsertParagraphSeparator) { |
| VisiblePosition nextWord = nextWordPosition(start); |
| - VisibleSelection words = |
| - createVisibleSelection(wordStartOfPrevious, endOfWord(nextWord)); |
| + VisibleSelection words = createVisibleSelection( |
| + selectionFromBaseAndExtent(wordStartOfPrevious, endOfWord(nextWord))); |
|
Xiaocheng
2016/10/21 11:18:36
We should use setBaseAndExtentDeprecated.
yosin_UTC9
2016/10/24 06:19:44
Done
|
| markMisspellingsAfterLineBreak(words); |
| return; |
| } |
| @@ -470,8 +496,7 @@ void SpellChecker::markMisspellingsAfterTypingToWord( |
| TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterTypingToWord"); |
| VisibleSelection adjacentWords = |
| - createVisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), |
| - endOfWord(wordStart, RightWordIfOnBoundary)); |
| + createVisibleSelection(selectWord(wordStart)); |
| markMisspellingsAndBadGrammar(adjacentWords); |
| } |
| @@ -868,10 +893,8 @@ void SpellChecker::respondToChangedSelection( |
| HTMLTextFormControlElement::endOfWord(newStart)); |
| } else { |
| if (newSelection.isContentEditable()) { |
| - const VisiblePosition newStart(newSelection.visibleStart()); |
| newAdjacentWords = |
| - createVisibleSelection(startOfWord(newStart, LeftWordIfOnBoundary), |
| - endOfWord(newStart, RightWordIfOnBoundary)); |
| + createVisibleSelection(selectWord(newSelection.visibleStart())); |
| } |
| } |
| @@ -929,8 +952,7 @@ void SpellChecker::spellCheckOldSelection( |
| VisiblePosition oldStart = createVisiblePosition(oldSelectionStart); |
| VisibleSelection oldAdjacentWords = |
| - createVisibleSelection(startOfWord(oldStart, LeftWordIfOnBoundary), |
| - endOfWord(oldStart, RightWordIfOnBoundary)); |
| + createVisibleSelection(selectWord(oldStart)); |
| if (oldAdjacentWords == newAdjacentWords) |
| return; |
| markMisspellingsAndBadGrammar(oldAdjacentWords); |