OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/autofill/country_combobox_model.h" | |
6 | |
7 #include "chrome/browser/autofill/autofill_country.h" | |
8 #include "ui/base/l10n/l10n_util_collator.h" | |
9 | |
10 namespace autofill { | |
11 | |
12 CountryComboboxModel::CountryComboboxModel() { | |
13 std::vector<std::string> country_codes; | |
14 AutofillCountry::GetAvailableCountries(&country_codes); | |
15 | |
16 std::string app_locale = AutofillCountry::ApplicationLocale(); | |
17 | |
18 for (std::vector<std::string>::iterator iter = country_codes.begin(); | |
19 iter != country_codes.end(); ++iter) { | |
20 countries_.push_back(new AutofillCountry(*iter, app_locale)); | |
21 } | |
22 | |
23 l10n_util::SortStringsUsingMethod(app_locale, | |
24 &countries_.get(), | |
25 &AutofillCountry::name); | |
26 | |
27 // The separator item. | |
28 countries_.insert(countries_.begin(), NULL); | |
29 // Insert the default country at the top as well as in the ordered list. | |
30 std::string default_country_code = | |
31 AutofillCountry::CountryCodeForLocale(app_locale); | |
32 countries_.insert(countries_.begin(), | |
33 new AutofillCountry(default_country_code, app_locale)); | |
34 // The empty item. | |
35 countries_.insert(countries_.begin(), NULL); | |
Ilya Sherman
2013/02/26 09:57:07
nit: This is a little hard to follow, since it's i
Evan Stade
2013/02/26 19:01:40
Done.
| |
36 } | |
37 | |
38 CountryComboboxModel::~CountryComboboxModel() {} | |
39 | |
40 int CountryComboboxModel::GetItemCount() const { | |
41 return countries_.size(); | |
42 } | |
43 | |
44 string16 CountryComboboxModel::GetItemAt(int index) { | |
45 AutofillCountry* country = countries_[index]; | |
46 if (country) | |
47 return countries_[index]->name(); | |
48 | |
49 // The empty item. | |
50 if (index == 0) | |
51 return string16(); | |
52 | |
53 // The separator item. | |
54 return ASCIIToUTF16("---"); | |
55 } | |
56 | |
57 } // namespace autofill | |
OLD | NEW |