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 | 7 |
| 8 #include <map> |
8 #include <string> | 9 #include <string> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "chrome/browser/search_engines/template_url.h" | 13 #include "chrome/browser/search_engines/template_url.h" |
13 #include "content/public/common/page_transition_types.h" | 14 #include "content/public/common/page_transition_types.h" |
14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
15 | 16 |
16 class AutocompleteProvider; | 17 class AutocompleteProvider; |
17 class Profile; | 18 class Profile; |
18 class TemplateURL; | 19 class TemplateURL; |
19 | 20 |
| 21 namespace base { |
| 22 class Time; |
| 23 } // namespace base |
| 24 |
20 // AutocompleteMatch ---------------------------------------------------------- | 25 // AutocompleteMatch ---------------------------------------------------------- |
21 | 26 |
22 // A single result line with classified spans. The autocomplete popup displays | 27 // A single result line with classified spans. The autocomplete popup displays |
23 // the 'contents' and the 'description' (the description is optional) in the | 28 // the 'contents' and the 'description' (the description is optional) in the |
24 // autocomplete dropdown, and fills in 'fill_into_edit' into the textbox when | 29 // autocomplete dropdown, and fills in 'fill_into_edit' into the textbox when |
25 // that line is selected. fill_into_edit may be the same as 'description' for | 30 // that line is selected. fill_into_edit may be the same as 'description' for |
26 // things like URLs, but may be different for searches or other providers. For | 31 // things like URLs, but may be different for searches or other providers. For |
27 // example, a search result may say "Search for asdf" as the description, but | 32 // example, a search result may say "Search for asdf" as the description, but |
28 // "asdf" should appear in the box. | 33 // "asdf" should appear in the box. |
29 struct AutocompleteMatch { | 34 struct AutocompleteMatch { |
(...skipping 27 matching lines...) Expand all Loading... |
57 } | 62 } |
58 | 63 |
59 // Offset within the string that this classification starts | 64 // Offset within the string that this classification starts |
60 size_t offset; | 65 size_t offset; |
61 | 66 |
62 int style; | 67 int style; |
63 }; | 68 }; |
64 | 69 |
65 typedef std::vector<ACMatchClassification> ACMatchClassifications; | 70 typedef std::vector<ACMatchClassification> ACMatchClassifications; |
66 | 71 |
| 72 // Type used by providers to attach additional, optional information to |
| 73 // an AutocompleteMatch. |
| 74 typedef std::map<std::string, std::string> AdditionalInfo; |
| 75 |
67 // The type of this match. | 76 // The type of this match. |
68 enum Type { | 77 enum Type { |
69 URL_WHAT_YOU_TYPED = 0, // The input as a URL. | 78 URL_WHAT_YOU_TYPED = 0, // The input as a URL. |
70 HISTORY_URL, // A past page whose URL contains the input. | 79 HISTORY_URL, // A past page whose URL contains the input. |
71 HISTORY_TITLE, // A past page whose title contains the input. | 80 HISTORY_TITLE, // A past page whose title contains the input. |
72 HISTORY_BODY, // A past page whose body contains the input. | 81 HISTORY_BODY, // A past page whose body contains the input. |
73 HISTORY_KEYWORD, // A past page whose keyword contains the input. | 82 HISTORY_KEYWORD, // A past page whose keyword contains the input. |
74 NAVSUGGEST, // A suggested URL. | 83 NAVSUGGEST, // A suggested URL. |
75 SEARCH_WHAT_YOU_TYPED, // The input as a search query (with the default | 84 SEARCH_WHAT_YOU_TYPED, // The input as a search query (with the default |
76 // engine). | 85 // engine). |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // invoke its keyword), this returns the empty string. The result is that | 191 // invoke its keyword), this returns the empty string. The result is that |
183 // this function returns a non-empty string in the same cases as when the UI | 192 // this function returns a non-empty string in the same cases as when the UI |
184 // should show up as being "in keyword mode". | 193 // should show up as being "in keyword mode". |
185 string16 GetSubstitutingExplicitlyInvokedKeyword(Profile* profile) const; | 194 string16 GetSubstitutingExplicitlyInvokedKeyword(Profile* profile) const; |
186 | 195 |
187 // Returns the TemplateURL associated with this match. This may be NULL if | 196 // Returns the TemplateURL associated with this match. This may be NULL if |
188 // the match has no keyword OR if the keyword no longer corresponds to a valid | 197 // the match has no keyword OR if the keyword no longer corresponds to a valid |
189 // TemplateURL. See comments on |keyword| below. | 198 // TemplateURL. See comments on |keyword| below. |
190 TemplateURL* GetTemplateURL(Profile* profile) const; | 199 TemplateURL* GetTemplateURL(Profile* profile) const; |
191 | 200 |
| 201 // Adds optional information to the |additional_info| dictionary. |
| 202 void RecordAdditionalInfo(const std::string& property, |
| 203 const std::string& value); |
| 204 void RecordAdditionalInfo(const std::string& property, int value); |
| 205 void RecordAdditionalInfo(const std::string& property, |
| 206 const base::Time& value); |
| 207 |
192 // The provider of this match, used to remember which provider the user had | 208 // The provider of this match, used to remember which provider the user had |
193 // selected when the input changes. This may be NULL, in which case there is | 209 // selected when the input changes. This may be NULL, in which case there is |
194 // no provider (or memory of the user's selection). | 210 // no provider (or memory of the user's selection). |
195 AutocompleteProvider* provider; | 211 AutocompleteProvider* provider; |
196 | 212 |
197 // The relevance of this match. See table in autocomplete.h for scores | 213 // The relevance of this match. See table in autocomplete.h for scores |
198 // returned by various providers. This is used to rank matches among all | 214 // returned by various providers. This is used to rank matches among all |
199 // responding providers, so different providers must be carefully tuned to | 215 // responding providers, so different providers must be carefully tuned to |
200 // supply matches with appropriate relevance. | 216 // supply matches with appropriate relevance. |
201 // | 217 // |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 292 |
277 // Optional search terms args. If present, | 293 // Optional search terms args. If present, |
278 // AutocompleteController::UpdateAssistedQueryStats() will incorporate this | 294 // AutocompleteController::UpdateAssistedQueryStats() will incorporate this |
279 // data with additional data it calculates and pass the completed struct to | 295 // data with additional data it calculates and pass the completed struct to |
280 // TemplateURLRef::ReplaceSearchTerms() to reset the match's |destination_url| | 296 // TemplateURLRef::ReplaceSearchTerms() to reset the match's |destination_url| |
281 // after the complete set of matches in the AutocompleteResult has been chosen | 297 // after the complete set of matches in the AutocompleteResult has been chosen |
282 // and sorted. Most providers will leave this as NULL, which will cause the | 298 // and sorted. Most providers will leave this as NULL, which will cause the |
283 // AutocompleteController to do no additional transformations. | 299 // AutocompleteController to do no additional transformations. |
284 scoped_ptr<TemplateURLRef::SearchTermsArgs> search_terms_args; | 300 scoped_ptr<TemplateURLRef::SearchTermsArgs> search_terms_args; |
285 | 301 |
| 302 // Information dictionary into which each provider can optionally record a |
| 303 // property and associated value and which is presented in chrome://omnibox. |
| 304 AdditionalInfo additional_info; |
| 305 |
286 #ifndef NDEBUG | 306 #ifndef NDEBUG |
287 // Does a data integrity check on this match. | 307 // Does a data integrity check on this match. |
288 void Validate() const; | 308 void Validate() const; |
289 | 309 |
290 // Checks one text/classifications pair for valid values. | 310 // Checks one text/classifications pair for valid values. |
291 void ValidateClassifications( | 311 void ValidateClassifications( |
292 const string16& text, | 312 const string16& text, |
293 const ACMatchClassifications& classifications) const; | 313 const ACMatchClassifications& classifications) const; |
294 #endif | 314 #endif |
295 }; | 315 }; |
296 | 316 |
297 typedef AutocompleteMatch::ACMatchClassification ACMatchClassification; | 317 typedef AutocompleteMatch::ACMatchClassification ACMatchClassification; |
298 typedef std::vector<ACMatchClassification> ACMatchClassifications; | 318 typedef std::vector<ACMatchClassification> ACMatchClassifications; |
299 typedef std::vector<AutocompleteMatch> ACMatches; | 319 typedef std::vector<AutocompleteMatch> ACMatches; |
300 | 320 |
301 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_ | 321 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_ |
OLD | NEW |