1 // Copyright (c) 2013 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 CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_SECTION_CONTAINER_H_ 6 #define CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_SECTION_CONTAINER_H_ 7 8 #import <Cocoa/Cocoa.h> 9 10 #include "base/mac/scoped_nsobject.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" 13 #import "chrome/browser/ui/cocoa/autofill/autofill_input_field.h" 14 #import "chrome/browser/ui/cocoa/autofill/autofill_layout.h" 15 16 namespace autofill { 17 class AutofillDialogViewDelegate; 18 } 19 20 @class AutofillSectionView; 21 @class AutofillSuggestionContainer; 22 @class AutofillTextField; 23 @class AutofillTooltipController; 24 @class LayoutView; 25 @class MenuButton; 26 @class MenuController; 27 28 // Delegate to handle display of validation messages. 29 @protocol AutofillValidationDisplay 30 31 // Updates the validation message for a given field. 32 - (void)updateMessageForField:(NSControl<AutofillInputField>*)field; 33 34 // Hides the validation error bubble. 35 - (void)hideErrorBubble; 36 37 @end 38 39 40 // View delegate for a section of the payment details. Contains a label 41 // describing the section as well as associated inputs and controls. Built 42 // dynamically based on data retrieved from AutofillDialogViewDelegate. 43 @interface AutofillSectionContainer : 44 NSViewController<AutofillLayout, AutofillInputDelegate> { 45 @private 46 base::scoped_nsobject<LayoutView> inputs_; 47 base::scoped_nsobject<MenuButton> suggestButton_; 48 base::scoped_nsobject<AutofillSuggestionContainer> suggestContainer_; 49 base::scoped_nsobject<NSTextField> label_; 50 51 // The view for the container. 52 base::scoped_nsobject<AutofillSectionView> view_; 53 54 // Some sections need to show an icon with an associated tooltip. This is the 55 // controller for such an icon. There is at most one such icon per section. 56 base::scoped_nsobject<AutofillTooltipController> tooltipController_; 57 58 // The logical superview for the tooltip icon. Weak pointer, owned by 59 // |inputs_|. 60 AutofillTextField* tooltipField_; 61 62 // List of weak pointers, which constitute unique field IDs. 63 std::vector<const autofill::DetailInput*> detailInputs_; 64 65 // A delegate to handle display of validation messages. Not owned. 66 id<AutofillValidationDisplay> validationDelegate_; 67 68 // Indicate whether the dialog should show suggestions or manual inputs when 69 // performLayout is triggered. 70 BOOL showSuggestions_; 71 72 base::scoped_nsobject<MenuController> menuController_; 73 autofill::DialogSection section_; 74 autofill::AutofillDialogViewDelegate* delegate_; // Not owned. 75 } 76 77 @property(readonly, nonatomic) autofill::DialogSection section; 78 @property(assign, nonatomic) id<AutofillValidationDisplay> validationDelegate; 79 80 // Designated initializer. Queries |delegate| for the list of desired input 81 // fields for |section|. 82 - (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate 83 forSection:(autofill::DialogSection)section; 84 85 // Populates |output| with mappings from field identification to input value. 86 - (void)getInputs:(autofill::FieldValueMap*)output; 87 88 // Called when the delegate-maintained suggestions model has changed. 89 - (void)modelChanged; 90 91 // Called when the contents of a section have changed. 92 - (void)update; 93 94 // Fills the section with Autofill data that was triggered by a user 95 // interaction with the originating |type|. 96 - (void)fillForType:(const autofill::ServerFieldType)type; 97 98 // Validate this section. Validation rules depend on |validationType|. 99 - (BOOL)validateFor:(autofill::ValidationType)validationType; 100 101 // Returns the value of the |suggestContainer_|'s input field, or nil if no 102 // suggestion is currently showing. 103 - (NSString*)suggestionText; 104 105 // Collects all input fields (direct & suggestions) into the given |array|. 106 - (void)addInputsToArray:(NSMutableArray*)array; 107 108 @end 109 110 @interface AutofillSectionContainer (ForTesting) 111 112 // Retrieve the field associated with the given type. 113 - (NSControl<AutofillInputField>*)getField:(autofill::ServerFieldType)type; 114 115 // Sets the value for the field matching |type|. Does nothing if the field is 116 // not part of this section. 117 - (void)setFieldValue:(NSString*)text 118 forType:(autofill::ServerFieldType)type; 119 120 // Sets the value for the suggestion text field. 121 - (void)setSuggestionFieldValue:(NSString*)text; 122 123 // Activates a given input field, determined by |type|. Does nothing if the 124 // field is not part of this section. 125 - (void)activateFieldForType:(autofill::ServerFieldType)type; 126 127 @end 128 129 #endif // CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_SECTION_CONTAINER_H_ 130