OLD | NEW |
---|---|
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 Loading... | |
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/27 23:13:35
Nit: Revert changes to this function
samarth
2012/08/28 23:18:46
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 Loading... | |
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_ || match.provider->name() == "ZeroSuggest") |
535 "expected series of calls. time_user_first_modified_omnibox_ is " | 537 << "We didn't get here through the expected series of calls. " |
536 "not set correctly and other things may be wrong."; | 538 << "time_user_first_modified_omnibox_ is not set correctly and other " |
539 << "things may be wrong."; | |
537 if (index != OmniboxPopupModel::kNoMatch) | 540 if (index != OmniboxPopupModel::kNoMatch) |
538 log.selected_index = index; | 541 log.selected_index = index; |
539 else if (!has_temporary_text_) | 542 else if (!has_temporary_text_) |
540 log.inline_autocompleted_length = inline_autocomplete_text_.length(); | 543 log.inline_autocompleted_length = inline_autocomplete_text_.length(); |
541 if (disposition == CURRENT_TAB) { | 544 if (disposition == CURRENT_TAB) { |
542 // If we know the destination is being opened in the current tab, | 545 // 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 | 546 // 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.) | 547 // tab, we don't know the tab ID yet.) |
545 log.tab_id = controller_->GetTabContents()-> | 548 log.tab_id = controller_->GetTabContents()-> |
546 restore_tab_helper()->session_id().id(); | 549 restore_tab_helper()->session_id().id(); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
689 } | 692 } |
690 | 693 |
691 void OmniboxEditModel::OnSetFocus(bool control_down) { | 694 void OmniboxEditModel::OnSetFocus(bool control_down) { |
692 has_focus_ = true; | 695 has_focus_ = true; |
693 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; | 696 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; |
694 | 697 |
695 InstantController* instant = controller_->GetInstant(); | 698 InstantController* instant = controller_->GetInstant(); |
696 if (instant) | 699 if (instant) |
697 instant->OnAutocompleteGotFocus(); | 700 instant->OnAutocompleteGotFocus(); |
698 | 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. | |
704 // Note that we avoid PermanentURL() here because it's not guaranteed to give | |
705 // us the actual underlying current URL, e.g. if we're on the NTP and the | |
706 // |permanent_text_| is empty. | |
707 autocomplete_controller_->StartZeroSuggest( | |
708 controller_->GetTabContents()->web_contents()->GetURL(), | |
709 user_text_); | |
710 | |
699 NotifySearchTabHelper(); | 711 NotifySearchTabHelper(); |
700 } | 712 } |
701 | 713 |
702 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { | 714 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { |
703 SetSuggestedText(string16(), INSTANT_COMPLETE_NOW); | 715 SetSuggestedText(string16(), INSTANT_COMPLETE_NOW); |
704 | 716 |
705 if (InstantController* instant = controller_->GetInstant()) | 717 if (InstantController* instant = controller_->GetInstant()) |
706 instant->OnAutocompleteLostFocus(view_gaining_focus); | 718 instant->OnAutocompleteLostFocus(view_gaining_focus); |
707 | 719 |
720 // TODO(jered): Rip this out along with StartZeroSuggest. | |
721 autocomplete_controller_->StopZeroSuggest(); | |
708 NotifySearchTabHelper(); | 722 NotifySearchTabHelper(); |
709 } | 723 } |
710 | 724 |
711 void OmniboxEditModel::OnKillFocus() { | 725 void OmniboxEditModel::OnKillFocus() { |
712 has_focus_ = false; | 726 has_focus_ = false; |
713 control_key_state_ = UP; | 727 control_key_state_ = UP; |
714 paste_state_ = NONE; | 728 paste_state_ = NONE; |
715 } | 729 } |
716 | 730 |
717 bool OmniboxEditModel::OnEscapeKeyPressed() { | 731 bool OmniboxEditModel::OnEscapeKeyPressed() { |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1213 } | 1227 } |
1214 | 1228 |
1215 void OmniboxEditModel::ClassifyStringForPasteAndGo( | 1229 void OmniboxEditModel::ClassifyStringForPasteAndGo( |
1216 const string16& text, | 1230 const string16& text, |
1217 AutocompleteMatch* match, | 1231 AutocompleteMatch* match, |
1218 GURL* alternate_nav_url) const { | 1232 GURL* alternate_nav_url) const { |
1219 DCHECK(match); | 1233 DCHECK(match); |
1220 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, | 1234 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, |
1221 string16(), false, false, match, alternate_nav_url); | 1235 string16(), false, false, match, alternate_nav_url); |
1222 } | 1236 } |
OLD | NEW |