Chromium Code Reviews| 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 // Ignore misspellings due the typographical apostrophe. |
| 477 if (misspelled_word == replacement) | 481 if (replacement == misspelled_word) { |
| 482 skip_these_replacements = true; | |
| 483 continue; | |
| 484 } | |
| 485 | |
| 486 replacements_adjusted.push_back(WebString::FromUTF16(replacement)); | |
| 487 } | |
| 488 | |
| 489 if (skip_these_replacements) | |
|
groby-ooo-7-16
2017/04/28 23:45:55
I believe this is wrong - with your change, if *an
rlanday
2017/05/01 20:40:01
My thinking was that if the spellchecker thinks th
groby-ooo-7-16
2017/05/08 15:31:22
What we currently do is that for all replacements,
| |
| 478 continue; | 490 continue; |
| 479 | 491 |
| 480 if (filter == USE_NATIVE_CHECKER) { | 492 if (filter == USE_NATIVE_CHECKER) { |
| 481 // Double-check misspelled words with out spellchecker and attach grammar | 493 // Double-check misspelled words with out spellchecker and attach grammar |
| 482 // 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, |
| 483 // i.e. they are probably contextually-misspelled words. | 495 // i.e. they are probably contextually-misspelled words. |
| 484 int unused_misspelling_start = 0; | 496 int unused_misspelling_start = 0; |
| 485 int unused_misspelling_length = 0; | 497 int unused_misspelling_length = 0; |
| 486 if (decoration == SpellCheckResult::SPELLING && | 498 if (decoration == SpellCheckResult::SPELLING && |
| 487 SpellCheckWord(misspelled_word.c_str(), kNoOffset, | 499 SpellCheckWord(misspelled_word.c_str(), kNoOffset, |
| 488 misspelled_word.length(), kNoTag, | 500 misspelled_word.length(), kNoTag, |
| 489 &unused_misspelling_start, &unused_misspelling_length, | 501 &unused_misspelling_start, &unused_misspelling_length, |
| 490 nullptr)) { | 502 nullptr)) { |
| 491 decoration = SpellCheckResult::GRAMMAR; | 503 decoration = SpellCheckResult::GRAMMAR; |
| 492 } | 504 } |
| 493 } | 505 } |
| 494 | 506 |
| 495 results.push_back(WebTextCheckingResult( | 507 results.push_back( |
| 496 static_cast<WebTextDecorationType>(decoration), | 508 WebTextCheckingResult(static_cast<WebTextDecorationType>(decoration), |
| 497 line_offset + spellcheck_result.location, spellcheck_result.length, | 509 line_offset + spellcheck_result.location, |
| 498 blink::WebString::FromUTF16(replacement))); | 510 spellcheck_result.length, replacements_adjusted)); |
| 499 } | 511 } |
| 500 | 512 |
| 501 textcheck_results->Assign(results); | 513 textcheck_results->Assign(results); |
| 502 } | 514 } |
| 503 | 515 |
| 504 bool SpellCheck::IsSpellcheckEnabled() { | 516 bool SpellCheck::IsSpellcheckEnabled() { |
| 505 #if defined(OS_ANDROID) | 517 #if defined(OS_ANDROID) |
| 506 if (!spellcheck::IsAndroidSpellCheckFeatureEnabled()) return false; | 518 if (!spellcheck::IsAndroidSpellCheckFeatureEnabled()) return false; |
| 507 #endif | 519 #endif |
| 508 return spellcheck_enabled_; | 520 return spellcheck_enabled_; |
| 509 } | 521 } |
| OLD | NEW |