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

Side by Side Diff: chrome/renderer/spellchecker/spellcheck_provider.cc

Issue 1263423006: Rename spellchecker preprocessor flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/spellchecker/spellcheck_provider.h" 5 #include "chrome/renderer/spellchecker/spellcheck_provider.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/spellcheck_marker.h" 10 #include "chrome/common/spellcheck_marker.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 // Try to satisfy check from cache. 67 // Try to satisfy check from cache.
68 if (SatisfyRequestFromCache(text, completion)) 68 if (SatisfyRequestFromCache(text, completion))
69 return; 69 return;
70 70
71 // Send this text to a browser. A browser checks the user profile and send 71 // Send this text to a browser. A browser checks the user profile and send
72 // this text to the Spelling service only if a user enables this feature. 72 // this text to the Spelling service only if a user enables this feature.
73 last_request_.clear(); 73 last_request_.clear();
74 last_results_.assign(blink::WebVector<blink::WebTextCheckingResult>()); 74 last_results_.assign(blink::WebVector<blink::WebTextCheckingResult>());
75 75
76 #if defined(USE_PLATFORM_SPELLCHECKER) 76 #if defined(USE_BROWSER_SPELLCHECKER)
77 // Text check (unified request for grammar and spell check) is only 77 // Text check (unified request for grammar and spell check) is only
78 // available for browser process, so we ask the system spellchecker 78 // available for browser process, so we ask the system spellchecker
79 // over IPC or return an empty result if the checker is not 79 // over IPC or return an empty result if the checker is not
80 // available. 80 // available.
81 Send(new SpellCheckHostMsg_RequestTextCheck( 81 Send(new SpellCheckHostMsg_RequestTextCheck(
82 routing_id(), 82 routing_id(),
83 text_check_completions_.Add(completion), 83 text_check_completions_.Add(completion),
84 text, 84 text,
85 markers)); 85 markers));
86 #else 86 #else
87 Send(new SpellCheckHostMsg_CallSpellingService( 87 Send(new SpellCheckHostMsg_CallSpellingService(
88 routing_id(), 88 routing_id(),
89 text_check_completions_.Add(completion), 89 text_check_completions_.Add(completion),
90 base::string16(text), 90 base::string16(text),
91 markers)); 91 markers));
92 #endif // !USE_PLATFORM_SPELLCHECKER 92 #endif // !USE_BROWSER_SPELLCHECKER
93 } 93 }
94 94
95 bool SpellCheckProvider::OnMessageReceived(const IPC::Message& message) { 95 bool SpellCheckProvider::OnMessageReceived(const IPC::Message& message) {
96 bool handled = true; 96 bool handled = true;
97 IPC_BEGIN_MESSAGE_MAP(SpellCheckProvider, message) 97 IPC_BEGIN_MESSAGE_MAP(SpellCheckProvider, message)
98 #if !defined(USE_PLATFORM_SPELLCHECKER) 98 #if !defined(USE_BROWSER_SPELLCHECKER)
99 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondSpellingService, 99 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondSpellingService,
100 OnRespondSpellingService) 100 OnRespondSpellingService)
101 #endif 101 #endif
102 #if defined(USE_PLATFORM_SPELLCHECKER) 102 #if defined(USE_BROWSER_SPELLCHECKER)
103 IPC_MESSAGE_HANDLER(SpellCheckMsg_AdvanceToNextMisspelling, 103 IPC_MESSAGE_HANDLER(SpellCheckMsg_AdvanceToNextMisspelling,
104 OnAdvanceToNextMisspelling) 104 OnAdvanceToNextMisspelling)
105 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondTextCheck, OnRespondTextCheck) 105 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondTextCheck, OnRespondTextCheck)
106 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel) 106 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel)
107 #endif 107 #endif
108 IPC_MESSAGE_UNHANDLED(handled = false) 108 IPC_MESSAGE_UNHANDLED(handled = false)
109 IPC_END_MESSAGE_MAP() 109 IPC_END_MESSAGE_MAP()
110 return handled; 110 return handled;
111 } 111 }
112 112
113 void SpellCheckProvider::FocusedNodeChanged(const blink::WebNode& unused) { 113 void SpellCheckProvider::FocusedNodeChanged(const blink::WebNode& unused) {
114 #if defined(USE_PLATFORM_SPELLCHECKER) 114 #if defined(USE_BROWSER_SPELLCHECKER)
115 WebFrame* frame = render_view()->GetWebView()->focusedFrame(); 115 WebFrame* frame = render_view()->GetWebView()->focusedFrame();
116 WebElement element = frame->document().isNull() ? WebElement() : 116 WebElement element = frame->document().isNull() ? WebElement() :
117 frame->document().focusedElement(); 117 frame->document().focusedElement();
118 bool enabled = !element.isNull() && render_view()->IsEditableNode(element); 118 bool enabled = !element.isNull() && render_view()->IsEditableNode(element);
119 119
120 bool checked = enabled && render_view()->GetWebView() && 120 bool checked = enabled && render_view()->GetWebView() &&
121 frame->isContinuousSpellCheckingEnabled(); 121 frame->isContinuousSpellCheckingEnabled();
122 122
123 Send(new SpellCheckHostMsg_ToggleSpellCheck(routing_id(), enabled, checked)); 123 Send(new SpellCheckHostMsg_ToggleSpellCheck(routing_id(), enabled, checked));
124 #endif // USE_PLATFORM_SPELLCHECKER 124 #endif // USE_BROWSER_SPELLCHECKER
125 } 125 }
126 126
127 void SpellCheckProvider::spellCheck( 127 void SpellCheckProvider::spellCheck(
128 const WebString& text, 128 const WebString& text,
129 int& offset, 129 int& offset,
130 int& length, 130 int& length,
131 WebVector<WebString>* optional_suggestions) { 131 WebVector<WebString>* optional_suggestions) {
132 base::string16 word(text); 132 base::string16 word(text);
133 std::vector<base::string16> suggestions; 133 std::vector<base::string16> suggestions;
134 spellcheck_->SpellCheckWord( 134 spellcheck_->SpellCheckWord(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 const base::CommandLine& command_line = 180 const base::CommandLine& command_line =
181 *base::CommandLine::ForCurrentProcess(); 181 *base::CommandLine::ForCurrentProcess();
182 if (command_line.HasSwitch(switches::kEnableSpellingAutoCorrect)) { 182 if (command_line.HasSwitch(switches::kEnableSpellingAutoCorrect)) {
183 UMA_HISTOGRAM_COUNTS("SpellCheck.api.autocorrect", word.length()); 183 UMA_HISTOGRAM_COUNTS("SpellCheck.api.autocorrect", word.length());
184 return spellcheck_->GetAutoCorrectionWord(word, routing_id()); 184 return spellcheck_->GetAutoCorrectionWord(word, routing_id());
185 } 185 }
186 return base::string16(); 186 return base::string16();
187 } 187 }
188 188
189 void SpellCheckProvider::showSpellingUI(bool show) { 189 void SpellCheckProvider::showSpellingUI(bool show) {
190 #if defined(USE_PLATFORM_SPELLCHECKER) 190 #if defined(USE_BROWSER_SPELLCHECKER)
191 UMA_HISTOGRAM_BOOLEAN("SpellCheck.api.showUI", show); 191 UMA_HISTOGRAM_BOOLEAN("SpellCheck.api.showUI", show);
192 Send(new SpellCheckHostMsg_ShowSpellingPanel(routing_id(), show)); 192 Send(new SpellCheckHostMsg_ShowSpellingPanel(routing_id(), show));
193 #endif 193 #endif
194 } 194 }
195 195
196 bool SpellCheckProvider::isShowingSpellingUI() { 196 bool SpellCheckProvider::isShowingSpellingUI() {
197 return spelling_panel_visible_; 197 return spelling_panel_visible_;
198 } 198 }
199 199
200 void SpellCheckProvider::updateSpellingUIWithMisspelledWord( 200 void SpellCheckProvider::updateSpellingUIWithMisspelledWord(
201 const WebString& word) { 201 const WebString& word) {
202 #if defined(USE_PLATFORM_SPELLCHECKER) 202 #if defined(USE_BROWSER_SPELLCHECKER)
203 Send(new SpellCheckHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id(), 203 Send(new SpellCheckHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id(),
204 word)); 204 word));
205 #endif 205 #endif
206 } 206 }
207 207
208 #if !defined(USE_PLATFORM_SPELLCHECKER) 208 #if !defined(USE_BROWSER_SPELLCHECKER)
209 void SpellCheckProvider::OnRespondSpellingService( 209 void SpellCheckProvider::OnRespondSpellingService(
210 int identifier, 210 int identifier,
211 bool succeeded, 211 bool succeeded,
212 const base::string16& line, 212 const base::string16& line,
213 const std::vector<SpellCheckResult>& results) { 213 const std::vector<SpellCheckResult>& results) {
214 WebTextCheckingCompletion* completion = 214 WebTextCheckingCompletion* completion =
215 text_check_completions_.Lookup(identifier); 215 text_check_completions_.Lookup(identifier);
216 if (!completion) 216 if (!completion)
217 return; 217 return;
218 text_check_completions_.Remove(identifier); 218 text_check_completions_.Remove(identifier);
(...skipping 28 matching lines...) Expand all
247 while (index < length) { 247 while (index < length) {
248 uint32 code = 0; 248 uint32 code = 0;
249 U16_NEXT(data, index, length, code); 249 U16_NEXT(data, index, length, code);
250 UErrorCode error = U_ZERO_ERROR; 250 UErrorCode error = U_ZERO_ERROR;
251 if (uscript_getScript(code, &error) != USCRIPT_COMMON) 251 if (uscript_getScript(code, &error) != USCRIPT_COMMON)
252 return true; 252 return true;
253 } 253 }
254 return false; 254 return false;
255 } 255 }
256 256
257 #if defined(USE_PLATFORM_SPELLCHECKER) 257 #if defined(USE_BROWSER_SPELLCHECKER)
258 void SpellCheckProvider::OnAdvanceToNextMisspelling() { 258 void SpellCheckProvider::OnAdvanceToNextMisspelling() {
259 if (!render_view()->GetWebView()) 259 if (!render_view()->GetWebView())
260 return; 260 return;
261 render_view()->GetWebView()->focusedFrame()->executeCommand( 261 render_view()->GetWebView()->focusedFrame()->executeCommand(
262 WebString::fromUTF8("AdvanceToNextMisspelling")); 262 WebString::fromUTF8("AdvanceToNextMisspelling"));
263 } 263 }
264 264
265 void SpellCheckProvider::OnRespondTextCheck( 265 void SpellCheckProvider::OnRespondTextCheck(
266 int identifier, 266 int identifier,
267 const base::string16& line, 267 const base::string16& line,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 results[i].length = last_results_[i].length; 353 results[i].length = last_results_[i].length;
354 results[i].replacement = last_results_[i].replacement; 354 results[i].replacement = last_results_[i].replacement;
355 } 355 }
356 completion->didFinishCheckingText(results); 356 completion->didFinishCheckingText(results);
357 return true; 357 return true;
358 } 358 }
359 } 359 }
360 360
361 return false; 361 return false;
362 } 362 }
OLDNEW
« no previous file with comments | « chrome/renderer/spellchecker/spellcheck_provider.h ('k') | chrome/renderer/spellchecker/spellcheck_provider_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698