OLD | NEW |
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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 } | 343 } |
344 | 344 |
345 DHISTOGRAM_TIMES("Spellcheck.InitTime", | 345 DHISTOGRAM_TIMES("Spellcheck.InitTime", |
346 base::Histogram::DebugNow() - debug_start_time); | 346 base::Histogram::DebugNow() - debug_start_time); |
347 } else { | 347 } else { |
348 NOTREACHED() << "Could not mmap spellchecker dictionary."; | 348 NOTREACHED() << "Could not mmap spellchecker dictionary."; |
349 } | 349 } |
350 } | 350 } |
351 | 351 |
352 void SpellCheck::AddWordToHunspell(const std::string& word) { | 352 void SpellCheck::AddWordToHunspell(const std::string& word) { |
353 if (!word.empty() && word.length() < MAXWORDUTF8LEN) | 353 if (!word.empty() && word.length() < MAXWORDLEN) |
354 hunspell_->add(word.c_str()); | 354 hunspell_->add(word.c_str()); |
355 } | 355 } |
356 | 356 |
357 bool SpellCheck::InitializeIfNeeded() { | 357 bool SpellCheck::InitializeIfNeeded() { |
358 if (is_using_platform_spelling_engine_) | 358 if (is_using_platform_spelling_engine_) |
359 return false; | 359 return false; |
360 | 360 |
361 if (!initialized_ && !dictionary_requested_) { | 361 if (!initialized_ && !dictionary_requested_) { |
362 // RenderThread will not exist in test. | 362 // RenderThread will not exist in test. |
363 if (RenderThread::Get()) | 363 if (RenderThread::Get()) |
(...skipping 15 matching lines...) Expand all Loading... |
379 bool word_correct = false; | 379 bool word_correct = false; |
380 | 380 |
381 if (is_using_platform_spelling_engine_) { | 381 if (is_using_platform_spelling_engine_) { |
382 #if defined(OS_MACOSX) | 382 #if defined(OS_MACOSX) |
383 RenderThread::Get()->Send(new SpellCheckHostMsg_CheckSpelling( | 383 RenderThread::Get()->Send(new SpellCheckHostMsg_CheckSpelling( |
384 word_to_check, tag, &word_correct)); | 384 word_to_check, tag, &word_correct)); |
385 #endif | 385 #endif |
386 } else { | 386 } else { |
387 std::string word_to_check_utf8(UTF16ToUTF8(word_to_check)); | 387 std::string word_to_check_utf8(UTF16ToUTF8(word_to_check)); |
388 // Hunspell shouldn't let us exceed its max, but check just in case | 388 // Hunspell shouldn't let us exceed its max, but check just in case |
389 if (word_to_check_utf8.length() < MAXWORDUTF8LEN) { | 389 if (word_to_check_utf8.length() < MAXWORDLEN) { |
390 if (hunspell_.get()) { | 390 if (hunspell_.get()) { |
391 // |hunspell_->spell| returns 0 if the word is spelled correctly and | 391 // |hunspell_->spell| returns 0 if the word is spelled correctly and |
392 // non-zero otherwsie. | 392 // non-zero otherwsie. |
393 word_correct = (hunspell_->spell(word_to_check_utf8.c_str()) != 0); | 393 word_correct = (hunspell_->spell(word_to_check_utf8.c_str()) != 0); |
394 } else { | 394 } else { |
395 // If |hunspell_| is NULL here, an error has occurred, but it's better | 395 // If |hunspell_| is NULL here, an error has occurred, but it's better |
396 // to check rather than crash. | 396 // to check rather than crash. |
397 word_correct = true; | 397 word_correct = true; |
398 } | 398 } |
399 } | 399 } |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 } | 514 } |
515 } | 515 } |
516 list[i] = WebKit::WebTextCheckingResult(type, | 516 list[i] = WebKit::WebTextCheckingResult(type, |
517 word_location + line_offset, | 517 word_location + line_offset, |
518 word_length, | 518 word_length, |
519 spellcheck_results[i].replacement); | 519 spellcheck_results[i].replacement); |
520 } | 520 } |
521 textcheck_results->swap(list); | 521 textcheck_results->swap(list); |
522 } | 522 } |
523 #endif | 523 #endif |
OLD | NEW |