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

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: 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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 autocomplete_controller_->Start( 432 autocomplete_controller_->Start(
433 user_text_, GetDesiredTLD(), 433 user_text_, GetDesiredTLD(),
434 prevent_inline_autocomplete || just_deleted_text_ || 434 prevent_inline_autocomplete || just_deleted_text_ ||
435 (has_selected_text && inline_autocomplete_text_.empty()) || 435 (has_selected_text && inline_autocomplete_text_.empty()) ||
436 (paste_state_ != NONE), keyword_is_selected, 436 (paste_state_ != NONE), keyword_is_selected,
437 keyword_is_selected || allow_exact_keyword_match_, 437 keyword_is_selected || allow_exact_keyword_match_,
438 AutocompleteInput::ALL_MATCHES); 438 AutocompleteInput::ALL_MATCHES);
439 } 439 }
440 440
441 void OmniboxEditModel::StopAutocomplete() { 441 void OmniboxEditModel::StopAutocomplete() {
442 if (popup_->IsOpen() && !in_revert_) { 442 if (popup_->IsOpen()) {
443 InstantController* instant = controller_->GetInstant(); 443 if (!in_revert_) {
444 if (instant && !instant->commit_on_pointer_release()) 444 InstantController* instant = controller_->GetInstant();
445 instant->DestroyPreviewContents(); 445 if (instant && !instant->commit_on_pointer_release())
446 instant->DestroyPreviewContents();
447 }
448
449 autocomplete_controller_->Stop(true);
446 } 450 }
447
448 autocomplete_controller_->Stop(true);
449 } 451 }
450 452
451 bool OmniboxEditModel::CanPasteAndGo(const string16& text) const { 453 bool OmniboxEditModel::CanPasteAndGo(const string16& text) const {
452 if (!view_->command_updater()->IsCommandEnabled(IDC_OPEN_CURRENT_URL)) 454 if (!view_->command_updater()->IsCommandEnabled(IDC_OPEN_CURRENT_URL))
453 return false; 455 return false;
454 456
455 AutocompleteMatch match; 457 AutocompleteMatch match;
456 ClassifyStringForPasteAndGo(text, &match, NULL); 458 ClassifyStringForPasteAndGo(text, &match, NULL);
457 return match.destination_url.is_valid(); 459 return match.destination_url.is_valid();
458 } 460 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 autocomplete_controller_->input().text(), 525 autocomplete_controller_->input().text(),
524 just_deleted_text_, 526 just_deleted_text_,
525 autocomplete_controller_->input().type(), 527 autocomplete_controller_->input().type(),
526 popup_->selected_line(), 528 popup_->selected_line(),
527 -1, // don't yet know tab ID; set later if appropriate 529 -1, // don't yet know tab ID; set later if appropriate
528 ClassifyPage(controller_->GetTabContents()-> 530 ClassifyPage(controller_->GetTabContents()->
529 web_contents()->GetURL()), 531 web_contents()->GetURL()),
530 base::TimeTicks::Now() - time_user_first_modified_omnibox_, 532 base::TimeTicks::Now() - time_user_first_modified_omnibox_,
531 0, // inline autocomplete length; possibly set later 533 0, // inline autocomplete length; possibly set later
532 result()); 534 result());
533 DCHECK(user_input_in_progress_) << "We didn't get here through the " 535 DCHECK(user_input_in_progress_ ||
534 "expected series of calls. time_user_first_modified_omnibox_ is " 536 match.type == AutocompleteMatch::SEARCH_ZEROSUGGEST ||
535 "not set correctly and other things may be wrong."; 537 match.type == AutocompleteMatch::SEARCH_ZEROSUGGEST_URL)
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.";
536 if (index != OmniboxPopupModel::kNoMatch) 541 if (index != OmniboxPopupModel::kNoMatch)
537 log.selected_index = index; 542 log.selected_index = index;
538 else if (!has_temporary_text_) 543 else if (!has_temporary_text_)
539 log.inline_autocompleted_length = inline_autocomplete_text_.length(); 544 log.inline_autocompleted_length = inline_autocomplete_text_.length();
540 if (disposition == CURRENT_TAB) { 545 if (disposition == CURRENT_TAB) {
541 // 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,
542 // 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
543 // tab, we don't know the tab ID yet.) 548 // tab, we don't know the tab ID yet.)
544 log.tab_id = controller_->GetTabContents()-> 549 log.tab_id = controller_->GetTabContents()->
545 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
687 } 692 }
688 693
689 void OmniboxEditModel::OnSetFocus(bool control_down) { 694 void OmniboxEditModel::OnSetFocus(bool control_down) {
690 has_focus_ = true; 695 has_focus_ = true;
691 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; 696 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP;
692 697
693 InstantController* instant = controller_->GetInstant(); 698 InstantController* instant = controller_->GetInstant();
694 if (instant) 699 if (instant)
695 instant->OnAutocompleteGotFocus(); 700 instant->OnAutocompleteGotFocus();
696 701
702 autocomplete_controller_->StartZerosuggest(PermanentURL(), user_text_);
703
697 NotifySearchTabHelper(); 704 NotifySearchTabHelper();
698 } 705 }
699 706
700 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { 707 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) {
701 SetSuggestedText(string16(), INSTANT_COMPLETE_NOW); 708 SetSuggestedText(string16(), INSTANT_COMPLETE_NOW);
702 709
703 InstantController* instant = controller_->GetInstant(); 710 InstantController* instant = controller_->GetInstant();
704 if (instant) 711 if (instant)
705 instant->OnAutocompleteLostFocus(view_gaining_focus); 712 instant->OnAutocompleteLostFocus(view_gaining_focus);
706 713
714 autocomplete_controller_->StopZerosuggest();
707 NotifySearchTabHelper(); 715 NotifySearchTabHelper();
708 } 716 }
709 717
710 void OmniboxEditModel::OnKillFocus() { 718 void OmniboxEditModel::OnKillFocus() {
711 has_focus_ = false; 719 has_focus_ = false;
712 control_key_state_ = UP; 720 control_key_state_ = UP;
713 paste_state_ = NONE; 721 paste_state_ = NONE;
714 } 722 }
715 723
716 bool OmniboxEditModel::OnEscapeKeyPressed() { 724 bool OmniboxEditModel::OnEscapeKeyPressed() {
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 } 1199 }
1192 1200
1193 void OmniboxEditModel::ClassifyStringForPasteAndGo( 1201 void OmniboxEditModel::ClassifyStringForPasteAndGo(
1194 const string16& text, 1202 const string16& text,
1195 AutocompleteMatch* match, 1203 AutocompleteMatch* match,
1196 GURL* alternate_nav_url) const { 1204 GURL* alternate_nav_url) const {
1197 DCHECK(match); 1205 DCHECK(match);
1198 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, 1206 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text,
1199 string16(), false, false, match, alternate_nav_url); 1207 string16(), false, false, match, alternate_nav_url);
1200 } 1208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698