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

Side by Side Diff: ios/chrome/browser/payments/payment_request_edit_view_controller.h

Issue 2744823003: [Payment Request] Generic edit form (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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef IOS_CHROME_BROWSER_PAYMENTS_PAYMENT_REQUEST_EDIT_VIEW_CONTROLLER_H_
6 #define IOS_CHROME_BROWSER_PAYMENTS_PAYMENT_REQUEST_EDIT_VIEW_CONTROLLER_H_
7
8 #import <UIKit/UIKit.h>
9 #include <vector>
10
11 #import "ios/chrome/browser/payments/payment_request_edit_view_controller_action s.h"
12 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
13 #import "ios/chrome/browser/ui/settings/cells/autofill_edit_item.h"
14
15 // Use these as the starting values for section identifier and item type enums
16 // in subclasses. These values are chosen to prevent overlapping with the
17 // section identifier and item type enums of this class.
18 const NSInteger kSectionIdentifierEnumStart = kSectionIdentifierEnumZero + 20;
lpromero 2017/03/22 10:51:33 Move declaration to internal header (see below) an
Moe 2017/03/22 17:54:31 Yep they're not used. sorry, aftermath of breaking
19 const NSInteger kItemTypeEnumStart = kItemTypeEnumZero + 100;
20
21 // Field definition for an editor field. Used for building the UI and
22 // validation.
23 @interface EditorField : NSObject
lpromero 2017/03/22 10:51:33 Can you move this into its own files?
Moe 2017/03/22 17:54:31 Done.
24
25 // Autofill type for the field. Corresponds to autofill::ServerFieldType
26 @property(nonatomic, assign) NSInteger autofillType;
27 // Label for the field.
28 @property(nonatomic, copy) NSString* label;
29 // Value of the field. May be nil.
30 @property(nonatomic, copy) NSString* value;
31 // Whether the field is required.
32 @property(nonatomic, getter=isRequired) BOOL required;
33 // The associated AutofillEditItem instance. May be nil.
34 @property(nonatomic, assign) AutofillEditItem* item;
35 // The section identifier for the associated AutofillEditItem.
36 @property(nonatomic, assign) NSInteger sectionIdentifier;
37
38 - (instancetype)initWithAutofillType:(NSInteger)autofillType
39 label:(NSString*)label
40 value:(NSString*)value
41 required:(BOOL)required;
42
43 @end
44
45 @class PaymentRequestEditViewController;
46
47 // Delegate protocol for PaymentRequestEditViewController.
48 @protocol PaymentRequestEditViewControllerDelegate<NSObject>
49
50 // Notifies the delegate that the user has finished editing the fields supplied
51 // to the initializer. The value property of each field reflects the submitted
52 // value.
53 - (void)paymentRequestEditViewController:
54 (PaymentRequestEditViewController*)controller
55 didFinishEditingFields:(NSArray<EditorField*>*)fields;
56
57 // Notifies the delegate that the user has chosen to return to the previous
58 // screen.
59 - (void)paymentRequestEditViewControllerDidReturn:
60 (PaymentRequestEditViewController*)controller;
61
62 @end
63
64 // Validator protocol for PaymentRequestEditViewController.
65 @protocol PaymentRequestEditViewControllerValidator<NSObject>
66
67 // Returns the validation error string for |value|. |autofillType| corresponds
68 // to autofill::ServerFieldType. |required| indicates whether this is a required
69 // field. If there are no validation errors, an empty string is returned.
70 - (NSString*)paymentRequestEditViewController:
71 (PaymentRequestEditViewController*)controller
72 validateValue:(NSString*)value
73 autofillType:(NSInteger)autofillType
74 required:(BOOL)required;
75
76 @end
77
78 // The collection view controller for a generic Payment Request edit screen. It
79 // features sections for every EditorField supplied to the initializer. Each
80 // section has a text field as well as an error message item which is visible
81 // wehn the value of its respective text field is invalid.
82 @interface PaymentRequestEditViewController
83 : CollectionViewController<UITextFieldDelegate,
lpromero 2017/03/22 10:51:33 These are implementation details, they can move to
Moe 2017/03/22 17:54:32 Done. "In retrospect", the subclasses may need to
84 PaymentRequestEditViewControllerActions,
85 PaymentRequestEditViewControllerValidator>
86
87 // The delegate to be notified when the user returns or finishes editing the
88 // fields.
89 @property(nonatomic, weak) id<PaymentRequestEditViewControllerDelegate>
90 editorDelegate;
91
92 // The delegate to be called for validating the fields.
lpromero 2017/03/22 10:51:33 Add a comment that by default, this object is the
Moe 2017/03/22 17:54:31 Done. Yes, the base class's default implementation
93 @property(nonatomic, weak) id<PaymentRequestEditViewControllerValidator>
94 validatorDelegate;
95
96 // Validates each field. If there is a validation error, displays an error
97 // message item in the same section as the field and returns NO. Otherwise
98 // removes the error message item in that section if one exists and sets the
99 // value on the field. Returns YES if all the fields are validated successfully.
100 - (BOOL)validateForm;
101
102 // Called after the editor field items have been added to the the collection
103 // view model. Subclasses override this method to add items after the editor
104 // fields.
105 - (void)loadFooterItems;
106
107 // Returns the index path for the cell associated with the currently focused
108 // text field.
109 - (NSIndexPath*)indexPathForCurrentTextField;
110
111 // Adds an error message item in the section |sectionIdentifier| if
112 // |errorMessage| is non-empty. Otherwise removes such an item if one exists.
113 - (void)addOrRemoveErrorMessage:(NSString*)errorMessage
lpromero 2017/03/22 10:51:33 Many things in this header are for subclasses use
Moe 2017/03/22 17:54:32 Done. Everything here is for subclasses use. The r
114 inSectionWithIdentifier:(NSInteger)sectionIdentifier;
115
116 // Initializes this instance with a list of field definitions for the editor.
117 - (instancetype)initWithEditorFields:(NSArray<EditorField*>*)fields
118 NS_DESIGNATED_INITIALIZER;
119
120 - (instancetype)init NS_UNAVAILABLE;
121
122 - (instancetype)initWithStyle:(CollectionViewControllerStyle)style
123 NS_UNAVAILABLE;
124
125 @end
126
127 #endif // IOS_CHROME_BROWSER_PAYMENTS_PAYMENT_REQUEST_EDIT_VIEW_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698