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