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