OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/ref_counted.h" | |
12 #include "content/common/page_transition_types.h" | 13 #include "content/common/page_transition_types.h" |
13 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 #include "chrome/browser/profiles/profile.h" | |
Peter Kasting
2011/04/07 20:19:21
Nit: #includes in alphabetical order
| |
14 | 16 |
15 class AutocompleteProvider; | 17 class AutocompleteProvider; |
16 class PageTransition; | 18 class PageTransition; |
17 class TemplateURL; | 19 class TemplateURL; |
18 | 20 |
19 // AutocompleteMatch ---------------------------------------------------------- | 21 // AutocompleteMatch ---------------------------------------------------------- |
20 | 22 |
21 // A single result line with classified spans. The autocomplete popup displays | 23 // A single result line with classified spans. The autocomplete popup displays |
22 // the 'contents' and the 'description' (the description is optional) in the | 24 // the 'contents' and the 'description' (the description is optional) in the |
23 // autocomplete dropdown, and fills in 'fill_into_edit' into the textbox when | 25 // autocomplete dropdown, and fills in 'fill_into_edit' into the textbox when |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 } | 58 } |
57 | 59 |
58 // Offset within the string that this classification starts | 60 // Offset within the string that this classification starts |
59 size_t offset; | 61 size_t offset; |
60 | 62 |
61 int style; | 63 int style; |
62 }; | 64 }; |
63 | 65 |
64 typedef std::vector<ACMatchClassification> ACMatchClassifications; | 66 typedef std::vector<ACMatchClassification> ACMatchClassifications; |
65 | 67 |
68 struct Keyword : public base::RefCounted<Keyword> { | |
69 Keyword() | |
70 : is_keyword_hint(false), is_keyword_mode(false) { | |
71 } | |
72 | |
73 string16 text; | |
74 | |
75 const TemplateURL* template_url; | |
76 | |
77 // True if this match should show a keyword hint. | |
78 bool is_keyword_hint; | |
79 | |
80 // True if the keyword has been accepted or if the default | |
81 // is to show keyword mode. | |
82 bool is_keyword_mode; | |
83 | |
Peter Kasting
2011/04/07 20:19:21
Nit: Extra newline
| |
84 }; | |
85 | |
66 // The type of this match. | 86 // The type of this match. |
67 enum Type { | 87 enum Type { |
68 URL_WHAT_YOU_TYPED = 0, // The input as a URL. | 88 URL_WHAT_YOU_TYPED = 0, // The input as a URL. |
69 HISTORY_URL, // A past page whose URL contains the input. | 89 HISTORY_URL, // A past page whose URL contains the input. |
70 HISTORY_TITLE, // A past page whose title contains the input. | 90 HISTORY_TITLE, // A past page whose title contains the input. |
71 HISTORY_BODY, // A past page whose body contains the input. | 91 HISTORY_BODY, // A past page whose body contains the input. |
72 HISTORY_KEYWORD, // A past page whose keyword contains the input. | 92 HISTORY_KEYWORD, // A past page whose keyword contains the input. |
73 NAVSUGGEST, // A suggested URL. | 93 NAVSUGGEST, // A suggested URL. |
74 SEARCH_WHAT_YOU_TYPED, // The input as a search query (with the default | 94 SEARCH_WHAT_YOU_TYPED, // The input as a search query (with the default |
75 // engine). | 95 // engine). |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 // Similar to ClassifyMatchInString(), but for cases where the range to mark | 136 // Similar to ClassifyMatchInString(), but for cases where the range to mark |
117 // as matching is already known (avoids calling find()). This can be helpful | 137 // as matching is already known (avoids calling find()). This can be helpful |
118 // when find() would be misleading (e.g. you want to mark the second match in | 138 // when find() would be misleading (e.g. you want to mark the second match in |
119 // a string instead of the first). | 139 // a string instead of the first). |
120 static void ClassifyLocationInString(size_t match_location, | 140 static void ClassifyLocationInString(size_t match_location, |
121 size_t match_length, | 141 size_t match_length, |
122 size_t overall_length, | 142 size_t overall_length, |
123 int style, | 143 int style, |
124 ACMatchClassifications* classifications); | 144 ACMatchClassifications* classifications); |
125 | 145 |
146 // Copies the destination_url with "www." stripped off to | |
147 // destination_url_normalized | |
148 void ComputeStrippedDestinationURL(); | |
149 | |
126 // The provider of this match, used to remember which provider the user had | 150 // The provider of this match, used to remember which provider the user had |
127 // selected when the input changes. This may be NULL, in which case there is | 151 // selected when the input changes. This may be NULL, in which case there is |
128 // no provider (or memory of the user's selection). | 152 // no provider (or memory of the user's selection). |
129 AutocompleteProvider* provider; | 153 AutocompleteProvider* provider; |
130 | 154 |
131 // The relevance of this match. See table above for scores returned by | 155 // The relevance of this match. See table above for scores returned by |
132 // various providers. This is used to rank matches among all responding | 156 // various providers. This is used to rank matches among all responding |
133 // providers, so different providers must be carefully tuned to supply | 157 // providers, so different providers must be carefully tuned to supply |
134 // matches with appropriate relevance. | 158 // matches with appropriate relevance. |
135 // | 159 // |
(...skipping 12 matching lines...) Expand all Loading... | |
148 // The position within fill_into_edit from which we'll display the inline | 172 // The position within fill_into_edit from which we'll display the inline |
149 // autocomplete string. This will be string16::npos if this match should | 173 // autocomplete string. This will be string16::npos if this match should |
150 // not be inline autocompleted. | 174 // not be inline autocompleted. |
151 size_t inline_autocomplete_offset; | 175 size_t inline_autocomplete_offset; |
152 | 176 |
153 // The URL to actually load when the autocomplete item is selected. This URL | 177 // The URL to actually load when the autocomplete item is selected. This URL |
154 // should be canonical so we can compare URLs with strcmp to avoid dupes. | 178 // should be canonical so we can compare URLs with strcmp to avoid dupes. |
155 // It may be empty if there is no possible navigation. | 179 // It may be empty if there is no possible navigation. |
156 GURL destination_url; | 180 GURL destination_url; |
157 | 181 |
182 // The destination URL with "www." stripped off for better dupe finding. | |
183 GURL destination_url_normalized; | |
Peter Kasting
2011/04/07 20:19:21
Nit: How about |stripped_destination_url| then?
| |
184 | |
158 // The main text displayed in the address bar dropdown. | 185 // The main text displayed in the address bar dropdown. |
159 string16 contents; | 186 string16 contents; |
160 ACMatchClassifications contents_class; | 187 ACMatchClassifications contents_class; |
161 | 188 |
162 // Additional helper text for each entry, such as a title or description. | 189 // Additional helper text for each entry, such as a title or description. |
163 string16 description; | 190 string16 description; |
164 ACMatchClassifications description_class; | 191 ACMatchClassifications description_class; |
165 | 192 |
166 // The transition type to use when the user opens this match. By default | 193 // The transition type to use when the user opens this match. By default |
167 // this is TYPED. Providers whose matches do not look like URLs should set | 194 // this is TYPED. Providers whose matches do not look like URLs should set |
168 // it to GENERATED. | 195 // it to GENERATED. |
169 PageTransition::Type transition; | 196 PageTransition::Type transition; |
170 | 197 |
171 // True when this match is the "what you typed" match from the history | 198 // True when this match is the "what you typed" match from the history |
172 // system. | 199 // system. |
173 bool is_history_what_you_typed_match; | 200 bool is_history_what_you_typed_match; |
174 | 201 |
175 // Type of this match. | 202 // Type of this match. |
176 Type type; | 203 Type type; |
177 | 204 |
178 // If this match corresponds to a keyword, this is the TemplateURL the | 205 // If this match corresponds to a keyword, this is the TemplateURL the |
179 // keyword was obtained from. | 206 // keyword was obtained from. |
180 const TemplateURL* template_url; | 207 const TemplateURL* template_url; |
181 | 208 |
209 // Keyword for this match | |
210 scoped_refptr<Keyword> keyword; | |
211 | |
182 // True if the user has starred the destination URL. | 212 // True if the user has starred the destination URL. |
183 bool starred; | 213 bool starred; |
184 | 214 |
185 // True if this match is from a previous result. | 215 // True if this match is from a previous result. |
186 bool from_previous; | 216 bool from_previous; |
187 | 217 |
188 #ifndef NDEBUG | 218 #ifndef NDEBUG |
189 // Does a data integrity check on this match. | 219 // Does a data integrity check on this match. |
190 void Validate() const; | 220 void Validate() const; |
191 | 221 |
192 // Checks one text/classifications pair for valid values. | 222 // Checks one text/classifications pair for valid values. |
193 void ValidateClassifications( | 223 void ValidateClassifications( |
194 const string16& text, | 224 const string16& text, |
195 const ACMatchClassifications& classifications) const; | 225 const ACMatchClassifications& classifications) const; |
196 #endif | 226 #endif |
197 }; | 227 }; |
198 | 228 |
199 typedef AutocompleteMatch::ACMatchClassification ACMatchClassification; | 229 typedef AutocompleteMatch::ACMatchClassification ACMatchClassification; |
200 typedef std::vector<ACMatchClassification> ACMatchClassifications; | 230 typedef std::vector<ACMatchClassification> ACMatchClassifications; |
201 | 231 |
202 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_ | 232 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_ |
OLD | NEW |