OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 5 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 has_temporary_text_ = false; | 873 has_temporary_text_ = false; |
874 | 874 |
875 if (user_input_in_progress_ || !in_revert_) | 875 if (user_input_in_progress_ || !in_revert_) |
876 delegate_->OnInputStateChanged(); | 876 delegate_->OnInputStateChanged(); |
877 } | 877 } |
878 | 878 |
879 void OmniboxEditModel::ClearKeyword(const base::string16& visible_text) { | 879 void OmniboxEditModel::ClearKeyword(const base::string16& visible_text) { |
880 autocomplete_controller()->Stop(false); | 880 autocomplete_controller()->Stop(false); |
881 omnibox_controller_->ClearPopupKeywordMode(); | 881 omnibox_controller_->ClearPopupKeywordMode(); |
882 | 882 |
883 // Add a space after the keyword to allow the user to continue typing without | 883 const base::string16 window_text(keyword_ + visible_text); |
884 // re-enabling keyword mode. | |
885 const base::string16 window_text = | |
886 keyword_ + base::ASCIIToUTF16(" ") + visible_text; | |
887 | 884 |
888 // Only reset the result if the edit text has changed since the | 885 // Only reset the result if the edit text has changed since the |
889 // keyword was accepted, or if the popup is closed. | 886 // keyword was accepted, or if the popup is closed. |
890 if (just_deleted_text_ || !visible_text.empty() || | 887 if (just_deleted_text_ || !visible_text.empty() || |
891 !(popup_model() && popup_model()->IsOpen())) { | 888 !(popup_model() && popup_model()->IsOpen())) { |
892 view_->OnBeforePossibleChange(); | 889 view_->OnBeforePossibleChange(); |
893 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length() + 1, | 890 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length(), |
894 false, false); | 891 false, false); |
895 keyword_.clear(); | 892 keyword_.clear(); |
896 is_keyword_hint_ = false; | 893 is_keyword_hint_ = false; |
897 view_->OnAfterPossibleChange(); | 894 view_->OnAfterPossibleChange(); |
898 just_deleted_text_ = true; // OnAfterPossibleChange() fails to clear this | 895 just_deleted_text_ = true; // OnAfterPossibleChange() fails to clear this |
899 // since the edit contents have actually grown | 896 // since the edit contents have actually grown |
900 // longer. | 897 // longer. |
901 } else { | 898 } else { |
902 is_keyword_hint_ = true; | 899 is_keyword_hint_ = true; |
903 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length() + 1, | 900 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length(), |
904 false, true); | 901 false, true); |
905 } | 902 } |
906 | 903 |
907 view_->UpdatePlaceholderText(); | 904 view_->UpdatePlaceholderText(); |
908 } | 905 } |
909 | 906 |
910 void OmniboxEditModel::OnSetFocus(bool control_down) { | 907 void OmniboxEditModel::OnSetFocus(bool control_down) { |
911 last_omnibox_focus_ = base::TimeTicks::Now(); | 908 last_omnibox_focus_ = base::TimeTicks::Now(); |
912 user_input_since_focus_ = false; | 909 user_input_since_focus_ = false; |
913 | 910 |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1445 // Update state and notify view if the omnibox has focus and the caret | 1442 // Update state and notify view if the omnibox has focus and the caret |
1446 // visibility changed. | 1443 // visibility changed. |
1447 const bool was_caret_visible = is_caret_visible(); | 1444 const bool was_caret_visible = is_caret_visible(); |
1448 focus_state_ = state; | 1445 focus_state_ = state; |
1449 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1446 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
1450 is_caret_visible() != was_caret_visible) | 1447 is_caret_visible() != was_caret_visible) |
1451 view_->ApplyCaretVisibility(); | 1448 view_->ApplyCaretVisibility(); |
1452 | 1449 |
1453 delegate_->OnFocusChanged(focus_state_, reason); | 1450 delegate_->OnFocusChanged(focus_state_, reason); |
1454 } | 1451 } |
OLD | NEW |