| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" | 5 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" |
| 6 | 6 |
| 7 #include "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "components/autofill/core/browser/address_i18n.h" | 10 #include "components/autofill/core/browser/address_i18n.h" |
| 11 #include "components/autofill/core/browser/autofill_profile.h" | 11 #include "components/autofill/core/browser/autofill_profile.h" |
| 12 #include "components/autofill/core/browser/credit_card.h" | 12 #include "components/autofill/core/browser/credit_card.h" |
| 13 #include "components/autofill/core/browser/field_types.h" | 13 #include "components/autofill/core/browser/field_types.h" |
| 14 #include "grit/components_strings.h" | 14 #include "grit/components_strings.h" |
| 15 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_data.h" | 15 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_data.h" |
| 16 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_field.h" | 16 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_field.h" |
| 17 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_ui.h" | 17 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_ui.h" |
| 18 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_ui_component.h" | 18 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_ui_component.h" |
| 19 #include "third_party/libaddressinput/chromium/required_fields.h" | 19 #include "third_party/libaddressinput/chromium/required_fields.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 21 | 21 |
| 22 namespace autofill { | 22 namespace autofill { |
| 23 namespace i18ninput { | 23 namespace i18ninput { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 using base::UTF16ToUTF8; | 27 using base::UTF16ToUTF8; |
| 28 using ::i18n::addressinput::AddressData; | |
| 29 using ::i18n::addressinput::AddressField; | 28 using ::i18n::addressinput::AddressField; |
| 30 using ::i18n::addressinput::AddressUiComponent; | 29 using ::i18n::addressinput::AddressUiComponent; |
| 30 using ::i18n::addressinput::Localization; |
| 31 |
| 32 std::vector<AddressUiComponent> BuildComponents(const std::string& country_code, |
| 33 std::string* language_code) { |
| 34 Localization localization; |
| 35 localization.SetGetter(l10n_util::GetStringUTF8); |
| 36 std::string not_used; |
| 37 return ::i18n::addressinput::BuildComponents( |
| 38 country_code, localization, g_browser_process->GetApplicationLocale(), |
| 39 language_code == NULL ? ¬_used : language_code); |
| 40 } |
| 31 | 41 |
| 32 DetailInput::Length LengthFromHint(AddressUiComponent::LengthHint hint) { | 42 DetailInput::Length LengthFromHint(AddressUiComponent::LengthHint hint) { |
| 33 if (hint == AddressUiComponent::HINT_SHORT) | 43 if (hint == AddressUiComponent::HINT_SHORT) |
| 34 return DetailInput::SHORT; | 44 return DetailInput::SHORT; |
| 35 DCHECK_EQ(hint, AddressUiComponent::HINT_LONG); | 45 DCHECK_EQ(hint, AddressUiComponent::HINT_LONG); |
| 36 return DetailInput::LONG; | 46 return DetailInput::LONG; |
| 37 } | 47 } |
| 38 | 48 |
| 39 } // namespace | 49 } // namespace |
| 40 | 50 |
| 41 void BuildAddressInputs(common::AddressType address_type, | 51 void BuildAddressInputs(common::AddressType address_type, |
| 42 const std::string& country_code, | 52 const std::string& country_code, |
| 43 DetailInputs* inputs, | 53 DetailInputs* inputs, |
| 44 std::string* language_code) { | 54 std::string* language_code) { |
| 45 std::vector<AddressUiComponent> components( | 55 const std::vector<AddressUiComponent>& components( |
| 46 ::i18n::addressinput::BuildComponents( | 56 BuildComponents(country_code, language_code)); |
| 47 country_code, g_browser_process->GetApplicationLocale(), | |
| 48 language_code)); | |
| 49 | 57 |
| 50 const bool billing = address_type == common::ADDRESS_TYPE_BILLING; | 58 const bool billing = address_type == common::ADDRESS_TYPE_BILLING; |
| 51 | 59 |
| 52 for (size_t i = 0; i < components.size(); ++i) { | 60 for (size_t i = 0; i < components.size(); ++i) { |
| 53 const AddressUiComponent& component = components[i]; | 61 const AddressUiComponent& component = components[i]; |
| 54 ServerFieldType server_type = TypeForField(component.field, address_type); | 62 ServerFieldType server_type = TypeForField(component.field, address_type); |
| 55 DetailInput::Length length = LengthFromHint(component.length_hint); | 63 DetailInput::Length length = LengthFromHint(component.length_hint); |
| 56 base::string16 placeholder = l10n_util::GetStringUTF16(component.name_id); | 64 base::string16 placeholder = base::UTF8ToUTF16(component.name); |
| 57 DetailInput input = { length, server_type, placeholder }; | 65 DetailInput input = { length, server_type, placeholder }; |
| 58 inputs->push_back(input); | 66 inputs->push_back(input); |
| 59 } | 67 } |
| 60 | 68 |
| 61 ServerFieldType server_type = | 69 ServerFieldType server_type = |
| 62 billing ? ADDRESS_BILLING_COUNTRY : ADDRESS_HOME_COUNTRY; | 70 billing ? ADDRESS_BILLING_COUNTRY : ADDRESS_HOME_COUNTRY; |
| 63 base::string16 placeholder_text = | 71 base::string16 placeholder_text = |
| 64 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_COUNTRY); | 72 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_COUNTRY); |
| 65 DetailInput input = { DetailInput::LONG, server_type, placeholder_text }; | 73 DetailInput input = { DetailInput::LONG, server_type, placeholder_text }; |
| 66 inputs->push_back(input); | 74 inputs->push_back(input); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 case ::i18n::addressinput::STREET_ADDRESS: | 135 case ::i18n::addressinput::STREET_ADDRESS: |
| 128 return billing ? ADDRESS_BILLING_STREET_ADDRESS : | 136 return billing ? ADDRESS_BILLING_STREET_ADDRESS : |
| 129 ADDRESS_HOME_STREET_ADDRESS; | 137 ADDRESS_HOME_STREET_ADDRESS; |
| 130 case ::i18n::addressinput::RECIPIENT: | 138 case ::i18n::addressinput::RECIPIENT: |
| 131 return billing ? NAME_BILLING_FULL : NAME_FULL; | 139 return billing ? NAME_BILLING_FULL : NAME_FULL; |
| 132 } | 140 } |
| 133 NOTREACHED(); | 141 NOTREACHED(); |
| 134 return UNKNOWN_TYPE; | 142 return UNKNOWN_TYPE; |
| 135 } | 143 } |
| 136 | 144 |
| 137 bool FieldForType(ServerFieldType server_type, | 145 bool FieldForType(ServerFieldType server_type, AddressField* field) { |
| 138 ::i18n::addressinput::AddressField* field) { | |
| 139 switch (server_type) { | 146 switch (server_type) { |
| 140 case ADDRESS_BILLING_COUNTRY: | 147 case ADDRESS_BILLING_COUNTRY: |
| 141 case ADDRESS_HOME_COUNTRY: | 148 case ADDRESS_HOME_COUNTRY: |
| 142 if (field) | 149 if (field) |
| 143 *field = ::i18n::addressinput::COUNTRY; | 150 *field = ::i18n::addressinput::COUNTRY; |
| 144 return true; | 151 return true; |
| 145 case ADDRESS_BILLING_STATE: | 152 case ADDRESS_BILLING_STATE: |
| 146 case ADDRESS_HOME_STATE: | 153 case ADDRESS_HOME_STATE: |
| 147 if (field) | 154 if (field) |
| 148 *field = ::i18n::addressinput::ADMIN_AREA; | 155 *field = ::i18n::addressinput::ADMIN_AREA; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 if (field) | 188 if (field) |
| 182 *field = ::i18n::addressinput::RECIPIENT; | 189 *field = ::i18n::addressinput::RECIPIENT; |
| 183 return true; | 190 return true; |
| 184 default: | 191 default: |
| 185 return false; | 192 return false; |
| 186 } | 193 } |
| 187 } | 194 } |
| 188 | 195 |
| 189 } // namespace i18ninput | 196 } // namespace i18ninput |
| 190 } // namespace autofill | 197 } // namespace autofill |
| OLD | NEW |