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

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

Issue 21024004: Add/remove spell checking markers in text inputs depending on focus. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Clean up in the test & the new expected file. Created 7 years, 5 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
« no previous file with comments | « Source/core/editing/Editor.h ('k') | Source/core/editing/SpellChecker.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/Editor.cpp
diff --git a/Source/core/editing/Editor.cpp b/Source/core/editing/Editor.cpp
index 9bbc1f14ce565e3967f4f96271cb57016a02d0d6..a8f90e5047e66bfd74cd8db6aa1178ca50687336 100644
--- a/Source/core/editing/Editor.cpp
+++ b/Source/core/editing/Editor.cpp
@@ -62,6 +62,7 @@
#include "core/editing/htmlediting.h"
#include "core/editing/markup.h"
#include "core/html/HTMLImageElement.h"
+#include "core/html/HTMLInputElement.h"
#include "core/html/HTMLTextAreaElement.h"
#include "core/loader/cache/ResourceFetcher.h"
#include "core/page/EditorClient.h"
@@ -87,6 +88,16 @@ using namespace HTMLNames;
using namespace WTF;
using namespace Unicode;
+namespace {
+
+bool isSelectionInTextField(const VisibleSelection& selection)
+{
+ HTMLTextFormControlElement* textControl = enclosingTextFormControl(selection.start());
+ return textControl && textControl->hasTagName(inputTag) && toHTMLInputElement(textControl)->isTextField();
+}
+
+} // namespace
+
// When an event handler has moved the selection outside of a text control
// we should use the target control's selection for this editing operation.
VisibleSelection Editor::selectionForCommand(Event* event)
@@ -2075,8 +2086,30 @@ void Editor::computeAndSetTypingStyle(StylePropertySet* style, EditAction editin
m_frame->selection()->setTypingStyle(typingStyle);
}
+
+void Editor::textFieldDidBeginEditing(Element* e)
+{
+ if (isContinuousSpellCheckingEnabled()) {
+ Element* element = toHTMLTextFormControlElement(e)->innerTextElement();
+ VisibleSelection selection = VisibleSelection::selectionFromContentsOfNode(element);
+ markMisspellingsAndBadGrammar(selection);
+ }
+}
+
void Editor::textFieldDidEndEditing(Element* e)
{
+ // Remove markers when deactivating a selection in an <input type="text"/>.
+ // Prevent new ones from appearing too.
+ m_spellChecker->cancelCheck();
+ HTMLTextFormControlElement* textFormControlElement = toHTMLTextFormControlElement(e);
+ HTMLElement* innerText = textFormControlElement->innerTextElement();
+ DocumentMarker::MarkerTypes markerTypes(DocumentMarker::Spelling);
+ if (isGrammarCheckingEnabled() || unifiedTextCheckerEnabled())
+ markerTypes.add(DocumentMarker::Grammar);
+ for (Node* node = innerText; node; node = NodeTraversal::next(node, innerText)) {
+ m_frame->document()->markers()->removeMarkers(node, markerTypes);
+ }
+
if (client())
client()->textFieldDidEndEditing(e);
}
@@ -2252,7 +2285,12 @@ void Editor::respondToChangedSelection(const VisibleSelection& oldSelection, Fra
// When typing we check spelling elsewhere, so don't redo it here.
// If this is a change in selection resulting from a delete operation,
// oldSelection may no longer be in the document.
- if (shouldCheckSpellingAndGrammar && closeTyping && oldSelection.isContentEditable() && oldSelection.start().deprecatedNode() && oldSelection.start().anchorNode()->inDocument()) {
+ if (shouldCheckSpellingAndGrammar
+ && closeTyping
+ && oldSelection.isContentEditable()
+ && oldSelection.start().deprecatedNode()
+ && oldSelection.start().anchorNode()->inDocument()
+ && !isSelectionInTextField(oldSelection)) {
VisiblePosition oldStart(oldSelection.visibleStart());
VisibleSelection oldAdjacentWords = VisibleSelection(startOfWord(oldStart, LeftWordIfOnBoundary), endOfWord(oldStart, RightWordIfOnBoundary));
if (oldAdjacentWords != newAdjacentWords) {
« no previous file with comments | « Source/core/editing/Editor.h ('k') | Source/core/editing/SpellChecker.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698