Chromium Code Reviews| Index: chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm |
| diff --git a/chrome/browser/ui/cocoa/constrained_web_dialog_delegate_mac.mm b/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm |
| similarity index 11% |
| copy from chrome/browser/ui/cocoa/constrained_web_dialog_delegate_mac.mm |
| copy to chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm |
| index eaac62a9a63a47bf366af04311f62840f6ab3ea8..eaafcc82a084831e05fa06edcd4a3ea21fa024d8 100644 |
| --- a/chrome/browser/ui/cocoa/constrained_web_dialog_delegate_mac.mm |
| +++ b/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm |
| @@ -1,140 +1,187 @@ |
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/ui/webui/constrained_web_dialog_delegate_base.h" |
| - |
| -#import <Cocoa/Cocoa.h> |
| +#include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h" |
| +#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
| +#include "chrome/browser/ui/chrome_style.h" |
| +#include "base/mac/bundle_locations.h" |
| #include "base/memory/scoped_nsobject.h" |
| +#include "chrome/browser/ui/chrome_style.h" |
| #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h" |
| #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_window.h" |
| -#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" |
| -#include "content/public/browser/web_contents.h" |
| -#include "content/public/browser/web_contents_view.h" |
| -#include "ui/gfx/size.h" |
| -#include "ui/web_dialogs/web_dialog_delegate.h" |
| -#include "ui/web_dialogs/web_dialog_ui.h" |
| -#include "ui/web_dialogs/web_dialog_web_contents_delegate.h" |
| - |
| -using content::WebContents; |
| -using ui::WebDialogDelegate; |
| -using ui::WebDialogWebContentsDelegate; |
| +#include "grit/generated_resources.h" |
| +#import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| +#include "ui/base/cocoa/window_size_constants.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| namespace { |
| -class ConstrainedWebDialogDelegateMac |
| - : public ConstrainedWebDialogDelegateBase { |
| - public: |
| - ConstrainedWebDialogDelegateMac( |
| - content::BrowserContext* browser_context, |
| - WebDialogDelegate* delegate, |
| - WebDialogWebContentsDelegate* tab_delegate) |
| - : ConstrainedWebDialogDelegateBase( |
| - browser_context, delegate, tab_delegate) {} |
| - |
| - // WebDialogWebContentsDelegate interface. |
| - virtual void CloseContents(WebContents* source) OVERRIDE { |
| - window_->CloseWebContentsModalDialog(); |
| - } |
| +// TODO(groby): Should this be shared with ConstrainedWindowAlert? |
|
sail
2013/04/10 02:36:56
We could move this to constrained_window_control_u
groby-ooo-7-16
2013/04/12 03:13:40
Done.
|
| +const CGFloat kButtonGap = 6; |
| - void set_window(ConstrainedWindowMac* window) { window_ = window; } |
| - ConstrainedWindowMac* window() const { return window_; } |
| +} // namespace |
| - private: |
| - // Weak, owned by ConstrainedWebDialogDelegateViewMac. |
| - ConstrainedWindowMac* window_; |
| +namespace autofill { |
| - DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateMac); |
| -}; |
| +// static |
| +AutofillDialogView* AutofillDialogView::Create( |
| + AutofillDialogController* controller) { |
| + return new AutofillDialogCocoa(controller); |
| +} |
| -} // namespace |
| +AutofillDialogCocoa::AutofillDialogCocoa(AutofillDialogController* controller) |
| + : controller_(controller) { |
| + sheet_controller_.reset([[AutofillDialogWindowController alloc] |
| + initWithWebContents:controller_->web_contents() |
| + autofillDialog:this]); |
|
sail
2013/04/10 02:36:56
align on ":"
groby-ooo-7-16
2013/04/12 03:13:40
Done.
|
| + scoped_nsobject<CustomConstrainedWindowSheet> sheet( |
| + [[CustomConstrainedWindowSheet alloc] |
| + initWithCustomWindow:[sheet_controller_ window]]); |
| + constrained_window_.reset( |
| + new ConstrainedWindowMac(this, controller_->web_contents(), sheet)); |
| +} |
| -class ConstrainedWebDialogDelegateViewMac : |
| - public ConstrainedWindowMacDelegate, |
| - public ConstrainedWebDialogDelegate { |
| - |
| - public: |
| - ConstrainedWebDialogDelegateViewMac( |
| - content::BrowserContext* browser_context, |
| - WebDialogDelegate* delegate, |
| - WebDialogWebContentsDelegate* tab_delegate, |
| - content::WebContents* web_contents); |
| - virtual ~ConstrainedWebDialogDelegateViewMac() {} |
| - |
| - // ConstrainedWebDialogDelegate interface |
| - virtual const WebDialogDelegate* |
| - GetWebDialogDelegate() const OVERRIDE { |
| - return impl_->GetWebDialogDelegate(); |
| - } |
| - virtual WebDialogDelegate* GetWebDialogDelegate() OVERRIDE { |
| - return impl_->GetWebDialogDelegate(); |
| - } |
| - virtual void OnDialogCloseFromWebUI() OVERRIDE { |
| - return impl_->OnDialogCloseFromWebUI(); |
| - } |
| - virtual void ReleaseWebContentsOnDialogClose() OVERRIDE { |
| - return impl_->ReleaseWebContentsOnDialogClose(); |
| - } |
| - virtual NativeWebContentsModalDialog GetNativeDialog() OVERRIDE { |
| - return constrained_window_->GetNativeDialog(); |
| - } |
| - virtual WebContents* GetWebContents() OVERRIDE { |
| - return impl_->GetWebContents(); |
| - } |
| +AutofillDialogCocoa::~AutofillDialogCocoa() { |
| +} |
| - // ConstrainedWindowMacDelegate interface |
| - virtual void OnConstrainedWindowClosed( |
| - ConstrainedWindowMac* window) OVERRIDE { |
| - if (!impl_->closed_via_webui()) |
| - GetWebDialogDelegate()->OnDialogClosed(""); |
| - delete this; |
| - } |
| +void AutofillDialogCocoa::Show() { |
| +} |
| + |
| +void AutofillDialogCocoa::Hide() { |
| +} |
| + |
| +void AutofillDialogCocoa::UpdateAccountChooser() { |
| +} |
| + |
| +void AutofillDialogCocoa::UpdateButtonStrip() { |
| +} |
| + |
| +void AutofillDialogCocoa::UpdateNotificationArea() { |
| +} |
| + |
| +void AutofillDialogCocoa::UpdateSection(DialogSection section) { |
| +} |
| + |
| +void AutofillDialogCocoa::GetUserInput(DialogSection section, |
| + DetailOutputMap* output) { |
| +} |
| - private: |
| - scoped_ptr<ConstrainedWebDialogDelegateMac> impl_; |
| - scoped_ptr<ConstrainedWindowMac> constrained_window_; |
| - scoped_nsobject<NSWindow> window_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewMac); |
| -}; |
| - |
| -ConstrainedWebDialogDelegateViewMac::ConstrainedWebDialogDelegateViewMac( |
| - content::BrowserContext* browser_context, |
| - WebDialogDelegate* delegate, |
| - WebDialogWebContentsDelegate* tab_delegate, |
| - content::WebContents* web_contents) |
| - : impl_(new ConstrainedWebDialogDelegateMac(browser_context, |
| - delegate, |
| - tab_delegate)) { |
| - // Create a window to hold web_contents in the constrained sheet: |
| - gfx::Size size; |
| - delegate->GetDialogSize(&size); |
| - NSRect frame = NSMakeRect(0, 0, size.width(), size.height()); |
| - |
| - window_.reset( |
| +string16 AutofillDialogCocoa::GetCvc() { |
| + return string16(); |
| +} |
| + |
| +bool AutofillDialogCocoa::UseBillingForShipping() { |
| + return false; |
| +} |
| + |
| +bool AutofillDialogCocoa::SaveDetailsInWallet() { |
| + return false; |
| +} |
| + |
| +bool AutofillDialogCocoa::SaveDetailsLocally() { |
| + return false; |
| +} |
| + |
| +const content::NavigationController* AutofillDialogCocoa::ShowSignIn() { |
| + return NULL; |
| +} |
| + |
| +void AutofillDialogCocoa::HideSignIn() {} |
| + |
| +void AutofillDialogCocoa::UpdateProgressBar(double value) {} |
| + |
| +void AutofillDialogCocoa::ModelChanged() {} |
| + |
| +void AutofillDialogCocoa::SubmitForTesting() {} |
| + |
| +void AutofillDialogCocoa::CancelForTesting() {} |
| + |
| +void AutofillDialogCocoa::OnConstrainedWindowClosed( |
| + ConstrainedWindowMac* window) { |
| + constrained_window_.reset(); |
| + // |this| belongs to |controller_|, so no self-destruction here. |
| + controller_->ViewClosed(); |
| +} |
| + |
| +void AutofillDialogCocoa::PerformClose() { |
| + controller_->OnCancel(); |
| + constrained_window_->CloseWebContentsModalDialog(); |
| +} |
| + |
| +} // autofill |
| + |
| +#pragma mark Window Controller |
| + |
| +@implementation AutofillDialogWindowController |
|
sail
2013/04/10 02:36:56
new line after
groby-ooo-7-16
2013/04/12 03:13:40
Done.
|
| +- (id)initWithWebContents:(content::WebContents*)webContents |
| + autofillDialog:(autofill::AutofillDialogCocoa*)autofillDialog { |
| + DCHECK(webContents); |
| + |
| + // TODO(groby): Should be ui::kWindowSizeDeterminedLater |
| + NSRect frame = NSMakeRect(0, 0, 550, 600); |
| + scoped_nsobject<ConstrainedWindowCustomWindow> window( |
| [[ConstrainedWindowCustomWindow alloc] initWithContentRect:frame]); |
| - [GetWebContents()->GetView()->GetNativeView() setFrame:frame]; |
| - [[window_ contentView] |
| - addSubview:GetWebContents()->GetView()->GetNativeView()]; |
| - scoped_nsobject<CustomConstrainedWindowSheet> sheet( |
| - [[CustomConstrainedWindowSheet alloc] |
| - initWithCustomWindow:window_]); |
| - constrained_window_.reset(new ConstrainedWindowMac( |
| - this, web_contents, sheet)); |
| + if ((self = [super initWithWindow:window])) { |
| + webContents_ = webContents; |
| + autofillDialog_ = autofillDialog; |
| + |
| + [self buildWindowButtons]; |
| + [self layoutButtons]; |
| + } |
| + return self; |
| +} |
| + |
| +- (IBAction)closeSheet:(id)sender { |
| + autofillDialog_->PerformClose(); |
| +} |
| - impl_->set_window(constrained_window_.get()); |
| +- (void)buildWindowButtons { |
| + if (buttonContainer_.get()) |
| + return; |
| + |
| + buttonContainer_.reset([[GTMWidthBasedTweaker alloc] initWithFrame: |
| + ui::kWindowSizeDeterminedLater]); |
| + [buttonContainer_ |
| + setAutoresizingMask:(NSViewMinXMargin | NSViewMinYMargin)]; |
| + |
| + scoped_nsobject<NSButton> button( |
| + [[ConstrainedWindowButton alloc] initWithFrame: |
| + ui::kWindowSizeDeterminedLater]); |
|
sail
2013/04/10 02:36:56
This definitely works. An alternative is to use NS
groby-ooo-7-16
2013/04/12 03:13:40
I take it NSControls can be created with zero size
|
| + [button setTitle:l10n_util::GetNSString(IDS_CANCEL)]; |
|
sail
2013/04/10 02:36:56
GetNSStringWithFixup (more below)
groby-ooo-7-16
2013/04/12 03:13:40
Done.
|
| + [button setKeyEquivalent:@"\e"]; |
|
sail
2013/04/10 02:36:56
use kKeyEquivalentEscape?
groby-ooo-7-16
2013/04/12 03:13:40
Done.
|
| + [button setTarget:self]; |
| + [button setAction:@selector(closeSheet:)]; |
| + [buttonContainer_ addSubview:button]; |
| + |
| + button.reset([[ConstrainedWindowButton alloc] initWithFrame: |
| + ui::kWindowSizeDeterminedLater]); |
| + [button setFrameOrigin:NSMakePoint(NSWidth([button frame]) + kButtonGap, 0)]; |
| + [button |
| + setTitle:l10n_util::GetNSString(IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON)]; |
| + [button setKeyEquivalent:@"\r"]; |
|
sail
2013/04/10 02:36:56
use kKeyEquivalentReturn?
groby-ooo-7-16
2013/04/12 03:13:40
Done.
|
| + [button setTarget:self]; |
| + [button setAction:@selector(closeSheet:)]; |
| + [buttonContainer_ addSubview:button]; |
| + |
| + const CGFloat dialogOffset = NSWidth([[self window] frame]) - |
| + chrome_style::kHorizontalPadding - NSMaxX([button frame]); |
| + [buttonContainer_ setFrame: |
| + NSMakeRect(dialogOffset, chrome_style::kClientBottomPadding, |
| + NSMaxX([button frame]), NSMaxY([button frame]))]; |
| + |
| + [[[self window] contentView] addSubview:buttonContainer_]; |
| } |
| -ConstrainedWebDialogDelegate* CreateConstrainedWebDialog( |
| - content::BrowserContext* browser_context, |
| - WebDialogDelegate* delegate, |
| - WebDialogWebContentsDelegate* tab_delegate, |
| - content::WebContents* web_contents) { |
| - // Deleted when the dialog closes. |
| - ConstrainedWebDialogDelegateViewMac* constrained_delegate = |
| - new ConstrainedWebDialogDelegateViewMac( |
| - browser_context, delegate, tab_delegate, web_contents); |
| - return constrained_delegate; |
| +- (void)layoutButtons { |
| + GTMUILocalizerAndLayoutTweaker* layoutTweaker = |
|
sail
2013/04/10 02:36:56
scoped_nsobject?
groby-ooo-7-16
2013/04/12 03:13:40
Done.
|
| + [[[GTMUILocalizerAndLayoutTweaker alloc] init] autorelease]; |
| + [layoutTweaker tweakUI:buttonContainer_]; |
| + NSRect frame = [buttonContainer_ frame]; |
| + frame.size.height = |
| + NSHeight([[[buttonContainer_ subviews] objectAtIndex:0] frame]); |
| + [buttonContainer_ setFrame:frame]; |
| } |
|
sail
2013/04/10 02:36:56
new line after?
groby-ooo-7-16
2013/04/12 03:13:40
Done.
|
| +@end |