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

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: merge 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..ccc527bef350d54695ed440a7fd2be44f360c724 100644
--- a/chrome/browser/ui/autofill/country_combobox_model.cc
+++ b/chrome/browser/ui/autofill/country_combobox_model.cc
@@ -4,17 +4,20 @@
#include "chrome/browser/ui/autofill/country_combobox_model.h"
+#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "components/autofill/core/browser/autofill_country.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "ui/base/l10n/l10n_util_collator.h"
+#include "ui/base/models/combobox_model_observer.h"
namespace autofill {
-CountryComboboxModel::CountryComboboxModel(const PersonalDataManager& manager) {
+CountryComboboxModel::CountryComboboxModel(const PersonalDataManager& manager)
+ : default_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 +64,53 @@ bool CountryComboboxModel::IsItemSeparatorAt(int index) {
return !countries_[index];
}
+int CountryComboboxModel::GetDefaultIndex() const {
+ return default_index_;
+}
+
+void CountryComboboxModel::AddObserver(ui::ComboboxModelObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void CountryComboboxModel::RemoveObserver(ui::ComboboxModelObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+void CountryComboboxModel::ResetDefault() {
+ SetDefaultIndex(0);
+}
+
+void CountryComboboxModel::SetDefaultCountry(const std::string& country_code) {
+ DCHECK_EQ(2U, country_code.length());
+
+ if (country_code == GetDefaultCountryCode())
Evan Stade 2014/01/15 23:12:29 I don't know if you missed, disagreed with, or wha
Dan Beam 2014/01/16 01:39:13 Done.
+ return;
+
+ for (size_t i = 0; i < countries_.size(); ++i) {
+ if (countries_[i] && countries_[i]->country_code() == country_code) {
+ SetDefaultIndex(i);
+ return;
+ }
+ }
+
+ NOTREACHED();
+}
+
+std::string CountryComboboxModel::GetDefaultCountryCode() const {
+ return countries_[default_index_]->country_code();
+}
+
+void CountryComboboxModel::SetDefaultIndex(int index) {
+ DCHECK_GE(index, 0);
+ DCHECK_LT(index, static_cast<int>(countries_.size()));
+ DCHECK(!IsItemSeparatorAt(index));
+
+ if (index == default_index_)
+ return;
+
+ default_index_ = index;
+ FOR_EACH_OBSERVER(ui::ComboboxModelObserver, observers_,
+ OnComboboxModelChanged(this));
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698