Commit c947c407 authored by mpearson's avatar mpearson Committed by Commit bot

Omnibox - Use Case Insensitive Matching when Bolding Query Suggestions

BUG=228694

Review URL: https://codereview.chromium.org/1134123004

Cr-Commit-Position: refs/heads/master@{#329298}
parent 1b13f371
...@@ -1110,6 +1110,16 @@ TEST_F(SearchProviderTest, InlineMixedCaseMatches) { ...@@ -1110,6 +1110,16 @@ TEST_F(SearchProviderTest, InlineMixedCaseMatches) {
EXPECT_EQ(ASCIIToUTF16("FOO"), term_match.fill_into_edit); EXPECT_EQ(ASCIIToUTF16("FOO"), term_match.fill_into_edit);
EXPECT_EQ(ASCIIToUTF16("OO"), term_match.inline_autocompletion); EXPECT_EQ(ASCIIToUTF16("OO"), term_match.inline_autocompletion);
EXPECT_TRUE(term_match.allowed_to_be_default_match); EXPECT_TRUE(term_match.allowed_to_be_default_match);
// Make sure the case doesn't affect the highlighting.
// (SearchProvider intentionally marks the new text as MATCH; that's why
// the tests below look backwards.)
ASSERT_EQ(2U, term_match.contents_class.size());
EXPECT_EQ(0U, term_match.contents_class[0].offset);
EXPECT_EQ(AutocompleteMatch::ACMatchClassification::NONE,
term_match.contents_class[0].style);
EXPECT_EQ(1U, term_match.contents_class[1].offset);
EXPECT_EQ(AutocompleteMatch::ACMatchClassification::MATCH,
term_match.contents_class[1].style);
} }
// Verifies AutocompleteControllers return results (including keyword // Verifies AutocompleteControllers return results (including keyword
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "components/omnibox/search_suggestion_parser.h" #include "components/omnibox/search_suggestion_parser.h"
#include <algorithm>
#include "base/i18n/icu_string_conversions.h" #include "base/i18n/icu_string_conversions.h"
#include "base/json/json_string_value_serializer.h" #include "base/json/json_string_value_serializer.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
...@@ -152,8 +154,11 @@ void SearchSuggestionParser::SuggestResult::ClassifyMatchContents( ...@@ -152,8 +154,11 @@ void SearchSuggestionParser::SuggestResult::ClassifyMatchContents(
lookup_text = input_text.substr(contents_index); lookup_text = input_text.substr(contents_index);
} }
} }
size_t lookup_position = match_contents_.find(lookup_text); // Do a case-insensitive search for |lookup_text|.
if (!allow_bolding_all && (lookup_position == base::string16::npos)) { base::string16::const_iterator lookup_position = std::search(
match_contents_.begin(), match_contents_.end(), lookup_text.begin(),
lookup_text.end(), base::CaseInsensitiveCompare<base::char16>());
if (!allow_bolding_all && (lookup_position == match_contents_.end())) {
// Bail if the code below to update the bolding would bold the whole // Bail if the code below to update the bolding would bold the whole
// string. Note that the string may already be entirely bolded; if // string. Note that the string may already be entirely bolded; if
// so, leave it as is. // so, leave it as is.
...@@ -164,7 +169,7 @@ void SearchSuggestionParser::SuggestResult::ClassifyMatchContents( ...@@ -164,7 +169,7 @@ void SearchSuggestionParser::SuggestResult::ClassifyMatchContents(
// will be highlighted, e.g. for input_text = "you" the suggestion may be // will be highlighted, e.g. for input_text = "you" the suggestion may be
// "youtube", so we'll bold the "tube" section: you*tube*. // "youtube", so we'll bold the "tube" section: you*tube*.
if (input_text != match_contents_) { if (input_text != match_contents_) {
if (lookup_position == base::string16::npos) { if (lookup_position == match_contents_.end()) {
// The input text is not a substring of the query string, e.g. input // The input text is not a substring of the query string, e.g. input
// text is "slasdot" and the query string is "slashdot", so we bold the // text is "slasdot" and the query string is "slashdot", so we bold the
// whole thing. // whole thing.
...@@ -176,13 +181,14 @@ void SearchSuggestionParser::SuggestResult::ClassifyMatchContents( ...@@ -176,13 +181,14 @@ void SearchSuggestionParser::SuggestResult::ClassifyMatchContents(
// short as a single character highlighted in a query suggestion result, // short as a single character highlighted in a query suggestion result,
// e.g. for input text "s" and query string "southwest airlines", it // e.g. for input text "s" and query string "southwest airlines", it
// looks odd if both the first and last s are highlighted. // looks odd if both the first and last s are highlighted.
if (lookup_position != 0) { const size_t lookup_index = lookup_position - match_contents_.begin();
if (lookup_index != 0) {
match_contents_class_.push_back( match_contents_class_.push_back(
ACMatchClassification(0, ACMatchClassification::MATCH)); ACMatchClassification(0, ACMatchClassification::MATCH));
} }
match_contents_class_.push_back( match_contents_class_.push_back(
ACMatchClassification(lookup_position, ACMatchClassification::NONE)); ACMatchClassification(lookup_index, ACMatchClassification::NONE));
size_t next_fragment_position = lookup_position + lookup_text.length(); size_t next_fragment_position = lookup_index + lookup_text.length();
if (next_fragment_position < match_contents_.length()) { if (next_fragment_position < match_contents_.length()) {
match_contents_class_.push_back(ACMatchClassification( match_contents_class_.push_back(ACMatchClassification(
next_fragment_position, ACMatchClassification::MATCH)); next_fragment_position, ACMatchClassification::MATCH));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment