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

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

Issue 10155006: Cancel unnecessary spellcheck requests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/renderer/spellchecker/spellcheck_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h" 5 #include "chrome/renderer/spellchecker/spellcheck.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 } 216 }
217 217
218 return true; 218 return true;
219 } 219 }
220 220
221 bool SpellCheck::SpellCheckParagraph( 221 bool SpellCheck::SpellCheckParagraph(
222 const string16& text, 222 const string16& text,
223 std::vector<SpellCheckResult>* results) { 223 std::vector<SpellCheckResult>* results) {
224 #if !defined(OS_MACOSX) 224 #if !defined(OS_MACOSX)
225 // Mac has its own spell checker, so this method will not be used. 225 // Mac has its own spell checker, so this method will not be used.
226
227 DCHECK(results); 226 DCHECK(results);
228 227
229 size_t length = text.length(); 228 size_t length = text.length();
230 size_t offset = 0; 229 size_t offset = 0;
231 230
232 // Spellcheck::SpellCheckWord() automatically breaks text into words and 231 // Spellcheck::SpellCheckWord() automatically breaks text into words and
233 // checks the spellings of the extracted words. This function sets the 232 // checks the spellings of the extracted words. This function sets the
234 // position and length of the first misspelled word and returns false when 233 // position and length of the first misspelled word and returns false when
235 // the text includes misspelled words. Therefore, we just repeat calling the 234 // the text includes misspelled words. Therefore, we just repeat calling the
236 // function until it returns true to check the whole text. 235 // function until it returns true to check the whole text.
237 int misspelling_start = 0; 236 int misspelling_start = 0;
238 int misspelling_length = 0; 237 int misspelling_length = 0;
239 while (offset <= length) { 238 while (offset <= length) {
239 std::vector<string16> suggestions;
240 if (SpellCheckWord(&text[offset], 240 if (SpellCheckWord(&text[offset],
241 length - offset, 241 length - offset,
242 0, 242 0,
243 &misspelling_start, 243 &misspelling_start,
244 &misspelling_length, 244 &misspelling_length,
245 NULL)) { 245 &suggestions)) {
246 return true; 246 return true;
247 } 247 }
248 248
249 if (results) { 249 string16 replacement;
250 results->push_back(SpellCheckResult( 250 if (!suggestions.empty())
251 SpellCheckResult::SPELLING, 251 replacement = JoinString(suggestions, '\n');
252 misspelling_start + offset, 252 results->push_back(SpellCheckResult(
253 misspelling_length)); 253 SpellCheckResult::SPELLING,
254 } 254 misspelling_start + offset,
255 misspelling_length,
256 replacement));
255 offset += misspelling_start + misspelling_length; 257 offset += misspelling_start + misspelling_length;
256 } 258 }
257 259
258 return false; 260 return false;
259 #else 261 #else
260 return true; 262 return true;
261 #endif 263 #endif
262 } 264 }
263 265
264 string16 SpellCheck::GetAutoCorrectionWord(const string16& word, int tag) { 266 string16 SpellCheck::GetAutoCorrectionWord(const string16& word, int tag) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 313 }
312 314
313 void SpellCheck::RequestTextChecking( 315 void SpellCheck::RequestTextChecking(
314 const string16& text, 316 const string16& text,
315 int offset, 317 int offset,
316 WebKit::WebTextCheckingCompletion* completion) { 318 WebKit::WebTextCheckingCompletion* completion) {
317 #if !defined(OS_MACOSX) 319 #if !defined(OS_MACOSX)
318 // Commented out on Mac, because SpellCheckRequest::PerformSpellCheck is not 320 // Commented out on Mac, because SpellCheckRequest::PerformSpellCheck is not
319 // implemented on Mac. Mac uses its own spellchecker, so this method 321 // implemented on Mac. Mac uses its own spellchecker, so this method
320 // will not be used. 322 // will not be used.
321
322 DCHECK(!is_using_platform_spelling_engine_); 323 DCHECK(!is_using_platform_spelling_engine_);
323 324
324 // Clean up the previous request before starting a new request. 325 // Clean up the previous request before starting a new request.
325 if (pending_request_param_.get()) { 326 if (pending_request_param_.get()) {
326 pending_request_param_->completion()->didFinishCheckingText( 327 pending_request_param_->completion()->didCancelCheckingText();
327 WebKit::WebVector<WebKit::WebTextCheckingResult>());
328 pending_request_param_ = NULL; 328 pending_request_param_ = NULL;
329 } 329 }
330 330
331 if (InitializeIfNeeded()) { 331 if (InitializeIfNeeded()) {
332 // We will check this text after we finish loading the hunspell dictionary. 332 // We will check this text after we finish loading the hunspell dictionary.
333 // Save parameters so that we can use them when we receive an init message 333 // Save parameters so that we can use them when we receive an init message
334 // from the browser process. 334 // from the browser process.
335 pending_request_param_ = new SpellCheckRequestParam( 335 pending_request_param_ = new SpellCheckRequestParam(
336 text, offset, completion); 336 text, offset, completion);
337 return; 337 return;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 } 421 }
422 422
423 return word_correct; 423 return word_correct;
424 } 424 }
425 425
426 void SpellCheck::PostDelayedSpellCheckTask() { 426 void SpellCheck::PostDelayedSpellCheckTask() {
427 if (!pending_request_param_) 427 if (!pending_request_param_)
428 return; 428 return;
429 429
430 if (file_ == base::kInvalidPlatformFileValue) { 430 if (file_ == base::kInvalidPlatformFileValue) {
431 pending_request_param_->completion()->didFinishCheckingText( 431 pending_request_param_->completion()->didCancelCheckingText();
432 WebKit::WebVector<WebKit::WebTextCheckingResult>());
433 } else { 432 } else {
434 requested_params_.push(pending_request_param_); 433 requested_params_.push(pending_request_param_);
435 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 434 base::MessageLoopProxy::current()->PostTask(FROM_HERE,
436 base::Bind(&SpellCheck::PerformSpellCheck, AsWeakPtr())); 435 base::Bind(&SpellCheck::PerformSpellCheck, AsWeakPtr()));
437 } 436 }
438 437
439 pending_request_param_ = NULL; 438 pending_request_param_ = NULL;
440 } 439 }
441 440
442 void SpellCheck::PerformSpellCheck() { 441 void SpellCheck::PerformSpellCheck() {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 503
505 string16 word; 504 string16 word;
506 int word_start; 505 int word_start;
507 int word_length; 506 int word_length;
508 while (contraction_iterator_.GetNextWord(&word, &word_start, &word_length)) { 507 while (contraction_iterator_.GetNextWord(&word, &word_start, &word_length)) {
509 if (!CheckSpelling(word, tag)) 508 if (!CheckSpelling(word, tag))
510 return false; 509 return false;
511 } 510 }
512 return true; 511 return true;
513 } 512 }
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/spellchecker/spellcheck_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698