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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 | 92 |
| 93 // Called whenever the autocomplete edit gets focused. | 93 // Called whenever the autocomplete edit gets focused. |
| 94 virtual void OnSetFocus() = 0; | 94 virtual void OnSetFocus() = 0; |
| 95 | 95 |
| 96 // Returns the favicon of the current page. | 96 // Returns the favicon of the current page. |
| 97 virtual SkBitmap GetFavIcon() const = 0; | 97 virtual SkBitmap GetFavIcon() const = 0; |
| 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 // Returns true if the keyword hint UI is visible. | |
| 103 virtual bool IsKeywordHintVisible() const = 0; | |
|
Peter Kasting
2011/01/14 00:43:31
This addition seems a little odd to me. The Autoc
James Su
2011/01/14 01:03:54
They keyword hint UI may not be visible if the bro
Peter Kasting
2011/01/14 01:20:01
The hint is just a hint. It is important that spa
James Su
2011/01/14 02:02:46
Existing code doesn't accept keyword by Tab key if
Peter Kasting
2011/01/14 02:30:36
Yeah, that seems like a bug.
James Su
2011/01/14 03:26:22
According to the original code, it's on purpose ra
Peter Kasting
2011/01/14 17:31:33
I am the UX designer. The original code was wrong
James Su
2011/01/14 18:04:12
Ok, I'll remove those code. It even makes the code
| |
| 104 | |
| 102 protected: | 105 protected: |
| 103 virtual ~AutocompleteEditController(); | 106 virtual ~AutocompleteEditController(); |
| 104 }; | 107 }; |
| 105 | 108 |
| 106 class AutocompleteEditModel : public NotificationObserver { | 109 class AutocompleteEditModel : public NotificationObserver { |
| 107 public: | 110 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 { | 111 struct State { |
| 122 State(bool user_input_in_progress, | 112 State(bool user_input_in_progress, |
| 123 const std::wstring& user_text, | 113 const std::wstring& user_text, |
| 124 const std::wstring& keyword, | 114 const std::wstring& keyword, |
| 125 bool is_keyword_hint, | 115 bool is_keyword_hint); |
| 126 KeywordUIState keyword_ui_state); | |
| 127 ~State(); | 116 ~State(); |
| 128 | 117 |
| 129 bool user_input_in_progress; | 118 bool user_input_in_progress; |
| 130 const std::wstring user_text; | 119 const std::wstring user_text; |
| 131 const std::wstring keyword; | 120 const std::wstring keyword; |
| 132 const bool is_keyword_hint; | 121 const bool is_keyword_hint; |
| 133 const KeywordUIState keyword_ui_state; | |
| 134 }; | 122 }; |
| 135 | 123 |
| 136 AutocompleteEditModel(AutocompleteEditView* view, | 124 AutocompleteEditModel(AutocompleteEditView* view, |
| 137 AutocompleteEditController* controller, | 125 AutocompleteEditController* controller, |
| 138 Profile* profile); | 126 Profile* profile); |
| 139 ~AutocompleteEditModel(); | 127 ~AutocompleteEditModel(); |
| 140 | 128 |
| 141 void SetPopupModel(AutocompletePopupModel* popup_model); | 129 void SetPopupModel(AutocompletePopupModel* popup_model); |
| 142 | 130 |
| 143 // TODO: The edit and popup should be siblings owned by the LocationBarView, | 131 // 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, | 239 WindowOpenDisposition disposition, |
| 252 PageTransition::Type transition, | 240 PageTransition::Type transition, |
| 253 const GURL& alternate_nav_url, | 241 const GURL& alternate_nav_url, |
| 254 size_t index, | 242 size_t index, |
| 255 const std::wstring& keyword); | 243 const std::wstring& keyword); |
| 256 | 244 |
| 257 bool has_focus() const { return has_focus_; } | 245 bool has_focus() const { return has_focus_; } |
| 258 | 246 |
| 259 // Accessors for keyword-related state (see comments on keyword_ and | 247 // Accessors for keyword-related state (see comments on keyword_ and |
| 260 // is_keyword_hint_). | 248 // is_keyword_hint_). |
| 261 std::wstring keyword() const { | 249 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_; } | 250 bool is_keyword_hint() const { return is_keyword_hint_; } |
| 266 | 251 |
| 267 // Accepts the current keyword hint as a keyword. | 252 // Accepts the current keyword hint as a keyword. |
| 268 void AcceptKeyword(); | 253 void AcceptKeyword(); |
| 269 | 254 |
| 270 // Clears the current keyword. |visible_text| is the (non-keyword) text | 255 // Clears the current keyword. |visible_text| is the (non-keyword) text |
| 271 // currently visible in the edit. | 256 // currently visible in the edit. |
| 272 void ClearKeyword(const std::wstring& visible_text); | 257 void ClearKeyword(const std::wstring& visible_text); |
| 273 | 258 |
| 274 // Returns true if a query to an autocomplete provider is currently | 259 // Returns true if a query to an autocomplete provider is currently |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 290 void OnKillFocus(); | 275 void OnKillFocus(); |
| 291 | 276 |
| 292 // Called when the user presses the escape key. Decides what, if anything, to | 277 // 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. | 278 // revert about any current edits. Returns whether the key was handled. |
| 294 bool OnEscapeKeyPressed(); | 279 bool OnEscapeKeyPressed(); |
| 295 | 280 |
| 296 // Called when the user presses or releases the control key. Changes state as | 281 // Called when the user presses or releases the control key. Changes state as |
| 297 // necessary. | 282 // necessary. |
| 298 void OnControlKeyChanged(bool pressed); | 283 void OnControlKeyChanged(bool pressed); |
| 299 | 284 |
| 300 // Called when the user pastes in text that replaces the entire edit contents. | 285 // Called when the user pastes in text. |replacing_all| should be true if the |
| 301 void on_paste_replacing_all() { paste_state_ = REPLACING_ALL; } | 286 // entire edit contents is being replaced. |
| 287 void OnPaste(bool replacing_all); | |
| 302 | 288 |
| 303 // Called when the user presses up or down. |count| is a repeat count, | 289 // Called when the user presses up or down. |count| is a repeat count, |
| 304 // negative for moving up, positive for moving down. | 290 // negative for moving up, positive for moving down. |
| 305 void OnUpOrDownKeyPressed(int count); | 291 void OnUpOrDownKeyPressed(int count); |
| 306 | 292 |
| 307 // Called when any relevant data changes. This rolls together several | 293 // 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 | 294 // separate pieces of data into one call so we can update all the UI |
| 309 // efficiently: | 295 // efficiently: |
| 310 // |text| is either the new temporary text from the user manually selecting | 296 // |text| is either the new temporary text from the user manually selecting |
| 311 // a different match, or the inline autocomplete text. We distinguish by | 297 // a different match, or the inline autocomplete text. We distinguish by |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 enum PasteState { | 332 enum PasteState { |
| 347 NONE, // Most recent edit was not a paste that replaced all text. | 333 NONE, // Most recent edit was not a paste that replaced all text. |
| 348 REPLACED_ALL, // Most recent edit was a paste that replaced all text. | 334 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 | 335 REPLACING_ALL, // In the middle of doing a paste that replaces all |
| 350 // text. We need this intermediate state because OnPaste() | 336 // text. We need this intermediate state because OnPaste() |
| 351 // does the actual detection of such pastes, but | 337 // does the actual detection of such pastes, but |
| 352 // OnAfterPossibleChange() has to update the paste state | 338 // OnAfterPossibleChange() has to update the paste state |
| 353 // for every edit. If OnPaste() set the state directly to | 339 // for every edit. If OnPaste() set the state directly to |
| 354 // REPLACED_ALL, OnAfterPossibleChange() wouldn't know | 340 // REPLACED_ALL, OnAfterPossibleChange() wouldn't know |
| 355 // whether that represented the current edit or a past one. | 341 // whether that represented the current edit or a past one. |
| 342 PASTED, // Most recent edit was a normal paste. | |
| 343 PASTING, // Like REPLACING_ALL, but indicating a normal paste. | |
| 356 }; | 344 }; |
| 357 | 345 |
| 358 enum ControlKeyState { | 346 enum ControlKeyState { |
| 359 UP, // The control key is not depressed. | 347 UP, // The control key is not depressed. |
| 360 DOWN_WITHOUT_CHANGE, // The control key is depressed, and the edit's | 348 DOWN_WITHOUT_CHANGE, // The control key is depressed, and the edit's |
| 361 // contents/selection have not changed since it was | 349 // contents/selection have not changed since it was |
| 362 // depressed. This is the only state in which we | 350 // depressed. This is the only state in which we |
| 363 // do the "ctrl-enter" behavior when the user hits | 351 // do the "ctrl-enter" behavior when the user hits |
| 364 // enter. | 352 // enter. |
| 365 DOWN_WITH_CHANGE, // The control key is depressed, and the edit's | 353 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() | 384 // Subtle note: This ignores the desired_tld_ (unlike GetDataForURLExport() |
| 397 // and CurrentTextIsURL()). The view needs this because it calls this | 385 // and CurrentTextIsURL()). The view needs this because it calls this |
| 398 // function during copy handling, when the control key is down to trigger the | 386 // function during copy handling, when the control key is down to trigger the |
| 399 // copy. | 387 // copy. |
| 400 bool GetURLForText(const std::wstring& text, GURL* url) const; | 388 bool GetURLForText(const std::wstring& text, GURL* url) const; |
| 401 | 389 |
| 402 // Determines the suggested search text and invokes OnSetSuggestedSearchText | 390 // Determines the suggested search text and invokes OnSetSuggestedSearchText |
| 403 // on the controller. | 391 // on the controller. |
| 404 void UpdateSuggestedSearchText(); | 392 void UpdateSuggestedSearchText(); |
| 405 | 393 |
| 394 // Accepts current keyword if the user only typed a whitespace at the end of | |
| 395 // |new_user_text|. Returns true if the current keyword is accepted. | |
| 396 bool MaybeAcceptKeywordBySpace(const std::wstring& new_user_text); | |
| 397 | |
| 406 AutocompleteEditView* view_; | 398 AutocompleteEditView* view_; |
| 407 | 399 |
| 408 AutocompletePopupModel* popup_; | 400 AutocompletePopupModel* popup_; |
| 409 | 401 |
| 410 AutocompleteEditController* controller_; | 402 AutocompleteEditController* controller_; |
| 411 | 403 |
| 412 NotificationRegistrar registrar_; | 404 NotificationRegistrar registrar_; |
| 413 | 405 |
| 414 // Whether the edit has focus. | 406 // Whether the edit has focus. |
| 415 bool has_focus_; | 407 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 | 456 // 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_, | 457 // and the popup is closed and "goog" is replaced by the permanent_text_, |
| 466 // which is the URL of the current page. | 458 // which is the URL of the current page. |
| 467 // | 459 // |
| 468 // original_url_ is only valid when there is temporary text, and is used as | 460 // 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 | 461 // 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 | 462 // 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_. | 463 // them and not revert all the way to the permanent_text_. |
| 472 bool has_temporary_text_; | 464 bool has_temporary_text_; |
| 473 GURL original_url_; | 465 GURL original_url_; |
| 474 KeywordUIState original_keyword_ui_state_; | |
| 475 | 466 |
| 476 // When the user's last action was to paste and replace all the text, we | 467 // 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 | 468 // 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 | 469 // paste in a new URL or part of one, and in either case inline autocomplete |
| 479 // would get in the way). | 470 // would get in the way). |
| 480 PasteState paste_state_; | 471 PasteState paste_state_; |
| 481 | 472 |
| 482 // Whether the control key is depressed. We track this to avoid calling | 473 // 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 | 474 // UpdatePopup() repeatedly if the user holds down the key, and to know |
| 484 // whether to trigger "ctrl-enter" behavior. | 475 // whether to trigger "ctrl-enter" behavior. |
| 485 ControlKeyState control_key_state_; | 476 ControlKeyState control_key_state_; |
| 486 | 477 |
| 487 // The keyword associated with the current match. The user may have an actual | 478 // 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 | 479 // 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; | 480 // can show a hint to press <tab>). This is the keyword in either case; |
| 490 // is_keyword_hint_ (below) distinguishes the two cases. | 481 // is_keyword_hint_ (below) distinguishes the two cases. |
| 491 std::wstring keyword_; | 482 std::wstring keyword_; |
| 492 | 483 |
| 493 // True if the keyword associated with this match is merely a hint, i.e. the | 484 // 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 | 485 // 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. | 486 // keyword_ to show a "Press <tab> to search" sort of hint. |
| 496 bool is_keyword_hint_; | 487 bool is_keyword_hint_; |
| 497 | 488 |
| 498 // See KeywordUIState enum. | |
| 499 KeywordUIState keyword_ui_state_; | |
| 500 | |
| 501 // Paste And Go-related state. See CanPasteAndGo(). | 489 // Paste And Go-related state. See CanPasteAndGo(). |
| 502 mutable GURL paste_and_go_url_; | 490 mutable GURL paste_and_go_url_; |
| 503 mutable PageTransition::Type paste_and_go_transition_; | 491 mutable PageTransition::Type paste_and_go_transition_; |
| 504 mutable GURL paste_and_go_alternate_nav_url_; | 492 mutable GURL paste_and_go_alternate_nav_url_; |
| 505 | 493 |
| 506 Profile* profile_; | 494 Profile* profile_; |
| 507 | 495 |
| 508 DISALLOW_COPY_AND_ASSIGN(AutocompleteEditModel); | 496 DISALLOW_COPY_AND_ASSIGN(AutocompleteEditModel); |
| 509 }; | 497 }; |
| 510 | 498 |
| 511 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_H_ | 499 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_H_ |
| OLD | NEW |