OLD | NEW |
---|---|
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 Loading... | |
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 const base::string16 prefix = | |
115 query_string.substr(0, query_string.rfind(match_contents)); | |
Mark P
2013/12/13 16:58:01
What if query_string does not contain match_conten
Anuj
2013/12/13 18:57:49
Done.
| |
116 lookup_text = input_text.find(prefix) == 0 ? | |
117 input_text.substr(prefix.length()) : input_text; | |
Mark P
2013/12/13 16:58:01
Should the latter case ever happen on matches mark
Anuj
2013/12/13 18:57:49
It should never happen, but like you said in previ
Mark P
2013/12/14 00:49:53
Okay, But why don't you structure this the same w
Anuj
2013/12/16 02:53:19
Done.
| |
118 } | |
113 // We do intra-string highlighting for suggestions - the suggested segment | 119 // We do intra-string highlighting for suggestions - the suggested segment |
114 // will be highlighted, e.g. for input_text = "you" the suggestion may be | 120 // will be highlighted, e.g. for input_text = "you" the suggestion may be |
115 // "youtube", so we'll bold the "tube" section: you*tube*. | 121 // "youtube", so we'll bold the "tube" section: you*tube*. |
116 if (input_text != match_contents) { | 122 if (lookup_text != match_contents) { |
117 size_t input_position = match->contents.find(input_text); | 123 size_t lookup_position = match->contents.find(lookup_text); |
118 if (input_position == base::string16::npos) { | 124 if (lookup_position == base::string16::npos) { |
119 // The input text is not a substring of the query string, e.g. input | 125 // 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 | 126 // text is "slasdot" and the query string is "slashdot", so we bold the |
121 // whole thing. | 127 // whole thing. |
122 match->contents_class.push_back(ACMatchClassification( | 128 match->contents_class.push_back(ACMatchClassification( |
123 0, ACMatchClassification::MATCH)); | 129 0, ACMatchClassification::MATCH)); |
124 } else { | 130 } else { |
125 // TODO(beng): ACMatchClassification::MATCH now seems to just mean | 131 // TODO(beng): ACMatchClassification::MATCH now seems to just mean |
126 // "bold" this. Consider modifying the terminology. | 132 // "bold" this. Consider modifying the terminology. |
127 // We don't iterate over the string here annotating all matches because | 133 // 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 | 134 // 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, | 135 // short as a single character highlighted in a query suggestion result, |
130 // e.g. for input text "s" and query string "southwest airlines", it | 136 // e.g. for input text "s" and query string "southwest airlines", it |
131 // looks odd if both the first and last s are highlighted. | 137 // looks odd if both the first and last s are highlighted. |
132 if (input_position != 0) { | 138 if (lookup_position != 0) { |
133 match->contents_class.push_back(ACMatchClassification( | 139 match->contents_class.push_back(ACMatchClassification( |
134 0, ACMatchClassification::MATCH)); | 140 0, ACMatchClassification::MATCH)); |
135 } | 141 } |
136 match->contents_class.push_back( | 142 match->contents_class.push_back( |
137 ACMatchClassification(input_position, ACMatchClassification::NONE)); | 143 ACMatchClassification(lookup_position, ACMatchClassification::NONE)); |
138 size_t next_fragment_position = input_position + input_text.length(); | 144 size_t next_fragment_position = lookup_position + lookup_text.length(); |
139 if (next_fragment_position < query_string.length()) { | 145 if (next_fragment_position < query_string.length()) { |
140 match->contents_class.push_back(ACMatchClassification( | 146 match->contents_class.push_back(ACMatchClassification( |
141 next_fragment_position, ACMatchClassification::MATCH)); | 147 next_fragment_position, ACMatchClassification::MATCH)); |
142 } | 148 } |
143 } | 149 } |
144 } else { | 150 } else { |
145 // Otherwise, |match| is a verbatim (what-you-typed) match, either for the | 151 // Otherwise, |match| is a verbatim (what-you-typed) match, either for the |
146 // default provider or a keyword search provider. | 152 // default provider or a keyword search provider. |
147 match->contents_class.push_back(ACMatchClassification( | 153 match->contents_class.push_back(ACMatchClassification( |
148 0, ACMatchClassification::NONE)); | 154 0, ACMatchClassification::NONE)); |
(...skipping 1877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2026 if (!OmniboxFieldTrial::InZeroSuggestFieldTrial() || | 2032 if (!OmniboxFieldTrial::InZeroSuggestFieldTrial() || |
2027 service == NULL || | 2033 service == NULL || |
2028 !service->IsSyncEnabledAndLoggedIn() || | 2034 !service->IsSyncEnabledAndLoggedIn() || |
2029 !sync_prefs.GetPreferredDataTypes(syncer::UserTypes()).Has( | 2035 !sync_prefs.GetPreferredDataTypes(syncer::UserTypes()).Has( |
2030 syncer::PROXY_TABS) || | 2036 syncer::PROXY_TABS) || |
2031 service->GetEncryptedDataTypes().Has(syncer::SESSIONS)) | 2037 service->GetEncryptedDataTypes().Has(syncer::SESSIONS)) |
2032 return false; | 2038 return false; |
2033 | 2039 |
2034 return true; | 2040 return true; |
2035 } | 2041 } |
OLD | NEW |