Chromium Code Reviews| Index: chrome/renderer/spellchecker/spellcheck.cc |
| diff --git a/chrome/renderer/spellchecker/spellcheck.cc b/chrome/renderer/spellchecker/spellcheck.cc |
| index e2d505500fe58625388e13c1c045d6e64f2be76b..3d379589ec130c6b169aa0fe4db2a86b9f66bd0f 100644 |
| --- a/chrome/renderer/spellchecker/spellcheck.cc |
| +++ b/chrome/renderer/spellchecker/spellcheck.cc |
| @@ -264,6 +264,12 @@ bool SpellCheck::SpellCheckWord( |
| int possible_misspelling_len; |
| // The longest sequence of text that all languages agree is skippable. |
| int agreed_skippable_len; |
| + // A vector of vectors containing spelling suggestions from different |
| + // languages. |
| + std::vector<std::vector<base::string16>> suggestions_list; |
| + // A vector to hold a language's misspelling suggestions between spellcheck |
| + // calls. |
| + std::vector<base::string16> language_suggestions; |
| // This loop only advances if all languages agree that a sequence of text is |
| // skippable. |
| @@ -274,18 +280,17 @@ bool SpellCheck::SpellCheckWord( |
| agreed_skippable_len = text_length; |
| *misspelling_start = 0; |
| *misspelling_len = 0; |
| - |
| - if (optional_suggestions) |
| - optional_suggestions->clear(); |
| + suggestions_list.clear(); |
| for (ScopedVector<SpellcheckLanguage>::iterator language = |
| languages_.begin(); |
| language != languages_.end();) { |
| + language_suggestions.clear(); |
| SpellcheckLanguage::SpellcheckWordResult result = |
| - (*language)->SpellCheckWord(text_begin, position_in_text, text_length, |
| - tag, &possible_misspelling_start, |
| - &possible_misspelling_len, |
| - optional_suggestions); |
| + (*language)->SpellCheckWord( |
| + text_begin, position_in_text, text_length, tag, |
| + &possible_misspelling_start, &possible_misspelling_len, |
| + optional_suggestions ? &language_suggestions : nullptr); |
| switch (result) { |
| case SpellcheckLanguage::SpellcheckWordResult::IS_CORRECT: |
| @@ -301,6 +306,7 @@ bool SpellCheck::SpellCheckWord( |
| if (position_in_text != possible_misspelling_start) { |
| *misspelling_len = 0; |
| position_in_text = possible_misspelling_start; |
| + suggestions_list.clear(); |
| language = languages_.begin(); |
| } else { |
| language++; |
| @@ -312,23 +318,57 @@ bool SpellCheck::SpellCheckWord( |
| // If true, this means the spellchecker moved past a word that was |
| // previously determined to be misspelled or skippable, which means |
| // another spellcheck language marked it as correct. |
| - language = position_in_text != *misspelling_start ? languages_.begin() |
| - : language + 1; |
| - position_in_text = *misspelling_start; |
| + if (position_in_text != *misspelling_start) { |
| + suggestions_list.clear(); |
| + language = languages_.begin(); |
| + position_in_text = *misspelling_start; |
| + } else { |
| + suggestions_list.push_back(language_suggestions); |
| + language++; |
| + } |
| break; |
| } |
| } |
| // If |*misspelling_len| is non-zero, that means at least one language |
| // marked a word misspelled and no other language considered it correct. |
| - if (*misspelling_len != 0) |
| + if (*misspelling_len != 0) { |
| + if (optional_suggestions) |
| + FillSuggestions(suggestions_list, optional_suggestions); |
| return false; |
| + } |
| } |
| NOTREACHED(); |
| return true; |
| } |
| +void SpellCheck::FillSuggestions( |
|
please use gerrit instead
2015/08/20 22:14:27
Match the order of functions in the header and the
Julius
2015/08/21 00:39:19
Done.
|
| + const std::vector<std::vector<base::string16>>& suggestions_list, |
| + std::vector<base::string16>* optional_suggestions) { |
| + // A vector containing the indices of the current suggestion for each |
| + // language's suggestion list. |
| + std::vector<size_t> indices(suggestions_list.size(), 0); |
| + // Take one suggestion at a time from each language's suggestions and add it |
| + // to |optional_suggestions|. |
| + for (size_t i = 0, num_empty = 0; |
| + num_empty < suggestions_list.size() && |
| + optional_suggestions->size() < |
| + chrome::spellcheck_common::kMaxSuggestions; |
| + i = (i + 1) % suggestions_list.size()) { |
| + if (indices[i] < suggestions_list[i].size()) { |
| + const base::string16& suggestion = suggestions_list[i][indices[i]]; |
| + // Only add the suggestion if it's unique. |
| + if (std::find(optional_suggestions->begin(), optional_suggestions->end(), |
| + suggestion) == optional_suggestions->end()) { |
| + optional_suggestions->push_back(suggestion); |
| + } |
| + if (++indices[i] == suggestions_list[i].size()) |
| + num_empty++; |
| + } |
| + } |
| +} |
| + |
| bool SpellCheck::SpellCheckParagraph( |
| const base::string16& text, |
| WebVector<WebTextCheckingResult>* results) { |