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 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // Restore caret visibility whenever the user focuses back into the omnibox. |
719 SetCaretVisibility(true); | 719 SetCaretVisibility(true); |
720 | 720 |
721 if (InstantController* instant = controller_->GetInstant()) | 721 if (InstantController* instant = controller_->GetInstant()) { |
722 instant->OmniboxGotFocus(); | 722 instant->OmniboxFocusChanged(FOCUS_VISIBLE, |
| 723 FOCUS_CHANGE_EXPLICIT, NULL); |
| 724 } |
723 | 725 |
724 content::WebContents* web_contents = controller_->GetWebContents(); | 726 content::WebContents* web_contents = controller_->GetWebContents(); |
725 if (web_contents) { | 727 if (web_contents) { |
726 // TODO(jered): We may want to merge this into Start() and just call that | 728 // 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 | 729 // 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 | 730 // 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 | 731 // the actual underlying current URL, e.g. if we're on the NTP and the |
730 // |permanent_text_| is empty. | 732 // |permanent_text_| is empty. |
731 autocomplete_controller_->StartZeroSuggest(web_contents->GetURL(), | 733 autocomplete_controller_->StartZeroSuggest(web_contents->GetURL(), |
732 user_text_); | 734 user_text_); |
733 } | 735 } |
734 | 736 |
735 NotifySearchTabHelper(); | 737 NotifySearchTabHelper(); |
736 } | 738 } |
737 | 739 |
738 void OmniboxEditModel::SetCaretVisibility(bool visible) { | 740 void OmniboxEditModel::SetCaretVisibility(bool visible) { |
| 741 SetCaretVisibilityInternal(visible, FOCUS_CHANGE_EXPLICIT); |
| 742 } |
| 743 |
| 744 void OmniboxEditModel::SetCaretVisibilityInternal( |
| 745 bool visible, |
| 746 OmniboxFocusChangeReason reason) { |
739 if (has_focus_ && visible != is_caret_visible_) { | 747 if (has_focus_ && visible != is_caret_visible_) { |
| 748 if (InstantController* instant = controller_->GetInstant()) { |
| 749 instant->OmniboxFocusChanged(visible ? FOCUS_VISIBLE : FOCUS_INVISIBLE, |
| 750 reason, NULL); |
| 751 } |
740 is_caret_visible_ = visible; | 752 is_caret_visible_ = visible; |
741 view_->ApplyCaretVisibility(); | 753 view_->ApplyCaretVisibility(); |
742 } | 754 } |
743 } | 755 } |
744 | 756 |
745 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { | 757 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { |
746 SetInstantSuggestion(InstantSuggestion()); | 758 SetInstantSuggestion(InstantSuggestion()); |
747 | 759 |
748 if (InstantController* instant = controller_->GetInstant()) | 760 if (InstantController* instant = controller_->GetInstant()) { |
749 instant->OmniboxLostFocus(view_gaining_focus); | 761 instant->OmniboxFocusChanged(FOCUS_NONE, FOCUS_CHANGE_EXPLICIT, |
| 762 view_gaining_focus); |
| 763 } |
750 | 764 |
751 // TODO(jered): Rip this out along with StartZeroSuggest. | 765 // TODO(jered): Rip this out along with StartZeroSuggest. |
752 autocomplete_controller_->StopZeroSuggest(); | 766 autocomplete_controller_->StopZeroSuggest(); |
753 NotifySearchTabHelper(); | 767 NotifySearchTabHelper(); |
754 } | 768 } |
755 | 769 |
756 void OmniboxEditModel::OnKillFocus() { | 770 void OmniboxEditModel::OnKillFocus() { |
757 has_focus_ = false; | 771 has_focus_ = false; |
758 control_key_state_ = UP; | 772 control_key_state_ = UP; |
759 paste_state_ = NONE; | 773 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 | 959 // that replaced all the text, preserve that information; otherwise, if we've |
946 // made some other edit, clear paste tracking. | 960 // made some other edit, clear paste tracking. |
947 if (paste_state_ == PASTING) | 961 if (paste_state_ == PASTING) |
948 paste_state_ = PASTED; | 962 paste_state_ = PASTED; |
949 else if (text_differs) | 963 else if (text_differs) |
950 paste_state_ = NONE; | 964 paste_state_ = NONE; |
951 | 965 |
952 // Restore caret visibility whenever the user changes text or selection in the | 966 // Restore caret visibility whenever the user changes text or selection in the |
953 // omnibox. | 967 // omnibox. |
954 if (text_differs || selection_differs) | 968 if (text_differs || selection_differs) |
955 SetCaretVisibility(true); | 969 SetCaretVisibilityInternal(true, FOCUS_CHANGE_TYPING); |
956 | 970 |
957 // Modifying the selection counts as accepting the autocompleted text. | 971 // Modifying the selection counts as accepting the autocompleted text. |
958 const bool user_text_changed = | 972 const bool user_text_changed = |
959 text_differs || (selection_differs && !inline_autocomplete_text_.empty()); | 973 text_differs || (selection_differs && !inline_autocomplete_text_.empty()); |
960 | 974 |
961 // If something has changed while the control key is down, prevent | 975 // 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 | 976 // "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. | 977 // to update the popup if it's open, since the desired_tld will have changed. |
964 if ((text_differs || selection_differs) && | 978 if ((text_differs || selection_differs) && |
965 (control_key_state_ == DOWN_WITHOUT_CHANGE)) { | 979 (control_key_state_ == DOWN_WITHOUT_CHANGE)) { |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 } | 1295 } |
1282 | 1296 |
1283 void OmniboxEditModel::ClassifyStringForPasteAndGo( | 1297 void OmniboxEditModel::ClassifyStringForPasteAndGo( |
1284 const string16& text, | 1298 const string16& text, |
1285 AutocompleteMatch* match, | 1299 AutocompleteMatch* match, |
1286 GURL* alternate_nav_url) const { | 1300 GURL* alternate_nav_url) const { |
1287 DCHECK(match); | 1301 DCHECK(match); |
1288 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, | 1302 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, |
1289 string16(), false, false, match, alternate_nav_url); | 1303 string16(), false, false, match, alternate_nav_url); |
1290 } | 1304 } |
OLD | NEW |