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> |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 | 96 |
97 // Comparison function for determining when one match is better than another. | 97 // Comparison function for determining when one match is better than another. |
98 static bool MoreRelevant(const AutocompleteMatch& elem1, | 98 static bool MoreRelevant(const AutocompleteMatch& elem1, |
99 const AutocompleteMatch& elem2); | 99 const AutocompleteMatch& elem2); |
100 | 100 |
101 // Comparison functions for removing matches with duplicate destinations. | 101 // Comparison functions for removing matches with duplicate destinations. |
102 static bool DestinationSortFunc(const AutocompleteMatch& elem1, | 102 static bool DestinationSortFunc(const AutocompleteMatch& elem1, |
103 const AutocompleteMatch& elem2); | 103 const AutocompleteMatch& elem2); |
104 static bool DestinationsEqual(const AutocompleteMatch& elem1, | 104 static bool DestinationsEqual(const AutocompleteMatch& elem1, |
105 const AutocompleteMatch& elem2); | 105 const AutocompleteMatch& elem2); |
106 static bool NormalizedSortFunc(const AutocompleteMatch& elem1, | |
107 const AutocompleteMatch& elem2); | |
108 static bool NormalizedEqual(const AutocompleteMatch& elem1, | |
109 const AutocompleteMatch& elem2); | |
110 | |
111 // Comparison function for finding duplicate keywords | |
112 static bool KeywordsEqual(const AutocompleteMatch& elem1, | |
113 const AutocompleteMatch& elem2); | |
106 | 114 |
107 // Helper functions for classes creating matches: | 115 // Helper functions for classes creating matches: |
108 // Fills in the classifications for |text|, using |style| as the base style | 116 // 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 | 117 // and marking the first instance of |find_text| as a match. (This match |
110 // will also not be dimmed, if |style| has DIM set.) | 118 // will also not be dimmed, if |style| has DIM set.) |
111 static void ClassifyMatchInString(const string16& find_text, | 119 static void ClassifyMatchInString(const string16& find_text, |
112 const string16& text, | 120 const string16& text, |
113 int style, | 121 int style, |
114 ACMatchClassifications* classifications); | 122 ACMatchClassifications* classifications); |
115 | 123 |
116 // Similar to ClassifyMatchInString(), but for cases where the range to mark | 124 // Similar to ClassifyMatchInString(), but for cases where the range to mark |
117 // as matching is already known (avoids calling find()). This can be helpful | 125 // 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 | 126 // when find() would be misleading (e.g. you want to mark the second match in |
119 // a string instead of the first). | 127 // a string instead of the first). |
120 static void ClassifyLocationInString(size_t match_location, | 128 static void ClassifyLocationInString(size_t match_location, |
121 size_t match_length, | 129 size_t match_length, |
122 size_t overall_length, | 130 size_t overall_length, |
123 int style, | 131 int style, |
124 ACMatchClassifications* classifications); | 132 ACMatchClassifications* classifications); |
125 | 133 |
134 // Copies the destination_url with "www." stripped off to normalized_url | |
135 void NormalizeDestination(); | |
Peter Kasting
2011/04/01 00:09:09
Nit: Perhaps "void ComputeStrippedDestinationURL()
| |
136 | |
126 // The provider of this match, used to remember which provider the user had | 137 // 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 | 138 // selected when the input changes. This may be NULL, in which case there is |
128 // no provider (or memory of the user's selection). | 139 // no provider (or memory of the user's selection). |
129 AutocompleteProvider* provider; | 140 AutocompleteProvider* provider; |
130 | 141 |
131 // The relevance of this match. See table above for scores returned by | 142 // The relevance of this match. See table above for scores returned by |
132 // various providers. This is used to rank matches among all responding | 143 // various providers. This is used to rank matches among all responding |
133 // providers, so different providers must be carefully tuned to supply | 144 // providers, so different providers must be carefully tuned to supply |
134 // matches with appropriate relevance. | 145 // matches with appropriate relevance. |
135 // | 146 // |
(...skipping 12 matching lines...) Expand all Loading... | |
148 // The position within fill_into_edit from which we'll display the inline | 159 // 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 | 160 // autocomplete string. This will be string16::npos if this match should |
150 // not be inline autocompleted. | 161 // not be inline autocompleted. |
151 size_t inline_autocomplete_offset; | 162 size_t inline_autocomplete_offset; |
152 | 163 |
153 // The URL to actually load when the autocomplete item is selected. This URL | 164 // 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. | 165 // should be canonical so we can compare URLs with strcmp to avoid dupes. |
155 // It may be empty if there is no possible navigation. | 166 // It may be empty if there is no possible navigation. |
156 GURL destination_url; | 167 GURL destination_url; |
157 | 168 |
169 // The destination URL with "www." stripped off for better dupe finding. | |
170 GURL normalized_url; | |
Peter Kasting
2011/04/01 00:09:09
Nit: This would be more explicit as |destination_u
| |
171 | |
158 // The main text displayed in the address bar dropdown. | 172 // The main text displayed in the address bar dropdown. |
159 string16 contents; | 173 string16 contents; |
160 ACMatchClassifications contents_class; | 174 ACMatchClassifications contents_class; |
161 | 175 |
162 // Additional helper text for each entry, such as a title or description. | 176 // Additional helper text for each entry, such as a title or description. |
163 string16 description; | 177 string16 description; |
164 ACMatchClassifications description_class; | 178 ACMatchClassifications description_class; |
165 | 179 |
166 // The transition type to use when the user opens this match. By default | 180 // 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 | 181 // this is TYPED. Providers whose matches do not look like URLs should set |
168 // it to GENERATED. | 182 // it to GENERATED. |
169 PageTransition::Type transition; | 183 PageTransition::Type transition; |
170 | 184 |
171 // True when this match is the "what you typed" match from the history | 185 // True when this match is the "what you typed" match from the history |
172 // system. | 186 // system. |
173 bool is_history_what_you_typed_match; | 187 bool is_history_what_you_typed_match; |
174 | 188 |
175 // Type of this match. | 189 // Type of this match. |
176 Type type; | 190 Type type; |
177 | 191 |
178 // If this match corresponds to a keyword, this is the TemplateURL the | 192 // If this match corresponds to a keyword, this is the TemplateURL the |
179 // keyword was obtained from. | 193 // keyword was obtained from. |
180 const TemplateURL* template_url; | 194 const TemplateURL* template_url; |
181 | 195 |
196 // Cached keyword for this match | |
197 mutable string16 keyword; | |
198 | |
182 // True if the user has starred the destination URL. | 199 // True if the user has starred the destination URL. |
183 bool starred; | 200 bool starred; |
184 | 201 |
185 // True if this match is from a previous result. | 202 // True if this match is from a previous result. |
186 bool from_previous; | 203 bool from_previous; |
187 | 204 |
188 #ifndef NDEBUG | 205 #ifndef NDEBUG |
189 // Does a data integrity check on this match. | 206 // Does a data integrity check on this match. |
190 void Validate() const; | 207 void Validate() const; |
191 | 208 |
192 // Checks one text/classifications pair for valid values. | 209 // Checks one text/classifications pair for valid values. |
193 void ValidateClassifications( | 210 void ValidateClassifications( |
194 const string16& text, | 211 const string16& text, |
195 const ACMatchClassifications& classifications) const; | 212 const ACMatchClassifications& classifications) const; |
196 #endif | 213 #endif |
197 }; | 214 }; |
198 | 215 |
199 typedef AutocompleteMatch::ACMatchClassification ACMatchClassification; | 216 typedef AutocompleteMatch::ACMatchClassification ACMatchClassification; |
200 typedef std::vector<ACMatchClassification> ACMatchClassifications; | 217 typedef std::vector<ACMatchClassification> ACMatchClassifications; |
201 | 218 |
202 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_ | 219 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_ |
OLD | NEW |