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

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

Issue 10832256: Experimental AutocompleteProvider for zerosuggest. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address comments. Created 8 years, 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 autocomplete_controller_->Start( 433 autocomplete_controller_->Start(
434 user_text_, GetDesiredTLD(), 434 user_text_, GetDesiredTLD(),
435 prevent_inline_autocomplete || just_deleted_text_ || 435 prevent_inline_autocomplete || just_deleted_text_ ||
436 (has_selected_text && inline_autocomplete_text_.empty()) || 436 (has_selected_text && inline_autocomplete_text_.empty()) ||
437 (paste_state_ != NONE), keyword_is_selected, 437 (paste_state_ != NONE), keyword_is_selected,
438 keyword_is_selected || allow_exact_keyword_match_, 438 keyword_is_selected || allow_exact_keyword_match_,
439 AutocompleteInput::ALL_MATCHES); 439 AutocompleteInput::ALL_MATCHES);
440 } 440 }
441 441
442 void OmniboxEditModel::StopAutocomplete() { 442 void OmniboxEditModel::StopAutocomplete() {
443 if (popup_->IsOpen() && !in_revert_) { 443 if (popup_->IsOpen()) {
Peter Kasting 2012/08/15 21:52:44 Nit: Revert remaining change to this function
Jered 2012/08/15 23:13:00 Done.
444 InstantController* instant = controller_->GetInstant(); 444 if (!in_revert_) {
445 if (instant && !instant->commit_on_pointer_release()) 445 InstantController* instant = controller_->GetInstant();
446 instant->Hide(); 446 if (instant && !instant->commit_on_pointer_release())
447 instant->Hide();
448 }
447 } 449 }
448 450
449 autocomplete_controller_->Stop(true); 451 autocomplete_controller_->Stop(true);
450 } 452 }
451 453
452 bool OmniboxEditModel::CanPasteAndGo(const string16& text) const { 454 bool OmniboxEditModel::CanPasteAndGo(const string16& text) const {
453 if (!view_->command_updater()->IsCommandEnabled(IDC_OPEN_CURRENT_URL)) 455 if (!view_->command_updater()->IsCommandEnabled(IDC_OPEN_CURRENT_URL))
454 return false; 456 return false;
455 457
456 AutocompleteMatch match; 458 AutocompleteMatch match;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 autocomplete_controller_->input().text(), 526 autocomplete_controller_->input().text(),
525 just_deleted_text_, 527 just_deleted_text_,
526 autocomplete_controller_->input().type(), 528 autocomplete_controller_->input().type(),
527 popup_->selected_line(), 529 popup_->selected_line(),
528 -1, // don't yet know tab ID; set later if appropriate 530 -1, // don't yet know tab ID; set later if appropriate
529 ClassifyPage(controller_->GetTabContents()-> 531 ClassifyPage(controller_->GetTabContents()->
530 web_contents()->GetURL()), 532 web_contents()->GetURL()),
531 base::TimeTicks::Now() - time_user_first_modified_omnibox_, 533 base::TimeTicks::Now() - time_user_first_modified_omnibox_,
532 0, // inline autocomplete length; possibly set later 534 0, // inline autocomplete length; possibly set later
533 result()); 535 result());
534 DCHECK(user_input_in_progress_) << "We didn't get here through the " 536 DCHECK(user_input_in_progress_ ||
535 "expected series of calls. time_user_first_modified_omnibox_ is " 537 (match.provider && match.provider->name() == "ZeroSuggest"))
Peter Kasting 2012/08/15 21:52:44 Nit: You don't need "match.provider &&", all match
Jered 2012/08/15 23:13:00 Done.
536 "not set correctly and other things may be wrong."; 538 << "We didn't get here through the expected series of calls. "
539 << "time_user_first_modified_omnibox_ is not set correctly and other "
540 << "things may be wrong.";
537 if (index != OmniboxPopupModel::kNoMatch) 541 if (index != OmniboxPopupModel::kNoMatch)
538 log.selected_index = index; 542 log.selected_index = index;
539 else if (!has_temporary_text_) 543 else if (!has_temporary_text_)
540 log.inline_autocompleted_length = inline_autocomplete_text_.length(); 544 log.inline_autocompleted_length = inline_autocomplete_text_.length();
541 if (disposition == CURRENT_TAB) { 545 if (disposition == CURRENT_TAB) {
542 // If we know the destination is being opened in the current tab, 546 // If we know the destination is being opened in the current tab,
543 // we can easily get the tab ID. (If it's being opened in a new 547 // we can easily get the tab ID. (If it's being opened in a new
544 // tab, we don't know the tab ID yet.) 548 // tab, we don't know the tab ID yet.)
545 log.tab_id = controller_->GetTabContents()-> 549 log.tab_id = controller_->GetTabContents()->
546 restore_tab_helper()->session_id().id(); 550 restore_tab_helper()->session_id().id();
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 } 692 }
689 693
690 void OmniboxEditModel::OnSetFocus(bool control_down) { 694 void OmniboxEditModel::OnSetFocus(bool control_down) {
691 has_focus_ = true; 695 has_focus_ = true;
692 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; 696 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP;
693 697
694 InstantController* instant = controller_->GetInstant(); 698 InstantController* instant = controller_->GetInstant();
695 if (instant) 699 if (instant)
696 instant->OnAutocompleteGotFocus(); 700 instant->OnAutocompleteGotFocus();
697 701
702 // TODO(jered): We may want to merge this into Start() and just call that
703 // here rather than having a special entry point for zero-suggest.
Peter Kasting 2012/08/15 21:52:44 Nit: Might want: // Note that we avoid PermanentU
Jered 2012/08/15 23:13:00 Done.
704 autocomplete_controller_->StartZeroSuggest(
705 controller_->GetTabContents()->web_contents()->GetURL(),
706 user_text_);
707
698 NotifySearchTabHelper(); 708 NotifySearchTabHelper();
699 } 709 }
700 710
701 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { 711 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) {
702 SetSuggestedText(string16(), INSTANT_COMPLETE_NOW); 712 SetSuggestedText(string16(), INSTANT_COMPLETE_NOW);
703 713
704 if (InstantController* instant = controller_->GetInstant()) 714 if (InstantController* instant = controller_->GetInstant())
705 instant->OnAutocompleteLostFocus(view_gaining_focus); 715 instant->OnAutocompleteLostFocus(view_gaining_focus);
706 716
717 // TODO(jered): Rip this out along with StartZeroSuggest.
718 autocomplete_controller_->StopZeroSuggest();
707 NotifySearchTabHelper(); 719 NotifySearchTabHelper();
708 } 720 }
709 721
710 void OmniboxEditModel::OnKillFocus() { 722 void OmniboxEditModel::OnKillFocus() {
711 has_focus_ = false; 723 has_focus_ = false;
712 control_key_state_ = UP; 724 control_key_state_ = UP;
713 paste_state_ = NONE; 725 paste_state_ = NONE;
714 } 726 }
715 727
716 bool OmniboxEditModel::OnEscapeKeyPressed() { 728 bool OmniboxEditModel::OnEscapeKeyPressed() {
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 } 1217 }
1206 1218
1207 void OmniboxEditModel::ClassifyStringForPasteAndGo( 1219 void OmniboxEditModel::ClassifyStringForPasteAndGo(
1208 const string16& text, 1220 const string16& text,
1209 AutocompleteMatch* match, 1221 AutocompleteMatch* match,
1210 GURL* alternate_nav_url) const { 1222 GURL* alternate_nav_url) const {
1211 DCHECK(match); 1223 DCHECK(match);
1212 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, 1224 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text,
1213 string16(), false, false, match, alternate_nav_url); 1225 string16(), false, false, match, alternate_nav_url);
1214 } 1226 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698