OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" | |
13 #include "chrome/browser/profiles/profile.h" | |
12 #include "content/common/page_transition_types.h" | 14 #include "content/common/page_transition_types.h" |
13 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
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 |
(...skipping 34 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(const string16& keyword_text, bool keyword_hint, bool keyword_mode) | |
70 : text(keyword_text), is_keyword_hint(keyword_hint), | |
71 is_keyword_mode(keyword_mode) { | |
72 } | |
73 | |
74 string16 text; | |
75 | |
76 const TemplateURL* template_url; | |
77 | |
78 // True if this match should show a keyword hint. | |
79 bool is_keyword_hint; | |
80 | |
81 // True if the keyword has been accepted or if the default | |
82 // is to show keyword mode. | |
83 bool is_keyword_mode; | |
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 15 matching lines...) Expand all Loading... | |
91 static std::string TypeToString(Type type); | 111 static std::string TypeToString(Type type); |
92 | 112 |
93 // Converts |type| to a resource identifier for the appropriate icon for this | 113 // Converts |type| to a resource identifier for the appropriate icon for this |
94 // type. | 114 // type. |
95 static int TypeToIcon(Type type); | 115 static int TypeToIcon(Type type); |
96 | 116 |
97 // Comparison function for determining when one match is better than another. | 117 // Comparison function for determining when one match is better than another. |
98 static bool MoreRelevant(const AutocompleteMatch& elem1, | 118 static bool MoreRelevant(const AutocompleteMatch& elem1, |
99 const AutocompleteMatch& elem2); | 119 const AutocompleteMatch& elem2); |
100 | 120 |
101 // Comparison functions for removing matches with duplicate destinations. | 121 // Comparison functions for removing matches with duplicate destinations. |
Peter Kasting
2011/04/11 23:17:33
Nit: You should document and/or name the functions
| |
102 static bool DestinationSortFunc(const AutocompleteMatch& elem1, | 122 static bool DestinationSortFunc(const AutocompleteMatch& elem1, |
103 const AutocompleteMatch& elem2); | 123 const AutocompleteMatch& elem2); |
104 static bool DestinationsEqual(const AutocompleteMatch& elem1, | 124 static bool DestinationsEqual(const AutocompleteMatch& elem1, |
105 const AutocompleteMatch& elem2); | 125 const AutocompleteMatch& elem2); |
106 | 126 |
107 // Helper functions for classes creating matches: | 127 // Helper functions for classes creating matches: |
108 // Fills in the classifications for |text|, using |style| as the base style | 128 // Fills in the classifications for |text|, using |style| as the base style |
109 // and marking the first instance of |find_text| as a match. (This match | 129 // and marking the first instance of |find_text| as a match. (This match |
110 // will also not be dimmed, if |style| has DIM set.) | 130 // will also not be dimmed, if |style| has DIM set.) |
111 static void ClassifyMatchInString(const string16& find_text, | 131 static void ClassifyMatchInString(const string16& find_text, |
112 const string16& text, | 132 const string16& text, |
113 int style, | 133 int style, |
114 ACMatchClassifications* classifications); | 134 ACMatchClassifications* classifications); |
115 | 135 |
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 // stripped_destination_url | |
Peter Kasting
2011/04/11 23:17:33
Nit: Add trailing period. I suggest using || arou
| |
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 in autocomplete.h for scores | 155 // The relevance of this match. See table in autocomplete.h for scores |
132 // returned by various providers. This is used to rank matches among all | 156 // returned by various providers. This is used to rank matches among all |
133 // responding providers, so different providers must be carefully tuned to | 157 // responding providers, so different providers must be carefully tuned to |
134 // supply matches with appropriate relevance. | 158 // supply 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 stripped_destination_url; | |
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 |