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

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 9 years, 4 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 "chrome/browser/autocomplete/autocomplete_match.h" 6 #include "chrome/browser/autocomplete/autocomplete_match.h"
7 #include "grit/theme_resources.h" 7 #include "grit/theme_resources.h"
8 8
9 // AutocompleteMatch ---------------------------------------------------------- 9 // AutocompleteMatch ----------------------------------------------------------
10 10
(...skipping 19 matching lines...) Expand all
30 deletable(deletable), 30 deletable(deletable),
31 inline_autocomplete_offset(string16::npos), 31 inline_autocomplete_offset(string16::npos),
32 transition(PageTransition::TYPED), 32 transition(PageTransition::TYPED),
33 is_history_what_you_typed_match(false), 33 is_history_what_you_typed_match(false),
34 type(type), 34 type(type),
35 template_url(NULL), 35 template_url(NULL),
36 starred(false), 36 starred(false),
37 from_previous(false) { 37 from_previous(false) {
38 } 38 }
39 39
40 AutocompleteMatch::AutocompleteMatch(const AutocompleteMatch& match)
41 : provider(match.provider),
42 relevance(match.relevance),
43 deletable(match.deletable),
44 fill_into_edit(match.fill_into_edit),
45 inline_autocomplete_offset(match.inline_autocomplete_offset),
46 destination_url(match.destination_url),
47 stripped_destination_url(match.stripped_destination_url),
48 contents(match.contents),
49 contents_class(match.contents_class),
50 description(match.description),
51 description_class(match.description_class),
52 transition(match.transition),
53 is_history_what_you_typed_match(match.is_history_what_you_typed_match),
54 type(match.type),
55 keyword(match.keyword),
56 template_url(match.template_url),
57 starred(match.starred),
58 from_previous(match.from_previous) {
59 if (match.associated_keyword.get())
60 associated_keyword.reset(new AutocompleteMatch(*match.associated_keyword));
61 }
62
40 AutocompleteMatch::~AutocompleteMatch() { 63 AutocompleteMatch::~AutocompleteMatch() {
41 } 64 }
42 65
66 AutocompleteMatch& AutocompleteMatch::operator=(
67 const AutocompleteMatch& match) {
68 if (this == &match)
69 return *this;
70
71 provider = match.provider;
72 relevance = match.relevance;
73 deletable = match.deletable;
74 fill_into_edit = match.fill_into_edit;
75 inline_autocomplete_offset = match.inline_autocomplete_offset;
76 destination_url = match.destination_url;
77 stripped_destination_url = match.stripped_destination_url;
78 contents = match.contents;
79 contents_class = match.contents_class;
80 description = match.description;
81 description_class = match.description_class;
82 transition = match.transition;
83 is_history_what_you_typed_match = match.is_history_what_you_typed_match;
84 type = match.type;
85 associated_keyword.reset(match.associated_keyword.get() ?
86 new AutocompleteMatch(*match.associated_keyword) : NULL);
87 keyword = match.keyword;
88 template_url = match.template_url;
89 starred = match.starred;
90 from_previous = match.from_previous;
91
92 return *this;
93 }
94
43 // static 95 // static
44 std::string AutocompleteMatch::TypeToString(Type type) { 96 std::string AutocompleteMatch::TypeToString(Type type) {
45 const char* strings[] = { 97 const char* strings[] = {
46 "url-what-you-typed", 98 "url-what-you-typed",
47 "history-url", 99 "history-url",
48 "history-title", 100 "history-title",
49 "history-body", 101 "history-body",
50 "history-keyword", 102 "history-keyword",
51 "navsuggest", 103 "navsuggest",
52 "search-what-you-typed", 104 "search-what-you-typed",
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 143
92 return elem1.relevance > elem2.relevance; 144 return elem1.relevance > elem2.relevance;
93 } 145 }
94 146
95 // static 147 // static
96 bool AutocompleteMatch::DestinationSortFunc(const AutocompleteMatch& elem1, 148 bool AutocompleteMatch::DestinationSortFunc(const AutocompleteMatch& elem1,
97 const AutocompleteMatch& elem2) { 149 const AutocompleteMatch& elem2) {
98 // Sort identical destination_urls together. Place the most relevant matches 150 // Sort identical destination_urls together. Place the most relevant matches
99 // first, so that when we call std::unique(), these are the ones that get 151 // first, so that when we call std::unique(), these are the ones that get
100 // preserved. 152 // preserved.
101 return (elem1.destination_url != elem2.destination_url) ? 153 return (elem1.stripped_destination_url != elem2.stripped_destination_url) ?
102 (elem1.destination_url < elem2.destination_url) : 154 (elem1.stripped_destination_url < elem2.stripped_destination_url) :
103 MoreRelevant(elem1, elem2); 155 MoreRelevant(elem1, elem2);
104 } 156 }
105 157
106 // static 158 // static
107 bool AutocompleteMatch::DestinationsEqual(const AutocompleteMatch& elem1, 159 bool AutocompleteMatch::DestinationsEqual(const AutocompleteMatch& elem1,
108 const AutocompleteMatch& elem2) { 160 const AutocompleteMatch& elem2) {
109 return elem1.destination_url == elem2.destination_url; 161 return elem1.stripped_destination_url == elem2.stripped_destination_url;
110 } 162 }
111 163
112 // static 164 // static
113 void AutocompleteMatch::ClassifyMatchInString( 165 void AutocompleteMatch::ClassifyMatchInString(
114 const string16& find_text, 166 const string16& find_text,
115 const string16& text, 167 const string16& text,
116 int style, 168 int style,
117 ACMatchClassifications* classification) { 169 ACMatchClassifications* classification) {
118 ClassifyLocationInString(text.find(find_text), find_text.length(), 170 ClassifyLocationInString(text.find(find_text), find_text.length(),
119 text.length(), style, classification); 171 text.length(), style, classification);
(...skipping 29 matching lines...) Expand all
149 classification->push_back(ACMatchClassification(match_location, 201 classification->push_back(ACMatchClassification(match_location,
150 (style | ACMatchClassification::MATCH) & ~ACMatchClassification::DIM)); 202 (style | ACMatchClassification::MATCH) & ~ACMatchClassification::DIM));
151 203
152 // Mark post-match portion of string (if any). 204 // Mark post-match portion of string (if any).
153 const size_t after_match(match_location + match_length); 205 const size_t after_match(match_location + match_length);
154 if (after_match < overall_length) { 206 if (after_match < overall_length) {
155 classification->push_back(ACMatchClassification(after_match, style)); 207 classification->push_back(ACMatchClassification(after_match, style));
156 } 208 }
157 } 209 }
158 210
211 void AutocompleteMatch::ComputeStrippedDestinationURL() {
212 static const char prefix[] = "www.";
213 static const size_t prefix_len = arraysize(prefix) - 1;
214
215 std::string host = destination_url.host();
216 if (destination_url.is_valid() && host.compare(0, prefix_len, prefix) == 0) {
217 host = host.substr(prefix_len);
218 GURL::Replacements replace_host;
219 replace_host.SetHostStr(host);
220 stripped_destination_url = destination_url.ReplaceComponents(replace_host);
221 } else {
222 stripped_destination_url = destination_url;
223 }
224 }
225
159 #ifndef NDEBUG 226 #ifndef NDEBUG
160 void AutocompleteMatch::Validate() const { 227 void AutocompleteMatch::Validate() const {
161 ValidateClassifications(contents, contents_class); 228 ValidateClassifications(contents, contents_class);
162 ValidateClassifications(description, description_class); 229 ValidateClassifications(description, description_class);
163 } 230 }
164 231
165 void AutocompleteMatch::ValidateClassifications( 232 void AutocompleteMatch::ValidateClassifications(
166 const string16& text, 233 const string16& text,
167 const ACMatchClassifications& classifications) const { 234 const ACMatchClassifications& classifications) const {
168 if (text.empty()) { 235 if (text.empty()) {
(...skipping 10 matching lines...) Expand all
179 // The classifications should always be sorted. 246 // The classifications should always be sorted.
180 size_t last_offset = classifications[0].offset; 247 size_t last_offset = classifications[0].offset;
181 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1); 248 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1);
182 i != classifications.end(); ++i) { 249 i != classifications.end(); ++i) {
183 DCHECK(i->offset > last_offset) << "Classification unsorted"; 250 DCHECK(i->offset > last_offset) << "Classification unsorted";
184 DCHECK(i->offset < text.length()) << "Classification out of bounds"; 251 DCHECK(i->offset < text.length()) << "Classification out of bounds";
185 last_offset = i->offset; 252 last_offset = i->offset;
186 } 253 }
187 } 254 }
188 #endif 255 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698