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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 using content::UserMetricsAction; | 63 using content::UserMetricsAction; |
64 using predictors::AutocompleteActionPredictor; | 64 using predictors::AutocompleteActionPredictor; |
65 using predictors::AutocompleteActionPredictorFactory; | 65 using predictors::AutocompleteActionPredictorFactory; |
66 | 66 |
67 /////////////////////////////////////////////////////////////////////////////// | 67 /////////////////////////////////////////////////////////////////////////////// |
68 // OmniboxEditModel::State | 68 // OmniboxEditModel::State |
69 | 69 |
70 OmniboxEditModel::State::State(bool user_input_in_progress, | 70 OmniboxEditModel::State::State(bool user_input_in_progress, |
71 const string16& user_text, | 71 const string16& user_text, |
72 const string16& keyword, | 72 const string16& keyword, |
73 bool is_keyword_hint) | 73 bool is_keyword_hint, |
| 74 bool is_caret_visible) |
74 : user_input_in_progress(user_input_in_progress), | 75 : user_input_in_progress(user_input_in_progress), |
75 user_text(user_text), | 76 user_text(user_text), |
76 keyword(keyword), | 77 keyword(keyword), |
77 is_keyword_hint(is_keyword_hint) { | 78 is_keyword_hint(is_keyword_hint), |
| 79 is_caret_visible(is_caret_visible) { |
78 } | 80 } |
79 | 81 |
80 OmniboxEditModel::State::~State() { | 82 OmniboxEditModel::State::~State() { |
81 } | 83 } |
82 | 84 |
83 /////////////////////////////////////////////////////////////////////////////// | 85 /////////////////////////////////////////////////////////////////////////////// |
84 // OmniboxEditModel | 86 // OmniboxEditModel |
85 | 87 |
86 OmniboxEditModel::OmniboxEditModel(OmniboxView* view, | 88 OmniboxEditModel::OmniboxEditModel(OmniboxView* view, |
87 OmniboxEditController* controller, | 89 OmniboxEditController* controller, |
88 Profile* profile) | 90 Profile* profile) |
89 : view_(view), | 91 : view_(view), |
90 popup_(NULL), | 92 popup_(NULL), |
91 controller_(controller), | 93 controller_(controller), |
92 has_focus_(false), | 94 has_focus_(false), |
| 95 is_caret_visible_(true), |
93 user_input_in_progress_(false), | 96 user_input_in_progress_(false), |
94 just_deleted_text_(false), | 97 just_deleted_text_(false), |
95 has_temporary_text_(false), | 98 has_temporary_text_(false), |
96 is_temporary_text_set_by_instant_(false), | 99 is_temporary_text_set_by_instant_(false), |
97 paste_state_(NONE), | 100 paste_state_(NONE), |
98 control_key_state_(UP), | 101 control_key_state_(UP), |
99 is_keyword_hint_(false), | 102 is_keyword_hint_(false), |
100 profile_(profile), | 103 profile_(profile), |
101 in_revert_(false), | 104 in_revert_(false), |
102 allow_exact_keyword_match_(false) { | 105 allow_exact_keyword_match_(false) { |
(...skipping 18 matching lines...) Expand all Loading... |
121 // on switching back, typing will "just work"). | 124 // on switching back, typing will "just work"). |
122 const string16 user_text(UserTextFromDisplayText(view_->GetText())); | 125 const string16 user_text(UserTextFromDisplayText(view_->GetText())); |
123 if (user_text.empty()) { | 126 if (user_text.empty()) { |
124 view_->RevertAll(); | 127 view_->RevertAll(); |
125 view_->SelectAll(true); | 128 view_->SelectAll(true); |
126 } else { | 129 } else { |
127 InternalSetUserText(user_text); | 130 InternalSetUserText(user_text); |
128 } | 131 } |
129 } | 132 } |
130 | 133 |
131 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_); |
132 } | 136 } |
133 | 137 |
134 void OmniboxEditModel::RestoreState(const State& state) { | 138 void OmniboxEditModel::RestoreState(const State& state) { |
| 139 SetCaretVisibility(state.is_caret_visible); |
135 // Restore any user editing. | 140 // Restore any user editing. |
136 if (state.user_input_in_progress) { | 141 if (state.user_input_in_progress) { |
137 // NOTE: Be sure and set keyword-related state BEFORE invoking | 142 // NOTE: Be sure and set keyword-related state BEFORE invoking |
138 // DisplayTextFromUserText(), as its result depends upon this state. | 143 // DisplayTextFromUserText(), as its result depends upon this state. |
139 keyword_ = state.keyword; | 144 keyword_ = state.keyword; |
140 is_keyword_hint_ = state.is_keyword_hint; | 145 is_keyword_hint_ = state.is_keyword_hint; |
141 view_->SetUserText(state.user_text, | 146 view_->SetUserText(state.user_text, |
142 DisplayTextFromUserText(state.user_text), false); | 147 DisplayTextFromUserText(state.user_text), false); |
143 } | 148 } |
144 } | 149 } |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 // that we avoid PermanentURL() here because it's not guaranteed to give us | 726 // that we avoid PermanentURL() here because it's not guaranteed to give us |
722 // the actual underlying current URL, e.g. if we're on the NTP and the | 727 // the actual underlying current URL, e.g. if we're on the NTP and the |
723 // |permanent_text_| is empty. | 728 // |permanent_text_| is empty. |
724 autocomplete_controller_->StartZeroSuggest(web_contents->GetURL(), | 729 autocomplete_controller_->StartZeroSuggest(web_contents->GetURL(), |
725 user_text_); | 730 user_text_); |
726 } | 731 } |
727 | 732 |
728 NotifySearchTabHelper(); | 733 NotifySearchTabHelper(); |
729 } | 734 } |
730 | 735 |
| 736 void OmniboxEditModel::SetCaretVisibility(bool visible) { |
| 737 if (has_focus_ && visible != is_caret_visible_) { |
| 738 is_caret_visible_ = visible; |
| 739 view_->ApplyCaretVisibility(); |
| 740 } |
| 741 } |
| 742 |
731 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { | 743 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { |
732 SetInstantSuggestion(InstantSuggestion()); | 744 SetInstantSuggestion(InstantSuggestion()); |
733 | 745 |
734 if (InstantController* instant = controller_->GetInstant()) | 746 if (InstantController* instant = controller_->GetInstant()) |
735 instant->OmniboxLostFocus(view_gaining_focus); | 747 instant->OmniboxLostFocus(view_gaining_focus); |
736 | 748 |
737 // TODO(jered): Rip this out along with StartZeroSuggest. | 749 // TODO(jered): Rip this out along with StartZeroSuggest. |
738 autocomplete_controller_->StopZeroSuggest(); | 750 autocomplete_controller_->StopZeroSuggest(); |
739 NotifySearchTabHelper(); | 751 NotifySearchTabHelper(); |
740 } | 752 } |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 } | 1274 } |
1263 | 1275 |
1264 void OmniboxEditModel::ClassifyStringForPasteAndGo( | 1276 void OmniboxEditModel::ClassifyStringForPasteAndGo( |
1265 const string16& text, | 1277 const string16& text, |
1266 AutocompleteMatch* match, | 1278 AutocompleteMatch* match, |
1267 GURL* alternate_nav_url) const { | 1279 GURL* alternate_nav_url) const { |
1268 DCHECK(match); | 1280 DCHECK(match); |
1269 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, | 1281 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, |
1270 string16(), false, false, match, alternate_nav_url); | 1282 string16(), false, false, match, alternate_nav_url); |
1271 } | 1283 } |
OLD | NEW |