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

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

Issue 11369137: Implement {Start,Stop}CapturingKeyStrokes for Instant. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Switch order in BIC. Created 8 years 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
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/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
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_focus_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_focus_visible(is_focus_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_focus_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
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_focus_visible_);
132 } 136 }
133 137
134 void OmniboxEditModel::RestoreState(const State& state) { 138 void OmniboxEditModel::RestoreState(const State& state) {
139 SetFocusVisibility(state.is_focus_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 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 // that we avoid PermanentURL() here because it's not guaranteed to give us 730 // that we avoid PermanentURL() here because it's not guaranteed to give us
726 // the actual underlying current URL, e.g. if we're on the NTP and the 731 // the actual underlying current URL, e.g. if we're on the NTP and the
727 // |permanent_text_| is empty. 732 // |permanent_text_| is empty.
728 autocomplete_controller_->StartZeroSuggest(web_contents->GetURL(), 733 autocomplete_controller_->StartZeroSuggest(web_contents->GetURL(),
729 user_text_); 734 user_text_);
730 } 735 }
731 736
732 NotifySearchTabHelper(); 737 NotifySearchTabHelper();
733 } 738 }
734 739
740 void OmniboxEditModel::SetFocusVisibility(bool visible) {
741 if (visible != is_focus_visible_) {
742 is_focus_visible_ = visible;
743 view_->ApplyFocusVisibility();
744 }
745 }
746
735 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { 747 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) {
736 SetInstantSuggestion(InstantSuggestion()); 748 SetInstantSuggestion(InstantSuggestion());
737 749
738 if (InstantController* instant = controller_->GetInstant()) 750 if (InstantController* instant = controller_->GetInstant())
739 instant->OmniboxLostFocus(view_gaining_focus); 751 instant->OmniboxLostFocus(view_gaining_focus);
740 752
741 // TODO(jered): Rip this out along with StartZeroSuggest. 753 // TODO(jered): Rip this out along with StartZeroSuggest.
742 autocomplete_controller_->StopZeroSuggest(); 754 autocomplete_controller_->StopZeroSuggest();
743 NotifySearchTabHelper(); 755 NotifySearchTabHelper();
744 } 756 }
745 757
746 void OmniboxEditModel::OnKillFocus() { 758 void OmniboxEditModel::OnKillFocus() {
747 has_focus_ = false; 759 has_focus_ = false;
760 is_focus_visible_ = true;
Peter Kasting 2012/12/04 02:00:52 I'm a little confused about the distinction betwee
samarth 2012/12/04 04:55:35 So the call in SetFocus can't be moved to OnSetFoc
748 control_key_state_ = UP; 761 control_key_state_ = UP;
749 paste_state_ = NONE; 762 paste_state_ = NONE;
750 } 763 }
751 764
752 bool OmniboxEditModel::OnEscapeKeyPressed() { 765 bool OmniboxEditModel::OnEscapeKeyPressed() {
753 if (has_temporary_text_) { 766 if (has_temporary_text_) {
754 AutocompleteMatch match; 767 AutocompleteMatch match;
755 InfoForCurrentSelection(&match, NULL); 768 InfoForCurrentSelection(&match, NULL);
756 if (match.destination_url != original_url_) { 769 if (match.destination_url != original_url_) {
757 RevertTemporaryText(true); 770 RevertTemporaryText(true);
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 } 1284 }
1272 1285
1273 void OmniboxEditModel::ClassifyStringForPasteAndGo( 1286 void OmniboxEditModel::ClassifyStringForPasteAndGo(
1274 const string16& text, 1287 const string16& text,
1275 AutocompleteMatch* match, 1288 AutocompleteMatch* match,
1276 GURL* alternate_nav_url) const { 1289 GURL* alternate_nav_url) const {
1277 DCHECK(match); 1290 DCHECK(match);
1278 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, 1291 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text,
1279 string16(), false, false, match, alternate_nav_url); 1292 string16(), false, false, match, alternate_nav_url);
1280 } 1293 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698