| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_INPUT_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ |
| 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 BEST_MATCH, | 40 BEST_MATCH, |
| 41 | 41 |
| 42 // Only synchronous matches should be returned. | 42 // Only synchronous matches should be returned. |
| 43 SYNCHRONOUS_MATCHES, | 43 SYNCHRONOUS_MATCHES, |
| 44 | 44 |
| 45 // All matches should be fetched. | 45 // All matches should be fetched. |
| 46 ALL_MATCHES, | 46 ALL_MATCHES, |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 AutocompleteInput(); | 49 AutocompleteInput(); |
| 50 // |text| and |cursor_position| represent the input query and location of |
| 51 // the cursor with the query respectively. |cursor_position| may be set to |
| 52 // string16::npos if the input |text| doesn't come directly from the user's |
| 53 // typing. |
| 54 // |
| 55 // See AutocompleteInput::desired_tld() for meaning of |desired_tld|. |
| 56 // |
| 57 // |prevent_inline_autocomplete| is true if the generated result set should |
| 58 // not require inline autocomplete for the default match. This is difficult |
| 59 // to explain in the abstract; the practical use case is that after the user |
| 60 // deletes text in the edit, the HistoryURLProvider should make sure not to |
| 61 // promote a match requiring inline autocomplete too highly. |
| 62 // |
| 63 // |prefer_keyword| should be true when the keyword UI is onscreen; this will |
| 64 // bias the autocomplete result set toward the keyword provider when the input |
| 65 // string is a bare keyword. |
| 66 // |
| 67 // |allow_exact_keyword_match| should be false when triggering keyword mode on |
| 68 // the input string would be surprising or wrong, e.g. when highlighting text |
| 69 // in a page and telling the browser to search for it or navigate to it. This |
| 70 // parameter only applies to substituting keywords. |
| 71 |
| 72 // If |matches_requested| is BEST_MATCH or SYNCHRONOUS_MATCHES the controller |
| 73 // asks the providers to only return matches which are synchronously |
| 74 // available, which should mean that all providers will be done immediately. |
| 50 AutocompleteInput(const string16& text, | 75 AutocompleteInput(const string16& text, |
| 76 size_t cursor_position, |
| 51 const string16& desired_tld, | 77 const string16& desired_tld, |
| 52 bool prevent_inline_autocomplete, | 78 bool prevent_inline_autocomplete, |
| 53 bool prefer_keyword, | 79 bool prefer_keyword, |
| 54 bool allow_exact_keyword_match, | 80 bool allow_exact_keyword_match, |
| 55 MatchesRequested matches_requested); | 81 MatchesRequested matches_requested); |
| 56 ~AutocompleteInput(); | 82 ~AutocompleteInput(); |
| 57 | 83 |
| 58 // If type is |FORCED_QUERY| and |text| starts with '?', it is removed. | 84 // If type is |FORCED_QUERY| and |text| starts with '?', it is removed. |
| 59 static void RemoveForcedQueryStringIfNecessary(Type type, string16* text); | 85 // Returns number of leading characters removed. |
| 86 static size_t RemoveForcedQueryStringIfNecessary(Type type, string16* text); |
| 60 | 87 |
| 61 // Converts |type| to a string representation. Used in logging. | 88 // Converts |type| to a string representation. Used in logging. |
| 62 static std::string TypeToString(Type type); | 89 static std::string TypeToString(Type type); |
| 63 | 90 |
| 64 // Parses |text| and returns the type of input this will be interpreted as. | 91 // Parses |text| and returns the type of input this will be interpreted as. |
| 65 // The components of the input are stored in the output parameter |parts|, if | 92 // The components of the input are stored in the output parameter |parts|, if |
| 66 // it is non-NULL. The scheme is stored in |scheme| if it is non-NULL. The | 93 // it is non-NULL. The scheme is stored in |scheme| if it is non-NULL. The |
| 67 // canonicalized URL is stored in |canonicalized_url|; however, this URL is | 94 // canonicalized URL is stored in |canonicalized_url|; however, this URL is |
| 68 // not guaranteed to be valid, especially if the parsed type is, e.g., QUERY. | 95 // not guaranteed to be valid, especially if the parsed type is, e.g., QUERY. |
| 69 static Type Parse(const string16& text, | 96 static Type Parse(const string16& text, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 90 static string16 FormattedStringWithEquivalentMeaning( | 117 static string16 FormattedStringWithEquivalentMeaning( |
| 91 const GURL& url, | 118 const GURL& url, |
| 92 const string16& formatted_url); | 119 const string16& formatted_url); |
| 93 | 120 |
| 94 // Returns the number of non-empty components in |parts| besides the host. | 121 // Returns the number of non-empty components in |parts| besides the host. |
| 95 static int NumNonHostComponents(const url_parse::Parsed& parts); | 122 static int NumNonHostComponents(const url_parse::Parsed& parts); |
| 96 | 123 |
| 97 // User-provided text to be completed. | 124 // User-provided text to be completed. |
| 98 const string16& text() const { return text_; } | 125 const string16& text() const { return text_; } |
| 99 | 126 |
| 127 // Returns 0-based cursor position within |text_| or string16::npos if not |
| 128 // used. |
| 129 size_t cursor_position() const { return cursor_position_; } |
| 130 |
| 100 // Use of this setter is risky, since no other internal state is updated | 131 // Use of this setter is risky, since no other internal state is updated |
| 101 // besides |text_| and |parts_|. Only callers who know that they're not | 132 // besides |text_|, |cursor_position_| and |parts_|. Only callers who know |
| 102 // changing the type/scheme/etc. should use this. | 133 // that they're not changing the type/scheme/etc. should use this. |
| 103 void UpdateText(const string16& text, const url_parse::Parsed& parts); | 134 void UpdateText(const string16& text, |
| 135 size_t cursor_position, |
| 136 const url_parse::Parsed& parts); |
| 104 | 137 |
| 105 // User's desired TLD, if one is not already present in the text to | 138 // User's desired TLD, if one is not already present in the text to |
| 106 // autocomplete. When this is non-empty, it also implies that "www." should | 139 // autocomplete. When this is non-empty, it also implies that "www." should |
| 107 // be prepended to the domain where possible. This should not have a leading | 140 // be prepended to the domain where possible. This should not have a leading |
| 108 // '.' (use "com" instead of ".com"). | 141 // '.' (use "com" instead of ".com"). |
| 109 const string16& desired_tld() const { return desired_tld_; } | 142 const string16& desired_tld() const { return desired_tld_; } |
| 110 | 143 |
| 111 // The type of input supplied. | 144 // The type of input supplied. |
| 112 Type type() const { return type_; } | 145 Type type() const { return type_; } |
| 113 | 146 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 139 MatchesRequested matches_requested() const { return matches_requested_; } | 172 MatchesRequested matches_requested() const { return matches_requested_; } |
| 140 | 173 |
| 141 // operator==() by another name. | 174 // operator==() by another name. |
| 142 bool Equals(const AutocompleteInput& other) const; | 175 bool Equals(const AutocompleteInput& other) const; |
| 143 | 176 |
| 144 // Resets all internal variables to the null-constructed state. | 177 // Resets all internal variables to the null-constructed state. |
| 145 void Clear(); | 178 void Clear(); |
| 146 | 179 |
| 147 private: | 180 private: |
| 148 string16 text_; | 181 string16 text_; |
| 182 size_t cursor_position_; |
| 149 string16 desired_tld_; | 183 string16 desired_tld_; |
| 150 Type type_; | 184 Type type_; |
| 151 url_parse::Parsed parts_; | 185 url_parse::Parsed parts_; |
| 152 string16 scheme_; | 186 string16 scheme_; |
| 153 GURL canonicalized_url_; | 187 GURL canonicalized_url_; |
| 154 bool prevent_inline_autocomplete_; | 188 bool prevent_inline_autocomplete_; |
| 155 bool prefer_keyword_; | 189 bool prefer_keyword_; |
| 156 bool allow_exact_keyword_match_; | 190 bool allow_exact_keyword_match_; |
| 157 MatchesRequested matches_requested_; | 191 MatchesRequested matches_requested_; |
| 158 }; | 192 }; |
| 159 | 193 |
| 160 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ | 194 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ |
| OLD | NEW |