Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: components/spellcheck/renderer/spellcheck.cc

Issue 2911253003: [Reland] Allow storing multiple replacements on SpellCheckResult (Closed)
Patch Set: Fix spell_check_host_impl_unittest.cc Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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;
Xiaocheng 2017/05/30 20:51:29 nit: It seems better to move L486-503 to a wrapper
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 the spellchecker suggested replacements, but they were all just
500 // changing apostrophe styles, ignore this misspelling. If there were never
501 // any suggested replacements, keep the misspelling.
502 if (replacements_adjusted.empty() && !replacements.empty())
490 continue; 503 continue;
491 504
492 if (filter == USE_NATIVE_CHECKER) { 505 if (filter == USE_NATIVE_CHECKER) {
493 // Double-check misspelled words with out spellchecker and attach grammar 506 // Double-check misspelled words with out spellchecker and attach grammar
494 // markers to them if our spellchecker tells us they are correct words, 507 // markers to them if our spellchecker tells us they are correct words,
495 // i.e. they are probably contextually-misspelled words. 508 // i.e. they are probably contextually-misspelled words.
496 int unused_misspelling_start = 0; 509 int unused_misspelling_start = 0;
497 int unused_misspelling_length = 0; 510 int unused_misspelling_length = 0;
498 if (decoration == SpellCheckResult::SPELLING && 511 if (decoration == SpellCheckResult::SPELLING &&
499 SpellCheckWord(misspelled_word.c_str(), kNoOffset, 512 SpellCheckWord(misspelled_word.c_str(), kNoOffset,
500 misspelled_word.length(), kNoTag, 513 misspelled_word.length(), kNoTag,
501 &unused_misspelling_start, &unused_misspelling_length, 514 &unused_misspelling_start, &unused_misspelling_length,
502 nullptr)) { 515 nullptr)) {
503 decoration = SpellCheckResult::GRAMMAR; 516 decoration = SpellCheckResult::GRAMMAR;
504 } 517 }
505 } 518 }
506 519
507 results.push_back(WebTextCheckingResult( 520 results.push_back(
508 static_cast<WebTextDecorationType>(decoration), 521 WebTextCheckingResult(static_cast<WebTextDecorationType>(decoration),
509 line_offset + spellcheck_result.location, spellcheck_result.length, 522 line_offset + spellcheck_result.location,
510 blink::WebString::FromUTF16(replacement))); 523 spellcheck_result.length, replacements_adjusted));
511 } 524 }
512 525
513 textcheck_results->Assign(results); 526 textcheck_results->Assign(results);
514 } 527 }
515 528
516 bool SpellCheck::IsSpellcheckEnabled() { 529 bool SpellCheck::IsSpellcheckEnabled() {
517 #if defined(OS_ANDROID) 530 #if defined(OS_ANDROID)
518 if (!spellcheck::IsAndroidSpellCheckFeatureEnabled()) return false; 531 if (!spellcheck::IsAndroidSpellCheckFeatureEnabled()) return false;
519 #endif 532 #endif
520 return spellcheck_enabled_; 533 return spellcheck_enabled_;
521 } 534 }
OLDNEW
« no previous file with comments | « components/spellcheck/common/spellcheck_result.cc ('k') | components/spellcheck/renderer/spellcheck_provider_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698