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

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

Issue 2883393003: [Payments] No longer resize Autofill assets in Payments/Autofill UI (Closed)
Patch Set: Created 3 years, 7 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/credit_card_edit_mediator.h" 5 #import "ios/chrome/browser/ui/payments/credit_card_edit_mediator.h"
6 6
7 #include "base/strings/sys_string_conversions.h" 7 #include "base/strings/sys_string_conversions.h"
8 #include "components/autofill/core/browser/autofill_data_util.h" 8 #include "components/autofill/core/browser/autofill_data_util.h"
9 #include "components/autofill/core/browser/autofill_profile.h" 9 #include "components/autofill/core/browser/autofill_profile.h"
10 #include "components/autofill/core/browser/credit_card.h" 10 #include "components/autofill/core/browser/credit_card.h"
(...skipping 14 matching lines...) Expand all
25 25
26 #if !defined(__has_feature) || !__has_feature(objc_arc) 26 #if !defined(__has_feature) || !__has_feature(objc_arc)
27 #error "This file requires ARC support." 27 #error "This file requires ARC support."
28 #endif 28 #endif
29 29
30 namespace { 30 namespace {
31 using ::AutofillUITypeFromAutofillType; 31 using ::AutofillUITypeFromAutofillType;
32 using ::autofill::data_util::GetIssuerNetworkForBasicCardIssuerNetwork; 32 using ::autofill::data_util::GetIssuerNetworkForBasicCardIssuerNetwork;
33 using ::autofill::data_util::GetPaymentRequestData; 33 using ::autofill::data_util::GetPaymentRequestData;
34 using ::payment_request_util::GetBillingAddressLabelFromAutofillProfile; 34 using ::payment_request_util::GetBillingAddressLabelFromAutofillProfile;
35
36 const CGFloat kCardIssuerNetworkIconDimension = 20.0;
37 } // namespace 35 } // namespace
38 36
39 @interface CreditCardEditViewControllerMediator () 37 @interface CreditCardEditViewControllerMediator ()
40 38
41 // The PaymentRequest object owning an instance of web::PaymentRequest as 39 // The PaymentRequest object owning an instance of web::PaymentRequest as
42 // provided by the page invoking the Payment Request API. This is a weak 40 // provided by the page invoking the Payment Request API. This is a weak
43 // pointer and should outlive this class. 41 // pointer and should outlive this class.
44 @property(nonatomic, assign) PaymentRequest* paymentRequest; 42 @property(nonatomic, assign) PaymentRequest* paymentRequest;
45 43
46 // The credit card to be edited, if any. This pointer is not owned by this class 44 // The credit card to be edited, if any. This pointer is not owned by this class
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 92
95 // Otherwise, return an item that displays a list of payment method type icons 93 // Otherwise, return an item that displays a list of payment method type icons
96 // for the accepted payment methods. 94 // for the accepted payment methods.
97 NSMutableArray* issuerNetworkIcons = [NSMutableArray array]; 95 NSMutableArray* issuerNetworkIcons = [NSMutableArray array];
98 for (const auto& supportedNetwork : 96 for (const auto& supportedNetwork :
99 _paymentRequest->supported_card_networks()) { 97 _paymentRequest->supported_card_networks()) {
100 const std::string issuerNetwork = 98 const std::string issuerNetwork =
101 GetIssuerNetworkForBasicCardIssuerNetwork(supportedNetwork); 99 GetIssuerNetworkForBasicCardIssuerNetwork(supportedNetwork);
102 const autofill::data_util::PaymentRequestData& cardData = 100 const autofill::data_util::PaymentRequestData& cardData =
103 GetPaymentRequestData(issuerNetwork); 101 GetPaymentRequestData(issuerNetwork);
104 UIImage* issuerNetworkIcon = 102 UIImage* issuerNetworkIcon = NativeImage(cardData.icon_resource_id);
105 ResizeImage(NativeImage(cardData.icon_resource_id),
106 CGSizeMake(kCardIssuerNetworkIconDimension,
107 kCardIssuerNetworkIconDimension),
108 ProjectionMode::kAspectFillNoClipping);
109 issuerNetworkIcon.accessibilityLabel = 103 issuerNetworkIcon.accessibilityLabel =
110 l10n_util::GetNSString(cardData.a11y_label_resource_id); 104 l10n_util::GetNSString(cardData.a11y_label_resource_id);
111 [issuerNetworkIcons addObject:issuerNetworkIcon]; 105 [issuerNetworkIcons addObject:issuerNetworkIcon];
112 } 106 }
113 107
114 AcceptedPaymentMethodsItem* acceptedMethodsItem = 108 AcceptedPaymentMethodsItem* acceptedMethodsItem =
115 [[AcceptedPaymentMethodsItem alloc] init]; 109 [[AcceptedPaymentMethodsItem alloc] init];
116 acceptedMethodsItem.message = 110 acceptedMethodsItem.message =
117 l10n_util::GetNSString(IDS_PAYMENTS_ACCEPTED_CARDS_LABEL); 111 l10n_util::GetNSString(IDS_PAYMENTS_ACCEPTED_CARDS_LABEL);
118 acceptedMethodsItem.methodTypeIcons = issuerNetworkIcons; 112 acceptedMethodsItem.methodTypeIcons = issuerNetworkIcons;
119 return acceptedMethodsItem; 113 return acceptedMethodsItem;
120 } 114 }
121 115
122 - (BOOL)shouldHideBackgroundForHeaderItem { 116 - (BOOL)shouldHideBackgroundForHeaderItem {
123 // YES if the header item displays the accepted payment method type icons. 117 // YES if the header item displays the accepted payment method type icons.
124 return !_creditCard || autofill::IsCreditCardLocal(*_creditCard); 118 return !_creditCard || autofill::IsCreditCardLocal(*_creditCard);
125 } 119 }
126 120
127 - (UIImage*)cardTypeIconFromCardNumber:(NSString*)cardNumber { 121 - (UIImage*)cardTypeIconFromCardNumber:(NSString*)cardNumber {
128 const char* issuerNetwork = autofill::CreditCard::GetCardNetwork( 122 const char* issuerNetwork = autofill::CreditCard::GetCardNetwork(
129 base::SysNSStringToUTF16(cardNumber)); 123 base::SysNSStringToUTF16(cardNumber));
130 // This should not happen in Payment Request. 124 // This should not happen in Payment Request.
131 if (issuerNetwork == autofill::kGenericCard) 125 if (issuerNetwork == autofill::kGenericCard)
132 return nil; 126 return nil;
133 127
134 // Resize and return the card issuer network icon. 128 // Return the card issuer network icon.
135 int resourceID = autofill::data_util::GetPaymentRequestData(issuerNetwork) 129 int resourceID = autofill::data_util::GetPaymentRequestData(issuerNetwork)
136 .icon_resource_id; 130 .icon_resource_id;
137 CGFloat dimension = kCardIssuerNetworkIconDimension; 131 return NativeImage(resourceID);
138 return ResizeImage(NativeImage(resourceID), CGSizeMake(dimension, dimension),
139 ProjectionMode::kAspectFillNoClipping);
140 } 132 }
141 133
142 #pragma mark - Helper methods 134 #pragma mark - Helper methods
143 135
144 // Returns the billing address label from an autofill profile with the given 136 // Returns the billing address label from an autofill profile with the given
145 // guid. Returns nil if the profile does not have an address. 137 // guid. Returns nil if the profile does not have an address.
146 - (NSString*)billingAddressLabelForProfileWithGUID:(NSString*)profileGUID { 138 - (NSString*)billingAddressLabelForProfileWithGUID:(NSString*)profileGUID {
147 DCHECK(profileGUID); 139 DCHECK(profileGUID);
148 autofill::AutofillProfile* profile = 140 autofill::AutofillProfile* profile =
149 autofill::PersonalDataManager::GetProfileFromProfilesByGUID( 141 autofill::PersonalDataManager::GetProfileFromProfilesByGUID(
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 label:l10n_util::GetNSString(IDS_PAYMENTS_EXP_YEAR) 216 label:l10n_util::GetNSString(IDS_PAYMENTS_EXP_YEAR)
225 value:creditCardExpYear 217 value:creditCardExpYear
226 required:YES] 218 required:YES]
227 ]]; 219 ]];
228 // The billing address field goes at the end. 220 // The billing address field goes at the end.
229 [editorFields addObject:billingAddressEditorField]; 221 [editorFields addObject:billingAddressEditorField];
230 return editorFields; 222 return editorFields;
231 } 223 }
232 224
233 @end 225 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698