| 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/addressinput_util.h" | 15 #include "third_party/libaddressinput/chromium/addressinput_util.h" |
| 16 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da
ta.h" | 16 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_data.h" |
| 17 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fi
eld.h" | 17 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_field.h" |
| 18 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
.h" | 18 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_ui.h" |
| 19 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
_component.h" | 19 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_ui_component.h" |
| 20 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/localizati
on.h" | |
| 21 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 22 | 21 |
| 23 namespace autofill { | 22 namespace autofill { |
| 24 namespace i18ninput { | 23 namespace i18ninput { |
| 25 | 24 |
| 26 namespace { | 25 namespace { |
| 27 | 26 |
| 28 using base::UTF16ToUTF8; | 27 using base::UTF16ToUTF8; |
| 28 using ::i18n::addressinput::AddressData; |
| 29 using ::i18n::addressinput::AddressField; | 29 using ::i18n::addressinput::AddressField; |
| 30 using ::i18n::addressinput::AddressUiComponent; | 30 using ::i18n::addressinput::AddressUiComponent; |
| 31 using ::i18n::addressinput::Localization; | |
| 32 | |
| 33 std::vector<AddressUiComponent> BuildComponents(const std::string& country_code, | |
| 34 std::string* language_code) { | |
| 35 Localization localization; | |
| 36 localization.SetGetter(l10n_util::GetStringUTF8); | |
| 37 std::string not_used; | |
| 38 return ::i18n::addressinput::BuildComponents( | |
| 39 country_code, localization, g_browser_process->GetApplicationLocale(), | |
| 40 language_code == NULL ? ¬_used : language_code); | |
| 41 } | |
| 42 | 31 |
| 43 DetailInput::Length LengthFromHint(AddressUiComponent::LengthHint hint) { | 32 DetailInput::Length LengthFromHint(AddressUiComponent::LengthHint hint) { |
| 44 if (hint == AddressUiComponent::HINT_SHORT) | 33 if (hint == AddressUiComponent::HINT_SHORT) |
| 45 return DetailInput::SHORT; | 34 return DetailInput::SHORT; |
| 46 DCHECK_EQ(hint, AddressUiComponent::HINT_LONG); | 35 DCHECK_EQ(hint, AddressUiComponent::HINT_LONG); |
| 47 return DetailInput::LONG; | 36 return DetailInput::LONG; |
| 48 } | 37 } |
| 49 | 38 |
| 50 } // namespace | 39 } // namespace |
| 51 | 40 |
| 52 void BuildAddressInputs(common::AddressType address_type, | 41 void BuildAddressInputs(common::AddressType address_type, |
| 53 const std::string& country_code, | 42 const std::string& country_code, |
| 54 DetailInputs* inputs, | 43 DetailInputs* inputs, |
| 55 std::string* language_code) { | 44 std::string* language_code) { |
| 56 const std::vector<AddressUiComponent>& components( | 45 std::vector<AddressUiComponent> components( |
| 57 BuildComponents(country_code, language_code)); | 46 ::i18n::addressinput::BuildComponents( |
| 47 country_code, g_browser_process->GetApplicationLocale(), |
| 48 language_code)); |
| 58 | 49 |
| 59 const bool billing = address_type == common::ADDRESS_TYPE_BILLING; | 50 const bool billing = address_type == common::ADDRESS_TYPE_BILLING; |
| 60 | 51 |
| 61 for (size_t i = 0; i < components.size(); ++i) { | 52 for (size_t i = 0; i < components.size(); ++i) { |
| 62 const AddressUiComponent& component = components[i]; | 53 const AddressUiComponent& component = components[i]; |
| 63 ServerFieldType server_type = TypeForField(component.field, address_type); | 54 ServerFieldType server_type = TypeForField(component.field, address_type); |
| 64 DetailInput::Length length = LengthFromHint(component.length_hint); | 55 DetailInput::Length length = LengthFromHint(component.length_hint); |
| 65 base::string16 placeholder = base::UTF8ToUTF16(component.name); | 56 base::string16 placeholder = l10n_util::GetStringUTF16(component.name_id); |
| 66 DetailInput input = { length, server_type, placeholder }; | 57 DetailInput input = { length, server_type, placeholder }; |
| 67 inputs->push_back(input); | 58 inputs->push_back(input); |
| 68 } | 59 } |
| 69 | 60 |
| 70 ServerFieldType server_type = | 61 ServerFieldType server_type = |
| 71 billing ? ADDRESS_BILLING_COUNTRY : ADDRESS_HOME_COUNTRY; | 62 billing ? ADDRESS_BILLING_COUNTRY : ADDRESS_HOME_COUNTRY; |
| 72 base::string16 placeholder_text = | 63 base::string16 placeholder_text = |
| 73 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_COUNTRY); | 64 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_COUNTRY); |
| 74 DetailInput input = { DetailInput::LONG, server_type, placeholder_text }; | 65 DetailInput input = { DetailInput::LONG, server_type, placeholder_text }; |
| 75 inputs->push_back(input); | 66 inputs->push_back(input); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 case ::i18n::addressinput::STREET_ADDRESS: | 129 case ::i18n::addressinput::STREET_ADDRESS: |
| 139 return billing ? ADDRESS_BILLING_STREET_ADDRESS : | 130 return billing ? ADDRESS_BILLING_STREET_ADDRESS : |
| 140 ADDRESS_HOME_STREET_ADDRESS; | 131 ADDRESS_HOME_STREET_ADDRESS; |
| 141 case ::i18n::addressinput::RECIPIENT: | 132 case ::i18n::addressinput::RECIPIENT: |
| 142 return billing ? NAME_BILLING_FULL : NAME_FULL; | 133 return billing ? NAME_BILLING_FULL : NAME_FULL; |
| 143 } | 134 } |
| 144 NOTREACHED(); | 135 NOTREACHED(); |
| 145 return UNKNOWN_TYPE; | 136 return UNKNOWN_TYPE; |
| 146 } | 137 } |
| 147 | 138 |
| 148 bool FieldForType(ServerFieldType server_type, AddressField* field) { | 139 bool FieldForType(ServerFieldType server_type, |
| 140 ::i18n::addressinput::AddressField* field) { |
| 149 switch (server_type) { | 141 switch (server_type) { |
| 150 case ADDRESS_BILLING_COUNTRY: | 142 case ADDRESS_BILLING_COUNTRY: |
| 151 case ADDRESS_HOME_COUNTRY: | 143 case ADDRESS_HOME_COUNTRY: |
| 152 if (field) | 144 if (field) |
| 153 *field = ::i18n::addressinput::COUNTRY; | 145 *field = ::i18n::addressinput::COUNTRY; |
| 154 return true; | 146 return true; |
| 155 case ADDRESS_BILLING_STATE: | 147 case ADDRESS_BILLING_STATE: |
| 156 case ADDRESS_HOME_STATE: | 148 case ADDRESS_HOME_STATE: |
| 157 if (field) | 149 if (field) |
| 158 *field = ::i18n::addressinput::ADMIN_AREA; | 150 *field = ::i18n::addressinput::ADMIN_AREA; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 if (field) | 183 if (field) |
| 192 *field = ::i18n::addressinput::RECIPIENT; | 184 *field = ::i18n::addressinput::RECIPIENT; |
| 193 return true; | 185 return true; |
| 194 default: | 186 default: |
| 195 return false; | 187 return false; |
| 196 } | 188 } |
| 197 } | 189 } |
| 198 | 190 |
| 199 } // namespace i18ninput | 191 } // namespace i18ninput |
| 200 } // namespace autofill | 192 } // namespace autofill |
| OLD | NEW |