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

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

Powered by Google App Engine
This is Rietveld 408576698