| 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 #import "ios/chrome/browser/ui/settings/autofill_edit_collection_view_controller
.h" | 5 #import "ios/chrome/browser/ui/settings/autofill_edit_collection_view_controller
.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "base/mac/foundation_util.h" | 8 #import "base/mac/foundation_util.h" |
| 9 #import "base/mac/scoped_nsobject.h" | |
| 10 #import "ios/chrome/browser/ui/autofill/autofill_edit_accessory_view.h" | 9 #import "ios/chrome/browser/ui/autofill/autofill_edit_accessory_view.h" |
| 11 #import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h" | 10 #import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h" |
| 12 #import "ios/chrome/browser/ui/settings/autofill_edit_collection_view_controller
+protected.h" | 11 #import "ios/chrome/browser/ui/settings/autofill_edit_collection_view_controller
+protected.h" |
| 13 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" | 12 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" |
| 14 | 13 |
| 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 15 #error "This file requires ARC support." |
| 16 #endif |
| 17 |
| 15 namespace { | 18 namespace { |
| 16 | 19 |
| 17 AutofillEditCell* AutofillEditCellForTextField(UITextField* textField) { | 20 AutofillEditCell* AutofillEditCellForTextField(UITextField* textField) { |
| 18 AutofillEditCell* settingsCell = nil; | 21 AutofillEditCell* settingsCell = nil; |
| 19 for (UIView* view = textField; view; view = [view superview]) { | 22 for (UIView* view = textField; view; view = [view superview]) { |
| 20 AutofillEditCell* cell = base::mac::ObjCCast<AutofillEditCell>(view); | 23 AutofillEditCell* cell = base::mac::ObjCCast<AutofillEditCell>(view); |
| 21 if (cell) { | 24 if (cell) { |
| 22 settingsCell = cell; | 25 settingsCell = cell; |
| 23 break; | 26 break; |
| 24 } | 27 } |
| 25 } | 28 } |
| 26 | 29 |
| 27 // There should be a cell associated with this text field. | 30 // There should be a cell associated with this text field. |
| 28 DCHECK(settingsCell); | 31 DCHECK(settingsCell); |
| 29 return settingsCell; | 32 return settingsCell; |
| 30 } | 33 } |
| 31 | 34 |
| 32 } // namespace | 35 } // namespace |
| 33 | 36 |
| 34 @interface AutofillEditCollectionViewController ()< | 37 @interface AutofillEditCollectionViewController ()< |
| 35 AutofillEditAccessoryDelegate> { | 38 AutofillEditAccessoryDelegate> { |
| 36 base::scoped_nsobject<AutofillEditCell> _currentEditingCell; | 39 AutofillEditCell* _currentEditingCell; |
| 37 base::scoped_nsobject<AutofillEditAccessoryView> _accessoryView; | 40 AutofillEditAccessoryView* _accessoryView; |
| 38 } | 41 } |
| 39 @end | 42 @end |
| 40 | 43 |
| 41 @implementation AutofillEditCollectionViewController | 44 @implementation AutofillEditCollectionViewController |
| 42 | 45 |
| 43 - (instancetype)initWithStyle:(CollectionViewControllerStyle)style { | 46 - (instancetype)initWithStyle:(CollectionViewControllerStyle)style { |
| 44 self = [super initWithStyle:style]; | 47 self = [super initWithStyle:style]; |
| 45 if (!self) { | 48 if (!self) { |
| 46 return nil; | 49 return nil; |
| 47 } | 50 } |
| 48 | 51 |
| 49 _accessoryView.reset( | 52 _accessoryView = [[AutofillEditAccessoryView alloc] initWithDelegate:self]; |
| 50 [[AutofillEditAccessoryView alloc] initWithDelegate:self]); | |
| 51 [self setShouldHideDoneButton:YES]; | 53 [self setShouldHideDoneButton:YES]; |
| 52 [self updateEditButton]; | 54 [self updateEditButton]; |
| 53 return self; | 55 return self; |
| 54 } | 56 } |
| 55 | 57 |
| 56 - (void)viewDidAppear:(BOOL)animated { | 58 - (void)viewDidAppear:(BOOL)animated { |
| 57 [super viewDidAppear:animated]; | 59 [super viewDidAppear:animated]; |
| 58 [[NSNotificationCenter defaultCenter] | 60 [[NSNotificationCenter defaultCenter] |
| 59 addObserver:self | 61 addObserver:self |
| 60 selector:@selector(keyboardDidShow) | 62 selector:@selector(keyboardDidShow) |
| 61 name:UIKeyboardDidShowNotification | 63 name:UIKeyboardDidShowNotification |
| 62 object:nil]; | 64 object:nil]; |
| 63 } | 65 } |
| 64 | 66 |
| 65 - (void)viewWillDisappear:(BOOL)animated { | 67 - (void)viewWillDisappear:(BOOL)animated { |
| 66 [super viewWillDisappear:animated]; | 68 [super viewWillDisappear:animated]; |
| 67 [[NSNotificationCenter defaultCenter] | 69 [[NSNotificationCenter defaultCenter] |
| 68 removeObserver:self | 70 removeObserver:self |
| 69 name:UIKeyboardDidShowNotification | 71 name:UIKeyboardDidShowNotification |
| 70 object:nil]; | 72 object:nil]; |
| 71 } | 73 } |
| 72 | 74 |
| 73 - (void)dealloc { | 75 - (void)dealloc { |
| 74 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 76 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 75 [super dealloc]; | |
| 76 } | 77 } |
| 77 | 78 |
| 78 #pragma mark - SettingsRootCollectionViewController | 79 #pragma mark - SettingsRootCollectionViewController |
| 79 | 80 |
| 80 - (BOOL)shouldShowEditButton { | 81 - (BOOL)shouldShowEditButton { |
| 81 return YES; | 82 return YES; |
| 82 } | 83 } |
| 83 | 84 |
| 84 - (BOOL)editButtonEnabled { | 85 - (BOOL)editButtonEnabled { |
| 85 return YES; | 86 return YES; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 102 nextCellSection < [[self collectionView] numberOfSections]) | 103 nextCellSection < [[self collectionView] numberOfSections]) |
| 103 return [NSIndexPath indexPathForRow:0 inSection:nextCellSection]; | 104 return [NSIndexPath indexPathForRow:0 inSection:nextCellSection]; |
| 104 | 105 |
| 105 return nil; | 106 return nil; |
| 106 } | 107 } |
| 107 | 108 |
| 108 #pragma mark - UITextFieldDelegate | 109 #pragma mark - UITextFieldDelegate |
| 109 | 110 |
| 110 - (void)textFieldDidBeginEditing:(UITextField*)textField { | 111 - (void)textFieldDidBeginEditing:(UITextField*)textField { |
| 111 AutofillEditCell* cell = AutofillEditCellForTextField(textField); | 112 AutofillEditCell* cell = AutofillEditCellForTextField(textField); |
| 112 _currentEditingCell.reset([cell retain]); | 113 _currentEditingCell = cell; |
| 113 [textField setInputAccessoryView:_accessoryView]; | 114 [textField setInputAccessoryView:_accessoryView]; |
| 114 [self updateAccessoryViewButtonState]; | 115 [self updateAccessoryViewButtonState]; |
| 115 } | 116 } |
| 116 | 117 |
| 117 - (void)textFieldDidEndEditing:(UITextField*)textField { | 118 - (void)textFieldDidEndEditing:(UITextField*)textField { |
| 118 AutofillEditCell* cell = AutofillEditCellForTextField(textField); | 119 AutofillEditCell* cell = AutofillEditCellForTextField(textField); |
| 119 DCHECK(_currentEditingCell == cell); | 120 DCHECK(_currentEditingCell == cell); |
| 120 [textField setInputAccessoryView:nil]; | 121 [textField setInputAccessoryView:nil]; |
| 121 _currentEditingCell.reset(nil); | 122 _currentEditingCell = nil; |
| 122 } | 123 } |
| 123 | 124 |
| 124 - (BOOL)textFieldShouldReturn:(UITextField*)textField { | 125 - (BOOL)textFieldShouldReturn:(UITextField*)textField { |
| 125 DCHECK([_currentEditingCell textField] == textField); | 126 DCHECK([_currentEditingCell textField] == textField); |
| 126 [self nextPressed]; | 127 [self nextPressed]; |
| 127 return NO; | 128 return NO; |
| 128 } | 129 } |
| 129 | 130 |
| 130 #pragma mark - AutofillEditAccessoryDelegate | 131 #pragma mark - AutofillEditAccessoryDelegate |
| 131 | 132 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 } | 177 } |
| 177 | 178 |
| 178 #pragma mark - Keyboard handling | 179 #pragma mark - Keyboard handling |
| 179 | 180 |
| 180 - (void)keyboardDidShow { | 181 - (void)keyboardDidShow { |
| 181 [self.collectionView scrollRectToVisible:[_currentEditingCell frame] | 182 [self.collectionView scrollRectToVisible:[_currentEditingCell frame] |
| 182 animated:YES]; | 183 animated:YES]; |
| 183 } | 184 } |
| 184 | 185 |
| 185 @end | 186 @end |
| OLD | NEW |