OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 OmniboxEditModel::State::~State() { | 115 OmniboxEditModel::State::~State() { |
116 } | 116 } |
117 | 117 |
118 /////////////////////////////////////////////////////////////////////////////// | 118 /////////////////////////////////////////////////////////////////////////////// |
119 // OmniboxEditModel | 119 // OmniboxEditModel |
120 | 120 |
121 OmniboxEditModel::OmniboxEditModel(OmniboxView* view, | 121 OmniboxEditModel::OmniboxEditModel(OmniboxView* view, |
122 OmniboxEditController* controller, | 122 OmniboxEditController* controller, |
123 Profile* profile) | 123 Profile* profile) |
124 : view_(view), | 124 : view_(view), |
125 popup_(NULL), | |
126 controller_(controller), | 125 controller_(controller), |
127 focus_state_(OMNIBOX_FOCUS_NONE), | 126 focus_state_(OMNIBOX_FOCUS_NONE), |
128 user_input_in_progress_(false), | 127 user_input_in_progress_(false), |
129 just_deleted_text_(false), | 128 just_deleted_text_(false), |
130 has_temporary_text_(false), | 129 has_temporary_text_(false), |
131 is_temporary_text_set_by_instant_(false), | 130 is_temporary_text_set_by_instant_(false), |
132 selected_instant_autocomplete_match_index_(OmniboxPopupModel::kNoMatch), | 131 selected_instant_autocomplete_match_index_(OmniboxPopupModel::kNoMatch), |
133 is_instant_temporary_text_a_search_query_(false), | 132 is_instant_temporary_text_a_search_query_(false), |
134 paste_state_(NONE), | 133 paste_state_(NONE), |
135 control_key_state_(UP), | 134 control_key_state_(UP), |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 229 |
231 void OmniboxEditModel::FinalizeInstantQuery(const string16& input_text, | 230 void OmniboxEditModel::FinalizeInstantQuery(const string16& input_text, |
232 const InstantSuggestion& suggestion, | 231 const InstantSuggestion& suggestion, |
233 bool skip_inline_autocomplete) { | 232 bool skip_inline_autocomplete) { |
234 if (skip_inline_autocomplete) { | 233 if (skip_inline_autocomplete) { |
235 const string16 final_text = input_text + suggestion.text; | 234 const string16 final_text = input_text + suggestion.text; |
236 view_->OnBeforePossibleChange(); | 235 view_->OnBeforePossibleChange(); |
237 view_->SetWindowTextAndCaretPos(final_text, final_text.length(), false, | 236 view_->SetWindowTextAndCaretPos(final_text, final_text.length(), false, |
238 false); | 237 false); |
239 view_->OnAfterPossibleChange(); | 238 view_->OnAfterPossibleChange(); |
240 } else if (popup_->IsOpen()) { | 239 } else if (popup_model()->IsOpen()) { |
241 SearchProvider* search_provider = | 240 SearchProvider* search_provider = |
242 autocomplete_controller()->search_provider(); | 241 autocomplete_controller()->search_provider(); |
243 // There may be no providers during testing; guard against that. | 242 // There may be no providers during testing; guard against that. |
244 if (search_provider) | 243 if (search_provider) |
245 search_provider->FinalizeInstantQuery(input_text, suggestion); | 244 search_provider->FinalizeInstantQuery(input_text, suggestion); |
246 } | 245 } |
247 } | 246 } |
248 | 247 |
249 void OmniboxEditModel::SetInstantSuggestion( | 248 void OmniboxEditModel::SetInstantSuggestion( |
250 const InstantSuggestion& suggestion) { | 249 const InstantSuggestion& suggestion) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 // has been closed or on return from a sleep state. | 341 // has been closed or on return from a sleep state. |
343 // (http://crbug.com/105689) | 342 // (http://crbug.com/105689) |
344 if (!delegate_->CurrentPageExists()) | 343 if (!delegate_->CurrentPageExists()) |
345 break; | 344 break; |
346 // Ask for prerendering if the destination URL is different than the | 345 // Ask for prerendering if the destination URL is different than the |
347 // current URL. | 346 // current URL. |
348 if (current_match.destination_url != PermanentURL()) | 347 if (current_match.destination_url != PermanentURL()) |
349 delegate_->DoPrerender(current_match); | 348 delegate_->DoPrerender(current_match); |
350 break; | 349 break; |
351 case AutocompleteActionPredictor::ACTION_PRECONNECT: | 350 case AutocompleteActionPredictor::ACTION_PRECONNECT: |
352 DoPreconnect(current_match); | 351 omnibox_controller_->DoPreconnect(current_match); |
353 break; | 352 break; |
354 case AutocompleteActionPredictor::ACTION_NONE: | 353 case AutocompleteActionPredictor::ACTION_NONE: |
355 break; | 354 break; |
356 } | 355 } |
357 | 356 |
358 controller_->OnChanged(); | 357 controller_->OnChanged(); |
359 } | 358 } |
360 | 359 |
361 void OmniboxEditModel::GetDataForURLExport(GURL* url, | 360 void OmniboxEditModel::GetDataForURLExport(GURL* url, |
362 string16* title, | 361 string16* title, |
(...skipping 18 matching lines...) Expand all Loading... |
381 #endif | 380 #endif |
382 | 381 |
383 // The value of input.prevent_inline_autocomplete() is determined by the | 382 // The value of input.prevent_inline_autocomplete() is determined by the |
384 // following conditions: | 383 // following conditions: |
385 // 1. If the caret is at the end of the text. | 384 // 1. If the caret is at the end of the text. |
386 // 2. If it's in IME composition mode. | 385 // 2. If it's in IME composition mode. |
387 // We send the caret position to Instant (so it can determine #1 itself), and | 386 // We send the caret position to Instant (so it can determine #1 itself), and |
388 // we use a separated widget for displaying the Instant suggest (so it doesn't | 387 // we use a separated widget for displaying the Instant suggest (so it doesn't |
389 // interfere with #2). So, we don't need to care about the value of | 388 // interfere with #2). So, we don't need to care about the value of |
390 // input.prevent_inline_autocomplete() here. | 389 // input.prevent_inline_autocomplete() here. |
391 return view_->DeleteAtEndPressed() || popup_->selected_line() != 0 || | 390 return view_->DeleteAtEndPressed() || popup_model()->selected_line() != 0 || |
392 just_deleted_text_; | 391 just_deleted_text_; |
393 } | 392 } |
394 | 393 |
395 bool OmniboxEditModel::CurrentTextIsURL() const { | 394 bool OmniboxEditModel::CurrentTextIsURL() const { |
396 if (view_->toolbar_model()->GetSearchTermsType() != | 395 if (view_->toolbar_model()->GetSearchTermsType() != |
397 ToolbarModel::NO_SEARCH_TERMS) | 396 ToolbarModel::NO_SEARCH_TERMS) |
398 return false; | 397 return false; |
399 | 398 |
400 // If current text is not composed of replaced search terms and | 399 // If current text is not composed of replaced search terms and |
401 // !user_input_in_progress_, then permanent text is showing and should be a | 400 // !user_input_in_progress_, then permanent text is showing and should be a |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 | 470 |
472 user_input_in_progress_ = in_progress; | 471 user_input_in_progress_ = in_progress; |
473 if (user_input_in_progress_) { | 472 if (user_input_in_progress_) { |
474 time_user_first_modified_omnibox_ = base::TimeTicks::Now(); | 473 time_user_first_modified_omnibox_ = base::TimeTicks::Now(); |
475 content::RecordAction(content::UserMetricsAction("OmniboxInputInProgress")); | 474 content::RecordAction(content::UserMetricsAction("OmniboxInputInProgress")); |
476 autocomplete_controller()->ResetSession(); | 475 autocomplete_controller()->ResetSession(); |
477 } | 476 } |
478 controller_->OnInputInProgress(in_progress); | 477 controller_->OnInputInProgress(in_progress); |
479 | 478 |
480 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_, | 479 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_, |
481 popup_->IsOpen(), user_text_.empty()); | 480 popup_model()->IsOpen(), user_text_.empty()); |
482 } | 481 } |
483 | 482 |
484 void OmniboxEditModel::Revert() { | 483 void OmniboxEditModel::Revert() { |
485 SetInputInProgress(false); | 484 SetInputInProgress(false); |
486 paste_state_ = NONE; | 485 paste_state_ = NONE; |
487 InternalSetUserText(string16()); | 486 InternalSetUserText(string16()); |
488 keyword_.clear(); | 487 keyword_.clear(); |
489 is_keyword_hint_ = false; | 488 is_keyword_hint_ = false; |
490 has_temporary_text_ = false; | 489 has_temporary_text_ = false; |
491 is_temporary_text_set_by_instant_ = false; | 490 is_temporary_text_set_by_instant_ = false; |
492 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; | 491 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; |
493 is_instant_temporary_text_a_search_query_ = false; | 492 is_instant_temporary_text_a_search_query_ = false; |
494 view_->SetWindowTextAndCaretPos(permanent_text_, | 493 view_->SetWindowTextAndCaretPos(permanent_text_, |
495 has_focus() ? permanent_text_.length() : 0, | 494 has_focus() ? permanent_text_.length() : 0, |
496 false, true); | 495 false, true); |
497 AutocompleteActionPredictor* action_predictor = | 496 AutocompleteActionPredictor* action_predictor = |
498 AutocompleteActionPredictorFactory::GetForProfile(profile_); | 497 AutocompleteActionPredictorFactory::GetForProfile(profile_); |
499 if (action_predictor) | 498 if (action_predictor) |
500 action_predictor->ClearTransitionalMatches(); | 499 action_predictor->ClearTransitionalMatches(); |
501 } | 500 } |
502 | 501 |
503 void OmniboxEditModel::StartAutocomplete( | 502 void OmniboxEditModel::StartAutocomplete( |
504 bool has_selected_text, | 503 bool has_selected_text, |
505 bool prevent_inline_autocomplete) const { | 504 bool prevent_inline_autocomplete) const { |
506 ClearPopupKeywordMode(); | 505 omnibox_controller_->ClearPopupKeywordMode(); |
507 | 506 |
508 bool keyword_is_selected = KeywordIsSelected(); | 507 bool keyword_is_selected = KeywordIsSelected(); |
509 popup_->SetHoveredLine(OmniboxPopupModel::kNoMatch); | 508 popup_model()->SetHoveredLine(OmniboxPopupModel::kNoMatch); |
510 | 509 |
511 size_t cursor_position; | 510 size_t cursor_position; |
512 if (inline_autocomplete_text_.empty()) { | 511 if (inline_autocomplete_text_.empty()) { |
513 // Cursor position is equivalent to the current selection's end. | 512 // Cursor position is equivalent to the current selection's end. |
514 size_t start; | 513 size_t start; |
515 view_->GetSelectionBounds(&start, &cursor_position); | 514 view_->GetSelectionBounds(&start, &cursor_position); |
516 // Adjust cursor position taking into account possible keyword in the user | 515 // Adjust cursor position taking into account possible keyword in the user |
517 // text. We rely on DisplayTextFromUserText() method which is consistent | 516 // text. We rely on DisplayTextFromUserText() method which is consistent |
518 // with keyword extraction done in KeywordProvider/SearchProvider. | 517 // with keyword extraction done in KeywordProvider/SearchProvider. |
519 const size_t cursor_offset = | 518 const size_t cursor_offset = |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 view_->OpenMatch(match, disposition, alternate_nav_url, | 653 view_->OpenMatch(match, disposition, alternate_nav_url, |
655 OmniboxPopupModel::kNoMatch); | 654 OmniboxPopupModel::kNoMatch); |
656 } | 655 } |
657 | 656 |
658 void OmniboxEditModel::OpenMatch(const AutocompleteMatch& match, | 657 void OmniboxEditModel::OpenMatch(const AutocompleteMatch& match, |
659 WindowOpenDisposition disposition, | 658 WindowOpenDisposition disposition, |
660 const GURL& alternate_nav_url, | 659 const GURL& alternate_nav_url, |
661 size_t index) { | 660 size_t index) { |
662 // We only care about cases where there is a selection (i.e. the popup is | 661 // We only care about cases where there is a selection (i.e. the popup is |
663 // open). | 662 // open). |
664 if (popup_->IsOpen()) { | 663 if (popup_model()->IsOpen()) { |
665 const base::TimeTicks& now(base::TimeTicks::Now()); | 664 const base::TimeTicks& now(base::TimeTicks::Now()); |
666 // TODO(sreeram): Handle is_temporary_text_set_by_instant_ correctly. | 665 // TODO(sreeram): Handle is_temporary_text_set_by_instant_ correctly. |
667 AutocompleteLog log( | 666 AutocompleteLog log( |
668 autocomplete_controller()->input().text(), | 667 autocomplete_controller()->input().text(), |
669 just_deleted_text_, | 668 just_deleted_text_, |
670 autocomplete_controller()->input().type(), | 669 autocomplete_controller()->input().type(), |
671 popup_->selected_line(), | 670 popup_model()->selected_line(), |
672 -1, // don't yet know tab ID; set later if appropriate | 671 -1, // don't yet know tab ID; set later if appropriate |
673 delegate_->CurrentPageExists() ? ClassifyPage(delegate_->GetURL()) : | 672 delegate_->CurrentPageExists() ? ClassifyPage(delegate_->GetURL()) : |
674 metrics::OmniboxEventProto_PageClassification_OTHER, | 673 metrics::OmniboxEventProto_PageClassification_OTHER, |
675 now - time_user_first_modified_omnibox_, | 674 now - time_user_first_modified_omnibox_, |
676 string16::npos, // completed_length; possibly set later | 675 string16::npos, // completed_length; possibly set later |
677 now - autocomplete_controller()->last_time_default_match_changed(), | 676 now - autocomplete_controller()->last_time_default_match_changed(), |
678 result()); | 677 result()); |
679 DCHECK(user_input_in_progress_ || | 678 DCHECK(user_input_in_progress_ || |
680 match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST) | 679 match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST) |
681 << "We didn't get here through the expected series of calls. " | 680 << "We didn't get here through the expected series of calls. " |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 if (match.starred) | 779 if (match.starred) |
781 bookmark_utils::RecordBookmarkLaunch(bookmark_utils::LAUNCH_OMNIBOX); | 780 bookmark_utils::RecordBookmarkLaunch(bookmark_utils::LAUNCH_OMNIBOX); |
782 } | 781 } |
783 | 782 |
784 bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) { | 783 bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) { |
785 DCHECK(is_keyword_hint_ && !keyword_.empty()); | 784 DCHECK(is_keyword_hint_ && !keyword_.empty()); |
786 | 785 |
787 autocomplete_controller()->Stop(false); | 786 autocomplete_controller()->Stop(false); |
788 is_keyword_hint_ = false; | 787 is_keyword_hint_ = false; |
789 | 788 |
790 if (popup_->IsOpen()) | 789 if (popup_model()->IsOpen()) |
791 popup_->SetSelectedLineState(OmniboxPopupModel::KEYWORD); | 790 popup_model()->SetSelectedLineState(OmniboxPopupModel::KEYWORD); |
792 else | 791 else |
793 StartAutocomplete(false, true); | 792 StartAutocomplete(false, true); |
794 | 793 |
795 // Ensure the current selection is saved before showing keyword mode | 794 // Ensure the current selection is saved before showing keyword mode |
796 // so that moving to another line and then reverting the text will restore | 795 // so that moving to another line and then reverting the text will restore |
797 // the current state properly. | 796 // the current state properly. |
798 bool save_original_selection = !has_temporary_text_; | 797 bool save_original_selection = !has_temporary_text_; |
799 has_temporary_text_ = true; | 798 has_temporary_text_ = true; |
800 is_temporary_text_set_by_instant_ = false; | 799 is_temporary_text_set_by_instant_ = false; |
801 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; | 800 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; |
802 is_instant_temporary_text_a_search_query_ = false; | 801 is_instant_temporary_text_a_search_query_ = false; |
803 view_->OnTemporaryTextMaybeChanged( | 802 view_->OnTemporaryTextMaybeChanged( |
804 DisplayTextFromUserText(CurrentMatch().fill_into_edit), | 803 DisplayTextFromUserText(CurrentMatch().fill_into_edit), |
805 save_original_selection, true); | 804 save_original_selection, true); |
806 | 805 |
807 content::RecordAction(UserMetricsAction("AcceptedKeywordHint")); | 806 content::RecordAction(UserMetricsAction("AcceptedKeywordHint")); |
808 UMA_HISTOGRAM_ENUMERATION(kEnteredKeywordModeHistogram, entered_method, | 807 UMA_HISTOGRAM_ENUMERATION(kEnteredKeywordModeHistogram, entered_method, |
809 ENTERED_KEYWORD_MODE_NUM_ITEMS); | 808 ENTERED_KEYWORD_MODE_NUM_ITEMS); |
810 | 809 |
811 return true; | 810 return true; |
812 } | 811 } |
813 | 812 |
| 813 void OmniboxEditModel::AcceptTemporaryTextAsUserText() { |
| 814 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); |
| 815 has_temporary_text_ = false; |
| 816 is_temporary_text_set_by_instant_ = false; |
| 817 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; |
| 818 is_instant_temporary_text_a_search_query_ = false; |
| 819 OnPopupBoundsChanged(gfx::Rect()); |
| 820 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_, |
| 821 popup_model()->IsOpen(), user_text_.empty()); |
| 822 } |
| 823 |
814 void OmniboxEditModel::ClearKeyword(const string16& visible_text) { | 824 void OmniboxEditModel::ClearKeyword(const string16& visible_text) { |
815 autocomplete_controller()->Stop(false); | 825 autocomplete_controller()->Stop(false); |
816 ClearPopupKeywordMode(); | 826 omnibox_controller_->ClearPopupKeywordMode(); |
817 | 827 |
818 const string16 window_text(keyword_ + visible_text); | 828 const string16 window_text(keyword_ + visible_text); |
819 | 829 |
820 // Only reset the result if the edit text has changed since the | 830 // Only reset the result if the edit text has changed since the |
821 // keyword was accepted, or if the popup is closed. | 831 // keyword was accepted, or if the popup is closed. |
822 if (just_deleted_text_ || !visible_text.empty() || !popup_->IsOpen()) { | 832 if (just_deleted_text_ || !visible_text.empty() || !popup_model()->IsOpen()) { |
823 view_->OnBeforePossibleChange(); | 833 view_->OnBeforePossibleChange(); |
824 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length(), | 834 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length(), |
825 false, false); | 835 false, false); |
826 keyword_.clear(); | 836 keyword_.clear(); |
827 is_keyword_hint_ = false; | 837 is_keyword_hint_ = false; |
828 view_->OnAfterPossibleChange(); | 838 view_->OnAfterPossibleChange(); |
829 just_deleted_text_ = true; // OnAfterPossibleChange() fails to clear this | 839 just_deleted_text_ = true; // OnAfterPossibleChange() fails to clear this |
830 // since the edit contents have actually grown | 840 // since the edit contents have actually grown |
831 // longer. | 841 // longer. |
832 } else { | 842 } else { |
833 is_keyword_hint_ = true; | 843 is_keyword_hint_ = true; |
834 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length(), | 844 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length(), |
835 false, true); | 845 false, true); |
836 } | 846 } |
837 } | 847 } |
838 | 848 |
839 const AutocompleteResult& OmniboxEditModel::result() const { | |
840 return autocomplete_controller()->result(); | |
841 } | |
842 | |
843 void OmniboxEditModel::OnSetFocus(bool control_down) { | 849 void OmniboxEditModel::OnSetFocus(bool control_down) { |
844 // If the omnibox lost focus while the caret was hidden and then regained | 850 // If the omnibox lost focus while the caret was hidden and then regained |
845 // focus, OnSetFocus() is called and should restore visibility. Note that | 851 // focus, OnSetFocus() is called and should restore visibility. Note that |
846 // focus can be regained without an accompanying call to | 852 // focus can be regained without an accompanying call to |
847 // OmniboxView::SetFocus(), e.g. by tabbing in. | 853 // OmniboxView::SetFocus(), e.g. by tabbing in. |
848 SetFocusState(OMNIBOX_FOCUS_VISIBLE, OMNIBOX_FOCUS_CHANGE_EXPLICIT); | 854 SetFocusState(OMNIBOX_FOCUS_VISIBLE, OMNIBOX_FOCUS_CHANGE_EXPLICIT); |
849 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; | 855 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; |
850 | 856 |
851 if (delegate_->CurrentPageExists()) { | 857 if (delegate_->CurrentPageExists()) { |
852 // TODO(jered): We may want to merge this into Start() and just call that | 858 // TODO(jered): We may want to merge this into Start() and just call that |
853 // here rather than having a special entry point for zero-suggest. Note | 859 // here rather than having a special entry point for zero-suggest. Note |
854 // that we avoid PermanentURL() here because it's not guaranteed to give us | 860 // that we avoid PermanentURL() here because it's not guaranteed to give us |
855 // the actual underlying current URL, e.g. if we're on the NTP and the | 861 // the actual underlying current URL, e.g. if we're on the NTP and the |
856 // |permanent_text_| is empty. | 862 // |permanent_text_| is empty. |
857 autocomplete_controller()->StartZeroSuggest(delegate_->GetURL(), | 863 autocomplete_controller()->StartZeroSuggest(delegate_->GetURL(), |
858 user_text_); | 864 user_text_); |
859 } | 865 } |
860 | 866 |
861 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_, | 867 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_, |
862 popup_->IsOpen(), user_text_.empty()); | 868 popup_model()->IsOpen(), user_text_.empty()); |
863 } | 869 } |
864 | 870 |
865 void OmniboxEditModel::SetCaretVisibility(bool visible) { | 871 void OmniboxEditModel::SetCaretVisibility(bool visible) { |
866 // Caret visibility only matters if the omnibox has focus. | 872 // Caret visibility only matters if the omnibox has focus. |
867 if (focus_state_ != OMNIBOX_FOCUS_NONE) { | 873 if (focus_state_ != OMNIBOX_FOCUS_NONE) { |
868 SetFocusState(visible ? OMNIBOX_FOCUS_VISIBLE : OMNIBOX_FOCUS_INVISIBLE, | 874 SetFocusState(visible ? OMNIBOX_FOCUS_VISIBLE : OMNIBOX_FOCUS_INVISIBLE, |
869 OMNIBOX_FOCUS_CHANGE_EXPLICIT); | 875 OMNIBOX_FOCUS_CHANGE_EXPLICIT); |
870 } | 876 } |
871 } | 877 } |
872 | 878 |
873 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { | 879 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { |
874 InstantController* instant = controller_->GetInstant(); | 880 InstantController* instant = controller_->GetInstant(); |
875 if (instant) { | 881 if (instant) { |
876 instant->OmniboxFocusChanged(OMNIBOX_FOCUS_NONE, | 882 instant->OmniboxFocusChanged(OMNIBOX_FOCUS_NONE, |
877 OMNIBOX_FOCUS_CHANGE_EXPLICIT, | 883 OMNIBOX_FOCUS_CHANGE_EXPLICIT, |
878 view_gaining_focus); | 884 view_gaining_focus); |
879 } | 885 } |
880 | 886 |
881 // TODO(jered): Rip this out along with StartZeroSuggest. | 887 // TODO(jered): Rip this out along with StartZeroSuggest. |
882 autocomplete_controller()->StopZeroSuggest(); | 888 autocomplete_controller()->StopZeroSuggest(); |
883 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_, | 889 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_, |
884 popup_->IsOpen(), user_text_.empty()); | 890 popup_model()->IsOpen(), user_text_.empty()); |
885 } | 891 } |
886 | 892 |
887 void OmniboxEditModel::OnKillFocus() { | 893 void OmniboxEditModel::OnKillFocus() { |
888 // TODO(samarth): determine if it is safe to move the call to | 894 // TODO(samarth): determine if it is safe to move the call to |
889 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us | 895 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us |
890 // just call SetFocusState() to handle the state change. | 896 // just call SetFocusState() to handle the state change. |
891 focus_state_ = OMNIBOX_FOCUS_NONE; | 897 focus_state_ = OMNIBOX_FOCUS_NONE; |
892 control_key_state_ = UP; | 898 control_key_state_ = UP; |
893 paste_state_ = NONE; | 899 paste_state_ = NONE; |
894 } | 900 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP; | 943 control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP; |
938 if ((control_key_state_ == DOWN_WITHOUT_CHANGE) && has_temporary_text_) { | 944 if ((control_key_state_ == DOWN_WITHOUT_CHANGE) && has_temporary_text_) { |
939 // Arrowing down and then hitting control accepts the temporary text as | 945 // Arrowing down and then hitting control accepts the temporary text as |
940 // the input text. | 946 // the input text. |
941 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); | 947 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); |
942 has_temporary_text_ = false; | 948 has_temporary_text_ = false; |
943 is_temporary_text_set_by_instant_ = false; | 949 is_temporary_text_set_by_instant_ = false; |
944 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; | 950 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; |
945 is_instant_temporary_text_a_search_query_ = false; | 951 is_instant_temporary_text_a_search_query_ = false; |
946 } | 952 } |
947 if ((old_state != DOWN_WITH_CHANGE) && popup_->IsOpen()) { | 953 if ((old_state != DOWN_WITH_CHANGE) && popup_model()->IsOpen()) { |
948 // Autocomplete history provider results may change, so refresh the | 954 // Autocomplete history provider results may change, so refresh the |
949 // popup. This will force user_input_in_progress_ to true, but if the | 955 // popup. This will force user_input_in_progress_ to true, but if the |
950 // popup is open, that should have already been the case. | 956 // popup is open, that should have already been the case. |
951 view_->UpdatePopup(); | 957 view_->UpdatePopup(); |
952 } | 958 } |
953 } | 959 } |
954 } | 960 } |
955 | 961 |
956 void OmniboxEditModel::OnUpOrDownKeyPressed(int count) { | 962 void OmniboxEditModel::OnUpOrDownKeyPressed(int count) { |
957 // NOTE: This purposefully doesn't trigger any code that resets paste_state_. | 963 // NOTE: This purposefully doesn't trigger any code that resets paste_state_. |
958 if (!popup_->IsOpen()) { | 964 if (!popup_model()->IsOpen()) { |
959 if (!query_in_progress()) { | 965 if (!query_in_progress()) { |
960 // The popup is neither open nor working on a query already. So, start an | 966 // The popup is neither open nor working on a query already. So, start an |
961 // autocomplete query for the current text. This also sets | 967 // autocomplete query for the current text. This also sets |
962 // user_input_in_progress_ to true, which we want: if the user has started | 968 // user_input_in_progress_ to true, which we want: if the user has started |
963 // to interact with the popup, changing the permanent_text_ shouldn't | 969 // to interact with the popup, changing the permanent_text_ shouldn't |
964 // change the displayed text. | 970 // change the displayed text. |
965 // Note: This does not force the popup to open immediately. | 971 // Note: This does not force the popup to open immediately. |
966 // TODO(pkasting): We should, in fact, force this particular query to open | 972 // TODO(pkasting): We should, in fact, force this particular query to open |
967 // the popup immediately. | 973 // the popup immediately. |
968 if (!user_input_in_progress_) | 974 if (!user_input_in_progress_) |
969 InternalSetUserText(permanent_text_); | 975 InternalSetUserText(permanent_text_); |
970 view_->UpdatePopup(); | 976 view_->UpdatePopup(); |
971 } else { | 977 } else { |
972 // TODO(pkasting): The popup is working on a query but is not open. We | 978 // TODO(pkasting): The popup is working on a query but is not open. We |
973 // should force it to open immediately. | 979 // should force it to open immediately. |
974 } | 980 } |
975 } else { | 981 } else { |
976 InstantController* instant = controller_->GetInstant(); | 982 InstantController* instant = controller_->GetInstant(); |
977 if (instant && instant->OnUpOrDownKeyPressed(count)) { | 983 if (instant && instant->OnUpOrDownKeyPressed(count)) { |
978 // If Instant handles the key press, it's showing a list of suggestions | 984 // If Instant handles the key press, it's showing a list of suggestions |
979 // that it's stepping through. In that case, our popup model is | 985 // that it's stepping through. In that case, our popup model is |
980 // irrelevant, so don't process the key press ourselves. However, do stop | 986 // irrelevant, so don't process the key press ourselves. However, do stop |
981 // the autocomplete system from changing the results. | 987 // the autocomplete system from changing the results. |
982 autocomplete_controller()->Stop(false); | 988 autocomplete_controller()->Stop(false); |
983 } else { | 989 } else { |
984 // The popup is open, so the user should be able to interact with it | 990 // The popup is open, so the user should be able to interact with it |
985 // normally. | 991 // normally. |
986 popup_->Move(count); | 992 popup_model()->Move(count); |
987 } | 993 } |
988 } | 994 } |
989 } | 995 } |
990 | 996 |
991 void OmniboxEditModel::OnPopupDataChanged( | 997 void OmniboxEditModel::OnPopupDataChanged( |
992 const string16& text, | 998 const string16& text, |
993 GURL* destination_for_temporary_text_change, | 999 GURL* destination_for_temporary_text_change, |
994 const string16& keyword, | 1000 const string16& keyword, |
995 bool is_keyword_hint) { | 1001 bool is_keyword_hint) { |
996 // Update keyword/hint-related local state. | 1002 // Update keyword/hint-related local state. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 // Modifying the selection counts as accepting the autocompleted text. | 1104 // Modifying the selection counts as accepting the autocompleted text. |
1099 const bool user_text_changed = | 1105 const bool user_text_changed = |
1100 text_differs || (selection_differs && !inline_autocomplete_text_.empty()); | 1106 text_differs || (selection_differs && !inline_autocomplete_text_.empty()); |
1101 | 1107 |
1102 // If something has changed while the control key is down, prevent | 1108 // If something has changed while the control key is down, prevent |
1103 // "ctrl-enter" until the control key is released. When we do this, we need | 1109 // "ctrl-enter" until the control key is released. When we do this, we need |
1104 // to update the popup if it's open, since the desired_tld will have changed. | 1110 // to update the popup if it's open, since the desired_tld will have changed. |
1105 if ((text_differs || selection_differs) && | 1111 if ((text_differs || selection_differs) && |
1106 (control_key_state_ == DOWN_WITHOUT_CHANGE)) { | 1112 (control_key_state_ == DOWN_WITHOUT_CHANGE)) { |
1107 control_key_state_ = DOWN_WITH_CHANGE; | 1113 control_key_state_ = DOWN_WITH_CHANGE; |
1108 if (!text_differs && !popup_->IsOpen()) | 1114 if (!text_differs && !popup_model()->IsOpen()) |
1109 return false; // Don't open the popup for no reason. | 1115 return false; // Don't open the popup for no reason. |
1110 } else if (!user_text_changed) { | 1116 } else if (!user_text_changed) { |
1111 return false; | 1117 return false; |
1112 } | 1118 } |
1113 | 1119 |
1114 // If the user text has not changed, we do not want to change the model's | 1120 // If the user text has not changed, we do not want to change the model's |
1115 // state associated with the text. Otherwise, we can get surprising behavior | 1121 // state associated with the text. Otherwise, we can get surprising behavior |
1116 // where the autocompleted text unexpectedly reappears, e.g. crbug.com/55983 | 1122 // where the autocompleted text unexpectedly reappears, e.g. crbug.com/55983 |
1117 if (user_text_changed) { | 1123 if (user_text_changed) { |
1118 InternalSetUserText(UserTextFromDisplayText(new_text)); | 1124 InternalSetUserText(UserTextFromDisplayText(new_text)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1164 // determine what keyword, if any, is applicable. | 1170 // determine what keyword, if any, is applicable. |
1165 // | 1171 // |
1166 // If MaybeAcceptKeywordBySpace() accepts the keyword and returns true, that | 1172 // If MaybeAcceptKeywordBySpace() accepts the keyword and returns true, that |
1167 // will have updated our state already, so in that case we don't also return | 1173 // will have updated our state already, so in that case we don't also return |
1168 // true from this function. | 1174 // true from this function. |
1169 return !(text_differs && allow_keyword_ui_change && !just_deleted_text && | 1175 return !(text_differs && allow_keyword_ui_change && !just_deleted_text && |
1170 no_selection && (selection_start == user_text_.length()) && | 1176 no_selection && (selection_start == user_text_.length()) && |
1171 MaybeAcceptKeywordBySpace(user_text_)); | 1177 MaybeAcceptKeywordBySpace(user_text_)); |
1172 } | 1178 } |
1173 | 1179 |
1174 void OmniboxEditModel::OnPopupBoundsChanged(const gfx::Rect& bounds) { | |
1175 InstantController* instant = controller_->GetInstant(); | |
1176 if (instant) | |
1177 instant->SetPopupBounds(bounds); | |
1178 } | |
1179 | |
1180 void OmniboxEditModel::OnResultChanged(bool default_match_changed) { | 1180 void OmniboxEditModel::OnResultChanged(bool default_match_changed) { |
1181 const bool was_open = popup_->IsOpen(); | |
1182 if (default_match_changed) { | |
1183 string16 inline_autocomplete_text; | |
1184 string16 keyword; | |
1185 bool is_keyword_hint = false; | |
1186 const AutocompleteResult& result = this->result(); | |
1187 const AutocompleteResult::const_iterator match(result.default_match()); | |
1188 if (match != result.end()) { | |
1189 if ((match->inline_autocomplete_offset != string16::npos) && | |
1190 (match->inline_autocomplete_offset < | |
1191 match->fill_into_edit.length())) { | |
1192 inline_autocomplete_text = | |
1193 match->fill_into_edit.substr(match->inline_autocomplete_offset); | |
1194 } | |
1195 | |
1196 if (!prerender::IsOmniboxEnabled(profile_)) | |
1197 DoPreconnect(*match); | |
1198 | |
1199 // We could prefetch the alternate nav URL, if any, but because there | |
1200 // can be many of these as a user types an initial series of characters, | |
1201 // the OS DNS cache could suffer eviction problems for minimal gain. | |
1202 | |
1203 match->GetKeywordUIState(profile_, &keyword, &is_keyword_hint); | |
1204 } | |
1205 | |
1206 popup_->OnResultChanged(); | |
1207 OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, | |
1208 is_keyword_hint); | |
1209 } else { | |
1210 popup_->OnResultChanged(); | |
1211 } | |
1212 | |
1213 if (popup_->IsOpen()) { | |
1214 OnPopupBoundsChanged(popup_->view()->GetTargetBounds()); | |
1215 | |
1216 InstantController* instant = controller_->GetInstant(); | |
1217 if (instant && !in_revert_) { | |
1218 instant->HandleAutocompleteResults( | |
1219 *autocomplete_controller()->providers(), | |
1220 autocomplete_controller()->result()); | |
1221 } | |
1222 } else if (was_open) { | |
1223 // Accepts the temporary text as the user text, because it makes little | |
1224 // sense to have temporary text when the popup is closed. | |
1225 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); | |
1226 has_temporary_text_ = false; | |
1227 is_temporary_text_set_by_instant_ = false; | |
1228 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; | |
1229 is_instant_temporary_text_a_search_query_ = false; | |
1230 OnPopupBoundsChanged(gfx::Rect()); | |
1231 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_, | |
1232 popup_->IsOpen(), user_text_.empty()); | |
1233 } | |
1234 } | 1181 } |
1235 | 1182 |
1236 bool OmniboxEditModel::query_in_progress() const { | 1183 bool OmniboxEditModel::query_in_progress() const { |
1237 return !autocomplete_controller()->done(); | 1184 return !autocomplete_controller()->done(); |
1238 } | 1185 } |
1239 | 1186 |
1240 void OmniboxEditModel::InternalSetUserText(const string16& text) { | 1187 void OmniboxEditModel::InternalSetUserText(const string16& text) { |
1241 user_text_ = text; | 1188 user_text_ = text; |
1242 just_deleted_text_ = false; | 1189 just_deleted_text_ = false; |
1243 inline_autocomplete_text_.clear(); | 1190 inline_autocomplete_text_.clear(); |
1244 } | 1191 } |
1245 | 1192 |
1246 bool OmniboxEditModel::KeywordIsSelected() const { | 1193 bool OmniboxEditModel::KeywordIsSelected() const { |
1247 return !is_keyword_hint_ && !keyword_.empty(); | 1194 return !is_keyword_hint_ && !keyword_.empty(); |
1248 } | 1195 } |
1249 | 1196 |
1250 void OmniboxEditModel::ClearPopupKeywordMode() const { | |
1251 if (popup_->IsOpen() && | |
1252 popup_->selected_line_state() == OmniboxPopupModel::KEYWORD) | |
1253 popup_->SetSelectedLineState(OmniboxPopupModel::NORMAL); | |
1254 } | |
1255 | |
1256 string16 OmniboxEditModel::DisplayTextFromUserText(const string16& text) const { | 1197 string16 OmniboxEditModel::DisplayTextFromUserText(const string16& text) const { |
1257 return KeywordIsSelected() ? | 1198 return KeywordIsSelected() ? |
1258 KeywordProvider::SplitReplacementStringFromInput(text, false) : text; | 1199 KeywordProvider::SplitReplacementStringFromInput(text, false) : text; |
1259 } | 1200 } |
1260 | 1201 |
1261 string16 OmniboxEditModel::UserTextFromDisplayText(const string16& text) const { | 1202 string16 OmniboxEditModel::UserTextFromDisplayText(const string16& text) const { |
1262 return KeywordIsSelected() ? (keyword_ + char16(' ') + text) : text; | 1203 return KeywordIsSelected() ? (keyword_ + char16(' ') + text) : text; |
1263 } | 1204 } |
1264 | 1205 |
1265 void OmniboxEditModel::GetInfoForCurrentText(AutocompleteMatch* match, | 1206 void OmniboxEditModel::GetInfoForCurrentText(AutocompleteMatch* match, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 // |is_temporary_text_set_by_instant_|, so we still shouldn't get | 1264 // |is_temporary_text_set_by_instant_|, so we still shouldn't get |
1324 // here. However, as protection against the unknowns and Instant | 1265 // here. However, as protection against the unknowns and Instant |
1325 // regressions, we simply return an invalid match instead of crashing | 1266 // regressions, we simply return an invalid match instead of crashing |
1326 // (hence no DCHECK). | 1267 // (hence no DCHECK). |
1327 } | 1268 } |
1328 } else { | 1269 } else { |
1329 *match = HistoryURLProvider::SuggestExactInput( | 1270 *match = HistoryURLProvider::SuggestExactInput( |
1330 autocomplete_controller()->history_url_provider(), input, false); | 1271 autocomplete_controller()->history_url_provider(), input, false); |
1331 } | 1272 } |
1332 } | 1273 } |
1333 } else if (popup_->IsOpen() || query_in_progress()) { | 1274 } else if (popup_model()->IsOpen() || query_in_progress()) { |
1334 if (query_in_progress()) { | 1275 if (query_in_progress()) { |
1335 // It's technically possible for |result| to be empty if no provider | 1276 // It's technically possible for |result| to be empty if no provider |
1336 // returns a synchronous result but the query has not completed | 1277 // returns a synchronous result but the query has not completed |
1337 // synchronously; pratically, however, that should never actually happen. | 1278 // synchronously; pratically, however, that should never actually happen. |
1338 if (result().empty()) | 1279 if (result().empty()) |
1339 return; | 1280 return; |
1340 // The user cannot have manually selected a match, or the query would have | 1281 // The user cannot have manually selected a match, or the query would have |
1341 // stopped. So the default match must be the desired selection. | 1282 // stopped. So the default match must be the desired selection. |
1342 *match = *result().default_match(); | 1283 *match = *result().default_match(); |
1343 } else { | 1284 } else { |
1344 // If there are no results, the popup should be closed, so we shouldn't | 1285 // If there are no results, the popup should be closed, so we shouldn't |
1345 // have gotten here. | 1286 // have gotten here. |
1346 CHECK(!result().empty()); | 1287 CHECK(!result().empty()); |
1347 CHECK(popup_->selected_line() < result().size()); | 1288 CHECK(popup_model()->selected_line() < result().size()); |
1348 *match = result().match_at(popup_->selected_line()); | 1289 *match = result().match_at(popup_model()->selected_line()); |
1349 } | 1290 } |
1350 if (alternate_nav_url && popup_->manually_selected_match().empty()) | 1291 if (alternate_nav_url && popup_model()->manually_selected_match().empty()) |
1351 *alternate_nav_url = result().alternate_nav_url(); | 1292 *alternate_nav_url = result().alternate_nav_url(); |
1352 } else { | 1293 } else { |
1353 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify( | 1294 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify( |
1354 UserTextFromDisplayText(view_->GetText()), KeywordIsSelected(), true, | 1295 UserTextFromDisplayText(view_->GetText()), KeywordIsSelected(), true, |
1355 match, alternate_nav_url); | 1296 match, alternate_nav_url); |
1356 } | 1297 } |
1357 } | 1298 } |
1358 | 1299 |
1359 void OmniboxEditModel::RevertTemporaryText(bool revert_popup) { | 1300 void OmniboxEditModel::RevertTemporaryText(bool revert_popup) { |
1360 // The user typed something, then selected a different item. Restore the | 1301 // The user typed something, then selected a different item. Restore the |
(...skipping 18 matching lines...) Expand all Loading... |
1379 // The two "false" arguments make sure that our shenanigans don't cause any | 1320 // The two "false" arguments make sure that our shenanigans don't cause any |
1380 // previously saved selection to be erased nor OnChanged() to be called. | 1321 // previously saved selection to be erased nor OnChanged() to be called. |
1381 view_->OnTemporaryTextMaybeChanged(user_text_ + inline_autocomplete_text_, | 1322 view_->OnTemporaryTextMaybeChanged(user_text_ + inline_autocomplete_text_, |
1382 false, false); | 1323 false, false); |
1383 AutocompleteResult::const_iterator match(result().default_match()); | 1324 AutocompleteResult::const_iterator match(result().default_match()); |
1384 instant->OnCancel(match != result().end() ? *match : AutocompleteMatch(), | 1325 instant->OnCancel(match != result().end() ? *match : AutocompleteMatch(), |
1385 user_text_, | 1326 user_text_, |
1386 user_text_ + inline_autocomplete_text_); | 1327 user_text_ + inline_autocomplete_text_); |
1387 } | 1328 } |
1388 if (revert_popup) | 1329 if (revert_popup) |
1389 popup_->ResetToDefaultMatch(); | 1330 popup_model()->ResetToDefaultMatch(); |
1390 view_->OnRevertTemporaryText(); | 1331 view_->OnRevertTemporaryText(); |
1391 } | 1332 } |
1392 | 1333 |
1393 bool OmniboxEditModel::MaybeAcceptKeywordBySpace(const string16& new_text) { | 1334 bool OmniboxEditModel::MaybeAcceptKeywordBySpace(const string16& new_text) { |
1394 size_t keyword_length = new_text.length() - 1; | 1335 size_t keyword_length = new_text.length() - 1; |
1395 return (paste_state_ == NONE) && is_keyword_hint_ && !keyword_.empty() && | 1336 return (paste_state_ == NONE) && is_keyword_hint_ && !keyword_.empty() && |
1396 inline_autocomplete_text_.empty() && | 1337 inline_autocomplete_text_.empty() && |
1397 (keyword_.length() == keyword_length) && | 1338 (keyword_.length() == keyword_length) && |
1398 IsSpaceCharForAcceptingKeyword(new_text[keyword_length]) && | 1339 IsSpaceCharForAcceptingKeyword(new_text[keyword_length]) && |
1399 !new_text.compare(0, keyword_length, keyword_, 0, keyword_length) && | 1340 !new_text.compare(0, keyword_length, keyword_, 0, keyword_length) && |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1450 // Remove "?" if we're in forced query mode. | 1391 // Remove "?" if we're in forced query mode. |
1451 AutocompleteInput::RemoveForcedQueryStringIfNecessary( | 1392 AutocompleteInput::RemoveForcedQueryStringIfNecessary( |
1452 autocomplete_controller()->input().type(), &user_text); | 1393 autocomplete_controller()->input().type(), &user_text); |
1453 AutocompleteInput::RemoveForcedQueryStringIfNecessary( | 1394 AutocompleteInput::RemoveForcedQueryStringIfNecessary( |
1454 autocomplete_controller()->input().type(), &full_text); | 1395 autocomplete_controller()->input().type(), &full_text); |
1455 | 1396 |
1456 size_t start, end; | 1397 size_t start, end; |
1457 view_->GetSelectionBounds(&start, &end); | 1398 view_->GetSelectionBounds(&start, &end); |
1458 | 1399 |
1459 return instant->Update(match, user_text, full_text, start, end, | 1400 return instant->Update(match, user_text, full_text, start, end, |
1460 UseVerbatimInstant(), user_input_in_progress_, popup_->IsOpen(), | 1401 UseVerbatimInstant(), user_input_in_progress_, popup_model()->IsOpen(), |
1461 in_escape_handler_, KeywordIsSelected()); | 1402 in_escape_handler_, KeywordIsSelected()); |
1462 } | 1403 } |
1463 | 1404 |
1464 void OmniboxEditModel::DoPreconnect(const AutocompleteMatch& match) { | |
1465 if (!match.destination_url.SchemeIs(extensions::kExtensionScheme)) { | |
1466 // Warm up DNS Prefetch cache, or preconnect to a search service. | |
1467 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type, | |
1468 AutocompleteMatchType::NUM_TYPES); | |
1469 if (profile_->GetNetworkPredictor()) { | |
1470 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( | |
1471 match.destination_url, | |
1472 AutocompleteActionPredictor::IsPreconnectable(match)); | |
1473 } | |
1474 // We could prefetch the alternate nav URL, if any, but because there | |
1475 // can be many of these as a user types an initial series of characters, | |
1476 // the OS DNS cache could suffer eviction problems for minimal gain. | |
1477 } | |
1478 } | |
1479 | |
1480 // static | 1405 // static |
1481 bool OmniboxEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { | 1406 bool OmniboxEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { |
1482 switch (c) { | 1407 switch (c) { |
1483 case 0x0020: // Space | 1408 case 0x0020: // Space |
1484 case 0x3000: // Ideographic Space | 1409 case 0x3000: // Ideographic Space |
1485 return true; | 1410 return true; |
1486 default: | 1411 default: |
1487 return false; | 1412 return false; |
1488 } | 1413 } |
1489 } | 1414 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 instant->OmniboxFocusChanged(state, reason, NULL); | 1446 instant->OmniboxFocusChanged(state, reason, NULL); |
1522 | 1447 |
1523 // Update state and notify view if the omnibox has focus and the caret | 1448 // Update state and notify view if the omnibox has focus and the caret |
1524 // visibility changed. | 1449 // visibility changed. |
1525 const bool was_caret_visible = is_caret_visible(); | 1450 const bool was_caret_visible = is_caret_visible(); |
1526 focus_state_ = state; | 1451 focus_state_ = state; |
1527 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1452 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
1528 is_caret_visible() != was_caret_visible) | 1453 is_caret_visible() != was_caret_visible) |
1529 view_->ApplyCaretVisibility(); | 1454 view_->ApplyCaretVisibility(); |
1530 } | 1455 } |
OLD | NEW |