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

Side by Side Diff: third_party/WebKit/Source/web/SpellCheckerClientImpl.cpp

Issue 2796473002: Split TextCheckerClientImpl off SpellCheckerClientImpl (Closed)
Patch Set: Remove explicit Created 3 years, 8 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 Apple, Inc. All rights reserved. 2 * Copyright (C) 2006, 2007 Apple, Inc. All rights reserved.
3 * Copyright (C) 2012 Google, Inc. All rights reserved. 3 * Copyright (C) 2012 Google, Inc. All rights reserved.
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 12 matching lines...) Expand all
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "web/SpellCheckerClientImpl.h" 27 #include "web/SpellCheckerClientImpl.h"
28 28
29 #include "core/dom/Element.h" 29 #include "core/dom/Element.h"
30 #include "core/editing/markers/DocumentMarkerController.h" 30 #include "core/editing/markers/DocumentMarkerController.h"
31 #include "core/editing/spellcheck/SpellChecker.h" 31 #include "core/editing/spellcheck/SpellChecker.h"
32 #include "core/frame/LocalFrame.h" 32 #include "core/frame/LocalFrame.h"
33 #include "core/frame/Settings.h"
34 #include "core/page/Page.h" 33 #include "core/page/Page.h"
35 #include "public/web/WebSpellCheckClient.h" 34 #include "public/web/WebSpellCheckClient.h"
36 #include "public/web/WebTextCheckingResult.h"
37 #include "web/WebTextCheckingCompletionImpl.h"
38 #include "web/WebViewImpl.h" 35 #include "web/WebViewImpl.h"
39 36
40 namespace blink { 37 namespace blink {
41 38
42 SpellCheckerClientImpl::SpellCheckerClientImpl(WebViewImpl* webview) 39 SpellCheckerClientImpl::SpellCheckerClientImpl(
43 : m_webView(webview), m_spellCheckThisFieldStatus(SpellCheckAutomatic) {} 40 WebViewImpl* webview,
41 TextCheckerClient* textCheckerClient)
42 : m_webView(webview),
43 m_textCheckerClient(textCheckerClient),
44 m_spellCheckThisFieldStatus(SpellCheckAutomatic) {}
44 45
45 SpellCheckerClientImpl::~SpellCheckerClientImpl() {} 46 SpellCheckerClientImpl::~SpellCheckerClientImpl() {}
46 47
47 bool SpellCheckerClientImpl::shouldSpellcheckByDefault() { 48 bool SpellCheckerClientImpl::shouldSpellcheckByDefault() {
48 // Spellcheck should be enabled for all editable areas (such as textareas, 49 // Spellcheck should be enabled for all editable areas (such as textareas,
49 // contentEditable regions, designMode docs and inputs). 50 // contentEditable regions, designMode docs and inputs).
50 if (!m_webView->focusedCoreFrame()->isLocalFrame()) 51 if (!m_webView->focusedCoreFrame()->isLocalFrame())
51 return false; 52 return false;
52 const LocalFrame* frame = toLocalFrame(m_webView->focusedCoreFrame()); 53 const LocalFrame* frame = toLocalFrame(m_webView->focusedCoreFrame());
53 if (!frame) 54 if (!frame)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // If a selection is in an editable element spell check its content. 103 // If a selection is in an editable element spell check its content.
103 if (Element* rootEditableElement = 104 if (Element* rootEditableElement =
104 frameSelection.rootEditableElement()) { 105 frameSelection.rootEditableElement()) {
105 frame->spellChecker().didBeginEditing(rootEditableElement); 106 frame->spellChecker().didBeginEditing(rootEditableElement);
106 } 107 }
107 } 108 }
108 } 109 }
109 } 110 }
110 } 111 }
111 112
112 void SpellCheckerClientImpl::checkSpellingOfString(const String& text,
113 int* misspellingLocation,
114 int* misspellingLength) {
115 // SpellCheckWord will write (0, 0) into the output vars, which is what our
116 // caller expects if the word is spelled correctly.
117 int spellLocation = -1;
118 int spellLength = 0;
119
120 // Check to see if the provided text is spelled correctly.
121 if (m_webView->spellCheckClient()) {
122 m_webView->spellCheckClient()->checkSpelling(text, spellLocation,
123 spellLength, nullptr);
124 } else {
125 spellLocation = 0;
126 spellLength = 0;
127 }
128
129 // Note: the Mac code checks if the pointers are null before writing to them,
130 // so we do too.
131 if (misspellingLocation)
132 *misspellingLocation = spellLocation;
133 if (misspellingLength)
134 *misspellingLength = spellLength;
135 }
136
137 void SpellCheckerClientImpl::requestCheckingOfString(
138 TextCheckingRequest* request) {
139 if (!m_webView->spellCheckClient())
140 return;
141 const String& text = request->data().text();
142 m_webView->spellCheckClient()->requestCheckingOfText(
143 text, new WebTextCheckingCompletionImpl(request));
144 }
145
146 void SpellCheckerClientImpl::cancelAllPendingRequests() {
147 if (!m_webView->spellCheckClient())
148 return;
149 m_webView->spellCheckClient()->cancelAllPendingRequests();
150 }
151
152 void SpellCheckerClientImpl::updateSpellingUIWithMisspelledWord( 113 void SpellCheckerClientImpl::updateSpellingUIWithMisspelledWord(
153 const String& misspelledWord) { 114 const String& misspelledWord) {
154 if (m_webView->spellCheckClient()) 115 if (m_webView->spellCheckClient())
155 m_webView->spellCheckClient()->updateSpellingUIWithMisspelledWord( 116 m_webView->spellCheckClient()->updateSpellingUIWithMisspelledWord(
156 WebString(misspelledWord)); 117 WebString(misspelledWord));
157 } 118 }
158 119
159 void SpellCheckerClientImpl::showSpellingUI(bool show) { 120 void SpellCheckerClientImpl::showSpellingUI(bool show) {
160 if (m_webView->spellCheckClient()) 121 if (m_webView->spellCheckClient())
161 m_webView->spellCheckClient()->showSpellingUI(show); 122 m_webView->spellCheckClient()->showSpellingUI(show);
162 } 123 }
163 124
164 bool SpellCheckerClientImpl::spellingUIIsShowing() { 125 bool SpellCheckerClientImpl::spellingUIIsShowing() {
165 if (m_webView->spellCheckClient()) 126 if (m_webView->spellCheckClient())
166 return m_webView->spellCheckClient()->isShowingSpellingUI(); 127 return m_webView->spellCheckClient()->isShowingSpellingUI();
167 return false; 128 return false;
168 } 129 }
169 130
170 } // namespace blink 131 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/SpellCheckerClientImpl.h ('k') | third_party/WebKit/Source/web/TextCheckerClientImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698