| 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/public/common/page_transition_types.h" | 13 #include "content/public/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 TemplateURL; | 17 class TemplateURL; |
| 17 | 18 |
| 18 // AutocompleteMatch ---------------------------------------------------------- | 19 // AutocompleteMatch ---------------------------------------------------------- |
| 19 | 20 |
| 20 // A single result line with classified spans. The autocomplete popup displays | 21 // A single result line with classified spans. The autocomplete popup displays |
| 21 // the 'contents' and the 'description' (the description is optional) in the | 22 // the 'contents' and the 'description' (the description is optional) in the |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 84 |
| 84 // Null-terminated array of characters that are not valid within |contents| | 85 // Null-terminated array of characters that are not valid within |contents| |
| 85 // and |description| strings. | 86 // and |description| strings. |
| 86 static const char16 kInvalidChars[]; | 87 static const char16 kInvalidChars[]; |
| 87 | 88 |
| 88 AutocompleteMatch(); | 89 AutocompleteMatch(); |
| 89 AutocompleteMatch(AutocompleteProvider* provider, | 90 AutocompleteMatch(AutocompleteProvider* provider, |
| 90 int relevance, | 91 int relevance, |
| 91 bool deletable, | 92 bool deletable, |
| 92 Type type); | 93 Type type); |
| 94 AutocompleteMatch(const AutocompleteMatch& match); |
| 93 ~AutocompleteMatch(); | 95 ~AutocompleteMatch(); |
| 94 | 96 |
| 97 AutocompleteMatch& operator=(const AutocompleteMatch& match); |
| 98 |
| 95 // Converts |type| to a string representation. Used in logging. | 99 // Converts |type| to a string representation. Used in logging. |
| 96 static std::string TypeToString(Type type); | 100 static std::string TypeToString(Type type); |
| 97 | 101 |
| 98 // Converts |type| to a resource identifier for the appropriate icon for this | 102 // Converts |type| to a resource identifier for the appropriate icon for this |
| 99 // type. | 103 // type. |
| 100 static int TypeToIcon(Type type); | 104 static int TypeToIcon(Type type); |
| 101 | 105 |
| 102 // Comparison function for determining when one match is better than another. | 106 // Comparison function for determining when one match is better than another. |
| 103 static bool MoreRelevant(const AutocompleteMatch& elem1, | 107 static bool MoreRelevant(const AutocompleteMatch& elem1, |
| 104 const AutocompleteMatch& elem2); | 108 const AutocompleteMatch& elem2); |
| 105 | 109 |
| 106 // Comparison functions for removing matches with duplicate destinations. | 110 // Comparison functions for removing matches with duplicate destinations. |
| 111 // Destinations are compared using |stripped_destination_url|. |
| 107 static bool DestinationSortFunc(const AutocompleteMatch& elem1, | 112 static bool DestinationSortFunc(const AutocompleteMatch& elem1, |
| 108 const AutocompleteMatch& elem2); | 113 const AutocompleteMatch& elem2); |
| 109 static bool DestinationsEqual(const AutocompleteMatch& elem1, | 114 static bool DestinationsEqual(const AutocompleteMatch& elem1, |
| 110 const AutocompleteMatch& elem2); | 115 const AutocompleteMatch& elem2); |
| 111 | 116 |
| 112 // Helper functions for classes creating matches: | 117 // Helper functions for classes creating matches: |
| 113 // Fills in the classifications for |text|, using |style| as the base style | 118 // Fills in the classifications for |text|, using |style| as the base style |
| 114 // and marking the first instance of |find_text| as a match. (This match | 119 // and marking the first instance of |find_text| as a match. (This match |
| 115 // will also not be dimmed, if |style| has DIM set.) | 120 // will also not be dimmed, if |style| has DIM set.) |
| 116 static void ClassifyMatchInString(const string16& find_text, | 121 static void ClassifyMatchInString(const string16& find_text, |
| 117 const string16& text, | 122 const string16& text, |
| 118 int style, | 123 int style, |
| 119 ACMatchClassifications* classifications); | 124 ACMatchClassifications* classifications); |
| 120 | 125 |
| 121 // Similar to ClassifyMatchInString(), but for cases where the range to mark | 126 // Similar to ClassifyMatchInString(), but for cases where the range to mark |
| 122 // as matching is already known (avoids calling find()). This can be helpful | 127 // as matching is already known (avoids calling find()). This can be helpful |
| 123 // when find() would be misleading (e.g. you want to mark the second match in | 128 // when find() would be misleading (e.g. you want to mark the second match in |
| 124 // a string instead of the first). | 129 // a string instead of the first). |
| 125 static void ClassifyLocationInString(size_t match_location, | 130 static void ClassifyLocationInString(size_t match_location, |
| 126 size_t match_length, | 131 size_t match_length, |
| 127 size_t overall_length, | 132 size_t overall_length, |
| 128 int style, | 133 int style, |
| 129 ACMatchClassifications* classifications); | 134 ACMatchClassifications* classifications); |
| 130 | 135 |
| 131 // Removes invalid characters from |text|. Should be called on strings coming | 136 // Removes invalid characters from |text|. Should be called on strings coming |
| 132 // from external sources (such as extensions) before assigning to |contents| | 137 // from external sources (such as extensions) before assigning to |contents| |
| 133 // or |description|. | 138 // or |description|. |
| 134 static string16 SanitizeString(const string16& text); | 139 static string16 SanitizeString(const string16& text); |
| 135 | 140 |
| 141 // Copies the destination_url with "www." stripped off to |
| 142 // |stripped_destination_url|. This method is invoked internally by the |
| 143 // AutocompleteController and does not normally need to be invoked. |
| 144 void ComputeStrippedDestinationURL(); |
| 145 |
| 146 // Gets the selected keyword or keyword hint for this match. Returns |
| 147 // true if |keyword| represents a keyword hint, or false if |keyword| |
| 148 // represents a selected keyword. (|keyword| will always be set [though |
| 149 // possibly to the empty string], and you cannot have both a selected keyword |
| 150 // and a keyword hint simultaneously.) |
| 151 bool GetKeyword(string16* keyword) const; |
| 152 |
| 136 // The provider of this match, used to remember which provider the user had | 153 // The provider of this match, used to remember which provider the user had |
| 137 // selected when the input changes. This may be NULL, in which case there is | 154 // selected when the input changes. This may be NULL, in which case there is |
| 138 // no provider (or memory of the user's selection). | 155 // no provider (or memory of the user's selection). |
| 139 AutocompleteProvider* provider; | 156 AutocompleteProvider* provider; |
| 140 | 157 |
| 141 // The relevance of this match. See table in autocomplete.h for scores | 158 // The relevance of this match. See table in autocomplete.h for scores |
| 142 // returned by various providers. This is used to rank matches among all | 159 // returned by various providers. This is used to rank matches among all |
| 143 // responding providers, so different providers must be carefully tuned to | 160 // responding providers, so different providers must be carefully tuned to |
| 144 // supply matches with appropriate relevance. | 161 // supply matches with appropriate relevance. |
| 145 // | 162 // |
| (...skipping 12 matching lines...) Expand all Loading... |
| 158 // The position within fill_into_edit from which we'll display the inline | 175 // The position within fill_into_edit from which we'll display the inline |
| 159 // autocomplete string. This will be string16::npos if this match should | 176 // autocomplete string. This will be string16::npos if this match should |
| 160 // not be inline autocompleted. | 177 // not be inline autocompleted. |
| 161 size_t inline_autocomplete_offset; | 178 size_t inline_autocomplete_offset; |
| 162 | 179 |
| 163 // The URL to actually load when the autocomplete item is selected. This URL | 180 // The URL to actually load when the autocomplete item is selected. This URL |
| 164 // should be canonical so we can compare URLs with strcmp to avoid dupes. | 181 // should be canonical so we can compare URLs with strcmp to avoid dupes. |
| 165 // It may be empty if there is no possible navigation. | 182 // It may be empty if there is no possible navigation. |
| 166 GURL destination_url; | 183 GURL destination_url; |
| 167 | 184 |
| 185 // The destination URL with "www." stripped off for better dupe finding. |
| 186 GURL stripped_destination_url; |
| 187 |
| 168 // The main text displayed in the address bar dropdown. | 188 // The main text displayed in the address bar dropdown. |
| 169 string16 contents; | 189 string16 contents; |
| 170 ACMatchClassifications contents_class; | 190 ACMatchClassifications contents_class; |
| 171 | 191 |
| 172 // Additional helper text for each entry, such as a title or description. | 192 // Additional helper text for each entry, such as a title or description. |
| 173 string16 description; | 193 string16 description; |
| 174 ACMatchClassifications description_class; | 194 ACMatchClassifications description_class; |
| 175 | 195 |
| 176 // The transition type to use when the user opens this match. By default | 196 // The transition type to use when the user opens this match. By default |
| 177 // this is TYPED. Providers whose matches do not look like URLs should set | 197 // this is TYPED. Providers whose matches do not look like URLs should set |
| 178 // it to GENERATED. | 198 // it to GENERATED. |
| 179 content::PageTransition transition; | 199 content::PageTransition transition; |
| 180 | 200 |
| 181 // True when this match is the "what you typed" match from the history | 201 // True when this match is the "what you typed" match from the history |
| 182 // system. | 202 // system. |
| 183 bool is_history_what_you_typed_match; | 203 bool is_history_what_you_typed_match; |
| 184 | 204 |
| 185 // Type of this match. | 205 // Type of this match. |
| 186 Type type; | 206 Type type; |
| 187 | 207 |
| 208 // Set with a keyword provider match if this match can show a keyword hint. |
| 209 // For example, if this is a SearchProvider match for "www.amazon.com", |
| 210 // |associated_keyword| could be a KeywordProvider match for "amazon.com". |
| 211 scoped_ptr<AutocompleteMatch> associated_keyword; |
| 212 |
| 213 // For matches that correspond to valid substituting keywords ("search |
| 214 // engines" that aren't the default engine, or extension keywords), this |
| 215 // is the keyword. If this is set, then when displaying this match, the |
| 216 // edit will use the "keyword mode" UI that shows a blue |
| 217 // "Search <engine name>" chit before the user's typing. This should be |
| 218 // set for any match that's an |associated_keyword| of a match in the main |
| 219 // result list, as well as any other matches in the main result list that |
| 220 // are direct keyword matches (e.g. if the user types in a keyword name and |
| 221 // some search terms directly). |
| 222 string16 keyword; |
| 223 |
| 188 // Indicates the TemplateURL the match originated from. This is set for | 224 // Indicates the TemplateURL the match originated from. This is set for |
| 189 // keywords as well as matches for the default search provider. | 225 // keywords as well as matches for the default search provider. |
| 190 const TemplateURL* template_url; | 226 const TemplateURL* template_url; |
| 191 | 227 |
| 192 // True if the user has starred the destination URL. | 228 // True if the user has starred the destination URL. |
| 193 bool starred; | 229 bool starred; |
| 194 | 230 |
| 195 // True if this match is from a previous result. | 231 // True if this match is from a previous result. |
| 196 bool from_previous; | 232 bool from_previous; |
| 197 | 233 |
| 198 #ifndef NDEBUG | 234 #ifndef NDEBUG |
| 199 // Does a data integrity check on this match. | 235 // Does a data integrity check on this match. |
| 200 void Validate() const; | 236 void Validate() const; |
| 201 | 237 |
| 202 // Checks one text/classifications pair for valid values. | 238 // Checks one text/classifications pair for valid values. |
| 203 void ValidateClassifications( | 239 void ValidateClassifications( |
| 204 const string16& text, | 240 const string16& text, |
| 205 const ACMatchClassifications& classifications) const; | 241 const ACMatchClassifications& classifications) const; |
| 206 #endif | 242 #endif |
| 207 }; | 243 }; |
| 208 | 244 |
| 209 typedef AutocompleteMatch::ACMatchClassification ACMatchClassification; | 245 typedef AutocompleteMatch::ACMatchClassification ACMatchClassification; |
| 210 typedef std::vector<ACMatchClassification> ACMatchClassifications; | 246 typedef std::vector<ACMatchClassification> ACMatchClassifications; |
| 211 | 247 |
| 212 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_ | 248 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_ |
| OLD | NEW |