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

Unified Diff: Source/core/editing/SpellChecker.cpp

Issue 357603003: Add functions searching a word boundary without VisualPosition to HTMLTextFormControlElement. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update Created 6 years, 6 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: Source/core/editing/SpellChecker.cpp
diff --git a/Source/core/editing/SpellChecker.cpp b/Source/core/editing/SpellChecker.cpp
index 43229a7769168f70ac1ce583e5ba4ec9a7267025..197dc67527c17574ec4f0e2704698e9b9b9194b4 100644
--- a/Source/core/editing/SpellChecker.cpp
+++ b/Source/core/editing/SpellChecker.cpp
@@ -58,6 +58,17 @@ bool isSelectionInTextField(const VisibleSelection& selection)
return isHTMLInputElement(textControl) && toHTMLInputElement(textControl)->isTextField();
}
+bool isSelectionInTextArea(const VisibleSelection& selection)
+{
+ HTMLTextFormControlElement* textControl = enclosingTextFormControl(selection.start());
+ return isHTMLTextAreaElement(textControl);
+}
+
+bool isSelectionInTextForm(const VisibleSelection& selection)
yosin_UTC9 2014/07/02 09:44:03 nit: It is better to call |isSelectionInTextFormCo
+{
+ return !!enclosingTextFormControl(selection.start());
+}
+
} // namespace
PassOwnPtr<SpellChecker> SpellChecker::create(LocalFrame& frame)
@@ -759,8 +770,14 @@ void SpellChecker::respondToChangedSelection(const VisibleSelection& oldSelectio
VisibleSelection newAdjacentWords;
VisibleSelection newSelectedSentence;
bool caretBrowsing = m_frame.settings() && m_frame.settings()->caretBrowsingEnabled();
- if (m_frame.selection().selection().isContentEditable() || caretBrowsing) {
- VisiblePosition newStart(m_frame.selection().selection().visibleStart());
+ const VisibleSelection newSelection = m_frame.selection().selection();
+ if (isSelectionInTextForm(newSelection)) {
+ Position newStart = newSelection.start();
+ newAdjacentWords.setWithoutValidation(HTMLTextFormControlElement::startOfWord(newStart), HTMLTextFormControlElement::endOfWord(newStart));
+ if (isContinuousGrammarCheckingEnabled)
+ newSelectedSentence.setWithoutValidation(HTMLTextFormControlElement::startOfSentence(newStart), HTMLTextFormControlElement::endOfSentence(newStart));
+ } else if (newSelection.isContentEditable() || caretBrowsing) {
+ VisiblePosition newStart(newSelection.visibleStart());
newAdjacentWords = VisibleSelection(startOfWord(newStart, LeftWordIfOnBoundary), endOfWord(newStart, RightWordIfOnBoundary));
if (isContinuousGrammarCheckingEnabled)
newSelectedSentence = VisibleSelection(startOfSentence(newStart), endOfSentence(newStart));
@@ -774,9 +791,9 @@ void SpellChecker::respondToChangedSelection(const VisibleSelection& oldSelectio
// oldSelection may no longer be in the document.
if (shouldCheckSpellingAndGrammar
&& closeTyping
- && oldSelection.isContentEditable()
- && oldSelection.start().inDocument()
- && !isSelectionInTextField(oldSelection)) {
+ && !isSelectionInTextField(oldSelection)
+ && (isSelectionInTextArea(oldSelection) || oldSelection.isContentEditable())
+ && oldSelection.start().inDocument()) {
spellCheckOldSelection(oldSelection, newAdjacentWords);
}
« no previous file with comments | « no previous file | Source/core/html/HTMLTextFormControlElement.h » ('j') | Source/core/html/HTMLTextFormControlElement.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698