blob: 292af786221150ee210a14c7943d583cb147a53f [file] [log] [blame]
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +01001// 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#include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h"
6
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +01007#include "base/bind.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +01008#include "base/mac/bundle_locations.h"
Ben Murdocheb525c52013-07-10 11:40:50 +01009#include "base/mac/scoped_nsobject.h"
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010010#include "base/message_loop/message_loop.h"
Ben Murdochfb250652013-07-31 11:42:55 +010011#include "base/strings/sys_string_conversions.h"
Ben Murdoch32409262013-08-07 11:04:47 +010012#include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h"
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010013#include "chrome/browser/ui/chrome_style.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010014#include "chrome/browser/ui/chrome_style.h"
15#include "chrome/browser/ui/chrome_style.h"
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010016#import "chrome/browser/ui/cocoa/autofill/autofill_account_chooser.h"
17#import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h"
Ben Murdochca12bfa2013-07-23 11:17:05 +010018#include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010019#import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h"
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010020#import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010021#import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h"
Ben Murdocheb525c52013-07-10 11:40:50 +010022#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010023#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h"
24#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_window.h"
Ben Murdochca12bfa2013-07-23 11:17:05 +010025#include "content/public/browser/web_contents.h"
26#include "content/public/browser/web_contents_view.h"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010027#import "ui/base/cocoa/flipped_view.h"
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010028#include "ui/base/cocoa/window_size_constants.h"
29
30namespace {
31
32const CGFloat kAccountChooserHeight = 20.0;
33const CGFloat kRelatedControlVerticalSpacing = 8.0;
34
35} // namespace;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010036
37namespace autofill {
38
39// static
40AutofillDialogView* AutofillDialogView::Create(
Ben Murdoch32409262013-08-07 11:04:47 +010041 AutofillDialogViewDelegate* delegate) {
42 return new AutofillDialogCocoa(delegate);
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010043}
44
Ben Murdoch32409262013-08-07 11:04:47 +010045AutofillDialogCocoa::AutofillDialogCocoa(AutofillDialogViewDelegate* delegate)
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010046 : close_weak_ptr_factory_(this),
Ben Murdoch32409262013-08-07 11:04:47 +010047 delegate_(delegate) {
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010048}
49
50AutofillDialogCocoa::~AutofillDialogCocoa() {
51}
52
53void AutofillDialogCocoa::Show() {
54 // This should only be called once.
Ben Murdoch32409262013-08-07 11:04:47 +010055 DCHECK(!sheet_delegate_.get());
56 sheet_delegate_.reset([[AutofillDialogWindowController alloc]
Ben Murdochbb1529c2013-08-08 10:24:53 +010057 initWithWebContents:delegate_->GetWebContents()
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010058 autofillDialog:this]);
Ben Murdocheb525c52013-07-10 11:40:50 +010059 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet(
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010060 [[CustomConstrainedWindowSheet alloc]
Ben Murdoch32409262013-08-07 11:04:47 +010061 initWithCustomWindow:[sheet_delegate_ window]]);
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010062 constrained_window_.reset(
Ben Murdochbb1529c2013-08-08 10:24:53 +010063 new ConstrainedWindowMac(this, delegate_->GetWebContents(), sheet));
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010064}
65
66void AutofillDialogCocoa::Hide() {
Ben Murdoch32409262013-08-07 11:04:47 +010067 [sheet_delegate_ hide];
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010068}
69
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010070void AutofillDialogCocoa::PerformClose() {
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010071 if (!close_weak_ptr_factory_.HasWeakPtrs()) {
72 base::MessageLoop::current()->PostTask(
73 FROM_HERE,
74 base::Bind(&AutofillDialogCocoa::CloseNow,
75 close_weak_ptr_factory_.GetWeakPtr()));
76 }
77}
78
79void AutofillDialogCocoa::CloseNow() {
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010080 constrained_window_->CloseWebContentsModalDialog();
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010081}
82
83void AutofillDialogCocoa::UpdateAccountChooser() {
Ben Murdoch32409262013-08-07 11:04:47 +010084 [sheet_delegate_ updateAccountChooser];
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010085}
86
87void AutofillDialogCocoa::UpdateButtonStrip() {
88}
89
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +010090void AutofillDialogCocoa::UpdateDetailArea() {
91}
92
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010093void AutofillDialogCocoa::UpdateForErrors() {
94}
95
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010096void AutofillDialogCocoa::UpdateNotificationArea() {
Ben Murdoch32409262013-08-07 11:04:47 +010097 [sheet_delegate_ updateNotificationArea];
Ben Murdocheb525c52013-07-10 11:40:50 +010098}
99
100void AutofillDialogCocoa::UpdateAutocheckoutStepsArea() {
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100101}
102
103void AutofillDialogCocoa::UpdateSection(DialogSection section) {
Ben Murdoch32409262013-08-07 11:04:47 +0100104 [sheet_delegate_ updateSection:section];
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100105}
106
107void AutofillDialogCocoa::FillSection(DialogSection section,
108 const DetailInput& originating_input) {
Ben Murdoch32409262013-08-07 11:04:47 +0100109 [sheet_delegate_ fillSection:section forInput:originating_input];
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100110}
111
112void AutofillDialogCocoa::GetUserInput(DialogSection section,
113 DetailOutputMap* output) {
Ben Murdoch32409262013-08-07 11:04:47 +0100114 [sheet_delegate_ getInputs:output forSection:section];
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100115}
116
117string16 AutofillDialogCocoa::GetCvc() {
118 return string16();
119}
120
121bool AutofillDialogCocoa::SaveDetailsLocally() {
Ben Murdoch32409262013-08-07 11:04:47 +0100122 return [sheet_delegate_ saveDetailsLocally];
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100123}
124
125const content::NavigationController* AutofillDialogCocoa::ShowSignIn() {
Ben Murdoch32409262013-08-07 11:04:47 +0100126 return [sheet_delegate_ showSignIn];
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100127}
128
129void AutofillDialogCocoa::HideSignIn() {
Ben Murdoch32409262013-08-07 11:04:47 +0100130 [sheet_delegate_ hideSignIn];
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100131}
132
133void AutofillDialogCocoa::UpdateProgressBar(double value) {}
134
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100135void AutofillDialogCocoa::ModelChanged() {
Ben Murdoch32409262013-08-07 11:04:47 +0100136 [sheet_delegate_ modelChanged];
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100137}
138
139void AutofillDialogCocoa::OnSignInResize(const gfx::Size& pref_size) {
140 // TODO(groby): Implement Mac support for this.
141}
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100142
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100143TestableAutofillDialogView* AutofillDialogCocoa::GetTestableView() {
144 return this;
145}
146
147void AutofillDialogCocoa::SubmitForTesting() {
Ben Murdoch32409262013-08-07 11:04:47 +0100148 [sheet_delegate_ accept:nil];
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100149}
150
151void AutofillDialogCocoa::CancelForTesting() {
Ben Murdoch32409262013-08-07 11:04:47 +0100152 [sheet_delegate_ cancel:nil];
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100153}
154
155string16 AutofillDialogCocoa::GetTextContentsOfInput(const DetailInput& input) {
156 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
157 DialogSection section = static_cast<DialogSection>(i);
158 DetailOutputMap contents;
Ben Murdoch32409262013-08-07 11:04:47 +0100159 [sheet_delegate_ getInputs:&contents forSection:section];
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100160 DetailOutputMap::const_iterator it = contents.find(&input);
161 if (it != contents.end())
162 return it->second;
163 }
164
165 NOTREACHED();
166 return string16();
167}
168
169void AutofillDialogCocoa::SetTextContentsOfInput(const DetailInput& input,
170 const string16& contents) {
Ben Murdoch32409262013-08-07 11:04:47 +0100171 [sheet_delegate_ setTextContents:base::SysUTF16ToNSString(contents)
Ben Murdochfb250652013-07-31 11:42:55 +0100172 forInput:input];
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100173}
174
175void AutofillDialogCocoa::SetTextContentsOfSuggestionInput(
176 DialogSection section,
177 const base::string16& text) {
Ben Murdoch32409262013-08-07 11:04:47 +0100178 [sheet_delegate_ setTextContents:base::SysUTF16ToNSString(text)
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100179 ofSuggestionForSection:section];
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100180}
181
182void AutofillDialogCocoa::ActivateInput(const DetailInput& input) {
Ben Murdoch32409262013-08-07 11:04:47 +0100183 [sheet_delegate_ activateFieldForInput:input];
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100184}
185
186gfx::Size AutofillDialogCocoa::GetSize() const {
Ben Murdoch32409262013-08-07 11:04:47 +0100187 return gfx::Size(NSSizeToCGSize([[sheet_delegate_ window] frame].size));
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100188}
189
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100190void AutofillDialogCocoa::OnConstrainedWindowClosed(
191 ConstrainedWindowMac* window) {
192 constrained_window_.reset();
Ben Murdoch32409262013-08-07 11:04:47 +0100193 // |this| belongs to |delegate_|, so no self-destruction here.
194 delegate_->ViewClosed();
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100195}
196
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100197} // autofill
198
199#pragma mark Window Controller
200
Ben Murdochca12bfa2013-07-23 11:17:05 +0100201@interface AutofillDialogWindowController ()
202
203// Notification that the WebContent's view frame has changed.
204- (void)onContentViewFrameDidChange:(NSNotification*)notification;
205
206@end
207
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100208@implementation AutofillDialogWindowController
209
210- (id)initWithWebContents:(content::WebContents*)webContents
211 autofillDialog:(autofill::AutofillDialogCocoa*)autofillDialog {
212 DCHECK(webContents);
213
Ben Murdocheb525c52013-07-10 11:40:50 +0100214 base::scoped_nsobject<ConstrainedWindowCustomWindow> window(
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100215 [[ConstrainedWindowCustomWindow alloc]
216 initWithContentRect:ui::kWindowSizeDeterminedLater]);
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100217
218 if ((self = [super initWithWindow:window])) {
219 webContents_ = webContents;
220 autofillDialog_ = autofillDialog;
221
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100222 mainContainer_.reset([[AutofillMainContainer alloc]
Ben Murdoch32409262013-08-07 11:04:47 +0100223 initWithDelegate:autofillDialog->delegate()]);
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100224 [mainContainer_ setTarget:self];
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100225
226 signInContainer_.reset(
227 [[AutofillSignInContainer alloc]
Ben Murdoch32409262013-08-07 11:04:47 +0100228 initWithDelegate:autofillDialog->delegate()]);
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100229 [[signInContainer_ view] setHidden:YES];
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100230
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100231 NSRect clientRect = [[mainContainer_ view] frame];
232 clientRect.origin = NSMakePoint(chrome_style::kClientBottomPadding,
233 chrome_style::kHorizontalPadding);
234 [[mainContainer_ view] setFrame:clientRect];
235 [[signInContainer_ view] setFrame:clientRect];
236
237 NSRect headerRect = clientRect;
238 headerRect.size.height = kAccountChooserHeight;
239 headerRect.origin.y = NSMaxY(clientRect);
240 accountChooser_.reset([[AutofillAccountChooser alloc]
241 initWithFrame:headerRect
Ben Murdoch32409262013-08-07 11:04:47 +0100242 delegate:autofillDialog->delegate()]);
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100243
244 // This needs a flipped content view because otherwise the size
245 // animation looks odd. However, replacing the contentView for constrained
246 // windows does not work - it does custom rendering.
Ben Murdocheb525c52013-07-10 11:40:50 +0100247 base::scoped_nsobject<NSView> flippedContentView(
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100248 [[FlippedView alloc] initWithFrame:NSZeroRect]);
249 [flippedContentView setSubviews:
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100250 @[accountChooser_, [mainContainer_ view], [signInContainer_ view]]];
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100251 [flippedContentView setAutoresizingMask:
252 (NSViewWidthSizable | NSViewHeightSizable)];
253 [[[self window] contentView] addSubview:flippedContentView];
Ben Murdocheb525c52013-07-10 11:40:50 +0100254 [mainContainer_ setAnchorView:[[accountChooser_ subviews] objectAtIndex:1]];
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100255
256 NSRect contentRect = clientRect;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100257 contentRect.origin = NSZeroPoint;
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100258 contentRect.size.width += 2 * chrome_style::kHorizontalPadding;
259 contentRect.size.height += NSHeight(headerRect) +
260 chrome_style::kClientBottomPadding +
261 chrome_style::kTitleTopPadding;
262 [self performLayout];
Ben Murdochca12bfa2013-07-23 11:17:05 +0100263
264 // Resizing the browser causes the ConstrainedWindow to move.
265 // Observe that to allow resizes based on browser size.
266 NSView* contentView = [[self window] contentView];
267 [contentView setPostsFrameChangedNotifications:YES];
268 [[NSNotificationCenter defaultCenter]
269 addObserver:self
270 selector:@selector(onContentViewFrameDidChange:)
271 name:NSWindowDidMoveNotification
272 object:[self window]];
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100273 }
274 return self;
275}
276
Ben Murdochca12bfa2013-07-23 11:17:05 +0100277- (void)dealloc {
278 [[NSNotificationCenter defaultCenter] removeObserver:self];
279 [super dealloc];
280}
281
282- (void)onContentViewFrameDidChange:(NSNotification*)notification {
283 [self performLayout];
284}
285
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100286- (void)requestRelayout {
287 [self performLayout];
288}
289
290- (NSSize)preferredSize {
291 NSSize contentSize;
292 // TODO(groby): Currently, keep size identical to main container.
293 // Change to allow autoresize of web contents.
294 contentSize = [mainContainer_ preferredSize];
295
296 NSSize headerSize = NSMakeSize(contentSize.width, kAccountChooserHeight);
297 NSSize size = NSMakeSize(
298 std::max(contentSize.width, headerSize.width),
Ben Murdochca12bfa2013-07-23 11:17:05 +0100299 contentSize.height + headerSize.height + kDetailTopPadding);
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100300 size.width += 2 * chrome_style::kHorizontalPadding;
301 size.height += chrome_style::kClientBottomPadding +
302 chrome_style::kTitleTopPadding;
Ben Murdochca12bfa2013-07-23 11:17:05 +0100303
304 // Show as much of the main view as is possible without going past the
305 // bottom of the browser window.
306 NSRect dialogFrameRect = [[self window] frame];
307 NSRect browserFrameRect =
308 [webContents_->GetView()->GetTopLevelNativeWindow() frame];
309 dialogFrameRect.size.height =
310 NSMaxY(dialogFrameRect) - NSMinY(browserFrameRect);
311 dialogFrameRect = [[self window] contentRectForFrameRect:dialogFrameRect];
312 size.height = std::min(NSHeight(dialogFrameRect), size.height);
313
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100314 return size;
315}
316
317- (void)performLayout {
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100318 NSRect contentRect = NSZeroRect;
319 contentRect.size = [self preferredSize];
320 NSRect clientRect = NSInsetRect(
321 contentRect, chrome_style::kHorizontalPadding, 0);
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100322 clientRect.origin.y = chrome_style::kClientBottomPadding;
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100323 clientRect.size.height -= chrome_style::kTitleTopPadding +
324 chrome_style::kClientBottomPadding;
325
Ben Murdochca12bfa2013-07-23 11:17:05 +0100326 NSRect headerRect, mainRect, dummyRect;
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100327 NSDivideRect(clientRect, &headerRect, &mainRect,
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100328 kAccountChooserHeight, NSMinYEdge);
Ben Murdochca12bfa2013-07-23 11:17:05 +0100329 NSDivideRect(mainRect, &dummyRect, &mainRect,
330 kDetailTopPadding, NSMinYEdge);
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100331
332 [accountChooser_ setFrame:headerRect];
333 if ([[signInContainer_ view] isHidden]) {
334 [[mainContainer_ view] setFrame:mainRect];
335 [mainContainer_ performLayout];
336 } else {
337 [[signInContainer_ view] setFrame:mainRect];
338 }
339
340 NSRect frameRect = [[self window] frameRectForContentRect:contentRect];
Ben Murdocheb525c52013-07-10 11:40:50 +0100341 [[self window] setFrame:frameRect display:YES];
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100342}
343
344- (IBAction)accept:(id)sender {
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100345 if ([mainContainer_ validate])
Ben Murdoch32409262013-08-07 11:04:47 +0100346 autofillDialog_->delegate()->OnAccept();
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100347}
348
349- (IBAction)cancel:(id)sender {
Ben Murdoch32409262013-08-07 11:04:47 +0100350 autofillDialog_->delegate()->OnCancel();
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100351 autofillDialog_->PerformClose();
352}
353
354- (void)hide {
Ben Murdoch32409262013-08-07 11:04:47 +0100355 autofillDialog_->delegate()->OnCancel();
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100356 autofillDialog_->PerformClose();
357}
358
359- (void)updateNotificationArea {
360 [mainContainer_ updateNotificationArea];
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100361}
362
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100363- (void)updateAccountChooser {
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100364 [accountChooser_ update];
Ben Murdocheb525c52013-07-10 11:40:50 +0100365 [mainContainer_ updateLegalDocuments];
366}
367
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100368- (void)updateSection:(autofill::DialogSection)section {
369 [[mainContainer_ sectionForId:section] update];
370}
371
Ben Murdochfb250652013-07-31 11:42:55 +0100372- (void)fillSection:(autofill::DialogSection)section
373 forInput:(const autofill::DetailInput&)input {
374 [[mainContainer_ sectionForId:section] fillForInput:input];
375}
376
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100377- (content::NavigationController*)showSignIn {
378 [signInContainer_ loadSignInPage];
379 [[mainContainer_ view] setHidden:YES];
380 [[signInContainer_ view] setHidden:NO];
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100381 [self performLayout];
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100382
383 return [signInContainer_ navigationController];
384}
385
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100386- (void)getInputs:(autofill::DetailOutputMap*)output
387 forSection:(autofill::DialogSection)section {
388 [[mainContainer_ sectionForId:section] getInputs:output];
389}
390
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100391- (BOOL)saveDetailsLocally {
392 return [mainContainer_ saveDetailsLocally];
393}
394
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100395- (void)hideSignIn {
396 [[signInContainer_ view] setHidden:YES];
397 [[mainContainer_ view] setHidden:NO];
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100398 [self performLayout];
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100399}
400
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100401- (void)modelChanged {
402 [mainContainer_ modelChanged];
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100403}
404
405@end
Ben Murdochfb250652013-07-31 11:42:55 +0100406
407
408@implementation AutofillDialogWindowController (TestableAutofillDialogView)
409
410- (void)setTextContents:(NSString*)text
411 forInput:(const autofill::DetailInput&)input {
412 for (size_t i = autofill::SECTION_MIN; i <= autofill::SECTION_MAX; ++i) {
413 autofill::DialogSection section = static_cast<autofill::DialogSection>(i);
414 // TODO(groby): Need to find the section for an input directly - wasteful.
415 [[mainContainer_ sectionForId:section] setFieldValue:text forInput:input];
416 }
417}
418
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100419- (void)setTextContents:(NSString*)text
420 ofSuggestionForSection:(autofill::DialogSection)section {
421 [[mainContainer_ sectionForId:section] setSuggestionFieldValue:text];
422}
423
Ben Murdochfb250652013-07-31 11:42:55 +0100424- (void)activateFieldForInput:(const autofill::DetailInput&)input {
425 for (size_t i = autofill::SECTION_MIN; i <= autofill::SECTION_MAX; ++i) {
426 autofill::DialogSection section = static_cast<autofill::DialogSection>(i);
427 [[mainContainer_ sectionForId:section] activateFieldForInput:input];
428 }
429}
430
431@end