| 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" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 const std::string& country_code, | 53 const std::string& country_code, |
| 54 DetailInputs* inputs, | 54 DetailInputs* inputs, |
| 55 std::string* language_code) { | 55 std::string* language_code) { |
| 56 const std::vector<AddressUiComponent>& components( | 56 const std::vector<AddressUiComponent>& components( |
| 57 BuildComponents(country_code, language_code)); | 57 BuildComponents(country_code, language_code)); |
| 58 | 58 |
| 59 const bool billing = address_type == common::ADDRESS_TYPE_BILLING; | 59 const bool billing = address_type == common::ADDRESS_TYPE_BILLING; |
| 60 | 60 |
| 61 for (size_t i = 0; i < components.size(); ++i) { | 61 for (size_t i = 0; i < components.size(); ++i) { |
| 62 const AddressUiComponent& component = components[i]; | 62 const AddressUiComponent& component = components[i]; |
| 63 ServerFieldType server_type = TypeForField(component.field, address_type); | 63 ServerFieldType server_type = i18n::TypeForField(component.field, billing); |
| 64 DetailInput::Length length = LengthFromHint(component.length_hint); | 64 DetailInput::Length length = LengthFromHint(component.length_hint); |
| 65 base::string16 placeholder = base::UTF8ToUTF16(component.name); | 65 base::string16 placeholder = base::UTF8ToUTF16(component.name); |
| 66 DetailInput input = { length, server_type, placeholder }; | 66 DetailInput input = { length, server_type, placeholder }; |
| 67 inputs->push_back(input); | 67 inputs->push_back(input); |
| 68 } | 68 } |
| 69 | 69 |
| 70 ServerFieldType server_type = | 70 ServerFieldType server_type = |
| 71 billing ? ADDRESS_BILLING_COUNTRY : ADDRESS_HOME_COUNTRY; | 71 billing ? ADDRESS_BILLING_COUNTRY : ADDRESS_HOME_COUNTRY; |
| 72 base::string16 placeholder_text = | 72 base::string16 placeholder_text = |
| 73 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_COUNTRY); | 73 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_COUNTRY); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 for (size_t i = 0; i < arraysize(more_required_fields); ++i) { | 111 for (size_t i = 0; i < arraysize(more_required_fields); ++i) { |
| 112 if (profile.GetInfo(AutofillType(more_required_fields[i]), | 112 if (profile.GetInfo(AutofillType(more_required_fields[i]), |
| 113 app_locale).empty()) { | 113 app_locale).empty()) { |
| 114 return false; | 114 return false; |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 return true; | 118 return true; |
| 119 } | 119 } |
| 120 | 120 |
| 121 ServerFieldType TypeForField(AddressField address_field, | |
| 122 common::AddressType address_type) { | |
| 123 bool billing = address_type == common::ADDRESS_TYPE_BILLING; | |
| 124 switch (address_field) { | |
| 125 case ::i18n::addressinput::COUNTRY: | |
| 126 return billing ? ADDRESS_BILLING_COUNTRY : ADDRESS_HOME_COUNTRY; | |
| 127 case ::i18n::addressinput::ADMIN_AREA: | |
| 128 return billing ? ADDRESS_BILLING_STATE : ADDRESS_HOME_STATE; | |
| 129 case ::i18n::addressinput::LOCALITY: | |
| 130 return billing ? ADDRESS_BILLING_CITY : ADDRESS_HOME_CITY; | |
| 131 case ::i18n::addressinput::DEPENDENT_LOCALITY: | |
| 132 return billing ? ADDRESS_BILLING_DEPENDENT_LOCALITY : | |
| 133 ADDRESS_HOME_DEPENDENT_LOCALITY; | |
| 134 case ::i18n::addressinput::POSTAL_CODE: | |
| 135 return billing ? ADDRESS_BILLING_ZIP : ADDRESS_HOME_ZIP; | |
| 136 case ::i18n::addressinput::SORTING_CODE: | |
| 137 return billing ? ADDRESS_BILLING_SORTING_CODE : ADDRESS_HOME_SORTING_CODE; | |
| 138 case ::i18n::addressinput::STREET_ADDRESS: | |
| 139 return billing ? ADDRESS_BILLING_STREET_ADDRESS : | |
| 140 ADDRESS_HOME_STREET_ADDRESS; | |
| 141 case ::i18n::addressinput::RECIPIENT: | |
| 142 return billing ? NAME_BILLING_FULL : NAME_FULL; | |
| 143 } | |
| 144 NOTREACHED(); | |
| 145 return UNKNOWN_TYPE; | |
| 146 } | |
| 147 | |
| 148 bool FieldForType(ServerFieldType server_type, AddressField* field) { | |
| 149 switch (server_type) { | |
| 150 case ADDRESS_BILLING_COUNTRY: | |
| 151 case ADDRESS_HOME_COUNTRY: | |
| 152 if (field) | |
| 153 *field = ::i18n::addressinput::COUNTRY; | |
| 154 return true; | |
| 155 case ADDRESS_BILLING_STATE: | |
| 156 case ADDRESS_HOME_STATE: | |
| 157 if (field) | |
| 158 *field = ::i18n::addressinput::ADMIN_AREA; | |
| 159 return true; | |
| 160 case ADDRESS_BILLING_CITY: | |
| 161 case ADDRESS_HOME_CITY: | |
| 162 if (field) | |
| 163 *field = ::i18n::addressinput::LOCALITY; | |
| 164 return true; | |
| 165 case ADDRESS_BILLING_DEPENDENT_LOCALITY: | |
| 166 case ADDRESS_HOME_DEPENDENT_LOCALITY: | |
| 167 if (field) | |
| 168 *field = ::i18n::addressinput::DEPENDENT_LOCALITY; | |
| 169 return true; | |
| 170 case ADDRESS_BILLING_SORTING_CODE: | |
| 171 case ADDRESS_HOME_SORTING_CODE: | |
| 172 if (field) | |
| 173 *field = ::i18n::addressinput::SORTING_CODE; | |
| 174 return true; | |
| 175 case ADDRESS_BILLING_ZIP: | |
| 176 case ADDRESS_HOME_ZIP: | |
| 177 if (field) | |
| 178 *field = ::i18n::addressinput::POSTAL_CODE; | |
| 179 return true; | |
| 180 case ADDRESS_BILLING_STREET_ADDRESS: | |
| 181 case ADDRESS_BILLING_LINE1: | |
| 182 case ADDRESS_BILLING_LINE2: | |
| 183 case ADDRESS_HOME_STREET_ADDRESS: | |
| 184 case ADDRESS_HOME_LINE1: | |
| 185 case ADDRESS_HOME_LINE2: | |
| 186 if (field) | |
| 187 *field = ::i18n::addressinput::STREET_ADDRESS; | |
| 188 return true; | |
| 189 case NAME_BILLING_FULL: | |
| 190 case NAME_FULL: | |
| 191 if (field) | |
| 192 *field = ::i18n::addressinput::RECIPIENT; | |
| 193 return true; | |
| 194 default: | |
| 195 return false; | |
| 196 } | |
| 197 } | |
| 198 | |
| 199 } // namespace i18ninput | 121 } // namespace i18ninput |
| 200 } // namespace autofill | 122 } // namespace autofill |
| OLD | NEW |