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

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

Issue 6731036: Enabled pressing TAB to cycle through the Omnibox results. (Closed) Base URL: http://src.chromium.org/svn/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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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
49 AutocompleteMatch::~AutocompleteMatch() { 72 AutocompleteMatch::~AutocompleteMatch() {
50 } 73 }
51 74
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
52 // static 104 // static
53 std::string AutocompleteMatch::TypeToString(Type type) { 105 std::string AutocompleteMatch::TypeToString(Type type) {
54 const char* strings[] = { 106 const char* strings[] = {
55 "url-what-you-typed", 107 "url-what-you-typed",
56 "history-url", 108 "history-url",
57 "history-title", 109 "history-title",
58 "history-body", 110 "history-body",
59 "history-keyword", 111 "history-keyword",
60 "navsuggest", 112 "navsuggest",
61 "search-what-you-typed", 113 "search-what-you-typed",
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 152
101 return elem1.relevance > elem2.relevance; 153 return elem1.relevance > elem2.relevance;
102 } 154 }
103 155
104 // static 156 // static
105 bool AutocompleteMatch::DestinationSortFunc(const AutocompleteMatch& elem1, 157 bool AutocompleteMatch::DestinationSortFunc(const AutocompleteMatch& elem1,
106 const AutocompleteMatch& elem2) { 158 const AutocompleteMatch& elem2) {
107 // Sort identical destination_urls together. Place the most relevant matches 159 // Sort identical destination_urls together. Place the most relevant matches
108 // first, so that when we call std::unique(), these are the ones that get 160 // first, so that when we call std::unique(), these are the ones that get
109 // preserved. 161 // preserved.
110 return (elem1.destination_url != elem2.destination_url) ? 162 return (elem1.stripped_destination_url != elem2.stripped_destination_url) ?
111 (elem1.destination_url < elem2.destination_url) : 163 (elem1.stripped_destination_url < elem2.stripped_destination_url) :
112 MoreRelevant(elem1, elem2); 164 MoreRelevant(elem1, elem2);
113 } 165 }
114 166
115 // static 167 // static
116 bool AutocompleteMatch::DestinationsEqual(const AutocompleteMatch& elem1, 168 bool AutocompleteMatch::DestinationsEqual(const AutocompleteMatch& elem1,
117 const AutocompleteMatch& elem2) { 169 const AutocompleteMatch& elem2) {
118 return elem1.destination_url == elem2.destination_url; 170 return elem1.stripped_destination_url == elem2.stripped_destination_url;
119 } 171 }
120 172
121 // static 173 // static
122 void AutocompleteMatch::ClassifyMatchInString( 174 void AutocompleteMatch::ClassifyMatchInString(
123 const string16& find_text, 175 const string16& find_text,
124 const string16& text, 176 const string16& text,
125 int style, 177 int style,
126 ACMatchClassifications* classification) { 178 ACMatchClassifications* classification) {
127 ClassifyLocationInString(text.find(find_text), find_text.length(), 179 ClassifyLocationInString(text.find(find_text), find_text.length(),
128 text.length(), style, classification); 180 text.length(), style, classification);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // static 220 // static
169 string16 AutocompleteMatch::SanitizeString(const string16& text) { 221 string16 AutocompleteMatch::SanitizeString(const string16& text) {
170 // NOTE: This logic is mirrored by |sanitizeString()| in 222 // NOTE: This logic is mirrored by |sanitizeString()| in
171 // schema_generated_bindings.js. 223 // schema_generated_bindings.js.
172 string16 result; 224 string16 result;
173 TrimWhitespace(text, TRIM_LEADING, &result); 225 TrimWhitespace(text, TRIM_LEADING, &result);
174 RemoveChars(result, kInvalidChars, &result); 226 RemoveChars(result, kInvalidChars, &result);
175 return result; 227 return result;
176 } 228 }
177 229
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
178 #ifndef NDEBUG 252 #ifndef NDEBUG
179 void AutocompleteMatch::Validate() const { 253 void AutocompleteMatch::Validate() const {
180 ValidateClassifications(contents, contents_class); 254 ValidateClassifications(contents, contents_class);
181 ValidateClassifications(description, description_class); 255 ValidateClassifications(description, description_class);
182 } 256 }
183 257
184 void AutocompleteMatch::ValidateClassifications( 258 void AutocompleteMatch::ValidateClassifications(
185 const string16& text, 259 const string16& text,
186 const ACMatchClassifications& classifications) const { 260 const ACMatchClassifications& classifications) const {
187 if (text.empty()) { 261 if (text.empty()) {
(...skipping 10 matching lines...) Expand all
198 // The classifications should always be sorted. 272 // The classifications should always be sorted.
199 size_t last_offset = classifications[0].offset; 273 size_t last_offset = classifications[0].offset;
200 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1); 274 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1);
201 i != classifications.end(); ++i) { 275 i != classifications.end(); ++i) {
202 DCHECK(i->offset > last_offset) << "Classification unsorted"; 276 DCHECK(i->offset > last_offset) << "Classification unsorted";
203 DCHECK(i->offset < text.length()) << "Classification out of bounds"; 277 DCHECK(i->offset < text.length()) << "Classification out of bounds";
204 last_offset = i->offset; 278 last_offset = i->offset;
205 } 279 }
206 } 280 }
207 #endif 281 #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