OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/omnibox/browser/autocomplete_match.h" | 5 #include "components/omnibox/browser/autocomplete_match.h" |
6 | 6 |
7 #include "base/i18n/time_formatting.h" | 7 #include "base/i18n/time_formatting.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "components/omnibox/browser/autocomplete_provider.h" | 16 #include "components/omnibox/browser/autocomplete_provider.h" |
17 #include "components/omnibox/browser/suggestion_answer.h" | 17 #include "components/omnibox/browser/suggestion_answer.h" |
18 #include "components/search_engines/template_url.h" | 18 #include "components/search_engines/template_url.h" |
19 #include "components/search_engines/template_url_service.h" | 19 #include "components/search_engines/template_url_service.h" |
20 #include "components/url_formatter/url_formatter.h" | 20 #include "components/url_formatter/url_formatter.h" |
21 #include "grit/components_scaled_resources.h" | 21 #include "grit/components_scaled_resources.h" |
| 22 #include "ui/gfx/vector_icons_public.h" |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 bool IsTrivialClassification(const ACMatchClassifications& classifications) { | 26 bool IsTrivialClassification(const ACMatchClassifications& classifications) { |
26 return classifications.empty() || | 27 return classifications.empty() || |
27 ((classifications.size() == 1) && | 28 ((classifications.size() == 1) && |
28 (classifications.back().style == ACMatchClassification::NONE)); | 29 (classifications.back().style == ACMatchClassification::NONE)); |
29 } | 30 } |
30 | 31 |
31 // Returns true if one of the |terms_prefixed_by_http_or_https| matches the | 32 // Returns true if one of the |terms_prefixed_by_http_or_https| matches the |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 IDR_OMNIBOX_CALCULATOR, // CALCULATOR | 214 IDR_OMNIBOX_CALCULATOR, // CALCULATOR |
214 IDR_OMNIBOX_HTTP, // CLIPBOARD | 215 IDR_OMNIBOX_HTTP, // CLIPBOARD |
215 }; | 216 }; |
216 #endif | 217 #endif |
217 static_assert(arraysize(kIcons) == AutocompleteMatchType::NUM_TYPES, | 218 static_assert(arraysize(kIcons) == AutocompleteMatchType::NUM_TYPES, |
218 "icons array must have NUM_TYPES elements"); | 219 "icons array must have NUM_TYPES elements"); |
219 return kIcons[type]; | 220 return kIcons[type]; |
220 } | 221 } |
221 | 222 |
222 // static | 223 // static |
| 224 gfx::VectorIconId AutocompleteMatch::TypeToVectorIcon(Type type) { |
| 225 #if !defined(OS_ANDROID) && !defined(OS_MACOSX) && !defined(OS_IOS) |
| 226 static const gfx::VectorIconId kIcons[] = { |
| 227 gfx::VectorIconId::OMNIBOX_HTTP, // URL_WHAT_YOU_TYPE |
| 228 gfx::VectorIconId::HISTORY, // HISTORY_URL |
| 229 gfx::VectorIconId::HISTORY, // HISTORY_TITLE |
| 230 gfx::VectorIconId::HISTORY, // HISTORY_BODY |
| 231 gfx::VectorIconId::HISTORY, // HISTORY_KEYWORD |
| 232 gfx::VectorIconId::OMNIBOX_HTTP, // NAVSUGGEST |
| 233 gfx::VectorIconId::OMNIBOX_SEARCH, // SEARCH_WHAT_YOU_TYPED |
| 234 gfx::VectorIconId::HISTORY, // SEARCH_HISTORY |
| 235 gfx::VectorIconId::OMNIBOX_SEARCH, // SEARCH_SUGGEST |
| 236 gfx::VectorIconId::OMNIBOX_SEARCH, // SEARCH_SUGGEST_ENTITY |
| 237 gfx::VectorIconId::OMNIBOX_SEARCH, // SEARCH_SUGGEST_TAIL |
| 238 gfx::VectorIconId::OMNIBOX_SEARCH, // SEARCH_SUGGEST_PERSONALIZED |
| 239 gfx::VectorIconId::OMNIBOX_SEARCH, // SEARCH_SUGGEST_PROFILE |
| 240 gfx::VectorIconId::OMNIBOX_SEARCH, // SEARCH_OTHER_ENGINE |
| 241 gfx::VectorIconId::OMNIBOX_EXTENSION_APP, // EXTENSION_APP |
| 242 gfx::VectorIconId::OMNIBOX_SEARCH, // CONTACT_DEPRECATED |
| 243 gfx::VectorIconId::OMNIBOX_HTTP, // BOOKMARK_TITLE |
| 244 gfx::VectorIconId::OMNIBOX_HTTP, // NAVSUGGEST_PERSONALIZED |
| 245 gfx::VectorIconId::OMNIBOX_CALCULATOR, // CALCULATOR |
| 246 gfx::VectorIconId::OMNIBOX_HTTP, // CLIPBOARD |
| 247 }; |
| 248 static_assert(arraysize(kIcons) == AutocompleteMatchType::NUM_TYPES, |
| 249 "icons array must have NUM_TYPES elements"); |
| 250 return kIcons[type]; |
| 251 #else |
| 252 NOTREACHED(); |
| 253 return gfx::VectorIconId::NUM_VECTOR_ICONS; |
| 254 #endif |
| 255 } |
| 256 |
| 257 // static |
223 bool AutocompleteMatch::MoreRelevant(const AutocompleteMatch& elem1, | 258 bool AutocompleteMatch::MoreRelevant(const AutocompleteMatch& elem1, |
224 const AutocompleteMatch& elem2) { | 259 const AutocompleteMatch& elem2) { |
225 // For equal-relevance matches, we sort alphabetically, so that providers | 260 // For equal-relevance matches, we sort alphabetically, so that providers |
226 // who return multiple elements at the same priority get a "stable" sort | 261 // who return multiple elements at the same priority get a "stable" sort |
227 // across multiple updates. | 262 // across multiple updates. |
228 return (elem1.relevance == elem2.relevance) ? | 263 return (elem1.relevance == elem2.relevance) ? |
229 (elem1.contents < elem2.contents) : (elem1.relevance > elem2.relevance); | 264 (elem1.contents < elem2.contents) : (elem1.relevance > elem2.relevance); |
230 } | 265 } |
231 | 266 |
232 // static | 267 // static |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 << " is unsorted in relation to last offset of " << last_offset | 673 << " is unsorted in relation to last offset of " << last_offset |
639 << ". Provider: " << provider_name << "."; | 674 << ". Provider: " << provider_name << "."; |
640 DCHECK_LT(i->offset, text.length()) | 675 DCHECK_LT(i->offset, text.length()) |
641 << " Classification of [" << i->offset << "," << text.length() | 676 << " Classification of [" << i->offset << "," << text.length() |
642 << "] is out of bounds for \"" << text << "\". Provider: " | 677 << "] is out of bounds for \"" << text << "\". Provider: " |
643 << provider_name << "."; | 678 << provider_name << "."; |
644 last_offset = i->offset; | 679 last_offset = i->offset; |
645 } | 680 } |
646 } | 681 } |
647 #endif | 682 #endif |
OLD | NEW |