OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_MAC_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_MAC_H_ |
6 #define CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_MAC_H_ | 6 #define CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_MAC_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #import <Cocoa/Cocoa.h> | 9 #import <Cocoa/Cocoa.h> |
10 | 10 |
11 #include "chrome/browser/tab_contents/constrained_window.h" | 11 #include "chrome/browser/tab_contents/constrained_window.h" |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/scoped_nsobject.h" | 15 #include "base/scoped_nsobject.h" |
16 | 16 |
17 @class BrowserWindowController; | 17 @class BrowserWindowController; |
18 @class GTMWindowSheetController; | 18 @class GTMWindowSheetController; |
19 @class NSView; | 19 @class NSView; |
20 @class NSWindow; | 20 @class NSWindow; |
21 class TabContents; | 21 class TabContents; |
22 | 22 |
23 // Base class for constrained dialog delegates. Never inherit from this | 23 // Base class for constrained dialog delegates. Never inherit from this |
24 // directly. | 24 // directly. |
25 class ConstrainedWindowMacDelegate { | 25 class ConstrainedWindowMacDelegate { |
26 public: | 26 public: |
27 ConstrainedWindowMacDelegate() : is_sheet_open_(false) { } | 27 ConstrainedWindowMacDelegate() : is_sheet_open_(false) {} |
28 virtual ~ConstrainedWindowMacDelegate(); | 28 virtual ~ConstrainedWindowMacDelegate() {} |
29 | 29 |
30 // Tells the delegate to either delete itself or set up a task to delete | 30 // Tells the delegate to either delete itself or set up a task to delete |
31 // itself later. Note that you MUST close the sheet belonging to your delegate | 31 // itself later. Note that you MUST close the sheet belonging to your delegate |
32 // in this method. | 32 // in this method. |
33 virtual void DeleteDelegate() = 0; | 33 virtual void DeleteDelegate() = 0; |
34 | 34 |
35 // Called by the tab controller, you do not need to do anything yourself | 35 // Called by the tab controller, you do not need to do anything yourself |
36 // with this method. | 36 // with this method. |
37 virtual void RunSheet(GTMWindowSheetController* sheetController, | 37 virtual void RunSheet(GTMWindowSheetController* sheetController, |
38 NSView* view) = 0; | 38 NSView* view) = 0; |
39 protected: | 39 protected: |
40 // Returns true if this delegate's sheet is currently showing. | 40 // Returns true if this delegate's sheet is currently showing. |
41 bool is_sheet_open() { return is_sheet_open_; } | 41 bool is_sheet_open() { return is_sheet_open_; } |
42 | 42 |
43 private: | 43 private: |
44 bool is_sheet_open_; | 44 bool is_sheet_open_; |
45 void set_sheet_open(bool is_open) { is_sheet_open_ = is_open; } | 45 void set_sheet_open(bool is_open) { is_sheet_open_ = is_open; } |
46 friend class ConstrainedWindowMac; | 46 friend class ConstrainedWindowMac; |
47 }; | 47 }; |
48 | 48 |
49 // Subclass this for a dialog delegate that displays a system sheet such as | 49 // Subclass this for a dialog delegate that displays a system sheet such as |
50 // an NSAlert, an open or save file panel, etc. | 50 // an NSAlert, an open or save file panel, etc. |
51 class ConstrainedWindowMacDelegateSystemSheet | 51 class ConstrainedWindowMacDelegateSystemSheet |
52 : public ConstrainedWindowMacDelegate { | 52 : public ConstrainedWindowMacDelegate { |
53 public: | 53 public: |
54 ConstrainedWindowMacDelegateSystemSheet(id delegate, SEL didEndSelector) | 54 ConstrainedWindowMacDelegateSystemSheet(id delegate, SEL didEndSelector); |
55 : systemSheet_(nil), | 55 virtual ~ConstrainedWindowMacDelegateSystemSheet(); |
56 delegate_([delegate retain]), | |
57 didEndSelector_(didEndSelector) { } | |
58 | 56 |
59 protected: | 57 protected: |
60 void set_sheet(id sheet) { systemSheet_.reset([sheet retain]); } | 58 void set_sheet(id sheet); |
61 id sheet() { return systemSheet_; } | 59 id sheet() { return systemSheet_; } |
62 | 60 |
63 // Returns an NSArray to be passed as parameters to GTMWindowSheetController. | 61 // Returns an NSArray to be passed as parameters to GTMWindowSheetController. |
64 // Array's contents should be the arguments passed to the system sheet's | 62 // Array's contents should be the arguments passed to the system sheet's |
65 // beginSheetForWindow:... method. The window argument must be [NSNull null]. | 63 // beginSheetForWindow:... method. The window argument must be [NSNull null]. |
66 // | 64 // |
67 // The default implementation returns | 65 // The default implementation returns |
68 // [null window, delegate, didEndSelector, null contextInfo] | 66 // [null window, delegate, didEndSelector, null contextInfo] |
69 // Subclasses may override this if they show a system sheet which takes | 67 // Subclasses may override this if they show a system sheet which takes |
70 // different parameters. | 68 // different parameters. |
71 virtual NSArray* GetSheetParameters(id delegate, SEL didEndSelector); | 69 virtual NSArray* GetSheetParameters(id delegate, SEL didEndSelector); |
72 | 70 |
73 private: | 71 private: |
74 virtual void RunSheet(GTMWindowSheetController* sheetController, | 72 virtual void RunSheet(GTMWindowSheetController* sheetController, |
75 NSView* view); | 73 NSView* view); |
76 scoped_nsobject<id> systemSheet_; | 74 scoped_nsobject<id> systemSheet_; |
77 scoped_nsobject<id> delegate_; | 75 scoped_nsobject<id> delegate_; |
78 SEL didEndSelector_; | 76 SEL didEndSelector_; |
79 }; | 77 }; |
80 | 78 |
81 // Subclass this for a dialog delegate that displays a custom sheet, e.g. loaded | 79 // Subclass this for a dialog delegate that displays a custom sheet, e.g. loaded |
82 // from a nib file. | 80 // from a nib file. |
83 class ConstrainedWindowMacDelegateCustomSheet | 81 class ConstrainedWindowMacDelegateCustomSheet |
84 : public ConstrainedWindowMacDelegate { | 82 : public ConstrainedWindowMacDelegate { |
85 public: | 83 public: |
86 ConstrainedWindowMacDelegateCustomSheet() | 84 ConstrainedWindowMacDelegateCustomSheet(); |
87 : customSheet_(nil), | 85 ConstrainedWindowMacDelegateCustomSheet(id delegate, SEL didEndSelector); |
88 delegate_(nil), | 86 ~ConstrainedWindowMacDelegateCustomSheet(); |
89 didEndSelector_(NULL) { } | |
90 | |
91 ConstrainedWindowMacDelegateCustomSheet(id delegate, SEL didEndSelector) | |
92 : customSheet_(nil), | |
93 delegate_([delegate retain]), | |
94 didEndSelector_(didEndSelector) { } | |
95 | 87 |
96 protected: | 88 protected: |
97 // For when you need to delay initalization after the constructor call. | 89 // For when you need to delay initalization after the constructor call. |
98 void init(NSWindow* sheet, id delegate, SEL didEndSelector) { | 90 void init(NSWindow* sheet, id delegate, SEL didEndSelector); |
99 DCHECK(!delegate_.get()); | 91 void set_sheet(NSWindow* sheet); |
100 DCHECK(!didEndSelector_); | |
101 customSheet_.reset([sheet retain]); | |
102 delegate_.reset([delegate retain]); | |
103 didEndSelector_ = didEndSelector; | |
104 DCHECK(delegate_.get()); | |
105 DCHECK(didEndSelector_); | |
106 } | |
107 void set_sheet(NSWindow* sheet) { customSheet_.reset([sheet retain]); } | |
108 NSWindow* sheet() { return customSheet_; } | 92 NSWindow* sheet() { return customSheet_; } |
109 | 93 |
110 private: | 94 private: |
111 virtual void RunSheet(GTMWindowSheetController* sheetController, | 95 virtual void RunSheet(GTMWindowSheetController* sheetController, |
112 NSView* view); | 96 NSView* view); |
113 scoped_nsobject<NSWindow> customSheet_; | 97 scoped_nsobject<NSWindow> customSheet_; |
114 scoped_nsobject<id> delegate_; | 98 scoped_nsobject<id> delegate_; |
115 SEL didEndSelector_; | 99 SEL didEndSelector_; |
116 }; | 100 }; |
117 | 101 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 BrowserWindowController* controller_; | 140 BrowserWindowController* controller_; |
157 | 141 |
158 // Stores if |ShowConstrainedWindow()| was called. | 142 // Stores if |ShowConstrainedWindow()| was called. |
159 bool should_be_visible_; | 143 bool should_be_visible_; |
160 | 144 |
161 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowMac); | 145 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowMac); |
162 }; | 146 }; |
163 | 147 |
164 #endif // CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_MAC_H_ | 148 #endif // CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_MAC_H_ |
165 | 149 |
OLD | NEW |