Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: chrome/browser/autocomplete/autocomplete.cc

Issue 9419043: Revert 122412 - Enabled pressing TAB to traverse through the Omnibox results (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/autocomplete/autocomplete.h" 5 #include "chrome/browser/autocomplete/autocomplete.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set>
9 8
10 #include "base/basictypes.h" 9 #include "base/basictypes.h"
11 #include "base/command_line.h" 10 #include "base/command_line.h"
12 #include "base/i18n/number_formatting.h" 11 #include "base/i18n/number_formatting.h"
13 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
14 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
15 #include "base/string_util.h" 14 #include "base/string_util.h"
16 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
17 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" 16 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h"
18 #include "chrome/browser/autocomplete/autocomplete_match.h" 17 #include "chrome/browser/autocomplete/autocomplete_match.h"
19 #include "chrome/browser/autocomplete/builtin_provider.h" 18 #include "chrome/browser/autocomplete/builtin_provider.h"
20 #include "chrome/browser/autocomplete/extension_app_provider.h" 19 #include "chrome/browser/autocomplete/extension_app_provider.h"
21 #include "chrome/browser/autocomplete/history_contents_provider.h" 20 #include "chrome/browser/autocomplete/history_contents_provider.h"
22 #include "chrome/browser/autocomplete/history_quick_provider.h" 21 #include "chrome/browser/autocomplete/history_quick_provider.h"
23 #include "chrome/browser/autocomplete/history_url_provider.h" 22 #include "chrome/browser/autocomplete/history_url_provider.h"
24 #include "chrome/browser/autocomplete/keyword_provider.h" 23 #include "chrome/browser/autocomplete/keyword_provider.h"
25 #include "chrome/browser/autocomplete/search_provider.h" 24 #include "chrome/browser/autocomplete/search_provider.h"
26 #include "chrome/browser/autocomplete/shortcuts_provider.h" 25 #include "chrome/browser/autocomplete/shortcuts_provider.h"
27 #include "chrome/browser/bookmarks/bookmark_model.h" 26 #include "chrome/browser/bookmarks/bookmark_model.h"
28 #include "chrome/browser/extensions/extension_service.h"
29 #include "chrome/browser/external_protocol/external_protocol_handler.h" 27 #include "chrome/browser/external_protocol/external_protocol_handler.h"
30 #include "chrome/browser/instant/instant_field_trial.h" 28 #include "chrome/browser/instant/instant_field_trial.h"
31 #include "chrome/browser/net/url_fixer_upper.h" 29 #include "chrome/browser/net/url_fixer_upper.h"
32 #include "chrome/browser/prefs/pref_service.h" 30 #include "chrome/browser/prefs/pref_service.h"
33 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
34 #include "chrome/browser/profiles/profile_io_data.h" 32 #include "chrome/browser/profiles/profile_io_data.h"
35 #include "chrome/browser/search_engines/template_url.h"
36 #include "chrome/browser/search_engines/template_url_service.h"
37 #include "chrome/browser/search_engines/template_url_service_factory.h"
38 #include "chrome/browser/ui/webui/history_ui.h" 33 #include "chrome/browser/ui/webui/history_ui.h"
39 #include "chrome/common/chrome_notification_types.h" 34 #include "chrome/common/chrome_notification_types.h"
40 #include "chrome/common/chrome_switches.h" 35 #include "chrome/common/chrome_switches.h"
41 #include "chrome/common/pref_names.h" 36 #include "chrome/common/pref_names.h"
42 #include "chrome/common/url_constants.h" 37 #include "chrome/common/url_constants.h"
43 #include "content/public/browser/notification_service.h" 38 #include "content/public/browser/notification_service.h"
44 #include "googleurl/src/gurl.h" 39 #include "googleurl/src/gurl.h"
45 #include "googleurl/src/url_canon_ip.h" 40 #include "googleurl/src/url_canon_ip.h"
46 #include "googleurl/src/url_util.h" 41 #include "googleurl/src/url_util.h"
47 #include "grit/generated_resources.h" 42 #include "grit/generated_resources.h"
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 ACMatches::iterator insertion_point = 676 ACMatches::iterator insertion_point =
682 std::upper_bound(begin(), end(), match, &AutocompleteMatch::MoreRelevant); 677 std::upper_bound(begin(), end(), match, &AutocompleteMatch::MoreRelevant);
683 matches_difference_type default_offset = default_match_ - begin(); 678 matches_difference_type default_offset = default_match_ - begin();
684 if ((insertion_point - begin()) <= default_offset) 679 if ((insertion_point - begin()) <= default_offset)
685 ++default_offset; 680 ++default_offset;
686 matches_.insert(insertion_point, match); 681 matches_.insert(insertion_point, match);
687 default_match_ = begin() + default_offset; 682 default_match_ = begin() + default_offset;
688 } 683 }
689 684
690 void AutocompleteResult::SortAndCull(const AutocompleteInput& input) { 685 void AutocompleteResult::SortAndCull(const AutocompleteInput& input) {
691 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i)
692 i->ComputeStrippedDestinationURL();
693
694 // Remove duplicates. 686 // Remove duplicates.
695 std::sort(matches_.begin(), matches_.end(), 687 std::sort(matches_.begin(), matches_.end(),
696 &AutocompleteMatch::DestinationSortFunc); 688 &AutocompleteMatch::DestinationSortFunc);
697 matches_.erase(std::unique(matches_.begin(), matches_.end(), 689 matches_.erase(std::unique(matches_.begin(), matches_.end(),
698 &AutocompleteMatch::DestinationsEqual), 690 &AutocompleteMatch::DestinationsEqual),
699 matches_.end()); 691 matches_.end());
700 692
701 // Sort and trim to the most relevant kMaxMatches matches. 693 // Sort and trim to the most relevant kMaxMatches matches.
702 const size_t num_matches = std::min(kMaxMatches, matches_.size()); 694 const size_t num_matches = std::min(kMaxMatches, matches_.size());
703 std::partial_sort(matches_.begin(), matches_.begin() + num_matches, 695 std::partial_sort(matches_.begin(), matches_.begin() + num_matches,
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 result_.Validate(); 984 result_.Validate();
993 #endif 985 #endif
994 986
995 if (!done_) { 987 if (!done_) {
996 // This conditional needs to match the conditional in Start that invokes 988 // This conditional needs to match the conditional in Start that invokes
997 // StartExpireTimer. 989 // StartExpireTimer.
998 result_.CopyOldMatches(input_, last_result); 990 result_.CopyOldMatches(input_, last_result);
999 } 991 }
1000 992
1001 UpdateKeywordDescriptions(&result_); 993 UpdateKeywordDescriptions(&result_);
1002 UpdateAssociatedKeywords(&result_);
1003 994
1004 bool notify_default_match = is_synchronous_pass; 995 bool notify_default_match = is_synchronous_pass;
1005 if (!is_synchronous_pass) { 996 if (!is_synchronous_pass) {
1006 const bool last_default_was_valid = 997 const bool last_default_was_valid =
1007 last_result.default_match() != last_result.end(); 998 last_result.default_match() != last_result.end();
1008 const bool default_is_valid = result_.default_match() != result_.end(); 999 const bool default_is_valid = result_.default_match() != result_.end();
1009 // We've gotten async results. Send notification that the default match 1000 // We've gotten async results. Send notification that the default match
1010 // updated if fill_into_edit differs or associated_keyword differ. (The 1001 // updated if fill_into_edit differs. We don't check the URL as that may
1011 // latter can change if we've just started Chrome and the keyword database 1002 // change for the default match even though the fill into edit hasn't
1012 // finishes loading while processing this request.) We don't check the URL 1003 // changed (see SearchProvider for one case of this).
1013 // as that may change for the default match even though the fill into edit
1014 // hasn't changed (see SearchProvider for one case of this).
1015 notify_default_match = 1004 notify_default_match =
1016 (last_default_was_valid != default_is_valid) || 1005 (last_default_was_valid != default_is_valid) ||
1017 (default_is_valid && 1006 (default_is_valid &&
1018 ((result_.default_match()->fill_into_edit != 1007 (result_.default_match()->fill_into_edit !=
1019 last_result.default_match()->fill_into_edit) || 1008 last_result.default_match()->fill_into_edit));
1020 (result_.default_match()->associated_keyword.get() !=
1021 last_result.default_match()->associated_keyword.get())));
1022 } 1009 }
1023 1010
1024 NotifyChanged(notify_default_match); 1011 NotifyChanged(notify_default_match);
1025 } 1012 }
1026 1013
1027 void AutocompleteController::UpdateAssociatedKeywords(
1028 AutocompleteResult* result) {
1029 if (!keyword_provider_)
1030 return;
1031
1032 std::set<string16> keywords;
1033 for (ACMatches::iterator match(result->begin()); match != result->end();
1034 ++match) {
1035 if (!match->keyword.empty()) {
1036 keywords.insert(match->keyword);
1037 } else {
1038 string16 keyword = match->associated_keyword.get() ?
1039 match->associated_keyword->keyword :
1040 keyword_provider_->GetKeywordForText(match->fill_into_edit);
1041
1042 // Only add the keyword if the match does not have a duplicate keyword
1043 // with a more relevant match.
1044 if (!keyword.empty() && !keywords.count(keyword)) {
1045 keywords.insert(keyword);
1046
1047 if (!match->associated_keyword.get())
1048 match->associated_keyword.reset(new AutocompleteMatch(
1049 keyword_provider_->CreateAutocompleteMatch(match->fill_into_edit,
1050 keyword, input_)));
1051 } else {
1052 match->associated_keyword.reset();
1053 }
1054 }
1055 }
1056 }
1057
1058 void AutocompleteController::UpdateKeywordDescriptions( 1014 void AutocompleteController::UpdateKeywordDescriptions(
1059 AutocompleteResult* result) { 1015 AutocompleteResult* result) {
1060 const TemplateURL* last_template_url = NULL; 1016 const TemplateURL* last_template_url = NULL;
1061 for (AutocompleteResult::iterator i = result->begin(); i != result->end(); 1017 for (AutocompleteResult::iterator i = result->begin(); i != result->end();
1062 ++i) { 1018 ++i) {
1063 if (((i->provider == keyword_provider_) && i->template_url) || 1019 if (((i->provider == keyword_provider_) && i->template_url) ||
1064 ((i->provider == search_provider_) && 1020 ((i->provider == search_provider_) &&
1065 (i->type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || 1021 (i->type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED ||
1066 i->type == AutocompleteMatch::SEARCH_HISTORY || 1022 i->type == AutocompleteMatch::SEARCH_HISTORY ||
1067 i->type == AutocompleteMatch::SEARCH_SUGGEST))) { 1023 i->type == AutocompleteMatch::SEARCH_SUGGEST))) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 const AutocompleteResult& result) 1079 const AutocompleteResult& result)
1124 : text(text), 1080 : text(text),
1125 input_type(input_type), 1081 input_type(input_type),
1126 selected_index(selected_index), 1082 selected_index(selected_index),
1127 tab_id(tab_id), 1083 tab_id(tab_id),
1128 elapsed_time_since_user_first_modified_omnibox( 1084 elapsed_time_since_user_first_modified_omnibox(
1129 elapsed_time_since_user_first_modified_omnibox), 1085 elapsed_time_since_user_first_modified_omnibox),
1130 inline_autocompleted_length(inline_autocompleted_length), 1086 inline_autocompleted_length(inline_autocompleted_length),
1131 result(result) { 1087 result(result) {
1132 } 1088 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete.h ('k') | chrome/browser/autocomplete/autocomplete_edit.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698