| 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/ui/autofill/autofill_dialog_models.h" | 5 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" |
| 6 | 6 |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/autofill/autofill_country.h" | 11 #include "chrome/browser/autofill/autofill_country.h" |
| 12 #include "ui/base/l10n/l10n_util_collator.h" |
| 12 | 13 |
| 13 namespace autofill { | 14 namespace autofill { |
| 14 | 15 |
| 15 SuggestionsMenuModelDelegate::~SuggestionsMenuModelDelegate() {} | 16 SuggestionsMenuModelDelegate::~SuggestionsMenuModelDelegate() {} |
| 16 | 17 |
| 17 // SuggestionsMenuModel ---------------------------------------------------- | 18 // SuggestionsMenuModel ---------------------------------------------------- |
| 18 | 19 |
| 19 SuggestionsMenuModel::SuggestionsMenuModel( | 20 SuggestionsMenuModel::SuggestionsMenuModel( |
| 20 SuggestionsMenuModelDelegate* delegate) | 21 SuggestionsMenuModelDelegate* delegate) |
| 21 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), | 22 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 return 10; | 98 return 10; |
| 98 } | 99 } |
| 99 | 100 |
| 100 string16 YearComboboxModel::GetItemAt(int index) { | 101 string16 YearComboboxModel::GetItemAt(int index) { |
| 101 return base::IntToString16(this_year_ + index); | 102 return base::IntToString16(this_year_ + index); |
| 102 } | 103 } |
| 103 | 104 |
| 104 // CountryComboboxModel -------------------------------------------------------- | 105 // CountryComboboxModel -------------------------------------------------------- |
| 105 | 106 |
| 106 CountryComboboxModel::CountryComboboxModel() { | 107 CountryComboboxModel::CountryComboboxModel() { |
| 107 AutofillCountry::GetAvailableCountries(&country_codes_); | 108 std::vector<std::string> country_codes; |
| 109 AutofillCountry::GetAvailableCountries(&country_codes); |
| 110 std::string app_locale = AutofillCountry::ApplicationLocale(); |
| 111 |
| 112 for (std::vector<std::string>::iterator iter = country_codes.begin(); |
| 113 iter != country_codes.end(); ++iter) { |
| 114 countries_.push_back(new AutofillCountry(*iter, app_locale)); |
| 115 } |
| 116 |
| 117 l10n_util::SortStringsUsingMethod(app_locale, |
| 118 &countries_.get(), |
| 119 &AutofillCountry::name); |
| 108 } | 120 } |
| 109 | 121 |
| 110 CountryComboboxModel::~CountryComboboxModel() {} | 122 CountryComboboxModel::~CountryComboboxModel() {} |
| 111 | 123 |
| 112 int CountryComboboxModel::GetItemCount() const { | 124 int CountryComboboxModel::GetItemCount() const { |
| 113 return country_codes_.size(); | 125 return countries_.size(); |
| 114 } | 126 } |
| 115 | 127 |
| 116 string16 CountryComboboxModel::GetItemAt(int index) { | 128 string16 CountryComboboxModel::GetItemAt(int index) { |
| 129 return countries_[index]->name(); |
| 130 } |
| 131 |
| 132 int CountryComboboxModel::GetDefaultIndex() const { |
| 117 std::string app_locale = AutofillCountry::ApplicationLocale(); | 133 std::string app_locale = AutofillCountry::ApplicationLocale(); |
| 118 const AutofillCountry country(country_codes_[index], app_locale); | 134 std::string country_code = |
| 119 return country.name(); | 135 AutofillCountry::CountryCodeForLocale(app_locale); |
| 136 for (size_t i = 0; i < countries_.size(); ++i) { |
| 137 if (countries_[i]->country_code() == country_code) |
| 138 return i; |
| 139 } |
| 140 NOTREACHED(); |
| 141 return 0; |
| 120 } | 142 } |
| 121 | 143 |
| 122 } // autofill | 144 } // autofill |
| OLD | NEW |