OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "ios/chrome/browser/ui/autofill/card_unmask_prompt_view_bridge.h" | 5 #include "ios/chrome/browser/ui/autofill/card_unmask_prompt_view_bridge.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/ios/ios_util.h" | 8 #include "base/ios/ios_util.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
14 #include "components/autofill/core/browser/ui/card_unmask_prompt_controller.h" | 14 #include "components/autofill/core/browser/ui/card_unmask_prompt_controller.h" |
15 #include "components/strings/grit/components_strings.h" | 15 #include "components/strings/grit/components_strings.h" |
16 #import "ios/chrome/browser/ui/autofill/cells/cvc_item.h" | 16 #import "ios/chrome/browser/ui/autofill/cells/cvc_item.h" |
17 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" | 17 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" |
18 #import "ios/chrome/browser/ui/autofill/cells/storage_switch_item.h" | 18 #import "ios/chrome/browser/ui/autofill/cells/storage_switch_item.h" |
19 #import "ios/chrome/browser/ui/autofill/storage_switch_tooltip.h" | 19 #import "ios/chrome/browser/ui/autofill/storage_switch_tooltip.h" |
20 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" | 20 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" |
21 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 21 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
22 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" | 22 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" |
23 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 23 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
24 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 24 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
25 #import "ios/chrome/browser/ui/rtl_geometry.h" | 25 #import "ios/chrome/browser/ui/rtl_geometry.h" |
26 #import "ios/third_party/material_components_ios/src/components/AppBar/src/Mater
ialAppBar.h" | 26 #import "ios/third_party/material_components_ios/src/components/AppBar/src/Mater
ialAppBar.h" |
27 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" | 27 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
29 | 29 |
| 30 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 31 #error "This file requires ARC support." |
| 32 #endif |
| 33 |
30 namespace { | 34 namespace { |
31 | 35 |
32 const CGFloat kTitleVerticalSpacing = 2.0f; | 36 const CGFloat kTitleVerticalSpacing = 2.0f; |
33 | 37 |
34 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 38 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
35 SectionIdentifierMain = kSectionIdentifierEnumZero, | 39 SectionIdentifierMain = kSectionIdentifierEnumZero, |
36 }; | 40 }; |
37 | 41 |
38 typedef NS_ENUM(NSInteger, ItemType) { | 42 typedef NS_ENUM(NSInteger, ItemType) { |
39 ItemTypeCVC = kItemTypeEnumZero, | 43 ItemTypeCVC = kItemTypeEnumZero, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 }]; | 108 }]; |
105 } | 109 } |
106 | 110 |
107 void CardUnmaskPromptViewBridge::DeleteSelf() { | 111 void CardUnmaskPromptViewBridge::DeleteSelf() { |
108 delete this; | 112 delete this; |
109 } | 113 } |
110 | 114 |
111 } // autofill | 115 } // autofill |
112 | 116 |
113 @interface CardUnmaskPromptViewIOS ()<UITextFieldDelegate> { | 117 @interface CardUnmaskPromptViewIOS ()<UITextFieldDelegate> { |
114 base::scoped_nsobject<UIBarButtonItem> _cancelButton; | 118 UIBarButtonItem* _cancelButton; |
115 base::scoped_nsobject<UIBarButtonItem> _verifyButton; | 119 UIBarButtonItem* _verifyButton; |
116 base::scoped_nsobject<CVCItem> _CVCItem; | 120 CVCItem* _CVCItem; |
117 base::scoped_nsobject<StatusItem> _statusItem; | 121 StatusItem* _statusItem; |
118 base::scoped_nsobject<StorageSwitchItem> _storageSwitchItem; | 122 StorageSwitchItem* _storageSwitchItem; |
119 | 123 |
120 // The tooltip is added as a child of the collection view rather than the | 124 // The tooltip is added as a child of the collection view rather than the |
121 // StorageSwitchContentView to allow it to overflow the bounds of the switch | 125 // StorageSwitchContentView to allow it to overflow the bounds of the switch |
122 // view. | 126 // view. |
123 base::scoped_nsobject<StorageSwitchTooltip> _storageSwitchTooltip; | 127 StorageSwitchTooltip* _storageSwitchTooltip; |
124 | 128 |
125 // Owns |self|. | 129 // Owns |self|. |
126 autofill::CardUnmaskPromptViewBridge* _bridge; // weak | 130 autofill::CardUnmaskPromptViewBridge* _bridge; // weak |
127 } | 131 } |
128 | 132 |
129 @end | 133 @end |
130 | 134 |
131 @implementation CardUnmaskPromptViewIOS | 135 @implementation CardUnmaskPromptViewIOS |
132 | 136 |
133 - (instancetype)initWithBridge:(autofill::CardUnmaskPromptViewBridge*)bridge { | 137 - (instancetype)initWithBridge:(autofill::CardUnmaskPromptViewBridge*)bridge { |
134 DCHECK(bridge); | 138 DCHECK(bridge); |
135 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; | 139 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; |
136 if (self) { | 140 if (self) { |
137 _bridge = bridge; | 141 _bridge = bridge; |
138 } | 142 } |
139 return self; | 143 return self; |
140 } | 144 } |
141 | 145 |
142 - (void)viewDidLoad { | 146 - (void)viewDidLoad { |
143 [super viewDidLoad]; | 147 [super viewDidLoad]; |
144 | 148 |
145 self.styler.cellStyle = MDCCollectionViewCellStyleCard; | 149 self.styler.cellStyle = MDCCollectionViewCellStyleCard; |
146 | 150 |
147 UILabel* titleLabel = | 151 UILabel* titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
148 [[[UILabel alloc] initWithFrame:CGRectZero] autorelease]; | |
149 titleLabel.text = | 152 titleLabel.text = |
150 SysUTF16ToNSString(_bridge->GetController()->GetWindowTitle()); | 153 SysUTF16ToNSString(_bridge->GetController()->GetWindowTitle()); |
151 titleLabel.font = [UIFont boldSystemFontOfSize:16]; | 154 titleLabel.font = [UIFont boldSystemFontOfSize:16]; |
152 titleLabel.accessibilityTraits |= UIAccessibilityTraitHeader; | 155 titleLabel.accessibilityTraits |= UIAccessibilityTraitHeader; |
153 [titleLabel sizeToFit]; | 156 [titleLabel sizeToFit]; |
154 | 157 |
155 UIView* titleView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; | 158 UIView* titleView = [[UIView alloc] initWithFrame:CGRectZero]; |
156 [titleView addSubview:titleLabel]; | 159 [titleView addSubview:titleLabel]; |
157 CGRect titleBounds = titleView.bounds; | 160 CGRect titleBounds = titleView.bounds; |
158 titleBounds.origin.y -= kTitleVerticalSpacing; | 161 titleBounds.origin.y -= kTitleVerticalSpacing; |
159 titleView.bounds = titleBounds; | 162 titleView.bounds = titleBounds; |
160 titleView.autoresizingMask = UIViewAutoresizingFlexibleLeadingMargin() | | 163 titleView.autoresizingMask = UIViewAutoresizingFlexibleLeadingMargin() | |
161 UIViewAutoresizingFlexibleBottomMargin; | 164 UIViewAutoresizingFlexibleBottomMargin; |
162 self.appBar.navigationBar.titleView = titleView; | 165 self.appBar.navigationBar.titleView = titleView; |
163 | 166 |
164 [self showCVCInputForm]; | 167 [self showCVCInputForm]; |
165 | 168 |
166 // Add the navigation buttons. | 169 // Add the navigation buttons. |
167 _cancelButton.reset([[UIBarButtonItem alloc] | 170 _cancelButton = |
168 initWithTitle:l10n_util::GetNSString(IDS_CANCEL) | 171 [[UIBarButtonItem alloc] initWithTitle:l10n_util::GetNSString(IDS_CANCEL) |
169 style:UIBarButtonItemStylePlain | 172 style:UIBarButtonItemStylePlain |
170 target:self | 173 target:self |
171 action:@selector(onCancel:)]); | 174 action:@selector(onCancel:)]; |
172 self.navigationItem.leftBarButtonItem = _cancelButton; | 175 self.navigationItem.leftBarButtonItem = _cancelButton; |
173 | 176 |
174 NSString* verifyButtonText = | 177 NSString* verifyButtonText = |
175 SysUTF16ToNSString(_bridge->GetController()->GetOkButtonLabel()); | 178 SysUTF16ToNSString(_bridge->GetController()->GetOkButtonLabel()); |
176 _verifyButton.reset([[UIBarButtonItem alloc] | 179 _verifyButton = |
177 initWithTitle:verifyButtonText | 180 [[UIBarButtonItem alloc] initWithTitle:verifyButtonText |
178 style:UIBarButtonItemStylePlain | 181 style:UIBarButtonItemStylePlain |
179 target:self | 182 target:self |
180 action:@selector(onVerify:)]); | 183 action:@selector(onVerify:)]; |
181 [_verifyButton setTitleTextAttributes:@{ | 184 [_verifyButton setTitleTextAttributes:@{ |
182 NSForegroundColorAttributeName : [[MDCPalette cr_bluePalette] tint600] | 185 NSForegroundColorAttributeName : [[MDCPalette cr_bluePalette] tint600] |
183 } | 186 } |
184 forState:UIControlStateNormal]; | 187 forState:UIControlStateNormal]; |
185 [_verifyButton setTitleTextAttributes:@{ | 188 [_verifyButton setTitleTextAttributes:@{ |
186 NSForegroundColorAttributeName : [UIColor lightGrayColor] | 189 NSForegroundColorAttributeName : [UIColor lightGrayColor] |
187 } | 190 } |
188 forState:UIControlStateDisabled]; | 191 forState:UIControlStateDisabled]; |
189 [_verifyButton setEnabled:NO]; | 192 [_verifyButton setEnabled:NO]; |
190 self.navigationItem.rightBarButtonItem = _verifyButton; | 193 self.navigationItem.rightBarButtonItem = _verifyButton; |
(...skipping 13 matching lines...) Expand all Loading... |
204 | 207 |
205 - (void)loadModel { | 208 - (void)loadModel { |
206 [super loadModel]; | 209 [super loadModel]; |
207 CollectionViewModel* model = self.collectionViewModel; | 210 CollectionViewModel* model = self.collectionViewModel; |
208 [model addSectionWithIdentifier:SectionIdentifierMain]; | 211 [model addSectionWithIdentifier:SectionIdentifierMain]; |
209 | 212 |
210 autofill::CardUnmaskPromptController* controller = _bridge->GetController(); | 213 autofill::CardUnmaskPromptController* controller = _bridge->GetController(); |
211 NSString* instructions = | 214 NSString* instructions = |
212 SysUTF16ToNSString(controller->GetInstructionsMessage()); | 215 SysUTF16ToNSString(controller->GetInstructionsMessage()); |
213 int CVCImageResourceID = controller->GetCvcImageRid(); | 216 int CVCImageResourceID = controller->GetCvcImageRid(); |
214 _CVCItem.reset([[CVCItem alloc] initWithType:ItemTypeCVC]); | 217 _CVCItem = [[CVCItem alloc] initWithType:ItemTypeCVC]; |
215 _CVCItem.get().instructionsText = instructions; | 218 _CVCItem.instructionsText = instructions; |
216 _CVCItem.get().CVCImageResourceID = CVCImageResourceID; | 219 _CVCItem.CVCImageResourceID = CVCImageResourceID; |
217 [model addItem:_CVCItem toSectionWithIdentifier:SectionIdentifierMain]; | 220 [model addItem:_CVCItem toSectionWithIdentifier:SectionIdentifierMain]; |
218 | 221 |
219 if (controller->CanStoreLocally()) { | 222 if (controller->CanStoreLocally()) { |
220 _storageSwitchItem.reset( | 223 _storageSwitchItem = |
221 [[StorageSwitchItem alloc] initWithType:ItemTypeStorageSwitch]); | 224 [[StorageSwitchItem alloc] initWithType:ItemTypeStorageSwitch]; |
222 _storageSwitchItem.get().on = controller->GetStoreLocallyStartState(); | 225 _storageSwitchItem.on = controller->GetStoreLocallyStartState(); |
223 [model addItem:_storageSwitchItem | 226 [model addItem:_storageSwitchItem |
224 toSectionWithIdentifier:SectionIdentifierMain]; | 227 toSectionWithIdentifier:SectionIdentifierMain]; |
225 | 228 |
226 _storageSwitchTooltip.reset([[StorageSwitchTooltip alloc] init]); | 229 _storageSwitchTooltip = [[StorageSwitchTooltip alloc] init]; |
227 [_storageSwitchTooltip setHidden:YES]; | 230 [_storageSwitchTooltip setHidden:YES]; |
228 [self.collectionView addSubview:_storageSwitchTooltip]; | 231 [self.collectionView addSubview:_storageSwitchTooltip]; |
229 } else { | 232 } else { |
230 _storageSwitchItem.reset(); | 233 _storageSwitchItem = nil; |
231 } | 234 } |
232 | 235 |
233 // No status item when loading the model. | 236 // No status item when loading the model. |
234 _statusItem.reset(); | 237 _statusItem = nil; |
235 } | 238 } |
236 | 239 |
237 #pragma mark - Private | 240 #pragma mark - Private |
238 | 241 |
239 - (void)showCVCInputForm { | 242 - (void)showCVCInputForm { |
240 [self showCVCInputFormWithError:nil]; | 243 [self showCVCInputFormWithError:nil]; |
241 } | 244 } |
242 | 245 |
243 - (void)showCVCInputFormWithError:(NSString*)errorMessage { | 246 - (void)showCVCInputFormWithError:(NSString*)errorMessage { |
244 [_verifyButton setEnabled:NO]; | 247 [_verifyButton setEnabled:NO]; |
245 | 248 |
246 [self loadModel]; | 249 [self loadModel]; |
247 _CVCItem.get().errorMessage = errorMessage; | 250 _CVCItem.errorMessage = errorMessage; |
248 // If the server requested a new expiration date, show the date input. If it | 251 // If the server requested a new expiration date, show the date input. If it |
249 // didn't and there was an error, show the "New card?" link which will show | 252 // didn't and there was an error, show the "New card?" link which will show |
250 // the date inputs on click. This link is intended to remind the user that | 253 // the date inputs on click. This link is intended to remind the user that |
251 // they might have recently received a new card with updated expiration date | 254 // they might have recently received a new card with updated expiration date |
252 // and CVC. At the same time, we only put the CVC input in an error state if | 255 // and CVC. At the same time, we only put the CVC input in an error state if |
253 // we're not requesting a new date. Because if we're asking the user for both, | 256 // we're not requesting a new date. Because if we're asking the user for both, |
254 // we don't know which is incorrect. | 257 // we don't know which is incorrect. |
255 if (_bridge->GetController()->ShouldRequestExpirationDate()) { | 258 if (_bridge->GetController()->ShouldRequestExpirationDate()) { |
256 _CVCItem.get().showDateInput = YES; | 259 _CVCItem.showDateInput = YES; |
257 } else if (errorMessage) { | 260 } else if (errorMessage) { |
258 _CVCItem.get().showNewCardButton = YES; | 261 _CVCItem.showNewCardButton = YES; |
259 _CVCItem.get().showCVCInputError = YES; | 262 _CVCItem.showCVCInputError = YES; |
260 } | 263 } |
261 } | 264 } |
262 | 265 |
263 - (void)showSpinner { | 266 - (void)showSpinner { |
264 [_verifyButton setEnabled:NO]; | 267 [_verifyButton setEnabled:NO]; |
265 [_storageSwitchTooltip setHidden:YES]; | 268 [_storageSwitchTooltip setHidden:YES]; |
266 | 269 |
267 [self | 270 [self |
268 updateWithStatus:StatusItemState::VERIFYING | 271 updateWithStatus:StatusItemState::VERIFYING |
269 text:l10n_util::GetNSString( | 272 text:l10n_util::GetNSString( |
(...skipping 10 matching lines...) Expand all Loading... |
280 | 283 |
281 - (void)showError:(NSString*)errorMessage { | 284 - (void)showError:(NSString*)errorMessage { |
282 [_cancelButton setTitle:l10n_util::GetNSString(IDS_CLOSE)]; | 285 [_cancelButton setTitle:l10n_util::GetNSString(IDS_CLOSE)]; |
283 [_verifyButton setEnabled:NO]; | 286 [_verifyButton setEnabled:NO]; |
284 | 287 |
285 [self updateWithStatus:StatusItemState::ERROR text:errorMessage]; | 288 [self updateWithStatus:StatusItemState::ERROR text:errorMessage]; |
286 } | 289 } |
287 | 290 |
288 - (void)updateWithStatus:(StatusItemState)state text:(NSString*)text { | 291 - (void)updateWithStatus:(StatusItemState)state text:(NSString*)text { |
289 if (!_statusItem) { | 292 if (!_statusItem) { |
290 _statusItem.reset([[StatusItem alloc] initWithType:ItemTypeStatus]); | 293 _statusItem = [[StatusItem alloc] initWithType:ItemTypeStatus]; |
291 _statusItem.get().text = text; | 294 _statusItem.text = text; |
292 _statusItem.get().state = state; | 295 _statusItem.state = state; |
293 // Remove all the present items to replace them with the status item. | 296 // Remove all the present items to replace them with the status item. |
294 [self.collectionViewModel | 297 [self.collectionViewModel |
295 removeSectionWithIdentifier:SectionIdentifierMain]; | 298 removeSectionWithIdentifier:SectionIdentifierMain]; |
296 [self.collectionViewModel addSectionWithIdentifier:SectionIdentifierMain]; | 299 [self.collectionViewModel addSectionWithIdentifier:SectionIdentifierMain]; |
297 [self.collectionViewModel addItem:_statusItem | 300 [self.collectionViewModel addItem:_statusItem |
298 toSectionWithIdentifier:SectionIdentifierMain]; | 301 toSectionWithIdentifier:SectionIdentifierMain]; |
299 [self.collectionView reloadData]; | 302 [self.collectionView reloadData]; |
300 } else { | 303 } else { |
301 _statusItem.get().text = text; | 304 _statusItem.text = text; |
302 _statusItem.get().state = state; | 305 _statusItem.state = state; |
303 [self reconfigureCellsForItems:@[ _statusItem.get() ] | 306 [self reconfigureCellsForItems:@[ _statusItem ] |
304 inSectionWithIdentifier:SectionIdentifierMain]; | 307 inSectionWithIdentifier:SectionIdentifierMain]; |
305 [self.collectionViewLayout invalidateLayout]; | 308 [self.collectionViewLayout invalidateLayout]; |
306 } | 309 } |
307 } | 310 } |
308 | 311 |
309 - (CGFloat)statusCellHeight { | 312 - (CGFloat)statusCellHeight { |
310 const CGFloat collectionViewWidth = | 313 const CGFloat collectionViewWidth = |
311 CGRectGetWidth(self.collectionView.bounds); | 314 CGRectGetWidth(self.collectionView.bounds); |
312 | 315 |
313 // The status cell replaces the previous content of the collection. So it is | 316 // The status cell replaces the previous content of the collection. So it is |
(...skipping 12 matching lines...) Expand all Loading... |
326 forItem:_statusItem]; | 329 forItem:_statusItem]; |
327 // Return the size of the replaced content, but make sure it is at least the | 330 // Return the size of the replaced content, but make sure it is at least the |
328 // minimal status cell height. | 331 // minimal status cell height. |
329 return MAX(preferredHeightForCVC + preferredHeightForStorageSwitch, | 332 return MAX(preferredHeightForCVC + preferredHeightForStorageSwitch, |
330 preferredHeightForStatus); | 333 preferredHeightForStatus); |
331 } | 334 } |
332 | 335 |
333 - (void)layoutTooltipFromButton:(UIButton*)button { | 336 - (void)layoutTooltipFromButton:(UIButton*)button { |
334 const CGRect buttonFrameInCollectionView = | 337 const CGRect buttonFrameInCollectionView = |
335 [self.collectionView convertRect:button.bounds fromView:button]; | 338 [self.collectionView convertRect:button.bounds fromView:button]; |
336 CGRect tooltipFrame = _storageSwitchTooltip.get().frame; | 339 CGRect tooltipFrame = _storageSwitchTooltip.frame; |
337 | 340 |
338 // First, set the width and use sizeToFit to have the label flow the text and | 341 // First, set the width and use sizeToFit to have the label flow the text and |
339 // set the height appropriately. | 342 // set the height appropriately. |
340 const CGFloat kTooltipMargin = 8; | 343 const CGFloat kTooltipMargin = 8; |
341 CGFloat availableWidth = | 344 CGFloat availableWidth = |
342 CGRectGetMinX(buttonFrameInCollectionView) - 2 * kTooltipMargin; | 345 CGRectGetMinX(buttonFrameInCollectionView) - 2 * kTooltipMargin; |
343 const CGFloat kMaxTooltipWidth = 210; | 346 const CGFloat kMaxTooltipWidth = 210; |
344 tooltipFrame.size.width = MIN(availableWidth, kMaxTooltipWidth); | 347 tooltipFrame.size.width = MIN(availableWidth, kMaxTooltipWidth); |
345 _storageSwitchTooltip.get().frame = tooltipFrame; | 348 _storageSwitchTooltip.frame = tooltipFrame; |
346 [_storageSwitchTooltip sizeToFit]; | 349 [_storageSwitchTooltip sizeToFit]; |
347 | 350 |
348 // Then use the size to position the tooltip appropriately, based on the | 351 // Then use the size to position the tooltip appropriately, based on the |
349 // button position. | 352 // button position. |
350 tooltipFrame = _storageSwitchTooltip.get().frame; | 353 tooltipFrame = _storageSwitchTooltip.frame; |
351 tooltipFrame.origin.x = CGRectGetMinX(buttonFrameInCollectionView) - | 354 tooltipFrame.origin.x = CGRectGetMinX(buttonFrameInCollectionView) - |
352 kTooltipMargin - CGRectGetWidth(tooltipFrame); | 355 kTooltipMargin - CGRectGetWidth(tooltipFrame); |
353 tooltipFrame.origin.y = CGRectGetMaxY(buttonFrameInCollectionView) - | 356 tooltipFrame.origin.y = CGRectGetMaxY(buttonFrameInCollectionView) - |
354 CGRectGetHeight(tooltipFrame); | 357 CGRectGetHeight(tooltipFrame); |
355 _storageSwitchTooltip.get().frame = tooltipFrame; | 358 _storageSwitchTooltip.frame = tooltipFrame; |
356 } | 359 } |
357 | 360 |
358 - (BOOL)inputCVCIsValid:(CVCItem*)item { | 361 - (BOOL)inputCVCIsValid:(CVCItem*)item { |
359 return _bridge->GetController()->InputCvcIsValid( | 362 return _bridge->GetController()->InputCvcIsValid( |
360 base::SysNSStringToUTF16(item.CVCText)); | 363 base::SysNSStringToUTF16(item.CVCText)); |
361 } | 364 } |
362 | 365 |
363 - (BOOL)inputExpirationIsValid:(CVCItem*)item { | 366 - (BOOL)inputExpirationIsValid:(CVCItem*)item { |
364 if (!item.showDateInput) { | 367 if (!item.showDateInput) { |
365 return YES; | 368 return YES; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 // Focus the first visible input, unless the orientation is landscape. In | 408 // Focus the first visible input, unless the orientation is landscape. In |
406 // landscape, the keyboard covers up the storage checkbox shown below this | 409 // landscape, the keyboard covers up the storage checkbox shown below this |
407 // view and the user might never see it. | 410 // view and the user might never see it. |
408 if (UIInterfaceOrientationIsPortrait( | 411 if (UIInterfaceOrientationIsPortrait( |
409 [UIApplication sharedApplication].statusBarOrientation)) { | 412 [UIApplication sharedApplication].statusBarOrientation)) { |
410 // Also check whether any of the inputs are already the first responder and | 413 // Also check whether any of the inputs are already the first responder and |
411 // are non-empty, in which case the focus should be left there. | 414 // are non-empty, in which case the focus should be left there. |
412 if ((!CVC.monthInput.isFirstResponder || CVC.monthInput.text.length == 0) && | 415 if ((!CVC.monthInput.isFirstResponder || CVC.monthInput.text.length == 0) && |
413 (!CVC.yearInput.isFirstResponder || CVC.yearInput.text.length == 0) && | 416 (!CVC.yearInput.isFirstResponder || CVC.yearInput.text.length == 0) && |
414 (!CVC.CVCInput.isFirstResponder || CVC.CVCInput.text.length == 0)) { | 417 (!CVC.CVCInput.isFirstResponder || CVC.CVCInput.text.length == 0)) { |
415 if (_CVCItem.get().showDateInput) { | 418 if (_CVCItem.showDateInput) { |
416 [CVC.monthInput becomeFirstResponder]; | 419 [CVC.monthInput becomeFirstResponder]; |
417 } else { | 420 } else { |
418 [CVC.CVCInput becomeFirstResponder]; | 421 [CVC.CVCInput becomeFirstResponder]; |
419 } | 422 } |
420 } | 423 } |
421 } | 424 } |
422 } | 425 } |
423 | 426 |
424 #pragma mark - Actions | 427 #pragma mark - Actions |
425 | 428 |
426 - (void)onVerify:(id)sender { | 429 - (void)onVerify:(id)sender { |
427 autofill::CardUnmaskPromptController* controller = _bridge->GetController(); | 430 autofill::CardUnmaskPromptController* controller = _bridge->GetController(); |
428 DCHECK(controller); | 431 DCHECK(controller); |
429 | 432 |
430 // The controller requires a 4-digit year. Convert if necessary. | 433 // The controller requires a 4-digit year. Convert if necessary. |
431 NSString* yearText = _CVCItem.get().yearText; | 434 NSString* yearText = _CVCItem.yearText; |
432 if (yearText.length == 2) { | 435 if (yearText.length == 2) { |
433 NSInteger inputYear = yearText.integerValue; | 436 NSInteger inputYear = yearText.integerValue; |
434 NSInteger currentYear = | 437 NSInteger currentYear = |
435 [[NSCalendar currentCalendar] components:NSCalendarUnitYear | 438 [[NSCalendar currentCalendar] components:NSCalendarUnitYear |
436 fromDate:[NSDate date]] | 439 fromDate:[NSDate date]] |
437 .year; | 440 .year; |
438 inputYear += currentYear - (currentYear % 100); | 441 inputYear += currentYear - (currentYear % 100); |
439 yearText = [@(inputYear) stringValue]; | 442 yearText = [@(inputYear) stringValue]; |
440 } | 443 } |
441 | 444 |
442 controller->OnUnmaskResponse( | 445 controller->OnUnmaskResponse(base::SysNSStringToUTF16(_CVCItem.CVCText), |
443 base::SysNSStringToUTF16(_CVCItem.get().CVCText), | 446 base::SysNSStringToUTF16(_CVCItem.monthText), |
444 base::SysNSStringToUTF16(_CVCItem.get().monthText), | 447 base::SysNSStringToUTF16(yearText), |
445 base::SysNSStringToUTF16(yearText), _storageSwitchItem.get().on); | 448 _storageSwitchItem.on); |
446 } | 449 } |
447 | 450 |
448 - (void)onCancel:(id)sender { | 451 - (void)onCancel:(id)sender { |
449 _bridge->PerformClose(); | 452 _bridge->PerformClose(); |
450 } | 453 } |
451 | 454 |
452 - (void)onTooltipButtonTapped:(UIButton*)button { | 455 - (void)onTooltipButtonTapped:(UIButton*)button { |
453 BOOL shouldShowTooltip = !button.selected; | 456 BOOL shouldShowTooltip = !button.selected; |
454 button.highlighted = shouldShowTooltip; | 457 button.highlighted = shouldShowTooltip; |
455 if (shouldShowTooltip) { | 458 if (shouldShowTooltip) { |
456 button.selected = YES; | 459 button.selected = YES; |
457 [self layoutTooltipFromButton:button]; | 460 [self layoutTooltipFromButton:button]; |
458 [_storageSwitchTooltip setHidden:NO]; | 461 [_storageSwitchTooltip setHidden:NO]; |
459 } else { | 462 } else { |
460 button.selected = NO; | 463 button.selected = NO; |
461 [_storageSwitchTooltip setHidden:YES]; | 464 [_storageSwitchTooltip setHidden:YES]; |
462 } | 465 } |
463 } | 466 } |
464 | 467 |
465 - (void)onStorageSwitchChanged:(UISwitch*)switchView { | 468 - (void)onStorageSwitchChanged:(UISwitch*)switchView { |
466 // Update the item. | 469 // Update the item. |
467 _storageSwitchItem.get().on = switchView.on; | 470 _storageSwitchItem.on = switchView.on; |
468 } | 471 } |
469 | 472 |
470 - (void)onNewCardLinkTapped:(UIButton*)button { | 473 - (void)onNewCardLinkTapped:(UIButton*)button { |
471 _bridge->GetController()->NewCardLinkClicked(); | 474 _bridge->GetController()->NewCardLinkClicked(); |
472 _CVCItem.get().instructionsText = | 475 _CVCItem.instructionsText = |
473 SysUTF16ToNSString(_bridge->GetController()->GetInstructionsMessage()); | 476 SysUTF16ToNSString(_bridge->GetController()->GetInstructionsMessage()); |
474 _CVCItem.get().monthText = @""; | 477 _CVCItem.monthText = @""; |
475 _CVCItem.get().yearText = @""; | 478 _CVCItem.yearText = @""; |
476 _CVCItem.get().CVCText = @""; | 479 _CVCItem.CVCText = @""; |
477 _CVCItem.get().errorMessage = @""; | 480 _CVCItem.errorMessage = @""; |
478 _CVCItem.get().showDateInput = YES; | 481 _CVCItem.showDateInput = YES; |
479 _CVCItem.get().showNewCardButton = NO; | 482 _CVCItem.showNewCardButton = NO; |
480 _CVCItem.get().showDateInputError = NO; | 483 _CVCItem.showDateInputError = NO; |
481 _CVCItem.get().showCVCInputError = NO; | 484 _CVCItem.showCVCInputError = NO; |
482 | 485 |
483 [self reconfigureCellsForItems:@[ _CVCItem.get() ] | 486 [self reconfigureCellsForItems:@[ _CVCItem ] |
484 inSectionWithIdentifier:SectionIdentifierMain]; | 487 inSectionWithIdentifier:SectionIdentifierMain]; |
485 [self.collectionViewLayout invalidateLayout]; | 488 [self.collectionViewLayout invalidateLayout]; |
486 | 489 |
487 [self inputsDidChange:_CVCItem]; | 490 [self inputsDidChange:_CVCItem]; |
488 } | 491 } |
489 | 492 |
490 #pragma mark - UITextField Events | 493 #pragma mark - UITextField Events |
491 | 494 |
492 - (void)monthInputDidChange:(UITextField*)textField { | 495 - (void)monthInputDidChange:(UITextField*)textField { |
493 _CVCItem.get().monthText = textField.text; | 496 _CVCItem.monthText = textField.text; |
494 [self inputsDidChange:_CVCItem]; | 497 [self inputsDidChange:_CVCItem]; |
495 [self updateDateErrorState:_CVCItem]; | 498 [self updateDateErrorState:_CVCItem]; |
496 } | 499 } |
497 | 500 |
498 - (void)yearInputDidChange:(UITextField*)textField { | 501 - (void)yearInputDidChange:(UITextField*)textField { |
499 _CVCItem.get().yearText = textField.text; | 502 _CVCItem.yearText = textField.text; |
500 [self inputsDidChange:_CVCItem]; | 503 [self inputsDidChange:_CVCItem]; |
501 [self updateDateErrorState:_CVCItem]; | 504 [self updateDateErrorState:_CVCItem]; |
502 } | 505 } |
503 | 506 |
504 - (void)CVCInputDidChange:(UITextField*)textField { | 507 - (void)CVCInputDidChange:(UITextField*)textField { |
505 _CVCItem.get().CVCText = textField.text; | 508 _CVCItem.CVCText = textField.text; |
506 [self inputsDidChange:_CVCItem]; | 509 [self inputsDidChange:_CVCItem]; |
507 if (_bridge->GetController()->InputCvcIsValid( | 510 if (_bridge->GetController()->InputCvcIsValid( |
508 base::SysNSStringToUTF16(textField.text))) { | 511 base::SysNSStringToUTF16(textField.text))) { |
509 _CVCItem.get().showCVCInputError = NO; | 512 _CVCItem.showCVCInputError = NO; |
510 [self updateDateErrorState:_CVCItem]; | 513 [self updateDateErrorState:_CVCItem]; |
511 } | 514 } |
512 } | 515 } |
513 | 516 |
514 #pragma mark - MDCCollectionViewStylingDelegate | 517 #pragma mark - MDCCollectionViewStylingDelegate |
515 | 518 |
516 - (CGFloat)collectionView:(UICollectionView*)collectionView | 519 - (CGFloat)collectionView:(UICollectionView*)collectionView |
517 cellHeightAtIndexPath:(NSIndexPath*)indexPath { | 520 cellHeightAtIndexPath:(NSIndexPath*)indexPath { |
518 CollectionViewItem* item = | 521 CollectionViewItem* item = |
519 [self.collectionViewModel itemAtIndexPath:indexPath]; | 522 [self.collectionViewModel itemAtIndexPath:indexPath]; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 - (void)collectionView:(UICollectionView*)collectionView | 582 - (void)collectionView:(UICollectionView*)collectionView |
580 willDisplayCell:(UICollectionViewCell*)cell | 583 willDisplayCell:(UICollectionViewCell*)cell |
581 forItemAtIndexPath:(NSIndexPath*)indexPath { | 584 forItemAtIndexPath:(NSIndexPath*)indexPath { |
582 CVCCell* CVC = base::mac::ObjCCast<CVCCell>(cell); | 585 CVCCell* CVC = base::mac::ObjCCast<CVCCell>(cell); |
583 if (CVC) { | 586 if (CVC) { |
584 [self focusInputIfNeeded:CVC]; | 587 [self focusInputIfNeeded:CVC]; |
585 } | 588 } |
586 } | 589 } |
587 | 590 |
588 @end | 591 @end |
OLD | NEW |