OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 5 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // This type indicates a native chrome suggestion. | 50 // This type indicates a native chrome suggestion. |
51 *type = 69; | 51 *type = 69; |
52 // Default value, indicating no subtype. | 52 // Default value, indicating no subtype. |
53 *subtype = base::string16::npos; | 53 *subtype = base::string16::npos; |
54 | 54 |
55 switch (match) { | 55 switch (match) { |
56 case AutocompleteMatchType::SEARCH_SUGGEST: { | 56 case AutocompleteMatchType::SEARCH_SUGGEST: { |
57 *type = 0; | 57 *type = 0; |
58 return; | 58 return; |
59 } | 59 } |
| 60 case AutocompleteMatchType::SEARCH_SUGGEST_ENTITY: { |
| 61 *subtype = 46; |
| 62 return; |
| 63 } |
| 64 case AutocompleteMatchType::SEARCH_SUGGEST_INFINITE: { |
| 65 *subtype = 33; |
| 66 return; |
| 67 } |
| 68 case AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED: { |
| 69 *subtype = 35; |
| 70 return; |
| 71 } |
| 72 case AutocompleteMatchType::SEARCH_SUGGEST_PROFILE: { |
| 73 *subtype = 44; |
| 74 return; |
| 75 } |
60 case AutocompleteMatchType::NAVSUGGEST: { | 76 case AutocompleteMatchType::NAVSUGGEST: { |
61 *type = 5; | 77 *type = 5; |
62 return; | 78 return; |
63 } | 79 } |
64 case AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED: { | 80 case AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED: { |
65 *subtype = 57; | 81 *subtype = 57; |
66 return; | 82 return; |
67 } | 83 } |
68 case AutocompleteMatchType::URL_WHAT_YOU_TYPED: { | 84 case AutocompleteMatchType::URL_WHAT_YOU_TYPED: { |
69 *subtype = 58; | 85 *subtype = 58; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 136 |
121 // Returns whether the autocompletion is trivial enough that we consider it | 137 // Returns whether the autocompletion is trivial enough that we consider it |
122 // an autocompletion for which the omnibox autocompletion code did not add | 138 // an autocompletion for which the omnibox autocompletion code did not add |
123 // any value. | 139 // any value. |
124 bool IsTrivialAutocompletion(const AutocompleteMatch& match) { | 140 bool IsTrivialAutocompletion(const AutocompleteMatch& match) { |
125 return match.type == AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED || | 141 return match.type == AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED || |
126 match.type == AutocompleteMatchType::URL_WHAT_YOU_TYPED || | 142 match.type == AutocompleteMatchType::URL_WHAT_YOU_TYPED || |
127 match.type == AutocompleteMatchType::SEARCH_OTHER_ENGINE; | 143 match.type == AutocompleteMatchType::SEARCH_OTHER_ENGINE; |
128 } | 144 } |
129 | 145 |
| 146 // Whether this autocomplete match type supports custom descriptions. |
| 147 bool AutocompleteMatchHasCustomDescription(const AutocompleteMatch& match) { |
| 148 return match.type == AutocompleteMatchType::SEARCH_SUGGEST_ENTITY || |
| 149 match.type == AutocompleteMatchType::SEARCH_SUGGEST_PROFILE; |
| 150 } |
| 151 |
130 } // namespace | 152 } // namespace |
131 | 153 |
132 const int AutocompleteController::kNoItemSelected = -1; | 154 const int AutocompleteController::kNoItemSelected = -1; |
133 | 155 |
134 AutocompleteController::AutocompleteController( | 156 AutocompleteController::AutocompleteController( |
135 Profile* profile, | 157 Profile* profile, |
136 AutocompleteControllerDelegate* delegate, | 158 AutocompleteControllerDelegate* delegate, |
137 int provider_types) | 159 int provider_types) |
138 : delegate_(delegate), | 160 : delegate_(delegate), |
139 history_url_provider_(NULL), | 161 history_url_provider_(NULL), |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 | 532 |
511 void AutocompleteController::UpdateKeywordDescriptions( | 533 void AutocompleteController::UpdateKeywordDescriptions( |
512 AutocompleteResult* result) { | 534 AutocompleteResult* result) { |
513 base::string16 last_keyword; | 535 base::string16 last_keyword; |
514 for (AutocompleteResult::iterator i(result->begin()); i != result->end(); | 536 for (AutocompleteResult::iterator i(result->begin()); i != result->end(); |
515 ++i) { | 537 ++i) { |
516 if ((i->provider->type() == AutocompleteProvider::TYPE_KEYWORD && | 538 if ((i->provider->type() == AutocompleteProvider::TYPE_KEYWORD && |
517 !i->keyword.empty()) || | 539 !i->keyword.empty()) || |
518 (i->provider->type() == AutocompleteProvider::TYPE_SEARCH && | 540 (i->provider->type() == AutocompleteProvider::TYPE_SEARCH && |
519 AutocompleteMatch::IsSearchType(i->type))) { | 541 AutocompleteMatch::IsSearchType(i->type))) { |
| 542 if (AutocompleteMatchHasCustomDescription(*i)) |
| 543 continue; |
520 i->description.clear(); | 544 i->description.clear(); |
521 i->description_class.clear(); | 545 i->description_class.clear(); |
522 DCHECK(!i->keyword.empty()); | 546 DCHECK(!i->keyword.empty()); |
523 if (i->keyword != last_keyword) { | 547 if (i->keyword != last_keyword) { |
524 const TemplateURL* template_url = i->GetTemplateURL(profile_, false); | 548 const TemplateURL* template_url = i->GetTemplateURL(profile_, false); |
525 if (template_url) { | 549 if (template_url) { |
526 // For extension keywords, just make the description the extension | 550 // For extension keywords, just make the description the extension |
527 // name -- don't assume that the normal search keyword description is | 551 // name -- don't assume that the normal search keyword description is |
528 // applicable. | 552 // applicable. |
529 i->description = template_url->AdjustedShortNameForLocaleDirection(); | 553 i->description = template_url->AdjustedShortNameForLocaleDirection(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 // the disruptive effect of belated omnibox updates, updates that | 657 // the disruptive effect of belated omnibox updates, updates that |
634 // come after the user has had to time to read the whole dropdown | 658 // come after the user has had to time to read the whole dropdown |
635 // and doesn't expect it to change. | 659 // and doesn't expect it to change. |
636 const int kStopTimeMS = 1500; | 660 const int kStopTimeMS = 1500; |
637 stop_timer_.Start(FROM_HERE, | 661 stop_timer_.Start(FROM_HERE, |
638 base::TimeDelta::FromMilliseconds(kStopTimeMS), | 662 base::TimeDelta::FromMilliseconds(kStopTimeMS), |
639 base::Bind(&AutocompleteController::Stop, | 663 base::Bind(&AutocompleteController::Stop, |
640 base::Unretained(this), | 664 base::Unretained(this), |
641 false)); | 665 false)); |
642 } | 666 } |
OLD | NEW |