| 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 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 | 8 |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "components/autofill/core/browser/autofill_data_util.h" | 11 #include "components/autofill/core/browser/autofill_data_util.h" |
| 12 #include "components/autofill/core/browser/autofill_profile.h" | 12 #include "components/autofill/core/browser/autofill_profile.h" |
| 13 #include "components/autofill/core/browser/credit_card.h" | 13 #include "components/autofill/core/browser/credit_card.h" |
| 14 #include "components/autofill/core/browser/field_types.h" | 14 #include "components/autofill/core/browser/field_types.h" |
| 15 #include "components/autofill/core/browser/personal_data_manager.h" | 15 #include "components/autofill/core/browser/personal_data_manager.h" |
| 16 #include "components/payments/currency_formatter.h" | 16 #include "components/payments/currency_formatter.h" |
| 17 #include "components/strings/grit/components_strings.h" | 17 #include "components/strings/grit/components_strings.h" |
| 18 #import "ios/chrome/browser/payments/cells/page_info_item.h" | 18 #import "ios/chrome/browser/payments/cells/page_info_item.h" |
| 19 #import "ios/chrome/browser/payments/cells/payment_method_item.h" | 19 #import "ios/chrome/browser/payments/cells/payment_method_item.h" |
| 20 #import "ios/chrome/browser/payments/cells/price_item.h" | 20 #import "ios/chrome/browser/payments/cells/price_item.h" |
| 21 #import "ios/chrome/browser/payments/cells/shipping_address_item.h" | 21 #import "ios/chrome/browser/payments/cells/shipping_address_item.h" |
| 22 #import "ios/chrome/browser/payments/payment_request_util.h" | 22 #import "ios/chrome/browser/payments/payment_request_util.h" |
| 23 #import "ios/chrome/browser/payments/payment_request_view_controller_actions.h" |
| 23 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" | 24 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" |
| 24 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item
.h" | 25 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item
.h" |
| 25 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 26 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
| 26 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" | 27 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" |
| 27 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 28 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 28 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 29 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
| 29 #include "ios/chrome/browser/ui/rtl_geometry.h" | 30 #include "ios/chrome/browser/ui/rtl_geometry.h" |
| 30 #include "ios/chrome/browser/ui/uikit_ui_util.h" | 31 #include "ios/chrome/browser/ui/uikit_ui_util.h" |
| 31 #include "ios/chrome/grit/ios_strings.h" | 32 #include "ios/chrome/grit/ios_strings.h" |
| 32 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" | 33 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" |
| 33 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" | 34 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" |
| 34 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 35 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
| 35 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" | 36 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" |
| 36 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 37 #include "ui/base/resource/resource_bundle.h" | 38 #include "ui/base/resource/resource_bundle.h" |
| 38 | 39 |
| 39 #if !defined(__has_feature) || !__has_feature(objc_arc) | 40 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 40 #error "This file requires ARC support." | 41 #error "This file requires ARC support." |
| 41 #endif | 42 #endif |
| 42 | 43 |
| 43 using payment_request_util::NameLabelFromAutofillProfile; | 44 using payment_request_util::NameLabelFromAutofillProfile; |
| 44 using payment_request_util::AddressLabelFromAutofillProfile; | 45 using payment_request_util::AddressLabelFromAutofillProfile; |
| 45 using payment_request_util::PhoneNumberLabelFromAutofillProfile; | 46 using payment_request_util::PhoneNumberLabelFromAutofillProfile; |
| 46 | 47 |
| 47 NSString* const kPaymentRequestCollectionViewId = | 48 NSString* const kPaymentRequestCollectionViewID = |
| 48 @"kPaymentRequestCollectionViewId"; | 49 @"kPaymentRequestCollectionViewID"; |
| 49 | 50 |
| 50 namespace { | 51 namespace { |
| 51 | 52 |
| 52 const CGFloat kButtonEdgeInset = 9; | 53 const CGFloat kButtonEdgeInset = 9; |
| 53 const CGFloat kSeparatorEdgeInset = 14; | 54 const CGFloat kSeparatorEdgeInset = 14; |
| 54 | 55 |
| 55 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 56 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 56 SectionIdentifierSummary = kSectionIdentifierEnumZero, | 57 SectionIdentifierSummary = kSectionIdentifierEnumZero, |
| 57 SectionIdentifierShipping, | 58 SectionIdentifierShipping, |
| 58 SectionIdentifierPayment, | 59 SectionIdentifierPayment, |
| 59 | 60 |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 typedef NS_ENUM(NSInteger, ItemType) { | 63 typedef NS_ENUM(NSInteger, ItemType) { |
| 63 ItemTypeSummaryPageInfo = kItemTypeEnumZero, | 64 ItemTypeSummaryPageInfo = kItemTypeEnumZero, |
| 64 ItemTypeSummaryTotal, | 65 ItemTypeSummaryTotal, |
| 65 ItemTypeShippingTitle, | 66 ItemTypeShippingTitle, |
| 66 ItemTypeShippingAddress, | 67 ItemTypeShippingAddress, |
| 67 ItemTypeAddShippingAddress, | 68 ItemTypeAddShippingAddress, |
| 68 ItemTypeShippingOption, | 69 ItemTypeShippingOption, |
| 69 ItemTypeSelectShippingOption, | 70 ItemTypeSelectShippingOption, |
| 70 ItemTypePaymentTitle, | 71 ItemTypePaymentTitle, |
| 71 ItemTypePaymentMethod, | 72 ItemTypePaymentMethod, |
| 72 ItemTypeAddPaymentMethod, | 73 ItemTypeAddPaymentMethod, |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 } // namespace | 76 } // namespace |
| 76 | 77 |
| 77 @interface PaymentRequestViewController () { | 78 @interface PaymentRequestViewController ()< |
| 79 PaymentRequestViewControllerActions> { |
| 78 UIBarButtonItem* _cancelButton; | 80 UIBarButtonItem* _cancelButton; |
| 79 MDCFlatButton* _payButton; | 81 MDCFlatButton* _payButton; |
| 80 | 82 |
| 81 // The PaymentRequest object owning an instance of web::PaymentRequest as | 83 // The PaymentRequest object owning an instance of web::PaymentRequest as |
| 82 // provided by the page invoking the Payment Request API. This is a weak | 84 // provided by the page invoking the Payment Request API. This is a weak |
| 83 // pointer and should outlive this class. | 85 // pointer and should outlive this class. |
| 84 PaymentRequest* _paymentRequest; | 86 PaymentRequest* _paymentRequest; |
| 85 | 87 |
| 86 PriceItem* _paymentSummaryItem; | 88 PriceItem* _paymentSummaryItem; |
| 87 ShippingAddressItem* _selectedShippingAddressItem; | 89 ShippingAddressItem* _selectedShippingAddressItem; |
| 88 CollectionViewTextItem* _selectedShippingOptionItem; | 90 CollectionViewTextItem* _selectedShippingOptionItem; |
| 89 PaymentMethodItem* _selectedPaymentMethodItem; | 91 PaymentMethodItem* _selectedPaymentMethodItem; |
| 90 } | 92 } |
| 91 | 93 |
| 92 // Called when the user presses the cancel button. | |
| 93 - (void)onCancel; | |
| 94 | |
| 95 // Called when the user presses the confirm button. | |
| 96 - (void)onConfirm; | |
| 97 | |
| 98 @end | 94 @end |
| 99 | 95 |
| 100 @implementation PaymentRequestViewController | 96 @implementation PaymentRequestViewController |
| 101 | 97 |
| 102 @synthesize pageFavicon = _pageFavicon; | 98 @synthesize pageFavicon = _pageFavicon; |
| 103 @synthesize pageTitle = _pageTitle; | 99 @synthesize pageTitle = _pageTitle; |
| 104 @synthesize pageHost = _pageHost; | 100 @synthesize pageHost = _pageHost; |
| 105 @synthesize delegate = _delegate; | 101 @synthesize delegate = _delegate; |
| 106 | 102 |
| 107 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest { | 103 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest { |
| 108 DCHECK(paymentRequest); | 104 DCHECK(paymentRequest); |
| 109 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { | 105 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { |
| 110 [self setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TITLE)]; | 106 [self setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TITLE)]; |
| 111 | 107 |
| 112 // Set up left (cancel) button. | 108 // Set up leading (cancel) button. |
| 113 _cancelButton = [[UIBarButtonItem alloc] | 109 _cancelButton = [[UIBarButtonItem alloc] |
| 114 initWithTitle:l10n_util::GetNSString( | 110 initWithTitle:l10n_util::GetNSString( |
| 115 IDS_IOS_PAYMENT_REQUEST_CANCEL_BUTTON) | 111 IDS_IOS_PAYMENT_REQUEST_CANCEL_BUTTON) |
| 116 style:UIBarButtonItemStylePlain | 112 style:UIBarButtonItemStylePlain |
| 117 target:nil | 113 target:nil |
| 118 action:@selector(onCancel)]; | 114 action:@selector(onCancel)]; |
| 119 [_cancelButton setTitleTextAttributes:@{ | 115 [_cancelButton setTitleTextAttributes:@{ |
| 120 NSForegroundColorAttributeName : [UIColor lightGrayColor] | 116 NSForegroundColorAttributeName : [UIColor lightGrayColor] |
| 121 } | 117 } |
| 122 forState:UIControlStateDisabled]; | 118 forState:UIControlStateDisabled]; |
| 123 [_cancelButton | 119 [_cancelButton |
| 124 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_CANCEL)]; | 120 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_CANCEL)]; |
| 125 [self navigationItem].leftBarButtonItem = _cancelButton; | 121 [self navigationItem].leftBarButtonItem = _cancelButton; |
| 126 | 122 |
| 127 // Set up right (pay) button. | 123 // Set up trailing (pay) button. |
| 128 _payButton = [[MDCFlatButton alloc] init]; | 124 _payButton = [[MDCFlatButton alloc] init]; |
| 129 [_payButton | 125 [_payButton |
| 130 setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON) | 126 setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON) |
| 131 forState:UIControlStateNormal]; | 127 forState:UIControlStateNormal]; |
| 132 [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] | 128 [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] |
| 133 forState:UIControlStateNormal]; | 129 forState:UIControlStateNormal]; |
| 134 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]]; | 130 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]]; |
| 135 [_payButton setBackgroundColor:[UIColor grayColor] | 131 [_payButton setBackgroundColor:[UIColor grayColor] |
| 136 forState:UIControlStateDisabled]; | 132 forState:UIControlStateDisabled]; |
| 137 [_payButton addTarget:nil | 133 [_payButton addTarget:nil |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 IDS_IOS_PAYMENT_REQUEST_ADD_SHIPPING_ADDRESS_BUTTON) | 285 IDS_IOS_PAYMENT_REQUEST_ADD_SHIPPING_ADDRESS_BUTTON) |
| 290 uppercaseStringWithLocale:[NSLocale currentLocale]]; | 286 uppercaseStringWithLocale:[NSLocale currentLocale]]; |
| 291 } | 287 } |
| 292 paymentMethodItem.accessibilityTraits |= UIAccessibilityTraitButton; | 288 paymentMethodItem.accessibilityTraits |= UIAccessibilityTraitButton; |
| 293 [model addItem:paymentMethodItem | 289 [model addItem:paymentMethodItem |
| 294 toSectionWithIdentifier:SectionIdentifierPayment]; | 290 toSectionWithIdentifier:SectionIdentifierPayment]; |
| 295 } | 291 } |
| 296 | 292 |
| 297 - (void)viewDidLoad { | 293 - (void)viewDidLoad { |
| 298 [super viewDidLoad]; | 294 [super viewDidLoad]; |
| 299 self.collectionView.accessibilityIdentifier = kPaymentRequestCollectionViewId; | 295 self.collectionView.accessibilityIdentifier = kPaymentRequestCollectionViewID; |
| 300 | 296 |
| 301 // Customize collection view settings. | 297 // Customize collection view settings. |
| 302 self.styler.cellStyle = MDCCollectionViewCellStyleCard; | 298 self.styler.cellStyle = MDCCollectionViewCellStyleCard; |
| 303 self.styler.separatorInset = | 299 self.styler.separatorInset = |
| 304 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); | 300 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); |
| 305 } | 301 } |
| 306 | 302 |
| 307 - (void)updatePaymentSummaryWithTotalValueChanged:(BOOL)totalValueChanged { | 303 - (void)updatePaymentSummaryWithTotalValueChanged:(BOOL)totalValueChanged { |
| 308 [self fillPaymentSummaryItem:_paymentSummaryItem | 304 [self fillPaymentSummaryItem:_paymentSummaryItem |
| 309 withPaymentItem:_paymentRequest->payment_details().total | 305 withPaymentItem:_paymentRequest->payment_details().total |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 482 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
| 487 if (type == ItemTypeSummaryTotal && | 483 if (type == ItemTypeSummaryTotal && |
| 488 _paymentRequest->payment_details().display_items.empty()) { | 484 _paymentRequest->payment_details().display_items.empty()) { |
| 489 return YES; | 485 return YES; |
| 490 } else { | 486 } else { |
| 491 return NO; | 487 return NO; |
| 492 } | 488 } |
| 493 } | 489 } |
| 494 | 490 |
| 495 @end | 491 @end |
| OLD | NEW |