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) { |
251 switch (suggestion.behavior) { | 250 switch (suggestion.behavior) { |
252 case INSTANT_COMPLETE_NOW: | 251 case INSTANT_COMPLETE_NOW: |
253 view_->SetInstantSuggestion(string16()); | 252 view_->SetInstantSuggestion(string16()); |
254 if (!suggestion.text.empty()) | 253 if (!suggestion.text.empty()) |
255 FinalizeInstantQuery(view_->GetText(), suggestion, false); | 254 FinalizeInstantQuery(view_->GetText(), suggestion, false); |
256 break; | 255 break; |
257 | 256 |
258 case INSTANT_COMPLETE_NEVER: { | 257 case INSTANT_COMPLETE_NEVER: { |
259 DCHECK_EQ(INSTANT_SUGGESTION_SEARCH, suggestion.type); | 258 DCHECK_EQ(INSTANT_SUGGESTION_SEARCH, suggestion.type); |
260 view_->SetInstantSuggestion(suggestion.text); | 259 view_->SetInstantSuggestion(suggestion.text); |
261 autocomplete_controller()->search_provider()->ClearInstantSuggestion(); | 260 SearchProvider* search_provider = |
261 autocomplete_controller()->search_provider(); | |
262 if (search_provider) | |
263 search_provider->ClearInstantSuggestion(); | |
sreeram
2013/05/22 15:33:45
Why put back the check? I took it purposefully, be
beaudoin
2013/05/22 17:06:00
Probably a merge mistake.
Done.
| |
262 break; | 264 break; |
263 } | 265 } |
264 | 266 |
265 case INSTANT_COMPLETE_REPLACE: { | 267 case INSTANT_COMPLETE_REPLACE: { |
266 const bool save_original_selection = !has_temporary_text_; | 268 const bool save_original_selection = !has_temporary_text_; |
267 view_->SetInstantSuggestion(string16()); | 269 view_->SetInstantSuggestion(string16()); |
268 has_temporary_text_ = true; | 270 has_temporary_text_ = true; |
269 is_temporary_text_set_by_instant_ = true; | 271 is_temporary_text_set_by_instant_ = true; |
270 selected_instant_autocomplete_match_index_ = | 272 selected_instant_autocomplete_match_index_ = |
271 suggestion.autocomplete_match_index; | 273 suggestion.autocomplete_match_index; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 // has been closed or on return from a sleep state. | 344 // has been closed or on return from a sleep state. |
343 // (http://crbug.com/105689) | 345 // (http://crbug.com/105689) |
344 if (!delegate_->CurrentPageExists()) | 346 if (!delegate_->CurrentPageExists()) |
345 break; | 347 break; |
346 // Ask for prerendering if the destination URL is different than the | 348 // Ask for prerendering if the destination URL is different than the |
347 // current URL. | 349 // current URL. |
348 if (current_match.destination_url != PermanentURL()) | 350 if (current_match.destination_url != PermanentURL()) |
349 delegate_->DoPrerender(current_match); | 351 delegate_->DoPrerender(current_match); |
350 break; | 352 break; |
351 case AutocompleteActionPredictor::ACTION_PRECONNECT: | 353 case AutocompleteActionPredictor::ACTION_PRECONNECT: |
352 DoPreconnect(current_match); | 354 omnibox_controller_->DoPreconnect(current_match); |
353 break; | 355 break; |
354 case AutocompleteActionPredictor::ACTION_NONE: | 356 case AutocompleteActionPredictor::ACTION_NONE: |
355 break; | 357 break; |
356 } | 358 } |
357 | 359 |
358 controller_->OnChanged(); | 360 controller_->OnChanged(); |
359 } | 361 } |
360 | 362 |
361 void OmniboxEditModel::GetDataForURLExport(GURL* url, | 363 void OmniboxEditModel::GetDataForURLExport(GURL* url, |
362 string16* title, | 364 string16* title, |
(...skipping 18 matching lines...) Expand all Loading... | |
381 #endif | 383 #endif |
382 | 384 |
383 // The value of input.prevent_inline_autocomplete() is determined by the | 385 // The value of input.prevent_inline_autocomplete() is determined by the |
384 // following conditions: | 386 // following conditions: |
385 // 1. If the caret is at the end of the text. | 387 // 1. If the caret is at the end of the text. |
386 // 2. If it's in IME composition mode. | 388 // 2. If it's in IME composition mode. |
387 // We send the caret position to Instant (so it can determine #1 itself), and | 389 // 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 | 390 // 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 | 391 // interfere with #2). So, we don't need to care about the value of |
390 // input.prevent_inline_autocomplete() here. | 392 // input.prevent_inline_autocomplete() here. |
391 return view_->DeleteAtEndPressed() || popup_->selected_line() != 0 || | 393 return view_->DeleteAtEndPressed() || popup_model()->selected_line() != 0 || |
392 just_deleted_text_; | 394 just_deleted_text_; |
393 } | 395 } |
394 | 396 |
395 bool OmniboxEditModel::CurrentTextIsURL() const { | 397 bool OmniboxEditModel::CurrentTextIsURL() const { |
396 if (view_->toolbar_model()->GetSearchTermsType() != | 398 if (view_->toolbar_model()->GetSearchTermsType() != |
397 ToolbarModel::NO_SEARCH_TERMS) | 399 ToolbarModel::NO_SEARCH_TERMS) |
398 return false; | 400 return false; |
399 | 401 |
400 // If current text is not composed of replaced search terms and | 402 // 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 | 403 // !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 | 473 |
472 user_input_in_progress_ = in_progress; | 474 user_input_in_progress_ = in_progress; |
473 if (user_input_in_progress_) { | 475 if (user_input_in_progress_) { |
474 time_user_first_modified_omnibox_ = base::TimeTicks::Now(); | 476 time_user_first_modified_omnibox_ = base::TimeTicks::Now(); |
475 content::RecordAction(content::UserMetricsAction("OmniboxInputInProgress")); | 477 content::RecordAction(content::UserMetricsAction("OmniboxInputInProgress")); |
476 autocomplete_controller()->ResetSession(); | 478 autocomplete_controller()->ResetSession(); |
477 } | 479 } |
478 controller_->OnInputInProgress(in_progress); | 480 controller_->OnInputInProgress(in_progress); |
479 | 481 |
480 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_, | 482 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_, |
481 popup_->IsOpen(), user_text_.empty()); | 483 popup_model()->IsOpen(), user_text_.empty()); |
482 } | 484 } |
483 | 485 |
484 void OmniboxEditModel::Revert() { | 486 void OmniboxEditModel::Revert() { |
485 SetInputInProgress(false); | 487 SetInputInProgress(false); |
486 paste_state_ = NONE; | 488 paste_state_ = NONE; |
487 InternalSetUserText(string16()); | 489 InternalSetUserText(string16()); |
488 keyword_.clear(); | 490 keyword_.clear(); |
489 is_keyword_hint_ = false; | 491 is_keyword_hint_ = false; |
490 has_temporary_text_ = false; | 492 has_temporary_text_ = false; |
491 is_temporary_text_set_by_instant_ = false; | 493 is_temporary_text_set_by_instant_ = false; |
492 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; | 494 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; |
493 is_instant_temporary_text_a_search_query_ = false; | 495 is_instant_temporary_text_a_search_query_ = false; |
494 view_->SetWindowTextAndCaretPos(permanent_text_, | 496 view_->SetWindowTextAndCaretPos(permanent_text_, |
495 has_focus() ? permanent_text_.length() : 0, | 497 has_focus() ? permanent_text_.length() : 0, |
496 false, true); | 498 false, true); |
497 AutocompleteActionPredictor* action_predictor = | 499 AutocompleteActionPredictor* action_predictor = |
498 AutocompleteActionPredictorFactory::GetForProfile(profile_); | 500 AutocompleteActionPredictorFactory::GetForProfile(profile_); |
499 if (action_predictor) | 501 if (action_predictor) |
500 action_predictor->ClearTransitionalMatches(); | 502 action_predictor->ClearTransitionalMatches(); |
501 } | 503 } |
502 | 504 |
503 void OmniboxEditModel::StartAutocomplete( | 505 void OmniboxEditModel::StartAutocomplete( |
504 bool has_selected_text, | 506 bool has_selected_text, |
505 bool prevent_inline_autocomplete) const { | 507 bool prevent_inline_autocomplete) const { |
506 ClearPopupKeywordMode(); | 508 omnibox_controller_->ClearPopupKeywordMode(); |
507 | 509 |
508 bool keyword_is_selected = KeywordIsSelected(); | 510 bool keyword_is_selected = KeywordIsSelected(); |
509 popup_->SetHoveredLine(OmniboxPopupModel::kNoMatch); | 511 popup_model()->SetHoveredLine(OmniboxPopupModel::kNoMatch); |
510 | 512 |
511 size_t cursor_position; | 513 size_t cursor_position; |
512 if (inline_autocomplete_text_.empty()) { | 514 if (inline_autocomplete_text_.empty()) { |
513 // Cursor position is equivalent to the current selection's end. | 515 // Cursor position is equivalent to the current selection's end. |
514 size_t start; | 516 size_t start; |
515 view_->GetSelectionBounds(&start, &cursor_position); | 517 view_->GetSelectionBounds(&start, &cursor_position); |
516 // Adjust cursor position taking into account possible keyword in the user | 518 // Adjust cursor position taking into account possible keyword in the user |
517 // text. We rely on DisplayTextFromUserText() method which is consistent | 519 // text. We rely on DisplayTextFromUserText() method which is consistent |
518 // with keyword extraction done in KeywordProvider/SearchProvider. | 520 // with keyword extraction done in KeywordProvider/SearchProvider. |
519 const size_t cursor_offset = | 521 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, | 656 view_->OpenMatch(match, disposition, alternate_nav_url, |
655 OmniboxPopupModel::kNoMatch); | 657 OmniboxPopupModel::kNoMatch); |
656 } | 658 } |
657 | 659 |
658 void OmniboxEditModel::OpenMatch(const AutocompleteMatch& match, | 660 void OmniboxEditModel::OpenMatch(const AutocompleteMatch& match, |
659 WindowOpenDisposition disposition, | 661 WindowOpenDisposition disposition, |
660 const GURL& alternate_nav_url, | 662 const GURL& alternate_nav_url, |
661 size_t index) { | 663 size_t index) { |
662 // We only care about cases where there is a selection (i.e. the popup is | 664 // We only care about cases where there is a selection (i.e. the popup is |
663 // open). | 665 // open). |
664 if (popup_->IsOpen()) { | 666 if (popup_model()->IsOpen()) { |
665 const base::TimeTicks& now(base::TimeTicks::Now()); | 667 const base::TimeTicks& now(base::TimeTicks::Now()); |
666 // TODO(sreeram): Handle is_temporary_text_set_by_instant_ correctly. | 668 // TODO(sreeram): Handle is_temporary_text_set_by_instant_ correctly. |
667 AutocompleteLog log( | 669 AutocompleteLog log( |
668 autocomplete_controller()->input().text(), | 670 autocomplete_controller()->input().text(), |
669 just_deleted_text_, | 671 just_deleted_text_, |
670 autocomplete_controller()->input().type(), | 672 autocomplete_controller()->input().type(), |
671 popup_->selected_line(), | 673 popup_model()->selected_line(), |
672 -1, // don't yet know tab ID; set later if appropriate | 674 -1, // don't yet know tab ID; set later if appropriate |
673 delegate_->CurrentPageExists() ? ClassifyPage(delegate_->GetURL()) : | 675 delegate_->CurrentPageExists() ? ClassifyPage(delegate_->GetURL()) : |
674 metrics::OmniboxEventProto_PageClassification_OTHER, | 676 metrics::OmniboxEventProto_PageClassification_OTHER, |
675 now - time_user_first_modified_omnibox_, | 677 now - time_user_first_modified_omnibox_, |
676 string16::npos, // completed_length; possibly set later | 678 string16::npos, // completed_length; possibly set later |
677 now - autocomplete_controller()->last_time_default_match_changed(), | 679 now - autocomplete_controller()->last_time_default_match_changed(), |
678 result()); | 680 result()); |
679 DCHECK(user_input_in_progress_ || | 681 DCHECK(user_input_in_progress_ || |
680 match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST) | 682 match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST) |
681 << "We didn't get here through the expected series of calls. " | 683 << "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) | 782 if (match.starred) |
781 bookmark_utils::RecordBookmarkLaunch(bookmark_utils::LAUNCH_OMNIBOX); | 783 bookmark_utils::RecordBookmarkLaunch(bookmark_utils::LAUNCH_OMNIBOX); |
782 } | 784 } |
783 | 785 |
784 bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) { | 786 bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) { |
785 DCHECK(is_keyword_hint_ && !keyword_.empty()); | 787 DCHECK(is_keyword_hint_ && !keyword_.empty()); |
786 | 788 |
787 autocomplete_controller()->Stop(false); | 789 autocomplete_controller()->Stop(false); |
788 is_keyword_hint_ = false; | 790 is_keyword_hint_ = false; |
789 | 791 |
790 if (popup_->IsOpen()) | 792 if (popup_model()->IsOpen()) |
791 popup_->SetSelectedLineState(OmniboxPopupModel::KEYWORD); | 793 popup_model()->SetSelectedLineState(OmniboxPopupModel::KEYWORD); |
792 else | 794 else |
793 StartAutocomplete(false, true); | 795 StartAutocomplete(false, true); |
794 | 796 |
795 // Ensure the current selection is saved before showing keyword mode | 797 // Ensure the current selection is saved before showing keyword mode |
796 // so that moving to another line and then reverting the text will restore | 798 // so that moving to another line and then reverting the text will restore |
797 // the current state properly. | 799 // the current state properly. |
798 bool save_original_selection = !has_temporary_text_; | 800 bool save_original_selection = !has_temporary_text_; |
799 has_temporary_text_ = true; | 801 has_temporary_text_ = true; |
800 is_temporary_text_set_by_instant_ = false; | 802 is_temporary_text_set_by_instant_ = false; |
801 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; | 803 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; |
802 is_instant_temporary_text_a_search_query_ = false; | 804 is_instant_temporary_text_a_search_query_ = false; |
803 view_->OnTemporaryTextMaybeChanged( | 805 view_->OnTemporaryTextMaybeChanged( |
804 DisplayTextFromUserText(CurrentMatch().fill_into_edit), | 806 DisplayTextFromUserText(CurrentMatch().fill_into_edit), |
805 save_original_selection, true); | 807 save_original_selection, true); |
806 | 808 |
807 content::RecordAction(UserMetricsAction("AcceptedKeywordHint")); | 809 content::RecordAction(UserMetricsAction("AcceptedKeywordHint")); |
808 UMA_HISTOGRAM_ENUMERATION(kEnteredKeywordModeHistogram, entered_method, | 810 UMA_HISTOGRAM_ENUMERATION(kEnteredKeywordModeHistogram, entered_method, |
809 ENTERED_KEYWORD_MODE_NUM_ITEMS); | 811 ENTERED_KEYWORD_MODE_NUM_ITEMS); |
810 | 812 |
811 return true; | 813 return true; |
812 } | 814 } |
813 | 815 |
816 void OmniboxEditModel::AcceptTemporaryTextAsUserText() { | |
817 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); | |
818 has_temporary_text_ = false; | |
819 is_temporary_text_set_by_instant_ = false; | |
820 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; | |
821 is_instant_temporary_text_a_search_query_ = false; | |
822 OnPopupBoundsChanged(gfx::Rect()); | |
823 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_, | |
824 popup_model()->IsOpen(), user_text_.empty()); | |
825 } | |
826 | |
814 void OmniboxEditModel::ClearKeyword(const string16& visible_text) { | 827 void OmniboxEditModel::ClearKeyword(const string16& visible_text) { |
815 autocomplete_controller()->Stop(false); | 828 autocomplete_controller()->Stop(false); |
816 ClearPopupKeywordMode(); | 829 omnibox_controller_->ClearPopupKeywordMode(); |
817 | 830 |
818 const string16 window_text(keyword_ + visible_text); | 831 const string16 window_text(keyword_ + visible_text); |
819 | 832 |
820 // Only reset the result if the edit text has changed since the | 833 // Only reset the result if the edit text has changed since the |
821 // keyword was accepted, or if the popup is closed. | 834 // keyword was accepted, or if the popup is closed. |
822 if (just_deleted_text_ || !visible_text.empty() || !popup_->IsOpen()) { | 835 if (just_deleted_text_ || !visible_text.empty() || !popup_model()->IsOpen()) { |
823 view_->OnBeforePossibleChange(); | 836 view_->OnBeforePossibleChange(); |
824 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length(), | 837 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length(), |
825 false, false); | 838 false, false); |
826 keyword_.clear(); | 839 keyword_.clear(); |
827 is_keyword_hint_ = false; | 840 is_keyword_hint_ = false; |
828 view_->OnAfterPossibleChange(); | 841 view_->OnAfterPossibleChange(); |
829 just_deleted_text_ = true; // OnAfterPossibleChange() fails to clear this | 842 just_deleted_text_ = true; // OnAfterPossibleChange() fails to clear this |
830 // since the edit contents have actually grown | 843 // since the edit contents have actually grown |
831 // longer. | 844 // longer. |
832 } else { | 845 } else { |
833 is_keyword_hint_ = true; | 846 is_keyword_hint_ = true; |
834 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length(), | 847 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length(), |
835 false, true); | 848 false, true); |
836 } | 849 } |
837 } | 850 } |
838 | 851 |
839 const AutocompleteResult& OmniboxEditModel::result() const { | |
840 return autocomplete_controller()->result(); | |
841 } | |
842 | |
843 void OmniboxEditModel::OnSetFocus(bool control_down) { | 852 void OmniboxEditModel::OnSetFocus(bool control_down) { |
844 // If the omnibox lost focus while the caret was hidden and then regained | 853 // If the omnibox lost focus while the caret was hidden and then regained |
845 // focus, OnSetFocus() is called and should restore visibility. Note that | 854 // focus, OnSetFocus() is called and should restore visibility. Note that |
846 // focus can be regained without an accompanying call to | 855 // focus can be regained without an accompanying call to |
847 // OmniboxView::SetFocus(), e.g. by tabbing in. | 856 // OmniboxView::SetFocus(), e.g. by tabbing in. |
848 SetFocusState(OMNIBOX_FOCUS_VISIBLE, OMNIBOX_FOCUS_CHANGE_EXPLICIT); | 857 SetFocusState(OMNIBOX_FOCUS_VISIBLE, OMNIBOX_FOCUS_CHANGE_EXPLICIT); |
849 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; | 858 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; |
850 | 859 |
851 if (delegate_->CurrentPageExists()) { | 860 if (delegate_->CurrentPageExists()) { |
852 // TODO(jered): We may want to merge this into Start() and just call that | 861 // 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 | 862 // 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 | 863 // 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 | 864 // the actual underlying current URL, e.g. if we're on the NTP and the |
856 // |permanent_text_| is empty. | 865 // |permanent_text_| is empty. |
857 autocomplete_controller()->StartZeroSuggest(delegate_->GetURL(), | 866 autocomplete_controller()->StartZeroSuggest(delegate_->GetURL(), |
858 user_text_); | 867 user_text_); |
859 } | 868 } |
860 | 869 |
861 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_, | 870 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_, |
862 popup_->IsOpen(), user_text_.empty()); | 871 popup_model()->IsOpen(), user_text_.empty()); |
863 } | 872 } |
864 | 873 |
865 void OmniboxEditModel::SetCaretVisibility(bool visible) { | 874 void OmniboxEditModel::SetCaretVisibility(bool visible) { |
866 // Caret visibility only matters if the omnibox has focus. | 875 // Caret visibility only matters if the omnibox has focus. |
867 if (focus_state_ != OMNIBOX_FOCUS_NONE) { | 876 if (focus_state_ != OMNIBOX_FOCUS_NONE) { |
868 SetFocusState(visible ? OMNIBOX_FOCUS_VISIBLE : OMNIBOX_FOCUS_INVISIBLE, | 877 SetFocusState(visible ? OMNIBOX_FOCUS_VISIBLE : OMNIBOX_FOCUS_INVISIBLE, |
869 OMNIBOX_FOCUS_CHANGE_EXPLICIT); | 878 OMNIBOX_FOCUS_CHANGE_EXPLICIT); |
870 } | 879 } |
871 } | 880 } |
872 | 881 |
873 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { | 882 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { |
874 InstantController* instant = controller_->GetInstant(); | 883 InstantController* instant = controller_->GetInstant(); |
875 if (instant) { | 884 if (instant) { |
876 instant->OmniboxFocusChanged(OMNIBOX_FOCUS_NONE, | 885 instant->OmniboxFocusChanged(OMNIBOX_FOCUS_NONE, |
877 OMNIBOX_FOCUS_CHANGE_EXPLICIT, | 886 OMNIBOX_FOCUS_CHANGE_EXPLICIT, |
878 view_gaining_focus); | 887 view_gaining_focus); |
879 } | 888 } |
880 | 889 |
881 // TODO(jered): Rip this out along with StartZeroSuggest. | 890 // TODO(jered): Rip this out along with StartZeroSuggest. |
882 autocomplete_controller()->StopZeroSuggest(); | 891 autocomplete_controller()->StopZeroSuggest(); |
883 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_, | 892 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_, |
884 popup_->IsOpen(), user_text_.empty()); | 893 popup_model()->IsOpen(), user_text_.empty()); |
885 } | 894 } |
886 | 895 |
887 void OmniboxEditModel::OnKillFocus() { | 896 void OmniboxEditModel::OnKillFocus() { |
888 // TODO(samarth): determine if it is safe to move the call to | 897 // TODO(samarth): determine if it is safe to move the call to |
889 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us | 898 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us |
890 // just call SetFocusState() to handle the state change. | 899 // just call SetFocusState() to handle the state change. |
891 focus_state_ = OMNIBOX_FOCUS_NONE; | 900 focus_state_ = OMNIBOX_FOCUS_NONE; |
892 control_key_state_ = UP; | 901 control_key_state_ = UP; |
893 paste_state_ = NONE; | 902 paste_state_ = NONE; |
894 } | 903 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
937 control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP; | 946 control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP; |
938 if ((control_key_state_ == DOWN_WITHOUT_CHANGE) && has_temporary_text_) { | 947 if ((control_key_state_ == DOWN_WITHOUT_CHANGE) && has_temporary_text_) { |
939 // Arrowing down and then hitting control accepts the temporary text as | 948 // Arrowing down and then hitting control accepts the temporary text as |
940 // the input text. | 949 // the input text. |
941 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); | 950 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); |
942 has_temporary_text_ = false; | 951 has_temporary_text_ = false; |
943 is_temporary_text_set_by_instant_ = false; | 952 is_temporary_text_set_by_instant_ = false; |
944 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; | 953 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; |
945 is_instant_temporary_text_a_search_query_ = false; | 954 is_instant_temporary_text_a_search_query_ = false; |
946 } | 955 } |
947 if ((old_state != DOWN_WITH_CHANGE) && popup_->IsOpen()) { | 956 if ((old_state != DOWN_WITH_CHANGE) && popup_model()->IsOpen()) { |
948 // Autocomplete history provider results may change, so refresh the | 957 // Autocomplete history provider results may change, so refresh the |
949 // popup. This will force user_input_in_progress_ to true, but if the | 958 // popup. This will force user_input_in_progress_ to true, but if the |
950 // popup is open, that should have already been the case. | 959 // popup is open, that should have already been the case. |
951 view_->UpdatePopup(); | 960 view_->UpdatePopup(); |
952 } | 961 } |
953 } | 962 } |
954 } | 963 } |
955 | 964 |
956 void OmniboxEditModel::OnUpOrDownKeyPressed(int count) { | 965 void OmniboxEditModel::OnUpOrDownKeyPressed(int count) { |
957 // NOTE: This purposefully doesn't trigger any code that resets paste_state_. | 966 // NOTE: This purposefully doesn't trigger any code that resets paste_state_. |
958 if (!popup_->IsOpen()) { | 967 if (!popup_model()->IsOpen()) { |
959 if (!query_in_progress()) { | 968 if (!query_in_progress()) { |
960 // The popup is neither open nor working on a query already. So, start an | 969 // The popup is neither open nor working on a query already. So, start an |
961 // autocomplete query for the current text. This also sets | 970 // autocomplete query for the current text. This also sets |
962 // user_input_in_progress_ to true, which we want: if the user has started | 971 // 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 | 972 // to interact with the popup, changing the permanent_text_ shouldn't |
964 // change the displayed text. | 973 // change the displayed text. |
965 // Note: This does not force the popup to open immediately. | 974 // Note: This does not force the popup to open immediately. |
966 // TODO(pkasting): We should, in fact, force this particular query to open | 975 // TODO(pkasting): We should, in fact, force this particular query to open |
967 // the popup immediately. | 976 // the popup immediately. |
968 if (!user_input_in_progress_) | 977 if (!user_input_in_progress_) |
969 InternalSetUserText(permanent_text_); | 978 InternalSetUserText(permanent_text_); |
970 view_->UpdatePopup(); | 979 view_->UpdatePopup(); |
971 } else { | 980 } else { |
972 // TODO(pkasting): The popup is working on a query but is not open. We | 981 // TODO(pkasting): The popup is working on a query but is not open. We |
973 // should force it to open immediately. | 982 // should force it to open immediately. |
974 } | 983 } |
975 } else { | 984 } else { |
976 InstantController* instant = controller_->GetInstant(); | 985 InstantController* instant = controller_->GetInstant(); |
977 if (instant && instant->OnUpOrDownKeyPressed(count)) { | 986 if (instant && instant->OnUpOrDownKeyPressed(count)) { |
978 // If Instant handles the key press, it's showing a list of suggestions | 987 // 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 | 988 // 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 | 989 // irrelevant, so don't process the key press ourselves. However, do stop |
981 // the autocomplete system from changing the results. | 990 // the autocomplete system from changing the results. |
982 autocomplete_controller()->Stop(false); | 991 autocomplete_controller()->Stop(false); |
983 } else { | 992 } else { |
984 // The popup is open, so the user should be able to interact with it | 993 // The popup is open, so the user should be able to interact with it |
985 // normally. | 994 // normally. |
986 popup_->Move(count); | 995 popup_model()->Move(count); |
987 } | 996 } |
988 } | 997 } |
989 } | 998 } |
990 | 999 |
991 void OmniboxEditModel::OnPopupDataChanged( | 1000 void OmniboxEditModel::OnPopupDataChanged( |
992 const string16& text, | 1001 const string16& text, |
993 GURL* destination_for_temporary_text_change, | 1002 GURL* destination_for_temporary_text_change, |
994 const string16& keyword, | 1003 const string16& keyword, |
995 bool is_keyword_hint) { | 1004 bool is_keyword_hint) { |
996 // Update keyword/hint-related local state. | 1005 // 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. | 1107 // Modifying the selection counts as accepting the autocompleted text. |
1099 const bool user_text_changed = | 1108 const bool user_text_changed = |
1100 text_differs || (selection_differs && !inline_autocomplete_text_.empty()); | 1109 text_differs || (selection_differs && !inline_autocomplete_text_.empty()); |
1101 | 1110 |
1102 // If something has changed while the control key is down, prevent | 1111 // 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 | 1112 // "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. | 1113 // to update the popup if it's open, since the desired_tld will have changed. |
1105 if ((text_differs || selection_differs) && | 1114 if ((text_differs || selection_differs) && |
1106 (control_key_state_ == DOWN_WITHOUT_CHANGE)) { | 1115 (control_key_state_ == DOWN_WITHOUT_CHANGE)) { |
1107 control_key_state_ = DOWN_WITH_CHANGE; | 1116 control_key_state_ = DOWN_WITH_CHANGE; |
1108 if (!text_differs && !popup_->IsOpen()) | 1117 if (!text_differs && !popup_model()->IsOpen()) |
1109 return false; // Don't open the popup for no reason. | 1118 return false; // Don't open the popup for no reason. |
1110 } else if (!user_text_changed) { | 1119 } else if (!user_text_changed) { |
1111 return false; | 1120 return false; |
1112 } | 1121 } |
1113 | 1122 |
1114 // If the user text has not changed, we do not want to change the model's | 1123 // 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 | 1124 // state associated with the text. Otherwise, we can get surprising behavior |
1116 // where the autocompleted text unexpectedly reappears, e.g. crbug.com/55983 | 1125 // where the autocompleted text unexpectedly reappears, e.g. crbug.com/55983 |
1117 if (user_text_changed) { | 1126 if (user_text_changed) { |
1118 InternalSetUserText(UserTextFromDisplayText(new_text)); | 1127 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. | 1173 // determine what keyword, if any, is applicable. |
1165 // | 1174 // |
1166 // If MaybeAcceptKeywordBySpace() accepts the keyword and returns true, that | 1175 // 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 | 1176 // will have updated our state already, so in that case we don't also return |
1168 // true from this function. | 1177 // true from this function. |
1169 return !(text_differs && allow_keyword_ui_change && !just_deleted_text && | 1178 return !(text_differs && allow_keyword_ui_change && !just_deleted_text && |
1170 no_selection && (selection_start == user_text_.length()) && | 1179 no_selection && (selection_start == user_text_.length()) && |
1171 MaybeAcceptKeywordBySpace(user_text_)); | 1180 MaybeAcceptKeywordBySpace(user_text_)); |
1172 } | 1181 } |
1173 | 1182 |
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) { | 1183 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 } | 1184 } |
1235 | 1185 |
1236 bool OmniboxEditModel::query_in_progress() const { | 1186 bool OmniboxEditModel::query_in_progress() const { |
1237 return !autocomplete_controller()->done(); | 1187 return !autocomplete_controller()->done(); |
1238 } | 1188 } |
1239 | 1189 |
1240 void OmniboxEditModel::InternalSetUserText(const string16& text) { | 1190 void OmniboxEditModel::InternalSetUserText(const string16& text) { |
1241 user_text_ = text; | 1191 user_text_ = text; |
1242 just_deleted_text_ = false; | 1192 just_deleted_text_ = false; |
1243 inline_autocomplete_text_.clear(); | 1193 inline_autocomplete_text_.clear(); |
1244 } | 1194 } |
1245 | 1195 |
1246 bool OmniboxEditModel::KeywordIsSelected() const { | 1196 bool OmniboxEditModel::KeywordIsSelected() const { |
1247 return !is_keyword_hint_ && !keyword_.empty(); | 1197 return !is_keyword_hint_ && !keyword_.empty(); |
1248 } | 1198 } |
1249 | 1199 |
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 { | 1200 string16 OmniboxEditModel::DisplayTextFromUserText(const string16& text) const { |
1257 return KeywordIsSelected() ? | 1201 return KeywordIsSelected() ? |
1258 KeywordProvider::SplitReplacementStringFromInput(text, false) : text; | 1202 KeywordProvider::SplitReplacementStringFromInput(text, false) : text; |
1259 } | 1203 } |
1260 | 1204 |
1261 string16 OmniboxEditModel::UserTextFromDisplayText(const string16& text) const { | 1205 string16 OmniboxEditModel::UserTextFromDisplayText(const string16& text) const { |
1262 return KeywordIsSelected() ? (keyword_ + char16(' ') + text) : text; | 1206 return KeywordIsSelected() ? (keyword_ + char16(' ') + text) : text; |
1263 } | 1207 } |
1264 | 1208 |
1265 void OmniboxEditModel::GetInfoForCurrentText(AutocompleteMatch* match, | 1209 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 | 1267 // |is_temporary_text_set_by_instant_|, so we still shouldn't get |
1324 // here. However, as protection against the unknowns and Instant | 1268 // here. However, as protection against the unknowns and Instant |
1325 // regressions, we simply return an invalid match instead of crashing | 1269 // regressions, we simply return an invalid match instead of crashing |
1326 // (hence no DCHECK). | 1270 // (hence no DCHECK). |
1327 } | 1271 } |
1328 } else { | 1272 } else { |
1329 *match = HistoryURLProvider::SuggestExactInput( | 1273 *match = HistoryURLProvider::SuggestExactInput( |
1330 autocomplete_controller()->history_url_provider(), input, false); | 1274 autocomplete_controller()->history_url_provider(), input, false); |
1331 } | 1275 } |
1332 } | 1276 } |
1333 } else if (popup_->IsOpen() || query_in_progress()) { | 1277 } else if (popup_model()->IsOpen() || query_in_progress()) { |
1334 if (query_in_progress()) { | 1278 if (query_in_progress()) { |
1335 // It's technically possible for |result| to be empty if no provider | 1279 // It's technically possible for |result| to be empty if no provider |
1336 // returns a synchronous result but the query has not completed | 1280 // returns a synchronous result but the query has not completed |
1337 // synchronously; pratically, however, that should never actually happen. | 1281 // synchronously; pratically, however, that should never actually happen. |
1338 if (result().empty()) | 1282 if (result().empty()) |
1339 return; | 1283 return; |
1340 // The user cannot have manually selected a match, or the query would have | 1284 // The user cannot have manually selected a match, or the query would have |
1341 // stopped. So the default match must be the desired selection. | 1285 // stopped. So the default match must be the desired selection. |
1342 *match = *result().default_match(); | 1286 *match = *result().default_match(); |
1343 } else { | 1287 } else { |
1344 // If there are no results, the popup should be closed, so we shouldn't | 1288 // If there are no results, the popup should be closed, so we shouldn't |
1345 // have gotten here. | 1289 // have gotten here. |
1346 CHECK(!result().empty()); | 1290 CHECK(!result().empty()); |
1347 CHECK(popup_->selected_line() < result().size()); | 1291 CHECK(popup_model()->selected_line() < result().size()); |
1348 *match = result().match_at(popup_->selected_line()); | 1292 *match = result().match_at(popup_model()->selected_line()); |
1349 } | 1293 } |
1350 if (alternate_nav_url && popup_->manually_selected_match().empty()) | 1294 if (alternate_nav_url && popup_model()->manually_selected_match().empty()) |
1351 *alternate_nav_url = result().alternate_nav_url(); | 1295 *alternate_nav_url = result().alternate_nav_url(); |
1352 } else { | 1296 } else { |
1353 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify( | 1297 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify( |
1354 UserTextFromDisplayText(view_->GetText()), KeywordIsSelected(), true, | 1298 UserTextFromDisplayText(view_->GetText()), KeywordIsSelected(), true, |
1355 match, alternate_nav_url); | 1299 match, alternate_nav_url); |
1356 } | 1300 } |
1357 } | 1301 } |
1358 | 1302 |
1359 void OmniboxEditModel::RevertTemporaryText(bool revert_popup) { | 1303 void OmniboxEditModel::RevertTemporaryText(bool revert_popup) { |
1360 // The user typed something, then selected a different item. Restore the | 1304 // 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 | 1323 // 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. | 1324 // previously saved selection to be erased nor OnChanged() to be called. |
1381 view_->OnTemporaryTextMaybeChanged(user_text_ + inline_autocomplete_text_, | 1325 view_->OnTemporaryTextMaybeChanged(user_text_ + inline_autocomplete_text_, |
1382 false, false); | 1326 false, false); |
1383 AutocompleteResult::const_iterator match(result().default_match()); | 1327 AutocompleteResult::const_iterator match(result().default_match()); |
1384 instant->OnCancel(match != result().end() ? *match : AutocompleteMatch(), | 1328 instant->OnCancel(match != result().end() ? *match : AutocompleteMatch(), |
1385 user_text_, | 1329 user_text_, |
1386 user_text_ + inline_autocomplete_text_); | 1330 user_text_ + inline_autocomplete_text_); |
1387 } | 1331 } |
1388 if (revert_popup) | 1332 if (revert_popup) |
1389 popup_->ResetToDefaultMatch(); | 1333 popup_model()->ResetToDefaultMatch(); |
1390 view_->OnRevertTemporaryText(); | 1334 view_->OnRevertTemporaryText(); |
1391 } | 1335 } |
1392 | 1336 |
1393 bool OmniboxEditModel::MaybeAcceptKeywordBySpace(const string16& new_text) { | 1337 bool OmniboxEditModel::MaybeAcceptKeywordBySpace(const string16& new_text) { |
1394 size_t keyword_length = new_text.length() - 1; | 1338 size_t keyword_length = new_text.length() - 1; |
1395 return (paste_state_ == NONE) && is_keyword_hint_ && !keyword_.empty() && | 1339 return (paste_state_ == NONE) && is_keyword_hint_ && !keyword_.empty() && |
1396 inline_autocomplete_text_.empty() && | 1340 inline_autocomplete_text_.empty() && |
1397 (keyword_.length() == keyword_length) && | 1341 (keyword_.length() == keyword_length) && |
1398 IsSpaceCharForAcceptingKeyword(new_text[keyword_length]) && | 1342 IsSpaceCharForAcceptingKeyword(new_text[keyword_length]) && |
1399 !new_text.compare(0, keyword_length, keyword_, 0, keyword_length) && | 1343 !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. | 1394 // Remove "?" if we're in forced query mode. |
1451 AutocompleteInput::RemoveForcedQueryStringIfNecessary( | 1395 AutocompleteInput::RemoveForcedQueryStringIfNecessary( |
1452 autocomplete_controller()->input().type(), &user_text); | 1396 autocomplete_controller()->input().type(), &user_text); |
1453 AutocompleteInput::RemoveForcedQueryStringIfNecessary( | 1397 AutocompleteInput::RemoveForcedQueryStringIfNecessary( |
1454 autocomplete_controller()->input().type(), &full_text); | 1398 autocomplete_controller()->input().type(), &full_text); |
1455 | 1399 |
1456 size_t start, end; | 1400 size_t start, end; |
1457 view_->GetSelectionBounds(&start, &end); | 1401 view_->GetSelectionBounds(&start, &end); |
1458 | 1402 |
1459 return instant->Update(match, user_text, full_text, start, end, | 1403 return instant->Update(match, user_text, full_text, start, end, |
1460 UseVerbatimInstant(), user_input_in_progress_, popup_->IsOpen(), | 1404 UseVerbatimInstant(), user_input_in_progress_, popup_model()->IsOpen(), |
1461 in_escape_handler_, KeywordIsSelected()); | 1405 in_escape_handler_, KeywordIsSelected()); |
1462 } | 1406 } |
1463 | 1407 |
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 | 1408 // static |
1481 bool OmniboxEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { | 1409 bool OmniboxEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { |
1482 switch (c) { | 1410 switch (c) { |
1483 case 0x0020: // Space | 1411 case 0x0020: // Space |
1484 case 0x3000: // Ideographic Space | 1412 case 0x3000: // Ideographic Space |
1485 return true; | 1413 return true; |
1486 default: | 1414 default: |
1487 return false; | 1415 return false; |
1488 } | 1416 } |
1489 } | 1417 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1521 instant->OmniboxFocusChanged(state, reason, NULL); | 1449 instant->OmniboxFocusChanged(state, reason, NULL); |
1522 | 1450 |
1523 // Update state and notify view if the omnibox has focus and the caret | 1451 // Update state and notify view if the omnibox has focus and the caret |
1524 // visibility changed. | 1452 // visibility changed. |
1525 const bool was_caret_visible = is_caret_visible(); | 1453 const bool was_caret_visible = is_caret_visible(); |
1526 focus_state_ = state; | 1454 focus_state_ = state; |
1527 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1455 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
1528 is_caret_visible() != was_caret_visible) | 1456 is_caret_visible() != was_caret_visible) |
1529 view_->ApplyCaretVisibility(); | 1457 view_->ApplyCaretVisibility(); |
1530 } | 1458 } |
OLD | NEW |