| 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 || word_length > chrome::kMaxAutoCorrectWordSize) |
| 249 return autocorrect_word; | 249 return autocorrect_word; |
| 250 | 250 |
| 251 if (InitializeIfNeeded()) | 251 if (InitializeIfNeeded()) |
| 252 return autocorrect_word; | 252 return autocorrect_word; |
| 253 | 253 |
| 254 char16 misspelled_word[SpellCheckCommon::kMaxAutoCorrectWordSize + 1]; | 254 char16 misspelled_word[chrome::kMaxAutoCorrectWordSize + 1]; |
| 255 const char16* word_char = word.c_str(); | 255 const char16* word_char = word.c_str(); |
| 256 for (int i = 0; i <= SpellCheckCommon::kMaxAutoCorrectWordSize; i++) { | 256 for (int i = 0; i <= chrome::kMaxAutoCorrectWordSize; ++i) { |
| 257 if (i >= word_length) | 257 if (i >= word_length) |
| 258 misspelled_word[i] = 0; | 258 misspelled_word[i] = 0; |
| 259 else | 259 else |
| 260 misspelled_word[i] = word_char[i]; | 260 misspelled_word[i] = word_char[i]; |
| 261 } | 261 } |
| 262 | 262 |
| 263 // Swap adjacent characters and spellcheck. | 263 // Swap adjacent characters and spellcheck. |
| 264 int misspelling_start, misspelling_len; | 264 int misspelling_start, misspelling_len; |
| 265 for (int i = 0; i < word_length - 1; i++) { | 265 for (int i = 0; i < word_length - 1; i++) { |
| 266 // Swap. | 266 // Swap. |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 // to check rather than crash. | 447 // to check rather than crash. |
| 448 if (!hunspell_.get()) | 448 if (!hunspell_.get()) |
| 449 return; | 449 return; |
| 450 | 450 |
| 451 char** suggestions; | 451 char** suggestions; |
| 452 int number_of_suggestions = | 452 int number_of_suggestions = |
| 453 hunspell_->suggest(&suggestions, UTF16ToUTF8(wrong_word).c_str()); | 453 hunspell_->suggest(&suggestions, UTF16ToUTF8(wrong_word).c_str()); |
| 454 | 454 |
| 455 // Populate the vector of WideStrings. | 455 // Populate the vector of WideStrings. |
| 456 for (int i = 0; i < number_of_suggestions; i++) { | 456 for (int i = 0; i < number_of_suggestions; i++) { |
| 457 if (i < SpellCheckCommon::kMaxSuggestions) | 457 if (i < chrome::kMaxSuggestions) |
| 458 optional_suggestions->push_back(UTF8ToUTF16(suggestions[i])); | 458 optional_suggestions->push_back(UTF8ToUTF16(suggestions[i])); |
| 459 free(suggestions[i]); | 459 free(suggestions[i]); |
| 460 } | 460 } |
| 461 if (suggestions != NULL) | 461 if (suggestions != NULL) |
| 462 free(suggestions); | 462 free(suggestions); |
| 463 } | 463 } |
| 464 | 464 |
| 465 // Returns whether or not the given string is a valid contraction. | 465 // Returns whether or not the given string is a valid contraction. |
| 466 // This function is a fall-back when the SpellcheckWordIterator class | 466 // This function is a fall-back when the SpellcheckWordIterator class |
| 467 // returns a concatenated word which is not in the selected dictionary | 467 // 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 } | 511 } |
| 512 } | 512 } |
| 513 list[i] = WebKit::WebTextCheckingResult(type, | 513 list[i] = WebKit::WebTextCheckingResult(type, |
| 514 word_location + line_offset, | 514 word_location + line_offset, |
| 515 word_length, | 515 word_length, |
| 516 spellcheck_results[i].replacement); | 516 spellcheck_results[i].replacement); |
| 517 } | 517 } |
| 518 textcheck_results->swap(list); | 518 textcheck_results->swap(list); |
| 519 } | 519 } |
| 520 #endif | 520 #endif |
| OLD | NEW |