| 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..98635174eb2951cd69726190b052b851abd725d8 100644
|
| --- a/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp
|
| +++ b/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp
|
| @@ -59,16 +59,15 @@ using namespace HTMLNames;
|
|
|
| namespace {
|
|
|
| -bool isSelectionInTextField(const VisibleSelection& selection) {
|
| +bool isPositionInTextField(const Position& selectionStart) {
|
| HTMLTextFormControlElement* textControl =
|
| - enclosingTextFormControl(selection.start());
|
| + enclosingTextFormControl(selectionStart);
|
| return isHTMLInputElement(textControl) &&
|
| toHTMLInputElement(textControl)->isTextField();
|
| }
|
|
|
| -bool isSelectionInTextArea(const VisibleSelection& selection) {
|
| - HTMLTextFormControlElement* textControl =
|
| - enclosingTextFormControl(selection.start());
|
| +bool isPositionInTextArea(const Position& position) {
|
| + HTMLTextFormControlElement* textControl = enclosingTextFormControl(position);
|
| return isHTMLTextAreaElement(textControl);
|
| }
|
|
|
| @@ -76,25 +75,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 +806,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 (isPositionInTextField(oldSelectionStart))
|
| return false;
|
| - if (isSelectionInTextArea(oldSelection))
|
| + if (isPositionInTextArea(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 +840,7 @@ void SpellChecker::respondToChangedSelection(
|
|
|
| if (!(options & FrameSelection::CloseTyping))
|
| return;
|
| - if (!shouldCheckOldSelection(oldSelection))
|
| + if (!shouldCheckOldSelection(oldSelectionStart))
|
| return;
|
|
|
| // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
|
| @@ -870,7 +873,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 +894,7 @@ void SpellChecker::spellCheckAfterBlur() {
|
| if (!frame().selection().selection().isContentEditable())
|
| return;
|
|
|
| - if (isSelectionInTextField(frame().selection().selection())) {
|
| + if (isPositionInTextField(frame().selection().selection().start())) {
|
| // textFieldDidEndEditing() and textFieldDidBeginEditing() handle this.
|
| return;
|
| }
|
| @@ -906,18 +909,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));
|
|
|