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 "components/spellcheck/renderer/spellcheck.h" | 5 #include "components/spellcheck/renderer/spellcheck.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 std::vector<WebTextCheckingResult> results; | 454 std::vector<WebTextCheckingResult> results; |
455 for (const SpellCheckResult& spellcheck_result : spellcheck_results) { | 455 for (const SpellCheckResult& spellcheck_result : spellcheck_results) { |
456 DCHECK_LE(static_cast<size_t>(spellcheck_result.location), | 456 DCHECK_LE(static_cast<size_t>(spellcheck_result.location), |
457 line_text.length()); | 457 line_text.length()); |
458 DCHECK_LE(static_cast<size_t>(spellcheck_result.location + | 458 DCHECK_LE(static_cast<size_t>(spellcheck_result.location + |
459 spellcheck_result.length), | 459 spellcheck_result.length), |
460 line_text.length()); | 460 line_text.length()); |
461 | 461 |
462 const base::string16& misspelled_word = | 462 const base::string16& misspelled_word = |
463 line_text.substr(spellcheck_result.location, spellcheck_result.length); | 463 line_text.substr(spellcheck_result.location, spellcheck_result.length); |
464 base::string16 replacement = spellcheck_result.replacement; | 464 const std::vector<base::string16>& replacements = |
| 465 spellcheck_result.replacements; |
465 SpellCheckResult::Decoration decoration = spellcheck_result.decoration; | 466 SpellCheckResult::Decoration decoration = spellcheck_result.decoration; |
466 | 467 |
467 // Ignore words in custom dictionary. | 468 // Ignore words in custom dictionary. |
468 if (custom_dictionary_.SpellCheckWord(misspelled_word, 0, | 469 if (custom_dictionary_.SpellCheckWord(misspelled_word, 0, |
469 misspelled_word.length())) { | 470 misspelled_word.length())) { |
470 continue; | 471 continue; |
471 } | 472 } |
472 | 473 |
473 // Use the same types of appostrophes as in the mispelled word. | 474 bool skip_these_replacements = false; |
474 PreserveOriginalApostropheTypes(misspelled_word, &replacement); | 475 std::vector<WebString> replacements_adjusted; |
| 476 for (base::string16 replacement : replacements) { |
| 477 // Use the same types of appostrophes as in the mispelled word. |
| 478 PreserveOriginalApostropheTypes(misspelled_word, &replacement); |
475 | 479 |
476 // Ignore misspellings due the typographical apostrophe. | 480 // If any of the replacements is the same as the misspelled word except |
477 if (misspelled_word == replacement) | 481 // for apostrophe type (straight vs. typographical), ignore this |
| 482 // misspelling since the spellchecker apparently thinks the word is |
| 483 // correctly spelled except that it doesn't like the apostrophe. |
| 484 if (replacement == misspelled_word) { |
| 485 skip_these_replacements = true; |
| 486 break; |
| 487 } |
| 488 |
| 489 replacements_adjusted.push_back(WebString::FromUTF16(replacement)); |
| 490 } |
| 491 |
| 492 if (skip_these_replacements) |
478 continue; | 493 continue; |
479 | 494 |
480 if (filter == USE_NATIVE_CHECKER) { | 495 if (filter == USE_NATIVE_CHECKER) { |
481 // Double-check misspelled words with out spellchecker and attach grammar | 496 // Double-check misspelled words with out spellchecker and attach grammar |
482 // markers to them if our spellchecker tells us they are correct words, | 497 // markers to them if our spellchecker tells us they are correct words, |
483 // i.e. they are probably contextually-misspelled words. | 498 // i.e. they are probably contextually-misspelled words. |
484 int unused_misspelling_start = 0; | 499 int unused_misspelling_start = 0; |
485 int unused_misspelling_length = 0; | 500 int unused_misspelling_length = 0; |
486 if (decoration == SpellCheckResult::SPELLING && | 501 if (decoration == SpellCheckResult::SPELLING && |
487 SpellCheckWord(misspelled_word.c_str(), kNoOffset, | 502 SpellCheckWord(misspelled_word.c_str(), kNoOffset, |
488 misspelled_word.length(), kNoTag, | 503 misspelled_word.length(), kNoTag, |
489 &unused_misspelling_start, &unused_misspelling_length, | 504 &unused_misspelling_start, &unused_misspelling_length, |
490 nullptr)) { | 505 nullptr)) { |
491 decoration = SpellCheckResult::GRAMMAR; | 506 decoration = SpellCheckResult::GRAMMAR; |
492 } | 507 } |
493 } | 508 } |
494 | 509 |
495 results.push_back(WebTextCheckingResult( | 510 results.push_back( |
496 static_cast<WebTextDecorationType>(decoration), | 511 WebTextCheckingResult(static_cast<WebTextDecorationType>(decoration), |
497 line_offset + spellcheck_result.location, spellcheck_result.length, | 512 line_offset + spellcheck_result.location, |
498 blink::WebString::FromUTF16(replacement))); | 513 spellcheck_result.length, replacements_adjusted)); |
499 } | 514 } |
500 | 515 |
501 textcheck_results->Assign(results); | 516 textcheck_results->Assign(results); |
502 } | 517 } |
503 | 518 |
504 bool SpellCheck::IsSpellcheckEnabled() { | 519 bool SpellCheck::IsSpellcheckEnabled() { |
505 #if defined(OS_ANDROID) | 520 #if defined(OS_ANDROID) |
506 if (!spellcheck::IsAndroidSpellCheckFeatureEnabled()) return false; | 521 if (!spellcheck::IsAndroidSpellCheckFeatureEnabled()) return false; |
507 #endif | 522 #endif |
508 return spellcheck_enabled_; | 523 return spellcheck_enabled_; |
509 } | 524 } |
OLD | NEW |