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

Side by Side Diff: ios/chrome/browser/ui/settings/autofill_edit_collection_view_controller.mm

Issue 2731293002: [Payment Request] Updates AutofillEditItem to reuse in Payment Request (Closed)
Patch Set: Addressed comments Created 3 years, 9 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 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" 9 #import "base/mac/scoped_nsobject.h"
10 #import "ios/chrome/browser/ui/settings/autofill_edit_accessory_view.h" 10 #import "ios/chrome/browser/ui/settings/autofill_edit_accessory_view.h"
11 #import "ios/chrome/browser/ui/settings/autofill_edit_collection_view_controller +protected.h"
11 #import "ios/chrome/browser/ui/settings/cells/autofill_edit_item.h" 12 #import "ios/chrome/browser/ui/settings/cells/autofill_edit_item.h"
12 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h" 13 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h"
13 14
14 namespace { 15 namespace {
15 16
16 AutofillEditCell* AutofillEditCellForTextField(UITextField* textField) { 17 AutofillEditCell* AutofillEditCellForTextField(UITextField* textField) {
17 AutofillEditCell* settingsCell = nil; 18 AutofillEditCell* settingsCell = nil;
18 for (UIView* view = textField; view; view = [view superview]) { 19 for (UIView* view = textField; view; view = [view superview]) {
19 AutofillEditCell* cell = base::mac::ObjCCast<AutofillEditCell>(view); 20 AutofillEditCell* cell = base::mac::ObjCCast<AutofillEditCell>(view);
20 if (cell) { 21 if (cell) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 122 }
122 123
123 - (BOOL)textFieldShouldReturn:(UITextField*)textField { 124 - (BOOL)textFieldShouldReturn:(UITextField*)textField {
124 DCHECK([_currentEditingCell textField] == textField); 125 DCHECK([_currentEditingCell textField] == textField);
125 [self nextPressed]; 126 [self nextPressed];
126 return NO; 127 return NO;
127 } 128 }
128 129
129 #pragma mark - AutofillEditAccessoryDelegate 130 #pragma mark - AutofillEditAccessoryDelegate
130 131
132 - (void)nextPressed {
133 [self moveToAnotherCellWithOffset:1];
134 }
135
136 - (void)previousPressed {
137 [self moveToAnotherCellWithOffset:-1];
138 }
139
140 - (void)closePressed {
141 [[_currentEditingCell textField] resignFirstResponder];
142 }
143
144 #pragma mark - Helper methods
145
131 - (NSIndexPath*)indexPathForCurrentTextField { 146 - (NSIndexPath*)indexPathForCurrentTextField {
132 DCHECK(_currentEditingCell); 147 DCHECK(_currentEditingCell);
133 return [[self collectionView] indexPathForCell:_currentEditingCell]; 148 return [[self collectionView] indexPathForCell:_currentEditingCell];
134 } 149 }
135 150
136 - (void)moveToAnotherCellWithOffset:(NSInteger)offset { 151 - (void)moveToAnotherCellWithOffset:(NSInteger)offset {
137 UICollectionView* collectionView = [self collectionView]; 152 UICollectionView* collectionView = [self collectionView];
138 NSIndexPath* cellPath = [self indexPathForCurrentTextField]; 153 NSIndexPath* cellPath = [self indexPathForCurrentTextField];
139 DCHECK(cellPath); 154 DCHECK(cellPath);
140 NSIndexPath* nextCellPath = 155 NSIndexPath* nextCellPath =
141 [self indexForCellPathWithOffset:offset fromPath:cellPath]; 156 [self indexForCellPathWithOffset:offset fromPath:cellPath];
142 157
143 if (!nextCellPath) { 158 if (!nextCellPath) {
144 [[_currentEditingCell textField] resignFirstResponder]; 159 [[_currentEditingCell textField] resignFirstResponder];
145 } else { 160 } else {
146 AutofillEditCell* nextCell = base::mac::ObjCCastStrict<AutofillEditCell>( 161 AutofillEditCell* nextCell = base::mac::ObjCCastStrict<AutofillEditCell>(
147 [collectionView cellForItemAtIndexPath:nextCellPath]); 162 [collectionView cellForItemAtIndexPath:nextCellPath]);
148 [nextCell.textField becomeFirstResponder]; 163 [nextCell.textField becomeFirstResponder];
149 } 164 }
150 } 165 }
151 166
152 - (void)nextPressed {
153 [self moveToAnotherCellWithOffset:1];
154 }
155
156 - (void)previousPressed {
157 [self moveToAnotherCellWithOffset:-1];
158 }
159
160 - (void)closePressed {
161 [[_currentEditingCell textField] resignFirstResponder];
162 }
163
164 - (void)updateAccessoryViewButtonState { 167 - (void)updateAccessoryViewButtonState {
165 NSIndexPath* currentPath = [self indexPathForCurrentTextField]; 168 NSIndexPath* currentPath = [self indexPathForCurrentTextField];
166 NSIndexPath* nextPath = 169 NSIndexPath* nextPath =
167 [self indexForCellPathWithOffset:1 fromPath:currentPath]; 170 [self indexForCellPathWithOffset:1 fromPath:currentPath];
168 NSIndexPath* previousPath = 171 NSIndexPath* previousPath =
169 [self indexForCellPathWithOffset:-1 fromPath:currentPath]; 172 [self indexForCellPathWithOffset:-1 fromPath:currentPath];
170 173
171 [[_accessoryView previousButton] setEnabled:previousPath != nil]; 174 [[_accessoryView previousButton] setEnabled:previousPath != nil];
172 [[_accessoryView nextButton] setEnabled:nextPath != nil]; 175 [[_accessoryView nextButton] setEnabled:nextPath != nil];
173 } 176 }
174 177
175 #pragma mark - Keyboard handling 178 #pragma mark - Keyboard handling
176 179
177 - (void)keyboardDidShow { 180 - (void)keyboardDidShow {
178 [self.collectionView scrollRectToVisible:[_currentEditingCell frame] 181 [self.collectionView scrollRectToVisible:[_currentEditingCell frame]
179 animated:YES]; 182 animated:YES];
180 } 183 }
181 184
182 @end 185 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698