1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/cocoa/nsCocoaWindow.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,410 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsCocoaWindow_h_ 1.10 +#define nsCocoaWindow_h_ 1.11 + 1.12 +#undef DARWIN 1.13 + 1.14 +#import <Cocoa/Cocoa.h> 1.15 + 1.16 +#include "nsBaseWidget.h" 1.17 +#include "nsPIWidgetCocoa.h" 1.18 +#include "nsAutoPtr.h" 1.19 +#include "nsCocoaUtils.h" 1.20 + 1.21 +class nsCocoaWindow; 1.22 +class nsChildView; 1.23 +class nsMenuBarX; 1.24 +@class ChildView; 1.25 + 1.26 +// Value copied from BITMAP_MAX_AREA, used in nsNativeThemeCocoa.mm 1.27 +#define CUIDRAW_MAX_AREA 500000 1.28 + 1.29 +// If we are using an SDK older than 10.7, define bits we need that are missing 1.30 +// from it. 1.31 +#if !defined(MAC_OS_X_VERSION_10_7) || \ 1.32 + MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 1.33 + 1.34 +enum { 1.35 + NSWindowAnimationBehaviorDefault = 0, 1.36 + NSWindowAnimationBehaviorNone = 2, 1.37 + NSWindowAnimationBehaviorDocumentWindow = 3, 1.38 + NSWindowAnimationBehaviorUtilityWindow = 4, 1.39 + NSWindowAnimationBehaviorAlertPanel = 5, 1.40 + NSWindowCollectionBehaviorFullScreenPrimary = 128, // 1 << 7 1.41 +}; 1.42 + 1.43 +typedef NSInteger NSWindowAnimationBehavior; 1.44 + 1.45 +@interface NSWindow (LionWindowFeatures) 1.46 +- (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior; 1.47 +- (void)toggleFullScreen:(id)sender; 1.48 +@end 1.49 + 1.50 +#endif 1.51 + 1.52 +typedef struct _nsCocoaWindowList { 1.53 + _nsCocoaWindowList() : prev(nullptr), window(nullptr) {} 1.54 + struct _nsCocoaWindowList *prev; 1.55 + nsCocoaWindow *window; // Weak 1.56 +} nsCocoaWindowList; 1.57 + 1.58 +// NSWindow subclass that is the base class for all of our own window classes. 1.59 +// Among other things, this class handles the storage of those settings that 1.60 +// need to be persisted across window destruction and reconstruction, i.e. when 1.61 +// switching to and from fullscreen mode. 1.62 +// We don't save shadow, transparency mode or background color because it's not 1.63 +// worth the hassle - Gecko will reset them anyway as soon as the window is 1.64 +// resized. 1.65 +@interface BaseWindow : NSWindow 1.66 +{ 1.67 + // Data Storage 1.68 + NSMutableDictionary* mState; 1.69 + BOOL mDrawsIntoWindowFrame; 1.70 + NSColor* mActiveTitlebarColor; 1.71 + NSColor* mInactiveTitlebarColor; 1.72 + 1.73 + // Shadow 1.74 + BOOL mScheduledShadowInvalidation; 1.75 + 1.76 + // Invalidation disabling 1.77 + BOOL mDisabledNeedsDisplay; 1.78 + 1.79 + // DPI cache. Getting the physical screen size (CGDisplayScreenSize) 1.80 + // is ridiculously slow, so we cache it in the toplevel window for all 1.81 + // descendants to use. 1.82 + float mDPI; 1.83 + 1.84 + NSTrackingArea* mTrackingArea; 1.85 + 1.86 + BOOL mBeingShown; 1.87 + BOOL mDrawTitle; 1.88 +} 1.89 + 1.90 +- (void)importState:(NSDictionary*)aState; 1.91 +- (NSMutableDictionary*)exportState; 1.92 +- (void)setDrawsContentsIntoWindowFrame:(BOOL)aState; 1.93 +- (BOOL)drawsContentsIntoWindowFrame; 1.94 +- (void)setTitlebarColor:(NSColor*)aColor forActiveWindow:(BOOL)aActive; 1.95 +- (NSColor*)titlebarColorForActiveWindow:(BOOL)aActive; 1.96 + 1.97 +- (void)deferredInvalidateShadow; 1.98 +- (void)invalidateShadow; 1.99 +- (float)getDPI; 1.100 + 1.101 +- (void)mouseEntered:(NSEvent*)aEvent; 1.102 +- (void)mouseExited:(NSEvent*)aEvent; 1.103 +- (void)mouseMoved:(NSEvent*)aEvent; 1.104 +- (void)updateTrackingArea; 1.105 +- (NSView*)trackingAreaView; 1.106 + 1.107 +- (void)setBeingShown:(BOOL)aValue; 1.108 +- (BOOL)isBeingShown; 1.109 +- (BOOL)isVisibleOrBeingShown; 1.110 + 1.111 +- (ChildView*)mainChildView; 1.112 + 1.113 +- (NSArray*)titlebarControls; 1.114 + 1.115 +- (void)setWantsTitleDrawn:(BOOL)aDrawTitle; 1.116 +- (BOOL)wantsTitleDrawn; 1.117 + 1.118 +- (void)disableSetNeedsDisplay; 1.119 +- (void)enableSetNeedsDisplay; 1.120 + 1.121 +@end 1.122 + 1.123 +@interface NSWindow (Undocumented) 1.124 + 1.125 +// If a window has been explicitly removed from the "window cache" (to 1.126 +// deactivate it), it's sometimes necessary to "reset" it to reactivate it 1.127 +// (and put it back in the "window cache"). One way to do this, which Apple 1.128 +// often uses, is to set the "window number" to '-1' and then back to its 1.129 +// original value. 1.130 +- (void)_setWindowNumber:(NSInteger)aNumber; 1.131 + 1.132 +// If we set the window's stylemask to be textured, the corners on the bottom of 1.133 +// the window are rounded by default. We use this private method to make 1.134 +// the corners square again, a la Safari. Starting with 10.7, all windows have 1.135 +// rounded bottom corners, so this call doesn't have any effect there. 1.136 +- (void)setBottomCornerRounded:(BOOL)rounded; 1.137 +- (BOOL)bottomCornerRounded; 1.138 + 1.139 +// Present in the same form on OS X since at least OS X 10.5. 1.140 +- (NSRect)contentRectForFrameRect:(NSRect)windowFrame styleMask:(NSUInteger)windowStyle; 1.141 +- (NSRect)frameRectForContentRect:(NSRect)windowContentRect styleMask:(NSUInteger)windowStyle; 1.142 + 1.143 +// Present since at least OS X 10.5. The OS calls this method on NSWindow 1.144 +// (and its subclasses) to find out which NSFrameView subclass to instantiate 1.145 +// to create its "frame view". 1.146 ++ (Class)frameViewClassForStyleMask:(NSUInteger)styleMask; 1.147 + 1.148 +@end 1.149 + 1.150 +@interface PopupWindow : BaseWindow 1.151 +{ 1.152 +@private 1.153 + BOOL mIsContextMenu; 1.154 +} 1.155 + 1.156 +- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask 1.157 + backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation; 1.158 +- (BOOL)isContextMenu; 1.159 +- (void)setIsContextMenu:(BOOL)flag; 1.160 +- (BOOL)canBecomeMainWindow; 1.161 + 1.162 +@end 1.163 + 1.164 +@interface BorderlessWindow : BaseWindow 1.165 +{ 1.166 +} 1.167 + 1.168 +- (BOOL)canBecomeKeyWindow; 1.169 +- (BOOL)canBecomeMainWindow; 1.170 + 1.171 +@end 1.172 + 1.173 +#if defined( MAC_OS_X_VERSION_10_6 ) && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 ) 1.174 +@interface WindowDelegate : NSObject <NSWindowDelegate> 1.175 +#else 1.176 +@interface WindowDelegate : NSObject 1.177 +#endif 1.178 +{ 1.179 + nsCocoaWindow* mGeckoWindow; // [WEAK] (we are owned by the window) 1.180 + // Used to avoid duplication when we send NS_ACTIVATE and 1.181 + // NS_DEACTIVATE to Gecko for toplevel widgets. Starts out 1.182 + // false. 1.183 + bool mToplevelActiveState; 1.184 + BOOL mHasEverBeenZoomed; 1.185 +} 1.186 ++ (void)paintMenubarForWindow:(NSWindow*)aWindow; 1.187 +- (id)initWithGeckoWindow:(nsCocoaWindow*)geckoWind; 1.188 +- (void)windowDidResize:(NSNotification*)aNotification; 1.189 +- (nsCocoaWindow*)geckoWidget; 1.190 +- (bool)toplevelActiveState; 1.191 +- (void)sendToplevelActivateEvents; 1.192 +- (void)sendToplevelDeactivateEvents; 1.193 +@end 1.194 + 1.195 +@class ToolbarWindow; 1.196 + 1.197 +// NSColor subclass that allows us to draw separate colors both in the titlebar 1.198 +// and for background of the window. 1.199 +@interface TitlebarAndBackgroundColor : NSColor 1.200 +{ 1.201 + ToolbarWindow *mWindow; // [WEAK] (we are owned by the window) 1.202 +} 1.203 + 1.204 +- (id)initWithWindow:(ToolbarWindow*)aWindow; 1.205 + 1.206 +@end 1.207 + 1.208 +// NSWindow subclass for handling windows with toolbars. 1.209 +@interface ToolbarWindow : BaseWindow 1.210 +{ 1.211 + TitlebarAndBackgroundColor *mColor; 1.212 + CGFloat mUnifiedToolbarHeight; 1.213 + NSColor *mBackgroundColor; 1.214 + NSView *mTitlebarView; // strong 1.215 + NSRect mWindowButtonsRect; 1.216 + NSRect mFullScreenButtonRect; 1.217 +} 1.218 +// Pass nil here to get the default appearance. 1.219 +- (void)setTitlebarColor:(NSColor*)aColor forActiveWindow:(BOOL)aActive; 1.220 +- (void)setUnifiedToolbarHeight:(CGFloat)aHeight; 1.221 +- (CGFloat)unifiedToolbarHeight; 1.222 +- (CGFloat)titlebarHeight; 1.223 +- (NSRect)titlebarRect; 1.224 +- (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect sync:(BOOL)aSync; 1.225 +- (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect; 1.226 +- (void)setDrawsContentsIntoWindowFrame:(BOOL)aState; 1.227 +- (void)placeWindowButtons:(NSRect)aRect; 1.228 +- (void)placeFullScreenButton:(NSRect)aRect; 1.229 +- (NSPoint)windowButtonsPositionWithDefaultPosition:(NSPoint)aDefaultPosition; 1.230 +- (NSPoint)fullScreenButtonPositionWithDefaultPosition:(NSPoint)aDefaultPosition; 1.231 +@end 1.232 + 1.233 +class nsCocoaWindow : public nsBaseWidget, public nsPIWidgetCocoa 1.234 +{ 1.235 +private: 1.236 + 1.237 + typedef nsBaseWidget Inherited; 1.238 + 1.239 +public: 1.240 + 1.241 + nsCocoaWindow(); 1.242 + virtual ~nsCocoaWindow(); 1.243 + 1.244 + NS_DECL_ISUPPORTS_INHERITED 1.245 + NS_DECL_NSPIWIDGETCOCOA 1.246 + 1.247 + NS_IMETHOD Create(nsIWidget* aParent, 1.248 + nsNativeWidget aNativeParent, 1.249 + const nsIntRect &aRect, 1.250 + nsDeviceContext *aContext, 1.251 + nsWidgetInitData *aInitData = nullptr); 1.252 + 1.253 + NS_IMETHOD Destroy(); 1.254 + 1.255 + NS_IMETHOD Show(bool aState); 1.256 + virtual nsIWidget* GetSheetWindowParent(void); 1.257 + NS_IMETHOD Enable(bool aState); 1.258 + virtual bool IsEnabled() const; 1.259 + NS_IMETHOD SetModal(bool aState); 1.260 + virtual bool IsVisible() const; 1.261 + NS_IMETHOD SetFocus(bool aState=false); 1.262 + virtual nsIntPoint WidgetToScreenOffset(); 1.263 + virtual nsIntPoint GetClientOffset(); 1.264 + virtual nsIntSize ClientToWindowSize(const nsIntSize& aClientSize); 1.265 + 1.266 + virtual void* GetNativeData(uint32_t aDataType) ; 1.267 + 1.268 + NS_IMETHOD ConstrainPosition(bool aAllowSlop, 1.269 + int32_t *aX, int32_t *aY); 1.270 + virtual void SetSizeConstraints(const SizeConstraints& aConstraints); 1.271 + NS_IMETHOD Move(double aX, double aY); 1.272 + NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, 1.273 + nsIWidget *aWidget, bool aActivate); 1.274 + NS_IMETHOD SetSizeMode(int32_t aMode); 1.275 + NS_IMETHOD HideWindowChrome(bool aShouldHide); 1.276 + void EnteredFullScreen(bool aFullScreen); 1.277 + NS_IMETHOD MakeFullScreen(bool aFullScreen); 1.278 + NS_IMETHOD Resize(double aWidth, double aHeight, bool aRepaint); 1.279 + NS_IMETHOD Resize(double aX, double aY, double aWidth, double aHeight, bool aRepaint); 1.280 + NS_IMETHOD GetClientBounds(nsIntRect &aRect); 1.281 + NS_IMETHOD GetScreenBounds(nsIntRect &aRect); 1.282 + void ReportMoveEvent(); 1.283 + void ReportSizeEvent(); 1.284 + NS_IMETHOD SetCursor(nsCursor aCursor); 1.285 + NS_IMETHOD SetCursor(imgIContainer* aCursor, uint32_t aHotspotX, uint32_t aHotspotY); 1.286 + 1.287 + CGFloat BackingScaleFactor(); 1.288 + void BackingScaleFactorChanged(); 1.289 + virtual double GetDefaultScaleInternal(); 1.290 + virtual int32_t RoundsWidgetCoordinatesTo() MOZ_OVERRIDE; 1.291 + 1.292 + NS_IMETHOD SetTitle(const nsAString& aTitle); 1.293 + 1.294 + NS_IMETHOD Invalidate(const nsIntRect &aRect); 1.295 + virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations); 1.296 + virtual LayerManager* GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr, 1.297 + LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE, 1.298 + LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT, 1.299 + bool* aAllowRetaining = nullptr); 1.300 + NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent, 1.301 + nsEventStatus& aStatus); 1.302 + NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, bool aDoCapture); 1.303 + NS_IMETHOD GetAttention(int32_t aCycleCount); 1.304 + virtual bool HasPendingInputEvent(); 1.305 + virtual nsTransparencyMode GetTransparencyMode(); 1.306 + virtual void SetTransparencyMode(nsTransparencyMode aMode); 1.307 + NS_IMETHOD SetWindowShadowStyle(int32_t aStyle); 1.308 + virtual void SetShowsToolbarButton(bool aShow); 1.309 + virtual void SetShowsFullScreenButton(bool aShow); 1.310 + virtual void SetWindowAnimationType(WindowAnimationType aType); 1.311 + virtual void SetDrawsTitle(bool aDrawTitle); 1.312 + NS_IMETHOD SetNonClientMargins(nsIntMargin &margins); 1.313 + NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, bool aActive); 1.314 + virtual void SetDrawsInTitlebar(bool aState); 1.315 + virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint, 1.316 + uint32_t aNativeMessage, 1.317 + uint32_t aModifierFlags); 1.318 + 1.319 + void DispatchSizeModeEvent(); 1.320 + 1.321 + virtual gfxASurface* GetThebesSurface(); 1.322 + 1.323 + // be notified that a some form of drag event needs to go into Gecko 1.324 + virtual bool DragEvent(unsigned int aMessage, Point aMouseGlobal, UInt16 aKeyModifiers); 1.325 + 1.326 + bool HasModalDescendents() { return mNumModalDescendents > 0; } 1.327 + NSWindow *GetCocoaWindow() { return mWindow; } 1.328 + 1.329 + void SetMenuBar(nsMenuBarX* aMenuBar); 1.330 + nsMenuBarX *GetMenuBar(); 1.331 + 1.332 + NS_IMETHOD NotifyIME(const IMENotification& aIMENotification) MOZ_OVERRIDE; 1.333 + NS_IMETHOD_(void) SetInputContext( 1.334 + const InputContext& aContext, 1.335 + const InputContextAction& aAction) MOZ_OVERRIDE; 1.336 + NS_IMETHOD_(InputContext) GetInputContext() 1.337 + { 1.338 + NSView* view = mWindow ? [mWindow contentView] : nil; 1.339 + if (view) { 1.340 + mInputContext.mNativeIMEContext = [view inputContext]; 1.341 + } 1.342 + // If inputContext isn't available on this window, returns this window's 1.343 + // pointer since nullptr means the platform has only one context per 1.344 + // process. 1.345 + if (!mInputContext.mNativeIMEContext) { 1.346 + mInputContext.mNativeIMEContext = this; 1.347 + } 1.348 + return mInputContext; 1.349 + } 1.350 + NS_IMETHOD_(bool) ExecuteNativeKeyBinding( 1.351 + NativeKeyBindingsType aType, 1.352 + const mozilla::WidgetKeyboardEvent& aEvent, 1.353 + DoCommandCallback aCallback, 1.354 + void* aCallbackData) MOZ_OVERRIDE; 1.355 + 1.356 + void SetPopupWindowLevel(); 1.357 + 1.358 + NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent); 1.359 +protected: 1.360 + 1.361 + nsresult CreateNativeWindow(const NSRect &aRect, 1.362 + nsBorderStyle aBorderStyle, 1.363 + bool aRectIsFrameRect); 1.364 + nsresult CreatePopupContentView(const nsIntRect &aRect, 1.365 + nsDeviceContext *aContext); 1.366 + void DestroyNativeWindow(); 1.367 + void AdjustWindowShadow(); 1.368 + void SetWindowBackgroundBlur(); 1.369 + void UpdateBounds(); 1.370 + 1.371 + nsresult DoResize(double aX, double aY, double aWidth, double aHeight, 1.372 + bool aRepaint, bool aConstrainToCurrentScreen); 1.373 + 1.374 + virtual already_AddRefed<nsIWidget> 1.375 + AllocateChildPopupWidget() 1.376 + { 1.377 + static NS_DEFINE_IID(kCPopUpCID, NS_POPUP_CID); 1.378 + nsCOMPtr<nsIWidget> widget = do_CreateInstance(kCPopUpCID); 1.379 + return widget.forget(); 1.380 + } 1.381 + 1.382 + nsIWidget* mParent; // if we're a popup, this is our parent [WEAK] 1.383 + BaseWindow* mWindow; // our cocoa window [STRONG] 1.384 + WindowDelegate* mDelegate; // our delegate for processing window msgs [STRONG] 1.385 + nsRefPtr<nsMenuBarX> mMenuBar; 1.386 + NSWindow* mSheetWindowParent; // if this is a sheet, this is the NSWindow it's attached to 1.387 + nsChildView* mPopupContentView; // if this is a popup, this is its content widget 1.388 + int32_t mShadowStyle; 1.389 + 1.390 + CGFloat mBackingScaleFactor; 1.391 + 1.392 + WindowAnimationType mAnimationType; 1.393 + 1.394 + bool mWindowMadeHere; // true if we created the window, false for embedding 1.395 + bool mSheetNeedsShow; // if this is a sheet, are we waiting to be shown? 1.396 + // this is used for sibling sheet contention only 1.397 + bool mFullScreen; 1.398 + bool mInFullScreenTransition; // true from the request to enter/exit fullscreen 1.399 + // (MakeFullScreen() call) to EnteredFullScreen() 1.400 + bool mModal; 1.401 + 1.402 + bool mUsesNativeFullScreen; // only true on Lion if SetShowsFullScreenButton(true); 1.403 + 1.404 + bool mIsAnimationSuppressed; 1.405 + 1.406 + bool mInReportMoveEvent; // true if in a call to ReportMoveEvent(). 1.407 + bool mInResize; // true if in a call to DoResize(). 1.408 + 1.409 + int32_t mNumModalDescendents; 1.410 + InputContext mInputContext; 1.411 +}; 1.412 + 1.413 +#endif // nsCocoaWindow_h_