Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3121)

Unified Diff: chrome/browser/ui/autofill/country_combobox_model.cc

Issue 124533003: Add country combobox to change country and rebuild address inputs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/autofill/country_combobox_model.cc
diff --git a/chrome/browser/ui/autofill/country_combobox_model.cc b/chrome/browser/ui/autofill/country_combobox_model.cc
index 8962b8261f3ba65fcae4294481bf067cbabd097b..b05bef30906a48c65ec5b7549835b5a20607fb79 100644
--- a/chrome/browser/ui/autofill/country_combobox_model.cc
+++ b/chrome/browser/ui/autofill/country_combobox_model.cc
@@ -12,9 +12,10 @@
namespace autofill {
-CountryComboboxModel::CountryComboboxModel(const PersonalDataManager& manager) {
+CountryComboboxModel::CountryComboboxModel(const PersonalDataManager& manager)
+ : selected_index_(0) {
// Insert the default country at the top as well as in the ordered list.
- std::string app_locale = g_browser_process->GetApplicationLocale();
+ const std::string& app_locale = g_browser_process->GetApplicationLocale();
std::string default_country_code =
manager.GetDefaultCountryCodeForNewAddress();
DCHECK(!default_country_code.empty());
@@ -61,4 +62,34 @@ bool CountryComboboxModel::IsItemSeparatorAt(int index) {
return !countries_[index];
}
+void CountryComboboxModel::SelectIndex(int index) {
+ DCHECK_GE(index, 0);
+ DCHECK_LT(index, static_cast<int>(countries_.size()));
+ DCHECK(!IsItemSeparatorAt(index));
+ selected_index_ = index;
+}
+
+void CountryComboboxModel::SelectDefaultIndex() {
+ SelectIndex(GetDefaultIndex());
+}
+
+void CountryComboboxModel::SelectCountry(const std::string& country_code) {
+ DCHECK_EQ(2U, country_code.length());
+ for (size_t i = 0; i < countries_.size(); ++i) {
+ if (countries_[i] && countries_[i]->country_code() == country_code) {
+ SelectIndex(i);
+ return;
+ }
+ }
+ NOTREACHED();
+}
+
+std::string CountryComboboxModel::GetSelectedCountryCode() const {
+ return countries_[selected_index_]->country_code();
+}
+
+bool CountryComboboxModel::IsDefaultIndexSelected() const {
+ return selected_index_ == GetDefaultIndex();
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698