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

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

Issue 12386019: Instant: Use only one hidden WebContents per profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 const char kOmniboxUserTextClearedHistogram[] = "Omnibox.UserTextCleared"; 81 const char kOmniboxUserTextClearedHistogram[] = "Omnibox.UserTextCleared";
82 82
83 enum UserTextClearedType { 83 enum UserTextClearedType {
84 OMNIBOX_USER_TEXT_CLEARED_BY_EDITING = 0, 84 OMNIBOX_USER_TEXT_CLEARED_BY_EDITING = 0,
85 OMNIBOX_USER_TEXT_CLEARED_WITH_ESCAPE = 1, 85 OMNIBOX_USER_TEXT_CLEARED_WITH_ESCAPE = 1,
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
92 /////////////////////////////////////////////////////////////////////////////// 91 ///////////////////////////////////////////////////////////////////////////////
93 // OmniboxEditModel::State 92 // OmniboxEditModel::State
94 93
95 OmniboxEditModel::State::State(bool user_input_in_progress, 94 OmniboxEditModel::State::State(bool user_input_in_progress,
96 const string16& user_text, 95 const string16& user_text,
97 const string16& keyword, 96 const string16& keyword,
98 bool is_keyword_hint, 97 bool is_keyword_hint,
99 OmniboxFocusState focus_state) 98 OmniboxFocusState focus_state)
100 : user_input_in_progress(user_input_in_progress), 99 : user_input_in_progress(user_input_in_progress),
101 user_text(user_text), 100 user_text(user_text),
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 void OmniboxEditModel::SetInstantSuggestion( 224 void OmniboxEditModel::SetInstantSuggestion(
226 const InstantSuggestion& suggestion) { 225 const InstantSuggestion& suggestion) {
227 switch (suggestion.behavior) { 226 switch (suggestion.behavior) {
228 case INSTANT_COMPLETE_NOW: 227 case INSTANT_COMPLETE_NOW:
229 view_->SetInstantSuggestion(string16()); 228 view_->SetInstantSuggestion(string16());
230 if (!suggestion.text.empty()) 229 if (!suggestion.text.empty())
231 FinalizeInstantQuery(view_->GetText(), suggestion, false); 230 FinalizeInstantQuery(view_->GetText(), suggestion, false);
232 break; 231 break;
233 232
234 case INSTANT_COMPLETE_NEVER: 233 case INSTANT_COMPLETE_NEVER:
235 DCHECK_EQ(INSTANT_SUGGESTION_SEARCH, suggestion.type); 234 DCHECK(!suggestion.is_url);
236 view_->SetInstantSuggestion(suggestion.text); 235 view_->SetInstantSuggestion(suggestion.text);
237 break; 236 break;
238 237
239 case INSTANT_COMPLETE_REPLACE: { 238 case INSTANT_COMPLETE_REPLACE: {
240 const bool save_original_selection = !has_temporary_text_; 239 const bool save_original_selection = !has_temporary_text_;
241 view_->SetInstantSuggestion(string16()); 240 view_->SetInstantSuggestion(string16());
242 has_temporary_text_ = true; 241 has_temporary_text_ = true;
243 is_temporary_text_set_by_instant_ = true; 242 is_temporary_text_set_by_instant_ = true;
244 // Instant suggestions are never a keyword. 243 // Instant suggestions are never a keyword.
245 keyword_ = string16(); 244 keyword_ = string16();
(...skipping 10 matching lines...) Expand all
256 return false; 255 return false;
257 256
258 const string16 suggestion = view_->GetInstantSuggestion(); 257 const string16 suggestion = view_->GetInstantSuggestion();
259 if (suggestion.empty()) 258 if (suggestion.empty())
260 return false; 259 return false;
261 260
262 // Assume that the gray text we are committing is a search suggestion. 261 // Assume that the gray text we are committing is a search suggestion.
263 FinalizeInstantQuery(view_->GetText(), 262 FinalizeInstantQuery(view_->GetText(),
264 InstantSuggestion(suggestion, 263 InstantSuggestion(suggestion,
265 INSTANT_COMPLETE_NOW, 264 INSTANT_COMPLETE_NOW,
266 INSTANT_SUGGESTION_SEARCH), 265 false),
267 skip_inline_autocomplete); 266 skip_inline_autocomplete);
268 return true; 267 return true;
269 } 268 }
270 269
271 bool OmniboxEditModel::AcceptCurrentInstantPreview() { 270 bool OmniboxEditModel::AcceptCurrentInstantPreview() {
272 return controller_->GetInstant() && 271 return controller_->GetInstant() &&
273 controller_->GetInstant()->CommitIfPossible(INSTANT_COMMIT_PRESSED_ENTER); 272 controller_->GetInstant()->CommitIfPossible(INSTANT_COMMIT_PRESSED_ENTER);
274 } 273 }
275 274
276 void OmniboxEditModel::OnChanged() { 275 void OmniboxEditModel::OnChanged() {
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 controller_->GetWebContents())-> 1291 controller_->GetWebContents())->
1293 OmniboxEditModelChanged(user_input_in_progress_, !in_revert_); 1292 OmniboxEditModelChanged(user_input_in_progress_, !in_revert_);
1294 } 1293 }
1295 } 1294 }
1296 1295
1297 bool OmniboxEditModel::DoInstant(const AutocompleteMatch& match) { 1296 bool OmniboxEditModel::DoInstant(const AutocompleteMatch& match) {
1298 InstantController* instant = controller_->GetInstant(); 1297 InstantController* instant = controller_->GetInstant();
1299 if (!instant || in_revert_) 1298 if (!instant || in_revert_)
1300 return false; 1299 return false;
1301 1300
1302 // Don't call Update() if the change is a result of a 1301 // Don't call Update() if the change is a result of an
1303 // INSTANT_COMPLETE_REPLACE instant suggestion. 1302 // INSTANT_COMPLETE_REPLACE Instant suggestion.
1304 if (has_temporary_text_ && is_temporary_text_set_by_instant_) 1303 if (has_temporary_text_ && is_temporary_text_set_by_instant_)
1305 return false; 1304 return false;
1306 1305
1307 // The two pieces of text we want to send Instant, viz., what the user has 1306 // The two pieces of text we want to send Instant, viz., what the user has
1308 // typed, and the full omnibox text including any inline autocompletion. 1307 // typed, and the full omnibox text including any inline autocompletion.
1309 string16 user_text = has_temporary_text_ ? 1308 string16 user_text = has_temporary_text_ ?
1310 match.fill_into_edit : DisplayTextFromUserText(user_text_); 1309 match.fill_into_edit : DisplayTextFromUserText(user_text_);
1311 string16 full_text = view_->GetText(); 1310 string16 full_text = view_->GetText();
1312 1311
1313 // Remove "?" if we're in forced query mode. 1312 // Remove "?" if we're in forced query mode.
1314 AutocompleteInput::RemoveForcedQueryStringIfNecessary( 1313 AutocompleteInput::RemoveForcedQueryStringIfNecessary(
1315 autocomplete_controller_->input().type(), &user_text); 1314 autocomplete_controller_->input().type(), &user_text);
1316 AutocompleteInput::RemoveForcedQueryStringIfNecessary( 1315 AutocompleteInput::RemoveForcedQueryStringIfNecessary(
1317 autocomplete_controller_->input().type(), &full_text); 1316 autocomplete_controller_->input().type(), &full_text);
1318 1317
1319 size_t start, end; 1318 size_t start, end;
1320 view_->GetSelectionBounds(&start, &end); 1319 view_->GetSelectionBounds(&start, &end);
1321 1320
1322 return instant->Update(match, user_text, full_text, start, end, 1321 return instant->Update(match, user_text, full_text, start, end,
1323 UseVerbatimInstant(), user_input_in_progress_, popup_->IsOpen(), 1322 UseVerbatimInstant(), user_input_in_progress_, popup_->IsOpen(),
1324 in_escape_handler_, KeywordIsSelected()); 1323 in_escape_handler_);
1325 } 1324 }
1326 1325
1327 void OmniboxEditModel::DoPrerender(const AutocompleteMatch& match) { 1326 void OmniboxEditModel::DoPrerender(const AutocompleteMatch& match) {
1328 // Do not prerender if the destination URL is the same as the current URL. 1327 // Do not prerender if the destination URL is the same as the current URL.
1329 if (match.destination_url == PermanentURL()) 1328 if (match.destination_url == PermanentURL())
1330 return; 1329 return;
1331 // It's possible the tab strip does not have an active tab contents, for 1330 // It's possible the tab strip does not have an active tab contents, for
1332 // instance if the tab has been closed or on return from a sleep state 1331 // instance if the tab has been closed or on return from a sleep state
1333 // (http://crbug.com/105689) 1332 // (http://crbug.com/105689)
1334 content::WebContents* tab = controller_->GetWebContents(); 1333 content::WebContents* tab = controller_->GetWebContents();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 instant->OmniboxFocusChanged(state, reason, NULL); 1401 instant->OmniboxFocusChanged(state, reason, NULL);
1403 1402
1404 // Update state and notify view if the omnibox has focus and the caret 1403 // Update state and notify view if the omnibox has focus and the caret
1405 // visibility changed. 1404 // visibility changed.
1406 const bool was_caret_visible = is_caret_visible(); 1405 const bool was_caret_visible = is_caret_visible();
1407 focus_state_ = state; 1406 focus_state_ = state;
1408 if (focus_state_ != OMNIBOX_FOCUS_NONE && 1407 if (focus_state_ != OMNIBOX_FOCUS_NONE &&
1409 is_caret_visible() != was_caret_visible) 1408 is_caret_visible() != was_caret_visible)
1410 view_->ApplyCaretVisibility(); 1409 view_->ApplyCaretVisibility();
1411 } 1410 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698