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 6c24e0529cf044c0eb27bf909f68d4b02c6ce4ac..c5d5dca6756c644251e20aab251b61bcebe42e14 100644 |
| --- a/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp |
| +++ b/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp |
| @@ -59,16 +59,16 @@ using namespace HTMLNames; |
| namespace { |
| -bool isSelectionInTextField(const VisibleSelection& selection) { |
| +bool isSelectionInTextField(const Position& selectionStart) { |
|
Xiaocheng
2016/10/19 02:08:58
nit: the function should be better renamed to "isP
yosin_UTC9
2016/10/19 03:55:26
Done
|
| HTMLTextFormControlElement* textControl = |
| - enclosingTextFormControl(selection.start()); |
| + enclosingTextFormControl(selectionStart); |
| return isHTMLInputElement(textControl) && |
| toHTMLInputElement(textControl)->isTextField(); |
| } |
| -bool isSelectionInTextArea(const VisibleSelection& selection) { |
| +bool isSelectionInTextArea(const Position& selectionStart) { |
|
Xiaocheng
2016/10/19 02:08:58
nit: the function should be better renamed to "isP
yosin_UTC9
2016/10/19 03:55:26
Done.
|
| HTMLTextFormControlElement* textControl = |
| - enclosingTextFormControl(selection.start()); |
| + enclosingTextFormControl(selectionStart); |
| return isHTMLTextAreaElement(textControl); |
| } |
| @@ -76,25 +76,31 @@ bool isSelectionInTextFormControl(const VisibleSelection& selection) { |
| return !!enclosingTextFormControl(selection.start()); |
| } |
| -static bool isSpellCheckingEnabledFor(const VisibleSelection& selection) { |
| - if (selection.isNone()) |
| +static bool isSpellCheckingEnabledFor(const Position& position) { |
| + if (position.isNull()) |
| return false; |
| // TODO(tkent): The following password type check should be done in |
| // HTMLElement::spellcheck(). crbug.com/371567 |
| if (HTMLTextFormControlElement* textControl = |
| - enclosingTextFormControl(selection.start())) { |
| + enclosingTextFormControl(position)) { |
| if (isHTMLInputElement(textControl) && |
| toHTMLInputElement(textControl)->type() == InputTypeNames::password) |
| return false; |
| } |
| - if (HTMLElement* element = Traversal<HTMLElement>::firstAncestorOrSelf( |
| - *selection.start().anchorNode())) { |
| + if (HTMLElement* element = |
| + Traversal<HTMLElement>::firstAncestorOrSelf(*position.anchorNode())) { |
| if (element->isSpellCheckingEnabled()) |
| return true; |
| } |
| return false; |
| } |
| +static bool isSpellCheckingEnabledFor(const VisibleSelection& selection) { |
| + if (selection.isNone()) |
| + return false; |
| + return isSpellCheckingEnabledFor(selection.start()); |
| +} |
| + |
| static EphemeralRange expandEndToSentenceBoundary(const EphemeralRange& range) { |
| DCHECK(range.isNotNull()); |
| const VisiblePosition& visibleEnd = |
| @@ -801,30 +807,28 @@ void SpellChecker::replaceMisspelledRange(const String& text) { |
| frame().editor().replaceSelectionWithText(text, false, false); |
| } |
| -static bool shouldCheckOldSelection(const VisibleSelection& oldSelection) { |
| - if (!oldSelection.start().isConnected()) |
| +static bool shouldCheckOldSelection(const Position& oldSelectionStart) { |
| + if (!oldSelectionStart.isConnected()) |
| return false; |
| - if (isSelectionInTextField(oldSelection)) |
| + if (isSelectionInTextField(oldSelectionStart)) |
| return false; |
| - if (isSelectionInTextArea(oldSelection)) |
| + if (isSelectionInTextArea(oldSelectionStart)) |
| return true; |
| // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| // needs to be audited. See http://crbug.com/590369 for more details. |
| // In the long term we should use idle time spell checker to prevent |
| // synchronous layout caused by spell checking (see crbug.com/517298). |
| - oldSelection.start() |
| - .document() |
| - ->updateStyleAndLayoutIgnorePendingStylesheets(); |
| + oldSelectionStart.document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| - return oldSelection.isContentEditable(); |
| + return isEditablePosition(oldSelectionStart); |
| } |
| void SpellChecker::respondToChangedSelection( |
| - const VisibleSelection& oldSelection, |
| + const Position& oldSelectionStart, |
| FrameSelection::SetSelectionOptions options) { |
| TRACE_EVENT0("blink", "SpellChecker::respondToChangedSelection"); |
| - if (!isSpellCheckingEnabledFor(oldSelection)) |
| + if (!isSpellCheckingEnabledFor(oldSelectionStart)) |
| return; |
| // When spell checking is off, existing markers disappear after the selection |
| @@ -837,7 +841,7 @@ void SpellChecker::respondToChangedSelection( |
| if (!(options & FrameSelection::CloseTyping)) |
| return; |
| - if (!shouldCheckOldSelection(oldSelection)) |
| + if (!shouldCheckOldSelection(oldSelectionStart)) |
| return; |
| // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| @@ -870,7 +874,7 @@ void SpellChecker::respondToChangedSelection( |
| // oldSelection may no longer be in the document. |
| // FIXME(http://crbug.com/382809): if oldSelection is on a textarea |
| // element, we cause synchronous layout. |
| - spellCheckOldSelection(oldSelection, newAdjacentWords); |
| + spellCheckOldSelection(oldSelectionStart, newAdjacentWords); |
| } |
| void SpellChecker::removeSpellingMarkers() { |
| @@ -891,7 +895,7 @@ void SpellChecker::spellCheckAfterBlur() { |
| if (!frame().selection().selection().isContentEditable()) |
| return; |
| - if (isSelectionInTextField(frame().selection().selection())) { |
| + if (isSelectionInTextField(frame().selection().selection().start())) { |
| // textFieldDidEndEditing() and textFieldDidBeginEditing() handle this. |
| return; |
| } |
| @@ -906,18 +910,18 @@ void SpellChecker::spellCheckAfterBlur() { |
| frame().document()->lifecycle()); |
| VisibleSelection empty; |
| - spellCheckOldSelection(frame().selection().selection(), empty); |
| + spellCheckOldSelection(frame().selection().selection().start(), empty); |
| } |
| void SpellChecker::spellCheckOldSelection( |
| - const VisibleSelection& oldSelection, |
| + const Position& oldSelectionStart, |
| const VisibleSelection& newAdjacentWords) { |
| if (!isSpellCheckingEnabled()) |
| return; |
| TRACE_EVENT0("blink", "SpellChecker::spellCheckOldSelection"); |
| - VisiblePosition oldStart(oldSelection.visibleStart()); |
| + VisiblePosition oldStart = createVisiblePosition(oldSelectionStart); |
| VisibleSelection oldAdjacentWords = |
| createVisibleSelection(startOfWord(oldStart, LeftWordIfOnBoundary), |
| endOfWord(oldStart, RightWordIfOnBoundary)); |