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()) { |
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 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_ || |
535 "expected series of calls. time_user_first_modified_omnibox_ is " | 537 (match.provider && match.provider->name() == "ZeroSuggest")) |
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 Loading... | |
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): Merge this into Start() and just call that here rather than | |
703 // having a special entry point for zero-suggest. | |
Peter Kasting
2012/08/15 05:30:39
Ah. That's what you meant.
Hmm. I wonder if we
Jered
2012/08/15 16:32:12
Done.
| |
704 autocomplete_controller_->StartZeroSuggest(PermanentURL(), user_text_); | |
705 | |
698 NotifySearchTabHelper(); | 706 NotifySearchTabHelper(); |
699 } | 707 } |
700 | 708 |
701 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { | 709 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { |
702 SetSuggestedText(string16(), INSTANT_COMPLETE_NOW); | 710 SetSuggestedText(string16(), INSTANT_COMPLETE_NOW); |
703 | 711 |
704 if (InstantController* instant = controller_->GetInstant()) | 712 if (InstantController* instant = controller_->GetInstant()) |
705 instant->OnAutocompleteLostFocus(view_gaining_focus); | 713 instant->OnAutocompleteLostFocus(view_gaining_focus); |
706 | 714 |
715 // TODO(jered): Rip this out along with StartZeroSuggest. | |
716 autocomplete_controller_->StopZeroSuggest(); | |
707 NotifySearchTabHelper(); | 717 NotifySearchTabHelper(); |
708 } | 718 } |
709 | 719 |
710 void OmniboxEditModel::OnKillFocus() { | 720 void OmniboxEditModel::OnKillFocus() { |
711 has_focus_ = false; | 721 has_focus_ = false; |
712 control_key_state_ = UP; | 722 control_key_state_ = UP; |
713 paste_state_ = NONE; | 723 paste_state_ = NONE; |
714 } | 724 } |
715 | 725 |
716 bool OmniboxEditModel::OnEscapeKeyPressed() { | 726 bool OmniboxEditModel::OnEscapeKeyPressed() { |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1205 } | 1215 } |
1206 | 1216 |
1207 void OmniboxEditModel::ClassifyStringForPasteAndGo( | 1217 void OmniboxEditModel::ClassifyStringForPasteAndGo( |
1208 const string16& text, | 1218 const string16& text, |
1209 AutocompleteMatch* match, | 1219 AutocompleteMatch* match, |
1210 GURL* alternate_nav_url) const { | 1220 GURL* alternate_nav_url) const { |
1211 DCHECK(match); | 1221 DCHECK(match); |
1212 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, | 1222 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, |
1213 string16(), false, false, match, alternate_nav_url); | 1223 string16(), false, false, match, alternate_nav_url); |
1214 } | 1224 } |
OLD | NEW |