widget/cocoa/nsCocoaWindow.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsCocoaWindow_h_
michael@0 7 #define nsCocoaWindow_h_
michael@0 8
michael@0 9 #undef DARWIN
michael@0 10
michael@0 11 #import <Cocoa/Cocoa.h>
michael@0 12
michael@0 13 #include "nsBaseWidget.h"
michael@0 14 #include "nsPIWidgetCocoa.h"
michael@0 15 #include "nsAutoPtr.h"
michael@0 16 #include "nsCocoaUtils.h"
michael@0 17
michael@0 18 class nsCocoaWindow;
michael@0 19 class nsChildView;
michael@0 20 class nsMenuBarX;
michael@0 21 @class ChildView;
michael@0 22
michael@0 23 // Value copied from BITMAP_MAX_AREA, used in nsNativeThemeCocoa.mm
michael@0 24 #define CUIDRAW_MAX_AREA 500000
michael@0 25
michael@0 26 // If we are using an SDK older than 10.7, define bits we need that are missing
michael@0 27 // from it.
michael@0 28 #if !defined(MAC_OS_X_VERSION_10_7) || \
michael@0 29 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
michael@0 30
michael@0 31 enum {
michael@0 32 NSWindowAnimationBehaviorDefault = 0,
michael@0 33 NSWindowAnimationBehaviorNone = 2,
michael@0 34 NSWindowAnimationBehaviorDocumentWindow = 3,
michael@0 35 NSWindowAnimationBehaviorUtilityWindow = 4,
michael@0 36 NSWindowAnimationBehaviorAlertPanel = 5,
michael@0 37 NSWindowCollectionBehaviorFullScreenPrimary = 128, // 1 << 7
michael@0 38 };
michael@0 39
michael@0 40 typedef NSInteger NSWindowAnimationBehavior;
michael@0 41
michael@0 42 @interface NSWindow (LionWindowFeatures)
michael@0 43 - (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior;
michael@0 44 - (void)toggleFullScreen:(id)sender;
michael@0 45 @end
michael@0 46
michael@0 47 #endif
michael@0 48
michael@0 49 typedef struct _nsCocoaWindowList {
michael@0 50 _nsCocoaWindowList() : prev(nullptr), window(nullptr) {}
michael@0 51 struct _nsCocoaWindowList *prev;
michael@0 52 nsCocoaWindow *window; // Weak
michael@0 53 } nsCocoaWindowList;
michael@0 54
michael@0 55 // NSWindow subclass that is the base class for all of our own window classes.
michael@0 56 // Among other things, this class handles the storage of those settings that
michael@0 57 // need to be persisted across window destruction and reconstruction, i.e. when
michael@0 58 // switching to and from fullscreen mode.
michael@0 59 // We don't save shadow, transparency mode or background color because it's not
michael@0 60 // worth the hassle - Gecko will reset them anyway as soon as the window is
michael@0 61 // resized.
michael@0 62 @interface BaseWindow : NSWindow
michael@0 63 {
michael@0 64 // Data Storage
michael@0 65 NSMutableDictionary* mState;
michael@0 66 BOOL mDrawsIntoWindowFrame;
michael@0 67 NSColor* mActiveTitlebarColor;
michael@0 68 NSColor* mInactiveTitlebarColor;
michael@0 69
michael@0 70 // Shadow
michael@0 71 BOOL mScheduledShadowInvalidation;
michael@0 72
michael@0 73 // Invalidation disabling
michael@0 74 BOOL mDisabledNeedsDisplay;
michael@0 75
michael@0 76 // DPI cache. Getting the physical screen size (CGDisplayScreenSize)
michael@0 77 // is ridiculously slow, so we cache it in the toplevel window for all
michael@0 78 // descendants to use.
michael@0 79 float mDPI;
michael@0 80
michael@0 81 NSTrackingArea* mTrackingArea;
michael@0 82
michael@0 83 BOOL mBeingShown;
michael@0 84 BOOL mDrawTitle;
michael@0 85 }
michael@0 86
michael@0 87 - (void)importState:(NSDictionary*)aState;
michael@0 88 - (NSMutableDictionary*)exportState;
michael@0 89 - (void)setDrawsContentsIntoWindowFrame:(BOOL)aState;
michael@0 90 - (BOOL)drawsContentsIntoWindowFrame;
michael@0 91 - (void)setTitlebarColor:(NSColor*)aColor forActiveWindow:(BOOL)aActive;
michael@0 92 - (NSColor*)titlebarColorForActiveWindow:(BOOL)aActive;
michael@0 93
michael@0 94 - (void)deferredInvalidateShadow;
michael@0 95 - (void)invalidateShadow;
michael@0 96 - (float)getDPI;
michael@0 97
michael@0 98 - (void)mouseEntered:(NSEvent*)aEvent;
michael@0 99 - (void)mouseExited:(NSEvent*)aEvent;
michael@0 100 - (void)mouseMoved:(NSEvent*)aEvent;
michael@0 101 - (void)updateTrackingArea;
michael@0 102 - (NSView*)trackingAreaView;
michael@0 103
michael@0 104 - (void)setBeingShown:(BOOL)aValue;
michael@0 105 - (BOOL)isBeingShown;
michael@0 106 - (BOOL)isVisibleOrBeingShown;
michael@0 107
michael@0 108 - (ChildView*)mainChildView;
michael@0 109
michael@0 110 - (NSArray*)titlebarControls;
michael@0 111
michael@0 112 - (void)setWantsTitleDrawn:(BOOL)aDrawTitle;
michael@0 113 - (BOOL)wantsTitleDrawn;
michael@0 114
michael@0 115 - (void)disableSetNeedsDisplay;
michael@0 116 - (void)enableSetNeedsDisplay;
michael@0 117
michael@0 118 @end
michael@0 119
michael@0 120 @interface NSWindow (Undocumented)
michael@0 121
michael@0 122 // If a window has been explicitly removed from the "window cache" (to
michael@0 123 // deactivate it), it's sometimes necessary to "reset" it to reactivate it
michael@0 124 // (and put it back in the "window cache"). One way to do this, which Apple
michael@0 125 // often uses, is to set the "window number" to '-1' and then back to its
michael@0 126 // original value.
michael@0 127 - (void)_setWindowNumber:(NSInteger)aNumber;
michael@0 128
michael@0 129 // If we set the window's stylemask to be textured, the corners on the bottom of
michael@0 130 // the window are rounded by default. We use this private method to make
michael@0 131 // the corners square again, a la Safari. Starting with 10.7, all windows have
michael@0 132 // rounded bottom corners, so this call doesn't have any effect there.
michael@0 133 - (void)setBottomCornerRounded:(BOOL)rounded;
michael@0 134 - (BOOL)bottomCornerRounded;
michael@0 135
michael@0 136 // Present in the same form on OS X since at least OS X 10.5.
michael@0 137 - (NSRect)contentRectForFrameRect:(NSRect)windowFrame styleMask:(NSUInteger)windowStyle;
michael@0 138 - (NSRect)frameRectForContentRect:(NSRect)windowContentRect styleMask:(NSUInteger)windowStyle;
michael@0 139
michael@0 140 // Present since at least OS X 10.5. The OS calls this method on NSWindow
michael@0 141 // (and its subclasses) to find out which NSFrameView subclass to instantiate
michael@0 142 // to create its "frame view".
michael@0 143 + (Class)frameViewClassForStyleMask:(NSUInteger)styleMask;
michael@0 144
michael@0 145 @end
michael@0 146
michael@0 147 @interface PopupWindow : BaseWindow
michael@0 148 {
michael@0 149 @private
michael@0 150 BOOL mIsContextMenu;
michael@0 151 }
michael@0 152
michael@0 153 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask
michael@0 154 backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation;
michael@0 155 - (BOOL)isContextMenu;
michael@0 156 - (void)setIsContextMenu:(BOOL)flag;
michael@0 157 - (BOOL)canBecomeMainWindow;
michael@0 158
michael@0 159 @end
michael@0 160
michael@0 161 @interface BorderlessWindow : BaseWindow
michael@0 162 {
michael@0 163 }
michael@0 164
michael@0 165 - (BOOL)canBecomeKeyWindow;
michael@0 166 - (BOOL)canBecomeMainWindow;
michael@0 167
michael@0 168 @end
michael@0 169
michael@0 170 #if defined( MAC_OS_X_VERSION_10_6 ) && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 )
michael@0 171 @interface WindowDelegate : NSObject <NSWindowDelegate>
michael@0 172 #else
michael@0 173 @interface WindowDelegate : NSObject
michael@0 174 #endif
michael@0 175 {
michael@0 176 nsCocoaWindow* mGeckoWindow; // [WEAK] (we are owned by the window)
michael@0 177 // Used to avoid duplication when we send NS_ACTIVATE and
michael@0 178 // NS_DEACTIVATE to Gecko for toplevel widgets. Starts out
michael@0 179 // false.
michael@0 180 bool mToplevelActiveState;
michael@0 181 BOOL mHasEverBeenZoomed;
michael@0 182 }
michael@0 183 + (void)paintMenubarForWindow:(NSWindow*)aWindow;
michael@0 184 - (id)initWithGeckoWindow:(nsCocoaWindow*)geckoWind;
michael@0 185 - (void)windowDidResize:(NSNotification*)aNotification;
michael@0 186 - (nsCocoaWindow*)geckoWidget;
michael@0 187 - (bool)toplevelActiveState;
michael@0 188 - (void)sendToplevelActivateEvents;
michael@0 189 - (void)sendToplevelDeactivateEvents;
michael@0 190 @end
michael@0 191
michael@0 192 @class ToolbarWindow;
michael@0 193
michael@0 194 // NSColor subclass that allows us to draw separate colors both in the titlebar
michael@0 195 // and for background of the window.
michael@0 196 @interface TitlebarAndBackgroundColor : NSColor
michael@0 197 {
michael@0 198 ToolbarWindow *mWindow; // [WEAK] (we are owned by the window)
michael@0 199 }
michael@0 200
michael@0 201 - (id)initWithWindow:(ToolbarWindow*)aWindow;
michael@0 202
michael@0 203 @end
michael@0 204
michael@0 205 // NSWindow subclass for handling windows with toolbars.
michael@0 206 @interface ToolbarWindow : BaseWindow
michael@0 207 {
michael@0 208 TitlebarAndBackgroundColor *mColor;
michael@0 209 CGFloat mUnifiedToolbarHeight;
michael@0 210 NSColor *mBackgroundColor;
michael@0 211 NSView *mTitlebarView; // strong
michael@0 212 NSRect mWindowButtonsRect;
michael@0 213 NSRect mFullScreenButtonRect;
michael@0 214 }
michael@0 215 // Pass nil here to get the default appearance.
michael@0 216 - (void)setTitlebarColor:(NSColor*)aColor forActiveWindow:(BOOL)aActive;
michael@0 217 - (void)setUnifiedToolbarHeight:(CGFloat)aHeight;
michael@0 218 - (CGFloat)unifiedToolbarHeight;
michael@0 219 - (CGFloat)titlebarHeight;
michael@0 220 - (NSRect)titlebarRect;
michael@0 221 - (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect sync:(BOOL)aSync;
michael@0 222 - (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect;
michael@0 223 - (void)setDrawsContentsIntoWindowFrame:(BOOL)aState;
michael@0 224 - (void)placeWindowButtons:(NSRect)aRect;
michael@0 225 - (void)placeFullScreenButton:(NSRect)aRect;
michael@0 226 - (NSPoint)windowButtonsPositionWithDefaultPosition:(NSPoint)aDefaultPosition;
michael@0 227 - (NSPoint)fullScreenButtonPositionWithDefaultPosition:(NSPoint)aDefaultPosition;
michael@0 228 @end
michael@0 229
michael@0 230 class nsCocoaWindow : public nsBaseWidget, public nsPIWidgetCocoa
michael@0 231 {
michael@0 232 private:
michael@0 233
michael@0 234 typedef nsBaseWidget Inherited;
michael@0 235
michael@0 236 public:
michael@0 237
michael@0 238 nsCocoaWindow();
michael@0 239 virtual ~nsCocoaWindow();
michael@0 240
michael@0 241 NS_DECL_ISUPPORTS_INHERITED
michael@0 242 NS_DECL_NSPIWIDGETCOCOA
michael@0 243
michael@0 244 NS_IMETHOD Create(nsIWidget* aParent,
michael@0 245 nsNativeWidget aNativeParent,
michael@0 246 const nsIntRect &aRect,
michael@0 247 nsDeviceContext *aContext,
michael@0 248 nsWidgetInitData *aInitData = nullptr);
michael@0 249
michael@0 250 NS_IMETHOD Destroy();
michael@0 251
michael@0 252 NS_IMETHOD Show(bool aState);
michael@0 253 virtual nsIWidget* GetSheetWindowParent(void);
michael@0 254 NS_IMETHOD Enable(bool aState);
michael@0 255 virtual bool IsEnabled() const;
michael@0 256 NS_IMETHOD SetModal(bool aState);
michael@0 257 virtual bool IsVisible() const;
michael@0 258 NS_IMETHOD SetFocus(bool aState=false);
michael@0 259 virtual nsIntPoint WidgetToScreenOffset();
michael@0 260 virtual nsIntPoint GetClientOffset();
michael@0 261 virtual nsIntSize ClientToWindowSize(const nsIntSize& aClientSize);
michael@0 262
michael@0 263 virtual void* GetNativeData(uint32_t aDataType) ;
michael@0 264
michael@0 265 NS_IMETHOD ConstrainPosition(bool aAllowSlop,
michael@0 266 int32_t *aX, int32_t *aY);
michael@0 267 virtual void SetSizeConstraints(const SizeConstraints& aConstraints);
michael@0 268 NS_IMETHOD Move(double aX, double aY);
michael@0 269 NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
michael@0 270 nsIWidget *aWidget, bool aActivate);
michael@0 271 NS_IMETHOD SetSizeMode(int32_t aMode);
michael@0 272 NS_IMETHOD HideWindowChrome(bool aShouldHide);
michael@0 273 void EnteredFullScreen(bool aFullScreen);
michael@0 274 NS_IMETHOD MakeFullScreen(bool aFullScreen);
michael@0 275 NS_IMETHOD Resize(double aWidth, double aHeight, bool aRepaint);
michael@0 276 NS_IMETHOD Resize(double aX, double aY, double aWidth, double aHeight, bool aRepaint);
michael@0 277 NS_IMETHOD GetClientBounds(nsIntRect &aRect);
michael@0 278 NS_IMETHOD GetScreenBounds(nsIntRect &aRect);
michael@0 279 void ReportMoveEvent();
michael@0 280 void ReportSizeEvent();
michael@0 281 NS_IMETHOD SetCursor(nsCursor aCursor);
michael@0 282 NS_IMETHOD SetCursor(imgIContainer* aCursor, uint32_t aHotspotX, uint32_t aHotspotY);
michael@0 283
michael@0 284 CGFloat BackingScaleFactor();
michael@0 285 void BackingScaleFactorChanged();
michael@0 286 virtual double GetDefaultScaleInternal();
michael@0 287 virtual int32_t RoundsWidgetCoordinatesTo() MOZ_OVERRIDE;
michael@0 288
michael@0 289 NS_IMETHOD SetTitle(const nsAString& aTitle);
michael@0 290
michael@0 291 NS_IMETHOD Invalidate(const nsIntRect &aRect);
michael@0 292 virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations);
michael@0 293 virtual LayerManager* GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr,
michael@0 294 LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE,
michael@0 295 LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT,
michael@0 296 bool* aAllowRetaining = nullptr);
michael@0 297 NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent,
michael@0 298 nsEventStatus& aStatus);
michael@0 299 NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, bool aDoCapture);
michael@0 300 NS_IMETHOD GetAttention(int32_t aCycleCount);
michael@0 301 virtual bool HasPendingInputEvent();
michael@0 302 virtual nsTransparencyMode GetTransparencyMode();
michael@0 303 virtual void SetTransparencyMode(nsTransparencyMode aMode);
michael@0 304 NS_IMETHOD SetWindowShadowStyle(int32_t aStyle);
michael@0 305 virtual void SetShowsToolbarButton(bool aShow);
michael@0 306 virtual void SetShowsFullScreenButton(bool aShow);
michael@0 307 virtual void SetWindowAnimationType(WindowAnimationType aType);
michael@0 308 virtual void SetDrawsTitle(bool aDrawTitle);
michael@0 309 NS_IMETHOD SetNonClientMargins(nsIntMargin &margins);
michael@0 310 NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, bool aActive);
michael@0 311 virtual void SetDrawsInTitlebar(bool aState);
michael@0 312 virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint,
michael@0 313 uint32_t aNativeMessage,
michael@0 314 uint32_t aModifierFlags);
michael@0 315
michael@0 316 void DispatchSizeModeEvent();
michael@0 317
michael@0 318 virtual gfxASurface* GetThebesSurface();
michael@0 319
michael@0 320 // be notified that a some form of drag event needs to go into Gecko
michael@0 321 virtual bool DragEvent(unsigned int aMessage, Point aMouseGlobal, UInt16 aKeyModifiers);
michael@0 322
michael@0 323 bool HasModalDescendents() { return mNumModalDescendents > 0; }
michael@0 324 NSWindow *GetCocoaWindow() { return mWindow; }
michael@0 325
michael@0 326 void SetMenuBar(nsMenuBarX* aMenuBar);
michael@0 327 nsMenuBarX *GetMenuBar();
michael@0 328
michael@0 329 NS_IMETHOD NotifyIME(const IMENotification& aIMENotification) MOZ_OVERRIDE;
michael@0 330 NS_IMETHOD_(void) SetInputContext(
michael@0 331 const InputContext& aContext,
michael@0 332 const InputContextAction& aAction) MOZ_OVERRIDE;
michael@0 333 NS_IMETHOD_(InputContext) GetInputContext()
michael@0 334 {
michael@0 335 NSView* view = mWindow ? [mWindow contentView] : nil;
michael@0 336 if (view) {
michael@0 337 mInputContext.mNativeIMEContext = [view inputContext];
michael@0 338 }
michael@0 339 // If inputContext isn't available on this window, returns this window's
michael@0 340 // pointer since nullptr means the platform has only one context per
michael@0 341 // process.
michael@0 342 if (!mInputContext.mNativeIMEContext) {
michael@0 343 mInputContext.mNativeIMEContext = this;
michael@0 344 }
michael@0 345 return mInputContext;
michael@0 346 }
michael@0 347 NS_IMETHOD_(bool) ExecuteNativeKeyBinding(
michael@0 348 NativeKeyBindingsType aType,
michael@0 349 const mozilla::WidgetKeyboardEvent& aEvent,
michael@0 350 DoCommandCallback aCallback,
michael@0 351 void* aCallbackData) MOZ_OVERRIDE;
michael@0 352
michael@0 353 void SetPopupWindowLevel();
michael@0 354
michael@0 355 NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent);
michael@0 356 protected:
michael@0 357
michael@0 358 nsresult CreateNativeWindow(const NSRect &aRect,
michael@0 359 nsBorderStyle aBorderStyle,
michael@0 360 bool aRectIsFrameRect);
michael@0 361 nsresult CreatePopupContentView(const nsIntRect &aRect,
michael@0 362 nsDeviceContext *aContext);
michael@0 363 void DestroyNativeWindow();
michael@0 364 void AdjustWindowShadow();
michael@0 365 void SetWindowBackgroundBlur();
michael@0 366 void UpdateBounds();
michael@0 367
michael@0 368 nsresult DoResize(double aX, double aY, double aWidth, double aHeight,
michael@0 369 bool aRepaint, bool aConstrainToCurrentScreen);
michael@0 370
michael@0 371 virtual already_AddRefed<nsIWidget>
michael@0 372 AllocateChildPopupWidget()
michael@0 373 {
michael@0 374 static NS_DEFINE_IID(kCPopUpCID, NS_POPUP_CID);
michael@0 375 nsCOMPtr<nsIWidget> widget = do_CreateInstance(kCPopUpCID);
michael@0 376 return widget.forget();
michael@0 377 }
michael@0 378
michael@0 379 nsIWidget* mParent; // if we're a popup, this is our parent [WEAK]
michael@0 380 BaseWindow* mWindow; // our cocoa window [STRONG]
michael@0 381 WindowDelegate* mDelegate; // our delegate for processing window msgs [STRONG]
michael@0 382 nsRefPtr<nsMenuBarX> mMenuBar;
michael@0 383 NSWindow* mSheetWindowParent; // if this is a sheet, this is the NSWindow it's attached to
michael@0 384 nsChildView* mPopupContentView; // if this is a popup, this is its content widget
michael@0 385 int32_t mShadowStyle;
michael@0 386
michael@0 387 CGFloat mBackingScaleFactor;
michael@0 388
michael@0 389 WindowAnimationType mAnimationType;
michael@0 390
michael@0 391 bool mWindowMadeHere; // true if we created the window, false for embedding
michael@0 392 bool mSheetNeedsShow; // if this is a sheet, are we waiting to be shown?
michael@0 393 // this is used for sibling sheet contention only
michael@0 394 bool mFullScreen;
michael@0 395 bool mInFullScreenTransition; // true from the request to enter/exit fullscreen
michael@0 396 // (MakeFullScreen() call) to EnteredFullScreen()
michael@0 397 bool mModal;
michael@0 398
michael@0 399 bool mUsesNativeFullScreen; // only true on Lion if SetShowsFullScreenButton(true);
michael@0 400
michael@0 401 bool mIsAnimationSuppressed;
michael@0 402
michael@0 403 bool mInReportMoveEvent; // true if in a call to ReportMoveEvent().
michael@0 404 bool mInResize; // true if in a call to DoResize().
michael@0 405
michael@0 406 int32_t mNumModalDescendents;
michael@0 407 InputContext mInputContext;
michael@0 408 };
michael@0 409
michael@0 410 #endif // nsCocoaWindow_h_

mercurial