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

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: address pkasting review comments 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& instant_suggestion,
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 instant_suggestion(instant_suggestion),
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.instant_suggestion);
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.) The only
194 // exception is if there's suggest text and the new URL is for a search result
195 // for the full text.
Peter Kasting 2013/04/03 00:35:35 This added comment describes what, not why. You n
sail 2013/04/03 19:34:11 Done.
196 string16 suggest_text = view_->GetInstantSuggestion();
Peter Kasting 2013/04/03 00:35:35 Nit: Name this |instant_suggestion|
sail 2013/04/03 19:34:11 Done.
187 const bool visibly_changed_permanent_text = 197 const bool visibly_changed_permanent_text =
188 (permanent_text_ != new_permanent_text) && 198 (permanent_text_ != new_permanent_text) &&
189 (!user_input_in_progress_ || !has_focus()); 199 (!user_input_in_progress_ || !has_focus()) &&
200 (suggest_text.empty() || new_permanent_text != user_text_ + suggest_text);
190 201
191 permanent_text_ = new_permanent_text; 202 permanent_text_ = new_permanent_text;
192 return visibly_changed_permanent_text; 203 return visibly_changed_permanent_text;
193 } 204 }
194 205
195 GURL OmniboxEditModel::PermanentURL() { 206 GURL OmniboxEditModel::PermanentURL() {
196 return URLFixerUpper::FixupURL(UTF16ToUTF8(permanent_text_), std::string()); 207 return URLFixerUpper::FixupURL(UTF16ToUTF8(permanent_text_), std::string());
197 } 208 }
198 209
199 void OmniboxEditModel::SetUserText(const string16& text) { 210 void OmniboxEditModel::SetUserText(const string16& text) {
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 } 818 }
808 819
809 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { 820 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) {
810 InstantController* instant = controller_->GetInstant(); 821 InstantController* instant = controller_->GetInstant();
811 if (instant) { 822 if (instant) {
812 instant->OmniboxFocusChanged(OMNIBOX_FOCUS_NONE, 823 instant->OmniboxFocusChanged(OMNIBOX_FOCUS_NONE,
813 OMNIBOX_FOCUS_CHANGE_EXPLICIT, 824 OMNIBOX_FOCUS_CHANGE_EXPLICIT,
814 view_gaining_focus); 825 view_gaining_focus);
815 } 826 }
816 827
817 SetInstantSuggestion(InstantSuggestion());
818
819 // TODO(jered): Rip this out along with StartZeroSuggest. 828 // TODO(jered): Rip this out along with StartZeroSuggest.
820 autocomplete_controller_->StopZeroSuggest(); 829 autocomplete_controller_->StopZeroSuggest();
821 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_); 830 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_);
822 } 831 }
823 832
824 void OmniboxEditModel::OnKillFocus() { 833 void OmniboxEditModel::OnKillFocus() {
825 // TODO(samarth): determine if it is safe to move the call to 834 // TODO(samarth): determine if it is safe to move the call to
826 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us 835 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us
827 // just call SetFocusState() to handle the state change. 836 // just call SetFocusState() to handle the state change.
828 focus_state_ = OMNIBOX_FOCUS_NONE; 837 focus_state_ = OMNIBOX_FOCUS_NONE;
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 instant->OmniboxFocusChanged(state, reason, NULL); 1394 instant->OmniboxFocusChanged(state, reason, NULL);
1386 1395
1387 // Update state and notify view if the omnibox has focus and the caret 1396 // Update state and notify view if the omnibox has focus and the caret
1388 // visibility changed. 1397 // visibility changed.
1389 const bool was_caret_visible = is_caret_visible(); 1398 const bool was_caret_visible = is_caret_visible();
1390 focus_state_ = state; 1399 focus_state_ = state;
1391 if (focus_state_ != OMNIBOX_FOCUS_NONE && 1400 if (focus_state_ != OMNIBOX_FOCUS_NONE &&
1392 is_caret_visible() != was_caret_visible) 1401 is_caret_visible() != was_caret_visible)
1393 view_->ApplyCaretVisibility(); 1402 view_->ApplyCaretVisibility();
1394 } 1403 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698