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