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

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

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) 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 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_ 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_
6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_ 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 #include <string> 10 #include <string>
11 11
12 #include "base/memory/scoped_ptr.h"
12 #include "content/public/common/page_transition_types.h" 13 #include "content/public/common/page_transition_types.h"
13 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
14 15
15 class AutocompleteProvider; 16 class AutocompleteProvider;
16 class TemplateURL; 17 class TemplateURL;
17 18
18 // AutocompleteMatch ---------------------------------------------------------- 19 // AutocompleteMatch ----------------------------------------------------------
19 20
20 // A single result line with classified spans. The autocomplete popup displays 21 // A single result line with classified spans. The autocomplete popup displays
21 // the 'contents' and the 'description' (the description is optional) in the 22 // the 'contents' and the 'description' (the description is optional) in the
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 84
84 // Null-terminated array of characters that are not valid within |contents| 85 // Null-terminated array of characters that are not valid within |contents|
85 // and |description| strings. 86 // and |description| strings.
86 static const char16 kInvalidChars[]; 87 static const char16 kInvalidChars[];
87 88
88 AutocompleteMatch(); 89 AutocompleteMatch();
89 AutocompleteMatch(AutocompleteProvider* provider, 90 AutocompleteMatch(AutocompleteProvider* provider,
90 int relevance, 91 int relevance,
91 bool deletable, 92 bool deletable,
92 Type type); 93 Type type);
94 AutocompleteMatch(const AutocompleteMatch& match);
93 ~AutocompleteMatch(); 95 ~AutocompleteMatch();
94 96
95 // Converts |type| to a string representation. Used in logging and debugging. 97 // Converts |type| to a string representation. Used in logging and debugging.
98 AutocompleteMatch& operator=(const AutocompleteMatch& match);
99
100 // Converts |type| to a string representation. Used in logging.
96 static std::string TypeToString(Type type); 101 static std::string TypeToString(Type type);
97 102
98 // Converts |type| to a resource identifier for the appropriate icon for this 103 // Converts |type| to a resource identifier for the appropriate icon for this
99 // type. 104 // type.
100 static int TypeToIcon(Type type); 105 static int TypeToIcon(Type type);
101 106
102 // Comparison function for determining when one match is better than another. 107 // Comparison function for determining when one match is better than another.
103 static bool MoreRelevant(const AutocompleteMatch& elem1, 108 static bool MoreRelevant(const AutocompleteMatch& elem1,
104 const AutocompleteMatch& elem2); 109 const AutocompleteMatch& elem2);
105 110
106 // Comparison functions for removing matches with duplicate destinations. 111 // Comparison functions for removing matches with duplicate destinations.
112 // Destinations are compared using |stripped_destination_url|.
107 static bool DestinationSortFunc(const AutocompleteMatch& elem1, 113 static bool DestinationSortFunc(const AutocompleteMatch& elem1,
108 const AutocompleteMatch& elem2); 114 const AutocompleteMatch& elem2);
109 static bool DestinationsEqual(const AutocompleteMatch& elem1, 115 static bool DestinationsEqual(const AutocompleteMatch& elem1,
110 const AutocompleteMatch& elem2); 116 const AutocompleteMatch& elem2);
111 117
112 // Helper functions for classes creating matches: 118 // Helper functions for classes creating matches:
113 // Fills in the classifications for |text|, using |style| as the base style 119 // Fills in the classifications for |text|, using |style| as the base style
114 // and marking the first instance of |find_text| as a match. (This match 120 // and marking the first instance of |find_text| as a match. (This match
115 // will also not be dimmed, if |style| has DIM set.) 121 // will also not be dimmed, if |style| has DIM set.)
116 static void ClassifyMatchInString(const string16& find_text, 122 static void ClassifyMatchInString(const string16& find_text,
117 const string16& text, 123 const string16& text,
118 int style, 124 int style,
119 ACMatchClassifications* classifications); 125 ACMatchClassifications* classifications);
120 126
121 // Similar to ClassifyMatchInString(), but for cases where the range to mark 127 // Similar to ClassifyMatchInString(), but for cases where the range to mark
122 // as matching is already known (avoids calling find()). This can be helpful 128 // as matching is already known (avoids calling find()). This can be helpful
123 // when find() would be misleading (e.g. you want to mark the second match in 129 // when find() would be misleading (e.g. you want to mark the second match in
124 // a string instead of the first). 130 // a string instead of the first).
125 static void ClassifyLocationInString(size_t match_location, 131 static void ClassifyLocationInString(size_t match_location,
126 size_t match_length, 132 size_t match_length,
127 size_t overall_length, 133 size_t overall_length,
128 int style, 134 int style,
129 ACMatchClassifications* classifications); 135 ACMatchClassifications* classifications);
130 136
131 // Removes invalid characters from |text|. Should be called on strings coming 137 // Removes invalid characters from |text|. Should be called on strings coming
132 // from external sources (such as extensions) before assigning to |contents| 138 // from external sources (such as extensions) before assigning to |contents|
133 // or |description|. 139 // or |description|.
134 static string16 SanitizeString(const string16& text); 140 static string16 SanitizeString(const string16& text);
135 141
142 // Copies the destination_url with "www." stripped off to
143 // |stripped_destination_url|. This method is invoked internally by the
144 // AutocompleteController and does not normally need to be invoked.
145 void ComputeStrippedDestinationURL();
146
147 // Gets the selected keyword or keyword hint for this match. Returns
148 // true if |keyword| represents a keyword hint, or false if |keyword|
149 // represents a selected keyword. (|keyword| will always be set [though
150 // possibly to the empty string], and you cannot have both a selected keyword
151 // and a keyword hint simultaneously.)
152 bool GetKeyword(string16* keyword) const;
153
136 // The provider of this match, used to remember which provider the user had 154 // The provider of this match, used to remember which provider the user had
137 // selected when the input changes. This may be NULL, in which case there is 155 // selected when the input changes. This may be NULL, in which case there is
138 // no provider (or memory of the user's selection). 156 // no provider (or memory of the user's selection).
139 AutocompleteProvider* provider; 157 AutocompleteProvider* provider;
140 158
141 // The relevance of this match. See table in autocomplete.h for scores 159 // The relevance of this match. See table in autocomplete.h for scores
142 // returned by various providers. This is used to rank matches among all 160 // returned by various providers. This is used to rank matches among all
143 // responding providers, so different providers must be carefully tuned to 161 // responding providers, so different providers must be carefully tuned to
144 // supply matches with appropriate relevance. 162 // supply matches with appropriate relevance.
145 // 163 //
(...skipping 12 matching lines...) Expand all
158 // The position within fill_into_edit from which we'll display the inline 176 // The position within fill_into_edit from which we'll display the inline
159 // autocomplete string. This will be string16::npos if this match should 177 // autocomplete string. This will be string16::npos if this match should
160 // not be inline autocompleted. 178 // not be inline autocompleted.
161 size_t inline_autocomplete_offset; 179 size_t inline_autocomplete_offset;
162 180
163 // The URL to actually load when the autocomplete item is selected. This URL 181 // The URL to actually load when the autocomplete item is selected. This URL
164 // should be canonical so we can compare URLs with strcmp to avoid dupes. 182 // should be canonical so we can compare URLs with strcmp to avoid dupes.
165 // It may be empty if there is no possible navigation. 183 // It may be empty if there is no possible navigation.
166 GURL destination_url; 184 GURL destination_url;
167 185
186 // The destination URL with "www." stripped off for better dupe finding.
187 GURL stripped_destination_url;
188
168 // The main text displayed in the address bar dropdown. 189 // The main text displayed in the address bar dropdown.
169 string16 contents; 190 string16 contents;
170 ACMatchClassifications contents_class; 191 ACMatchClassifications contents_class;
171 192
172 // Additional helper text for each entry, such as a title or description. 193 // Additional helper text for each entry, such as a title or description.
173 string16 description; 194 string16 description;
174 ACMatchClassifications description_class; 195 ACMatchClassifications description_class;
175 196
176 // The transition type to use when the user opens this match. By default 197 // The transition type to use when the user opens this match. By default
177 // this is TYPED. Providers whose matches do not look like URLs should set 198 // this is TYPED. Providers whose matches do not look like URLs should set
178 // it to GENERATED. 199 // it to GENERATED.
179 content::PageTransition transition; 200 content::PageTransition transition;
180 201
181 // True when this match is the "what you typed" match from the history 202 // True when this match is the "what you typed" match from the history
182 // system. 203 // system.
183 bool is_history_what_you_typed_match; 204 bool is_history_what_you_typed_match;
184 205
185 // Type of this match. 206 // Type of this match.
186 Type type; 207 Type type;
187 208
209 // Set with a keyword provider match if this match can show a keyword hint.
210 // For example, if this is a SearchProvider match for "www.amazon.com",
211 // |associated_keyword| could be a KeywordProvider match for "amazon.com".
212 scoped_ptr<AutocompleteMatch> associated_keyword;
213
214 // For matches that correspond to valid substituting keywords ("search
215 // engines" that aren't the default engine, or extension keywords), this
216 // is the keyword. If this is set, then when displaying this match, the
217 // edit will use the "keyword mode" UI that shows a blue
218 // "Search <engine name>" chit before the user's typing. This should be
219 // set for any match that's an |associated_keyword| of a match in the main
220 // result list, as well as any other matches in the main result list that
221 // are direct keyword matches (e.g. if the user types in a keyword name and
222 // some search terms directly).
223 string16 keyword;
224
188 // Indicates the TemplateURL the match originated from. This is set for 225 // Indicates the TemplateURL the match originated from. This is set for
189 // keywords as well as matches for the default search provider. 226 // keywords as well as matches for the default search provider.
190 const TemplateURL* template_url; 227 const TemplateURL* template_url;
191 228
192 // True if the user has starred the destination URL. 229 // True if the user has starred the destination URL.
193 bool starred; 230 bool starred;
194 231
195 // True if this match is from a previous result. 232 // True if this match is from a previous result.
196 bool from_previous; 233 bool from_previous;
197 234
198 #ifndef NDEBUG 235 #ifndef NDEBUG
199 // Does a data integrity check on this match. 236 // Does a data integrity check on this match.
200 void Validate() const; 237 void Validate() const;
201 238
202 // Checks one text/classifications pair for valid values. 239 // Checks one text/classifications pair for valid values.
203 void ValidateClassifications( 240 void ValidateClassifications(
204 const string16& text, 241 const string16& text,
205 const ACMatchClassifications& classifications) const; 242 const ACMatchClassifications& classifications) const;
206 #endif 243 #endif
207 }; 244 };
208 245
209 typedef AutocompleteMatch::ACMatchClassification ACMatchClassification; 246 typedef AutocompleteMatch::ACMatchClassification ACMatchClassification;
210 typedef std::vector<ACMatchClassification> ACMatchClassifications; 247 typedef std::vector<ACMatchClassification> ACMatchClassifications;
211 248
212 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_ 249 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_unittest.cc ('k') | chrome/browser/autocomplete/autocomplete_match.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698