| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/autocomplete/autocomplete_edit.h" | 5 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 keyword_ui_state_ = allow_keyword_ui_change ? NORMAL : NO_KEYWORD; | 690 keyword_ui_state_ = allow_keyword_ui_change ? NORMAL : NO_KEYWORD; |
| 691 | 691 |
| 692 view_->UpdatePopup(); | 692 view_->UpdatePopup(); |
| 693 return true; | 693 return true; |
| 694 } | 694 } |
| 695 | 695 |
| 696 void AutocompleteEditModel::PopupBoundsChangedTo(const gfx::Rect& bounds) { | 696 void AutocompleteEditModel::PopupBoundsChangedTo(const gfx::Rect& bounds) { |
| 697 controller_->OnPopupBoundsChanged(bounds); | 697 controller_->OnPopupBoundsChanged(bounds); |
| 698 } | 698 } |
| 699 | 699 |
| 700 void AutocompleteEditModel::ResultsUpdated() { | |
| 701 UpdateSuggestedSearchText(); | |
| 702 } | |
| 703 | |
| 704 // Return true if the suggestion type warrants a TCP/IP preconnection. | 700 // Return true if the suggestion type warrants a TCP/IP preconnection. |
| 705 // i.e., it is now highly likely that the user will select the related domain. | 701 // i.e., it is now highly likely that the user will select the related domain. |
| 706 static bool IsPreconnectable(AutocompleteMatch::Type type) { | 702 static bool IsPreconnectable(AutocompleteMatch::Type type) { |
| 707 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", type, | 703 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", type, |
| 708 AutocompleteMatch::NUM_TYPES); | 704 AutocompleteMatch::NUM_TYPES); |
| 709 switch (type) { | 705 switch (type) { |
| 710 // Matches using the user's default search engine. | 706 // Matches using the user's default search engine. |
| 711 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: | 707 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: |
| 712 case AutocompleteMatch::SEARCH_HISTORY: | 708 case AutocompleteMatch::SEARCH_HISTORY: |
| 713 case AutocompleteMatch::SEARCH_SUGGEST: | 709 case AutocompleteMatch::SEARCH_SUGGEST: |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 GURL* url) const { | 788 GURL* url) const { |
| 793 GURL parsed_url; | 789 GURL parsed_url; |
| 794 const AutocompleteInput::Type type = AutocompleteInput::Parse( | 790 const AutocompleteInput::Type type = AutocompleteInput::Parse( |
| 795 UserTextFromDisplayText(text), std::wstring(), NULL, NULL, &parsed_url); | 791 UserTextFromDisplayText(text), std::wstring(), NULL, NULL, &parsed_url); |
| 796 if (type != AutocompleteInput::URL) | 792 if (type != AutocompleteInput::URL) |
| 797 return false; | 793 return false; |
| 798 | 794 |
| 799 *url = parsed_url; | 795 *url = parsed_url; |
| 800 return true; | 796 return true; |
| 801 } | 797 } |
| 802 | |
| 803 // Returns true if suggested search text should be shown for the specified match | |
| 804 // type. | |
| 805 static bool ShouldShowSuggestSearchTextFor(AutocompleteMatch::Type type) { | |
| 806 // TODO: add support for other engines when in keyword mode. | |
| 807 return ((type == AutocompleteMatch::SEARCH_HISTORY) || | |
| 808 (type == AutocompleteMatch::SEARCH_SUGGEST)); | |
| 809 } | |
| 810 | |
| 811 void AutocompleteEditModel::UpdateSuggestedSearchText() { | |
| 812 if (!InstantController::IsEnabled(profile_, InstantController::VERBATIM_TYPE)) | |
| 813 return; | |
| 814 | |
| 815 string16 suggested_text; | |
| 816 // The suggested text comes from the first search result. | |
| 817 if (popup_->IsOpen()) { | |
| 818 const AutocompleteResult& result = popup_->result(); | |
| 819 if ((result.size() > 1) && (popup_->selected_line() == 0) && | |
| 820 ((result.begin()->inline_autocomplete_offset == std::wstring::npos) || | |
| 821 (result.begin()->inline_autocomplete_offset == | |
| 822 result.begin()->fill_into_edit.size()))) { | |
| 823 for (AutocompleteResult::const_iterator i = result.begin() + 1; | |
| 824 i != result.end(); ++i) { | |
| 825 // TODO: add support for other engines when in keyword mode. | |
| 826 if (ShouldShowSuggestSearchTextFor(i->type) && | |
| 827 i->inline_autocomplete_offset != std::wstring::npos) { | |
| 828 suggested_text = WideToUTF16(i->fill_into_edit.substr( | |
| 829 i->inline_autocomplete_offset)); | |
| 830 break; | |
| 831 } | |
| 832 } | |
| 833 } | |
| 834 } | |
| 835 controller_->OnSetSuggestedSearchText(suggested_text); | |
| 836 } | |
| OLD | NEW |