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 #ifndef CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_MAC_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_MAC_ |
6 #define CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_MAC_ | 6 #define CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_MAC_ |
7 | 7 |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 | 9 |
| 10 #include "base/mac/scoped_nsobject.h" |
| 11 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 12 |
10 namespace content { | 13 namespace content { |
11 class WebContents; | 14 class WebContents; |
12 } | 15 } |
13 class ConstrainedWindowMac; | 16 class ConstrainedWindowMac; |
14 class SingleWebContentsDialogManagerCocoa; | 17 class SingleWebContentsDialogManagerCocoa; |
15 @protocol ConstrainedWindowSheet; | 18 @protocol ConstrainedWindowSheet; |
16 | 19 |
17 // A delegate for a constrained window. The delegate is notified when the | 20 // A delegate for a constrained window. The delegate is notified when the |
18 // window closes. | 21 // window closes. |
19 class ConstrainedWindowMacDelegate { | 22 class ConstrainedWindowMacDelegate { |
20 public: | 23 public: |
21 virtual void OnConstrainedWindowClosed(ConstrainedWindowMac* window) = 0; | 24 virtual void OnConstrainedWindowClosed(ConstrainedWindowMac* window) = 0; |
22 }; | 25 }; |
23 | 26 |
| 27 // Creates a ConstrainedWindowMac, shows the dialog, and returns it. |
| 28 std::unique_ptr<ConstrainedWindowMac> CreateAndShowWebModalDialogMac( |
| 29 ConstrainedWindowMacDelegate* delegate, |
| 30 content::WebContents* web_contents, |
| 31 id<ConstrainedWindowSheet> sheet); |
| 32 |
| 33 // Creates a ConstrainedWindowMac and returns it. |
| 34 std::unique_ptr<ConstrainedWindowMac> CreateWebModalDialogMac( |
| 35 ConstrainedWindowMacDelegate* delegate, |
| 36 content::WebContents* web_contents, |
| 37 id<ConstrainedWindowSheet> sheet); |
| 38 |
24 // Constrained window implementation for Mac. | 39 // Constrained window implementation for Mac. |
25 // Normally an instance of this class is owned by the delegate. The delegate | 40 // Normally an instance of this class is owned by the delegate. The delegate |
26 // should delete the instance when the window is closed. | 41 // should delete the instance when the window is closed. |
27 class ConstrainedWindowMac { | 42 class ConstrainedWindowMac { |
28 public: | 43 public: |
29 ConstrainedWindowMac(ConstrainedWindowMacDelegate* delegate, | 44 ConstrainedWindowMac(ConstrainedWindowMacDelegate* delegate, |
30 content::WebContents* web_contents, | 45 content::WebContents* web_contents, |
31 id<ConstrainedWindowSheet> sheet); | 46 id<ConstrainedWindowSheet> sheet); |
32 ~ConstrainedWindowMac(); | 47 ~ConstrainedWindowMac(); |
33 | 48 |
| 49 // Shows the constrained window. |
| 50 void ShowWebContentsModalDialog(); |
| 51 |
34 // Closes the constrained window. | 52 // Closes the constrained window. |
35 void CloseWebContentsModalDialog(); | 53 void CloseWebContentsModalDialog(); |
36 | 54 |
37 SingleWebContentsDialogManagerCocoa* manager() const { return manager_; } | 55 SingleWebContentsDialogManagerCocoa* manager() const { return manager_; } |
38 void set_manager(SingleWebContentsDialogManagerCocoa* manager) { | 56 void set_manager(SingleWebContentsDialogManagerCocoa* manager) { |
39 manager_ = manager; | 57 manager_ = manager; |
40 } | 58 } |
| 59 id<ConstrainedWindowSheet> sheet() const { return sheet_.get(); } |
41 | 60 |
42 // Called by |manager_| when the dialog is closing. | 61 // Called by |manager_| when the dialog is closing. |
43 void OnDialogClosing(); | 62 void OnDialogClosing(); |
44 | 63 |
| 64 // Whether or not the dialog was shown. If the dialog is auto-resizable, it |
| 65 // is hidden until its WebContents initially loads. |
| 66 bool DialogWasShown(); |
| 67 |
| 68 // Gets the dialog manager for |web_contents_|. |
| 69 web_modal::WebContentsModalDialogManager* GetDialogManager(); |
| 70 |
45 private: | 71 private: |
46 ConstrainedWindowMacDelegate* delegate_; // weak, owns us. | 72 ConstrainedWindowMacDelegate* delegate_; // weak, owns us. |
47 SingleWebContentsDialogManagerCocoa* manager_; // weak, owned by WCMDM. | 73 SingleWebContentsDialogManagerCocoa* manager_; // weak, owned by WCMDM. |
| 74 content::WebContents* web_contents_; // weak, owned by dialog initiator. |
| 75 base::scoped_nsprotocol<id<ConstrainedWindowSheet>> sheet_; |
| 76 scoped_ptr<SingleWebContentsDialogManagerCocoa> native_manager_; |
48 }; | 77 }; |
49 | 78 |
50 #endif // CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_MAC_ | 79 #endif // CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_MAC_ |
OLD | NEW |