Chromium Code Reviews| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 | 98 |
| 99 // Returns the title of the current page. | 99 // Returns the title of the current page. |
| 100 virtual std::wstring GetTitle() const = 0; | 100 virtual std::wstring GetTitle() const = 0; |
| 101 | 101 |
| 102 protected: | 102 protected: |
| 103 virtual ~AutocompleteEditController(); | 103 virtual ~AutocompleteEditController(); |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 class AutocompleteEditModel : public NotificationObserver { | 106 class AutocompleteEditModel : public NotificationObserver { |
| 107 public: | 107 public: |
| 108 enum KeywordUIState { | |
| 109 // The user is typing normally. | |
| 110 NORMAL, | |
| 111 // The user is editing in the middle of the input string. Even if the | |
| 112 // input looks like a keyword, don't display the keyword UI, as to not | |
| 113 // interfere with the user's editing. | |
| 114 NO_KEYWORD, | |
| 115 // The user has triggered the keyword UI. Until it disappears, bias | |
| 116 // autocomplete results so that input strings of the keyword alone default | |
| 117 // to the keyword provider, not a normal navigation or search. | |
| 118 KEYWORD, | |
| 119 }; | |
| 120 | |
| 121 struct State { | 108 struct State { |
| 122 State(bool user_input_in_progress, | 109 State(bool user_input_in_progress, |
| 123 const std::wstring& user_text, | 110 const std::wstring& user_text, |
| 124 const std::wstring& keyword, | 111 const std::wstring& keyword, |
| 125 bool is_keyword_hint, | 112 bool is_keyword_hint); |
| 126 KeywordUIState keyword_ui_state); | |
| 127 ~State(); | 113 ~State(); |
| 128 | 114 |
| 129 bool user_input_in_progress; | 115 bool user_input_in_progress; |
| 130 const std::wstring user_text; | 116 const std::wstring user_text; |
| 131 const std::wstring keyword; | 117 const std::wstring keyword; |
| 132 const bool is_keyword_hint; | 118 const bool is_keyword_hint; |
| 133 const KeywordUIState keyword_ui_state; | |
| 134 }; | 119 }; |
| 135 | 120 |
| 136 AutocompleteEditModel(AutocompleteEditView* view, | 121 AutocompleteEditModel(AutocompleteEditView* view, |
| 137 AutocompleteEditController* controller, | 122 AutocompleteEditController* controller, |
| 138 Profile* profile); | 123 Profile* profile); |
| 139 ~AutocompleteEditModel(); | 124 ~AutocompleteEditModel(); |
| 140 | 125 |
| 141 void SetPopupModel(AutocompletePopupModel* popup_model); | 126 void SetPopupModel(AutocompletePopupModel* popup_model); |
| 142 | 127 |
| 143 // TODO: The edit and popup should be siblings owned by the LocationBarView, | 128 // TODO: The edit and popup should be siblings owned by the LocationBarView, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 WindowOpenDisposition disposition, | 236 WindowOpenDisposition disposition, |
| 252 PageTransition::Type transition, | 237 PageTransition::Type transition, |
| 253 const GURL& alternate_nav_url, | 238 const GURL& alternate_nav_url, |
| 254 size_t index, | 239 size_t index, |
| 255 const std::wstring& keyword); | 240 const std::wstring& keyword); |
| 256 | 241 |
| 257 bool has_focus() const { return has_focus_; } | 242 bool has_focus() const { return has_focus_; } |
| 258 | 243 |
| 259 // Accessors for keyword-related state (see comments on keyword_ and | 244 // Accessors for keyword-related state (see comments on keyword_ and |
| 260 // is_keyword_hint_). | 245 // is_keyword_hint_). |
| 261 std::wstring keyword() const { | 246 const std::wstring& keyword() const { return keyword_; } |
| 262 return (is_keyword_hint_ || (keyword_ui_state_ != NO_KEYWORD)) ? | |
| 263 keyword_ : std::wstring(); | |
| 264 } | |
| 265 bool is_keyword_hint() const { return is_keyword_hint_; } | 247 bool is_keyword_hint() const { return is_keyword_hint_; } |
| 266 | 248 |
| 267 // Accepts the current keyword hint as a keyword. | 249 // Accepts the current keyword hint as a keyword. |
| 268 void AcceptKeyword(); | 250 void AcceptKeyword(); |
| 269 | 251 |
| 270 // Clears the current keyword. |visible_text| is the (non-keyword) text | 252 // Clears the current keyword. |visible_text| is the (non-keyword) text |
| 271 // currently visible in the edit. | 253 // currently visible in the edit. |
| 272 void ClearKeyword(const std::wstring& visible_text); | 254 void ClearKeyword(const std::wstring& visible_text); |
| 273 | 255 |
| 274 // Returns true if a query to an autocomplete provider is currently | 256 // Returns true if a query to an autocomplete provider is currently |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 290 void OnKillFocus(); | 272 void OnKillFocus(); |
| 291 | 273 |
| 292 // Called when the user presses the escape key. Decides what, if anything, to | 274 // Called when the user presses the escape key. Decides what, if anything, to |
| 293 // revert about any current edits. Returns whether the key was handled. | 275 // revert about any current edits. Returns whether the key was handled. |
| 294 bool OnEscapeKeyPressed(); | 276 bool OnEscapeKeyPressed(); |
| 295 | 277 |
| 296 // Called when the user presses or releases the control key. Changes state as | 278 // Called when the user presses or releases the control key. Changes state as |
| 297 // necessary. | 279 // necessary. |
| 298 void OnControlKeyChanged(bool pressed); | 280 void OnControlKeyChanged(bool pressed); |
| 299 | 281 |
| 300 // Called when the user pastes in text that replaces the entire edit contents. | 282 // Called when the user pastes in text. |replacing_all| should be true if the |
| 301 void on_paste_replacing_all() { paste_state_ = REPLACING_ALL; } | 283 // entire edit contents is being replaced. |
| 284 void OnPaste(bool replacing_all); | |
| 302 | 285 |
| 303 // Called when the user presses up or down. |count| is a repeat count, | 286 // Called when the user presses up or down. |count| is a repeat count, |
| 304 // negative for moving up, positive for moving down. | 287 // negative for moving up, positive for moving down. |
| 305 void OnUpOrDownKeyPressed(int count); | 288 void OnUpOrDownKeyPressed(int count); |
| 306 | 289 |
| 307 // Called when any relevant data changes. This rolls together several | 290 // Called when any relevant data changes. This rolls together several |
| 308 // separate pieces of data into one call so we can update all the UI | 291 // separate pieces of data into one call so we can update all the UI |
| 309 // efficiently: | 292 // efficiently: |
| 310 // |text| is either the new temporary text from the user manually selecting | 293 // |text| is either the new temporary text from the user manually selecting |
| 311 // a different match, or the inline autocomplete text. We distinguish by | 294 // a different match, or the inline autocomplete text. We distinguish by |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 337 bool allow_keyword_ui_change); | 320 bool allow_keyword_ui_change); |
| 338 | 321 |
| 339 // Invoked when the popup is going to change its bounds to |bounds|. | 322 // Invoked when the popup is going to change its bounds to |bounds|. |
| 340 void PopupBoundsChangedTo(const gfx::Rect& bounds); | 323 void PopupBoundsChangedTo(const gfx::Rect& bounds); |
| 341 | 324 |
| 342 // Invoked when the autocomplete results may have changed in some way. | 325 // Invoked when the autocomplete results may have changed in some way. |
| 343 void ResultsUpdated(); | 326 void ResultsUpdated(); |
| 344 | 327 |
| 345 private: | 328 private: |
| 346 enum PasteState { | 329 enum PasteState { |
| 347 NONE, // Most recent edit was not a paste that replaced all text. | 330 NONE, // Most recent edit was not a paste that replaced all text. |
|
Peter Kasting
2011/01/20 00:04:22
Nit: These might make more sense in the order NONE
James Su
2011/01/20 06:49:31
Done.
| |
| 348 REPLACED_ALL, // Most recent edit was a paste that replaced all text. | 331 REPLACED_ALL, // Most recent edit was a paste that replaced all text. |
| 349 REPLACING_ALL, // In the middle of doing a paste that replaces all | 332 REPLACING_ALL, // In the middle of doing a paste that replaces all |
| 350 // text. We need this intermediate state because OnPaste() | 333 // text. We need this intermediate state because OnPaste() |
| 351 // does the actual detection of such pastes, but | 334 // does the actual detection of such pastes, but |
| 352 // OnAfterPossibleChange() has to update the paste state | 335 // OnAfterPossibleChange() has to update the paste state |
| 353 // for every edit. If OnPaste() set the state directly to | 336 // for every edit. If OnPaste() set the state directly to |
| 354 // REPLACED_ALL, OnAfterPossibleChange() wouldn't know | 337 // REPLACED_ALL, OnAfterPossibleChange() wouldn't know |
| 355 // whether that represented the current edit or a past one. | 338 // whether that represented the current edit or a past one. |
| 339 PASTED, // Most recent edit was a normal paste. | |
| 340 PASTING, // Like REPLACING_ALL, but indicating a normal paste. | |
| 356 }; | 341 }; |
| 357 | 342 |
| 358 enum ControlKeyState { | 343 enum ControlKeyState { |
| 359 UP, // The control key is not depressed. | 344 UP, // The control key is not depressed. |
| 360 DOWN_WITHOUT_CHANGE, // The control key is depressed, and the edit's | 345 DOWN_WITHOUT_CHANGE, // The control key is depressed, and the edit's |
| 361 // contents/selection have not changed since it was | 346 // contents/selection have not changed since it was |
| 362 // depressed. This is the only state in which we | 347 // depressed. This is the only state in which we |
| 363 // do the "ctrl-enter" behavior when the user hits | 348 // do the "ctrl-enter" behavior when the user hits |
| 364 // enter. | 349 // enter. |
| 365 DOWN_WITH_CHANGE, // The control key is depressed, and the edit's | 350 DOWN_WITH_CHANGE, // The control key is depressed, and the edit's |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 396 // Subtle note: This ignores the desired_tld_ (unlike GetDataForURLExport() | 381 // Subtle note: This ignores the desired_tld_ (unlike GetDataForURLExport() |
| 397 // and CurrentTextIsURL()). The view needs this because it calls this | 382 // and CurrentTextIsURL()). The view needs this because it calls this |
| 398 // function during copy handling, when the control key is down to trigger the | 383 // function during copy handling, when the control key is down to trigger the |
| 399 // copy. | 384 // copy. |
| 400 bool GetURLForText(const std::wstring& text, GURL* url) const; | 385 bool GetURLForText(const std::wstring& text, GURL* url) const; |
| 401 | 386 |
| 402 // Determines the suggested search text and invokes OnSetSuggestedSearchText | 387 // Determines the suggested search text and invokes OnSetSuggestedSearchText |
| 403 // on the controller. | 388 // on the controller. |
| 404 void UpdateSuggestedSearchText(); | 389 void UpdateSuggestedSearchText(); |
| 405 | 390 |
| 391 // Accepts current keyword if the user only typed a whitespace at the end of | |
|
Peter Kasting
2011/01/20 00:04:22
Nit: whitespace -> space
James Su
2011/01/20 06:49:31
Done.
| |
| 392 // |new_user_text|. Returns true if the current keyword is accepted. | |
| 393 bool MaybeAcceptKeywordBySpace(const std::wstring& new_user_text); | |
| 394 | |
| 406 AutocompleteEditView* view_; | 395 AutocompleteEditView* view_; |
| 407 | 396 |
| 408 AutocompletePopupModel* popup_; | 397 AutocompletePopupModel* popup_; |
| 409 | 398 |
| 410 AutocompleteEditController* controller_; | 399 AutocompleteEditController* controller_; |
| 411 | 400 |
| 412 NotificationRegistrar registrar_; | 401 NotificationRegistrar registrar_; |
| 413 | 402 |
| 414 // Whether the edit has focus. | 403 // Whether the edit has focus. |
| 415 bool has_focus_; | 404 bool has_focus_; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 // When the user hits <esc>, the edit box reverts to "goog". Hit <esc> again | 453 // When the user hits <esc>, the edit box reverts to "goog". Hit <esc> again |
| 465 // and the popup is closed and "goog" is replaced by the permanent_text_, | 454 // and the popup is closed and "goog" is replaced by the permanent_text_, |
| 466 // which is the URL of the current page. | 455 // which is the URL of the current page. |
| 467 // | 456 // |
| 468 // original_url_ is only valid when there is temporary text, and is used as | 457 // original_url_ is only valid when there is temporary text, and is used as |
| 469 // the unique identifier of the originally selected item. Thus, if the user | 458 // the unique identifier of the originally selected item. Thus, if the user |
| 470 // arrows to a different item with the same text, we can still distinguish | 459 // arrows to a different item with the same text, we can still distinguish |
| 471 // them and not revert all the way to the permanent_text_. | 460 // them and not revert all the way to the permanent_text_. |
| 472 bool has_temporary_text_; | 461 bool has_temporary_text_; |
| 473 GURL original_url_; | 462 GURL original_url_; |
| 474 KeywordUIState original_keyword_ui_state_; | |
| 475 | 463 |
| 476 // When the user's last action was to paste and replace all the text, we | 464 // When the user's last action was to paste and replace all the text, we |
| 477 // disallow inline autocomplete (on the theory that the user is trying to | 465 // disallow inline autocomplete (on the theory that the user is trying to |
| 478 // paste in a new URL or part of one, and in either case inline autocomplete | 466 // paste in a new URL or part of one, and in either case inline autocomplete |
| 479 // would get in the way). | 467 // would get in the way). |
| 480 PasteState paste_state_; | 468 PasteState paste_state_; |
| 481 | 469 |
| 482 // Whether the control key is depressed. We track this to avoid calling | 470 // Whether the control key is depressed. We track this to avoid calling |
| 483 // UpdatePopup() repeatedly if the user holds down the key, and to know | 471 // UpdatePopup() repeatedly if the user holds down the key, and to know |
| 484 // whether to trigger "ctrl-enter" behavior. | 472 // whether to trigger "ctrl-enter" behavior. |
| 485 ControlKeyState control_key_state_; | 473 ControlKeyState control_key_state_; |
| 486 | 474 |
| 487 // The keyword associated with the current match. The user may have an actual | 475 // The keyword associated with the current match. The user may have an actual |
| 488 // selected keyword, or just some input text that looks like a keyword (so we | 476 // selected keyword, or just some input text that looks like a keyword (so we |
| 489 // can show a hint to press <tab>). This is the keyword in either case; | 477 // can show a hint to press <tab>). This is the keyword in either case; |
| 490 // is_keyword_hint_ (below) distinguishes the two cases. | 478 // is_keyword_hint_ (below) distinguishes the two cases. |
| 491 std::wstring keyword_; | 479 std::wstring keyword_; |
| 492 | 480 |
| 493 // True if the keyword associated with this match is merely a hint, i.e. the | 481 // True if the keyword associated with this match is merely a hint, i.e. the |
| 494 // user hasn't actually selected a keyword yet. When this is true, we can use | 482 // user hasn't actually selected a keyword yet. When this is true, we can use |
| 495 // keyword_ to show a "Press <tab> to search" sort of hint. | 483 // keyword_ to show a "Press <tab> to search" sort of hint. |
| 496 bool is_keyword_hint_; | 484 bool is_keyword_hint_; |
| 497 | 485 |
| 498 // See KeywordUIState enum. | |
| 499 KeywordUIState keyword_ui_state_; | |
| 500 | |
| 501 // Paste And Go-related state. See CanPasteAndGo(). | 486 // Paste And Go-related state. See CanPasteAndGo(). |
| 502 mutable GURL paste_and_go_url_; | 487 mutable GURL paste_and_go_url_; |
| 503 mutable PageTransition::Type paste_and_go_transition_; | 488 mutable PageTransition::Type paste_and_go_transition_; |
| 504 mutable GURL paste_and_go_alternate_nav_url_; | 489 mutable GURL paste_and_go_alternate_nav_url_; |
| 505 | 490 |
| 506 Profile* profile_; | 491 Profile* profile_; |
| 507 | 492 |
| 508 DISALLOW_COPY_AND_ASSIGN(AutocompleteEditModel); | 493 DISALLOW_COPY_AND_ASSIGN(AutocompleteEditModel); |
| 509 }; | 494 }; |
| 510 | 495 |
| 511 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_H_ | 496 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_H_ |
| OLD | NEW |