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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 std::vector<WebTextCheckingResult> results; | 466 std::vector<WebTextCheckingResult> results; |
467 for (const SpellCheckResult& spellcheck_result : spellcheck_results) { | 467 for (const SpellCheckResult& spellcheck_result : spellcheck_results) { |
468 DCHECK_LE(static_cast<size_t>(spellcheck_result.location), | 468 DCHECK_LE(static_cast<size_t>(spellcheck_result.location), |
469 line_text.length()); | 469 line_text.length()); |
470 DCHECK_LE(static_cast<size_t>(spellcheck_result.location + | 470 DCHECK_LE(static_cast<size_t>(spellcheck_result.location + |
471 spellcheck_result.length), | 471 spellcheck_result.length), |
472 line_text.length()); | 472 line_text.length()); |
473 | 473 |
474 const base::string16& misspelled_word = | 474 const base::string16& misspelled_word = |
475 line_text.substr(spellcheck_result.location, spellcheck_result.length); | 475 line_text.substr(spellcheck_result.location, spellcheck_result.length); |
476 const std::vector<base::string16>& replacements = | 476 base::string16 replacement = spellcheck_result.replacement; |
477 spellcheck_result.replacements; | |
478 SpellCheckResult::Decoration decoration = spellcheck_result.decoration; | 477 SpellCheckResult::Decoration decoration = spellcheck_result.decoration; |
479 | 478 |
480 // Ignore words in custom dictionary. | 479 // Ignore words in custom dictionary. |
481 if (custom_dictionary_.SpellCheckWord(misspelled_word, 0, | 480 if (custom_dictionary_.SpellCheckWord(misspelled_word, 0, |
482 misspelled_word.length())) { | 481 misspelled_word.length())) { |
483 continue; | 482 continue; |
484 } | 483 } |
485 | 484 |
486 std::vector<WebString> replacements_adjusted; | 485 // Use the same types of appostrophes as in the mispelled word. |
487 for (base::string16 replacement : replacements) { | 486 PreserveOriginalApostropheTypes(misspelled_word, &replacement); |
488 // Use the same types of appostrophes as in the mispelled word. | |
489 PreserveOriginalApostropheTypes(misspelled_word, &replacement); | |
490 | 487 |
491 // Ignore suggestions that are just changing the apostrophe type | 488 // Ignore misspellings due the typographical apostrophe. |
492 // (straight vs. typographical) | 489 if (misspelled_word == replacement) |
493 if (replacement == misspelled_word) | |
494 continue; | |
495 | |
496 replacements_adjusted.push_back(WebString::FromUTF16(replacement)); | |
497 } | |
498 | |
499 if (replacements_adjusted.empty()) | |
500 continue; | 490 continue; |
501 | 491 |
502 if (filter == USE_NATIVE_CHECKER) { | 492 if (filter == USE_NATIVE_CHECKER) { |
503 // Double-check misspelled words with out spellchecker and attach grammar | 493 // Double-check misspelled words with out spellchecker and attach grammar |
504 // markers to them if our spellchecker tells us they are correct words, | 494 // markers to them if our spellchecker tells us they are correct words, |
505 // i.e. they are probably contextually-misspelled words. | 495 // i.e. they are probably contextually-misspelled words. |
506 int unused_misspelling_start = 0; | 496 int unused_misspelling_start = 0; |
507 int unused_misspelling_length = 0; | 497 int unused_misspelling_length = 0; |
508 if (decoration == SpellCheckResult::SPELLING && | 498 if (decoration == SpellCheckResult::SPELLING && |
509 SpellCheckWord(misspelled_word.c_str(), kNoOffset, | 499 SpellCheckWord(misspelled_word.c_str(), kNoOffset, |
510 misspelled_word.length(), kNoTag, | 500 misspelled_word.length(), kNoTag, |
511 &unused_misspelling_start, &unused_misspelling_length, | 501 &unused_misspelling_start, &unused_misspelling_length, |
512 nullptr)) { | 502 nullptr)) { |
513 decoration = SpellCheckResult::GRAMMAR; | 503 decoration = SpellCheckResult::GRAMMAR; |
514 } | 504 } |
515 } | 505 } |
516 | 506 |
517 results.push_back( | 507 results.push_back(WebTextCheckingResult( |
518 WebTextCheckingResult(static_cast<WebTextDecorationType>(decoration), | 508 static_cast<WebTextDecorationType>(decoration), |
519 line_offset + spellcheck_result.location, | 509 line_offset + spellcheck_result.location, spellcheck_result.length, |
520 spellcheck_result.length, replacements_adjusted)); | 510 blink::WebString::FromUTF16(replacement))); |
521 } | 511 } |
522 | 512 |
523 textcheck_results->Assign(results); | 513 textcheck_results->Assign(results); |
524 } | 514 } |
525 | 515 |
526 bool SpellCheck::IsSpellcheckEnabled() { | 516 bool SpellCheck::IsSpellcheckEnabled() { |
527 #if defined(OS_ANDROID) | 517 #if defined(OS_ANDROID) |
528 if (!spellcheck::IsAndroidSpellCheckFeatureEnabled()) return false; | 518 if (!spellcheck::IsAndroidSpellCheckFeatureEnabled()) return false; |
529 #endif | 519 #endif |
530 return spellcheck_enabled_; | 520 return spellcheck_enabled_; |
531 } | 521 } |
OLD | NEW |