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

Side by Side Diff: ios/chrome/browser/payments/payment_request_view_controller.mm

Issue 2701923003: [Payment Request] Error message screen (Closed)
Patch Set: Addressed comments Created 3 years, 10 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 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 "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "components/autofill/core/browser/autofill_data_util.h" 13 #include "components/autofill/core/browser/autofill_data_util.h"
14 #include "components/autofill/core/browser/autofill_profile.h" 14 #include "components/autofill/core/browser/autofill_profile.h"
15 #include "components/autofill/core/browser/credit_card.h" 15 #include "components/autofill/core/browser/credit_card.h"
16 #include "components/autofill/core/browser/field_types.h" 16 #include "components/autofill/core/browser/field_types.h"
17 #include "components/autofill/core/browser/personal_data_manager.h" 17 #include "components/autofill/core/browser/personal_data_manager.h"
18 #include "components/payments/currency_formatter.h" 18 #include "components/payments/currency_formatter.h"
19 #include "components/strings/grit/components_strings.h" 19 #include "components/strings/grit/components_strings.h"
20 #import "ios/chrome/browser/payments/cells/page_info_item.h" 20 #import "ios/chrome/browser/payments/cells/page_info_item.h"
21 #import "ios/chrome/browser/payments/cells/payment_method_item.h" 21 #import "ios/chrome/browser/payments/cells/payment_method_item.h"
22 #import "ios/chrome/browser/payments/cells/price_item.h" 22 #import "ios/chrome/browser/payments/cells/price_item.h"
23 #import "ios/chrome/browser/payments/cells/shipping_address_item.h" 23 #import "ios/chrome/browser/payments/cells/shipping_address_item.h"
24 #import "ios/chrome/browser/payments/payment_request_util.h" 24 #import "ios/chrome/browser/payments/payment_request_util.h"
25 #import "ios/chrome/browser/payments/payment_request_view_controller_actions.h"
25 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" 26 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
26 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h" 27 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h"
27 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" 28 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
28 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h " 29 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h "
29 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 30 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
30 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 31 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
31 #include "ios/chrome/browser/ui/rtl_geometry.h" 32 #include "ios/chrome/browser/ui/rtl_geometry.h"
32 #include "ios/chrome/browser/ui/uikit_ui_util.h" 33 #include "ios/chrome/browser/ui/uikit_ui_util.h"
33 #include "ios/chrome/grit/ios_strings.h" 34 #include "ios/chrome/grit/ios_strings.h"
34 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" 35 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
35 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h" 36 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h"
36 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" 37 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
37 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h" 38 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h"
38 #include "ui/base/l10n/l10n_util.h" 39 #include "ui/base/l10n/l10n_util.h"
39 #include "ui/base/resource/resource_bundle.h" 40 #include "ui/base/resource/resource_bundle.h"
40 41
41 using payment_request_util::NameLabelFromAutofillProfile; 42 using payment_request_util::NameLabelFromAutofillProfile;
42 using payment_request_util::AddressLabelFromAutofillProfile; 43 using payment_request_util::AddressLabelFromAutofillProfile;
43 using payment_request_util::PhoneNumberLabelFromAutofillProfile; 44 using payment_request_util::PhoneNumberLabelFromAutofillProfile;
44 45
45 NSString* const kPaymentRequestCollectionViewId = 46 NSString* const kPaymentRequestCollectionViewID =
46 @"kPaymentRequestCollectionViewId"; 47 @"kPaymentRequestCollectionViewID";
47 48
48 namespace { 49 namespace {
49 50
50 const CGFloat kButtonEdgeInset = 9; 51 const CGFloat kButtonEdgeInset = 9;
51 const CGFloat kSeparatorEdgeInset = 14; 52 const CGFloat kSeparatorEdgeInset = 14;
52 53
53 typedef NS_ENUM(NSInteger, SectionIdentifier) { 54 typedef NS_ENUM(NSInteger, SectionIdentifier) {
54 SectionIdentifierSummary = kSectionIdentifierEnumZero, 55 SectionIdentifierSummary = kSectionIdentifierEnumZero,
55 SectionIdentifierShipping, 56 SectionIdentifierShipping,
56 SectionIdentifierPayment, 57 SectionIdentifierPayment,
57 58
58 }; 59 };
59 60
60 typedef NS_ENUM(NSInteger, ItemType) { 61 typedef NS_ENUM(NSInteger, ItemType) {
61 ItemTypeSummaryPageInfo = kItemTypeEnumZero, 62 ItemTypeSummaryPageInfo = kItemTypeEnumZero,
62 ItemTypeSummaryTotal, 63 ItemTypeSummaryTotal,
63 ItemTypeShippingTitle, 64 ItemTypeShippingTitle,
64 ItemTypeShippingAddress, 65 ItemTypeShippingAddress,
65 ItemTypeAddShippingAddress, 66 ItemTypeAddShippingAddress,
66 ItemTypeShippingOption, 67 ItemTypeShippingOption,
67 ItemTypeSelectShippingOption, 68 ItemTypeSelectShippingOption,
68 ItemTypePaymentTitle, 69 ItemTypePaymentTitle,
69 ItemTypePaymentMethod, 70 ItemTypePaymentMethod,
70 ItemTypeAddPaymentMethod, 71 ItemTypeAddPaymentMethod,
71 }; 72 };
72 73
73 } // namespace 74 } // namespace
74 75
75 @interface PaymentRequestViewController () { 76 @interface PaymentRequestViewController ()<
77 PaymentRequestViewControllerActions> {
76 base::WeakNSProtocol<id<PaymentRequestViewControllerDelegate>> _delegate; 78 base::WeakNSProtocol<id<PaymentRequestViewControllerDelegate>> _delegate;
77 base::scoped_nsobject<UIBarButtonItem> _cancelButton; 79 base::scoped_nsobject<UIBarButtonItem> _cancelButton;
78 base::scoped_nsobject<MDCFlatButton> _payButton; 80 base::scoped_nsobject<MDCFlatButton> _payButton;
79 81
80 // The PaymentRequest object owning an instance of web::PaymentRequest as 82 // The PaymentRequest object owning an instance of web::PaymentRequest as
81 // provided by the page invoking the Payment Request API. This is a weak 83 // provided by the page invoking the Payment Request API. This is a weak
82 // pointer and should outlive this class. 84 // pointer and should outlive this class.
83 PaymentRequest* _paymentRequest; 85 PaymentRequest* _paymentRequest;
84 86
85 PriceItem* _paymentSummaryItem; 87 PriceItem* _paymentSummaryItem;
86 ShippingAddressItem* _selectedShippingAddressItem; 88 ShippingAddressItem* _selectedShippingAddressItem;
87 CollectionViewTextItem* _selectedShippingOptionItem; 89 CollectionViewTextItem* _selectedShippingOptionItem;
88 PaymentMethodItem* _selectedPaymentMethodItem; 90 PaymentMethodItem* _selectedPaymentMethodItem;
89 91
90 base::mac::ObjCPropertyReleaser 92 base::mac::ObjCPropertyReleaser
91 _propertyReleaser_PaymentRequestViewController; 93 _propertyReleaser_PaymentRequestViewController;
92 } 94 }
93 95
94 // Called when the user presses the cancel button.
95 - (void)onCancel;
96
97 // Called when the user presses the confirm button.
98 - (void)onConfirm;
99
100 @end 96 @end
101 97
102 @implementation PaymentRequestViewController 98 @implementation PaymentRequestViewController
103 99
104 @synthesize pageFavicon = _pageFavicon; 100 @synthesize pageFavicon = _pageFavicon;
105 @synthesize pageTitle = _pageTitle; 101 @synthesize pageTitle = _pageTitle;
106 @synthesize pageHost = _pageHost; 102 @synthesize pageHost = _pageHost;
107 103
108 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest { 104 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest {
109 DCHECK(paymentRequest); 105 DCHECK(paymentRequest);
110 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { 106 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) {
111 _propertyReleaser_PaymentRequestViewController.Init( 107 _propertyReleaser_PaymentRequestViewController.Init(
112 self, [PaymentRequestViewController class]); 108 self, [PaymentRequestViewController class]);
113 109
114 [self setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TITLE)]; 110 [self setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TITLE)];
115 111
116 // Set up left (cancel) button. 112 // Set up leading (cancel) button.
117 _cancelButton.reset([[UIBarButtonItem alloc] 113 _cancelButton.reset([[UIBarButtonItem alloc]
118 initWithTitle:l10n_util::GetNSString( 114 initWithTitle:l10n_util::GetNSString(
119 IDS_IOS_PAYMENT_REQUEST_CANCEL_BUTTON) 115 IDS_IOS_PAYMENT_REQUEST_CANCEL_BUTTON)
120 style:UIBarButtonItemStylePlain 116 style:UIBarButtonItemStylePlain
121 target:nil 117 target:nil
122 action:@selector(onCancel)]); 118 action:@selector(onCancel)]);
123 [_cancelButton setTitleTextAttributes:@{ 119 [_cancelButton setTitleTextAttributes:@{
124 NSForegroundColorAttributeName : [UIColor lightGrayColor] 120 NSForegroundColorAttributeName : [UIColor lightGrayColor]
125 } 121 }
126 forState:UIControlStateDisabled]; 122 forState:UIControlStateDisabled];
127 [_cancelButton 123 [_cancelButton
128 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_CANCEL)]; 124 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_CANCEL)];
129 [self navigationItem].leftBarButtonItem = _cancelButton; 125 [self navigationItem].leftBarButtonItem = _cancelButton;
130 126
131 // Set up right (pay) button. 127 // Set up trailing (pay) button.
132 _payButton.reset([[MDCFlatButton alloc] init]); 128 _payButton.reset([[MDCFlatButton alloc] init]);
133 [_payButton 129 [_payButton
134 setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON) 130 setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON)
135 forState:UIControlStateNormal]; 131 forState:UIControlStateNormal];
136 [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] 132 [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500]
137 forState:UIControlStateNormal]; 133 forState:UIControlStateNormal];
138 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]]; 134 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]];
139 [_payButton setBackgroundColor:[UIColor grayColor] 135 [_payButton setBackgroundColor:[UIColor grayColor]
140 forState:UIControlStateDisabled]; 136 forState:UIControlStateDisabled];
141 [_payButton addTarget:nil 137 [_payButton addTarget:nil
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 IDS_IOS_PAYMENT_REQUEST_ADD_SHIPPING_ADDRESS_BUTTON) 301 IDS_IOS_PAYMENT_REQUEST_ADD_SHIPPING_ADDRESS_BUTTON)
306 uppercaseStringWithLocale:[NSLocale currentLocale]]; 302 uppercaseStringWithLocale:[NSLocale currentLocale]];
307 } 303 }
308 paymentMethodItem.accessibilityTraits |= UIAccessibilityTraitButton; 304 paymentMethodItem.accessibilityTraits |= UIAccessibilityTraitButton;
309 [model addItem:paymentMethodItem 305 [model addItem:paymentMethodItem
310 toSectionWithIdentifier:SectionIdentifierPayment]; 306 toSectionWithIdentifier:SectionIdentifierPayment];
311 } 307 }
312 308
313 - (void)viewDidLoad { 309 - (void)viewDidLoad {
314 [super viewDidLoad]; 310 [super viewDidLoad];
315 self.collectionView.accessibilityIdentifier = kPaymentRequestCollectionViewId; 311 self.collectionView.accessibilityIdentifier = kPaymentRequestCollectionViewID;
316 312
317 // Customize collection view settings. 313 // Customize collection view settings.
318 self.styler.cellStyle = MDCCollectionViewCellStyleCard; 314 self.styler.cellStyle = MDCCollectionViewCellStyleCard;
319 self.styler.separatorInset = 315 self.styler.separatorInset =
320 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); 316 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset);
321 } 317 }
322 318
323 - (void)updatePaymentSummaryWithTotalValueChanged:(BOOL)totalValueChanged { 319 - (void)updatePaymentSummaryWithTotalValueChanged:(BOOL)totalValueChanged {
324 [self fillPaymentSummaryItem:_paymentSummaryItem 320 [self fillPaymentSummaryItem:_paymentSummaryItem
325 withPaymentItem:_paymentRequest->payment_details().total 321 withPaymentItem:_paymentRequest->payment_details().total
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; 498 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
503 if (type == ItemTypeSummaryTotal && 499 if (type == ItemTypeSummaryTotal &&
504 _paymentRequest->payment_details().display_items.empty()) { 500 _paymentRequest->payment_details().display_items.empty()) {
505 return YES; 501 return YES;
506 } else { 502 } else {
507 return NO; 503 return NO;
508 } 504 }
509 } 505 }
510 506
511 @end 507 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698