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

Unified Diff: chrome/browser/autofill/address.cc

Issue 6484022: Autofill i18n: Set postal code and state field labels based on the selected country. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Properly merged with ToT Created 9 years, 10 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
« no previous file with comments | « chrome/browser/autofill/address.h ('k') | chrome/browser/autofill/address_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autofill/address.cc
diff --git a/chrome/browser/autofill/address.cc b/chrome/browser/autofill/address.cc
index 7465279b25822ad869c9acb94441ee662f05e7b4..67c17839ddffe5741965cb6d9339337e5692a5e0 100644
--- a/chrome/browser/autofill/address.cc
+++ b/chrome/browser/autofill/address.cc
@@ -6,6 +6,7 @@
#include "base/basictypes.h"
#include "base/string_util.h"
+#include "chrome/browser/autofill/autofill_country.h"
#include "chrome/browser/autofill/autofill_type.h"
#include "chrome/browser/autofill/field_types.h"
@@ -80,7 +81,7 @@ void Address::GetAvailableFieldTypes(FieldTypeSet* available_types) const {
if (!zip_code_.empty())
available_types->insert(ADDRESS_HOME_ZIP);
- if (!country_.empty())
+ if (!country_code_.empty())
available_types->insert(ADDRESS_HOME_COUNTRY);
}
@@ -119,7 +120,7 @@ string16 Address::GetFieldText(const AutoFillType& type) const {
return zip_code_;
if (field_type == ADDRESS_HOME_COUNTRY)
- return country_;
+ return Country();
return string16();
}
@@ -135,7 +136,7 @@ void Address::SetInfo(const AutoFillType& type, const string16& value) {
else if (subgroup == AutoFillType::ADDRESS_STATE)
state_ = value;
else if (subgroup == AutoFillType::ADDRESS_COUNTRY)
- country_ = value;
+ SetCountry(value);
else if (subgroup == AutoFillType::ADDRESS_ZIP)
zip_code_ = value;
else
@@ -149,7 +150,7 @@ void Address::Clear() {
line2_.clear();
city_.clear();
state_.clear();
- country_.clear();
+ country_code_.clear();
zip_code_.clear();
}
@@ -161,10 +162,18 @@ Address::Address(const Address& address)
line2_(address.line2_),
city_(address.city_),
state_(address.state_),
- country_(address.country_),
+ country_code_(address.country_code_),
zip_code_(address.zip_code_) {
}
+string16 Address::Country() const {
+ if (country_code().empty())
+ return string16();
+
+ std::string app_locale = AutoFillCountry::ApplicationLocale();
+ return AutoFillCountry(country_code(), app_locale).name();
+}
+
void Address::set_line1(const string16& line1) {
line1_ = line1;
line1_tokens_.clear();
@@ -183,6 +192,11 @@ void Address::set_line2(const string16& line2) {
*iter = StringToLowerASCII(*iter);
}
+void Address::SetCountry(const string16& country) {
+ std::string app_locale = AutoFillCountry::ApplicationLocale();
+ country_code_ = AutoFillCountry::GetCountryCode(country, app_locale);
+}
+
bool Address::IsLine1(const string16& text) const {
return IsLineMatch(text, line1_tokens_);
}
@@ -200,7 +214,9 @@ bool Address::IsState(const string16& text) const {
}
bool Address::IsCountry(const string16& text) const {
- return (StringToLowerASCII(country_) == StringToLowerASCII(text));
+ std::string app_locale = AutoFillCountry::ApplicationLocale();
+ std::string country_code = AutoFillCountry::GetCountryCode(text, app_locale);
+ return (!country_code.empty() && country_code_ == country_code);
}
bool Address::IsZipCode(const string16& text) const {
@@ -226,8 +242,8 @@ bool Address::FindInfoMatchesHelper(const FieldTypeSubGroup& subgroup,
StartsWith(state_, info, false)) {
*match = state_;
} else if (subgroup == AutoFillType::ADDRESS_COUNTRY &&
- StartsWith(country_, info, false)) {
- *match = country_;
+ StartsWith(Country(), info, false)) {
+ *match = Country();
} else if (subgroup == AutoFillType::ADDRESS_ZIP &&
StartsWith(zip_code_, info, true)) {
*match = zip_code_;
« no previous file with comments | « chrome/browser/autofill/address.h ('k') | chrome/browser/autofill/address_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698