Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_input.h

Issue 11414303: Make Google Search autocomplete provider cursor aware. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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.
Peter Kasting 2012/12/05 20:49:38 Nit: Add "|cursor_position| may be set to string16
Bart N. 2012/12/06 21:43:32 Done.
Bart N. 2012/12/06 21:43:32 Done.
52 //
53 // |prevent_inline_autocomplete| is true if the generated result set should
54 // not require inline autocomplete for the default match. This is difficult
55 // to explain in the abstract; the practical use case is that after the user
56 // deletes text in the edit, the HistoryURLProvider should make sure not to
57 // promote a match requiring inline autocomplete too highly.
58 //
59 // |prefer_keyword| should be true when the keyword UI is onscreen; this will
60 // bias the autocomplete result set toward the keyword provider when the input
61 // string is a bare keyword.
62 //
63 // |allow_exact_keyword_match| should be false when triggering keyword mode on
64 // the input string would be surprising or wrong, e.g. when highlighting text
65 // in a page and telling the browser to search for it or navigate to it. This
66 // parameter only applies to substituting keywords.
67
68 // If |matches_requested| is BEST_MATCH or SYNCHRONOUS_MATCHES the controller
69 // asks the providers to only return matches which are synchronously
70 // available, which should mean that all providers will be done immediately.
50 AutocompleteInput(const string16& text, 71 AutocompleteInput(const string16& text,
72 size_t cursor_position,
51 const string16& desired_tld, 73 const string16& desired_tld,
52 bool prevent_inline_autocomplete, 74 bool prevent_inline_autocomplete,
53 bool prefer_keyword, 75 bool prefer_keyword,
54 bool allow_exact_keyword_match, 76 bool allow_exact_keyword_match,
55 MatchesRequested matches_requested); 77 MatchesRequested matches_requested);
56 ~AutocompleteInput(); 78 ~AutocompleteInput();
57 79
58 // If type is |FORCED_QUERY| and |text| starts with '?', it is removed. 80 // If type is |FORCED_QUERY| and |text| starts with '?', it is removed.
59 static void RemoveForcedQueryStringIfNecessary(Type type, string16* text); 81 // Returns number of leading characters removed.
82 static size_t RemoveForcedQueryStringIfNecessary(Type type, string16* text);
60 83
61 // Converts |type| to a string representation. Used in logging. 84 // Converts |type| to a string representation. Used in logging.
62 static std::string TypeToString(Type type); 85 static std::string TypeToString(Type type);
63 86
64 // Parses |text| and returns the type of input this will be interpreted as. 87 // 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 88 // 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 89 // 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 90 // 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. 91 // not guaranteed to be valid, especially if the parsed type is, e.g., QUERY.
69 static Type Parse(const string16& text, 92 static Type Parse(const string16& text,
(...skipping 20 matching lines...) Expand all
90 static string16 FormattedStringWithEquivalentMeaning( 113 static string16 FormattedStringWithEquivalentMeaning(
91 const GURL& url, 114 const GURL& url,
92 const string16& formatted_url); 115 const string16& formatted_url);
93 116
94 // Returns the number of non-empty components in |parts| besides the host. 117 // Returns the number of non-empty components in |parts| besides the host.
95 static int NumNonHostComponents(const url_parse::Parsed& parts); 118 static int NumNonHostComponents(const url_parse::Parsed& parts);
96 119
97 // User-provided text to be completed. 120 // User-provided text to be completed.
98 const string16& text() const { return text_; } 121 const string16& text() const { return text_; }
99 122
123 // Returns 0-based cursor position within |text_| or string16::npos if not
124 // used or past the last character.
Peter Kasting 2012/12/05 20:49:38 Seems like for a string "abc", we should allow the
Bart N. 2012/12/06 21:43:32 It isn't a bug, it was done intentionally. However
125 size_t cursor_position() const { return cursor_position_; }
126
100 // Use of this setter is risky, since no other internal state is updated 127 // 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 128 // besides |text_|, |cursor_position_| and |parts_|. Only callers who know
102 // changing the type/scheme/etc. should use this. 129 // that they're not changing the type/scheme/etc. should use this.
103 void UpdateText(const string16& text, const url_parse::Parsed& parts); 130 void UpdateText(const string16& text, size_t cursor_position,
Peter Kasting 2012/12/05 20:49:38 Nit: One arg per line
Bart N. 2012/12/06 21:43:32 Done.
131 const url_parse::Parsed& parts);
104 132
105 // User's desired TLD, if one is not already present in the text to 133 // 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 134 // 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 135 // be prepended to the domain where possible. This should not have a leading
108 // '.' (use "com" instead of ".com"). 136 // '.' (use "com" instead of ".com").
109 const string16& desired_tld() const { return desired_tld_; } 137 const string16& desired_tld() const { return desired_tld_; }
110 138
111 // The type of input supplied. 139 // The type of input supplied.
112 Type type() const { return type_; } 140 Type type() const { return type_; }
113 141
(...skipping 25 matching lines...) Expand all
139 MatchesRequested matches_requested() const { return matches_requested_; } 167 MatchesRequested matches_requested() const { return matches_requested_; }
140 168
141 // operator==() by another name. 169 // operator==() by another name.
142 bool Equals(const AutocompleteInput& other) const; 170 bool Equals(const AutocompleteInput& other) const;
143 171
144 // Resets all internal variables to the null-constructed state. 172 // Resets all internal variables to the null-constructed state.
145 void Clear(); 173 void Clear();
146 174
147 private: 175 private:
148 string16 text_; 176 string16 text_;
177 size_t cursor_position_;
149 string16 desired_tld_; 178 string16 desired_tld_;
150 Type type_; 179 Type type_;
151 url_parse::Parsed parts_; 180 url_parse::Parsed parts_;
152 string16 scheme_; 181 string16 scheme_;
153 GURL canonicalized_url_; 182 GURL canonicalized_url_;
154 bool prevent_inline_autocomplete_; 183 bool prevent_inline_autocomplete_;
155 bool prefer_keyword_; 184 bool prefer_keyword_;
156 bool allow_exact_keyword_match_; 185 bool allow_exact_keyword_match_;
157 MatchesRequested matches_requested_; 186 MatchesRequested matches_requested_;
158 }; 187 };
159 188
160 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ 189 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698