OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/payments/payment_request_view_controller.h" | 5 #import "ios/chrome/browser/payments/payment_request_view_controller.h" |
6 | 6 |
7 #import "base/ios/weak_nsobject.h" | 7 #import "base/ios/weak_nsobject.h" |
8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
9 #include "base/mac/objc_property_releaser.h" | 9 #include "base/mac/objc_property_releaser.h" |
10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "components/autofill/core/browser/autofill_data_util.h" | 12 #include "components/autofill/core/browser/autofill_data_util.h" |
13 #include "components/autofill/core/browser/autofill_profile.h" | 13 #include "components/autofill/core/browser/autofill_profile.h" |
14 #include "components/autofill/core/browser/credit_card.h" | 14 #include "components/autofill/core/browser/credit_card.h" |
15 #include "components/autofill/core/browser/field_types.h" | 15 #include "components/autofill/core/browser/field_types.h" |
16 #include "components/autofill/core/browser/personal_data_manager.h" | 16 #include "components/autofill/core/browser/personal_data_manager.h" |
| 17 #include "components/strings/grit/components_strings.h" |
17 #include "ios/chrome/browser/application_context.h" | 18 #include "ios/chrome/browser/application_context.h" |
18 #import "ios/chrome/browser/payments/cells/page_info_item.h" | 19 #import "ios/chrome/browser/payments/cells/page_info_item.h" |
19 #import "ios/chrome/browser/payments/cells/payment_method_item.h" | 20 #import "ios/chrome/browser/payments/cells/payment_method_item.h" |
20 #import "ios/chrome/browser/payments/cells/shipping_address_item.h" | 21 #import "ios/chrome/browser/payments/cells/shipping_address_item.h" |
21 #import "ios/chrome/browser/payments/payment_request_utils.h" | 22 #import "ios/chrome/browser/payments/payment_request_utils.h" |
22 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" | 23 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" |
23 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item
.h" | 24 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item
.h" |
24 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 25 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
25 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" | 26 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" |
26 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 27 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
27 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 28 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
28 #include "ios/chrome/browser/ui/rtl_geometry.h" | 29 #include "ios/chrome/browser/ui/rtl_geometry.h" |
29 #include "ios/chrome/grit/ios_strings.h" | 30 #include "ios/chrome/grit/ios_strings.h" |
30 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" | 31 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" |
31 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" | 32 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" |
32 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" | 33 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" |
33 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
34 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
35 | 36 |
| 37 using payment_request_utils::NameLabelFromAutofillProfile; |
| 38 using payment_request_utils::AddressLabelFromAutofillProfile; |
| 39 using payment_request_utils::PhoneNumberLabelFromAutofillProfile; |
| 40 |
36 NSString* const kPaymentRequestCollectionViewId = | 41 NSString* const kPaymentRequestCollectionViewId = |
37 @"kPaymentRequestCollectionViewId"; | 42 @"kPaymentRequestCollectionViewId"; |
38 | 43 |
39 namespace { | 44 namespace { |
40 | 45 |
41 const CGFloat kButtonEdgeInset = 9; | 46 const CGFloat kButtonEdgeInset = 9; |
42 const CGFloat kSeparatorEdgeInset = 14; | 47 const CGFloat kSeparatorEdgeInset = 14; |
43 | 48 |
44 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 49 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
45 SectionIdentifierSummary = kSectionIdentifierEnumZero, | 50 SectionIdentifierSummary = kSectionIdentifierEnumZero, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 _cancelButton.reset([[UIBarButtonItem alloc] | 104 _cancelButton.reset([[UIBarButtonItem alloc] |
100 initWithTitle:l10n_util::GetNSString( | 105 initWithTitle:l10n_util::GetNSString( |
101 IDS_IOS_PAYMENT_REQUEST_CANCEL_BUTTON) | 106 IDS_IOS_PAYMENT_REQUEST_CANCEL_BUTTON) |
102 style:UIBarButtonItemStylePlain | 107 style:UIBarButtonItemStylePlain |
103 target:nil | 108 target:nil |
104 action:@selector(onCancel)]); | 109 action:@selector(onCancel)]); |
105 [_cancelButton setTitleTextAttributes:@{ | 110 [_cancelButton setTitleTextAttributes:@{ |
106 NSForegroundColorAttributeName : [UIColor lightGrayColor] | 111 NSForegroundColorAttributeName : [UIColor lightGrayColor] |
107 } | 112 } |
108 forState:UIControlStateDisabled]; | 113 forState:UIControlStateDisabled]; |
| 114 [_cancelButton |
| 115 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_CANCEL)]; |
109 [self navigationItem].leftBarButtonItem = _cancelButton; | 116 [self navigationItem].leftBarButtonItem = _cancelButton; |
110 | 117 |
111 // Set up right (pay) button. | 118 // Set up right (pay) button. |
112 _payButton.reset([[MDCFlatButton alloc] init]); | 119 _payButton.reset([[MDCFlatButton alloc] init]); |
113 [_payButton | 120 [_payButton |
114 setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON) | 121 setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON) |
115 forState:UIControlStateNormal]; | 122 forState:UIControlStateNormal]; |
116 [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] | 123 [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] |
117 forState:UIControlStateNormal]; | 124 forState:UIControlStateNormal]; |
118 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]]; | 125 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]]; |
119 [_payButton setBackgroundColor:[UIColor grayColor] | 126 [_payButton setBackgroundColor:[UIColor grayColor] |
120 forState:UIControlStateDisabled]; | 127 forState:UIControlStateDisabled]; |
121 [_payButton addTarget:nil | 128 [_payButton addTarget:nil |
122 action:@selector(onConfirm) | 129 action:@selector(onConfirm) |
123 forControlEvents:UIControlEventTouchUpInside]; | 130 forControlEvents:UIControlEventTouchUpInside]; |
| 131 [_payButton |
| 132 setAccessibilityLabel:l10n_util::GetNSString( |
| 133 IDS_IOS_ACCNAME_PAYMENT_REQUEST_PAY_BUTTON)]; |
124 [_payButton sizeToFit]; | 134 [_payButton sizeToFit]; |
125 [_payButton setEnabled:NO]; | 135 [_payButton setEnabled:NO]; |
126 [_payButton setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() | | 136 [_payButton setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() | |
127 UIViewAutoresizingFlexibleTopMargin | | 137 UIViewAutoresizingFlexibleTopMargin | |
128 UIViewAutoresizingFlexibleBottomMargin]; | 138 UIViewAutoresizingFlexibleBottomMargin]; |
129 | 139 |
130 // The navigation bar will set the rightBarButtonItem's height to the full | 140 // The navigation bar will set the rightBarButtonItem's height to the full |
131 // height of the bar. We don't want that for the button so we use a UIView | 141 // height of the bar. We don't want that for the button so we use a UIView |
132 // here to contain the button instead and the button is vertically centered | 142 // here to contain the button instead and the button is vertically centered |
133 // inside the full bar height. | 143 // inside the full bar height. |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 NSIndexPath* indexPath = | 319 NSIndexPath* indexPath = |
310 [self.collectionViewModel indexPathForItem:_selectedShippingAddressItem | 320 [self.collectionViewModel indexPathForItem:_selectedShippingAddressItem |
311 inSectionWithIdentifier:SectionIdentifierShipping]; | 321 inSectionWithIdentifier:SectionIdentifierShipping]; |
312 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; | 322 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; |
313 } | 323 } |
314 | 324 |
315 #pragma mark - Helper methods | 325 #pragma mark - Helper methods |
316 | 326 |
317 - (void)fillShippingAddressItem:(ShippingAddressItem*)item | 327 - (void)fillShippingAddressItem:(ShippingAddressItem*)item |
318 withAddress:(autofill::AutofillProfile*)address { | 328 withAddress:(autofill::AutofillProfile*)address { |
319 item.name = | 329 item.name = NameLabelFromAutofillProfile(address); |
320 base::SysUTF16ToNSString(address->GetRawInfo(autofill::NAME_FULL)); | 330 item.address = AddressLabelFromAutofillProfile(address); |
321 item.address = | 331 item.phoneNumber = PhoneNumberLabelFromAutofillProfile(address); |
322 payment_request_utils::AddressLabelFromAutofillProfile(address); | |
323 item.phoneNumber = base::SysUTF16ToNSString( | |
324 address->GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER)); | |
325 } | 332 } |
326 | 333 |
327 #pragma mark UICollectionViewDataSource | 334 #pragma mark UICollectionViewDataSource |
328 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView | 335 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView |
329 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { | 336 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { |
330 UICollectionViewCell* cell = | 337 UICollectionViewCell* cell = |
331 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; | 338 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; |
332 | 339 |
333 NSInteger itemType = | 340 NSInteger itemType = |
334 [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 341 [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 405 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
399 if (type == ItemTypeSummaryTotal && | 406 if (type == ItemTypeSummaryTotal && |
400 _paymentRequest.details.display_items.empty()) { | 407 _paymentRequest.details.display_items.empty()) { |
401 return YES; | 408 return YES; |
402 } else { | 409 } else { |
403 return NO; | 410 return NO; |
404 } | 411 } |
405 } | 412 } |
406 | 413 |
407 @end | 414 @end |
OLD | NEW |