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

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

Issue 459008: Mac: the return of the tab-modal-sheets patch. (Closed)
Patch Set: Merged ToT. Must ... commit ... soon. Created 11 years 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
« no previous file with comments | « chrome/browser/browser.cc ('k') | chrome/browser/cocoa/constrained_window_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 13 matching lines...) Expand all
24 class ConstrainedWindowMacDelegate { 24 class ConstrainedWindowMacDelegate {
25 public: 25 public:
26 ConstrainedWindowMacDelegate() : is_sheet_open_(false) { } 26 ConstrainedWindowMacDelegate() : is_sheet_open_(false) { }
27 virtual ~ConstrainedWindowMacDelegate(); 27 virtual ~ConstrainedWindowMacDelegate();
28 28
29 // Tells the delegate to either delete itself or set up a task to delete 29 // Tells the delegate to either delete itself or set up a task to delete
30 // itself later. Note that you MUST close the sheet belonging to your delegate 30 // itself later. Note that you MUST close the sheet belonging to your delegate
31 // in this method. 31 // in this method.
32 virtual void DeleteDelegate() = 0; 32 virtual void DeleteDelegate() = 0;
33 33
34 // Responds to things done by the parent tab. Called by
35 // |ConstrainedWindowMac::ParentWillDo()|. Returns |true| if it did something
36 // in response, |false| if it did not and if
37 // |ConstrainedWindowMac::ParentWillDo()| should run its default handler. The
38 // default implementation just returns |false|.
39 virtual bool ParentWillDo(ConstrainedWindow::Event event) { return false; }
40
34 // Called by the tab controller, you do not need to do anything yourself 41 // Called by the tab controller, you do not need to do anything yourself
35 // with this method. 42 // with this method.
36 virtual void RunSheet(GTMWindowSheetController* sheetController, 43 virtual void RunSheet(GTMWindowSheetController* sheetController,
37 NSView* view) = 0; 44 NSView* view,
45 SEL frameSelector,
46 SEL positionSelector) = 0;
47
38 protected: 48 protected:
39 // Returns true if this delegate's sheet is currently showing. 49 // Returns true if this delegate's sheet is currently showing.
40 bool is_sheet_open() { return is_sheet_open_; } 50 bool is_sheet_open() { return is_sheet_open_; }
41 51
42 private: 52 private:
43 bool is_sheet_open_; 53 bool is_sheet_open_;
44 void set_sheet_open(bool is_open) { is_sheet_open_ = is_open; } 54 void set_sheet_open(bool is_open) { is_sheet_open_ = is_open; }
45 friend class ConstrainedWindowMac; 55 friend class ConstrainedWindowMac;
46 }; 56 };
47 57
48 // Subclass this for a dialog delegate that displays a system sheet such as 58 // Subclass this for a dialog delegate that displays a system sheet such as
49 // an NSAlert, an open or save file panel, etc. 59 // an NSSavePanel, NSOpenPanel, etc. This can handle any system sheet that GTM
50 class ConstrainedWindowMacDelegateSystemSheet 60 // supports (if in a somewhat ugly way).
61 class ConstrainedWindowMacDelegateSystemSheetParams
51 : public ConstrainedWindowMacDelegate { 62 : public ConstrainedWindowMacDelegate {
52 public: 63 public:
53 ConstrainedWindowMacDelegateSystemSheet(id delegate, SEL didEndSelector) 64 // See third_party/GTM/AppKit/GTMWindowSheetController.h for the format of
65 // |params|.
66 explicit ConstrainedWindowMacDelegateSystemSheetParams(NSArray* params)
54 : systemSheet_(nil), 67 : systemSheet_(nil),
55 delegate_([delegate retain]), 68 params_([params retain]) { }
56 didEndSelector_(didEndSelector) { }
57 69
58 protected: 70 protected:
59 void set_sheet(id sheet) { systemSheet_.reset([sheet retain]); } 71 void set_sheet(id sheet) { systemSheet_.reset([sheet retain]); }
60 id sheet() { return systemSheet_; } 72 id sheet() { return systemSheet_; }
73 void set_params(NSArray* params) { params_.reset([params retain]); }
74 NSArray* params() { return static_cast<NSArray*>(params_); }
75 virtual void RunSheet(GTMWindowSheetController* sheetController,
76 NSView* view,
77 SEL frameSelector,
78 SEL positionSelector);
79
80 private:
81 scoped_nsobject<id> systemSheet_;
82 scoped_nsobject<id> params_;
83 };
84
85 // Subclass this for a dialog delegate that displays a system sheet such as
86 // an NSAlert or other simple panel.
87 class ConstrainedWindowMacDelegateSystemSheet
88 : public ConstrainedWindowMacDelegateSystemSheetParams {
89 public:
90 ConstrainedWindowMacDelegateSystemSheet(id delegate, SEL didEndSelector)
91 : ConstrainedWindowMacDelegateSystemSheetParams(nil),
92 delegate_([delegate retain]),
93 didEndSelector_(didEndSelector) { }
61 94
62 private: 95 private:
63 virtual void RunSheet(GTMWindowSheetController* sheetController, 96 virtual void RunSheet(GTMWindowSheetController* sheetController,
64 NSView* view); 97 NSView* view,
65 scoped_nsobject<id> systemSheet_; 98 SEL frameSelector,
99 SEL positionSelector);
66 scoped_nsobject<id> delegate_; 100 scoped_nsobject<id> delegate_;
67 SEL didEndSelector_; 101 SEL didEndSelector_;
68 }; 102 };
69 103
70 // Subclass this for a dialog delegate that displays a custom sheet, e.g. loaded 104 // Subclass this for a dialog delegate that displays a custom sheet, e.g. loaded
71 // from a nib file. 105 // from a nib file.
72 class ConstrainedWindowMacDelegateCustomSheet 106 class ConstrainedWindowMacDelegateCustomSheet
73 : public ConstrainedWindowMacDelegate { 107 : public ConstrainedWindowMacDelegate {
74 public: 108 public:
75 ConstrainedWindowMacDelegateCustomSheet() 109 ConstrainedWindowMacDelegateCustomSheet()
(...skipping 15 matching lines...) Expand all
91 delegate_.reset([delegate retain]); 125 delegate_.reset([delegate retain]);
92 didEndSelector_ = didEndSelector; 126 didEndSelector_ = didEndSelector;
93 DCHECK(delegate_.get()); 127 DCHECK(delegate_.get());
94 DCHECK(didEndSelector_); 128 DCHECK(didEndSelector_);
95 } 129 }
96 void set_sheet(NSWindow* sheet) { customSheet_.reset([sheet retain]); } 130 void set_sheet(NSWindow* sheet) { customSheet_.reset([sheet retain]); }
97 NSWindow* sheet() { return customSheet_; } 131 NSWindow* sheet() { return customSheet_; }
98 132
99 private: 133 private:
100 virtual void RunSheet(GTMWindowSheetController* sheetController, 134 virtual void RunSheet(GTMWindowSheetController* sheetController,
101 NSView* view); 135 NSView* view,
136 SEL frameSelector,
137 SEL positionSelector);
102 scoped_nsobject<NSWindow> customSheet_; 138 scoped_nsobject<NSWindow> customSheet_;
103 scoped_nsobject<id> delegate_; 139 scoped_nsobject<id> delegate_;
104 SEL didEndSelector_; 140 SEL didEndSelector_;
105 }; 141 };
106 142
107 // Constrained window implementation for the Mac port. A constrained window 143 // Constrained window implementation for the Mac port. A constrained window
108 // is a per-tab sheet on OS X. 144 // is a per-tab sheet on OS X.
109 // 145 //
110 // Constrained windows work slightly differently on OS X than on the other 146 // Constrained windows work slightly differently on OS X than on the other
111 // platforms: 147 // platforms:
112 // 1. A constrained window is bound to both a tab and window on OS X. 148 // 1. A constrained window is bound to both a tab and window on OS X.
113 // 2. The delegate is responsible for closing the sheet again when it is 149 // 2. The delegate is responsible for closing the sheet again when it is
114 // deleted. 150 // deleted.
115 class ConstrainedWindowMac : public ConstrainedWindow { 151 class ConstrainedWindowMac : public ConstrainedWindow {
116 public: 152 public:
117 virtual ~ConstrainedWindowMac(); 153 virtual ~ConstrainedWindowMac();
118 154
119 // Overridden from ConstrainedWindow: 155 // Overridden from ConstrainedWindow:
120 virtual void CloseConstrainedWindow(); 156 virtual void CloseConstrainedWindow();
157 virtual bool ParentWillDo(ConstrainedWindow::Event event);
121 158
122 // Returns the TabContents that constrains this Constrained Window. 159 // Returns the TabContents that constrains this Constrained Window.
123 TabContents* owner() const { return owner_; } 160 TabContents* owner() const { return owner_; }
124 161
125 // Returns the window's delegate. 162 // Returns the window's delegate.
126 ConstrainedWindowMacDelegate* delegate() { return delegate_; } 163 ConstrainedWindowMacDelegate* delegate() { return delegate_; }
127 164
128 // Tells |controller_| that the sheet would like to be displayed. 165 // Tells |controller_| that the sheet would like to be displayed.
129 void Realize(BrowserWindowController* controller); 166 void Realize(BrowserWindowController* controller);
130 167
(...skipping 12 matching lines...) Expand all
143 // Delegate that provides the contents of this constrained window. 180 // Delegate that provides the contents of this constrained window.
144 ConstrainedWindowMacDelegate* delegate_; 181 ConstrainedWindowMacDelegate* delegate_;
145 182
146 // Controller of the window that contains this sheet. 183 // Controller of the window that contains this sheet.
147 BrowserWindowController* controller_; 184 BrowserWindowController* controller_;
148 185
149 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowMac); 186 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowMac);
150 }; 187 };
151 188
152 #endif // CHROME_BROWSER_COCOA_CONSTRAINED_WINDOW_MAC_H_ 189 #endif // CHROME_BROWSER_COCOA_CONSTRAINED_WINDOW_MAC_H_
153
OLDNEW
« no previous file with comments | « chrome/browser/browser.cc ('k') | chrome/browser/cocoa/constrained_window_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698