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 // Insert the default country at the top as well as in the ordered list. |
| 14 std::string app_locale = AutofillCountry::ApplicationLocale(); |
| 15 std::string default_country_code = |
| 16 AutofillCountry::CountryCodeForLocale(app_locale); |
| 17 countries_.push_back(new AutofillCountry(default_country_code, app_locale)); |
| 18 // The separator item. |
| 19 countries_.push_back(NULL); |
| 20 |
| 21 // The sorted list of countries. |
| 22 std::vector<std::string> country_codes; |
| 23 AutofillCountry::GetAvailableCountries(&country_codes); |
| 24 std::vector<AutofillCountry*> sorted_countries; |
| 25 |
| 26 for (std::vector<std::string>::iterator iter = country_codes.begin(); |
| 27 iter != country_codes.end(); ++iter) { |
| 28 sorted_countries.push_back(new AutofillCountry(*iter, app_locale)); |
| 29 } |
| 30 |
| 31 l10n_util::SortStringsUsingMethod(app_locale, |
| 32 &sorted_countries, |
| 33 &AutofillCountry::name); |
| 34 countries_.insert(countries_.end(), |
| 35 sorted_countries.begin(), |
| 36 sorted_countries.end()); |
| 37 } |
| 38 |
| 39 CountryComboboxModel::~CountryComboboxModel() {} |
| 40 |
| 41 int CountryComboboxModel::GetItemCount() const { |
| 42 return countries_.size(); |
| 43 } |
| 44 |
| 45 string16 CountryComboboxModel::GetItemAt(int index) { |
| 46 AutofillCountry* country = countries_[index]; |
| 47 if (country) |
| 48 return countries_[index]->name(); |
| 49 |
| 50 // The separator item. |
| 51 return ASCIIToUTF16("---"); |
| 52 } |
| 53 |
| 54 } // namespace autofill |
OLD | NEW |