Index: chrome/browser/ui/autofill/autofill_dialog_common.cc |
diff --git a/chrome/browser/ui/autofill/autofill_dialog_common.cc b/chrome/browser/ui/autofill/autofill_dialog_common.cc |
index 4391a6b0d18d94711069617aaa590d3ce8457c76..4c558d7f11cfc6ba47d16a893f8165d3d89d3f1f 100644 |
--- a/chrome/browser/ui/autofill/autofill_dialog_common.cc |
+++ b/chrome/browser/ui/autofill/autofill_dialog_common.cc |
@@ -5,6 +5,7 @@ |
#include "chrome/browser/ui/autofill/autofill_dialog_common.h" |
#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" |
#include "components/autofill/core/browser/autofill_country.h" |
#include "components/autofill/core/browser/autofill_field.h" |
#include "components/autofill/core/browser/autofill_type.h" |
@@ -17,6 +18,14 @@ |
namespace autofill { |
namespace common { |
+namespace { |
+ |
+const std::string& GetLocale() { |
+ return g_browser_process->GetApplicationLocale(); |
+} |
+ |
+} // namespace |
+ |
// Returns true if |input| should be shown when |field_type| has been requested. |
bool InputTypeMatchesFieldType(const DetailInput& input, |
const AutofillType& field_type) { |
@@ -71,9 +80,9 @@ void BuildInputs(const DetailInput* input_template, |
} |
} |
-// Constructs |inputs| from template data for a given |dialog_section|. |
void BuildInputsForSection(DialogSection dialog_section, |
- DetailInputs* inputs) { |
+ DetailInputs* inputs, |
+ const std::string& country_region) { |
const DetailInput kCCInputs[] = { |
{ 1, CREDIT_CARD_NUMBER, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER }, |
{ 2, CREDIT_CARD_EXP_MONTH, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH }, |
@@ -83,6 +92,7 @@ void BuildInputsForSection(DialogSection dialog_section, |
1.5 }, |
}; |
+ const int kBillingInputsStartRow = 3; |
const DetailInput kBillingInputs[] = { |
{ 3, NAME_BILLING_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME }, |
{ 4, ADDRESS_BILLING_LINE1, |
@@ -91,29 +101,32 @@ void BuildInputsForSection(DialogSection dialog_section, |
IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, |
{ 6, ADDRESS_BILLING_CITY, |
IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, |
- // TODO(estade): state placeholder should depend on locale. |
{ 7, ADDRESS_BILLING_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, |
{ 7, ADDRESS_BILLING_ZIP, |
IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, |
- // We don't allow the user to change the country: http://crbug.com/247518 |
- { -1, ADDRESS_BILLING_COUNTRY, 0 }, |
- { 9, PHONE_BILLING_WHOLE_NUMBER, |
+ }; |
+ |
+ const DetailInput kBillingPhoneInputs[] = { |
+ { 19, PHONE_BILLING_WHOLE_NUMBER, |
IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, |
}; |
const DetailInput kEmailInputs[] = { |
- { 10, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, |
+ { 20, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, |
}; |
+ const int kShippingInputsStartRow = 21; |
const DetailInput kShippingInputs[] = { |
- { 11, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME }, |
- { 12, ADDRESS_HOME_LINE1, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, |
- { 13, ADDRESS_HOME_LINE2, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, |
- { 14, ADDRESS_HOME_CITY, IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, |
- { 15, ADDRESS_HOME_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, |
- { 15, ADDRESS_HOME_ZIP, IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, |
- { -1, ADDRESS_HOME_COUNTRY, 0 }, |
- { 17, PHONE_HOME_WHOLE_NUMBER, |
+ { 21, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME }, |
+ { 22, ADDRESS_HOME_LINE1, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, |
+ { 23, ADDRESS_HOME_LINE2, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, |
+ { 24, ADDRESS_HOME_CITY, IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, |
+ { 25, ADDRESS_HOME_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, |
+ { 25, ADDRESS_HOME_ZIP, IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, |
+ }; |
+ |
+ const DetailInput kShippingPhoneInputs[] = { |
+ { 37, PHONE_HOME_WHOLE_NUMBER, |
IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, |
}; |
@@ -123,17 +136,42 @@ void BuildInputsForSection(DialogSection dialog_section, |
break; |
case SECTION_BILLING: |
- BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); |
+ if (i18ninput::IsI18nAddressInputEnabled()) { |
+ i18ninput::BuildI18nInputs(i18ninput::ADDRESS_TYPE_BILLING, |
+ country_region, |
+ kBillingInputsStartRow, |
+ inputs); |
+ } else { |
+ BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); |
+ } |
+ BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); |
BuildInputs(kEmailInputs, arraysize(kEmailInputs), inputs); |
break; |
case SECTION_CC_BILLING: |
BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); |
- BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); |
+ if (i18ninput::IsI18nAddressInputEnabled()) { |
+ i18ninput::BuildI18nInputs(i18ninput::ADDRESS_TYPE_BILLING, |
+ country_region, |
+ kBillingInputsStartRow, |
+ inputs); |
+ } else { |
+ BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); |
+ } |
+ BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); |
break; |
case SECTION_SHIPPING: |
- BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); |
+ if (i18ninput::IsI18nAddressInputEnabled()) { |
+ i18ninput::BuildI18nInputs(i18ninput::ADDRESS_TYPE_SHIPPING, |
+ country_region, |
+ kShippingInputsStartRow, |
+ inputs); |
+ } else { |
+ BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); |
+ } |
+ BuildInputs( |
+ kShippingPhoneInputs, arraysize(kShippingPhoneInputs), inputs); |
break; |
} |
} |
@@ -178,13 +216,19 @@ AutofillMetrics::DialogUiEvent DialogSectionToUiSelectionChangedEvent( |
return AutofillMetrics::NUM_DIALOG_UI_EVENTS; |
} |
-string16 GetHardcodedValueForType(ServerFieldType type) { |
- if (AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY) { |
- AutofillCountry country("US", g_browser_process->GetApplicationLocale()); |
- return country.name(); |
- } |
+base::string16 GetInitialValueForType(ServerFieldType type, |
+ const std::string& country_code) { |
+ if (AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY) |
+ return GetCountryName(country_code); |
+ return base::string16(); |
+} |
+ |
+base::string16 GetCountryName(const std::string& country_code) { |
+ return AutofillCountry(country_code, GetLocale()).name(); |
+} |
- return string16(); |
+std::string GetCountryCode(const base::string16& country_name) { |
Evan Stade
2013/11/25 19:52:06
I don't think these 2 functions are particularly n
Dan Beam
2013/11/28 02:52:45
Done.
|
+ return AutofillCountry::GetCountryCode(country_name, GetLocale()); |
} |
} // namespace common |