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

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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } // namespace 139 } // namespace
140 140
141 /////////////////////////////////////////////////////////////////////////////// 141 ///////////////////////////////////////////////////////////////////////////////
142 // OmniboxEditModel::State 142 // OmniboxEditModel::State
143 143
144 OmniboxEditModel::State::State(bool user_input_in_progress, 144 OmniboxEditModel::State::State(bool user_input_in_progress,
145 const string16& user_text, 145 const string16& user_text,
146 const string16& gray_text, 146 const string16& gray_text,
147 const string16& keyword, 147 const string16& keyword,
148 bool is_keyword_hint, 148 bool is_keyword_hint,
149 OmniboxFocusState focus_state) 149 OmniboxFocusState focus_state,
150 FocusSource focus_source)
150 : user_input_in_progress(user_input_in_progress), 151 : user_input_in_progress(user_input_in_progress),
151 user_text(user_text), 152 user_text(user_text),
152 gray_text(gray_text), 153 gray_text(gray_text),
153 keyword(keyword), 154 keyword(keyword),
154 is_keyword_hint(is_keyword_hint), 155 is_keyword_hint(is_keyword_hint),
155 focus_state(focus_state) { 156 focus_state(focus_state),
157 focus_source(focus_source) {
156 } 158 }
157 159
158 OmniboxEditModel::State::~State() { 160 OmniboxEditModel::State::~State() {
159 } 161 }
160 162
161 /////////////////////////////////////////////////////////////////////////////// 163 ///////////////////////////////////////////////////////////////////////////////
162 // OmniboxEditModel 164 // OmniboxEditModel
163 165
164 OmniboxEditModel::OmniboxEditModel(OmniboxView* view, 166 OmniboxEditModel::OmniboxEditModel(OmniboxView* view,
165 OmniboxEditController* controller, 167 OmniboxEditController* controller,
166 Profile* profile) 168 Profile* profile)
167 : view_(view), 169 : view_(view),
168 controller_(controller), 170 controller_(controller),
169 focus_state_(OMNIBOX_FOCUS_NONE), 171 focus_state_(OMNIBOX_FOCUS_NONE),
172 focus_source_(INVALID),
170 user_input_in_progress_(false), 173 user_input_in_progress_(false),
171 user_input_since_focus_(true), 174 user_input_since_focus_(true),
172 just_deleted_text_(false), 175 just_deleted_text_(false),
173 has_temporary_text_(false), 176 has_temporary_text_(false),
174 paste_state_(NONE), 177 paste_state_(NONE),
175 control_key_state_(UP), 178 control_key_state_(UP),
176 is_keyword_hint_(false), 179 is_keyword_hint_(false),
177 profile_(profile), 180 profile_(profile),
178 in_revert_(false), 181 in_revert_(false),
179 allow_exact_keyword_match_(false) { 182 allow_exact_keyword_match_(false) {
(...skipping 20 matching lines...) Expand all
200 } else { 203 } else {
201 InternalSetUserText(user_text); 204 InternalSetUserText(user_text);
202 } 205 }
203 } 206 }
204 207
205 return State(user_input_in_progress_, 208 return State(user_input_in_progress_,
206 user_text_, 209 user_text_,
207 view_->GetGrayTextAutocompletion(), 210 view_->GetGrayTextAutocompletion(),
208 keyword_, 211 keyword_,
209 is_keyword_hint_, 212 is_keyword_hint_,
210 focus_state_); 213 focus_state_,
214 focus_source_);
211 } 215 }
212 216
213 void OmniboxEditModel::RestoreState(const State& state) { 217 void OmniboxEditModel::RestoreState(const State& state) {
214 SetFocusState(state.focus_state, OMNIBOX_FOCUS_CHANGE_TAB_SWITCH); 218 SetFocusState(state.focus_state, OMNIBOX_FOCUS_CHANGE_TAB_SWITCH);
219 focus_source_ = state.focus_source;
215 // Restore any user editing. 220 // Restore any user editing.
216 if (state.user_input_in_progress) { 221 if (state.user_input_in_progress) {
217 // NOTE: Be sure and set keyword-related state BEFORE invoking 222 // NOTE: Be sure and set keyword-related state BEFORE invoking
218 // DisplayTextFromUserText(), as its result depends upon this state. 223 // DisplayTextFromUserText(), as its result depends upon this state.
219 keyword_ = state.keyword; 224 keyword_ = state.keyword;
220 is_keyword_hint_ = state.is_keyword_hint; 225 is_keyword_hint_ = state.is_keyword_hint;
221 view_->SetUserText(state.user_text, 226 view_->SetUserText(state.user_text,
222 DisplayTextFromUserText(state.user_text), false); 227 DisplayTextFromUserText(state.user_text), false);
223 view_->SetGrayTextAutocompletion(state.gray_text); 228 view_->SetGrayTextAutocompletion(state.gray_text);
224 } 229 }
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 // TODO(jered): Rip this out along with StartZeroSuggest. 847 // TODO(jered): Rip this out along with StartZeroSuggest.
843 autocomplete_controller()->StopZeroSuggest(); 848 autocomplete_controller()->StopZeroSuggest();
844 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_); 849 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_);
845 } 850 }
846 851
847 void OmniboxEditModel::OnKillFocus() { 852 void OmniboxEditModel::OnKillFocus() {
848 // TODO(samarth): determine if it is safe to move the call to 853 // TODO(samarth): determine if it is safe to move the call to
849 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us 854 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us
850 // just call SetFocusState() to handle the state change. 855 // just call SetFocusState() to handle the state change.
851 focus_state_ = OMNIBOX_FOCUS_NONE; 856 focus_state_ = OMNIBOX_FOCUS_NONE;
857 focus_source_ = INVALID;
852 control_key_state_ = UP; 858 control_key_state_ = UP;
853 paste_state_ = NONE; 859 paste_state_ = NONE;
854 } 860 }
855 861
856 bool OmniboxEditModel::OnEscapeKeyPressed() { 862 bool OmniboxEditModel::OnEscapeKeyPressed() {
857 if (has_temporary_text_) { 863 if (has_temporary_text_) {
858 if (CurrentMatch(NULL).destination_url != original_url_) { 864 if (CurrentMatch(NULL).destination_url != original_url_) {
859 RevertTemporaryText(true); 865 RevertTemporaryText(true);
860 return true; 866 return true;
861 } 867 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 bool just_deleted_text, 1021 bool just_deleted_text,
1016 bool allow_keyword_ui_change) { 1022 bool allow_keyword_ui_change) {
1017 // Update the paste state as appropriate: if we're just finishing a paste 1023 // Update the paste state as appropriate: if we're just finishing a paste
1018 // that replaced all the text, preserve that information; otherwise, if we've 1024 // that replaced all the text, preserve that information; otherwise, if we've
1019 // made some other edit, clear paste tracking. 1025 // made some other edit, clear paste tracking.
1020 if (paste_state_ == PASTING) 1026 if (paste_state_ == PASTING)
1021 paste_state_ = PASTED; 1027 paste_state_ = PASTED;
1022 else if (text_differs) 1028 else if (text_differs)
1023 paste_state_ = NONE; 1029 paste_state_ = NONE;
1024 1030
1025 // Restore caret visibility whenever the user changes text or selection in the 1031 if (text_differs || selection_differs) {
1026 // omnibox. 1032 // Record current focus state for this input if we haven't already.
1027 if (text_differs || selection_differs) 1033 DCHECK_NE(OMNIBOX_FOCUS_NONE, focus_state_);
1034 if (focus_source_ == INVALID) {
1035 focus_source_ = (focus_state_ == OMNIBOX_FOCUS_VISIBLE) ?
1036 OMNIBOX : FAKEBOX;
1037 }
1038
1039 // Restore caret visibility whenever the user changes text or selection in
1040 // the omnibox.
1028 SetFocusState(OMNIBOX_FOCUS_VISIBLE, OMNIBOX_FOCUS_CHANGE_TYPING); 1041 SetFocusState(OMNIBOX_FOCUS_VISIBLE, OMNIBOX_FOCUS_CHANGE_TYPING);
1042 }
1029 1043
1030 // Modifying the selection counts as accepting the autocompleted text. 1044 // Modifying the selection counts as accepting the autocompleted text.
1031 const bool user_text_changed = 1045 const bool user_text_changed =
1032 text_differs || (selection_differs && !inline_autocomplete_text_.empty()); 1046 text_differs || (selection_differs && !inline_autocomplete_text_.empty());
1033 1047
1034 // If something has changed while the control key is down, prevent 1048 // If something has changed while the control key is down, prevent
1035 // "ctrl-enter" until the control key is released. 1049 // "ctrl-enter" until the control key is released.
1036 if ((text_differs || selection_differs) && 1050 if ((text_differs || selection_differs) &&
1037 (control_key_state_ == DOWN_WITHOUT_CHANGE)) 1051 (control_key_state_ == DOWN_WITHOUT_CHANGE))
1038 control_key_state_ = DOWN_WITH_CHANGE; 1052 control_key_state_ = DOWN_WITH_CHANGE;
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 case 0x3000: // Ideographic Space 1267 case 0x3000: // Ideographic Space
1254 return true; 1268 return true;
1255 default: 1269 default:
1256 return false; 1270 return false;
1257 } 1271 }
1258 } 1272 }
1259 1273
1260 AutocompleteInput::PageClassification OmniboxEditModel::ClassifyPage() const { 1274 AutocompleteInput::PageClassification OmniboxEditModel::ClassifyPage() const {
1261 if (!delegate_->CurrentPageExists()) 1275 if (!delegate_->CurrentPageExists())
1262 return AutocompleteInput::OTHER; 1276 return AutocompleteInput::OTHER;
1263 if (delegate_->IsInstantNTP()) 1277 if (delegate_->IsInstantNTP()) {
1264 return AutocompleteInput::INSTANT_NEW_TAB_PAGE; 1278 // Note that we treat OMNIBOX as the source if focus_source_ is INVALID,
1279 // i.e., if input isn't actually in progress.
1280 return (focus_source_ == FAKEBOX) ?
1281 AutocompleteInput::INSTANT_NEW_TAB_PAGE_WITH_FAKEBOX_AS_STARTING_FOCUS :
1282 AutocompleteInput::INSTANT_NEW_TAB_PAGE_WITH_OMNIBOX_AS_STARTING_FOCUS;
1283 }
1265 const GURL& gurl = delegate_->GetURL(); 1284 const GURL& gurl = delegate_->GetURL();
1266 if (!gurl.is_valid()) 1285 if (!gurl.is_valid())
1267 return AutocompleteInput::INVALID_SPEC; 1286 return AutocompleteInput::INVALID_SPEC;
1268 const std::string& url = gurl.spec(); 1287 const std::string& url = gurl.spec();
1269 if (url == chrome::kChromeUINewTabURL) 1288 if (url == chrome::kChromeUINewTabURL)
1270 return AutocompleteInput::NEW_TAB_PAGE; 1289 return AutocompleteInput::NEW_TAB_PAGE;
1271 if (url == content::kAboutBlankURL) 1290 if (url == content::kAboutBlankURL)
1272 return AutocompleteInput::BLANK; 1291 return AutocompleteInput::BLANK;
1273 if (url == profile()->GetPrefs()->GetString(prefs::kHomePage)) 1292 if (url == profile()->GetPrefs()->GetString(prefs::kHomePage))
1274 return AutocompleteInput::HOMEPAGE; 1293 return AutocompleteInput::HOMEPAGE;
(...skipping 22 matching lines...) Expand all
1297 instant->OmniboxFocusChanged(state, reason, NULL); 1316 instant->OmniboxFocusChanged(state, reason, NULL);
1298 1317
1299 // Update state and notify view if the omnibox has focus and the caret 1318 // Update state and notify view if the omnibox has focus and the caret
1300 // visibility changed. 1319 // visibility changed.
1301 const bool was_caret_visible = is_caret_visible(); 1320 const bool was_caret_visible = is_caret_visible();
1302 focus_state_ = state; 1321 focus_state_ = state;
1303 if (focus_state_ != OMNIBOX_FOCUS_NONE && 1322 if (focus_state_ != OMNIBOX_FOCUS_NONE &&
1304 is_caret_visible() != was_caret_visible) 1323 is_caret_visible() != was_caret_visible)
1305 view_->ApplyCaretVisibility(); 1324 view_->ApplyCaretVisibility();
1306 } 1325 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_edit_model.h ('k') | chrome/common/metrics/proto/omnibox_event.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698