OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #import "ios/chrome/browser/ui/payments/contact_info_edit_mediator.h" | 5 #import "ios/chrome/browser/ui/payments/contact_info_edit_mediator.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #include "components/autofill/core/browser/autofill_country.h" | 9 #include "components/autofill/core/browser/autofill_country.h" |
10 #include "components/autofill/core/browser/autofill_profile.h" | 10 #include "components/autofill/core/browser/autofill_profile.h" |
11 #include "components/autofill/core/browser/autofill_type.h" | 11 #include "components/autofill/core/browser/autofill_type.h" |
12 #include "components/autofill/core/browser/field_types.h" | 12 #include "components/autofill/core/browser/field_types.h" |
13 #include "components/payments/core/payment_request_data_util.h" | 13 #include "components/payments/core/payment_request_data_util.h" |
14 #include "components/strings/grit/components_strings.h" | 14 #include "components/strings/grit/components_strings.h" |
15 #include "ios/chrome/browser/application_context.h" | |
16 #include "ios/chrome/browser/payments/payment_request.h" | 15 #include "ios/chrome/browser/payments/payment_request.h" |
17 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" | 16 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" |
18 #import "ios/chrome/browser/ui/payments/payment_request_edit_consumer.h" | 17 #import "ios/chrome/browser/ui/payments/payment_request_edit_consumer.h" |
19 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" | 18 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" |
20 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
21 | 20 |
22 #if !defined(__has_feature) || !__has_feature(objc_arc) | 21 #if !defined(__has_feature) || !__has_feature(objc_arc) |
23 #error "This file requires ARC support." | 22 #error "This file requires ARC support." |
24 #endif | 23 #endif |
25 | 24 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } | 72 } |
74 | 73 |
75 - (BOOL)shouldHideBackgroundForHeaderItem { | 74 - (BOOL)shouldHideBackgroundForHeaderItem { |
76 return NO; | 75 return NO; |
77 } | 76 } |
78 | 77 |
79 - (void)formatValueForEditorField:(EditorField*)field { | 78 - (void)formatValueForEditorField:(EditorField*)field { |
80 if (field.autofillUIType == AutofillUITypeProfileHomePhoneWholeNumber) { | 79 if (field.autofillUIType == AutofillUITypeProfileHomePhoneWholeNumber) { |
81 const std::string countryCode = | 80 const std::string countryCode = |
82 autofill::AutofillCountry::CountryCodeForLocale( | 81 autofill::AutofillCountry::CountryCodeForLocale( |
83 GetApplicationContext()->GetApplicationLocale()); | 82 _paymentRequest->GetApplicationLocale()); |
84 field.value = | 83 field.value = |
85 base::SysUTF8ToNSString(payments::data_util::FormatPhoneForDisplay( | 84 base::SysUTF8ToNSString(payments::data_util::FormatPhoneForDisplay( |
86 base::SysNSStringToUTF8(field.value), countryCode)); | 85 base::SysNSStringToUTF8(field.value), countryCode)); |
87 } | 86 } |
88 } | 87 } |
89 | 88 |
90 - (UIImage*)iconIdentifyingEditorField:(EditorField*)field { | 89 - (UIImage*)iconIdentifyingEditorField:(EditorField*)field { |
91 return nil; | 90 return nil; |
92 } | 91 } |
93 | 92 |
(...skipping 18 matching lines...) Expand all Loading... |
112 nameField.returnKeyType = UIReturnKeyDone; | 111 nameField.returnKeyType = UIReturnKeyDone; |
113 } | 112 } |
114 [self.fields addObject:nameField]; | 113 [self.fields addObject:nameField]; |
115 } | 114 } |
116 | 115 |
117 if (_paymentRequest->request_payer_phone()) { | 116 if (_paymentRequest->request_payer_phone()) { |
118 NSString* phone = | 117 NSString* phone = |
119 self.profile | 118 self.profile |
120 ? base::SysUTF16ToNSString( | 119 ? base::SysUTF16ToNSString( |
121 payments::data_util::GetFormattedPhoneNumberForDisplay( | 120 payments::data_util::GetFormattedPhoneNumberForDisplay( |
122 *self.profile, | 121 *self.profile, _paymentRequest->GetApplicationLocale())) |
123 GetApplicationContext()->GetApplicationLocale())) | |
124 : nil; | 122 : nil; |
125 EditorField* phoneField = [[EditorField alloc] | 123 EditorField* phoneField = [[EditorField alloc] |
126 initWithAutofillUIType:AutofillUITypeProfileHomePhoneWholeNumber | 124 initWithAutofillUIType:AutofillUITypeProfileHomePhoneWholeNumber |
127 fieldType:EditorFieldTypeTextField | 125 fieldType:EditorFieldTypeTextField |
128 label:l10n_util::GetNSString( | 126 label:l10n_util::GetNSString( |
129 IDS_PAYMENTS_PHONE_FIELD_IN_CONTACT_DETAILS) | 127 IDS_PAYMENTS_PHONE_FIELD_IN_CONTACT_DETAILS) |
130 value:phone | 128 value:phone |
131 required:YES]; | 129 required:YES]; |
132 phoneField.keyboardType = UIKeyboardTypePhonePad; | 130 phoneField.keyboardType = UIKeyboardTypePhonePad; |
133 if (!_paymentRequest->request_payer_email()) | 131 if (!_paymentRequest->request_payer_email()) |
(...skipping 22 matching lines...) Expand all Loading... |
156 "requested."; | 154 "requested."; |
157 return self.fields; | 155 return self.fields; |
158 } | 156 } |
159 | 157 |
160 // Takes in an autofill profile and an autofill field type and returns the | 158 // Takes in an autofill profile and an autofill field type and returns the |
161 // corresponding field value. Returns nil if |profile| is nullptr. | 159 // corresponding field value. Returns nil if |profile| is nullptr. |
162 - (NSString*)fieldValueFromProfile:(autofill::AutofillProfile*)profile | 160 - (NSString*)fieldValueFromProfile:(autofill::AutofillProfile*)profile |
163 fieldType:(autofill::ServerFieldType)fieldType { | 161 fieldType:(autofill::ServerFieldType)fieldType { |
164 return profile ? base::SysUTF16ToNSString(profile->GetInfo( | 162 return profile ? base::SysUTF16ToNSString(profile->GetInfo( |
165 autofill::AutofillType(fieldType), | 163 autofill::AutofillType(fieldType), |
166 GetApplicationContext()->GetApplicationLocale())) | 164 _paymentRequest->GetApplicationLocale())) |
167 : nil; | 165 : nil; |
168 } | 166 } |
169 | 167 |
170 @end | 168 @end |
OLD | NEW |