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

Side by Side Diff: Source/core/editing/Editor.cpp

Issue 21694005: Spell check whole content of an editable element when it gets focused. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: change alerts to logs (tests) Created 7 years, 4 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 } 1010 }
1011 1011
1012 bool Editor::isContinuousSpellCheckingEnabled() const 1012 bool Editor::isContinuousSpellCheckingEnabled() const
1013 { 1013 {
1014 return client().isContinuousSpellCheckingEnabled(); 1014 return client().isContinuousSpellCheckingEnabled();
1015 } 1015 }
1016 1016
1017 void Editor::toggleContinuousSpellChecking() 1017 void Editor::toggleContinuousSpellChecking()
1018 { 1018 {
1019 client().toggleContinuousSpellChecking(); 1019 client().toggleContinuousSpellChecking();
1020 if (!isContinuousSpellCheckingEnabled()) {
tony 2013/08/22 18:44:34 Nit: If you early return, when enabled, the rest o
1021 for (Frame* frame = m_frame->page()->mainFrame(); frame && frame->docume nt(); frame = frame->tree()->traverseNext()) {
1022 for (Node* node = frame->document()->rootNode(); node; node = NodeTr aversal::next(node)) {
1023 node->setAlreadySpellChecked(false);
1024 }
1025 }
1026 }
1020 } 1027 }
1021 1028
1022 bool Editor::isGrammarCheckingEnabled() 1029 bool Editor::isGrammarCheckingEnabled()
1023 { 1030 {
1024 return client().isGrammarCheckingEnabled(); 1031 return client().isGrammarCheckingEnabled();
1025 } 1032 }
1026 1033
1027 bool Editor::shouldEndEditing(Range* range) 1034 bool Editor::shouldEndEditing(Range* range)
1028 { 1035 {
1029 return client().shouldEndEditing(range); 1036 return client().shouldEndEditing(range);
(...skipping 22 matching lines...) Expand all
1052 bool Editor::canRedo() 1059 bool Editor::canRedo()
1053 { 1060 {
1054 return client().canRedo(); 1061 return client().canRedo();
1055 } 1062 }
1056 1063
1057 void Editor::redo() 1064 void Editor::redo()
1058 { 1065 {
1059 client().redo(); 1066 client().redo();
1060 } 1067 }
1061 1068
1062 void Editor::didBeginEditing() 1069 void Editor::elementDidBeginEditing(Element* element)
1063 { 1070 {
1071 if (isContinuousSpellCheckingEnabled() && unifiedTextCheckerEnabled()) {
1072 bool isTextField = false;
1073 HTMLTextFormControlElement* enclosingHTMLTextFormControlElement = 0;
1074 if (!isHTMLTextFormControlElement(element))
1075 enclosingHTMLTextFormControlElement = enclosingTextFormControl(first PositionInNode(element));
1076 element = enclosingHTMLTextFormControlElement ? enclosingHTMLTextFormCon trolElement : element;
1077 Element* parent = element;
1078 if (isHTMLTextFormControlElement(element)) {
1079 HTMLTextFormControlElement* textControl = toHTMLTextFormControlEleme nt(element);
1080 parent = textControl;
1081 element = textControl->innerTextElement();
1082 isTextField = textControl->hasTagName(inputTag) && toHTMLInputElemen t(textControl)->isTextField();
1083 }
1084
1085 if (isTextField || !parent->isAlreadySpellChecked()) {
1086 // We always recheck textfields because markers are removed from the m on blur.
1087 VisibleSelection selection = VisibleSelection::selectionFromContents OfNode(element);
1088 markMisspellingsAndBadGrammar(selection);
1089 if (!isTextField)
1090 parent->setAlreadySpellChecked(true);
1091 }
1092 }
1093 }
1094
1095 void Editor::didBeginEditing(Element* rootEditableElement)
1096 {
1097 elementDidBeginEditing(rootEditableElement);
1064 client().didBeginEditing(); 1098 client().didBeginEditing();
1065 } 1099 }
1066 1100
1067 void Editor::didEndEditing() 1101 void Editor::didEndEditing()
1068 { 1102 {
1069 client().didEndEditing(); 1103 client().didEndEditing();
1070 } 1104 }
1071 1105
1072 void Editor::setBaseWritingDirection(WritingDirection direction) 1106 void Editor::setBaseWritingDirection(WritingDirection direction)
1073 { 1107 {
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 1894
1861 // Handle block styles, substracting these from the typing style. 1895 // Handle block styles, substracting these from the typing style.
1862 RefPtr<EditingStyle> blockStyle = typingStyle->extractAndRemoveBlockProperti es(); 1896 RefPtr<EditingStyle> blockStyle = typingStyle->extractAndRemoveBlockProperti es();
1863 if (!blockStyle->isEmpty()) 1897 if (!blockStyle->isEmpty())
1864 applyCommand(ApplyStyleCommand::create(m_frame->document(), blockStyle.g et(), editingAction)); 1898 applyCommand(ApplyStyleCommand::create(m_frame->document(), blockStyle.g et(), editingAction));
1865 1899
1866 // Set the remaining style as the typing style. 1900 // Set the remaining style as the typing style.
1867 m_frame->selection()->setTypingStyle(typingStyle); 1901 m_frame->selection()->setTypingStyle(typingStyle);
1868 } 1902 }
1869 1903
1870 1904 void Editor::textAreaOrTextFieldDidBeginEditing(Element* e)
1871 void Editor::textFieldDidBeginEditing(Element* e)
1872 { 1905 {
1873 if (isContinuousSpellCheckingEnabled()) { 1906 elementDidBeginEditing(e);
1874 Element* element = toHTMLTextFormControlElement(e)->innerTextElement();
1875 VisibleSelection selection = VisibleSelection::selectionFromContentsOfNo de(element);
1876 markMisspellingsAndBadGrammar(selection);
1877 }
1878 } 1907 }
1879 1908
1880 void Editor::textFieldDidEndEditing(Element* e) 1909 void Editor::textFieldDidEndEditing(Element* e)
1881 { 1910 {
1882 // Remove markers when deactivating a selection in an <input type="text"/>. 1911 // Remove markers when deactivating a selection in an <input type="text"/>.
1883 // Prevent new ones from appearing too. 1912 // Prevent new ones from appearing too.
1884 m_spellCheckRequester->cancelCheck(); 1913 m_spellCheckRequester->cancelCheck();
1885 HTMLTextFormControlElement* textFormControlElement = toHTMLTextFormControlEl ement(e); 1914 HTMLTextFormControlElement* textFormControlElement = toHTMLTextFormControlEl ement(e);
1886 HTMLElement* innerText = textFormControlElement->innerTextElement(); 1915 HTMLElement* innerText = textFormControlElement->innerTextElement();
1887 DocumentMarker::MarkerTypes markerTypes(DocumentMarker::Spelling); 1916 DocumentMarker::MarkerTypes markerTypes(DocumentMarker::Spelling);
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
2174 return WebCore::unifiedTextCheckerEnabled(m_frame); 2203 return WebCore::unifiedTextCheckerEnabled(m_frame);
2175 } 2204 }
2176 2205
2177 void Editor::toggleOverwriteModeEnabled() 2206 void Editor::toggleOverwriteModeEnabled()
2178 { 2207 {
2179 m_overwriteModeEnabled = !m_overwriteModeEnabled; 2208 m_overwriteModeEnabled = !m_overwriteModeEnabled;
2180 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); 2209 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled);
2181 }; 2210 };
2182 2211
2183 } // namespace WebCore 2212 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698