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

Side by Side Diff: chrome/browser/autocomplete/search_provider.cc

Issue 98463012: Infinite Suggest for mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed reviewer comments Created 7 years 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "chrome/browser/autocomplete/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 return false; 102 return false;
103 } 103 }
104 104
105 // Builds the match contents and classification for the contents, and updates 105 // Builds the match contents and classification for the contents, and updates
106 // the given |AutocompleteMatch|. 106 // the given |AutocompleteMatch|.
107 void SetAndClassifyMatchContents(const base::string16& query_string, 107 void SetAndClassifyMatchContents(const base::string16& query_string,
108 const base::string16& input_text, 108 const base::string16& input_text,
109 const base::string16& match_contents, 109 const base::string16& match_contents,
110 AutocompleteMatch* match) { 110 AutocompleteMatch* match) {
111 match->contents = match_contents.empty() ? query_string : match_contents; 111 match->contents = match_contents.empty() ? query_string : match_contents;
112 112 base::string16 lookup_text = input_text;
113 if (match->type == AutocompleteMatchType::SEARCH_SUGGEST_INFINITE) {
114 size_t content_index = query_string.rfind(match_contents);
Scott Hess - ex-Googler 2013/12/14 00:40:57 I'm like 27% confident in this code (probably less
Mark P 2013/12/14 00:49:53 FYI, I'm confident it can appear multiple times.
Anuj 2013/12/16 02:53:19 Yes, match_contents can appear multiple times, but
Anuj 2013/12/16 02:53:19 Done.
Scott Hess - ex-Googler 2013/12/16 20:26:13 I'll defer to Mark. I was mostly concerned that y
115 if (content_index != base::string16::npos) {
116 const base::string16 prefix = query_string.substr(0, content_index);
117 lookup_text = input_text.find(prefix) == 0 ?
118 input_text.substr(prefix.length()) : input_text;
Scott Hess - ex-Googler 2013/12/14 00:40:57 std::string::find() will keep looking for |prefix|
Anuj 2013/12/16 02:53:19 Done.
119 }
120 }
113 // We do intra-string highlighting for suggestions - the suggested segment 121 // We do intra-string highlighting for suggestions - the suggested segment
114 // will be highlighted, e.g. for input_text = "you" the suggestion may be 122 // will be highlighted, e.g. for input_text = "you" the suggestion may be
115 // "youtube", so we'll bold the "tube" section: you*tube*. 123 // "youtube", so we'll bold the "tube" section: you*tube*.
116 if (input_text != match_contents) { 124 if (lookup_text != match_contents) {
117 size_t input_position = match->contents.find(input_text); 125 size_t lookup_position = match->contents.find(lookup_text);
118 if (input_position == base::string16::npos) { 126 if (lookup_position == base::string16::npos) {
119 // The input text is not a substring of the query string, e.g. input 127 // The input text is not a substring of the query string, e.g. input
120 // text is "slasdot" and the query string is "slashdot", so we bold the 128 // text is "slasdot" and the query string is "slashdot", so we bold the
121 // whole thing. 129 // whole thing.
122 match->contents_class.push_back(ACMatchClassification( 130 match->contents_class.push_back(ACMatchClassification(
123 0, ACMatchClassification::MATCH)); 131 0, ACMatchClassification::MATCH));
124 } else { 132 } else {
125 // TODO(beng): ACMatchClassification::MATCH now seems to just mean 133 // TODO(beng): ACMatchClassification::MATCH now seems to just mean
126 // "bold" this. Consider modifying the terminology. 134 // "bold" this. Consider modifying the terminology.
127 // We don't iterate over the string here annotating all matches because 135 // We don't iterate over the string here annotating all matches because
128 // it looks odd to have every occurrence of a substring that may be as 136 // it looks odd to have every occurrence of a substring that may be as
129 // short as a single character highlighted in a query suggestion result, 137 // short as a single character highlighted in a query suggestion result,
130 // e.g. for input text "s" and query string "southwest airlines", it 138 // e.g. for input text "s" and query string "southwest airlines", it
131 // looks odd if both the first and last s are highlighted. 139 // looks odd if both the first and last s are highlighted.
132 if (input_position != 0) { 140 if (lookup_position != 0) {
133 match->contents_class.push_back(ACMatchClassification( 141 match->contents_class.push_back(ACMatchClassification(
134 0, ACMatchClassification::MATCH)); 142 0, ACMatchClassification::MATCH));
135 } 143 }
136 match->contents_class.push_back( 144 match->contents_class.push_back(
137 ACMatchClassification(input_position, ACMatchClassification::NONE)); 145 ACMatchClassification(lookup_position, ACMatchClassification::NONE));
138 size_t next_fragment_position = input_position + input_text.length(); 146 size_t next_fragment_position = lookup_position + lookup_text.length();
139 if (next_fragment_position < query_string.length()) { 147 if (next_fragment_position < query_string.length()) {
140 match->contents_class.push_back(ACMatchClassification( 148 match->contents_class.push_back(ACMatchClassification(
141 next_fragment_position, ACMatchClassification::MATCH)); 149 next_fragment_position, ACMatchClassification::MATCH));
142 } 150 }
143 } 151 }
144 } else { 152 } else {
145 // Otherwise, |match| is a verbatim (what-you-typed) match, either for the 153 // Otherwise, |match| is a verbatim (what-you-typed) match, either for the
146 // default provider or a keyword search provider. 154 // default provider or a keyword search provider.
147 match->contents_class.push_back(ACMatchClassification( 155 match->contents_class.push_back(ACMatchClassification(
148 0, ACMatchClassification::NONE)); 156 0, ACMatchClassification::NONE));
(...skipping 1877 matching lines...) Expand 10 before | Expand all | Expand 10 after
2026 if (!OmniboxFieldTrial::InZeroSuggestFieldTrial() || 2034 if (!OmniboxFieldTrial::InZeroSuggestFieldTrial() ||
2027 service == NULL || 2035 service == NULL ||
2028 !service->IsSyncEnabledAndLoggedIn() || 2036 !service->IsSyncEnabledAndLoggedIn() ||
2029 !sync_prefs.GetPreferredDataTypes(syncer::UserTypes()).Has( 2037 !sync_prefs.GetPreferredDataTypes(syncer::UserTypes()).Has(
2030 syncer::PROXY_TABS) || 2038 syncer::PROXY_TABS) ||
2031 service->GetEncryptedDataTypes().Has(syncer::SESSIONS)) 2039 service->GetEncryptedDataTypes().Has(syncer::SESSIONS))
2032 return false; 2040 return false;
2033 2041
2034 return true; 2042 return true;
2035 } 2043 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698