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

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

Issue 18223002: InstantExtended: Remove overlay control code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_controller.h" 5 #include "chrome/browser/ui/omnibox/omnibox_controller.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 8 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
9 #include "chrome/browser/autocomplete/autocomplete_match.h" 9 #include "chrome/browser/autocomplete/autocomplete_match.h"
10 #include "chrome/browser/autocomplete/search_provider.h" 10 #include "chrome/browser/autocomplete/search_provider.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 string16 user_text, 60 string16 user_text,
61 size_t cursor_position, 61 size_t cursor_position,
62 const GURL& current_url, 62 const GURL& current_url,
63 bool prevent_inline_autocomplete, 63 bool prevent_inline_autocomplete,
64 bool prefer_keyword, 64 bool prefer_keyword,
65 bool allow_exact_keyword_match, 65 bool allow_exact_keyword_match,
66 int omnibox_start_margin) const { 66 int omnibox_start_margin) const {
67 ClearPopupKeywordMode(); 67 ClearPopupKeywordMode();
68 popup_->SetHoveredLine(OmniboxPopupModel::kNoMatch); 68 popup_->SetHoveredLine(OmniboxPopupModel::kNoMatch);
69 69
70 #if defined(HTML_INSTANT_EXTENDED_POPUP)
71 InstantController* instant_controller = GetInstantController();
72 if (instant_controller)
73 instant_controller->OnAutocompleteStart();
74 #endif
75 if (chrome::IsInstantExtendedAPIEnabled()) { 70 if (chrome::IsInstantExtendedAPIEnabled()) {
76 autocomplete_controller_->search_provider()-> 71 autocomplete_controller_->search_provider()->
77 SetOmniboxStartMargin(omnibox_start_margin); 72 SetOmniboxStartMargin(omnibox_start_margin);
78 } 73 }
79 74
80 // We don't explicitly clear OmniboxPopupModel::manually_selected_match, as 75 // We don't explicitly clear OmniboxPopupModel::manually_selected_match, as
81 // Start ends up invoking OmniboxPopupModel::OnResultChanged which clears it. 76 // Start ends up invoking OmniboxPopupModel::OnResultChanged which clears it.
82 autocomplete_controller_->Start(AutocompleteInput( 77 autocomplete_controller_->Start(AutocompleteInput(
83 user_text, cursor_position, string16(), current_url, 78 user_text, cursor_position, string16(), current_url,
84 prevent_inline_autocomplete, prefer_keyword, allow_exact_keyword_match, 79 prevent_inline_autocomplete, prefer_keyword, allow_exact_keyword_match,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } else { 112 } else {
118 InvalidateCurrentMatch(); 113 InvalidateCurrentMatch();
119 popup_->OnResultChanged(); 114 popup_->OnResultChanged();
120 omnibox_edit_model_->OnPopupDataChanged(string16(), NULL, string16(), 115 omnibox_edit_model_->OnPopupDataChanged(string16(), NULL, string16(),
121 false); 116 false);
122 } 117 }
123 } else { 118 } else {
124 popup_->OnResultChanged(); 119 popup_->OnResultChanged();
125 } 120 }
126 121
127 // TODO(beaudoin): This may no longer be needed now that instant classic is 122 if (!popup_->IsOpen() && was_open) {
128 // gone.
129 if (popup_->IsOpen()) {
130 // The popup size may have changed, let instant know.
131 OnPopupBoundsChanged(popup_->view()->GetTargetBounds());
132
133 #if defined(HTML_INSTANT_EXTENDED_POPUP)
134 InstantController* instant_controller = GetInstantController();
135 if (instant_controller && !omnibox_edit_model_->in_revert()) {
136 instant_controller->HandleAutocompleteResults(
137 *autocomplete_controller_->providers(),
138 autocomplete_controller_->result());
139 }
140 #endif
141 } else if (was_open) {
142 // Accept the temporary text as the user text, because it makes little sense 123 // Accept the temporary text as the user text, because it makes little sense
143 // to have temporary text when the popup is closed. 124 // to have temporary text when the popup is closed.
144 omnibox_edit_model_->AcceptTemporaryTextAsUserText(); 125 omnibox_edit_model_->AcceptTemporaryTextAsUserText();
145 // The popup has been closed, let instant know.
146 OnPopupBoundsChanged(gfx::Rect());
147 } 126 }
148 } 127 }
149 128
150 bool OmniboxController::DoInstant(const AutocompleteMatch& match, 129 bool OmniboxController::DoInstant(const AutocompleteMatch& match,
151 string16 user_text, 130 string16 user_text,
152 string16 full_text, 131 string16 full_text,
153 size_t selection_start, 132 size_t selection_start,
154 size_t selection_end, 133 size_t selection_end,
155 bool user_input_in_progress, 134 bool user_input_in_progress,
156 bool in_escape_handler, 135 bool in_escape_handler,
157 bool just_deleted_text, 136 bool just_deleted_text,
158 bool keyword_is_selected) { 137 bool keyword_is_selected) {
159 #if defined(HTML_INSTANT_EXTENDED_POPUP)
160 InstantController* instant_controller = GetInstantController();
161 if (!instant_controller)
162 return false;
163
164 // Remove "?" if we're in forced query mode.
165 AutocompleteInput::RemoveForcedQueryStringIfNecessary(
166 autocomplete_controller_->input().type(), &user_text);
167 AutocompleteInput::RemoveForcedQueryStringIfNecessary(
168 autocomplete_controller_->input().type(), &full_text);
169 return instant_controller->Update(
170 match, user_text, full_text, selection_start, selection_end,
171 UseVerbatimInstant(just_deleted_text), user_input_in_progress,
172 popup_->IsOpen(), in_escape_handler, keyword_is_selected);
173 #else
174 return false; 138 return false;
Peter Kasting 2013/06/28 18:47:55 Should there be a TODO to nuke this function too?
Jered 2013/06/28 19:09:55 Just did it.
175 #endif
176 } 139 }
177 140
178 void OmniboxController::SetInstantSuggestion( 141 void OmniboxController::SetInstantSuggestion(
179 const InstantSuggestion& suggestion) { 142 const InstantSuggestion& suggestion) {
180 // Should only get called for the HTML popup. 143 // TODO(jered): Delete this.
181 #if defined(HTML_INSTANT_EXTENDED_POPUP)
182 switch (suggestion.behavior) {
183 case INSTANT_COMPLETE_NOW:
184 // Set blue suggestion text.
185 // TODO(beaudoin): Create a valid current_match_ and call
186 // omnibox_edit_model_->OnCurrentMatchChanged.
187 return;
188
189 case INSTANT_COMPLETE_NEVER: {
190 DCHECK_EQ(INSTANT_SUGGESTION_SEARCH, suggestion.type);
191
192 // Set gray suggestion text.
193 // Remove "?" if we're in forced query mode.
194 gray_suggestion_ = suggestion.text;
195
196 omnibox_edit_model_->OnGrayTextChanged();
197 return;
198 }
199
200 case INSTANT_COMPLETE_REPLACE:
201 // Replace the entire omnibox text by the suggestion the user just arrowed
202 // to.
203 CreateAndSetInstantMatch(suggestion.text, suggestion.text,
204 suggestion.type == INSTANT_SUGGESTION_SEARCH ?
205 AutocompleteMatchType::SEARCH_SUGGEST :
206 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
207
208 omnibox_edit_model_->OnCurrentMatchChanged(true);
209 return;
210 }
211 #endif
212 } 144 }
213 145
214 void OmniboxController::InvalidateCurrentMatch() { 146 void OmniboxController::InvalidateCurrentMatch() {
215 current_match_ = AutocompleteMatch(); 147 current_match_ = AutocompleteMatch();
216 } 148 }
217 149
218 void OmniboxController::ClearPopupKeywordMode() const { 150 void OmniboxController::ClearPopupKeywordMode() const {
219 if (popup_->IsOpen() && 151 if (popup_->IsOpen() &&
220 popup_->selected_line_state() == OmniboxPopupModel::KEYWORD) 152 popup_->selected_line_state() == OmniboxPopupModel::KEYWORD)
221 popup_->SetSelectedLineState(OmniboxPopupModel::NORMAL); 153 popup_->SetSelectedLineState(OmniboxPopupModel::NORMAL);
222 } 154 }
223 155
224 void OmniboxController::DoPreconnect(const AutocompleteMatch& match) { 156 void OmniboxController::DoPreconnect(const AutocompleteMatch& match) {
225 if (!match.destination_url.SchemeIs(extensions::kExtensionScheme)) { 157 if (!match.destination_url.SchemeIs(extensions::kExtensionScheme)) {
226 // Warm up DNS Prefetch cache, or preconnect to a search service. 158 // Warm up DNS Prefetch cache, or preconnect to a search service.
227 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type, 159 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type,
228 AutocompleteMatchType::NUM_TYPES); 160 AutocompleteMatchType::NUM_TYPES);
229 if (profile_->GetNetworkPredictor()) { 161 if (profile_->GetNetworkPredictor()) {
230 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( 162 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl(
231 match.destination_url, 163 match.destination_url,
232 AutocompleteActionPredictor::IsPreconnectable(match)); 164 AutocompleteActionPredictor::IsPreconnectable(match));
233 } 165 }
234 // We could prefetch the alternate nav URL, if any, but because there 166 // We could prefetch the alternate nav URL, if any, but because there
235 // can be many of these as a user types an initial series of characters, 167 // can be many of these as a user types an initial series of characters,
236 // the OS DNS cache could suffer eviction problems for minimal gain. 168 // the OS DNS cache could suffer eviction problems for minimal gain.
237 } 169 }
238 } 170 }
239 171
240 void OmniboxController::OnPopupBoundsChanged(const gfx::Rect& bounds) {
241 InstantController* instant_controller = GetInstantController();
242 if (instant_controller)
243 instant_controller->SetPopupBounds(bounds);
244 }
245
246 bool OmniboxController::UseVerbatimInstant(bool just_deleted_text) const { 172 bool OmniboxController::UseVerbatimInstant(bool just_deleted_text) const {
247 #if defined(OS_MACOSX) 173 #if defined(OS_MACOSX)
248 // TODO(suzhe): Fix Mac port to display Instant suggest in a separated NSView, 174 // TODO(suzhe): Fix Mac port to display Instant suggest in a separated NSView,
249 // so that we can display Instant suggest along with composition text. 175 // so that we can display Instant suggest along with composition text.
250 const AutocompleteInput& input = autocomplete_controller_->input(); 176 const AutocompleteInput& input = autocomplete_controller_->input();
251 if (input.prevent_inline_autocomplete()) 177 if (input.prevent_inline_autocomplete())
252 return true; 178 return true;
253 #endif 179 #endif
254 180
255 // The value of input.prevent_inline_autocomplete() is determined by the 181 // The value of input.prevent_inline_autocomplete() is determined by the
(...skipping 16 matching lines...) Expand all
272 string16 input_text, 198 string16 input_text,
273 AutocompleteMatchType::Type match_type) { 199 AutocompleteMatchType::Type match_type) {
274 string16 keyword = GetDefaultSearchProviderKeyword(profile_); 200 string16 keyword = GetDefaultSearchProviderKeyword(profile_);
275 if (keyword.empty()) 201 if (keyword.empty())
276 return; // CreateSearchSuggestion needs a keyword. 202 return; // CreateSearchSuggestion needs a keyword.
277 203
278 current_match_ = SearchProvider::CreateSearchSuggestion( 204 current_match_ = SearchProvider::CreateSearchSuggestion(
279 profile_, NULL, AutocompleteInput(), query_string, input_text, 0, 205 profile_, NULL, AutocompleteInput(), query_string, input_text, 0,
280 match_type, 0, false, keyword, -1); 206 match_type, 0, false, keyword, -1);
281 } 207 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698