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

Side by Side Diff: chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm

Issue 21692002: Rename AutofillDialogController to AutofillDialogViewDelegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 4 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h" 5 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/mac/bundle_locations.h" 8 #include "base/mac/bundle_locations.h"
9 #include "base/mac/scoped_nsobject.h" 9 #include "base/mac/scoped_nsobject.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" 12 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h"
13 #include "chrome/browser/ui/chrome_style.h" 13 #include "chrome/browser/ui/chrome_style.h"
14 #include "chrome/browser/ui/chrome_style.h" 14 #include "chrome/browser/ui/chrome_style.h"
15 #include "chrome/browser/ui/chrome_style.h" 15 #include "chrome/browser/ui/chrome_style.h"
16 #import "chrome/browser/ui/cocoa/autofill/autofill_account_chooser.h" 16 #import "chrome/browser/ui/cocoa/autofill/autofill_account_chooser.h"
17 #import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h" 17 #import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h"
18 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" 18 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h"
19 #import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h" 19 #import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h"
20 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h" 20 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h"
21 #import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h" 21 #import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h"
22 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" 22 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h"
23 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.h" 23 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.h"
24 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi ndow.h" 24 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi ndow.h"
25 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
26 #include "content/public/browser/web_contents_view.h" 26 #include "content/public/browser/web_contents_view.h"
27 #import "ui/base/cocoa/flipped_view.h" 27 #import "ui/base/cocoa/flipped_view.h"
28 #include "ui/base/cocoa/window_size_constants.h" 28 #include "ui/base/cocoa/window_size_constants.h"
29 29
30 namespace { 30 namespace {
31 31
32 const CGFloat kAccountChooserHeight = 20.0; 32 const CGFloat kAccountChooserHeight = 20.0;
33 const CGFloat kRelatedControlVerticalSpacing = 8.0; 33 const CGFloat kRelatedControlVerticalSpacing = 8.0;
34 34
35 } // namespace; 35 } // namespace;
36 36
37 namespace autofill { 37 namespace autofill {
38 38
39 // static 39 // static
40 AutofillDialogView* AutofillDialogView::Create( 40 AutofillDialogView* AutofillDialogView::Create(
41 AutofillDialogController* controller) { 41 AutofillDialogViewDelegate* delegate) {
42 return new AutofillDialogCocoa(controller); 42 return new AutofillDialogCocoa(delegate);
43 } 43 }
44 44
45 AutofillDialogCocoa::AutofillDialogCocoa(AutofillDialogController* controller) 45 AutofillDialogCocoa::AutofillDialogCocoa(AutofillDialogViewDelegate* delegate)
46 : close_weak_ptr_factory_(this), 46 : close_weak_ptr_factory_(this),
47 controller_(controller) { 47 delegate_(delegate) {
48 } 48 }
49 49
50 AutofillDialogCocoa::~AutofillDialogCocoa() { 50 AutofillDialogCocoa::~AutofillDialogCocoa() {
51 } 51 }
52 52
53 void AutofillDialogCocoa::Show() { 53 void AutofillDialogCocoa::Show() {
54 // This should only be called once. 54 // This should only be called once.
55 DCHECK(!sheet_controller_.get()); 55 DCHECK(!sheet_delegate_.get());
56 sheet_controller_.reset([[AutofillDialogWindowController alloc] 56 sheet_delegate_.reset([[AutofillDialogWindowController alloc]
57 initWithWebContents:controller_->web_contents() 57 initWithWebContents:delegate_->web_contents()
58 autofillDialog:this]); 58 autofillDialog:this]);
59 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( 59 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet(
60 [[CustomConstrainedWindowSheet alloc] 60 [[CustomConstrainedWindowSheet alloc]
61 initWithCustomWindow:[sheet_controller_ window]]); 61 initWithCustomWindow:[sheet_delegate_ window]]);
62 constrained_window_.reset( 62 constrained_window_.reset(
63 new ConstrainedWindowMac(this, controller_->web_contents(), sheet)); 63 new ConstrainedWindowMac(this, delegate_->web_contents(), sheet));
64 } 64 }
65 65
66 void AutofillDialogCocoa::Hide() { 66 void AutofillDialogCocoa::Hide() {
67 [sheet_controller_ hide]; 67 [sheet_delegate_ hide];
68 } 68 }
69 69
70 void AutofillDialogCocoa::PerformClose() { 70 void AutofillDialogCocoa::PerformClose() {
71 if (!close_weak_ptr_factory_.HasWeakPtrs()) { 71 if (!close_weak_ptr_factory_.HasWeakPtrs()) {
72 base::MessageLoop::current()->PostTask( 72 base::MessageLoop::current()->PostTask(
73 FROM_HERE, 73 FROM_HERE,
74 base::Bind(&AutofillDialogCocoa::CloseNow, 74 base::Bind(&AutofillDialogCocoa::CloseNow,
75 close_weak_ptr_factory_.GetWeakPtr())); 75 close_weak_ptr_factory_.GetWeakPtr()));
76 } 76 }
77 } 77 }
78 78
79 void AutofillDialogCocoa::CloseNow() { 79 void AutofillDialogCocoa::CloseNow() {
80 constrained_window_->CloseWebContentsModalDialog(); 80 constrained_window_->CloseWebContentsModalDialog();
81 } 81 }
82 82
83 void AutofillDialogCocoa::UpdateAccountChooser() { 83 void AutofillDialogCocoa::UpdateAccountChooser() {
84 [sheet_controller_ updateAccountChooser]; 84 [sheet_delegate_ updateAccountChooser];
85 } 85 }
86 86
87 void AutofillDialogCocoa::UpdateButtonStrip() { 87 void AutofillDialogCocoa::UpdateButtonStrip() {
88 } 88 }
89 89
90 void AutofillDialogCocoa::UpdateDetailArea() { 90 void AutofillDialogCocoa::UpdateDetailArea() {
91 } 91 }
92 92
93 void AutofillDialogCocoa::UpdateForErrors() { 93 void AutofillDialogCocoa::UpdateForErrors() {
94 } 94 }
95 95
96 void AutofillDialogCocoa::UpdateNotificationArea() { 96 void AutofillDialogCocoa::UpdateNotificationArea() {
97 [sheet_controller_ updateNotificationArea]; 97 [sheet_delegate_ updateNotificationArea];
98 } 98 }
99 99
100 void AutofillDialogCocoa::UpdateAutocheckoutStepsArea() { 100 void AutofillDialogCocoa::UpdateAutocheckoutStepsArea() {
101 } 101 }
102 102
103 void AutofillDialogCocoa::UpdateSection(DialogSection section) { 103 void AutofillDialogCocoa::UpdateSection(DialogSection section) {
104 [sheet_controller_ updateSection:section]; 104 [sheet_delegate_ updateSection:section];
105 } 105 }
106 106
107 void AutofillDialogCocoa::FillSection(DialogSection section, 107 void AutofillDialogCocoa::FillSection(DialogSection section,
108 const DetailInput& originating_input) { 108 const DetailInput& originating_input) {
109 [sheet_controller_ fillSection:section forInput:originating_input]; 109 [sheet_delegate_ fillSection:section forInput:originating_input];
110 } 110 }
111 111
112 void AutofillDialogCocoa::GetUserInput(DialogSection section, 112 void AutofillDialogCocoa::GetUserInput(DialogSection section,
113 DetailOutputMap* output) { 113 DetailOutputMap* output) {
114 [sheet_controller_ getInputs:output forSection:section]; 114 [sheet_delegate_ getInputs:output forSection:section];
115 } 115 }
116 116
117 string16 AutofillDialogCocoa::GetCvc() { 117 string16 AutofillDialogCocoa::GetCvc() {
118 return string16(); 118 return string16();
119 } 119 }
120 120
121 bool AutofillDialogCocoa::SaveDetailsLocally() { 121 bool AutofillDialogCocoa::SaveDetailsLocally() {
122 return [sheet_controller_ saveDetailsLocally]; 122 return [sheet_delegate_ saveDetailsLocally];
123 } 123 }
124 124
125 const content::NavigationController* AutofillDialogCocoa::ShowSignIn() { 125 const content::NavigationController* AutofillDialogCocoa::ShowSignIn() {
126 return [sheet_controller_ showSignIn]; 126 return [sheet_delegate_ showSignIn];
127 } 127 }
128 128
129 void AutofillDialogCocoa::HideSignIn() { 129 void AutofillDialogCocoa::HideSignIn() {
130 [sheet_controller_ hideSignIn]; 130 [sheet_delegate_ hideSignIn];
131 } 131 }
132 132
133 void AutofillDialogCocoa::UpdateProgressBar(double value) {} 133 void AutofillDialogCocoa::UpdateProgressBar(double value) {}
134 134
135 void AutofillDialogCocoa::ModelChanged() { 135 void AutofillDialogCocoa::ModelChanged() {
136 [sheet_controller_ modelChanged]; 136 [sheet_delegate_ modelChanged];
137 } 137 }
138 138
139 void AutofillDialogCocoa::OnSignInResize(const gfx::Size& pref_size) { 139 void AutofillDialogCocoa::OnSignInResize(const gfx::Size& pref_size) {
140 // TODO(groby): Implement Mac support for this. 140 // TODO(groby): Implement Mac support for this.
141 } 141 }
142 142
143 TestableAutofillDialogView* AutofillDialogCocoa::GetTestableView() { 143 TestableAutofillDialogView* AutofillDialogCocoa::GetTestableView() {
144 return this; 144 return this;
145 } 145 }
146 146
147 void AutofillDialogCocoa::SubmitForTesting() { 147 void AutofillDialogCocoa::SubmitForTesting() {
148 [sheet_controller_ accept:nil]; 148 [sheet_delegate_ accept:nil];
149 } 149 }
150 150
151 void AutofillDialogCocoa::CancelForTesting() { 151 void AutofillDialogCocoa::CancelForTesting() {
152 [sheet_controller_ cancel:nil]; 152 [sheet_delegate_ cancel:nil];
153 } 153 }
154 154
155 string16 AutofillDialogCocoa::GetTextContentsOfInput(const DetailInput& input) { 155 string16 AutofillDialogCocoa::GetTextContentsOfInput(const DetailInput& input) {
156 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { 156 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
157 DialogSection section = static_cast<DialogSection>(i); 157 DialogSection section = static_cast<DialogSection>(i);
158 DetailOutputMap contents; 158 DetailOutputMap contents;
159 [sheet_controller_ getInputs:&contents forSection:section]; 159 [sheet_delegate_ getInputs:&contents forSection:section];
160 DetailOutputMap::const_iterator it = contents.find(&input); 160 DetailOutputMap::const_iterator it = contents.find(&input);
161 if (it != contents.end()) 161 if (it != contents.end())
162 return it->second; 162 return it->second;
163 } 163 }
164 164
165 NOTREACHED(); 165 NOTREACHED();
166 return string16(); 166 return string16();
167 } 167 }
168 168
169 void AutofillDialogCocoa::SetTextContentsOfInput(const DetailInput& input, 169 void AutofillDialogCocoa::SetTextContentsOfInput(const DetailInput& input,
170 const string16& contents) { 170 const string16& contents) {
171 [sheet_controller_ setTextContents:base::SysUTF16ToNSString(contents) 171 [sheet_delegate_ setTextContents:base::SysUTF16ToNSString(contents)
172 forInput:input]; 172 forInput:input];
173 } 173 }
174 174
175 void AutofillDialogCocoa::SetTextContentsOfSuggestionInput( 175 void AutofillDialogCocoa::SetTextContentsOfSuggestionInput(
176 DialogSection section, 176 DialogSection section,
177 const base::string16& text) { 177 const base::string16& text) {
178 [sheet_controller_ setTextContents:base::SysUTF16ToNSString(text) 178 [sheet_delegate_ setTextContents:base::SysUTF16ToNSString(text)
179 ofSuggestionForSection:section]; 179 ofSuggestionForSection:section];
180 } 180 }
181 181
182 void AutofillDialogCocoa::ActivateInput(const DetailInput& input) { 182 void AutofillDialogCocoa::ActivateInput(const DetailInput& input) {
183 [sheet_controller_ activateFieldForInput:input]; 183 [sheet_delegate_ activateFieldForInput:input];
184 } 184 }
185 185
186 gfx::Size AutofillDialogCocoa::GetSize() const { 186 gfx::Size AutofillDialogCocoa::GetSize() const {
187 return gfx::Size(NSSizeToCGSize([[sheet_controller_ window] frame].size)); 187 return gfx::Size(NSSizeToCGSize([[sheet_delegate_ window] frame].size));
188 } 188 }
189 189
190 void AutofillDialogCocoa::OnConstrainedWindowClosed( 190 void AutofillDialogCocoa::OnConstrainedWindowClosed(
191 ConstrainedWindowMac* window) { 191 ConstrainedWindowMac* window) {
192 constrained_window_.reset(); 192 constrained_window_.reset();
193 // |this| belongs to |controller_|, so no self-destruction here. 193 // |this| belongs to |delegate_|, so no self-destruction here.
194 controller_->ViewClosed(); 194 delegate_->ViewClosed();
195 } 195 }
196 196
197 } // autofill 197 } // autofill
198 198
199 #pragma mark Window Controller 199 #pragma mark Window Controller
200 200
201 @interface AutofillDialogWindowController () 201 @interface AutofillDialogWindowController ()
202 202
203 // Notification that the WebContent's view frame has changed. 203 // Notification that the WebContent's view frame has changed.
204 - (void)onContentViewFrameDidChange:(NSNotification*)notification; 204 - (void)onContentViewFrameDidChange:(NSNotification*)notification;
205 205
206 @end 206 @end
207 207
208 @implementation AutofillDialogWindowController 208 @implementation AutofillDialogWindowController
209 209
210 - (id)initWithWebContents:(content::WebContents*)webContents 210 - (id)initWithWebContents:(content::WebContents*)webContents
211 autofillDialog:(autofill::AutofillDialogCocoa*)autofillDialog { 211 autofillDialog:(autofill::AutofillDialogCocoa*)autofillDialog {
212 DCHECK(webContents); 212 DCHECK(webContents);
213 213
214 base::scoped_nsobject<ConstrainedWindowCustomWindow> window( 214 base::scoped_nsobject<ConstrainedWindowCustomWindow> window(
215 [[ConstrainedWindowCustomWindow alloc] 215 [[ConstrainedWindowCustomWindow alloc]
216 initWithContentRect:ui::kWindowSizeDeterminedLater]); 216 initWithContentRect:ui::kWindowSizeDeterminedLater]);
217 217
218 if ((self = [super initWithWindow:window])) { 218 if ((self = [super initWithWindow:window])) {
219 webContents_ = webContents; 219 webContents_ = webContents;
220 autofillDialog_ = autofillDialog; 220 autofillDialog_ = autofillDialog;
221 221
222 mainContainer_.reset([[AutofillMainContainer alloc] 222 mainContainer_.reset([[AutofillMainContainer alloc]
223 initWithController:autofillDialog->controller()]); 223 initWithDelegate:autofillDialog->delegate()]);
224 [mainContainer_ setTarget:self]; 224 [mainContainer_ setTarget:self];
225 225
226 signInContainer_.reset( 226 signInContainer_.reset(
227 [[AutofillSignInContainer alloc] 227 [[AutofillSignInContainer alloc]
228 initWithController:autofillDialog->controller()]); 228 initWithDelegate:autofillDialog->delegate()]);
229 [[signInContainer_ view] setHidden:YES]; 229 [[signInContainer_ view] setHidden:YES];
230 230
231 NSRect clientRect = [[mainContainer_ view] frame]; 231 NSRect clientRect = [[mainContainer_ view] frame];
232 clientRect.origin = NSMakePoint(chrome_style::kClientBottomPadding, 232 clientRect.origin = NSMakePoint(chrome_style::kClientBottomPadding,
233 chrome_style::kHorizontalPadding); 233 chrome_style::kHorizontalPadding);
234 [[mainContainer_ view] setFrame:clientRect]; 234 [[mainContainer_ view] setFrame:clientRect];
235 [[signInContainer_ view] setFrame:clientRect]; 235 [[signInContainer_ view] setFrame:clientRect];
236 236
237 NSRect headerRect = clientRect; 237 NSRect headerRect = clientRect;
238 headerRect.size.height = kAccountChooserHeight; 238 headerRect.size.height = kAccountChooserHeight;
239 headerRect.origin.y = NSMaxY(clientRect); 239 headerRect.origin.y = NSMaxY(clientRect);
240 accountChooser_.reset([[AutofillAccountChooser alloc] 240 accountChooser_.reset([[AutofillAccountChooser alloc]
241 initWithFrame:headerRect 241 initWithFrame:headerRect
242 controller:autofillDialog->controller()]); 242 delegate:autofillDialog->delegate()]);
243 243
244 // This needs a flipped content view because otherwise the size 244 // This needs a flipped content view because otherwise the size
245 // animation looks odd. However, replacing the contentView for constrained 245 // animation looks odd. However, replacing the contentView for constrained
246 // windows does not work - it does custom rendering. 246 // windows does not work - it does custom rendering.
247 base::scoped_nsobject<NSView> flippedContentView( 247 base::scoped_nsobject<NSView> flippedContentView(
248 [[FlippedView alloc] initWithFrame:NSZeroRect]); 248 [[FlippedView alloc] initWithFrame:NSZeroRect]);
249 [flippedContentView setSubviews: 249 [flippedContentView setSubviews:
250 @[accountChooser_, [mainContainer_ view], [signInContainer_ view]]]; 250 @[accountChooser_, [mainContainer_ view], [signInContainer_ view]]];
251 [flippedContentView setAutoresizingMask: 251 [flippedContentView setAutoresizingMask:
252 (NSViewWidthSizable | NSViewHeightSizable)]; 252 (NSViewWidthSizable | NSViewHeightSizable)];
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 } else { 336 } else {
337 [[signInContainer_ view] setFrame:mainRect]; 337 [[signInContainer_ view] setFrame:mainRect];
338 } 338 }
339 339
340 NSRect frameRect = [[self window] frameRectForContentRect:contentRect]; 340 NSRect frameRect = [[self window] frameRectForContentRect:contentRect];
341 [[self window] setFrame:frameRect display:YES]; 341 [[self window] setFrame:frameRect display:YES];
342 } 342 }
343 343
344 - (IBAction)accept:(id)sender { 344 - (IBAction)accept:(id)sender {
345 if ([mainContainer_ validate]) 345 if ([mainContainer_ validate])
346 autofillDialog_->controller()->OnAccept(); 346 autofillDialog_->delegate()->OnAccept();
347 } 347 }
348 348
349 - (IBAction)cancel:(id)sender { 349 - (IBAction)cancel:(id)sender {
350 autofillDialog_->controller()->OnCancel(); 350 autofillDialog_->delegate()->OnCancel();
351 autofillDialog_->PerformClose(); 351 autofillDialog_->PerformClose();
352 } 352 }
353 353
354 - (void)hide { 354 - (void)hide {
355 autofillDialog_->controller()->OnCancel(); 355 autofillDialog_->delegate()->OnCancel();
356 autofillDialog_->PerformClose(); 356 autofillDialog_->PerformClose();
357 } 357 }
358 358
359 - (void)updateNotificationArea { 359 - (void)updateNotificationArea {
360 [mainContainer_ updateNotificationArea]; 360 [mainContainer_ updateNotificationArea];
361 } 361 }
362 362
363 - (void)updateAccountChooser { 363 - (void)updateAccountChooser {
364 [accountChooser_ update]; 364 [accountChooser_ update];
365 [mainContainer_ updateLegalDocuments]; 365 [mainContainer_ updateLegalDocuments];
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 } 422 }
423 423
424 - (void)activateFieldForInput:(const autofill::DetailInput&)input { 424 - (void)activateFieldForInput:(const autofill::DetailInput&)input {
425 for (size_t i = autofill::SECTION_MIN; i <= autofill::SECTION_MAX; ++i) { 425 for (size_t i = autofill::SECTION_MIN; i <= autofill::SECTION_MAX; ++i) {
426 autofill::DialogSection section = static_cast<autofill::DialogSection>(i); 426 autofill::DialogSection section = static_cast<autofill::DialogSection>(i);
427 [[mainContainer_ sectionForId:section] activateFieldForInput:input]; 427 [[mainContainer_ sectionForId:section] activateFieldForInput:input];
428 } 428 }
429 } 429 }
430 430
431 @end 431 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h ('k') | chrome/browser/ui/cocoa/autofill/autofill_main_container.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698