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

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: Rename flag and add 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()) {
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 }
449
450 autocomplete_controller_->Stop(true);
447 } 451 }
448
449 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;
457 ClassifyStringForPasteAndGo(text, &match, NULL); 459 ClassifyStringForPasteAndGo(text, &match, NULL);
458 return match.destination_url.is_valid(); 460 return match.destination_url.is_valid();
459 } 461 }
(...skipping 64 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.type == AutocompleteMatch::SEARCH_ZEROSUGGEST ||
536 "not set correctly and other things may be wrong."; 538 match.type == AutocompleteMatch::SEARCH_ZEROSUGGEST_URL)
539 << "We didn't get here through the expected series of calls. "
540 << "time_user_first_modified_omnibox_ is not set correctly and other "
541 << "things may be wrong.";
537 if (index != OmniboxPopupModel::kNoMatch) 542 if (index != OmniboxPopupModel::kNoMatch)
538 log.selected_index = index; 543 log.selected_index = index;
539 else if (!has_temporary_text_) 544 else if (!has_temporary_text_)
540 log.inline_autocompleted_length = inline_autocomplete_text_.length(); 545 log.inline_autocompleted_length = inline_autocomplete_text_.length();
541 if (disposition == CURRENT_TAB) { 546 if (disposition == CURRENT_TAB) {
542 // If we know the destination is being opened in the current tab, 547 // 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 548 // 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.) 549 // tab, we don't know the tab ID yet.)
545 log.tab_id = controller_->GetTabContents()-> 550 log.tab_id = controller_->GetTabContents()->
546 restore_tab_helper()->session_id().id(); 551 restore_tab_helper()->session_id().id();
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 } 693 }
689 694
690 void OmniboxEditModel::OnSetFocus(bool control_down) { 695 void OmniboxEditModel::OnSetFocus(bool control_down) {
691 has_focus_ = true; 696 has_focus_ = true;
692 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; 697 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP;
693 698
694 InstantController* instant = controller_->GetInstant(); 699 InstantController* instant = controller_->GetInstant();
695 if (instant) 700 if (instant)
696 instant->OnAutocompleteGotFocus(); 701 instant->OnAutocompleteGotFocus();
697 702
703 // TODO(jered): Remove this call once suggestions are decoupled from typing
704 // in the omnibox. Then we can just run Zerosuggest as a normal provider.
705 autocomplete_controller_->StartZerosuggest(PermanentURL(), user_text_);
706
698 NotifySearchTabHelper(); 707 NotifySearchTabHelper();
699 } 708 }
700 709
701 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { 710 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) {
702 SetSuggestedText(string16(), INSTANT_COMPLETE_NOW); 711 SetSuggestedText(string16(), INSTANT_COMPLETE_NOW);
703 712
704 if (InstantController* instant = controller_->GetInstant()) 713 if (InstantController* instant = controller_->GetInstant())
705 instant->OnAutocompleteLostFocus(view_gaining_focus); 714 instant->OnAutocompleteLostFocus(view_gaining_focus);
706 715
716 // TODO(jered): Rip this out along with StartZerosuggest.
717 autocomplete_controller_->StopZerosuggest();
707 NotifySearchTabHelper(); 718 NotifySearchTabHelper();
708 } 719 }
709 720
710 void OmniboxEditModel::OnKillFocus() { 721 void OmniboxEditModel::OnKillFocus() {
711 has_focus_ = false; 722 has_focus_ = false;
712 control_key_state_ = UP; 723 control_key_state_ = UP;
713 paste_state_ = NONE; 724 paste_state_ = NONE;
714 } 725 }
715 726
716 bool OmniboxEditModel::OnEscapeKeyPressed() { 727 bool OmniboxEditModel::OnEscapeKeyPressed() {
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 } 1216 }
1206 1217
1207 void OmniboxEditModel::ClassifyStringForPasteAndGo( 1218 void OmniboxEditModel::ClassifyStringForPasteAndGo(
1208 const string16& text, 1219 const string16& text,
1209 AutocompleteMatch* match, 1220 AutocompleteMatch* match,
1210 GURL* alternate_nav_url) const { 1221 GURL* alternate_nav_url) const {
1211 DCHECK(match); 1222 DCHECK(match);
1212 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, 1223 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text,
1213 string16(), false, false, match, alternate_nav_url); 1224 string16(), false, false, match, alternate_nav_url);
1214 } 1225 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698