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

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

Issue 105193002: Replace string16 with base::string16. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // destinations are expected for non-navigable matches. 110 // destinations are expected for non-navigable matches.
111 static bool DestinationSortFunc(const AutocompleteMatch& elem1, 111 static bool DestinationSortFunc(const AutocompleteMatch& elem1,
112 const AutocompleteMatch& elem2); 112 const AutocompleteMatch& elem2);
113 static bool DestinationsEqual(const AutocompleteMatch& elem1, 113 static bool DestinationsEqual(const AutocompleteMatch& elem1,
114 const AutocompleteMatch& elem2); 114 const AutocompleteMatch& elem2);
115 115
116 // Helper functions for classes creating matches: 116 // Helper functions for classes creating matches:
117 // Fills in the classifications for |text|, using |style| as the base style 117 // Fills in the classifications for |text|, using |style| as the base style
118 // and marking the first instance of |find_text| as a match. (This match 118 // and marking the first instance of |find_text| as a match. (This match
119 // will also not be dimmed, if |style| has DIM set.) 119 // will also not be dimmed, if |style| has DIM set.)
120 static void ClassifyMatchInString(const string16& find_text, 120 static void ClassifyMatchInString(const base::string16& find_text,
121 const string16& text, 121 const base::string16& text,
122 int style, 122 int style,
123 ACMatchClassifications* classifications); 123 ACMatchClassifications* classifications);
124 124
125 // Similar to ClassifyMatchInString(), but for cases where the range to mark 125 // Similar to ClassifyMatchInString(), but for cases where the range to mark
126 // as matching is already known (avoids calling find()). This can be helpful 126 // as matching is already known (avoids calling find()). This can be helpful
127 // when find() would be misleading (e.g. you want to mark the second match in 127 // when find() would be misleading (e.g. you want to mark the second match in
128 // a string instead of the first). 128 // a string instead of the first).
129 static void ClassifyLocationInString(size_t match_location, 129 static void ClassifyLocationInString(size_t match_location,
130 size_t match_length, 130 size_t match_length,
131 size_t overall_length, 131 size_t overall_length,
(...skipping 17 matching lines...) Expand all
149 // different from the last existing classification. |offset| must be larger 149 // different from the last existing classification. |offset| must be larger
150 // than the offset of the last classification in |classifications|. 150 // than the offset of the last classification in |classifications|.
151 static void AddLastClassificationIfNecessary( 151 static void AddLastClassificationIfNecessary(
152 ACMatchClassifications* classifications, 152 ACMatchClassifications* classifications,
153 size_t offset, 153 size_t offset,
154 int style); 154 int style);
155 155
156 // Removes invalid characters from |text|. Should be called on strings coming 156 // Removes invalid characters from |text|. Should be called on strings coming
157 // from external sources (such as extensions) before assigning to |contents| 157 // from external sources (such as extensions) before assigning to |contents|
158 // or |description|. 158 // or |description|.
159 static string16 SanitizeString(const string16& text); 159 static base::string16 SanitizeString(const base::string16& text);
160 160
161 // Convenience function to check if |type| is a search (as opposed to a URL or 161 // Convenience function to check if |type| is a search (as opposed to a URL or
162 // an extension). 162 // an extension).
163 static bool IsSearchType(Type type); 163 static bool IsSearchType(Type type);
164 164
165 // Copies the destination_url with "www." stripped off to 165 // Copies the destination_url with "www." stripped off to
166 // |stripped_destination_url| and also converts https protocol to 166 // |stripped_destination_url| and also converts https protocol to
167 // http. These two conversions are merely to allow comparisons to 167 // http. These two conversions are merely to allow comparisons to
168 // remove likely duplicates; these URLs are not used as actual 168 // remove likely duplicates; these URLs are not used as actual
169 // destination URLs. This method is invoked internally by the 169 // destination URLs. This method is invoked internally by the
(...skipping 10 matching lines...) Expand all
180 // and |is_keyword_hint| will be set to false. If this match has a non-NULL 180 // and |is_keyword_hint| will be set to false. If this match has a non-NULL
181 // |associated_keyword|, i.e. we should show a "Press [tab] to search ___" 181 // |associated_keyword|, i.e. we should show a "Press [tab] to search ___"
182 // hint and allow the user to toggle into keyword mode, |keyword| will be set 182 // hint and allow the user to toggle into keyword mode, |keyword| will be set
183 // to the associated keyword and |is_keyword_hint| will be set to true. Note 183 // to the associated keyword and |is_keyword_hint| will be set to true. Note
184 // that only one of these states can be in effect at once. In all other 184 // that only one of these states can be in effect at once. In all other
185 // cases, |keyword| will be cleared, even when our member variable |keyword| 185 // cases, |keyword| will be cleared, even when our member variable |keyword|
186 // is non-empty -- such as with non-substituting keywords or matches that 186 // is non-empty -- such as with non-substituting keywords or matches that
187 // represent searches using the default search engine. See also 187 // represent searches using the default search engine. See also
188 // GetSubstitutingExplicitlyInvokedKeyword(). 188 // GetSubstitutingExplicitlyInvokedKeyword().
189 void GetKeywordUIState(Profile* profile, 189 void GetKeywordUIState(Profile* profile,
190 string16* keyword, 190 base::string16* keyword,
191 bool* is_keyword_hint) const; 191 bool* is_keyword_hint) const;
192 192
193 // Returns |keyword|, but only if it represents a substituting keyword that 193 // Returns |keyword|, but only if it represents a substituting keyword that
194 // the user has explicitly invoked. If for example this match represents a 194 // the user has explicitly invoked. If for example this match represents a
195 // search with the default search engine (and the user didn't explicitly 195 // search with the default search engine (and the user didn't explicitly
196 // invoke its keyword), this returns the empty string. The result is that 196 // invoke its keyword), this returns the empty string. The result is that
197 // this function returns a non-empty string in the same cases as when the UI 197 // this function returns a non-empty string in the same cases as when the UI
198 // should show up as being "in keyword mode". 198 // should show up as being "in keyword mode".
199 string16 GetSubstitutingExplicitlyInvokedKeyword(Profile* profile) const; 199 base::string16 GetSubstitutingExplicitlyInvokedKeyword(
200 Profile* profile) const;
200 201
201 // Returns the TemplateURL associated with this match. This may be NULL if 202 // Returns the TemplateURL associated with this match. This may be NULL if
202 // the match has no keyword OR if the keyword no longer corresponds to a valid 203 // the match has no keyword OR if the keyword no longer corresponds to a valid
203 // TemplateURL. See comments on |keyword| below. 204 // TemplateURL. See comments on |keyword| below.
204 // If |allow_fallback_to_destination_host| is true and the keyword does 205 // If |allow_fallback_to_destination_host| is true and the keyword does
205 // not map to a valid TemplateURL, we'll then check for a TemplateURL that 206 // not map to a valid TemplateURL, we'll then check for a TemplateURL that
206 // corresponds to the destination_url's hostname. 207 // corresponds to the destination_url's hostname.
207 TemplateURL* GetTemplateURL(Profile* profile, 208 TemplateURL* GetTemplateURL(Profile* profile,
208 bool allow_fallback_to_destination_host) const; 209 bool allow_fallback_to_destination_host) const;
209 210
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 // its value is -1. At the time of writing this comment, it is only 248 // its value is -1. At the time of writing this comment, it is only
248 // set for matches from HistoryURL and HistoryQuickProvider. 249 // set for matches from HistoryURL and HistoryQuickProvider.
249 int typed_count; 250 int typed_count;
250 251
251 // True if the user should be able to delete this match. 252 // True if the user should be able to delete this match.
252 bool deletable; 253 bool deletable;
253 254
254 // This string is loaded into the location bar when the item is selected 255 // This string is loaded into the location bar when the item is selected
255 // by pressing the arrow keys. This may be different than a URL, for example, 256 // by pressing the arrow keys. This may be different than a URL, for example,
256 // for search suggestions, this would just be the search terms. 257 // for search suggestions, this would just be the search terms.
257 string16 fill_into_edit; 258 base::string16 fill_into_edit;
258 259
259 // The inline autocompletion to display after the user's typing in the 260 // The inline autocompletion to display after the user's typing in the
260 // omnibox, if this match becomes the default match. It may be empty. 261 // omnibox, if this match becomes the default match. It may be empty.
261 string16 inline_autocompletion; 262 base::string16 inline_autocompletion;
262 263
263 // If false, the omnibox should prevent this match from being the 264 // If false, the omnibox should prevent this match from being the
264 // default match. Providers should set this to true only if the 265 // default match. Providers should set this to true only if the
265 // user's input, plus any inline autocompletion on this match, would 266 // user's input, plus any inline autocompletion on this match, would
266 // lead the user to expect a navigation to this match's destination. 267 // lead the user to expect a navigation to this match's destination.
267 // For example, with input "foo", a search for "bar" or navigation 268 // For example, with input "foo", a search for "bar" or navigation
268 // to "bar.com" should not set this flag; a navigation to "foo.com" 269 // to "bar.com" should not set this flag; a navigation to "foo.com"
269 // should only set this flag if ".com" will be inline autocompleted; 270 // should only set this flag if ".com" will be inline autocompleted;
270 // and a navigation to "foo/" (an intranet host) or search for "foo" 271 // and a navigation to "foo/" (an intranet host) or search for "foo"
271 // should set this flag. 272 // should set this flag.
272 bool allowed_to_be_default_match; 273 bool allowed_to_be_default_match;
273 274
274 // The URL to actually load when the autocomplete item is selected. This URL 275 // The URL to actually load when the autocomplete item is selected. This URL
275 // should be canonical so we can compare URLs with strcmp to avoid dupes. 276 // should be canonical so we can compare URLs with strcmp to avoid dupes.
276 // It may be empty if there is no possible navigation. 277 // It may be empty if there is no possible navigation.
277 GURL destination_url; 278 GURL destination_url;
278 279
279 // The destination URL with "www." stripped off for better dupe finding. 280 // The destination URL with "www." stripped off for better dupe finding.
280 GURL stripped_destination_url; 281 GURL stripped_destination_url;
281 282
282 // The main text displayed in the address bar dropdown. 283 // The main text displayed in the address bar dropdown.
283 string16 contents; 284 base::string16 contents;
284 ACMatchClassifications contents_class; 285 ACMatchClassifications contents_class;
285 286
286 // Additional helper text for each entry, such as a title or description. 287 // Additional helper text for each entry, such as a title or description.
287 string16 description; 288 base::string16 description;
288 ACMatchClassifications description_class; 289 ACMatchClassifications description_class;
289 290
290 // The transition type to use when the user opens this match. By default 291 // The transition type to use when the user opens this match. By default
291 // this is TYPED. Providers whose matches do not look like URLs should set 292 // this is TYPED. Providers whose matches do not look like URLs should set
292 // it to GENERATED. 293 // it to GENERATED.
293 content::PageTransition transition; 294 content::PageTransition transition;
294 295
295 // True when this match is the "what you typed" match from the history 296 // True when this match is the "what you typed" match from the history
296 // system. 297 // system.
297 bool is_history_what_you_typed_match; 298 bool is_history_what_you_typed_match;
(...skipping 10 matching lines...) Expand all
308 // for both explicit "keyword mode" matches as well as matches for the default 309 // for both explicit "keyword mode" matches as well as matches for the default
309 // search provider (so, any match for which we're doing substitution); it 310 // search provider (so, any match for which we're doing substitution); it
310 // doesn't imply (alone) that the UI is going to show a keyword hint or 311 // doesn't imply (alone) that the UI is going to show a keyword hint or
311 // keyword mode. For that, see GetKeywordUIState() or 312 // keyword mode. For that, see GetKeywordUIState() or
312 // GetSubstitutingExplicitlyInvokedKeyword(). 313 // GetSubstitutingExplicitlyInvokedKeyword().
313 // 314 //
314 // CAUTION: The TemplateURL associated with this keyword may be deleted or 315 // CAUTION: The TemplateURL associated with this keyword may be deleted or
315 // modified while the AutocompleteMatch is alive. This means anyone who 316 // modified while the AutocompleteMatch is alive. This means anyone who
316 // accesses it must perform any necessary sanity checks before blindly using 317 // accesses it must perform any necessary sanity checks before blindly using
317 // it! 318 // it!
318 string16 keyword; 319 base::string16 keyword;
319 320
320 // True if the user has starred the destination URL. 321 // True if the user has starred the destination URL.
321 bool starred; 322 bool starred;
322 323
323 // True if this match is from a previous result. 324 // True if this match is from a previous result.
324 bool from_previous; 325 bool from_previous;
325 326
326 // Optional search terms args. If present, 327 // Optional search terms args. If present,
327 // AutocompleteController::UpdateAssistedQueryStats() will incorporate this 328 // AutocompleteController::UpdateAssistedQueryStats() will incorporate this
328 // data with additional data it calculates and pass the completed struct to 329 // data with additional data it calculates and pass the completed struct to
329 // TemplateURLRef::ReplaceSearchTerms() to reset the match's |destination_url| 330 // TemplateURLRef::ReplaceSearchTerms() to reset the match's |destination_url|
330 // after the complete set of matches in the AutocompleteResult has been chosen 331 // after the complete set of matches in the AutocompleteResult has been chosen
331 // and sorted. Most providers will leave this as NULL, which will cause the 332 // and sorted. Most providers will leave this as NULL, which will cause the
332 // AutocompleteController to do no additional transformations. 333 // AutocompleteController to do no additional transformations.
333 scoped_ptr<TemplateURLRef::SearchTermsArgs> search_terms_args; 334 scoped_ptr<TemplateURLRef::SearchTermsArgs> search_terms_args;
334 335
335 // Information dictionary into which each provider can optionally record a 336 // Information dictionary into which each provider can optionally record a
336 // property and associated value and which is presented in chrome://omnibox. 337 // property and associated value and which is presented in chrome://omnibox.
337 AdditionalInfo additional_info; 338 AdditionalInfo additional_info;
338 339
339 #ifndef NDEBUG 340 #ifndef NDEBUG
340 // Does a data integrity check on this match. 341 // Does a data integrity check on this match.
341 void Validate() const; 342 void Validate() const;
342 343
343 // Checks one text/classifications pair for valid values. 344 // Checks one text/classifications pair for valid values.
344 void ValidateClassifications( 345 void ValidateClassifications(
345 const string16& text, 346 const base::string16& text,
346 const ACMatchClassifications& classifications) const; 347 const ACMatchClassifications& classifications) const;
347 #endif 348 #endif
348 }; 349 };
349 350
350 typedef AutocompleteMatch::ACMatchClassification ACMatchClassification; 351 typedef AutocompleteMatch::ACMatchClassification ACMatchClassification;
351 typedef std::vector<ACMatchClassification> ACMatchClassifications; 352 typedef std::vector<ACMatchClassification> ACMatchClassifications;
352 typedef std::vector<AutocompleteMatch> ACMatches; 353 typedef std::vector<AutocompleteMatch> ACMatches;
353 354
354 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_ 355 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_input_unittest.cc ('k') | chrome/browser/autocomplete/autocomplete_match.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698