| 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 // If any of the replacements is the same as the misspelled word except |
| 489 if (misspelled_word == replacement) | 492 // for apostrophe type (straight vs. typographical), ignore this |
| 493 // misspelling since the spellchecker apparently thinks the word is |
| 494 // correctly spelled except that it doesn't like the apostrophe. |
| 495 if (replacement == misspelled_word) |
| 496 continue; |
| 497 |
| 498 replacements_adjusted.push_back(WebString::FromUTF16(replacement)); |
| 499 } |
| 500 |
| 501 if (replacements_adjusted.empty()) |
| 490 continue; | 502 continue; |
| 491 | 503 |
| 492 if (filter == USE_NATIVE_CHECKER) { | 504 if (filter == USE_NATIVE_CHECKER) { |
| 493 // Double-check misspelled words with out spellchecker and attach grammar | 505 // Double-check misspelled words with out spellchecker and attach grammar |
| 494 // markers to them if our spellchecker tells us they are correct words, | 506 // markers to them if our spellchecker tells us they are correct words, |
| 495 // i.e. they are probably contextually-misspelled words. | 507 // i.e. they are probably contextually-misspelled words. |
| 496 int unused_misspelling_start = 0; | 508 int unused_misspelling_start = 0; |
| 497 int unused_misspelling_length = 0; | 509 int unused_misspelling_length = 0; |
| 498 if (decoration == SpellCheckResult::SPELLING && | 510 if (decoration == SpellCheckResult::SPELLING && |
| 499 SpellCheckWord(misspelled_word.c_str(), kNoOffset, | 511 SpellCheckWord(misspelled_word.c_str(), kNoOffset, |
| 500 misspelled_word.length(), kNoTag, | 512 misspelled_word.length(), kNoTag, |
| 501 &unused_misspelling_start, &unused_misspelling_length, | 513 &unused_misspelling_start, &unused_misspelling_length, |
| 502 nullptr)) { | 514 nullptr)) { |
| 503 decoration = SpellCheckResult::GRAMMAR; | 515 decoration = SpellCheckResult::GRAMMAR; |
| 504 } | 516 } |
| 505 } | 517 } |
| 506 | 518 |
| 507 results.push_back(WebTextCheckingResult( | 519 results.push_back( |
| 508 static_cast<WebTextDecorationType>(decoration), | 520 WebTextCheckingResult(static_cast<WebTextDecorationType>(decoration), |
| 509 line_offset + spellcheck_result.location, spellcheck_result.length, | 521 line_offset + spellcheck_result.location, |
| 510 blink::WebString::FromUTF16(replacement))); | 522 spellcheck_result.length, replacements_adjusted)); |
| 511 } | 523 } |
| 512 | 524 |
| 513 textcheck_results->Assign(results); | 525 textcheck_results->Assign(results); |
| 514 } | 526 } |
| 515 | 527 |
| 516 bool SpellCheck::IsSpellcheckEnabled() { | 528 bool SpellCheck::IsSpellcheckEnabled() { |
| 517 #if defined(OS_ANDROID) | 529 #if defined(OS_ANDROID) |
| 518 if (!spellcheck::IsAndroidSpellCheckFeatureEnabled()) return false; | 530 if (!spellcheck::IsAndroidSpellCheckFeatureEnabled()) return false; |
| 519 #endif | 531 #endif |
| 520 return spellcheck_enabled_; | 532 return spellcheck_enabled_; |
| 521 } | 533 } |
| OLD | NEW |