OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_EDIT_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_H_ |
6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "chrome/browser/autocomplete/autocomplete_match.h" | 10 #include "chrome/browser/autocomplete/autocomplete_match.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 virtual void OnAutocompleteLosingFocus( | 43 virtual void OnAutocompleteLosingFocus( |
44 gfx::NativeView view_gaining_focus) = 0; | 44 gfx::NativeView view_gaining_focus) = 0; |
45 | 45 |
46 // Sent prior to OnAutoCompleteAccept and before the model has been reverted. | 46 // Sent prior to OnAutoCompleteAccept and before the model has been reverted. |
47 // This is only invoked if the popup is closed before invoking | 47 // This is only invoked if the popup is closed before invoking |
48 // OnAutoCompleteAccept. | 48 // OnAutoCompleteAccept. |
49 virtual void OnAutocompleteWillAccept() = 0; | 49 virtual void OnAutocompleteWillAccept() = 0; |
50 | 50 |
51 // Commits the suggested text. |typed_text| is the current text showing in the | 51 // Commits the suggested text. |typed_text| is the current text showing in the |
52 // autocomplete. Returns true if the text was committed. | 52 // autocomplete. Returns true if the text was committed. |
53 virtual bool OnCommitSuggestedText(const std::wstring& typed_text) = 0; | 53 virtual bool OnCommitSuggestedText(const string16& typed_text) = 0; |
54 | 54 |
55 // Accepts the currently showing instant preview, if any, and returns true. | 55 // Accepts the currently showing instant preview, if any, and returns true. |
56 // Returns false if there is no instant preview showing. | 56 // Returns false if there is no instant preview showing. |
57 virtual bool AcceptCurrentInstantPreview() = 0; | 57 virtual bool AcceptCurrentInstantPreview() = 0; |
58 | 58 |
59 // Invoked when the popup is going to change its bounds to |bounds|. | 59 // Invoked when the popup is going to change its bounds to |bounds|. |
60 virtual void OnPopupBoundsChanged(const gfx::Rect& bounds) = 0; | 60 virtual void OnPopupBoundsChanged(const gfx::Rect& bounds) = 0; |
61 | 61 |
62 // When the user presses enter or selects a line with the mouse, this | 62 // When the user presses enter or selects a line with the mouse, this |
63 // function will get called synchronously with the url to open and | 63 // function will get called synchronously with the url to open and |
(...skipping 23 matching lines...) Expand all Loading... |
87 // Called whenever the autocomplete edit is losing focus. | 87 // Called whenever the autocomplete edit is losing focus. |
88 virtual void OnKillFocus() = 0; | 88 virtual void OnKillFocus() = 0; |
89 | 89 |
90 // Called whenever the autocomplete edit gets focused. | 90 // Called whenever the autocomplete edit gets focused. |
91 virtual void OnSetFocus() = 0; | 91 virtual void OnSetFocus() = 0; |
92 | 92 |
93 // Returns the favicon of the current page. | 93 // Returns the favicon of the current page. |
94 virtual SkBitmap GetFavIcon() const = 0; | 94 virtual SkBitmap GetFavIcon() const = 0; |
95 | 95 |
96 // Returns the title of the current page. | 96 // Returns the title of the current page. |
97 virtual std::wstring GetTitle() const = 0; | 97 virtual string16 GetTitle() const = 0; |
98 | 98 |
99 protected: | 99 protected: |
100 virtual ~AutocompleteEditController(); | 100 virtual ~AutocompleteEditController(); |
101 }; | 101 }; |
102 | 102 |
103 class AutocompleteEditModel : public NotificationObserver { | 103 class AutocompleteEditModel : public NotificationObserver { |
104 public: | 104 public: |
105 struct State { | 105 struct State { |
106 State(bool user_input_in_progress, | 106 State(bool user_input_in_progress, |
107 const std::wstring& user_text, | 107 const string16& user_text, |
108 const std::wstring& keyword, | 108 const string16& keyword, |
109 bool is_keyword_hint); | 109 bool is_keyword_hint); |
110 ~State(); | 110 ~State(); |
111 | 111 |
112 bool user_input_in_progress; | 112 bool user_input_in_progress; |
113 const std::wstring user_text; | 113 const string16 user_text; |
114 const std::wstring keyword; | 114 const string16 keyword; |
115 const bool is_keyword_hint; | 115 const bool is_keyword_hint; |
116 }; | 116 }; |
117 | 117 |
118 AutocompleteEditModel(AutocompleteEditView* view, | 118 AutocompleteEditModel(AutocompleteEditView* view, |
119 AutocompleteEditController* controller, | 119 AutocompleteEditController* controller, |
120 Profile* profile); | 120 Profile* profile); |
121 ~AutocompleteEditModel(); | 121 ~AutocompleteEditModel(); |
122 | 122 |
123 void SetPopupModel(AutocompletePopupModel* popup_model); | 123 void SetPopupModel(AutocompletePopupModel* popup_model); |
124 | 124 |
(...skipping 12 matching lines...) Expand all Loading... |
137 | 137 |
138 // Restores local state from the saved |state|. | 138 // Restores local state from the saved |state|. |
139 void RestoreState(const State& state); | 139 void RestoreState(const State& state); |
140 | 140 |
141 // Returns the match for the current text. If the user has not edited the text | 141 // Returns the match for the current text. If the user has not edited the text |
142 // this is the match corresponding to the permanent text. | 142 // this is the match corresponding to the permanent text. |
143 AutocompleteMatch CurrentMatch(); | 143 AutocompleteMatch CurrentMatch(); |
144 | 144 |
145 // Called when the user wants to export the entire current text as a URL. | 145 // Called when the user wants to export the entire current text as a URL. |
146 // Sets the url, and if known, the title and favicon. | 146 // Sets the url, and if known, the title and favicon. |
147 void GetDataForURLExport(GURL* url, std::wstring* title, SkBitmap* favicon); | 147 void GetDataForURLExport(GURL* url, string16* title, SkBitmap* favicon); |
148 | 148 |
149 // Returns true if a verbatim query should be used for instant. A verbatim | 149 // Returns true if a verbatim query should be used for instant. A verbatim |
150 // query is forced in certain situations, such as pressing delete at the end | 150 // query is forced in certain situations, such as pressing delete at the end |
151 // of the edit. | 151 // of the edit. |
152 bool UseVerbatimInstant(); | 152 bool UseVerbatimInstant(); |
153 | 153 |
154 // If the user presses ctrl-enter, it means "add .com to the the end". The | 154 // If the user presses ctrl-enter, it means "add .com to the the end". The |
155 // desired TLD is the TLD the user desires to add to the end of the current | 155 // desired TLD is the TLD the user desires to add to the end of the current |
156 // input, if any, based on their control key state and any other actions | 156 // input, if any, based on their control key state and any other actions |
157 // they've taken. | 157 // they've taken. |
158 std::wstring GetDesiredTLD() const; | 158 string16 GetDesiredTLD() const; |
159 | 159 |
160 // Returns true if the current edit contents will be treated as a | 160 // Returns true if the current edit contents will be treated as a |
161 // URL/navigation, as opposed to a search. | 161 // URL/navigation, as opposed to a search. |
162 bool CurrentTextIsURL() const; | 162 bool CurrentTextIsURL() const; |
163 | 163 |
164 // Returns the match type for the current edit contents. | 164 // Returns the match type for the current edit contents. |
165 AutocompleteMatch::Type CurrentTextType() const; | 165 AutocompleteMatch::Type CurrentTextType() const; |
166 | 166 |
167 // Invoked to adjust the text before writting to the clipboard for a copy | 167 // Invoked to adjust the text before writting to the clipboard for a copy |
168 // (e.g. by adding 'http' to the front). |sel_min| gives the minimum position | 168 // (e.g. by adding 'http' to the front). |sel_min| gives the minimum position |
169 // of the selection e.g. min(selection_start, selection_end). |text| is the | 169 // of the selection e.g. min(selection_start, selection_end). |text| is the |
170 // currently selected text. If |is_all_selected| is true all the text in the | 170 // currently selected text. If |is_all_selected| is true all the text in the |
171 // edit is selected. If the url should be copied to the clipboard |write_url| | 171 // edit is selected. If the url should be copied to the clipboard |write_url| |
172 // is set to true and |url| set to the url to write. | 172 // is set to true and |url| set to the url to write. |
173 void AdjustTextForCopy(int sel_min, | 173 void AdjustTextForCopy(int sel_min, |
174 bool is_all_selected, | 174 bool is_all_selected, |
175 std::wstring* text, | 175 string16* text, |
176 GURL* url, | 176 GURL* url, |
177 bool* write_url); | 177 bool* write_url); |
178 | 178 |
179 bool user_input_in_progress() const { return user_input_in_progress_; } | 179 bool user_input_in_progress() const { return user_input_in_progress_; } |
180 | 180 |
181 // Sets the state of user_input_in_progress_, and notifies the observer if | 181 // Sets the state of user_input_in_progress_, and notifies the observer if |
182 // that state has changed. | 182 // that state has changed. |
183 void SetInputInProgress(bool in_progress); | 183 void SetInputInProgress(bool in_progress); |
184 | 184 |
185 // Updates permanent_text_ to |new_permanent_text|. Returns true if this | 185 // Updates permanent_text_ to |new_permanent_text|. Returns true if this |
186 // change should be immediately user-visible, because either the user is not | 186 // change should be immediately user-visible, because either the user is not |
187 // editing or the edit does not have focus. | 187 // editing or the edit does not have focus. |
188 bool UpdatePermanentText(const std::wstring& new_permanent_text); | 188 bool UpdatePermanentText(const string16& new_permanent_text); |
189 | 189 |
190 // Sets the user_text_ to |text|. Only the View should call this. | 190 // Sets the user_text_ to |text|. Only the View should call this. |
191 void SetUserText(const std::wstring& text); | 191 void SetUserText(const string16& text); |
192 | 192 |
193 // Calls through to SearchProvider::FinalizeInstantQuery. | 193 // Calls through to SearchProvider::FinalizeInstantQuery. |
194 void FinalizeInstantQuery(const std::wstring& input_text, | 194 void FinalizeInstantQuery(const string16& input_text, |
195 const std::wstring& suggest_text); | 195 const string16& suggest_text); |
196 | 196 |
197 // Reverts the edit model back to its unedited state (permanent text showing, | 197 // Reverts the edit model back to its unedited state (permanent text showing, |
198 // no user input in progress). | 198 // no user input in progress). |
199 void Revert(); | 199 void Revert(); |
200 | 200 |
201 // Directs the popup to start autocomplete. | 201 // Directs the popup to start autocomplete. |
202 void StartAutocomplete(bool has_selected_text, | 202 void StartAutocomplete(bool has_selected_text, |
203 bool prevent_inline_autocomplete) const; | 203 bool prevent_inline_autocomplete) const; |
204 | 204 |
205 // Determines whether the user can "paste and go", given the specified text. | 205 // Determines whether the user can "paste and go", given the specified text. |
206 // This also updates the internal paste-and-go-related state variables as | 206 // This also updates the internal paste-and-go-related state variables as |
207 // appropriate so that the controller doesn't need to be repeatedly queried | 207 // appropriate so that the controller doesn't need to be repeatedly queried |
208 // for the same text in every clipboard-related function. | 208 // for the same text in every clipboard-related function. |
209 bool CanPasteAndGo(const std::wstring& text) const; | 209 bool CanPasteAndGo(const string16& text) const; |
210 | 210 |
211 // Navigates to the destination last supplied to CanPasteAndGo. | 211 // Navigates to the destination last supplied to CanPasteAndGo. |
212 void PasteAndGo(); | 212 void PasteAndGo(); |
213 | 213 |
214 // Returns the url set by way of CanPasteAndGo. | 214 // Returns the url set by way of CanPasteAndGo. |
215 const GURL& paste_and_go_url() const { return paste_and_go_url_; } | 215 const GURL& paste_and_go_url() const { return paste_and_go_url_; } |
216 | 216 |
217 // Returns true if this is a paste-and-search rather than paste-and-go (or | 217 // Returns true if this is a paste-and-search rather than paste-and-go (or |
218 // nothing). | 218 // nothing). |
219 bool is_paste_and_search() const { | 219 bool is_paste_and_search() const { |
220 return (paste_and_go_transition_ != PageTransition::TYPED); | 220 return (paste_and_go_transition_ != PageTransition::TYPED); |
221 } | 221 } |
222 | 222 |
223 // Asks the browser to load the popup's currently selected item, using the | 223 // Asks the browser to load the popup's currently selected item, using the |
224 // supplied disposition. This may close the popup. If |for_drop| is true, | 224 // supplied disposition. This may close the popup. If |for_drop| is true, |
225 // it indicates the input is being accepted as part of a drop operation and | 225 // it indicates the input is being accepted as part of a drop operation and |
226 // the transition should be treated as LINK (so that it won't trigger the | 226 // the transition should be treated as LINK (so that it won't trigger the |
227 // URL to be autocompleted). | 227 // URL to be autocompleted). |
228 void AcceptInput(WindowOpenDisposition disposition, | 228 void AcceptInput(WindowOpenDisposition disposition, |
229 bool for_drop); | 229 bool for_drop); |
230 | 230 |
231 // Asks the browser to load the item at |index|, with the given properties. | 231 // Asks the browser to load the item at |index|, with the given properties. |
232 void OpenURL(const GURL& url, | 232 void OpenURL(const GURL& url, |
233 WindowOpenDisposition disposition, | 233 WindowOpenDisposition disposition, |
234 PageTransition::Type transition, | 234 PageTransition::Type transition, |
235 const GURL& alternate_nav_url, | 235 const GURL& alternate_nav_url, |
236 size_t index, | 236 size_t index, |
237 const std::wstring& keyword); | 237 const string16& keyword); |
238 | 238 |
239 bool has_focus() const { return has_focus_; } | 239 bool has_focus() const { return has_focus_; } |
240 | 240 |
241 // Accessors for keyword-related state (see comments on keyword_ and | 241 // Accessors for keyword-related state (see comments on keyword_ and |
242 // is_keyword_hint_). | 242 // is_keyword_hint_). |
243 const std::wstring& keyword() const { return keyword_; } | 243 const string16& keyword() const { return keyword_; } |
244 bool is_keyword_hint() const { return is_keyword_hint_; } | 244 bool is_keyword_hint() const { return is_keyword_hint_; } |
245 | 245 |
246 // Accepts the current keyword hint as a keyword. It always returns true for | 246 // Accepts the current keyword hint as a keyword. It always returns true for |
247 // caller convenience. | 247 // caller convenience. |
248 bool AcceptKeyword(); | 248 bool AcceptKeyword(); |
249 | 249 |
250 // Clears the current keyword. |visible_text| is the (non-keyword) text | 250 // Clears the current keyword. |visible_text| is the (non-keyword) text |
251 // currently visible in the edit. | 251 // currently visible in the edit. |
252 void ClearKeyword(const std::wstring& visible_text); | 252 void ClearKeyword(const string16& visible_text); |
253 | 253 |
254 // Returns true if a query to an autocomplete provider is currently | 254 // Returns true if a query to an autocomplete provider is currently |
255 // in progress. This logic should in the future live in | 255 // in progress. This logic should in the future live in |
256 // AutocompleteController but resides here for now. This method is used by | 256 // AutocompleteController but resides here for now. This method is used by |
257 // AutomationProvider::AutocompleteEditIsQueryInProgress. | 257 // AutomationProvider::AutocompleteEditIsQueryInProgress. |
258 bool query_in_progress() const; | 258 bool query_in_progress() const; |
259 | 259 |
260 // Returns the current autocomplete result. This logic should in the future | 260 // Returns the current autocomplete result. This logic should in the future |
261 // live in AutocompleteController but resides here for now. This method is | 261 // live in AutocompleteController but resides here for now. This method is |
262 // used by AutomationProvider::AutocompleteEditGetMatches. | 262 // used by AutomationProvider::AutocompleteEditGetMatches. |
(...skipping 27 matching lines...) Expand all Loading... |
290 // |text| is either the new temporary text from the user manually selecting | 290 // |text| is either the new temporary text from the user manually selecting |
291 // a different match, or the inline autocomplete text. We distinguish by | 291 // a different match, or the inline autocomplete text. We distinguish by |
292 // checking if |destination_for_temporary_text_change| is NULL. | 292 // checking if |destination_for_temporary_text_change| is NULL. |
293 // |destination_for_temporary_text_change| is NULL (if temporary text should | 293 // |destination_for_temporary_text_change| is NULL (if temporary text should |
294 // not change) or the pre-change destination URL (if temporary text should | 294 // not change) or the pre-change destination URL (if temporary text should |
295 // change) so we can save it off to restore later. | 295 // change) so we can save it off to restore later. |
296 // |keyword| is the keyword to show a hint for if |is_keyword_hint| is true, | 296 // |keyword| is the keyword to show a hint for if |is_keyword_hint| is true, |
297 // or the currently selected keyword if |is_keyword_hint| is false (see | 297 // or the currently selected keyword if |is_keyword_hint| is false (see |
298 // comments on keyword_ and is_keyword_hint_). | 298 // comments on keyword_ and is_keyword_hint_). |
299 void OnPopupDataChanged( | 299 void OnPopupDataChanged( |
300 const std::wstring& text, | 300 const string16& text, |
301 GURL* destination_for_temporary_text_change, | 301 GURL* destination_for_temporary_text_change, |
302 const std::wstring& keyword, | 302 const string16& keyword, |
303 bool is_keyword_hint); | 303 bool is_keyword_hint); |
304 | 304 |
305 // Called by the AutocompleteEditView after something changes, with details | 305 // Called by the AutocompleteEditView after something changes, with details |
306 // about what state changes occured. Updates internal state, updates the | 306 // about what state changes occured. Updates internal state, updates the |
307 // popup if necessary, and returns true if any significant changes occurred. | 307 // popup if necessary, and returns true if any significant changes occurred. |
308 // If |allow_keyword_ui_change| is false then the change should not affect | 308 // If |allow_keyword_ui_change| is false then the change should not affect |
309 // keyword ui state, even if the text matches a keyword exactly. This value | 309 // keyword ui state, even if the text matches a keyword exactly. This value |
310 // may be false when: | 310 // may be false when: |
311 // 1) The insert caret is not at the end of the edit box | 311 // 1) The insert caret is not at the end of the edit box |
312 // 2) The user is composing a text with an IME | 312 // 2) The user is composing a text with an IME |
313 bool OnAfterPossibleChange(const std::wstring& new_text, | 313 bool OnAfterPossibleChange(const string16& new_text, |
314 bool selection_differs, | 314 bool selection_differs, |
315 bool text_differs, | 315 bool text_differs, |
316 bool just_deleted_text, | 316 bool just_deleted_text, |
317 bool allow_keyword_ui_change); | 317 bool allow_keyword_ui_change); |
318 | 318 |
319 // Invoked when the popup is going to change its bounds to |bounds|. | 319 // Invoked when the popup is going to change its bounds to |bounds|. |
320 void PopupBoundsChangedTo(const gfx::Rect& bounds); | 320 void PopupBoundsChangedTo(const gfx::Rect& bounds); |
321 | 321 |
322 private: | 322 private: |
323 enum PasteState { | 323 enum PasteState { |
(...skipping 20 matching lines...) Expand all Loading... |
344 // he simply hasn't released the key, rather than that | 344 // he simply hasn't released the key, rather than that |
345 // he intended to hit "ctrl-enter". | 345 // he intended to hit "ctrl-enter". |
346 }; | 346 }; |
347 | 347 |
348 // NotificationObserver | 348 // NotificationObserver |
349 virtual void Observe(NotificationType type, | 349 virtual void Observe(NotificationType type, |
350 const NotificationSource& source, | 350 const NotificationSource& source, |
351 const NotificationDetails& details); | 351 const NotificationDetails& details); |
352 | 352 |
353 // Called whenever user_text_ should change. | 353 // Called whenever user_text_ should change. |
354 void InternalSetUserText(const std::wstring& text); | 354 void InternalSetUserText(const string16& text); |
355 | 355 |
356 // Returns true if a keyword is selected. | 356 // Returns true if a keyword is selected. |
357 bool KeywordIsSelected() const; | 357 bool KeywordIsSelected() const; |
358 | 358 |
359 // Conversion between user text and display text. User text is the text the | 359 // Conversion between user text and display text. User text is the text the |
360 // user has input. Display text is the text being shown in the edit. The | 360 // user has input. Display text is the text being shown in the edit. The |
361 // two are different if a keyword is selected. | 361 // two are different if a keyword is selected. |
362 std::wstring DisplayTextFromUserText(const std::wstring& text) const; | 362 string16 DisplayTextFromUserText(const string16& text) const; |
363 std::wstring UserTextFromDisplayText(const std::wstring& text) const; | 363 string16 UserTextFromDisplayText(const string16& text) const; |
364 | 364 |
365 // Returns the default match for the current text, as well as the alternate | 365 // Returns the default match for the current text, as well as the alternate |
366 // nav URL, if |alternate_nav_url| is non-NULL and there is such a URL. | 366 // nav URL, if |alternate_nav_url| is non-NULL and there is such a URL. |
367 void GetInfoForCurrentText(AutocompleteMatch* match, | 367 void GetInfoForCurrentText(AutocompleteMatch* match, |
368 GURL* alternate_nav_url) const; | 368 GURL* alternate_nav_url) const; |
369 | 369 |
370 // Returns true if |text| (which is display text in the current context) | 370 // Returns true if |text| (which is display text in the current context) |
371 // parses as a URL, and in that case sets |url| to the calculated URL. | 371 // parses as a URL, and in that case sets |url| to the calculated URL. |
372 // Subtle note: This ignores the desired_tld_ (unlike GetDataForURLExport() | 372 // Subtle note: This ignores the desired_tld_ (unlike GetDataForURLExport() |
373 // and CurrentTextIsURL()). The view needs this because it calls this | 373 // and CurrentTextIsURL()). The view needs this because it calls this |
374 // function during copy handling, when the control key is down to trigger the | 374 // function during copy handling, when the control key is down to trigger the |
375 // copy. | 375 // copy. |
376 bool GetURLForText(const std::wstring& text, GURL* url) const; | 376 bool GetURLForText(const string16& text, GURL* url) const; |
377 | 377 |
378 // Accepts current keyword if the user only typed a space at the end of | 378 // Accepts current keyword if the user only typed a space at the end of |
379 // |new_user_text|. Returns true if the current keyword is accepted. | 379 // |new_user_text|. Returns true if the current keyword is accepted. |
380 bool MaybeAcceptKeywordBySpace(const std::wstring& new_user_text); | 380 bool MaybeAcceptKeywordBySpace(const string16& new_user_text); |
381 | 381 |
382 // Checks if a given character is a valid space character for accepting | 382 // Checks if a given character is a valid space character for accepting |
383 // keyword. | 383 // keyword. |
384 static bool IsSpaceCharForAcceptingKeyword(wchar_t c); | 384 static bool IsSpaceCharForAcceptingKeyword(wchar_t c); |
385 | 385 |
386 AutocompleteEditView* view_; | 386 AutocompleteEditView* view_; |
387 | 387 |
388 AutocompletePopupModel* popup_; | 388 AutocompletePopupModel* popup_; |
389 | 389 |
390 AutocompleteEditController* controller_; | 390 AutocompleteEditController* controller_; |
391 | 391 |
392 NotificationRegistrar registrar_; | 392 NotificationRegistrar registrar_; |
393 | 393 |
394 // Whether the edit has focus. | 394 // Whether the edit has focus. |
395 bool has_focus_; | 395 bool has_focus_; |
396 | 396 |
397 // The URL of the currently displayed page. | 397 // The URL of the currently displayed page. |
398 std::wstring permanent_text_; | 398 string16 permanent_text_; |
399 | 399 |
400 // This flag is true when the user has modified the contents of the edit, but | 400 // This flag is true when the user has modified the contents of the edit, but |
401 // not yet accepted them. We use this to determine when we need to save | 401 // not yet accepted them. We use this to determine when we need to save |
402 // state (on switching tabs) and whether changes to the page URL should be | 402 // state (on switching tabs) and whether changes to the page URL should be |
403 // immediately displayed. | 403 // immediately displayed. |
404 // This flag will be true in a superset of the cases where the popup is open. | 404 // This flag will be true in a superset of the cases where the popup is open. |
405 bool user_input_in_progress_; | 405 bool user_input_in_progress_; |
406 | 406 |
407 // The text that the user has entered. This does not include inline | 407 // The text that the user has entered. This does not include inline |
408 // autocomplete text that has not yet been accepted. | 408 // autocomplete text that has not yet been accepted. |
409 std::wstring user_text_; | 409 string16 user_text_; |
410 | 410 |
411 // When the user closes the popup, we need to remember the URL for their | 411 // When the user closes the popup, we need to remember the URL for their |
412 // desired choice, so that if they hit enter without reopening the popup we | 412 // desired choice, so that if they hit enter without reopening the popup we |
413 // know where to go. We could simply rerun autocomplete in this case, but | 413 // know where to go. We could simply rerun autocomplete in this case, but |
414 // we'd need to either wait for all results to come in (unacceptably slow) or | 414 // we'd need to either wait for all results to come in (unacceptably slow) or |
415 // do the wrong thing when the user had chosen some provider whose results | 415 // do the wrong thing when the user had chosen some provider whose results |
416 // were not returned instantaneously. | 416 // were not returned instantaneously. |
417 // | 417 // |
418 // This variable is only valid when user_input_in_progress_ is true, since | 418 // This variable is only valid when user_input_in_progress_ is true, since |
419 // when it is false the user has either never input anything (so there won't | 419 // when it is false the user has either never input anything (so there won't |
420 // be a value here anyway) or has canceled their input, which should be | 420 // be a value here anyway) or has canceled their input, which should be |
421 // treated the same way. Also, since this is for preserving a desired URL | 421 // treated the same way. Also, since this is for preserving a desired URL |
422 // after the popup has been closed, we ignore this if the popup is open, and | 422 // after the popup has been closed, we ignore this if the popup is open, and |
423 // simply ask the popup for the desired URL directly. As a result, the | 423 // simply ask the popup for the desired URL directly. As a result, the |
424 // contents of this variable only need to be updated when the popup is closed | 424 // contents of this variable only need to be updated when the popup is closed |
425 // but user_input_in_progress_ is not being cleared. | 425 // but user_input_in_progress_ is not being cleared. |
426 std::wstring url_for_remembered_user_selection_; | 426 string16 url_for_remembered_user_selection_; |
427 | 427 |
428 // Inline autocomplete is allowed if the user has not just deleted text, and | 428 // Inline autocomplete is allowed if the user has not just deleted text, and |
429 // no temporary text is showing. In this case, inline_autocomplete_text_ is | 429 // no temporary text is showing. In this case, inline_autocomplete_text_ is |
430 // appended to the user_text_ and displayed selected (at least initially). | 430 // appended to the user_text_ and displayed selected (at least initially). |
431 // | 431 // |
432 // NOTE: When the popup is closed there should never be inline autocomplete | 432 // NOTE: When the popup is closed there should never be inline autocomplete |
433 // text (actions that close the popup should either accept the text, convert | 433 // text (actions that close the popup should either accept the text, convert |
434 // it to a normal selection, or change the edit entirely). | 434 // it to a normal selection, or change the edit entirely). |
435 bool just_deleted_text_; | 435 bool just_deleted_text_; |
436 std::wstring inline_autocomplete_text_; | 436 string16 inline_autocomplete_text_; |
437 | 437 |
438 // Used by OnPopupDataChanged to keep track of whether there is currently a | 438 // Used by OnPopupDataChanged to keep track of whether there is currently a |
439 // temporary text. | 439 // temporary text. |
440 // | 440 // |
441 // Example of use: If the user types "goog", then arrows down in the | 441 // Example of use: If the user types "goog", then arrows down in the |
442 // autocomplete popup until, say, "google.com" appears in the edit box, then | 442 // autocomplete popup until, say, "google.com" appears in the edit box, then |
443 // the user_text_ is still "goog", and "google.com" is "temporary text". | 443 // the user_text_ is still "goog", and "google.com" is "temporary text". |
444 // When the user hits <esc>, the edit box reverts to "goog". Hit <esc> again | 444 // When the user hits <esc>, the edit box reverts to "goog". Hit <esc> again |
445 // and the popup is closed and "goog" is replaced by the permanent_text_, | 445 // and the popup is closed and "goog" is replaced by the permanent_text_, |
446 // which is the URL of the current page. | 446 // which is the URL of the current page. |
(...skipping 12 matching lines...) Expand all Loading... |
459 | 459 |
460 // Whether the control key is depressed. We track this to avoid calling | 460 // Whether the control key is depressed. We track this to avoid calling |
461 // UpdatePopup() repeatedly if the user holds down the key, and to know | 461 // UpdatePopup() repeatedly if the user holds down the key, and to know |
462 // whether to trigger "ctrl-enter" behavior. | 462 // whether to trigger "ctrl-enter" behavior. |
463 ControlKeyState control_key_state_; | 463 ControlKeyState control_key_state_; |
464 | 464 |
465 // The keyword associated with the current match. The user may have an actual | 465 // The keyword associated with the current match. The user may have an actual |
466 // selected keyword, or just some input text that looks like a keyword (so we | 466 // selected keyword, or just some input text that looks like a keyword (so we |
467 // can show a hint to press <tab>). This is the keyword in either case; | 467 // can show a hint to press <tab>). This is the keyword in either case; |
468 // is_keyword_hint_ (below) distinguishes the two cases. | 468 // is_keyword_hint_ (below) distinguishes the two cases. |
469 std::wstring keyword_; | 469 string16 keyword_; |
470 | 470 |
471 // True if the keyword associated with this match is merely a hint, i.e. the | 471 // True if the keyword associated with this match is merely a hint, i.e. the |
472 // user hasn't actually selected a keyword yet. When this is true, we can use | 472 // user hasn't actually selected a keyword yet. When this is true, we can use |
473 // keyword_ to show a "Press <tab> to search" sort of hint. | 473 // keyword_ to show a "Press <tab> to search" sort of hint. |
474 bool is_keyword_hint_; | 474 bool is_keyword_hint_; |
475 | 475 |
476 // Paste And Go-related state. See CanPasteAndGo(). | 476 // Paste And Go-related state. See CanPasteAndGo(). |
477 mutable GURL paste_and_go_url_; | 477 mutable GURL paste_and_go_url_; |
478 mutable PageTransition::Type paste_and_go_transition_; | 478 mutable PageTransition::Type paste_and_go_transition_; |
479 mutable GURL paste_and_go_alternate_nav_url_; | 479 mutable GURL paste_and_go_alternate_nav_url_; |
480 | 480 |
481 Profile* profile_; | 481 Profile* profile_; |
482 | 482 |
483 DISALLOW_COPY_AND_ASSIGN(AutocompleteEditModel); | 483 DISALLOW_COPY_AND_ASSIGN(AutocompleteEditModel); |
484 }; | 484 }; |
485 | 485 |
486 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_H_ | 486 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_H_ |
OLD | NEW |