Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: ios/chrome/browser/ui/payments/address_edit_mediator.mm

Issue 2949813003: [Payment Request] Formats phone number and credit card number in editors. (Closed)
Patch Set: Fixed broken tests Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/address_edit_mediator.h" 5 #import "ios/chrome/browser/ui/payments/address_edit_mediator.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/strings/sys_string_conversions.h" 15 #include "base/strings/sys_string_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "components/autofill/core/browser/autofill_address_util.h" 17 #include "components/autofill/core/browser/autofill_address_util.h"
18 #include "components/autofill/core/browser/autofill_country.h" 18 #include "components/autofill/core/browser/autofill_country.h"
19 #include "components/autofill/core/browser/autofill_profile.h" 19 #include "components/autofill/core/browser/autofill_profile.h"
20 #include "components/autofill/core/browser/autofill_type.h" 20 #include "components/autofill/core/browser/autofill_type.h"
21 #include "components/autofill/core/browser/country_combobox_model.h" 21 #include "components/autofill/core/browser/country_combobox_model.h"
22 #include "components/autofill/core/browser/field_types.h" 22 #include "components/autofill/core/browser/field_types.h"
23 #include "components/autofill/core/browser/personal_data_manager.h" 23 #include "components/autofill/core/browser/personal_data_manager.h"
24 #include "components/payments/core/payment_request_data_util.h"
24 #include "components/strings/grit/components_strings.h" 25 #include "components/strings/grit/components_strings.h"
25 #include "ios/chrome/browser/application_context.h" 26 #include "ios/chrome/browser/application_context.h"
26 #include "ios/chrome/browser/payments/payment_request.h" 27 #include "ios/chrome/browser/payments/payment_request.h"
27 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" 28 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h"
28 #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h" 29 #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h"
29 #import "ios/chrome/browser/ui/payments/payment_request_edit_consumer.h" 30 #import "ios/chrome/browser/ui/payments/payment_request_edit_consumer.h"
30 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" 31 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h"
31 #include "ios/chrome/grit/ios_strings.h" 32 #include "ios/chrome/grit/ios_strings.h"
32 #include "third_party/libaddressinput/messages.h" 33 #include "third_party/libaddressinput/messages.h"
33 #include "ui/base/l10n/l10n_util.h" 34 #include "ui/base/l10n/l10n_util.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 #pragma mark - CreditCardEditViewControllerDataSource 113 #pragma mark - CreditCardEditViewControllerDataSource
113 114
114 - (CollectionViewItem*)headerItem { 115 - (CollectionViewItem*)headerItem {
115 return nil; 116 return nil;
116 } 117 }
117 118
118 - (BOOL)shouldHideBackgroundForHeaderItem { 119 - (BOOL)shouldHideBackgroundForHeaderItem {
119 return NO; 120 return NO;
120 } 121 }
121 122
123 - (void)formatValueForEditorField:(EditorField*)field {
124 if (field.autofillUIType == AutofillUITypeProfileHomePhoneWholeNumber) {
125 field.value =
126 base::SysUTF8ToNSString(payments::data_util::FormatPhoneForDisplay(
127 base::SysNSStringToUTF8(field.value),
128 base::SysNSStringToUTF8(self.selectedCountryCode)));
129 }
130 }
131
122 - (UIImage*)iconIdentifyingEditorField:(EditorField*)field { 132 - (UIImage*)iconIdentifyingEditorField:(EditorField*)field {
123 return nil; 133 return nil;
124 } 134 }
125 135
126 #pragma mark - RegionDataLoaderConsumer 136 #pragma mark - RegionDataLoaderConsumer
127 137
128 - (void)regionDataLoaderDidSucceedWithRegions: 138 - (void)regionDataLoaderDidSucceedWithRegions:
129 (NSDictionary<NSString*, NSString*>*)regions { 139 (NSDictionary<NSString*, NSString*>*)regions {
130 // Enable the previously disabled field. 140 // Enable the previously disabled field.
131 self.regionField.enabled = YES; 141 self.regionField.enabled = YES;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 } 302 }
293 } 303 }
294 } 304 }
295 305
296 // Always add phone number field at the end. 306 // Always add phone number field at the end.
297 NSNumber* phoneNumberFieldKey = 307 NSNumber* phoneNumberFieldKey =
298 [NSNumber numberWithInt:AutofillUITypeProfileHomePhoneWholeNumber]; 308 [NSNumber numberWithInt:AutofillUITypeProfileHomePhoneWholeNumber];
299 EditorField* field = self.fieldsMap[phoneNumberFieldKey]; 309 EditorField* field = self.fieldsMap[phoneNumberFieldKey];
300 if (!field) { 310 if (!field) {
301 NSString* value = 311 NSString* value =
302 [self fieldValueFromProfile:self.address 312 self.address
303 fieldType:autofill::PHONE_HOME_WHOLE_NUMBER]; 313 ? base::SysUTF16ToNSString(
314 payments::data_util::GetFormattedPhoneNumberForDisplay(
315 *self.address,
316 GetApplicationContext()->GetApplicationLocale()))
317 : nil;
304 field = [[EditorField alloc] 318 field = [[EditorField alloc]
305 initWithAutofillUIType:AutofillUITypeProfileHomePhoneWholeNumber 319 initWithAutofillUIType:AutofillUITypeProfileHomePhoneWholeNumber
306 fieldType:EditorFieldTypeTextField 320 fieldType:EditorFieldTypeTextField
307 label:l10n_util::GetNSString(IDS_IOS_AUTOFILL_PHONE) 321 label:l10n_util::GetNSString(IDS_IOS_AUTOFILL_PHONE)
308 value:value 322 value:value
309 required:YES]; 323 required:YES];
310 [self.fieldsMap setObject:field forKey:phoneNumberFieldKey]; 324 [self.fieldsMap setObject:field forKey:phoneNumberFieldKey];
311 } 325 }
312 [self.fields addObject:field]; 326 [self.fields addObject:field];
313 327
314 return self.fields; 328 return self.fields;
315 } 329 }
316 330
317 // Takes in an autofill profile and an autofill field type and returns the 331 // Takes in an autofill profile and an autofill field type and returns the
318 // corresponding field value. Returns nil if |profile| is nullptr. 332 // corresponding field value. Returns nil if |profile| is nullptr.
319 - (NSString*)fieldValueFromProfile:(autofill::AutofillProfile*)profile 333 - (NSString*)fieldValueFromProfile:(autofill::AutofillProfile*)profile
320 fieldType:(autofill::ServerFieldType)fieldType { 334 fieldType:(autofill::ServerFieldType)fieldType {
321 return profile ? base::SysUTF16ToNSString(profile->GetInfo( 335 return profile ? base::SysUTF16ToNSString(profile->GetInfo(
322 autofill::AutofillType(fieldType), 336 autofill::AutofillType(fieldType),
323 GetApplicationContext()->GetApplicationLocale())) 337 GetApplicationContext()->GetApplicationLocale()))
324 : nil; 338 : nil;
325 } 339 }
326 340
327 @end 341 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698