| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/webui/constrained_web_dialog_delegate_base.h" | 5 #include "chrome/browser/ui/webui/constrained_web_dialog_delegate_base.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/memory/scoped_nsobject.h" | 9 #include "base/memory/scoped_nsobject.h" |
| 10 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" | 10 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" |
| 11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" | 11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" |
| 12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" | 12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "ui/gfx/size.h" | 14 #include "ui/gfx/size.h" |
| 15 #include "ui/web_dialogs/web_dialog_delegate.h" | 15 #include "ui/web_dialogs/web_dialog_delegate.h" |
| 16 #include "ui/web_dialogs/web_dialog_ui.h" | 16 #include "ui/web_dialogs/web_dialog_ui.h" |
| 17 #include "ui/web_dialogs/web_dialog_web_contents_delegate.h" | 17 #include "ui/web_dialogs/web_dialog_web_contents_delegate.h" |
| 18 | 18 |
| 19 using content::WebContents; | 19 using content::WebContents; |
| 20 using ui::WebDialogDelegate; | 20 using ui::WebDialogDelegate; |
| 21 using ui::WebDialogWebContentsDelegate; | 21 using ui::WebDialogWebContentsDelegate; |
| 22 | 22 |
| 23 class ConstrainedWebDialogDelegateMac : | 23 namespace { |
| 24 |
| 25 class ConstrainedWebDialogDelegateMac |
| 26 : public ConstrainedWebDialogDelegateBase { |
| 27 public: |
| 28 ConstrainedWebDialogDelegateMac( |
| 29 content::BrowserContext* browser_context, |
| 30 WebDialogDelegate* delegate, |
| 31 WebDialogWebContentsDelegate* tab_delegate) |
| 32 : ConstrainedWebDialogDelegateBase( |
| 33 browser_context, delegate, tab_delegate) {} |
| 34 |
| 35 // WebDialogWebContentsDelegate interface. |
| 36 virtual void CloseContents(WebContents* source) OVERRIDE { |
| 37 window_->CloseWebContentsModalDialog(); |
| 38 } |
| 39 |
| 40 void set_window(ConstrainedWindowMac* window) { window_ = window; } |
| 41 ConstrainedWindowMac* window() const { return window_; } |
| 42 |
| 43 private: |
| 44 // Weak, owned by ConstrainedWebDialogDelegateViewMac. |
| 45 ConstrainedWindowMac* window_; |
| 46 |
| 47 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateMac); |
| 48 }; |
| 49 |
| 50 } // namespace |
| 51 |
| 52 class ConstrainedWebDialogDelegateViewMac : |
| 24 public ConstrainedWindowMacDelegate, | 53 public ConstrainedWindowMacDelegate, |
| 25 public ConstrainedWebDialogDelegate { | 54 public ConstrainedWebDialogDelegate { |
| 26 | 55 |
| 27 public: | 56 public: |
| 28 ConstrainedWebDialogDelegateMac( | 57 ConstrainedWebDialogDelegateViewMac( |
| 29 content::BrowserContext* browser_context, | 58 content::BrowserContext* browser_context, |
| 30 WebDialogDelegate* delegate, | 59 WebDialogDelegate* delegate, |
| 31 WebDialogWebContentsDelegate* tab_delegate, | 60 WebDialogWebContentsDelegate* tab_delegate, |
| 32 content::WebContents* web_contents); | 61 content::WebContents* web_contents); |
| 33 virtual ~ConstrainedWebDialogDelegateMac() {} | 62 virtual ~ConstrainedWebDialogDelegateViewMac() {} |
| 34 | 63 |
| 35 // ConstrainedWebDialogDelegate interface | 64 // ConstrainedWebDialogDelegate interface |
| 36 virtual const WebDialogDelegate* | 65 virtual const WebDialogDelegate* |
| 37 GetWebDialogDelegate() const OVERRIDE { | 66 GetWebDialogDelegate() const OVERRIDE { |
| 38 return impl_->GetWebDialogDelegate(); | 67 return impl_->GetWebDialogDelegate(); |
| 39 } | 68 } |
| 40 virtual WebDialogDelegate* GetWebDialogDelegate() OVERRIDE { | 69 virtual WebDialogDelegate* GetWebDialogDelegate() OVERRIDE { |
| 41 return impl_->GetWebDialogDelegate(); | 70 return impl_->GetWebDialogDelegate(); |
| 42 } | 71 } |
| 43 virtual void OnDialogCloseFromWebUI() OVERRIDE { | 72 virtual void OnDialogCloseFromWebUI() OVERRIDE { |
| 44 return impl_->OnDialogCloseFromWebUI(); | 73 return impl_->OnDialogCloseFromWebUI(); |
| 45 } | 74 } |
| 46 virtual void ReleaseWebContentsOnDialogClose() OVERRIDE { | 75 virtual void ReleaseWebContentsOnDialogClose() OVERRIDE { |
| 47 return impl_->ReleaseWebContentsOnDialogClose(); | 76 return impl_->ReleaseWebContentsOnDialogClose(); |
| 48 } | 77 } |
| 49 virtual WebContentsModalDialog* GetWindow() OVERRIDE { | 78 virtual NativeWebContentsModalDialog GetNativeDialog() OVERRIDE { |
| 50 return impl_->GetWindow(); | 79 return constrained_window_->GetNativeDialog(); |
| 51 } | 80 } |
| 52 virtual WebContents* GetWebContents() OVERRIDE { | 81 virtual WebContents* GetWebContents() OVERRIDE { |
| 53 return impl_->GetWebContents(); | 82 return impl_->GetWebContents(); |
| 54 } | 83 } |
| 55 | 84 |
| 56 // ConstrainedWindowMacDelegate interface | 85 // ConstrainedWindowMacDelegate interface |
| 57 virtual void OnConstrainedWindowClosed( | 86 virtual void OnConstrainedWindowClosed( |
| 58 ConstrainedWindowMac* window) OVERRIDE { | 87 ConstrainedWindowMac* window) OVERRIDE { |
| 59 if (!impl_->closed_via_webui()) | 88 if (!impl_->closed_via_webui()) |
| 60 GetWebDialogDelegate()->OnDialogClosed(""); | 89 GetWebDialogDelegate()->OnDialogClosed(""); |
| 61 delete this; | 90 delete this; |
| 62 } | 91 } |
| 63 | 92 |
| 64 private: | 93 private: |
| 65 scoped_ptr<ConstrainedWebDialogDelegateBase> impl_; | 94 scoped_ptr<ConstrainedWebDialogDelegateMac> impl_; |
| 66 scoped_ptr<ConstrainedWindowMac> constrained_window_; | 95 scoped_ptr<ConstrainedWindowMac> constrained_window_; |
| 67 scoped_nsobject<NSWindow> window_; | 96 scoped_nsobject<NSWindow> window_; |
| 68 | 97 |
| 69 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateMac); | 98 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewMac); |
| 70 }; | 99 }; |
| 71 | 100 |
| 72 ConstrainedWebDialogDelegateMac::ConstrainedWebDialogDelegateMac( | 101 ConstrainedWebDialogDelegateViewMac::ConstrainedWebDialogDelegateViewMac( |
| 73 content::BrowserContext* browser_context, | 102 content::BrowserContext* browser_context, |
| 74 WebDialogDelegate* delegate, | 103 WebDialogDelegate* delegate, |
| 75 WebDialogWebContentsDelegate* tab_delegate, | 104 WebDialogWebContentsDelegate* tab_delegate, |
| 76 content::WebContents* web_contents) | 105 content::WebContents* web_contents) |
| 77 : impl_(new ConstrainedWebDialogDelegateBase(browser_context, | 106 : impl_(new ConstrainedWebDialogDelegateMac(browser_context, |
| 78 delegate, | 107 delegate, |
| 79 tab_delegate)) { | 108 tab_delegate)) { |
| 80 // Create a window to hold web_contents in the constrained sheet: | 109 // Create a window to hold web_contents in the constrained sheet: |
| 81 gfx::Size size; | 110 gfx::Size size; |
| 82 delegate->GetDialogSize(&size); | 111 delegate->GetDialogSize(&size); |
| 83 NSRect frame = NSMakeRect(0, 0, size.width(), size.height()); | 112 NSRect frame = NSMakeRect(0, 0, size.width(), size.height()); |
| 84 | 113 |
| 85 window_.reset( | 114 window_.reset( |
| 86 [[ConstrainedWindowCustomWindow alloc] initWithContentRect:frame]); | 115 [[ConstrainedWindowCustomWindow alloc] initWithContentRect:frame]); |
| 87 [GetWebContents()->GetNativeView() setFrame:frame]; | 116 [GetWebContents()->GetNativeView() setFrame:frame]; |
| 88 [[window_ contentView] addSubview:GetWebContents()->GetNativeView()]; | 117 [[window_ contentView] addSubview:GetWebContents()->GetNativeView()]; |
| 89 | 118 |
| 90 scoped_nsobject<CustomConstrainedWindowSheet> sheet( | 119 scoped_nsobject<CustomConstrainedWindowSheet> sheet( |
| 91 [[CustomConstrainedWindowSheet alloc] | 120 [[CustomConstrainedWindowSheet alloc] |
| 92 initWithCustomWindow:window_]); | 121 initWithCustomWindow:window_]); |
| 93 constrained_window_.reset(new ConstrainedWindowMac( | 122 constrained_window_.reset(new ConstrainedWindowMac( |
| 94 this, web_contents, sheet)); | 123 this, web_contents, sheet)); |
| 95 return impl_->set_window(constrained_window_.get()); | 124 |
| 125 impl_->set_window(constrained_window_.get()); |
| 96 } | 126 } |
| 97 | 127 |
| 98 ConstrainedWebDialogDelegate* CreateConstrainedWebDialog( | 128 ConstrainedWebDialogDelegate* CreateConstrainedWebDialog( |
| 99 content::BrowserContext* browser_context, | 129 content::BrowserContext* browser_context, |
| 100 WebDialogDelegate* delegate, | 130 WebDialogDelegate* delegate, |
| 101 WebDialogWebContentsDelegate* tab_delegate, | 131 WebDialogWebContentsDelegate* tab_delegate, |
| 102 content::WebContents* web_contents) { | 132 content::WebContents* web_contents) { |
| 103 // Deleted when the dialog closes. | 133 // Deleted when the dialog closes. |
| 104 ConstrainedWebDialogDelegateMac* constrained_delegate = | 134 ConstrainedWebDialogDelegateViewMac* constrained_delegate = |
| 105 new ConstrainedWebDialogDelegateMac( | 135 new ConstrainedWebDialogDelegateViewMac( |
| 106 browser_context, delegate, tab_delegate, web_contents); | 136 browser_context, delegate, tab_delegate, web_contents); |
| 107 return constrained_delegate; | 137 return constrained_delegate; |
| 108 } | 138 } |
| OLD | NEW |