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..ecef2be762b85345d706f159650f03283a542ead 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,185 @@ |
-// 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; |
+#import "chrome/browser/ui/cocoa/key_equivalent_constants.h" |
+#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(); |
- } |
+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]); |
+ 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() { |
+} |
- 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( |
+void AutofillDialogCocoa::UpdateNotificationArea() { |
+} |
+ |
+void AutofillDialogCocoa::UpdateSection(DialogSection section, |
+ UserInputAction action) { |
+} |
+ |
+void AutofillDialogCocoa::GetUserInput(DialogSection section, |
+ DetailOutputMap* output) { |
+} |
+ |
+string16 AutofillDialogCocoa::GetCvc() { |
+ return string16(); |
+} |
+ |
+bool AutofillDialogCocoa::UseBillingForShipping() { |
+ 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() { |
+ PerformClose(); |
+} |
+ |
+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 |
+ |
+- (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; |
+} |
- impl_->set_window(constrained_window_.get()); |
+- (IBAction)closeSheet:(id)sender { |
+ autofillDialog_->PerformClose(); |
} |
-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)buildWindowButtons { |
+ if (buttonContainer_.get()) |
+ return; |
+ |
+ buttonContainer_.reset([[GTMWidthBasedTweaker alloc] initWithFrame: |
+ ui::kWindowSizeDeterminedLater]); |
+ [buttonContainer_ |
+ setAutoresizingMask:(NSViewMinXMargin | NSViewMinYMargin)]; |
+ |
+ scoped_nsobject<NSButton> button( |
+ [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); |
+ [button setTitle:l10n_util::GetNSStringWithFixup(IDS_CANCEL)]; |
+ [button setKeyEquivalent:kKeyEquivalentEscape]; |
+ [button setTarget:self]; |
+ [button setAction:@selector(closeSheet:)]; |
+ [button sizeToFit]; |
+ [buttonContainer_ addSubview:button]; |
+ |
+ CGFloat nextX = NSMaxX([button frame]) + kButtonGap; |
+ button.reset([[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); |
+ [button setFrameOrigin:NSMakePoint(nextX, 0)]; |
+ [button setTitle:l10n_util::GetNSStringWithFixup( |
+ IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON)]; |
+ [button setKeyEquivalent:kKeyEquivalentReturn]; |
+ [button setTarget:self]; |
+ [button setAction:@selector(closeSheet:)]; |
+ [button sizeToFit]; |
+ [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_]; |
} |
+ |
+- (void)layoutButtons { |
+ scoped_nsobject<GTMUILocalizerAndLayoutTweaker> layoutTweaker( |
+ [[GTMUILocalizerAndLayoutTweaker alloc] init]); |
+ [layoutTweaker tweakUI:buttonContainer_]; |
+} |
+ |
+@end |