Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: chrome/browser/cocoa/constrained_window_mac.h

Issue 164547: Mac: make save/open dialogs operate as tab-modal sheets.... Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Painfully (but hopefully correctly) merged ToT. Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_COCOA_CONSTRAINED_WINDOW_MAC_H_ 5 #ifndef CHROME_BROWSER_COCOA_CONSTRAINED_WINDOW_MAC_H_
6 #define CHROME_BROWSER_COCOA_CONSTRAINED_WINDOW_MAC_H_ 6 #define CHROME_BROWSER_COCOA_CONSTRAINED_WINDOW_MAC_H_
7 7
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 9
10 #include "chrome/browser/tab_contents/constrained_window.h" 10 #include "chrome/browser/tab_contents/constrained_window.h"
(...skipping 12 matching lines...) Expand all
23 class ConstrainedWindowMacDelegate { 23 class ConstrainedWindowMacDelegate {
24 public: 24 public:
25 ConstrainedWindowMacDelegate() : is_sheet_open_(false) { } 25 ConstrainedWindowMacDelegate() : is_sheet_open_(false) { }
26 virtual ~ConstrainedWindowMacDelegate(); 26 virtual ~ConstrainedWindowMacDelegate();
27 27
28 // Tells the delegate to either delete itself or set up a task to delete 28 // Tells the delegate to either delete itself or set up a task to delete
29 // itself later. Note that you MUST close the sheet belonging to your delegate 29 // itself later. Note that you MUST close the sheet belonging to your delegate
30 // in this method. 30 // in this method.
31 virtual void DeleteDelegate() = 0; 31 virtual void DeleteDelegate() = 0;
32 32
33 // Responds to things done by the parent tab. Called by
34 // |ConstrainedWindowMac::ParentWillDo()|. Returns |true| if it did something
35 // in response, |false| if it did not and if
36 // |ConstrainedWindowMac::ParentWillDo()| should run its default handler. The
37 // default implementation just returns |false|.
38 virtual bool ParentWillDo(ConstrainedWindow::Event event) { return false; }
39
40 // Gives the modality level of the constrained window. The default
41 // implementation just specifies "content-modality".
42 virtual ConstrainedWindow::ModalityLevel GetModalityLevel()
43 { return ConstrainedWindow::kModalForContent; }
44
33 // Called by the tab controller, you do not need to do anything yourself 45 // Called by the tab controller, you do not need to do anything yourself
34 // with this method. 46 // with this method.
35 virtual void RunSheet(GTMWindowSheetController* sheetController, 47 virtual void RunSheet(GTMWindowSheetController* sheetController,
36 NSView* view) = 0; 48 NSView* view,
49 SEL frameSelector,
50 SEL positionSelector) = 0;
37 protected: 51 protected:
38 // Returns true if this delegate's sheet is currently showing. 52 // Returns true if this delegate's sheet is currently showing.
39 bool is_sheet_open() { return is_sheet_open_; } 53 bool is_sheet_open() { return is_sheet_open_; }
40 54
41 private: 55 private:
42 bool is_sheet_open_; 56 bool is_sheet_open_;
43 void set_sheet_open(bool is_open) { is_sheet_open_ = is_open; } 57 void set_sheet_open(bool is_open) { is_sheet_open_ = is_open; }
44 friend class ConstrainedWindowMac; 58 friend class ConstrainedWindowMac;
45 }; 59 };
46 60
47 // Subclass this for a dialog delegate that displays a system sheet such as 61 // Subclass this for a dialog delegate that displays a system sheet such as
48 // an NSAlert, an open or save file panel, etc. 62 // an NSSavePanel, NSOpenPanel, etc. This can handle any system sheet that GTM
49 class ConstrainedWindowMacDelegateSystemSheet 63 // supports (if in a somewhat ugly way).
64 class ConstrainedWindowMacDelegateSystemSheetParams
50 : public ConstrainedWindowMacDelegate { 65 : public ConstrainedWindowMacDelegate {
51 public: 66 public:
52 ConstrainedWindowMacDelegateSystemSheet(id delegate, SEL didEndSelector) 67 // See third_party/GTM/AppKit/GTMWindowSheetController.h for the format of
68 // |params|.
69 explicit ConstrainedWindowMacDelegateSystemSheetParams(NSArray* params)
53 : systemSheet_(nil), 70 : systemSheet_(nil),
54 delegate_([delegate retain]), 71 params_([params retain]) { }
55 didEndSelector_(didEndSelector) { }
56 72
57 protected: 73 protected:
58 void set_sheet(id sheet) { systemSheet_.reset([sheet retain]); } 74 void set_sheet(id sheet) { systemSheet_.reset([sheet retain]); }
59 id sheet() { return systemSheet_; } 75 id sheet() { return systemSheet_; }
76 void set_params(NSArray* params) { params_.reset([params retain]); }
77 NSArray* params() { return static_cast<NSArray*>(params_); }
78 virtual void RunSheet(GTMWindowSheetController* sheetController,
79 NSView* view,
80 SEL frameSelector,
81 SEL positionSelector);
82
83 private:
84 scoped_nsobject<id> systemSheet_;
85 scoped_nsobject<id> params_;
86 };
87
88 // Subclass this for a dialog delegate that displays a system sheet such as
89 // an NSAlert or other simple panel.
90 class ConstrainedWindowMacDelegateSystemSheet
91 : public ConstrainedWindowMacDelegateSystemSheetParams {
92 public:
93 ConstrainedWindowMacDelegateSystemSheet(id delegate, SEL didEndSelector)
94 : ConstrainedWindowMacDelegateSystemSheetParams(nil),
95 delegate_([delegate retain]),
96 didEndSelector_(didEndSelector) { }
60 97
61 private: 98 private:
62 virtual void RunSheet(GTMWindowSheetController* sheetController, 99 virtual void RunSheet(GTMWindowSheetController* sheetController,
63 NSView* view); 100 NSView* view,
64 scoped_nsobject<id> systemSheet_; 101 SEL frameSelector,
102 SEL positionSelector);
65 scoped_nsobject<id> delegate_; 103 scoped_nsobject<id> delegate_;
66 SEL didEndSelector_; 104 SEL didEndSelector_;
67 }; 105 };
68 106
69 // Subclass this for a dialog delegate that displays a custom sheet, e.g. loaded 107 // Subclass this for a dialog delegate that displays a custom sheet, e.g. loaded
70 // from a nib file. 108 // from a nib file.
71 class ConstrainedWindowMacDelegateCustomSheet 109 class ConstrainedWindowMacDelegateCustomSheet
72 : public ConstrainedWindowMacDelegate { 110 : public ConstrainedWindowMacDelegate {
73 public: 111 public:
74 ConstrainedWindowMacDelegateCustomSheet() 112 ConstrainedWindowMacDelegateCustomSheet()
(...skipping 15 matching lines...) Expand all
90 delegate_.reset([delegate retain]); 128 delegate_.reset([delegate retain]);
91 didEndSelector_ = didEndSelector; 129 didEndSelector_ = didEndSelector;
92 DCHECK(delegate_.get()); 130 DCHECK(delegate_.get());
93 DCHECK(didEndSelector_); 131 DCHECK(didEndSelector_);
94 } 132 }
95 void set_sheet(NSWindow* sheet) { customSheet_.reset([sheet retain]); } 133 void set_sheet(NSWindow* sheet) { customSheet_.reset([sheet retain]); }
96 NSWindow* sheet() { return customSheet_; } 134 NSWindow* sheet() { return customSheet_; }
97 135
98 private: 136 private:
99 virtual void RunSheet(GTMWindowSheetController* sheetController, 137 virtual void RunSheet(GTMWindowSheetController* sheetController,
100 NSView* view); 138 NSView* view,
139 SEL frameSelector,
140 SEL positionSelector);
101 scoped_nsobject<NSWindow> customSheet_; 141 scoped_nsobject<NSWindow> customSheet_;
102 scoped_nsobject<id> delegate_; 142 scoped_nsobject<id> delegate_;
103 SEL didEndSelector_; 143 SEL didEndSelector_;
104 }; 144 };
105 145
106 // Constrained window implementation for the Mac port. A constrained window 146 // Constrained window implementation for the Mac port. A constrained window
107 // is a per-tab sheet on OS X. 147 // is a per-tab sheet on OS X.
108 // 148 //
109 // Constrained windows work slightly differently on OS X than on the other 149 // Constrained windows work slightly differently on OS X than on the other
110 // platforms: 150 // platforms:
111 // 1. A constrained window is bound to both a tab and window on OS X. 151 // 1. A constrained window is bound to both a tab and window on OS X.
112 // 2. The delegate is responsible for closing the sheet again when it is 152 // 2. The delegate is responsible for closing the sheet again when it is
113 // deleted. 153 // deleted.
114 class ConstrainedWindowMac : public ConstrainedWindow { 154 class ConstrainedWindowMac : public ConstrainedWindow {
115 public: 155 public:
116 virtual ~ConstrainedWindowMac(); 156 virtual ~ConstrainedWindowMac();
117 157
118 // Overridden from ConstrainedWindow: 158 // Overridden from ConstrainedWindow:
119 virtual void CloseConstrainedWindow(); 159 virtual void CloseConstrainedWindow();
160 virtual bool ParentWillDo(ConstrainedWindow::Event event);
161
162 // This returns a cached result from the delegate. It can't just get the
163 // delegate to answer because we may outlive the delegate.
164 virtual ConstrainedWindow::ModalityLevel GetModalityLevel()
165 { return modality_level_; }
120 166
121 // Returns the TabContents that constrains this Constrained Window. 167 // Returns the TabContents that constrains this Constrained Window.
122 TabContents* owner() const { return owner_; } 168 TabContents* owner() const { return owner_; }
123 169
124 // Returns the window's delegate. 170 // Returns the window's delegate.
125 ConstrainedWindowMacDelegate* delegate() { return delegate_; } 171 ConstrainedWindowMacDelegate* delegate() { return delegate_; }
126 172
127 // Makes the constrained window visible, if it is not yet visible. 173 // Makes the constrained window visible, if it is not yet visible.
128 void Realize(BrowserWindowController* controller); 174 void Realize(BrowserWindowController* controller);
129 175
130 private: 176 private:
131 friend class ConstrainedWindow; 177 friend class ConstrainedWindow;
132 178
133 ConstrainedWindowMac(TabContents* owner, 179 ConstrainedWindowMac(TabContents* owner,
134 ConstrainedWindowMacDelegate* delegate); 180 ConstrainedWindowMacDelegate* delegate);
135 181
136 // The TabContents that owns and constrains this ConstrainedWindow. 182 // The TabContents that owns and constrains this ConstrainedWindow.
137 TabContents* owner_; 183 TabContents* owner_;
138 184
139 // Delegate that provides the contents of this constrained window. 185 // Delegate that provides the contents of this constrained window.
140 ConstrainedWindowMacDelegate* delegate_; 186 ConstrainedWindowMacDelegate* delegate_;
141 187
142 // Controller of the window that contains this sheet. 188 // Controller of the window that contains this sheet.
143 BrowserWindowController* controller_; 189 BrowserWindowController* controller_;
144 190
191 // Level of modality (cached result from delegate).
192 ConstrainedWindow::ModalityLevel modality_level_;
193
145 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowMac); 194 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowMac);
146 }; 195 };
147 196
148 #endif // CHROME_BROWSER_COCOA_CONSTRAINED_WINDOW_MAC_H_ 197 #endif // CHROME_BROWSER_COCOA_CONSTRAINED_WINDOW_MAC_H_
149
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/browser_window_controller.mm ('k') | chrome/browser/cocoa/constrained_window_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698