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

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

Issue 12792013: Instant extended: Remove suggest commit on lost focus (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update another test Created 7 years, 8 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 OMNIBOX_USER_TEXT_CLEARED_NUM_OF_ITEMS, 86 OMNIBOX_USER_TEXT_CLEARED_NUM_OF_ITEMS,
87 }; 87 };
88 88
89 } // namespace 89 } // namespace
90 90
91 /////////////////////////////////////////////////////////////////////////////// 91 ///////////////////////////////////////////////////////////////////////////////
92 // OmniboxEditModel::State 92 // OmniboxEditModel::State
93 93
94 OmniboxEditModel::State::State(bool user_input_in_progress, 94 OmniboxEditModel::State::State(bool user_input_in_progress,
95 const string16& user_text, 95 const string16& user_text,
96 const string16& suggest_text,
96 const string16& keyword, 97 const string16& keyword,
97 bool is_keyword_hint, 98 bool is_keyword_hint,
98 OmniboxFocusState focus_state) 99 OmniboxFocusState focus_state)
99 : user_input_in_progress(user_input_in_progress), 100 : user_input_in_progress(user_input_in_progress),
100 user_text(user_text), 101 user_text(user_text),
102 suggest_text(suggest_text),
101 keyword(keyword), 103 keyword(keyword),
102 is_keyword_hint(is_keyword_hint), 104 is_keyword_hint(is_keyword_hint),
103 focus_state(focus_state) { 105 focus_state(focus_state) {
104 } 106 }
105 107
106 OmniboxEditModel::State::~State() { 108 OmniboxEditModel::State::~State() {
107 } 109 }
108 110
109 /////////////////////////////////////////////////////////////////////////////// 111 ///////////////////////////////////////////////////////////////////////////////
110 // OmniboxEditModel 112 // OmniboxEditModel
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // on switching back, typing will "just work"). 151 // on switching back, typing will "just work").
150 const string16 user_text(UserTextFromDisplayText(view_->GetText())); 152 const string16 user_text(UserTextFromDisplayText(view_->GetText()));
151 if (user_text.empty()) { 153 if (user_text.empty()) {
152 view_->RevertAll(); 154 view_->RevertAll();
153 view_->SelectAll(true); 155 view_->SelectAll(true);
154 } else { 156 } else {
155 InternalSetUserText(user_text); 157 InternalSetUserText(user_text);
156 } 158 }
157 } 159 }
158 160
159 return State(user_input_in_progress_, user_text_, keyword_, is_keyword_hint_, 161 return State(user_input_in_progress_,
162 user_text_,
163 view_->GetInstantSuggestion(),
164 keyword_,
165 is_keyword_hint_,
160 focus_state_); 166 focus_state_);
161 } 167 }
162 168
163 void OmniboxEditModel::RestoreState(const State& state) { 169 void OmniboxEditModel::RestoreState(const State& state) {
164 SetFocusState(state.focus_state, OMNIBOX_FOCUS_CHANGE_TAB_SWITCH); 170 SetFocusState(state.focus_state, OMNIBOX_FOCUS_CHANGE_TAB_SWITCH);
165 // Restore any user editing. 171 // Restore any user editing.
166 if (state.user_input_in_progress) { 172 if (state.user_input_in_progress) {
167 // NOTE: Be sure and set keyword-related state BEFORE invoking 173 // NOTE: Be sure and set keyword-related state BEFORE invoking
168 // DisplayTextFromUserText(), as its result depends upon this state. 174 // DisplayTextFromUserText(), as its result depends upon this state.
169 keyword_ = state.keyword; 175 keyword_ = state.keyword;
170 is_keyword_hint_ = state.is_keyword_hint; 176 is_keyword_hint_ = state.is_keyword_hint;
171 view_->SetUserText(state.user_text, 177 view_->SetUserText(state.user_text,
172 DisplayTextFromUserText(state.user_text), false); 178 DisplayTextFromUserText(state.user_text), false);
179 view_->SetInstantSuggestion(state.suggest_text);
173 } 180 }
174 } 181 }
175 182
176 AutocompleteMatch OmniboxEditModel::CurrentMatch() { 183 AutocompleteMatch OmniboxEditModel::CurrentMatch() {
177 AutocompleteMatch match; 184 AutocompleteMatch match;
178 GetInfoForCurrentText(&match, NULL); 185 GetInfoForCurrentText(&match, NULL);
179 return match; 186 return match;
180 } 187 }
181 188
182 bool OmniboxEditModel::UpdatePermanentText(const string16& new_permanent_text) { 189 bool OmniboxEditModel::UpdatePermanentText(const string16& new_permanent_text) {
183 // When there's a new URL, and the user is not editing anything or the edit 190 // When there's a new URL, and the user is not editing anything or the edit
184 // doesn't have focus, we want to revert the edit to show the new URL. (The 191 // doesn't have focus, we want to revert the edit to show the new URL. (The
185 // common case where the edit doesn't have focus is when the user has started 192 // common case where the edit doesn't have focus is when the user has started
186 // an edit and then abandoned it and clicked a link on the page.) 193 // an edit and then abandoned it and clicked a link on the page.)
194 string16 suggest_text = view_->GetInstantSuggestion();
187 const bool visibly_changed_permanent_text = 195 const bool visibly_changed_permanent_text =
188 (permanent_text_ != new_permanent_text) && 196 (permanent_text_ != new_permanent_text) &&
189 (!user_input_in_progress_ || !has_focus()); 197 (!user_input_in_progress_ || !has_focus()) &&
198 (suggest_text.empty() || new_permanent_text != user_text_ + suggest_text);
Peter Kasting 2013/03/30 18:48:21 Why do we have to add this final clause? At the l
sail 2013/04/02 22:32:06 This prevents the omnibox text from changing when
190 199
191 permanent_text_ = new_permanent_text; 200 permanent_text_ = new_permanent_text;
192 return visibly_changed_permanent_text; 201 return visibly_changed_permanent_text;
193 } 202 }
194 203
195 GURL OmniboxEditModel::PermanentURL() { 204 GURL OmniboxEditModel::PermanentURL() {
196 return URLFixerUpper::FixupURL(UTF16ToUTF8(permanent_text_), std::string()); 205 return URLFixerUpper::FixupURL(UTF16ToUTF8(permanent_text_), std::string());
197 } 206 }
198 207
199 void OmniboxEditModel::SetUserText(const string16& text) { 208 void OmniboxEditModel::SetUserText(const string16& text) {
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 } 814 }
806 815
807 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { 816 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) {
808 InstantController* instant = controller_->GetInstant(); 817 InstantController* instant = controller_->GetInstant();
809 if (instant) { 818 if (instant) {
810 instant->OmniboxFocusChanged(OMNIBOX_FOCUS_NONE, 819 instant->OmniboxFocusChanged(OMNIBOX_FOCUS_NONE,
811 OMNIBOX_FOCUS_CHANGE_EXPLICIT, 820 OMNIBOX_FOCUS_CHANGE_EXPLICIT,
812 view_gaining_focus); 821 view_gaining_focus);
813 } 822 }
814 823
815 SetInstantSuggestion(InstantSuggestion());
816
817 // TODO(jered): Rip this out along with StartZeroSuggest. 824 // TODO(jered): Rip this out along with StartZeroSuggest.
818 autocomplete_controller_->StopZeroSuggest(); 825 autocomplete_controller_->StopZeroSuggest();
819 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_); 826 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_);
820 } 827 }
821 828
822 void OmniboxEditModel::OnKillFocus() { 829 void OmniboxEditModel::OnKillFocus() {
823 // TODO(samarth): determine if it is safe to move the call to 830 // TODO(samarth): determine if it is safe to move the call to
824 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us 831 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us
825 // just call SetFocusState() to handle the state change. 832 // just call SetFocusState() to handle the state change.
826 focus_state_ = OMNIBOX_FOCUS_NONE; 833 focus_state_ = OMNIBOX_FOCUS_NONE;
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 instant->OmniboxFocusChanged(state, reason, NULL); 1390 instant->OmniboxFocusChanged(state, reason, NULL);
1384 1391
1385 // Update state and notify view if the omnibox has focus and the caret 1392 // Update state and notify view if the omnibox has focus and the caret
1386 // visibility changed. 1393 // visibility changed.
1387 const bool was_caret_visible = is_caret_visible(); 1394 const bool was_caret_visible = is_caret_visible();
1388 focus_state_ = state; 1395 focus_state_ = state;
1389 if (focus_state_ != OMNIBOX_FOCUS_NONE && 1396 if (focus_state_ != OMNIBOX_FOCUS_NONE &&
1390 is_caret_visible() != was_caret_visible) 1397 is_caret_visible() != was_caret_visible)
1391 view_->ApplyCaretVisibility(); 1398 view_->ApplyCaretVisibility();
1392 } 1399 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698