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/scoped_ptr.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" |
14 | 15 |
15 class AutocompleteProvider; | 16 class AutocompleteProvider; |
16 class PageTransition; | 17 class PageTransition; |
17 class TemplateURL; | 18 class TemplateURL; |
18 | 19 |
19 // AutocompleteMatch ---------------------------------------------------------- | 20 // AutocompleteMatch ---------------------------------------------------------- |
20 | 21 |
21 // A single result line with classified spans. The autocomplete popup displays | 22 // A single result line with classified spans. The autocomplete popup displays |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 EXTENSION_APP, // An Extension App with a title/url that contains | 81 EXTENSION_APP, // An Extension App with a title/url that contains |
81 // the input. | 82 // the input. |
82 NUM_TYPES, | 83 NUM_TYPES, |
83 }; | 84 }; |
84 | 85 |
85 AutocompleteMatch(); | 86 AutocompleteMatch(); |
86 AutocompleteMatch(AutocompleteProvider* provider, | 87 AutocompleteMatch(AutocompleteProvider* provider, |
87 int relevance, | 88 int relevance, |
88 bool deletable, | 89 bool deletable, |
89 Type type); | 90 Type type); |
91 AutocompleteMatch(const AutocompleteMatch& match); | |
90 ~AutocompleteMatch(); | 92 ~AutocompleteMatch(); |
91 | 93 |
94 AutocompleteMatch& operator=(const AutocompleteMatch& match); | |
95 | |
92 // Converts |type| to a string representation. Used in logging. | 96 // Converts |type| to a string representation. Used in logging. |
93 static std::string TypeToString(Type type); | 97 static std::string TypeToString(Type type); |
94 | 98 |
95 // Converts |type| to a resource identifier for the appropriate icon for this | 99 // Converts |type| to a resource identifier for the appropriate icon for this |
96 // type. | 100 // type. |
97 static int TypeToIcon(Type type); | 101 static int TypeToIcon(Type type); |
98 | 102 |
99 // Comparison function for determining when one match is better than another. | 103 // Comparison function for determining when one match is better than another. |
100 static bool MoreRelevant(const AutocompleteMatch& elem1, | 104 static bool MoreRelevant(const AutocompleteMatch& elem1, |
101 const AutocompleteMatch& elem2); | 105 const AutocompleteMatch& elem2); |
102 | 106 |
103 // Comparison functions for removing matches with duplicate destinations. | 107 // Comparison functions for removing matches with duplicate destinations. |
108 // Destinations are compared using |stripped_destination_url|. | |
104 static bool DestinationSortFunc(const AutocompleteMatch& elem1, | 109 static bool DestinationSortFunc(const AutocompleteMatch& elem1, |
105 const AutocompleteMatch& elem2); | 110 const AutocompleteMatch& elem2); |
106 static bool DestinationsEqual(const AutocompleteMatch& elem1, | 111 static bool DestinationsEqual(const AutocompleteMatch& elem1, |
107 const AutocompleteMatch& elem2); | 112 const AutocompleteMatch& elem2); |
108 | 113 |
109 // Helper functions for classes creating matches: | 114 // Helper functions for classes creating matches: |
110 // Fills in the classifications for |text|, using |style| as the base style | 115 // Fills in the classifications for |text|, using |style| as the base style |
111 // and marking the first instance of |find_text| as a match. (This match | 116 // and marking the first instance of |find_text| as a match. (This match |
112 // will also not be dimmed, if |style| has DIM set.) | 117 // will also not be dimmed, if |style| has DIM set.) |
113 static void ClassifyMatchInString(const string16& find_text, | 118 static void ClassifyMatchInString(const string16& find_text, |
114 const string16& text, | 119 const string16& text, |
115 int style, | 120 int style, |
116 ACMatchClassifications* classifications); | 121 ACMatchClassifications* classifications); |
117 | 122 |
118 // Similar to ClassifyMatchInString(), but for cases where the range to mark | 123 // Similar to ClassifyMatchInString(), but for cases where the range to mark |
119 // as matching is already known (avoids calling find()). This can be helpful | 124 // as matching is already known (avoids calling find()). This can be helpful |
120 // when find() would be misleading (e.g. you want to mark the second match in | 125 // when find() would be misleading (e.g. you want to mark the second match in |
121 // a string instead of the first). | 126 // a string instead of the first). |
122 static void ClassifyLocationInString(size_t match_location, | 127 static void ClassifyLocationInString(size_t match_location, |
123 size_t match_length, | 128 size_t match_length, |
124 size_t overall_length, | 129 size_t overall_length, |
125 int style, | 130 int style, |
126 ACMatchClassifications* classifications); | 131 ACMatchClassifications* classifications); |
127 | 132 |
133 // Copies the destination_url with "www." stripped off to | |
134 // |stripped_destination_url|. | |
135 void ComputeStrippedDestinationURL(); | |
136 | |
128 // 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 |
129 // 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 |
130 // no provider (or memory of the user's selection). | 139 // no provider (or memory of the user's selection). |
131 AutocompleteProvider* provider; | 140 AutocompleteProvider* provider; |
132 | 141 |
133 // The relevance of this match. See table in autocomplete.h for scores | 142 // The relevance of this match. See table in autocomplete.h for scores |
134 // returned by various providers. This is used to rank matches among all | 143 // returned by various providers. This is used to rank matches among all |
135 // responding providers, so different providers must be carefully tuned to | 144 // responding providers, so different providers must be carefully tuned to |
136 // supply matches with appropriate relevance. | 145 // supply matches with appropriate relevance. |
137 // | 146 // |
(...skipping 12 matching lines...) Expand all Loading... | |
150 // 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 |
151 // autocomplete string. This will be string16::npos if this match should | 160 // autocomplete string. This will be string16::npos if this match should |
152 // not be inline autocompleted. | 161 // not be inline autocompleted. |
153 size_t inline_autocomplete_offset; | 162 size_t inline_autocomplete_offset; |
154 | 163 |
155 // 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 |
156 // 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. |
157 // It may be empty if there is no possible navigation. | 166 // It may be empty if there is no possible navigation. |
158 GURL destination_url; | 167 GURL destination_url; |
159 | 168 |
169 // The destination URL with "www." stripped off for better dupe finding. | |
170 GURL stripped_destination_url; | |
171 | |
160 // The main text displayed in the address bar dropdown. | 172 // The main text displayed in the address bar dropdown. |
161 string16 contents; | 173 string16 contents; |
162 ACMatchClassifications contents_class; | 174 ACMatchClassifications contents_class; |
163 | 175 |
164 // 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. |
165 string16 description; | 177 string16 description; |
166 ACMatchClassifications description_class; | 178 ACMatchClassifications description_class; |
167 | 179 |
168 // 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 |
169 // 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 |
170 // it to GENERATED. | 182 // it to GENERATED. |
171 PageTransition::Type transition; | 183 PageTransition::Type transition; |
172 | 184 |
173 // 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 |
174 // system. | 186 // system. |
175 bool is_history_what_you_typed_match; | 187 bool is_history_what_you_typed_match; |
176 | 188 |
177 // Type of this match. | 189 // Type of this match. |
178 Type type; | 190 Type type; |
179 | 191 |
192 // Set if this match has a keyword hint. | |
Peter Kasting
2011/07/27 20:18:25
Nit: I'm a little concerned about potential confus
| |
193 scoped_ptr<AutocompleteMatch> associated_keyword; | |
194 | |
195 // If this match corresponds to a keyword, this is the keyword text. | |
196 string16 keyword; | |
197 | |
180 // Indicates the TemplateURL the match originated from. This is set for | 198 // Indicates the TemplateURL the match originated from. This is set for |
181 // keywords as well as matches for the default search provider. | 199 // keywords as well as matches for the default search provider. |
182 const TemplateURL* template_url; | 200 const TemplateURL* template_url; |
183 | 201 |
184 // True if the user has starred the destination URL. | 202 // True if the user has starred the destination URL. |
185 bool starred; | 203 bool starred; |
186 | 204 |
187 // True if this match is from a previous result. | 205 // True if this match is from a previous result. |
188 bool from_previous; | 206 bool from_previous; |
189 | 207 |
190 #ifndef NDEBUG | 208 #ifndef NDEBUG |
191 // Does a data integrity check on this match. | 209 // Does a data integrity check on this match. |
192 void Validate() const; | 210 void Validate() const; |
193 | 211 |
194 // Checks one text/classifications pair for valid values. | 212 // Checks one text/classifications pair for valid values. |
195 void ValidateClassifications( | 213 void ValidateClassifications( |
196 const string16& text, | 214 const string16& text, |
197 const ACMatchClassifications& classifications) const; | 215 const ACMatchClassifications& classifications) const; |
198 #endif | 216 #endif |
199 }; | 217 }; |
200 | 218 |
201 typedef AutocompleteMatch::ACMatchClassification ACMatchClassification; | 219 typedef AutocompleteMatch::ACMatchClassification ACMatchClassification; |
202 typedef std::vector<ACMatchClassification> ACMatchClassifications; | 220 typedef std::vector<ACMatchClassification> ACMatchClassifications; |
203 | 221 |
204 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_ | 222 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_ |
OLD | NEW |