OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_MAC_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_MAC_ |
6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_MAC_ | 6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_MAC_ |
7 | 7 |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 #include <vector> | 9 #include <vector> |
10 #include "base/scoped_nsobject.h" | 10 #include "base/scoped_nsobject.h" |
11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
12 #include "chrome/browser/autofill/autofill_dialog.h" | 12 #include "chrome/browser/autofill/autofill_dialog.h" |
13 #include "chrome/browser/autofill/autofill_profile.h" | 13 #include "chrome/browser/autofill/autofill_profile.h" |
14 #include "chrome/browser/autofill/credit_card.h" | 14 #include "chrome/browser/autofill/credit_card.h" |
15 | 15 |
16 namespace AutoFillDialogControllerInternal { | 16 namespace AutoFillDialogControllerInternal { |
17 class PersonalDataManagerObserver; | 17 class PersonalDataManagerObserver; |
18 } // AutoFillDialogControllerInternal | 18 } // AutoFillDialogControllerInternal |
19 | 19 |
20 @class AutoFillAddressViewController; | 20 @class AutoFillAddressSheetController; |
21 @class AutoFillCreditCardViewController; | 21 @class AutoFillCreditCardSheetController; |
| 22 @class AutoFillTableView; |
22 class Profile; | 23 class Profile; |
23 @class SectionSeparatorView; | |
24 @class WindowSizeAutosaver; | 24 @class WindowSizeAutosaver; |
25 | 25 |
26 // A window controller for managing the autofill options dialog. | 26 // A window controller for managing the autofill options dialog. |
27 // Application modally presents a dialog allowing the user to store | 27 // Application modally presents a dialog allowing the user to store |
28 // personal address and credit card information. | 28 // personal address and credit card information. |
29 @interface AutoFillDialogController : NSWindowController { | 29 @interface AutoFillDialogController : NSWindowController { |
30 @private | 30 @private |
31 IBOutlet NSView* childView_; | 31 // Outlet to the main NSTableView object listing both addresses and credit |
32 IBOutlet NSView* addressSection_; | 32 // cards with section headers for both. |
33 IBOutlet SectionSeparatorView* addressSectionBox_; | 33 IBOutlet AutoFillTableView* tableView_; |
34 IBOutlet NSView* creditCardSection_; | |
35 | 34 |
36 // Note on ownership: the controllers are strongly owned by the dialog | 35 // This observer is passed in by the caller of the dialog. When the dialog |
37 // controller. Their views are inserted into the dialog's view hierarchy | 36 // is dismissed |observer_| is called with new values for the addresses and |
38 // but are retained by these controllers as well. | 37 // credit cards. |
| 38 // Weak, not retained. |
| 39 AutoFillDialogObserver* observer_; |
39 | 40 |
40 // Array of |AutoFillAddressViewController|. | 41 // Reference to input parameter. |
41 scoped_nsobject<NSMutableArray> addressFormViewControllers_; | 42 // Weak, not retained. |
| 43 Profile* profile_; |
42 | 44 |
43 // Array of |AutoFillCreditCardViewController|. | 45 // Reference to input parameter. |
44 scoped_nsobject<NSMutableArray> creditCardFormViewControllers_; | 46 // Weak, not retained. |
| 47 AutoFillProfile* importedProfile_; |
45 | 48 |
46 AutoFillDialogObserver* observer_; // Weak, not retained. | 49 // Reference to input parameter. |
47 Profile* profile_; // Weak, not retained. | 50 // Weak, not retained. |
48 AutoFillProfile* importedProfile_; // Weak, not retained. | 51 CreditCard* importedCreditCard_; |
49 CreditCard* importedCreditCard_; // Weak, not retained. | 52 |
| 53 // Working list of input profiles. |
50 std::vector<AutoFillProfile> profiles_; | 54 std::vector<AutoFillProfile> profiles_; |
| 55 |
| 56 // Working list of input credit cards. |
51 std::vector<CreditCard> creditCards_; | 57 std::vector<CreditCard> creditCards_; |
| 58 |
| 59 // State of checkbox for enabling Mac Address Book integration. |
52 BOOL auxiliaryEnabled_; | 60 BOOL auxiliaryEnabled_; |
| 61 |
| 62 // State for |itemIsSelected| property used in bindings for "Edit..." and |
| 63 // "Remove" buttons. |
| 64 BOOL itemIsSelected_; |
| 65 |
| 66 // Utility object to save and restore dialog position. |
53 scoped_nsobject<WindowSizeAutosaver> sizeSaver_; | 67 scoped_nsobject<WindowSizeAutosaver> sizeSaver_; |
54 | 68 |
| 69 // Transient reference to address "Add" / "Edit" sheet for address |
| 70 // information. |
| 71 scoped_nsobject<AutoFillAddressSheetController> addressSheetController; |
| 72 |
| 73 // Transient reference to address "Add" / "Edit" sheet for credit card |
| 74 // information. |
| 75 scoped_nsobject<AutoFillCreditCardSheetController> creditCardSheetController; |
| 76 |
55 // Manages PersonalDataManager loading. | 77 // Manages PersonalDataManager loading. |
56 scoped_ptr<AutoFillDialogControllerInternal::PersonalDataManagerObserver> | 78 scoped_ptr<AutoFillDialogControllerInternal::PersonalDataManagerObserver> |
57 personalDataManagerObserver_; | 79 personalDataManagerObserver_; |
58 } | 80 } |
59 | 81 |
60 // Property representing state of Address Book "me" card usage. Checkbox is | 82 // Property representing state of Address Book "me" card usage. Checkbox is |
61 // bound to this in nib. | 83 // bound to this in nib. |
62 @property (nonatomic) BOOL auxiliaryEnabled; | 84 @property (nonatomic) BOOL auxiliaryEnabled; |
63 | 85 |
64 // Main interface for displaying an application modal autofill dialog on screen. | 86 // Property representing selection state in |tableView_|. Enabled state of |
| 87 // edit and delete buttons are bound to this property. |
| 88 @property (nonatomic) BOOL itemIsSelected; |
| 89 |
| 90 // Main interface for displaying an application modal AutoFill dialog on screen. |
65 // This class method creates a new |AutoFillDialogController| and runs it as a | 91 // This class method creates a new |AutoFillDialogController| and runs it as a |
66 // modal dialog. The controller autoreleases itself when the dialog is closed. | 92 // modal dialog. The controller autoreleases itself when the dialog is closed. |
67 // |observer| can be NULL, but if it is, then no notification is sent during | 93 // |observer| can be NULL, but if it is, then no notification is sent during |
68 // call to |save|. If |observer| is non-NULL then its |OnAutoFillDialogApply| | 94 // call to |save|. If |observer| is non-NULL then its |OnAutoFillDialogApply| |
69 // method is invoked during |save| with the new address and credit card | 95 // method is invoked during |save| with the new address and credit card |
70 // information. | 96 // information. |
71 // |profile| must be non-NULL. | 97 // |profile| must be non-NULL. |
72 // AutoFill profile and credit card data is initialized from the | 98 // AutoFill profile and credit card data is initialized from the |
73 // |PersonalDataManager| that is associated with the input |profile|. | 99 // |PersonalDataManager| that is associated with the input |profile|. |
74 // If |importedProfile| or |importedCreditCard| parameters are supplied then | 100 // If |importedProfile| or |importedCreditCard| parameters are supplied then |
75 // the |PersonalDataManager| data is ignored. Both may be NULL. | 101 // the |PersonalDataManager| data is ignored. Both may be NULL. |
76 + (void)showAutoFillDialogWithObserver:(AutoFillDialogObserver*)observer | 102 + (void)showAutoFillDialogWithObserver:(AutoFillDialogObserver*)observer |
77 profile:(Profile*)profile | 103 profile:(Profile*)profile |
78 importedProfile:(AutoFillProfile*)importedProfile | 104 importedProfile:(AutoFillProfile*)importedProfile |
79 importedCreditCard:(CreditCard*)importedCreditCard; | 105 importedCreditCard:(CreditCard*)importedCreditCard; |
80 | 106 |
81 // IBActions for the dialog buttons. | 107 // IBActions for the dialog buttons. |
82 - (IBAction)save:(id)sender; | 108 - (IBAction)save:(id)sender; |
83 - (IBAction)cancel:(id)sender; | 109 - (IBAction)cancel:(id)sender; |
84 | 110 |
85 // IBActions for adding new items. | 111 // IBActions for adding new items. |
86 - (IBAction)addNewAddress:(id)sender; | 112 - (IBAction)addNewAddress:(id)sender; |
87 - (IBAction)addNewCreditCard:(id)sender; | 113 - (IBAction)addNewCreditCard:(id)sender; |
88 | 114 |
89 // IBActions for deleting items. |sender| is expected to be either a | 115 // IBAction for deleting an item. |sender| is expected to be the "Remove" |
90 // |AutoFillAddressViewController| or a |AutoFillCreditCardViewController|. | 116 // button. The deletion acts on the selected item in either the address or |
91 - (IBAction)deleteAddress:(id)sender; | 117 // credit card list. |
92 - (IBAction)deleteCreditCard:(id)sender; | 118 - (IBAction)deleteSelection:(id)sender; |
93 | 119 |
94 // IBAction for sender to alert dialog that an address label has changed. | 120 // IBActions for editing an item. |sender| is expected to be the "Edit..." |
95 - (IBAction)notifyAddressChange:(id)sender; | 121 // button. The editing acts on the selected item in either the address or |
| 122 // credit card list. |
| 123 - (IBAction)editSelection:(id)sender; |
96 | 124 |
97 // Returns an array of labels representing the addresses in the | 125 // NSTableView data source methods. |
98 // |addressFormViewControllers_|. | 126 - (id)tableView:(NSTableView *)tableView |
| 127 objectValueForTableColumn:(NSTableColumn *)tableColumn |
| 128 row:(NSInteger)rowIndex; |
| 129 |
| 130 - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView; |
| 131 |
| 132 // Returns an array of labels representing the addresses in the |profiles_|. |
99 - (NSArray*)addressLabels; | 133 - (NSArray*)addressLabels; |
100 | 134 |
101 // Returns an array of labels representing the credit cards in the | |
102 // |creditCardFormViewControllers_|. | |
103 - (NSArray*)creditCardLabels; | |
104 | |
105 @end | 135 @end |
106 | 136 |
107 // Interface exposed for unit testing. | 137 // Interface exposed for unit testing. |
108 @interface AutoFillDialogController (ExposedForUnitTests) | 138 @interface AutoFillDialogController (ExposedForUnitTests) |
109 // Returns an instance of AutoFillDialogController. See |-initWithObserver| | 139 // Returns an instance of AutoFillDialogController. See |-initWithObserver| |
110 // for details about arguments. | 140 // for details about arguments. |
111 // Note: controller is autoreleased when |-closeDialog| is called. | 141 // Note: controller is autoreleased when |-closeDialog| is called. |
112 + (AutoFillDialogController*)controllerWithObserver: | 142 + (AutoFillDialogController*)controllerWithObserver: |
113 (AutoFillDialogObserver*)observer | 143 (AutoFillDialogObserver*)observer |
114 profile:(Profile*)profile | 144 profile:(Profile*)profile |
115 importedProfile:(AutoFillProfile*)importedProfile | 145 importedProfile:(AutoFillProfile*)importedProfile |
116 importedCreditCard:(CreditCard*)importedCreditCard; | 146 importedCreditCard:(CreditCard*)importedCreditCard; |
117 | 147 |
118 - (id)initWithObserver:(AutoFillDialogObserver*)observer | 148 - (id)initWithObserver:(AutoFillDialogObserver*)observer |
119 profile:(Profile*)profile | 149 profile:(Profile*)profile |
120 importedProfile:(AutoFillProfile*)importedProfile | 150 importedProfile:(AutoFillProfile*)importedProfile |
121 importedCreditCard:(CreditCard*)importedCreditCard; | 151 importedCreditCard:(CreditCard*)importedCreditCard; |
122 - (NSMutableArray*)addressFormViewControllers; | |
123 - (NSMutableArray*)creditCardFormViewControllers; | |
124 - (void)closeDialog; | 152 - (void)closeDialog; |
| 153 - (AutoFillAddressSheetController*)addressSheetController; |
| 154 - (AutoFillCreditCardSheetController*)creditCardSheetController; |
| 155 - (void)selectAddressAtIndex:(size_t)i; |
| 156 - (void)selectCreditCardAtIndex:(size_t)i; |
125 @end | 157 @end |
126 | 158 |
127 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_MAC_ | 159 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_MAC_ |
OLD | NEW |