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/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
18 #include "components/omnibox/browser/autocomplete_provider.h" | 18 #include "components/omnibox/browser/autocomplete_provider.h" |
19 #include "components/omnibox/browser/suggestion_answer.h" | 19 #include "components/omnibox/browser/suggestion_answer.h" |
20 #include "components/search_engines/template_url.h" | 20 #include "components/search_engines/template_url.h" |
21 #include "components/search_engines/template_url_service.h" | 21 #include "components/search_engines/template_url_service.h" |
22 #include "components/url_formatter/url_formatter.h" | 22 #include "components/url_formatter/url_formatter.h" |
| 23 #include "grit/components_scaled_resources.h" |
23 #include "ui/gfx/vector_icons_public.h" | 24 #include "ui/gfx/vector_icons_public.h" |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 bool IsTrivialClassification(const ACMatchClassifications& classifications) { | 28 bool IsTrivialClassification(const ACMatchClassifications& classifications) { |
28 return classifications.empty() || | 29 return classifications.empty() || |
29 ((classifications.size() == 1) && | 30 ((classifications.size() == 1) && |
30 (classifications.back().style == ACMatchClassification::NONE)); | 31 (classifications.back().style == ACMatchClassification::NONE)); |
31 } | 32 } |
32 | 33 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 keyword = match.keyword; | 160 keyword = match.keyword; |
160 from_previous = match.from_previous; | 161 from_previous = match.from_previous; |
161 search_terms_args.reset(match.search_terms_args.get() ? | 162 search_terms_args.reset(match.search_terms_args.get() ? |
162 new TemplateURLRef::SearchTermsArgs(*match.search_terms_args) : NULL); | 163 new TemplateURLRef::SearchTermsArgs(*match.search_terms_args) : NULL); |
163 additional_info = match.additional_info; | 164 additional_info = match.additional_info; |
164 duplicate_matches = match.duplicate_matches; | 165 duplicate_matches = match.duplicate_matches; |
165 return *this; | 166 return *this; |
166 } | 167 } |
167 | 168 |
168 // static | 169 // static |
| 170 int AutocompleteMatch::TypeToIcon(Type type) { |
| 171 #if !defined(OS_IOS) |
| 172 static const int kIcons[] = { |
| 173 IDR_OMNIBOX_HTTP, // URL_WHAT_YOU_TYPE |
| 174 IDR_OMNIBOX_HTTP, // HISTORY_URL |
| 175 IDR_OMNIBOX_HTTP, // HISTORY_TITLE |
| 176 IDR_OMNIBOX_HTTP, // HISTORY_BODY |
| 177 IDR_OMNIBOX_HTTP, // HISTORY_KEYWORD |
| 178 IDR_OMNIBOX_HTTP, // NAVSUGGEST |
| 179 IDR_OMNIBOX_SEARCH, // SEARCH_WHAT_YOU_TYPED |
| 180 IDR_OMNIBOX_SEARCH, // SEARCH_HISTORY |
| 181 IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST |
| 182 IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST_ENTITY |
| 183 IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST_TAIL |
| 184 IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST_PERSONALIZED |
| 185 IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST_PROFILE |
| 186 IDR_OMNIBOX_SEARCH, // SEARCH_OTHER_ENGINE |
| 187 IDR_OMNIBOX_EXTENSION_APP, // EXTENSION_APP |
| 188 IDR_OMNIBOX_SEARCH, // CONTACT_DEPRECATED |
| 189 IDR_OMNIBOX_HTTP, // BOOKMARK_TITLE |
| 190 IDR_OMNIBOX_HTTP, // NAVSUGGEST_PERSONALIZED |
| 191 IDR_OMNIBOX_CALCULATOR, // CALCULATOR |
| 192 IDR_OMNIBOX_HTTP, // CLIPBOARD |
| 193 IDR_OMNIBOX_SEARCH, // VOICE_SEARCH |
| 194 IDR_OMNIBOX_HTTP, // PHYSICAL_WEB |
| 195 IDR_OMNIBOX_HTTP, // PHYSICAL_WEB_OVERFLOW |
| 196 }; |
| 197 #else |
| 198 static const int kIcons[] = { |
| 199 IDR_OMNIBOX_HTTP, // URL_WHAT_YOU_TYPE |
| 200 IDR_OMNIBOX_HISTORY, // HISTORY_URL |
| 201 IDR_OMNIBOX_HISTORY, // HISTORY_TITLE |
| 202 IDR_OMNIBOX_HISTORY, // HISTORY_BODY |
| 203 IDR_OMNIBOX_HISTORY, // HISTORY_KEYWORD |
| 204 IDR_OMNIBOX_HTTP, // NAVSUGGEST |
| 205 IDR_OMNIBOX_SEARCH, // SEARCH_WHAT_YOU_TYPED |
| 206 IDR_OMNIBOX_HISTORY, // SEARCH_HISTORY |
| 207 IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST |
| 208 IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST_ENTITY |
| 209 IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST_TAIL |
| 210 IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST_PERSONALIZED |
| 211 IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST_PROFILE |
| 212 IDR_OMNIBOX_SEARCH, // SEARCH_OTHER_ENGINE |
| 213 IDR_OMNIBOX_EXTENSION_APP, // EXTENSION_APP |
| 214 IDR_OMNIBOX_SEARCH, // CONTACT_DEPRECATED |
| 215 IDR_OMNIBOX_HTTP, // BOOKMARK_TITLE |
| 216 IDR_OMNIBOX_HTTP, // NAVSUGGEST_PERSONALIZED |
| 217 IDR_OMNIBOX_CALCULATOR, // CALCULATOR |
| 218 IDR_OMNIBOX_HTTP, // CLIPBOARD |
| 219 IDR_OMNIBOX_SEARCH, // VOICE_SEARCH |
| 220 IDR_OMNIBOX_HTTP, // PHYSICAL_WEB |
| 221 IDR_OMNIBOX_HTTP, // PHYSICAL_WEB_OVERFLOW |
| 222 }; |
| 223 #endif |
| 224 static_assert(arraysize(kIcons) == AutocompleteMatchType::NUM_TYPES, |
| 225 "icons array must have NUM_TYPES elements"); |
| 226 return kIcons[type]; |
| 227 } |
| 228 |
| 229 // static |
169 gfx::VectorIconId AutocompleteMatch::TypeToVectorIcon(Type type) { | 230 gfx::VectorIconId AutocompleteMatch::TypeToVectorIcon(Type type) { |
170 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 231 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
171 static const gfx::VectorIconId kIcons[] = { | 232 static const gfx::VectorIconId kIcons[] = { |
172 gfx::VectorIconId::OMNIBOX_HTTP, // URL_WHAT_YOU_TYPE | 233 gfx::VectorIconId::OMNIBOX_HTTP, // URL_WHAT_YOU_TYPE |
173 gfx::VectorIconId::OMNIBOX_HTTP, // HISTORY_URL | 234 gfx::VectorIconId::OMNIBOX_HTTP, // HISTORY_URL |
174 gfx::VectorIconId::OMNIBOX_HTTP, // HISTORY_TITLE | 235 gfx::VectorIconId::OMNIBOX_HTTP, // HISTORY_TITLE |
175 gfx::VectorIconId::OMNIBOX_HTTP, // HISTORY_BODY | 236 gfx::VectorIconId::OMNIBOX_HTTP, // HISTORY_BODY |
176 gfx::VectorIconId::OMNIBOX_HTTP, // HISTORY_KEYWORD | 237 gfx::VectorIconId::OMNIBOX_HTTP, // HISTORY_KEYWORD |
177 gfx::VectorIconId::OMNIBOX_HTTP, // NAVSUGGEST | 238 gfx::VectorIconId::OMNIBOX_HTTP, // NAVSUGGEST |
178 gfx::VectorIconId::OMNIBOX_SEARCH, // SEARCH_WHAT_YOU_TYPED | 239 gfx::VectorIconId::OMNIBOX_SEARCH, // SEARCH_WHAT_YOU_TYPED |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 << " is unsorted in relation to last offset of " << last_offset | 663 << " is unsorted in relation to last offset of " << last_offset |
603 << ". Provider: " << provider_name << "."; | 664 << ". Provider: " << provider_name << "."; |
604 DCHECK_LT(i->offset, text.length()) | 665 DCHECK_LT(i->offset, text.length()) |
605 << " Classification of [" << i->offset << "," << text.length() | 666 << " Classification of [" << i->offset << "," << text.length() |
606 << "] is out of bounds for \"" << text << "\". Provider: " | 667 << "] is out of bounds for \"" << text << "\". Provider: " |
607 << provider_name << "."; | 668 << provider_name << "."; |
608 last_offset = i->offset; | 669 last_offset = i->offset; |
609 } | 670 } |
610 } | 671 } |
611 #endif | 672 #endif |
OLD | NEW |