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

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

Issue 159780: Add support for constrained windows on os x, based on Avi's GTMWindowSheetController. (Closed)
Patch Set: Merge with ToT Created 11 years, 4 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_COCOA_CONSTRAINED_WINDOW_MAC_H_
6 #define CHROME_BROWSER_COCOA_CONSTRAINED_WINDOW_MAC_H_
7
8 #import <Cocoa/Cocoa.h>
9
10 #include "chrome/browser/tab_contents/constrained_window.h"
11
12 #include "base/basictypes.h"
13 #include "base/scoped_nsobject.h"
14
15 @class BrowserWindowController;
16 @class GTMWindowSheetController;
17 @class NSView;
18 @class NSWindow;
19 class TabContents;
20
21 // Base class for constrained dialog delegates. Never inherit from this
22 // directly.
23 class ConstrainedWindowMacDelegate {
24 public:
25 ConstrainedWindowMacDelegate() : is_sheet_open_(false) { }
26 virtual ~ConstrainedWindowMacDelegate();
27
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
30 // in this method.
31 virtual void DeleteDelegate() = 0;
32
33 // Called by the tab controller, you do not need to do anything yourself
34 // with this method.
35 virtual void RunSheet(GTMWindowSheetController* sheetController,
36 NSView* view) = 0;
37 protected:
38 // Returns true if this delegate's sheet is currently showing.
39 bool is_sheet_open() { return is_sheet_open_; }
40
41 private:
42 bool is_sheet_open_;
43 void set_sheet_open(bool is_open) { is_sheet_open_ = is_open; }
44 friend class ConstrainedWindowMac;
45 };
46
47 // Subclass this for a dialog delegate that displays a system sheet such as
48 // an NSAlert, an open or save file panel, etc.
49 class ConstrainedWindowMacDelegateSystemSheet
50 : public ConstrainedWindowMacDelegate {
51 public:
52 ConstrainedWindowMacDelegateSystemSheet(id delegate, SEL didEndSelector)
53 : systemSheet_(nil),
54 delegate_([delegate retain]),
55 didEndSelector_(didEndSelector) { }
56
57 protected:
58 void set_sheet(id sheet) { systemSheet_.reset([sheet retain]); }
59 id sheet() { return systemSheet_; }
60
61 private:
62 virtual void RunSheet(GTMWindowSheetController* sheetController,
63 NSView* view);
64 scoped_nsobject<id> systemSheet_;
65 scoped_nsobject<id> delegate_;
66 SEL didEndSelector_;
67 };
68
69 // Subclass this for a dialog delegate that displays a custom sheet, e.g. loaded
70 // from a nib file.
71 class ConstrainedWindowMacDelegateCustomSheet
72 : public ConstrainedWindowMacDelegate {
73 public:
74 ConstrainedWindowMacDelegateCustomSheet(
75 NSWindow* customSheet, id delegate, SEL didEndSelector)
76 : customSheet_(nil),
77 delegate_([delegate retain]),
78 didEndSelector_(didEndSelector) { }
79
80 protected:
81 void set_sheet(NSWindow* sheet) { customSheet_.reset([sheet retain]); }
82 NSWindow* sheet() { return customSheet_; }
83
84 private:
85 virtual void RunSheet(GTMWindowSheetController* sheetController,
86 NSView* view);
87 scoped_nsobject<NSWindow> customSheet_;
88 scoped_nsobject<id> delegate_;
89 SEL didEndSelector_;
90 };
91
92 // Constrained window implementation for the Mac port. A constrained window
93 // is a per-tab sheet on OS X.
94 //
95 // Contrained wiindows work slightly differently on OS X than on the other
Avi (use Gerrit) 2009/08/11 20:27:49 wiindows
96 // platforms:
97 // 1. A constrained window is bound to both a tab and window on os x.
Avi (use Gerrit) 2009/08/11 20:27:49 OS X; match yourself five lines up.
98 // 2. The delegate is responsible for closing the sheet again when it is deleted .
Avi (use Gerrit) 2009/08/11 20:27:49 80col
99 class ConstrainedWindowMac : public ConstrainedWindow {
100 public:
101 virtual ~ConstrainedWindowMac();
102
103 // Overridden from ConstrainedWindow:
104 virtual void CloseConstrainedWindow();
105
106 // Returns the TabContents that constrains this Constrained Window.
107 TabContents* owner() const { return owner_; }
108
109 // Returns the window's delegate.
110 ConstrainedWindowMacDelegate* delegate() { return delegate_; }
111
112 // Makes the constrained window visible, if it is not yet visible.
113 void Realize(BrowserWindowController* controller);
114
115 private:
116 friend class ConstrainedWindow;
117
118 ConstrainedWindowMac(TabContents* owner,
119 ConstrainedWindowMacDelegate* delegate);
120
121 // The TabContents that owns and constrains this ConstrainedWindow.
122 TabContents* owner_;
123
124 // Delegate that provides the contents of this constrained window.
125 ConstrainedWindowMacDelegate* delegate_;
126
127 // Controller of the window that contains this sheet.
128 BrowserWindowController* controller_;
129
130 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowMac);
131 };
132
133 #endif // CHROME_BROWSER_COCOA_CONSTRAINED_WINDOW_MAC_H_
134
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