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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
10 #include "components/autofill/core/browser/field_types.h" | 10 #include "components/autofill/core/browser/field_types.h" |
11 #include "grit/component_strings.h" | 11 #include "grit/component_strings.h" |
12 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fi
eld.h" | 12 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_field.h" |
13 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
.h" | 13 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_ui.h" |
14 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
_component.h" | 14 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_ui_component.h" |
15 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/localizati
on.h" | |
16 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
17 | 16 |
18 namespace autofill { | 17 namespace autofill { |
19 namespace i18ninput { | 18 namespace i18ninput { |
20 | 19 |
21 namespace { | 20 namespace { |
22 | 21 |
23 using i18n::addressinput::AddressField; | 22 using i18n::addressinput::AddressField; |
24 using i18n::addressinput::AddressUiComponent; | 23 using i18n::addressinput::AddressUiComponent; |
25 | 24 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 } // namespace | 58 } // namespace |
60 | 59 |
61 bool Enabled() { | 60 bool Enabled() { |
62 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 61 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
63 return command_line->HasSwitch(::switches::kEnableAutofillAddressI18n); | 62 return command_line->HasSwitch(::switches::kEnableAutofillAddressI18n); |
64 } | 63 } |
65 | 64 |
66 void BuildAddressInputs(common::AddressType address_type, | 65 void BuildAddressInputs(common::AddressType address_type, |
67 const std::string& country_code, | 66 const std::string& country_code, |
68 DetailInputs* inputs) { | 67 DetailInputs* inputs) { |
69 i18n::addressinput::Localization localization; | |
70 // TODO(dbeam): figure out how to include libaddressinput's translations into | |
71 // some .pak file so I can call |SetGetter(&l10n_util::GetStringUTF8)| here. | |
72 std::vector<AddressUiComponent> components( | 68 std::vector<AddressUiComponent> components( |
73 i18n::addressinput::BuildComponents(country_code, localization)); | 69 i18n::addressinput::BuildComponents(country_code)); |
74 | 70 |
75 const bool billing = address_type == common::ADDRESS_TYPE_BILLING; | 71 const bool billing = address_type == common::ADDRESS_TYPE_BILLING; |
76 | 72 |
77 for (size_t i = 0; i < components.size(); ++i) { | 73 for (size_t i = 0; i < components.size(); ++i) { |
78 const AddressUiComponent& component = components[i]; | 74 const AddressUiComponent& component = components[i]; |
79 if (component.field == i18n::addressinput::ORGANIZATION) { | 75 if (component.field == i18n::addressinput::ORGANIZATION) { |
80 // TODO(dbeam): figure out when we actually need this. | 76 // TODO(dbeam): figure out when we actually need this. |
81 continue; | 77 continue; |
82 } | 78 } |
83 | 79 |
84 ServerFieldType server_type = GetServerType(component.field, billing); | 80 ServerFieldType server_type = GetServerType(component.field, billing); |
85 DetailInput::Length length = LengthFromHint(component.length_hint); | 81 DetailInput::Length length = LengthFromHint(component.length_hint); |
86 base::string16 placeholder = base::UTF8ToUTF16(component.name); | 82 base::string16 placeholder = l10n_util::GetStringUTF16(component.name_id); |
87 DetailInput input = { length, server_type, placeholder }; | 83 DetailInput input = { length, server_type, placeholder }; |
88 inputs->push_back(input); | 84 inputs->push_back(input); |
89 | 85 |
90 if (component.field == i18n::addressinput::STREET_ADDRESS && | 86 if (component.field == i18n::addressinput::STREET_ADDRESS && |
91 component.length_hint == AddressUiComponent::HINT_LONG) { | 87 component.length_hint == AddressUiComponent::HINT_LONG) { |
92 // TODO(dbeam): support more than 2 address lines. http://crbug.com/324889 | 88 // TODO(dbeam): support more than 2 address lines. http://crbug.com/324889 |
93 ServerFieldType server_type = | 89 ServerFieldType server_type = |
94 billing ? ADDRESS_BILLING_LINE2 : ADDRESS_HOME_LINE2; | 90 billing ? ADDRESS_BILLING_LINE2 : ADDRESS_HOME_LINE2; |
95 base::string16 placeholder = base::UTF8ToUTF16(component.name); | 91 base::string16 placeholder = l10n_util::GetStringUTF16(component.name_id); |
96 DetailInput input = { length, server_type, placeholder }; | 92 DetailInput input = { length, server_type, placeholder }; |
97 inputs->push_back(input); | 93 inputs->push_back(input); |
98 } | 94 } |
99 } | 95 } |
100 | 96 |
101 ServerFieldType server_type = | 97 ServerFieldType server_type = |
102 billing ? ADDRESS_BILLING_COUNTRY : ADDRESS_HOME_COUNTRY; | 98 billing ? ADDRESS_BILLING_COUNTRY : ADDRESS_HOME_COUNTRY; |
103 base::string16 placeholder_text = | 99 base::string16 placeholder_text = |
104 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_COUNTRY); | 100 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_COUNTRY); |
105 // TODO(dbeam): unhide so users can switch countries. http://crbug.com/331544 | 101 // TODO(dbeam): unhide so users can switch countries. http://crbug.com/331544 |
106 DetailInput input = { DetailInput::NONE, server_type, placeholder_text }; | 102 DetailInput input = { DetailInput::NONE, server_type, placeholder_text }; |
107 inputs->push_back(input); | 103 inputs->push_back(input); |
108 } | 104 } |
109 | 105 |
110 } // namespace i18ninput | 106 } // namespace i18ninput |
111 } // namespace autofill | 107 } // namespace autofill |
OLD | NEW |