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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 } else { | 129 } else { |
130 InternalSetUserText(user_text); | 130 InternalSetUserText(user_text); |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 return State(user_input_in_progress_, user_text_, keyword_, is_keyword_hint_, | 134 return State(user_input_in_progress_, user_text_, keyword_, is_keyword_hint_, |
135 is_caret_visible_); | 135 is_caret_visible_); |
136 } | 136 } |
137 | 137 |
138 void OmniboxEditModel::RestoreState(const State& state) { | 138 void OmniboxEditModel::RestoreState(const State& state) { |
139 SetCaretVisibility(state.is_caret_visible); | 139 SetCaretVisibilityInternal(state.is_caret_visible, FOCUS_CHANGE_TAB_SWITCH); |
140 // Restore any user editing. | 140 // Restore any user editing. |
141 if (state.user_input_in_progress) { | 141 if (state.user_input_in_progress) { |
142 // NOTE: Be sure and set keyword-related state BEFORE invoking | 142 // NOTE: Be sure and set keyword-related state BEFORE invoking |
143 // DisplayTextFromUserText(), as its result depends upon this state. | 143 // DisplayTextFromUserText(), as its result depends upon this state. |
144 keyword_ = state.keyword; | 144 keyword_ = state.keyword; |
145 is_keyword_hint_ = state.is_keyword_hint; | 145 is_keyword_hint_ = state.is_keyword_hint; |
146 view_->SetUserText(state.user_text, | 146 view_->SetUserText(state.user_text, |
147 DisplayTextFromUserText(state.user_text), false); | 147 DisplayTextFromUserText(state.user_text), false); |
148 } | 148 } |
149 } | 149 } |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
708 } | 708 } |
709 } | 709 } |
710 | 710 |
711 const AutocompleteResult& OmniboxEditModel::result() const { | 711 const AutocompleteResult& OmniboxEditModel::result() const { |
712 return autocomplete_controller_->result(); | 712 return autocomplete_controller_->result(); |
713 } | 713 } |
714 | 714 |
715 void OmniboxEditModel::OnSetFocus(bool control_down) { | 715 void OmniboxEditModel::OnSetFocus(bool control_down) { |
716 has_focus_ = true; | 716 has_focus_ = true; |
717 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; | 717 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; |
718 // Restore caret visibility whenever the user focuses back into the omnibox. | 718 // If the omnibox lost focus while the caret was hidden and then regained |
719 // focus, OnSetFocus() is called and should restore visibility. Note that | |
720 // focus can be regained without an accompanying call to | |
721 // OmniboxView::SetFocus(), e.g. by tabbing in. | |
719 SetCaretVisibility(true); | 722 SetCaretVisibility(true); |
720 | 723 |
721 if (InstantController* instant = controller_->GetInstant()) | 724 if (InstantController* instant = controller_->GetInstant()) { |
Peter Kasting
2012/12/08 01:12:20
Oh, sorry, didn't notice this before.
Please do n
samarth
2012/12/08 01:51:34
Happy to, I really don't like them either.
| |
722 instant->OmniboxGotFocus(); | 725 instant->OmniboxFocusChanged(FOCUS_VISIBLE, |
726 FOCUS_CHANGE_EXPLICIT, NULL); | |
727 } | |
Peter Kasting
2012/12/07 23:22:03
This block seems like it duplicates SetCaretVisibi
samarth
2012/12/08 00:55:47
It's sometimes necessary. Added comment.
| |
723 | 728 |
724 content::WebContents* web_contents = controller_->GetWebContents(); | 729 content::WebContents* web_contents = controller_->GetWebContents(); |
725 if (web_contents) { | 730 if (web_contents) { |
726 // TODO(jered): We may want to merge this into Start() and just call that | 731 // TODO(jered): We may want to merge this into Start() and just call that |
727 // here rather than having a special entry point for zero-suggest. Note | 732 // here rather than having a special entry point for zero-suggest. Note |
728 // that we avoid PermanentURL() here because it's not guaranteed to give us | 733 // that we avoid PermanentURL() here because it's not guaranteed to give us |
729 // the actual underlying current URL, e.g. if we're on the NTP and the | 734 // the actual underlying current URL, e.g. if we're on the NTP and the |
730 // |permanent_text_| is empty. | 735 // |permanent_text_| is empty. |
731 autocomplete_controller_->StartZeroSuggest(web_contents->GetURL(), | 736 autocomplete_controller_->StartZeroSuggest(web_contents->GetURL(), |
732 user_text_); | 737 user_text_); |
733 } | 738 } |
734 | 739 |
735 NotifySearchTabHelper(); | 740 NotifySearchTabHelper(); |
736 } | 741 } |
737 | 742 |
738 void OmniboxEditModel::SetCaretVisibility(bool visible) { | 743 void OmniboxEditModel::SetCaretVisibility(bool visible) { |
744 SetCaretVisibilityInternal(visible, FOCUS_CHANGE_EXPLICIT); | |
745 } | |
746 | |
747 void OmniboxEditModel::SetCaretVisibilityInternal( | |
Peter Kasting
2012/12/07 23:22:03
Function definition order should match .h declarat
samarth
2012/12/08 00:55:47
Done.
| |
748 bool visible, | |
749 OmniboxFocusChangeReason reason) { | |
739 if (has_focus_ && visible != is_caret_visible_) { | 750 if (has_focus_ && visible != is_caret_visible_) { |
751 if (InstantController* instant = controller_->GetInstant()) { | |
752 instant->OmniboxFocusChanged(visible ? FOCUS_VISIBLE : FOCUS_INVISIBLE, | |
753 reason, NULL); | |
754 } | |
740 is_caret_visible_ = visible; | 755 is_caret_visible_ = visible; |
741 view_->ApplyCaretVisibility(); | 756 view_->ApplyCaretVisibility(); |
742 } | 757 } |
743 } | 758 } |
744 | 759 |
745 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { | 760 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { |
746 SetInstantSuggestion(InstantSuggestion()); | 761 SetInstantSuggestion(InstantSuggestion()); |
747 | 762 |
748 if (InstantController* instant = controller_->GetInstant()) | 763 if (InstantController* instant = controller_->GetInstant()) { |
749 instant->OmniboxLostFocus(view_gaining_focus); | 764 instant->OmniboxFocusChanged(FOCUS_NONE, FOCUS_CHANGE_EXPLICIT, |
765 view_gaining_focus); | |
766 } | |
750 | 767 |
751 // TODO(jered): Rip this out along with StartZeroSuggest. | 768 // TODO(jered): Rip this out along with StartZeroSuggest. |
752 autocomplete_controller_->StopZeroSuggest(); | 769 autocomplete_controller_->StopZeroSuggest(); |
753 NotifySearchTabHelper(); | 770 NotifySearchTabHelper(); |
754 } | 771 } |
755 | 772 |
756 void OmniboxEditModel::OnKillFocus() { | 773 void OmniboxEditModel::OnKillFocus() { |
757 has_focus_ = false; | 774 has_focus_ = false; |
758 control_key_state_ = UP; | 775 control_key_state_ = UP; |
759 paste_state_ = NONE; | 776 paste_state_ = NONE; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
945 // that replaced all the text, preserve that information; otherwise, if we've | 962 // that replaced all the text, preserve that information; otherwise, if we've |
946 // made some other edit, clear paste tracking. | 963 // made some other edit, clear paste tracking. |
947 if (paste_state_ == PASTING) | 964 if (paste_state_ == PASTING) |
948 paste_state_ = PASTED; | 965 paste_state_ = PASTED; |
949 else if (text_differs) | 966 else if (text_differs) |
950 paste_state_ = NONE; | 967 paste_state_ = NONE; |
951 | 968 |
952 // Restore caret visibility whenever the user changes text or selection in the | 969 // Restore caret visibility whenever the user changes text or selection in the |
953 // omnibox. | 970 // omnibox. |
954 if (text_differs || selection_differs) | 971 if (text_differs || selection_differs) |
955 SetCaretVisibility(true); | 972 SetCaretVisibilityInternal(true, FOCUS_CHANGE_TYPING); |
956 | 973 |
957 // Modifying the selection counts as accepting the autocompleted text. | 974 // Modifying the selection counts as accepting the autocompleted text. |
958 const bool user_text_changed = | 975 const bool user_text_changed = |
959 text_differs || (selection_differs && !inline_autocomplete_text_.empty()); | 976 text_differs || (selection_differs && !inline_autocomplete_text_.empty()); |
960 | 977 |
961 // If something has changed while the control key is down, prevent | 978 // If something has changed while the control key is down, prevent |
962 // "ctrl-enter" until the control key is released. When we do this, we need | 979 // "ctrl-enter" until the control key is released. When we do this, we need |
963 // to update the popup if it's open, since the desired_tld will have changed. | 980 // to update the popup if it's open, since the desired_tld will have changed. |
964 if ((text_differs || selection_differs) && | 981 if ((text_differs || selection_differs) && |
965 (control_key_state_ == DOWN_WITHOUT_CHANGE)) { | 982 (control_key_state_ == DOWN_WITHOUT_CHANGE)) { |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1281 } | 1298 } |
1282 | 1299 |
1283 void OmniboxEditModel::ClassifyStringForPasteAndGo( | 1300 void OmniboxEditModel::ClassifyStringForPasteAndGo( |
1284 const string16& text, | 1301 const string16& text, |
1285 AutocompleteMatch* match, | 1302 AutocompleteMatch* match, |
1286 GURL* alternate_nav_url) const { | 1303 GURL* alternate_nav_url) const { |
1287 DCHECK(match); | 1304 DCHECK(match); |
1288 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, | 1305 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, |
1289 string16(), false, false, match, alternate_nav_url); | 1306 string16(), false, false, match, alternate_nav_url); |
1290 } | 1307 } |
OLD | NEW |