CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / widget / src / cocoa / nsCocoaWindow.h
blob875c62e5557af335f2317c1545355845b84e80fc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Josh Aas <josh@mozilla.com>
24 * Colin Barrett <cbarrett@mozilla.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef nsCocoaWindow_h_
41 #define nsCocoaWindow_h_
43 #undef DARWIN
45 #import <Cocoa/Cocoa.h>
47 #include "nsBaseWidget.h"
48 #include "nsPIWidgetCocoa.h"
49 #include "nsAutoPtr.h"
50 #include "nsCocoaUtils.h"
52 class nsCocoaWindow;
53 class nsChildView;
54 class nsMenuBarX;
56 typedef struct _nsCocoaWindowList {
57 _nsCocoaWindowList() : prev(NULL), window(NULL) {}
58 struct _nsCocoaWindowList *prev;
59 nsCocoaWindow *window; // Weak
60 } nsCocoaWindowList;
62 // NSWindow subclass that is the base class for all of our own window classes.
63 // Among other things, this class handles the storage of those settings that
64 // need to be persisted across window destruction and reconstruction, i.e. when
65 // switching to and from fullscreen mode.
66 // We don't save shadow, transparency mode or background color because it's not
67 // worth the hassle - Gecko will reset them anyway as soon as the window is
68 // resized.
69 @interface BaseWindow : NSWindow
71 // Data Storage
72 NSMutableDictionary* mState;
73 BOOL mDrawsIntoWindowFrame;
74 NSColor* mActiveTitlebarColor;
75 NSColor* mInactiveTitlebarColor;
77 // Shadow
78 BOOL mScheduledShadowInvalidation;
80 // DPI cache. Getting the physical screen size (CGDisplayScreenSize)
81 // is ridiculously slow, so we cache it in the toplevel window for all
82 // descendants to use.
83 float mDPI;
86 - (void)importState:(NSDictionary*)aState;
87 - (NSMutableDictionary*)exportState;
88 - (void)setDrawsContentsIntoWindowFrame:(BOOL)aState;
89 - (BOOL)drawsContentsIntoWindowFrame;
90 - (void)setTitlebarColor:(NSColor*)aColor forActiveWindow:(BOOL)aActive;
91 - (NSColor*)titlebarColorForActiveWindow:(BOOL)aActive;
93 - (void)deferredInvalidateShadow;
94 - (void)invalidateShadow;
95 - (float)getDPI;
97 @end
99 @interface NSWindow (Undocumented)
101 // If a window has been explicitly removed from the "window cache" (to
102 // deactivate it), it's sometimes necessary to "reset" it to reactivate it
103 // (and put it back in the "window cache"). One way to do this, which Apple
104 // often uses, is to set the "window number" to '-1' and then back to its
105 // original value.
106 - (void)_setWindowNumber:(NSInteger)aNumber;
108 // If we set the window's stylemask to be textured, the corners on the bottom of
109 // the window are rounded by default. We use this private method to make
110 // the corners square again, a la Safari.
111 - (void)setBottomCornerRounded:(BOOL)rounded;
113 @end
115 @interface PopupWindow : BaseWindow
117 @private
118 BOOL mIsContextMenu;
121 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask
122 backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation;
123 - (BOOL)isContextMenu;
124 - (void)setIsContextMenu:(BOOL)flag;
125 - (BOOL)canBecomeMainWindow;
127 @end
129 @interface BorderlessWindow : BaseWindow
133 - (BOOL)canBecomeKeyWindow;
134 - (BOOL)canBecomeMainWindow;
136 @end
138 #if defined( MAC_OS_X_VERSION_10_6 ) && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 )
139 @interface WindowDelegate : NSObject <NSWindowDelegate>
140 #else
141 @interface WindowDelegate : NSObject
142 #endif
144 nsCocoaWindow* mGeckoWindow; // [WEAK] (we are owned by the window)
145 // Used to avoid duplication when we send NS_ACTIVATE and
146 // NS_DEACTIVATE to Gecko for toplevel widgets. Starts out
147 // PR_FALSE.
148 PRBool mToplevelActiveState;
149 BOOL mHasEverBeenZoomed;
151 + (void)paintMenubarForWindow:(NSWindow*)aWindow;
152 - (id)initWithGeckoWindow:(nsCocoaWindow*)geckoWind;
153 - (void)windowDidResize:(NSNotification*)aNotification;
154 - (void)sendFocusEvent:(PRUint32)eventType;
155 - (nsCocoaWindow*)geckoWidget;
156 - (PRBool)toplevelActiveState;
157 - (void)sendToplevelActivateEvents;
158 - (void)sendToplevelDeactivateEvents;
159 @end
161 struct UnifiedGradientInfo {
162 float titlebarHeight;
163 float toolbarHeight;
164 BOOL windowIsMain;
165 BOOL drawTitlebar; // NO for toolbar, YES for titlebar
168 @class ToolbarWindow;
170 // NSColor subclass that allows us to draw separate colors both in the titlebar
171 // and for background of the window.
172 @interface TitlebarAndBackgroundColor : NSColor
174 ToolbarWindow *mWindow; // [WEAK] (we are owned by the window)
177 - (id)initWithWindow:(ToolbarWindow*)aWindow;
179 @end
181 // NSWindow subclass for handling windows with toolbars.
182 @interface ToolbarWindow : BaseWindow
184 TitlebarAndBackgroundColor *mColor;
185 float mUnifiedToolbarHeight;
186 NSColor *mBackgroundColor;
188 // Pass nil here to get the default appearance.
189 - (void)setTitlebarColor:(NSColor*)aColor forActiveWindow:(BOOL)aActive;
190 - (void)setUnifiedToolbarHeight:(float)aHeight;
191 - (float)unifiedToolbarHeight;
192 - (float)titlebarHeight;
193 - (NSRect)titlebarRect;
194 - (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect sync:(BOOL)aSync;
195 - (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect;
196 - (void)setDrawsContentsIntoWindowFrame:(BOOL)aState;
197 @end
199 class nsCocoaWindow : public nsBaseWidget, public nsPIWidgetCocoa
201 private:
203 typedef nsBaseWidget Inherited;
205 public:
207 nsCocoaWindow();
208 virtual ~nsCocoaWindow();
210 NS_DECL_ISUPPORTS_INHERITED
211 NS_DECL_NSPIWIDGETCOCOA
213 NS_IMETHOD Create(nsIWidget* aParent,
214 nsNativeWidget aNativeParent,
215 const nsIntRect &aRect,
216 EVENT_CALLBACK aHandleEventFunction,
217 nsIDeviceContext *aContext,
218 nsIAppShell *aAppShell = nsnull,
219 nsIToolkit *aToolkit = nsnull,
220 nsWidgetInitData *aInitData = nsnull);
222 NS_IMETHOD Destroy();
224 NS_IMETHOD Show(PRBool aState);
225 virtual nsIWidget* GetSheetWindowParent(void);
226 NS_IMETHOD Enable(PRBool aState);
227 NS_IMETHOD IsEnabled(PRBool *aState);
228 NS_IMETHOD SetModal(PRBool aState);
229 NS_IMETHOD IsVisible(PRBool & aState);
230 NS_IMETHOD SetFocus(PRBool aState=PR_FALSE);
231 virtual nsIntPoint WidgetToScreenOffset();
232 virtual nsIntPoint GetClientOffset();
233 virtual nsIntSize ClientToWindowSize(const nsIntSize& aClientSize);
235 virtual void* GetNativeData(PRUint32 aDataType) ;
237 NS_IMETHOD ConstrainPosition(PRBool aAllowSlop,
238 PRInt32 *aX, PRInt32 *aY);
239 NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
240 NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
241 nsIWidget *aWidget, PRBool aActivate);
242 NS_IMETHOD SetSizeMode(PRInt32 aMode);
243 NS_IMETHOD HideWindowChrome(PRBool aShouldHide);
244 NS_IMETHOD MakeFullScreen(PRBool aFullScreen);
245 NS_IMETHOD Resize(PRInt32 aWidth,PRInt32 aHeight, PRBool aRepaint);
246 NS_IMETHOD Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint);
247 NS_IMETHOD GetClientBounds(nsIntRect &aRect);
248 NS_IMETHOD GetScreenBounds(nsIntRect &aRect);
249 void ReportMoveEvent();
250 void ReportSizeEvent();
251 NS_IMETHOD SetCursor(nsCursor aCursor);
252 NS_IMETHOD SetCursor(imgIContainer* aCursor, PRUint32 aHotspotX, PRUint32 aHotspotY);
254 NS_IMETHOD SetTitle(const nsAString& aTitle);
256 NS_IMETHOD Invalidate(const nsIntRect &aRect, PRBool aIsSynchronous);
257 NS_IMETHOD Update();
258 virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations);
259 virtual LayerManager* GetLayerManager(LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT,
260 bool* aAllowRetaining = nsnull);
261 NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus) ;
262 NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, nsIMenuRollup * aMenuRollup,
263 PRBool aDoCapture, PRBool aConsumeRollupEvent);
264 NS_IMETHOD GetAttention(PRInt32 aCycleCount);
265 virtual PRBool HasPendingInputEvent();
266 virtual nsTransparencyMode GetTransparencyMode();
267 virtual void SetTransparencyMode(nsTransparencyMode aMode);
268 NS_IMETHOD SetWindowShadowStyle(PRInt32 aStyle);
269 virtual void SetShowsToolbarButton(PRBool aShow);
270 NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, PRBool aActive);
271 virtual void SetDrawsInTitlebar(PRBool aState);
272 virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint,
273 PRUint32 aNativeMessage,
274 PRUint32 aModifierFlags);
276 void DispatchSizeModeEvent();
278 virtual gfxASurface* GetThebesSurface();
279 virtual void DrawOver(LayerManager* aManager, nsIntRect aRect);
281 // be notified that a some form of drag event needs to go into Gecko
282 virtual PRBool DragEvent(unsigned int aMessage, Point aMouseGlobal, UInt16 aKeyModifiers);
284 PRBool HasModalDescendents() { return mNumModalDescendents > 0; }
285 NSWindow *GetCocoaWindow() { return mWindow; }
287 void SetMenuBar(nsMenuBarX* aMenuBar);
288 nsMenuBarX *GetMenuBar();
290 // nsIKBStateControl interface
291 NS_IMETHOD ResetInputState();
293 NS_IMETHOD BeginSecureKeyboardInput();
294 NS_IMETHOD EndSecureKeyboardInput();
296 static void UnifiedShading(void* aInfo, const CGFloat* aIn, CGFloat* aOut);
298 void SetPopupWindowLevel();
300 PRBool IsChildInFailingLeftClickThrough(NSView *aChild);
301 PRBool ShouldFocusPlugin();
303 NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent);
304 protected:
306 nsresult CreateNativeWindow(const NSRect &aRect,
307 nsBorderStyle aBorderStyle,
308 PRBool aRectIsFrameRect);
309 nsresult CreatePopupContentView(const nsIntRect &aRect,
310 EVENT_CALLBACK aHandleEventFunction,
311 nsIDeviceContext *aContext,
312 nsIAppShell *aAppShell,
313 nsIToolkit *aToolkit);
314 void DestroyNativeWindow();
315 void AdjustWindowShadow();
316 void SetUpWindowFilter();
317 void CleanUpWindowFilter();
318 void UpdateBounds();
320 virtual already_AddRefed<nsIWidget>
321 AllocateChildPopupWidget()
323 static NS_DEFINE_IID(kCPopUpCID, NS_POPUP_CID);
324 nsCOMPtr<nsIWidget> widget = do_CreateInstance(kCPopUpCID);
325 return widget.forget();
328 nsIWidget* mParent; // if we're a popup, this is our parent [WEAK]
329 BaseWindow* mWindow; // our cocoa window [STRONG]
330 WindowDelegate* mDelegate; // our delegate for processing window msgs [STRONG]
331 nsRefPtr<nsMenuBarX> mMenuBar;
332 NSWindow* mSheetWindowParent; // if this is a sheet, this is the NSWindow it's attached to
333 nsChildView* mPopupContentView; // if this is a popup, this is its content widget
334 PRInt32 mShadowStyle;
335 NSUInteger mWindowFilter;
337 PRPackedBool mWindowMadeHere; // true if we created the window, false for embedding
338 PRPackedBool mSheetNeedsShow; // if this is a sheet, are we waiting to be shown?
339 // this is used for sibling sheet contention only
340 PRPackedBool mFullScreen;
341 PRPackedBool mModal;
343 PRInt32 mNumModalDescendents;
346 #endif // nsCocoaWindow_h_