Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/payment_request_selector_view_controller .h" | 5 #import "ios/chrome/browser/ui/payments/payment_request_selector_view_controller .h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "components/strings/grit/components_strings.h" | 8 #include "components/strings/grit/components_strings.h" |
| 9 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" | 9 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" |
| 10 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" | 10 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 (paymentRequestSelectorViewController:didSelectItemAtIndexForEditing | 254 (paymentRequestSelectorViewController:didSelectItemAtIndexForEditing |
| 255 :)]) { | 255 :)]) { |
| 256 [self.delegate paymentRequestSelectorViewController:self | 256 [self.delegate paymentRequestSelectorViewController:self |
| 257 didSelectItemAtIndexForEditing:index]; | 257 didSelectItemAtIndexForEditing:index]; |
| 258 } | 258 } |
| 259 return; | 259 return; |
| 260 } | 260 } |
| 261 | 261 |
| 262 switch (item.type) { | 262 switch (item.type) { |
| 263 case ItemTypeSelectableItem: { | 263 case ItemTypeSelectableItem: { |
| 264 CollectionViewItem<PaymentsIsSelectable>* newSelectedItem = | 264 NSUInteger currentlySelectedItemIndex = self.dataSource.selectedItemIndex; |
| 265 reinterpret_cast<CollectionViewItem<PaymentsIsSelectable>*>(item); | 265 // Notify the delegate of the selection. Update the currently selected and |
| 266 // Update the currently selected and the newly selected cells only if the | 266 // the newly selected cells only if the selection can actually be made. |
| 267 // newly selected cell corresponds to a complete item and can be selected. | 267 NSUInteger index = |
| 268 if (newSelectedItem.isComplete) { | 268 [self.collectionViewModel indexInItemTypeForIndexPath:indexPath]; |
| 269 DCHECK(index < [[self.dataSource selectableItems] count]); | |
|
macourteau
2017/06/28 19:11:42
nit: DCHECK_LT ?
Moe
2017/06/29 01:34:02
Done.
| |
| 270 if ([self.delegate paymentRequestSelectorViewController:self | |
| 271 didSelectItemAtIndex:index]) { | |
| 269 // Update the currently selected cell, if any. | 272 // Update the currently selected cell, if any. |
| 270 if (self.dataSource.selectedItemIndex != NSUIntegerMax) { | 273 if (currentlySelectedItemIndex != NSUIntegerMax) { |
| 271 DCHECK(self.dataSource.selectedItemIndex < | 274 DCHECK(currentlySelectedItemIndex < |
| 272 [[self.dataSource selectableItems] count]); | 275 [[self.dataSource selectableItems] count]); |
| 273 CollectionViewItem<PaymentsIsSelectable>* oldSelectedItem = | 276 CollectionViewItem<PaymentsIsSelectable>* oldSelectedItem = |
| 274 [[self.dataSource selectableItems] | 277 [[self.dataSource selectableItems] |
| 275 objectAtIndex:self.dataSource.selectedItemIndex]; | 278 objectAtIndex:currentlySelectedItemIndex]; |
| 276 oldSelectedItem.accessoryType = MDCCollectionViewCellAccessoryNone; | 279 oldSelectedItem.accessoryType = MDCCollectionViewCellAccessoryNone; |
| 277 [self reconfigureCellsForItems:@[ oldSelectedItem ]]; | 280 [self reconfigureCellsForItems:@[ oldSelectedItem ]]; |
| 278 } | 281 } |
| 279 // Update the newly selected cell. | 282 // Update the newly selected cell. |
| 283 CollectionViewItem<PaymentsIsSelectable>* newSelectedItem = | |
| 284 reinterpret_cast<CollectionViewItem<PaymentsIsSelectable>*>(item); | |
| 280 newSelectedItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark; | 285 newSelectedItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark; |
| 281 [self reconfigureCellsForItems:@[ newSelectedItem ]]; | 286 [self reconfigureCellsForItems:@[ newSelectedItem ]]; |
| 282 } | 287 } |
| 283 // Notify the delegate of the selection. | |
| 284 NSUInteger index = | |
| 285 [self.collectionViewModel indexInItemTypeForIndexPath:indexPath]; | |
| 286 DCHECK(index < [[self.dataSource selectableItems] count]); | |
| 287 [self.delegate paymentRequestSelectorViewController:self | |
| 288 didSelectItemAtIndex:index]; | |
| 289 break; | 288 break; |
| 290 } | 289 } |
| 291 case ItemTypeAddItem: { | 290 case ItemTypeAddItem: { |
| 292 if ([self.delegate | 291 if ([self.delegate |
| 293 respondsToSelector:@selector | 292 respondsToSelector:@selector |
| 294 (paymentRequestSelectorViewControllerDidSelectAddItem:)]) { | 293 (paymentRequestSelectorViewControllerDidSelectAddItem:)]) { |
| 295 [self.delegate | 294 [self.delegate |
| 296 paymentRequestSelectorViewControllerDidSelectAddItem:self]; | 295 paymentRequestSelectorViewControllerDidSelectAddItem:self]; |
| 297 } | 296 } |
| 298 break; | 297 break; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 323 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { | 322 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { |
| 324 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 323 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
| 325 if (type == ItemTypeHeader) { | 324 if (type == ItemTypeHeader) { |
| 326 return YES; | 325 return YES; |
| 327 } else { | 326 } else { |
| 328 return NO; | 327 return NO; |
| 329 } | 328 } |
| 330 } | 329 } |
| 331 | 330 |
| 332 @end | 331 @end |
| OLD | NEW |