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

Side by Side Diff: chrome/browser/autofill/autofill_dialog_controller_mac.mm

Issue 558066: Autofill dialog for the Mac. This is UI only at this point. The UI is not h... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "chrome/browser/autofill/autofill_dialog_controller_mac.h"
6 #include "base/mac_util.h"
7 #import "chrome/browser/autofill/autofill_address_model_mac.h"
8 #import "chrome/browser/autofill/autofill_address_view_controller_mac.h"
9 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h"
10 #import "chrome/browser/autofill/autofill_credit_card_view_controller_mac.h"
11 #import "chrome/browser/cocoa/disclosure_view_controller.h"
12 #import "chrome/browser/cocoa/section_separator_view.h"
13 #include "chrome/browser/profile.h"
14
15 @interface AutoFillDialogController (PrivateMethods)
16 - (void)runModalDialog;
17 - (void)installChildViews;
18 @end
19
20 @implementation AutoFillDialogController
21
22 + (void)showAutoFillDialogWithObserver:(AutoFillDialogObserver*)observer
23 autoFillProfiles:(const std::vector<AutoFillProfile*>&)profiles
24 creditCards:(const std::vector<CreditCard*>&)creditCards {
25 AutoFillDialogController* controller =
26 [AutoFillDialogController controllerWithObserver:observer
27 autoFillProfiles:profiles
28 creditCards:creditCards];
29
30 // Only run modal dialog if it is not already being shown.
31 if (![controller isWindowLoaded]) {
32 [controller runModalDialog];
33 }
34 }
35
36 - (void)awakeFromNib {
37 [addressSectionBox_ setShowTopLine:FALSE];
38 [self installChildViews];
39 }
40
41 // NSWindow Delegate callback. When the window closes the controller can
42 // be released.
43 - (void)windowWillClose:(NSNotification *)notification {
44 [self autorelease];
45 }
46
47
48 // Called when the user clicks the save button.
49 - (IBAction)save:(id)sender {
50 if (observer_) {
51 [addressFormViewController_ copyModelToProfile:&profiles_[0]];
52 [creditCardFormViewController_ copyModelToCreditCard:&creditCards_[0]];
53 observer_->OnAutoFillDialogApply(&profiles_, &creditCards_);
54 }
55 [self closeDialog];
56 }
57
58 // Called when the user clicks the cancel button. All we need to do is stop
59 // the modal session.
60 - (IBAction)cancel:(id)sender {
61 [self closeDialog];
62 }
63
64 @end
65
66 @implementation AutoFillDialogController (ExposedForUnitTests)
67
68 + (AutoFillDialogController*)controllerWithObserver:
69 (AutoFillDialogObserver*)observer
70 autoFillProfiles:(const std::vector<AutoFillProfile*>&)profiles
71 creditCards:(const std::vector<CreditCard*>&)creditCards {
72
73 // Deallocation is done upon window close. See |windowWillClose:|.
74 AutoFillDialogController* controller =
75 [[self alloc] initWithObserver:observer
76 autoFillProfiles:profiles
77 creditCards:creditCards];
78 return controller;
79 }
80
81
82 // This is the designated initializer for this class.
83 // |profiles| are non-retained immutable list of autofill profiles.
84 // |creditCards| are non-retained immutable list of credit card info.
85 - (id)initWithObserver:(AutoFillDialogObserver*)observer
86 autoFillProfiles:(const std::vector<AutoFillProfile*>&)profiles
87 creditCards:(const std::vector<CreditCard*>&)creditCards {
88 // Use initWithWindowNibPath: instead of initWithWindowNibName: so we
89 // can override it in a unit test.
90 NSString* nibpath = [mac_util::MainAppBundle()
91 pathForResource:@"AutoFillDialog"
92 ofType:@"nib"];
93 if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
94 observer_ = observer;
95
96 // Make local copy of |profiles|.
97 std::vector<AutoFillProfile*>::const_iterator i;
98 for (i = profiles.begin(); i != profiles.end(); ++i)
99 profiles_.push_back(**i);
100
101 // Make local copy of |creditCards|.
102 std::vector<CreditCard*>::const_iterator j;
103 for (j = creditCards.begin(); j != creditCards.end(); ++j)
104 creditCards_.push_back(**j);
105 }
106 return self;
107 }
108
109 // Close the dialog.
110 - (void)closeDialog {
111 [[self window] close];
112 [NSApp stopModal];
113 }
114
115 - (AutoFillAddressViewController*)addressFormViewController {
116 return addressFormViewController_.get();
117 }
118
119 - (AutoFillCreditCardViewController*)creditCardFormViewController {
120 return creditCardFormViewController_.get();
121 }
122
123 @end
124
125 @implementation AutoFillDialogController (PrivateMethods)
126
127 // Run application modal.
128 - (void)runModalDialog {
129 [NSApp runModalForWindow:[self window]];
130 }
131
132 // Install controller and views for the address form and the credit card form.
133 // They are installed into the appropriate sibling order so that they can be
134 // arranged vertically by the VerticalLayoutView class. We insert the views
135 // into the |childView_| but we hold onto the controllers and release them in
136 // our dealloc once the dialog closes.
137 - (void)installChildViews {
138 if (profiles_.size() > 0) {
139 AutoFillAddressViewController* autoFillAddressViewController =
140 [[AutoFillAddressViewController alloc] initWithProfile:profiles_[0]];
141 addressFormViewController_.reset(autoFillAddressViewController);
142
143 // Embed the child view into our (owned by us) target view.
144 [childView_ addSubview:[addressFormViewController_ view]
145 positioned:NSWindowBelow relativeTo:addressSection_];
146 [[addressFormViewController_ view] setFrameOrigin:NSMakePoint(0, 0)];
147 }
148
149 if (creditCards_.size() > 0) {
150 AutoFillCreditCardViewController* autoFillCreditCardViewController =
151 [[AutoFillCreditCardViewController alloc]
152 initWithCreditCard:creditCards_[0]];
153 creditCardFormViewController_.reset(autoFillCreditCardViewController);
154
155 // Embed the child view into our (owned by us) target view.
156 [childView_ addSubview:[creditCardFormViewController_ view]
157 positioned:NSWindowBelow relativeTo:creditCardSection_];
158 [[creditCardFormViewController_ view] setFrameOrigin:NSMakePoint(0, 0)];
159 }
160 }
161
162 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698