| 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 return true; | 238 return true; |
| 239 #endif | 239 #endif |
| 240 } | 240 } |
| 241 | 241 |
| 242 string16 SpellCheck::GetAutoCorrectionWord(const string16& word, int tag) { | 242 string16 SpellCheck::GetAutoCorrectionWord(const string16& word, int tag) { |
| 243 string16 autocorrect_word; | 243 string16 autocorrect_word; |
| 244 if (!auto_spell_correct_turned_on_) | 244 if (!auto_spell_correct_turned_on_) |
| 245 return autocorrect_word; // Return the empty string. | 245 return autocorrect_word; // Return the empty string. |
| 246 | 246 |
| 247 int word_length = static_cast<int>(word.size()); | 247 int word_length = static_cast<int>(word.size()); |
| 248 if (word_length < 2 || word_length > SpellCheckCommon::kMaxAutoCorrectWordSize
) | 248 if (word_length < 2 || |
| 249 word_length > chrome::spellcheck_common::kMaxAutoCorrectWordSize) |
| 249 return autocorrect_word; | 250 return autocorrect_word; |
| 250 | 251 |
| 251 if (InitializeIfNeeded()) | 252 if (InitializeIfNeeded()) |
| 252 return autocorrect_word; | 253 return autocorrect_word; |
| 253 | 254 |
| 254 char16 misspelled_word[SpellCheckCommon::kMaxAutoCorrectWordSize + 1]; | 255 char16 misspelled_word[ |
| 256 chrome::spellcheck_common::kMaxAutoCorrectWordSize + 1]; |
| 255 const char16* word_char = word.c_str(); | 257 const char16* word_char = word.c_str(); |
| 256 for (int i = 0; i <= SpellCheckCommon::kMaxAutoCorrectWordSize; i++) { | 258 for (int i = 0; i <= chrome::spellcheck_common::kMaxAutoCorrectWordSize; |
| 259 ++i) { |
| 257 if (i >= word_length) | 260 if (i >= word_length) |
| 258 misspelled_word[i] = 0; | 261 misspelled_word[i] = 0; |
| 259 else | 262 else |
| 260 misspelled_word[i] = word_char[i]; | 263 misspelled_word[i] = word_char[i]; |
| 261 } | 264 } |
| 262 | 265 |
| 263 // Swap adjacent characters and spellcheck. | 266 // Swap adjacent characters and spellcheck. |
| 264 int misspelling_start, misspelling_len; | 267 int misspelling_start, misspelling_len; |
| 265 for (int i = 0; i < word_length - 1; i++) { | 268 for (int i = 0; i < word_length - 1; i++) { |
| 266 // Swap. | 269 // Swap. |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 // If |hunspell_| is NULL here, an error has occurred, but it's better | 449 // If |hunspell_| is NULL here, an error has occurred, but it's better |
| 447 // to check rather than crash. | 450 // to check rather than crash. |
| 448 if (!hunspell_.get()) | 451 if (!hunspell_.get()) |
| 449 return; | 452 return; |
| 450 | 453 |
| 451 char** suggestions; | 454 char** suggestions; |
| 452 int number_of_suggestions = | 455 int number_of_suggestions = |
| 453 hunspell_->suggest(&suggestions, UTF16ToUTF8(wrong_word).c_str()); | 456 hunspell_->suggest(&suggestions, UTF16ToUTF8(wrong_word).c_str()); |
| 454 | 457 |
| 455 // Populate the vector of WideStrings. | 458 // Populate the vector of WideStrings. |
| 456 for (int i = 0; i < number_of_suggestions; i++) { | 459 for (int i = 0; i < number_of_suggestions; ++i) { |
| 457 if (i < SpellCheckCommon::kMaxSuggestions) | 460 if (i < chrome::spellcheck_common::kMaxSuggestions) |
| 458 optional_suggestions->push_back(UTF8ToUTF16(suggestions[i])); | 461 optional_suggestions->push_back(UTF8ToUTF16(suggestions[i])); |
| 459 free(suggestions[i]); | 462 free(suggestions[i]); |
| 460 } | 463 } |
| 461 if (suggestions != NULL) | 464 if (suggestions != NULL) |
| 462 free(suggestions); | 465 free(suggestions); |
| 463 } | 466 } |
| 464 | 467 |
| 465 // Returns whether or not the given string is a valid contraction. | 468 // Returns whether or not the given string is a valid contraction. |
| 466 // This function is a fall-back when the SpellcheckWordIterator class | 469 // This function is a fall-back when the SpellcheckWordIterator class |
| 467 // returns a concatenated word which is not in the selected dictionary | 470 // returns a concatenated word which is not in the selected dictionary |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 } | 514 } |
| 512 } | 515 } |
| 513 list[i] = WebKit::WebTextCheckingResult(type, | 516 list[i] = WebKit::WebTextCheckingResult(type, |
| 514 word_location + line_offset, | 517 word_location + line_offset, |
| 515 word_length, | 518 word_length, |
| 516 spellcheck_results[i].replacement); | 519 spellcheck_results[i].replacement); |
| 517 } | 520 } |
| 518 textcheck_results->swap(list); | 521 textcheck_results->swap(list); |
| 519 } | 522 } |
| 520 #endif | 523 #endif |
| OLD | NEW |