Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_edit_model.cc

Issue 20587003: InstantExtended: record initial focus state for omnibox interactions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } // namespace 135 } // namespace
136 136
137 /////////////////////////////////////////////////////////////////////////////// 137 ///////////////////////////////////////////////////////////////////////////////
138 // OmniboxEditModel::State 138 // OmniboxEditModel::State
139 139
140 OmniboxEditModel::State::State(bool user_input_in_progress, 140 OmniboxEditModel::State::State(bool user_input_in_progress,
141 const string16& user_text, 141 const string16& user_text,
142 const string16& gray_text, 142 const string16& gray_text,
143 const string16& keyword, 143 const string16& keyword,
144 bool is_keyword_hint, 144 bool is_keyword_hint,
145 OmniboxFocusState focus_state) 145 OmniboxFocusState focus_state,
146 OmniboxFocusState focus_state_for_input)
146 : user_input_in_progress(user_input_in_progress), 147 : user_input_in_progress(user_input_in_progress),
147 user_text(user_text), 148 user_text(user_text),
148 gray_text(gray_text), 149 gray_text(gray_text),
149 keyword(keyword), 150 keyword(keyword),
150 is_keyword_hint(is_keyword_hint), 151 is_keyword_hint(is_keyword_hint),
151 focus_state(focus_state) { 152 focus_state(focus_state),
153 focus_state_for_input(focus_state_for_input) {
152 } 154 }
153 155
154 OmniboxEditModel::State::~State() { 156 OmniboxEditModel::State::~State() {
155 } 157 }
156 158
157 /////////////////////////////////////////////////////////////////////////////// 159 ///////////////////////////////////////////////////////////////////////////////
158 // OmniboxEditModel 160 // OmniboxEditModel
159 161
160 OmniboxEditModel::OmniboxEditModel(OmniboxView* view, 162 OmniboxEditModel::OmniboxEditModel(OmniboxView* view,
161 OmniboxEditController* controller, 163 OmniboxEditController* controller,
162 Profile* profile) 164 Profile* profile)
163 : view_(view), 165 : view_(view),
164 controller_(controller), 166 controller_(controller),
165 focus_state_(OMNIBOX_FOCUS_NONE), 167 focus_state_(OMNIBOX_FOCUS_NONE),
168 focus_state_for_input_(OMNIBOX_FOCUS_NONE),
166 user_input_in_progress_(false), 169 user_input_in_progress_(false),
167 just_deleted_text_(false), 170 just_deleted_text_(false),
168 has_temporary_text_(false), 171 has_temporary_text_(false),
169 paste_state_(NONE), 172 paste_state_(NONE),
170 control_key_state_(UP), 173 control_key_state_(UP),
171 is_keyword_hint_(false), 174 is_keyword_hint_(false),
172 profile_(profile), 175 profile_(profile),
173 in_revert_(false), 176 in_revert_(false),
174 allow_exact_keyword_match_(false) { 177 allow_exact_keyword_match_(false) {
175 omnibox_controller_.reset(new OmniboxController(this, profile)); 178 omnibox_controller_.reset(new OmniboxController(this, profile));
(...skipping 19 matching lines...) Expand all
195 } else { 198 } else {
196 InternalSetUserText(user_text); 199 InternalSetUserText(user_text);
197 } 200 }
198 } 201 }
199 202
200 return State(user_input_in_progress_, 203 return State(user_input_in_progress_,
201 user_text_, 204 user_text_,
202 view_->GetGrayTextAutocompletion(), 205 view_->GetGrayTextAutocompletion(),
203 keyword_, 206 keyword_,
204 is_keyword_hint_, 207 is_keyword_hint_,
205 focus_state_); 208 focus_state_,
209 focus_state_for_input_);
206 } 210 }
207 211
208 void OmniboxEditModel::RestoreState(const State& state) { 212 void OmniboxEditModel::RestoreState(const State& state) {
209 SetFocusState(state.focus_state, OMNIBOX_FOCUS_CHANGE_TAB_SWITCH); 213 SetFocusState(state.focus_state, OMNIBOX_FOCUS_CHANGE_TAB_SWITCH);
214 focus_state_for_input_ = state.focus_state_for_input;
210 // Restore any user editing. 215 // Restore any user editing.
211 if (state.user_input_in_progress) { 216 if (state.user_input_in_progress) {
212 // NOTE: Be sure and set keyword-related state BEFORE invoking 217 // NOTE: Be sure and set keyword-related state BEFORE invoking
213 // DisplayTextFromUserText(), as its result depends upon this state. 218 // DisplayTextFromUserText(), as its result depends upon this state.
214 keyword_ = state.keyword; 219 keyword_ = state.keyword;
215 is_keyword_hint_ = state.is_keyword_hint; 220 is_keyword_hint_ = state.is_keyword_hint;
216 view_->SetUserText(state.user_text, 221 view_->SetUserText(state.user_text,
217 DisplayTextFromUserText(state.user_text), false); 222 DisplayTextFromUserText(state.user_text), false);
218 view_->SetGrayTextAutocompletion(state.gray_text); 223 view_->SetGrayTextAutocompletion(state.gray_text);
219 } 224 }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_); 443 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_);
439 } 444 }
440 445
441 void OmniboxEditModel::Revert() { 446 void OmniboxEditModel::Revert() {
442 SetInputInProgress(false); 447 SetInputInProgress(false);
443 paste_state_ = NONE; 448 paste_state_ = NONE;
444 InternalSetUserText(string16()); 449 InternalSetUserText(string16());
445 keyword_.clear(); 450 keyword_.clear();
446 is_keyword_hint_ = false; 451 is_keyword_hint_ = false;
447 has_temporary_text_ = false; 452 has_temporary_text_ = false;
453 focus_state_for_input_ = OMNIBOX_FOCUS_NONE;
Peter Kasting 2013/07/26 22:58:09 Is this right? What if the user reverts everythin
samarth 2013/07/26 23:00:55 That works today because PageClassifcation is only
samarth 2013/07/26 23:19:01 Ok, Peter convinced me that not keeping this here
Peter Kasting 2013/07/26 23:22:34 Turns out you mean OpenMatch(), which is called, b
Mark P 2013/07/26 23:36:35 Okay. That sounds fine.
448 view_->SetWindowTextAndCaretPos(permanent_text_, 454 view_->SetWindowTextAndCaretPos(permanent_text_,
449 has_focus() ? permanent_text_.length() : 0, 455 has_focus() ? permanent_text_.length() : 0,
450 false, true); 456 false, true);
451 AutocompleteActionPredictor* action_predictor = 457 AutocompleteActionPredictor* action_predictor =
452 AutocompleteActionPredictorFactory::GetForProfile(profile_); 458 AutocompleteActionPredictorFactory::GetForProfile(profile_);
453 if (action_predictor) 459 if (action_predictor)
454 action_predictor->ClearTransitionalMatches(); 460 action_predictor->ClearTransitionalMatches();
455 } 461 }
456 462
457 void OmniboxEditModel::StartAutocomplete( 463 void OmniboxEditModel::StartAutocomplete(
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 // TODO(jered): Rip this out along with StartZeroSuggest. 840 // TODO(jered): Rip this out along with StartZeroSuggest.
835 autocomplete_controller()->StopZeroSuggest(); 841 autocomplete_controller()->StopZeroSuggest();
836 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_); 842 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_);
837 } 843 }
838 844
839 void OmniboxEditModel::OnKillFocus() { 845 void OmniboxEditModel::OnKillFocus() {
840 // TODO(samarth): determine if it is safe to move the call to 846 // TODO(samarth): determine if it is safe to move the call to
841 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us 847 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us
842 // just call SetFocusState() to handle the state change. 848 // just call SetFocusState() to handle the state change.
843 focus_state_ = OMNIBOX_FOCUS_NONE; 849 focus_state_ = OMNIBOX_FOCUS_NONE;
850 focus_state_for_input_ = OMNIBOX_FOCUS_NONE;
844 control_key_state_ = UP; 851 control_key_state_ = UP;
845 paste_state_ = NONE; 852 paste_state_ = NONE;
846 } 853 }
847 854
848 bool OmniboxEditModel::OnEscapeKeyPressed() { 855 bool OmniboxEditModel::OnEscapeKeyPressed() {
849 if (has_temporary_text_) { 856 if (has_temporary_text_) {
850 if (CurrentMatch(NULL).destination_url != original_url_) { 857 if (CurrentMatch(NULL).destination_url != original_url_) {
851 RevertTemporaryText(true); 858 RevertTemporaryText(true);
852 return true; 859 return true;
853 } 860 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 bool just_deleted_text, 1014 bool just_deleted_text,
1008 bool allow_keyword_ui_change) { 1015 bool allow_keyword_ui_change) {
1009 // Update the paste state as appropriate: if we're just finishing a paste 1016 // Update the paste state as appropriate: if we're just finishing a paste
1010 // that replaced all the text, preserve that information; otherwise, if we've 1017 // that replaced all the text, preserve that information; otherwise, if we've
1011 // made some other edit, clear paste tracking. 1018 // made some other edit, clear paste tracking.
1012 if (paste_state_ == PASTING) 1019 if (paste_state_ == PASTING)
1013 paste_state_ = PASTED; 1020 paste_state_ = PASTED;
1014 else if (text_differs) 1021 else if (text_differs)
1015 paste_state_ = NONE; 1022 paste_state_ = NONE;
1016 1023
1017 // Restore caret visibility whenever the user changes text or selection in the 1024 if (text_differs || selection_differs) {
1018 // omnibox. 1025 // Record current focus state for this input if we haven't already.
1019 if (text_differs || selection_differs) 1026 DCHECK_NE(OMNIBOX_FOCUS_NONE, focus_state_);
1027 if (focus_state_for_input_ == OMNIBOX_FOCUS_NONE)
1028 focus_state_for_input_ = focus_state_;
1029
1030 // Restore caret visibility whenever the user changes text or selection in
1031 // the omnibox.
1020 SetFocusState(OMNIBOX_FOCUS_VISIBLE, OMNIBOX_FOCUS_CHANGE_TYPING); 1032 SetFocusState(OMNIBOX_FOCUS_VISIBLE, OMNIBOX_FOCUS_CHANGE_TYPING);
1033 }
1021 1034
1022 // Modifying the selection counts as accepting the autocompleted text. 1035 // Modifying the selection counts as accepting the autocompleted text.
1023 const bool user_text_changed = 1036 const bool user_text_changed =
1024 text_differs || (selection_differs && !inline_autocomplete_text_.empty()); 1037 text_differs || (selection_differs && !inline_autocomplete_text_.empty());
1025 1038
1026 // If something has changed while the control key is down, prevent 1039 // If something has changed while the control key is down, prevent
1027 // "ctrl-enter" until the control key is released. When we do this, we need 1040 // "ctrl-enter" until the control key is released. When we do this, we need
1028 // to update the popup if it's open, since the desired_tld will have changed. 1041 // to update the popup if it's open, since the desired_tld will have changed.
1029 if ((text_differs || selection_differs) && 1042 if ((text_differs || selection_differs) &&
1030 (control_key_state_ == DOWN_WITHOUT_CHANGE)) { 1043 (control_key_state_ == DOWN_WITHOUT_CHANGE)) {
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 return true; 1264 return true;
1252 default: 1265 default:
1253 return false; 1266 return false;
1254 } 1267 }
1255 } 1268 }
1256 1269
1257 metrics::OmniboxEventProto::PageClassification 1270 metrics::OmniboxEventProto::PageClassification
1258 OmniboxEditModel::ClassifyPage() const { 1271 OmniboxEditModel::ClassifyPage() const {
1259 if (!delegate_->CurrentPageExists()) 1272 if (!delegate_->CurrentPageExists())
1260 return metrics::OmniboxEventProto::OTHER; 1273 return metrics::OmniboxEventProto::OTHER;
1261 if (delegate_->IsInstantNTP()) 1274 if (delegate_->IsInstantNTP()) {
1262 return metrics::OmniboxEventProto::INSTANT_NEW_TAB_PAGE; 1275 DCHECK_NE(OMNIBOX_FOCUS_NONE, focus_state_for_input_);
1276 if (focus_state_for_input_ == OMNIBOX_FOCUS_VISIBLE) {
1277 return metrics::OmniboxEventProto::
1278 INSTANT_NEW_TAB_PAGE_WITH_OMNIBOX_AS_STARTING_FOCUS;
1279 } else if (focus_state_for_input_ == OMNIBOX_FOCUS_INVISIBLE) {
Peter Kasting 2013/07/26 23:22:34 Nit: No else after return; also, per Chromium styl
samarth 2013/07/29 18:55:35 Done.
1280 return metrics::OmniboxEventProto::
1281 INSTANT_NEW_TAB_PAGE_WITH_FAKEBOX_AS_STARTING_FOCUS;
1282 }
1283 NOTREACHED();
1284 return metrics::OmniboxEventProto::OBSOLETE_INSTANT_NEW_TAB_PAGE;
1285 }
1263 const GURL& gurl = delegate_->GetURL(); 1286 const GURL& gurl = delegate_->GetURL();
1264 if (!gurl.is_valid()) 1287 if (!gurl.is_valid())
1265 return metrics::OmniboxEventProto::INVALID_SPEC; 1288 return metrics::OmniboxEventProto::INVALID_SPEC;
1266 const std::string& url = gurl.spec(); 1289 const std::string& url = gurl.spec();
1267 if (url == chrome::kChromeUINewTabURL) 1290 if (url == chrome::kChromeUINewTabURL)
1268 return metrics::OmniboxEventProto::NEW_TAB_PAGE; 1291 return metrics::OmniboxEventProto::NEW_TAB_PAGE;
1269 if (url == content::kAboutBlankURL) 1292 if (url == content::kAboutBlankURL)
1270 return metrics::OmniboxEventProto::BLANK; 1293 return metrics::OmniboxEventProto::BLANK;
1271 if (url == profile()->GetPrefs()->GetString(prefs::kHomePage)) 1294 if (url == profile()->GetPrefs()->GetString(prefs::kHomePage))
1272 return metrics::OmniboxEventProto::HOMEPAGE; 1295 return metrics::OmniboxEventProto::HOMEPAGE;
(...skipping 23 matching lines...) Expand all
1296 instant->OmniboxFocusChanged(state, reason, NULL); 1319 instant->OmniboxFocusChanged(state, reason, NULL);
1297 1320
1298 // Update state and notify view if the omnibox has focus and the caret 1321 // Update state and notify view if the omnibox has focus and the caret
1299 // visibility changed. 1322 // visibility changed.
1300 const bool was_caret_visible = is_caret_visible(); 1323 const bool was_caret_visible = is_caret_visible();
1301 focus_state_ = state; 1324 focus_state_ = state;
1302 if (focus_state_ != OMNIBOX_FOCUS_NONE && 1325 if (focus_state_ != OMNIBOX_FOCUS_NONE &&
1303 is_caret_visible() != was_caret_visible) 1326 is_caret_visible() != was_caret_visible)
1304 view_->ApplyCaretVisibility(); 1327 view_->ApplyCaretVisibility();
1305 } 1328 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698