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

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

Issue 9419043: Revert 122412 - Enabled pressing TAB to traverse through the Omnibox results (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 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 | Annotate | Revision Log
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 "base/logging.h" 5 #include "base/logging.h"
6 #include "base/string_util.h" 6 #include "base/string_util.h"
7 #include "chrome/browser/autocomplete/autocomplete_match.h" 7 #include "chrome/browser/autocomplete/autocomplete_match.h"
8 #include "grit/theme_resources.h" 8 #include "grit/theme_resources.h"
9 9
10 // AutocompleteMatch ---------------------------------------------------------- 10 // AutocompleteMatch ----------------------------------------------------------
(...skipping 28 matching lines...) Expand all
39 deletable(deletable), 39 deletable(deletable),
40 inline_autocomplete_offset(string16::npos), 40 inline_autocomplete_offset(string16::npos),
41 transition(content::PAGE_TRANSITION_TYPED), 41 transition(content::PAGE_TRANSITION_TYPED),
42 is_history_what_you_typed_match(false), 42 is_history_what_you_typed_match(false),
43 type(type), 43 type(type),
44 template_url(NULL), 44 template_url(NULL),
45 starred(false), 45 starred(false),
46 from_previous(false) { 46 from_previous(false) {
47 } 47 }
48 48
49 AutocompleteMatch::AutocompleteMatch(const AutocompleteMatch& match)
50 : provider(match.provider),
51 relevance(match.relevance),
52 deletable(match.deletable),
53 fill_into_edit(match.fill_into_edit),
54 inline_autocomplete_offset(match.inline_autocomplete_offset),
55 destination_url(match.destination_url),
56 stripped_destination_url(match.stripped_destination_url),
57 contents(match.contents),
58 contents_class(match.contents_class),
59 description(match.description),
60 description_class(match.description_class),
61 transition(match.transition),
62 is_history_what_you_typed_match(match.is_history_what_you_typed_match),
63 type(match.type),
64 keyword(match.keyword),
65 template_url(match.template_url),
66 starred(match.starred),
67 from_previous(match.from_previous) {
68 if (match.associated_keyword.get())
69 associated_keyword.reset(new AutocompleteMatch(*match.associated_keyword));
70 }
71
72 AutocompleteMatch::~AutocompleteMatch() { 49 AutocompleteMatch::~AutocompleteMatch() {
73 } 50 }
74 51
75 AutocompleteMatch& AutocompleteMatch::operator=(
76 const AutocompleteMatch& match) {
77 if (this == &match)
78 return *this;
79
80 provider = match.provider;
81 relevance = match.relevance;
82 deletable = match.deletable;
83 fill_into_edit = match.fill_into_edit;
84 inline_autocomplete_offset = match.inline_autocomplete_offset;
85 destination_url = match.destination_url;
86 stripped_destination_url = match.stripped_destination_url;
87 contents = match.contents;
88 contents_class = match.contents_class;
89 description = match.description;
90 description_class = match.description_class;
91 transition = match.transition;
92 is_history_what_you_typed_match = match.is_history_what_you_typed_match;
93 type = match.type;
94 associated_keyword.reset(match.associated_keyword.get() ?
95 new AutocompleteMatch(*match.associated_keyword) : NULL);
96 keyword = match.keyword;
97 template_url = match.template_url;
98 starred = match.starred;
99 from_previous = match.from_previous;
100
101 return *this;
102 }
103
104 // static 52 // static
105 std::string AutocompleteMatch::TypeToString(Type type) { 53 std::string AutocompleteMatch::TypeToString(Type type) {
106 const char* strings[] = { 54 const char* strings[] = {
107 "url-what-you-typed", 55 "url-what-you-typed",
108 "history-url", 56 "history-url",
109 "history-title", 57 "history-title",
110 "history-body", 58 "history-body",
111 "history-keyword", 59 "history-keyword",
112 "navsuggest", 60 "navsuggest",
113 "search-what-you-typed", 61 "search-what-you-typed",
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 100
153 return elem1.relevance > elem2.relevance; 101 return elem1.relevance > elem2.relevance;
154 } 102 }
155 103
156 // static 104 // static
157 bool AutocompleteMatch::DestinationSortFunc(const AutocompleteMatch& elem1, 105 bool AutocompleteMatch::DestinationSortFunc(const AutocompleteMatch& elem1,
158 const AutocompleteMatch& elem2) { 106 const AutocompleteMatch& elem2) {
159 // Sort identical destination_urls together. Place the most relevant matches 107 // Sort identical destination_urls together. Place the most relevant matches
160 // first, so that when we call std::unique(), these are the ones that get 108 // first, so that when we call std::unique(), these are the ones that get
161 // preserved. 109 // preserved.
162 return (elem1.stripped_destination_url != elem2.stripped_destination_url) ? 110 return (elem1.destination_url != elem2.destination_url) ?
163 (elem1.stripped_destination_url < elem2.stripped_destination_url) : 111 (elem1.destination_url < elem2.destination_url) :
164 MoreRelevant(elem1, elem2); 112 MoreRelevant(elem1, elem2);
165 } 113 }
166 114
167 // static 115 // static
168 bool AutocompleteMatch::DestinationsEqual(const AutocompleteMatch& elem1, 116 bool AutocompleteMatch::DestinationsEqual(const AutocompleteMatch& elem1,
169 const AutocompleteMatch& elem2) { 117 const AutocompleteMatch& elem2) {
170 return elem1.stripped_destination_url == elem2.stripped_destination_url; 118 return elem1.destination_url == elem2.destination_url;
171 } 119 }
172 120
173 // static 121 // static
174 void AutocompleteMatch::ClassifyMatchInString( 122 void AutocompleteMatch::ClassifyMatchInString(
175 const string16& find_text, 123 const string16& find_text,
176 const string16& text, 124 const string16& text,
177 int style, 125 int style,
178 ACMatchClassifications* classification) { 126 ACMatchClassifications* classification) {
179 ClassifyLocationInString(text.find(find_text), find_text.length(), 127 ClassifyLocationInString(text.find(find_text), find_text.length(),
180 text.length(), style, classification); 128 text.length(), style, classification);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 // static 168 // static
221 string16 AutocompleteMatch::SanitizeString(const string16& text) { 169 string16 AutocompleteMatch::SanitizeString(const string16& text) {
222 // NOTE: This logic is mirrored by |sanitizeString()| in 170 // NOTE: This logic is mirrored by |sanitizeString()| in
223 // schema_generated_bindings.js. 171 // schema_generated_bindings.js.
224 string16 result; 172 string16 result;
225 TrimWhitespace(text, TRIM_LEADING, &result); 173 TrimWhitespace(text, TRIM_LEADING, &result);
226 RemoveChars(result, kInvalidChars, &result); 174 RemoveChars(result, kInvalidChars, &result);
227 return result; 175 return result;
228 } 176 }
229 177
230 void AutocompleteMatch::ComputeStrippedDestinationURL() {
231 static const char prefix[] = "www.";
232 static const size_t prefix_len = arraysize(prefix) - 1;
233
234 std::string host = destination_url.host();
235 if (destination_url.is_valid() && host.compare(0, prefix_len, prefix) == 0) {
236 host = host.substr(prefix_len);
237 GURL::Replacements replace_host;
238 replace_host.SetHostStr(host);
239 stripped_destination_url = destination_url.ReplaceComponents(replace_host);
240 } else {
241 stripped_destination_url = destination_url;
242 }
243 }
244
245 bool AutocompleteMatch::GetKeyword(string16* keyword) const {
246 const bool is_keyword_hint = associated_keyword.get() != NULL;
247 keyword->assign(is_keyword_hint ? associated_keyword->keyword :
248 this->keyword);
249 return is_keyword_hint;
250 }
251
252 #ifndef NDEBUG 178 #ifndef NDEBUG
253 void AutocompleteMatch::Validate() const { 179 void AutocompleteMatch::Validate() const {
254 ValidateClassifications(contents, contents_class); 180 ValidateClassifications(contents, contents_class);
255 ValidateClassifications(description, description_class); 181 ValidateClassifications(description, description_class);
256 } 182 }
257 183
258 void AutocompleteMatch::ValidateClassifications( 184 void AutocompleteMatch::ValidateClassifications(
259 const string16& text, 185 const string16& text,
260 const ACMatchClassifications& classifications) const { 186 const ACMatchClassifications& classifications) const {
261 if (text.empty()) { 187 if (text.empty()) {
(...skipping 13 matching lines...) Expand all
275 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1); 201 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1);
276 i != classifications.end(); ++i) { 202 i != classifications.end(); ++i) {
277 DCHECK_GT(i->offset, last_offset) 203 DCHECK_GT(i->offset, last_offset)
278 << "Classification unsorted for \"" << text << '"'; 204 << "Classification unsorted for \"" << text << '"';
279 DCHECK_LT(i->offset, text.length()) 205 DCHECK_LT(i->offset, text.length())
280 << "Classification out of bounds for \"" << text << '"'; 206 << "Classification out of bounds for \"" << text << '"';
281 last_offset = i->offset; 207 last_offset = i->offset;
282 } 208 }
283 } 209 }
284 #endif 210 #endif
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_match.h ('k') | chrome/browser/autocomplete/autocomplete_popup_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698