Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Unified Diff: third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp

Issue 2424383002: Make SpellChecker::respondToChangedSelection() to take Position instead of VisibleSelection (Closed)
Patch Set: 2016-10-19T12:54:03 Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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));

Powered by Google App Engine
This is Rietveld 408576698