Chromium Code Reviews| Index: chrome/browser/ui/autofill/autofill_dialog_input_i18n.cc |
| diff --git a/chrome/browser/ui/autofill/autofill_dialog_input_i18n.cc b/chrome/browser/ui/autofill/autofill_dialog_input_i18n.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5b27cbebc3bfb2b9d49e86a00d98d5498a2e2513 |
| --- /dev/null |
| +++ b/chrome/browser/ui/autofill/autofill_dialog_input_i18n.cc |
| @@ -0,0 +1,141 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/autofill/autofill_dialog_input_i18n.h" |
| + |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/ui/autofill/autofill_dialog_common.h" |
| +#include "grit/component_strings.h" |
| +#include "grit/generated_resources.h" |
| + |
| +namespace autofill { |
| +namespace common { |
| + |
| +namespace { |
| + |
| +void GetLanguageAndCountryRegionFromApplicationLocale( |
| + std::string* language, |
| + std::string* country_region) { |
| + DCHECK(g_browser_process); |
| + const std::string& locale = g_browser_process->GetApplicationLocale(); |
| + *language = locale.substr(0, locale.find('-')); |
| + if (!country_region) |
| + return; |
| + const size_t country_region_pos = language->length() + 1; |
| + if (locale.length() <= country_region_pos) { |
| + *country_region = "US"; |
| + return; |
| + } |
| + *country_region = locale.substr(country_region_pos); |
| +} |
| + |
| +} // namespace |
| + |
| +AutofillDialogInputI18n::AutofillDialogInputI18n() {} |
| + |
| +AutofillDialogInputI18n::~AutofillDialogInputI18n() {} |
| + |
| +void AutofillDialogInputI18n::BuildInputsForSection( |
| + DialogSection dialog_section, |
| + DetailInputs* inputs) { |
| + std::string language; |
| + std::string country_region; |
| + GetLanguageAndCountryRegionFromApplicationLocale(&language, &country_region); |
| + BuildLocalizedInputs(dialog_section, language, country_region, inputs); |
| +} |
| + |
| +void AutofillDialogInputI18n::BuildInputsForSection( |
| + DialogSection dialog_section, |
| + const std::string& selected_country_region, |
| + DetailInputs* inputs) { |
| + std::string language; |
| + GetLanguageAndCountryRegionFromApplicationLocale(&language, NULL); |
| + BuildLocalizedInputs( |
| + dialog_section, language, selected_country_region, inputs); |
| +} |
| + |
| +// static |
| +ServerFieldType AutofillDialogInputI18n::GetFieldType( |
|
Evan Stade
2013/10/02 00:57:19
AutofillType::GetEquivalentBillingFieldType
|
| + AddressType address_type, |
| + ServerFieldType field_type) { |
| + switch (field_type) { |
| + case ADDRESS_HOME_LINE1: |
| + return address_type == ADDRESS_TYPE_SHIPPING ? field_type |
| + : ADDRESS_BILLING_LINE1; |
| + case ADDRESS_HOME_LINE2: |
| + return address_type == ADDRESS_TYPE_SHIPPING ? field_type |
| + : ADDRESS_BILLING_LINE2; |
| + case ADDRESS_HOME_CITY: |
| + return address_type == ADDRESS_TYPE_SHIPPING ? field_type |
| + : ADDRESS_BILLING_CITY; |
| + case ADDRESS_HOME_STATE: |
| + return address_type == ADDRESS_TYPE_SHIPPING ? field_type |
| + : ADDRESS_BILLING_STATE; |
| + case ADDRESS_HOME_ZIP: |
| + return address_type == ADDRESS_TYPE_SHIPPING ? field_type |
| + : ADDRESS_BILLING_ZIP; |
| + case ADDRESS_HOME_COUNTRY: |
| + return address_type == ADDRESS_TYPE_SHIPPING ? field_type |
| + : ADDRESS_BILLING_COUNTRY; |
| + default: |
| + NOTREACHED(); |
| + return field_type; |
| + } |
| +} |
| + |
| +void AutofillDialogInputI18n::BuildLocalizedInputs( |
| + DialogSection dialog_section, |
| + const std::string& language, |
| + const std::string& country_region, |
| + DetailInputs* inputs) { |
| + if (dialog_section == SECTION_CC || dialog_section == SECTION_CC_BILLING) |
| + ::autofill::common::BuildInputsForSection(SECTION_CC, inputs); |
| + |
| + int field_row = 3; |
| + if (dialog_section == SECTION_BILLING || |
| + dialog_section == SECTION_CC_BILLING) { |
| + inputs->push_back({field_row++, NAME_BILLING_FULL, |
| + IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME}); |
| + field_row = BuildAddressInputs( |
| + ADDRESS_TYPE_BILLING, field_row, language, country_region, inputs); |
| + inputs->push_back({field_row++, PHONE_BILLING_WHOLE_NUMBER, |
| + IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER}); |
| + inputs->push_back( |
| + {field_row++, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL}); |
| + } |
| + |
| + if (dialog_section == SECTION_SHIPPING) { |
| + inputs->push_back({field_row++, NAME_FULL, |
| + IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME}); |
| + field_row = BuildAddressInputs( |
| + ADDRESS_TYPE_SHIPPING, field_row, language, country_region, inputs); |
| + inputs->push_back({field_row++, PHONE_HOME_WHOLE_NUMBER, |
| + IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER}); |
| + } |
| +} |
| + |
| +int AutofillDialogInputI18n::BuildAddressInputs( |
| + AddressType type, |
| + int field_row, |
| + const std::string& language, |
| + const std::string& country_region, |
| + DetailInputs* inputs) { |
| + // Language and country/region parameters are ignored until libaddressinput is |
| + // integrated. |
| + inputs->push_back({field_row++, GetFieldType(type, ADDRESS_HOME_LINE1), |
| + IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1}); |
| + inputs->push_back({field_row++, GetFieldType(type, ADDRESS_HOME_LINE2), |
| + IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2}); |
| + inputs->push_back({field_row++, GetFieldType(type, ADDRESS_HOME_CITY), |
| + IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY}); |
| + inputs->push_back({field_row, GetFieldType(type, ADDRESS_HOME_STATE), |
| + IDS_AUTOFILL_FIELD_LABEL_STATE}); |
| + inputs->push_back({field_row++, GetFieldType(type, ADDRESS_HOME_ZIP), |
| + IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE}); |
| + inputs->push_back({field_row++, GetFieldType(type, ADDRESS_HOME_COUNTRY)}); |
| + return field_row; |
| +} |
| + |
| +} // namespace common |
| +} // namespace autofill |