Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; 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 nsChildView_h_ |
michael@0 | 7 | #define nsChildView_h_ |
michael@0 | 8 | |
michael@0 | 9 | // formal protocols |
michael@0 | 10 | #include "mozView.h" |
michael@0 | 11 | #ifdef ACCESSIBILITY |
michael@0 | 12 | #include "mozilla/a11y/Accessible.h" |
michael@0 | 13 | #include "mozAccessibleProtocol.h" |
michael@0 | 14 | #endif |
michael@0 | 15 | |
michael@0 | 16 | #include "nsAutoPtr.h" |
michael@0 | 17 | #include "nsISupports.h" |
michael@0 | 18 | #include "nsBaseWidget.h" |
michael@0 | 19 | #include "nsIPluginInstanceOwner.h" |
michael@0 | 20 | #include "nsIPluginWidget.h" |
michael@0 | 21 | #include "nsWeakPtr.h" |
michael@0 | 22 | #include "TextInputHandler.h" |
michael@0 | 23 | #include "nsCocoaUtils.h" |
michael@0 | 24 | #include "gfxQuartzSurface.h" |
michael@0 | 25 | #include "GLContextTypes.h" |
michael@0 | 26 | #include "mozilla/Mutex.h" |
michael@0 | 27 | #include "nsRegion.h" |
michael@0 | 28 | #include "mozilla/MouseEvents.h" |
michael@0 | 29 | |
michael@0 | 30 | #include "nsString.h" |
michael@0 | 31 | #include "nsIDragService.h" |
michael@0 | 32 | |
michael@0 | 33 | #include "npapi.h" |
michael@0 | 34 | |
michael@0 | 35 | #import <Carbon/Carbon.h> |
michael@0 | 36 | #import <Cocoa/Cocoa.h> |
michael@0 | 37 | #import <AppKit/NSOpenGL.h> |
michael@0 | 38 | |
michael@0 | 39 | // The header files QuickdrawAPI.h and QDOffscreen.h are missing on OS X 10.7 |
michael@0 | 40 | // and up (though the QuickDraw APIs defined in them are still present) -- so |
michael@0 | 41 | // we need to supply the relevant parts of their contents here. It's likely |
michael@0 | 42 | // that Apple will eventually remove the APIs themselves (probably in OS X |
michael@0 | 43 | // 10.8), so we need to make them weak imports, and test for their presence |
michael@0 | 44 | // before using them. |
michael@0 | 45 | #ifdef __cplusplus |
michael@0 | 46 | extern "C" { |
michael@0 | 47 | #endif |
michael@0 | 48 | #if !defined(__QUICKDRAWAPI__) |
michael@0 | 49 | |
michael@0 | 50 | extern void SetPort(GrafPtr port) |
michael@0 | 51 | __attribute__((weak_import)); |
michael@0 | 52 | extern void SetOrigin(short h, short v) |
michael@0 | 53 | __attribute__((weak_import)); |
michael@0 | 54 | extern RgnHandle NewRgn(void) |
michael@0 | 55 | __attribute__((weak_import)); |
michael@0 | 56 | extern void DisposeRgn(RgnHandle rgn) |
michael@0 | 57 | __attribute__((weak_import)); |
michael@0 | 58 | extern void RectRgn(RgnHandle rgn, const Rect * r) |
michael@0 | 59 | __attribute__((weak_import)); |
michael@0 | 60 | extern GDHandle GetMainDevice(void) |
michael@0 | 61 | __attribute__((weak_import)); |
michael@0 | 62 | extern Boolean IsPortOffscreen(CGrafPtr port) |
michael@0 | 63 | __attribute__((weak_import)); |
michael@0 | 64 | extern void SetPortVisibleRegion(CGrafPtr port, RgnHandle visRgn) |
michael@0 | 65 | __attribute__((weak_import)); |
michael@0 | 66 | extern void SetPortClipRegion(CGrafPtr port, RgnHandle clipRgn) |
michael@0 | 67 | __attribute__((weak_import)); |
michael@0 | 68 | extern CGrafPtr GetQDGlobalsThePort(void) |
michael@0 | 69 | __attribute__((weak_import)); |
michael@0 | 70 | |
michael@0 | 71 | #endif /* __QUICKDRAWAPI__ */ |
michael@0 | 72 | |
michael@0 | 73 | #if !defined(__QDOFFSCREEN__) |
michael@0 | 74 | |
michael@0 | 75 | extern void GetGWorld(CGrafPtr * port, GDHandle * gdh) |
michael@0 | 76 | __attribute__((weak_import)); |
michael@0 | 77 | extern void SetGWorld(CGrafPtr port, GDHandle gdh) |
michael@0 | 78 | __attribute__((weak_import)); |
michael@0 | 79 | |
michael@0 | 80 | #endif /* __QDOFFSCREEN__ */ |
michael@0 | 81 | #ifdef __cplusplus |
michael@0 | 82 | } |
michael@0 | 83 | #endif |
michael@0 | 84 | |
michael@0 | 85 | class gfxASurface; |
michael@0 | 86 | class nsChildView; |
michael@0 | 87 | class nsCocoaWindow; |
michael@0 | 88 | union nsPluginPort; |
michael@0 | 89 | |
michael@0 | 90 | namespace { |
michael@0 | 91 | class GLPresenter; |
michael@0 | 92 | class RectTextureImage; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | namespace mozilla { |
michael@0 | 96 | namespace layers { |
michael@0 | 97 | class GLManager; |
michael@0 | 98 | } |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | @interface NSEvent (Undocumented) |
michael@0 | 102 | |
michael@0 | 103 | // Return Cocoa event's corresponding Carbon event. Not initialized (on |
michael@0 | 104 | // synthetic events) until the OS actually "sends" the event. This method |
michael@0 | 105 | // has been present in the same form since at least OS X 10.2.8. |
michael@0 | 106 | - (EventRef)_eventRef; |
michael@0 | 107 | |
michael@0 | 108 | @end |
michael@0 | 109 | |
michael@0 | 110 | @interface NSView (Undocumented) |
michael@0 | 111 | |
michael@0 | 112 | // Draws the title string of a window. |
michael@0 | 113 | // Present on NSThemeFrame since at least 10.6. |
michael@0 | 114 | // _drawTitleBar is somewhat complex, and has changed over the years |
michael@0 | 115 | // since OS X 10.6. But in that time it's never done anything that |
michael@0 | 116 | // would break when called outside of -[NSView drawRect:] (which we |
michael@0 | 117 | // sometimes do), or whose output can't be redirected to a |
michael@0 | 118 | // CGContextRef object (which we also sometimes do). This is likely |
michael@0 | 119 | // to remain true for the indefinite future. However we should |
michael@0 | 120 | // check _drawTitleBar in each new major version of OS X. For more |
michael@0 | 121 | // information see bug 877767. |
michael@0 | 122 | - (void)_drawTitleBar:(NSRect)aRect; |
michael@0 | 123 | |
michael@0 | 124 | // Returns an NSRect that is the bounding box for all an NSView's dirty |
michael@0 | 125 | // rectangles (ones that need to be redrawn). The full list of dirty |
michael@0 | 126 | // rectangles can be obtained by calling -[NSView _dirtyRegion] and then |
michael@0 | 127 | // calling -[NSRegion getRects:count:] on what it returns. Both these |
michael@0 | 128 | // methods have been present in the same form since at least OS X 10.5. |
michael@0 | 129 | // Unlike -[NSView getRectsBeingDrawn:count:], these methods can be called |
michael@0 | 130 | // outside a call to -[NSView drawRect:]. |
michael@0 | 131 | - (NSRect)_dirtyRect; |
michael@0 | 132 | |
michael@0 | 133 | // Undocumented method of one or more of NSFrameView's subclasses. Called |
michael@0 | 134 | // when one or more of the titlebar buttons needs to be repositioned, to |
michael@0 | 135 | // disappear, or to reappear (say if the window's style changes). If |
michael@0 | 136 | // 'redisplay' is true, the entire titlebar (the window's top 22 pixels) is |
michael@0 | 137 | // marked as needing redisplay. This method has been present in the same |
michael@0 | 138 | // format since at least OS X 10.5. |
michael@0 | 139 | - (void)_tileTitlebarAndRedisplay:(BOOL)redisplay; |
michael@0 | 140 | |
michael@0 | 141 | @end |
michael@0 | 142 | |
michael@0 | 143 | // Support for pixel scroll deltas, not part of NSEvent.h |
michael@0 | 144 | // See http://lists.apple.com/archives/cocoa-dev/2007/Feb/msg00050.html |
michael@0 | 145 | @interface NSEvent (DeviceDelta) |
michael@0 | 146 | // Leopard and SnowLeopard |
michael@0 | 147 | - (CGFloat)deviceDeltaX; |
michael@0 | 148 | - (CGFloat)deviceDeltaY; |
michael@0 | 149 | // Lion and above |
michael@0 | 150 | - (CGFloat)scrollingDeltaX; |
michael@0 | 151 | - (CGFloat)scrollingDeltaY; |
michael@0 | 152 | - (BOOL)hasPreciseScrollingDeltas; |
michael@0 | 153 | @end |
michael@0 | 154 | |
michael@0 | 155 | #if !defined(MAC_OS_X_VERSION_10_6) || \ |
michael@0 | 156 | MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 |
michael@0 | 157 | @interface NSEvent (SnowLeopardEventFeatures) |
michael@0 | 158 | + (NSUInteger)pressedMouseButtons; |
michael@0 | 159 | + (NSUInteger)modifierFlags; |
michael@0 | 160 | @end |
michael@0 | 161 | #endif |
michael@0 | 162 | |
michael@0 | 163 | // The following section, required to support fluid swipe tracking on OS X 10.7 |
michael@0 | 164 | // and up, contains defines/declarations that are only available on 10.7 and up. |
michael@0 | 165 | // [NSEvent trackSwipeEventWithOptions:...] also requires that the compiler |
michael@0 | 166 | // support "blocks" |
michael@0 | 167 | // (http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html) |
michael@0 | 168 | // -- which it does on 10.6 and up (using the 10.6 SDK or higher). |
michael@0 | 169 | // |
michael@0 | 170 | // MAC_OS_X_VERSION_MAX_ALLOWED "controls which OS functionality, if used, |
michael@0 | 171 | // will result in a compiler error because that functionality is not |
michael@0 | 172 | // available" (quoting from AvailabilityMacros.h). The compiler initializes |
michael@0 | 173 | // it to the version of the SDK being used. Its value does *not* prevent the |
michael@0 | 174 | // binary from running on higher OS versions. MAC_OS_X_VERSION_10_7 and |
michael@0 | 175 | // friends are defined (in AvailabilityMacros.h) as decimal numbers (not |
michael@0 | 176 | // hexadecimal numbers). |
michael@0 | 177 | #if !defined(MAC_OS_X_VERSION_10_7) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
michael@0 | 178 | enum { |
michael@0 | 179 | NSEventPhaseNone = 0, |
michael@0 | 180 | NSEventPhaseBegan = 0x1 << 0, |
michael@0 | 181 | NSEventPhaseStationary = 0x1 << 1, |
michael@0 | 182 | NSEventPhaseChanged = 0x1 << 2, |
michael@0 | 183 | NSEventPhaseEnded = 0x1 << 3, |
michael@0 | 184 | NSEventPhaseCancelled = 0x1 << 4, |
michael@0 | 185 | }; |
michael@0 | 186 | typedef NSUInteger NSEventPhase; |
michael@0 | 187 | |
michael@0 | 188 | enum { |
michael@0 | 189 | NSFullScreenWindowMask = 1 << 14 |
michael@0 | 190 | }; |
michael@0 | 191 | |
michael@0 | 192 | @interface NSWindow (LionWindowFeatures) |
michael@0 | 193 | - (NSRect)convertRectToScreen:(NSRect)aRect; |
michael@0 | 194 | @end |
michael@0 | 195 | |
michael@0 | 196 | #ifdef __LP64__ |
michael@0 | 197 | enum { |
michael@0 | 198 | NSEventSwipeTrackingLockDirection = 0x1 << 0, |
michael@0 | 199 | NSEventSwipeTrackingClampGestureAmount = 0x1 << 1 |
michael@0 | 200 | }; |
michael@0 | 201 | typedef NSUInteger NSEventSwipeTrackingOptions; |
michael@0 | 202 | |
michael@0 | 203 | enum { |
michael@0 | 204 | NSEventGestureAxisNone = 0, |
michael@0 | 205 | NSEventGestureAxisHorizontal, |
michael@0 | 206 | NSEventGestureAxisVertical |
michael@0 | 207 | }; |
michael@0 | 208 | typedef NSInteger NSEventGestureAxis; |
michael@0 | 209 | |
michael@0 | 210 | @interface NSEvent (FluidSwipeTracking) |
michael@0 | 211 | + (BOOL)isSwipeTrackingFromScrollEventsEnabled; |
michael@0 | 212 | - (BOOL)hasPreciseScrollingDeltas; |
michael@0 | 213 | - (CGFloat)scrollingDeltaX; |
michael@0 | 214 | - (CGFloat)scrollingDeltaY; |
michael@0 | 215 | - (NSEventPhase)phase; |
michael@0 | 216 | - (void)trackSwipeEventWithOptions:(NSEventSwipeTrackingOptions)options |
michael@0 | 217 | dampenAmountThresholdMin:(CGFloat)minDampenThreshold |
michael@0 | 218 | max:(CGFloat)maxDampenThreshold |
michael@0 | 219 | usingHandler:(void (^)(CGFloat gestureAmount, NSEventPhase phase, BOOL isComplete, BOOL *stop))trackingHandler; |
michael@0 | 220 | @end |
michael@0 | 221 | #endif // #ifdef __LP64__ |
michael@0 | 222 | #endif // #if !defined(MAC_OS_X_VERSION_10_7) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
michael@0 | 223 | |
michael@0 | 224 | #if !defined(MAC_OS_X_VERSION_10_8) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_8 |
michael@0 | 225 | enum { |
michael@0 | 226 | NSEventPhaseMayBegin = 0x1 << 5 |
michael@0 | 227 | }; |
michael@0 | 228 | #endif // #if !defined(MAC_OS_X_VERSION_10_8) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_8 |
michael@0 | 229 | |
michael@0 | 230 | // Undocumented scrollPhase flag that lets us discern between real scrolls and |
michael@0 | 231 | // automatically firing momentum scroll events. |
michael@0 | 232 | @interface NSEvent (ScrollPhase) |
michael@0 | 233 | // Leopard and SnowLeopard |
michael@0 | 234 | - (long long)_scrollPhase; |
michael@0 | 235 | // Lion and above |
michael@0 | 236 | - (NSEventPhase)momentumPhase; |
michael@0 | 237 | @end |
michael@0 | 238 | |
michael@0 | 239 | @interface ChildView : NSView< |
michael@0 | 240 | #ifdef ACCESSIBILITY |
michael@0 | 241 | mozAccessible, |
michael@0 | 242 | #endif |
michael@0 | 243 | mozView, NSTextInput, NSTextInputClient> |
michael@0 | 244 | { |
michael@0 | 245 | @private |
michael@0 | 246 | // the nsChildView that created the view. It retains this NSView, so |
michael@0 | 247 | // the link back to it must be weak. |
michael@0 | 248 | nsChildView* mGeckoChild; |
michael@0 | 249 | |
michael@0 | 250 | // Text input handler for mGeckoChild and us. Note that this is a weak |
michael@0 | 251 | // reference. Ideally, this should be a strong reference but a ChildView |
michael@0 | 252 | // object can live longer than the mGeckoChild that owns it. And if |
michael@0 | 253 | // mTextInputHandler were a strong reference, this would make it difficult |
michael@0 | 254 | // for Gecko's leak detector to detect leaked TextInputHandler objects. |
michael@0 | 255 | // This is initialized by [mozView installTextInputHandler:aHandler] and |
michael@0 | 256 | // cleared by [mozView uninstallTextInputHandler]. |
michael@0 | 257 | mozilla::widget::TextInputHandler* mTextInputHandler; // [WEAK] |
michael@0 | 258 | |
michael@0 | 259 | BOOL mIsPluginView; |
michael@0 | 260 | NPEventModel mPluginEventModel; |
michael@0 | 261 | NPDrawingModel mPluginDrawingModel; |
michael@0 | 262 | |
michael@0 | 263 | // when mouseDown: is called, we store its event here (strong) |
michael@0 | 264 | NSEvent* mLastMouseDownEvent; |
michael@0 | 265 | |
michael@0 | 266 | // Whether the last mouse down event was blocked from Gecko. |
michael@0 | 267 | BOOL mBlockedLastMouseDown; |
michael@0 | 268 | |
michael@0 | 269 | // when acceptsFirstMouse: is called, we store the event here (strong) |
michael@0 | 270 | NSEvent* mClickThroughMouseDownEvent; |
michael@0 | 271 | |
michael@0 | 272 | // rects that were invalidated during a draw, so have pending drawing |
michael@0 | 273 | NSMutableArray* mPendingDirtyRects; |
michael@0 | 274 | BOOL mPendingFullDisplay; |
michael@0 | 275 | BOOL mPendingDisplay; |
michael@0 | 276 | |
michael@0 | 277 | // WheelStart/Stop events should always come in pairs. This BOOL records the |
michael@0 | 278 | // last received event so that, when we receive one of the events, we make sure |
michael@0 | 279 | // to send its pair event first, in case we didn't yet for any reason. |
michael@0 | 280 | BOOL mExpectingWheelStop; |
michael@0 | 281 | |
michael@0 | 282 | // Holds our drag service across multiple drag calls. The reference to the |
michael@0 | 283 | // service is obtained when the mouse enters the view and is released when |
michael@0 | 284 | // the mouse exits or there is a drop. This prevents us from having to |
michael@0 | 285 | // re-establish the connection to the service manager many times per second |
michael@0 | 286 | // when handling |draggingUpdated:| messages. |
michael@0 | 287 | nsIDragService* mDragService; |
michael@0 | 288 | |
michael@0 | 289 | NSOpenGLContext *mGLContext; |
michael@0 | 290 | |
michael@0 | 291 | // Simple gestures support |
michael@0 | 292 | // |
michael@0 | 293 | // mGestureState is used to detect when Cocoa has called both |
michael@0 | 294 | // magnifyWithEvent and rotateWithEvent within the same |
michael@0 | 295 | // beginGestureWithEvent and endGestureWithEvent sequence. We |
michael@0 | 296 | // discard the spurious gesture event so as not to confuse Gecko. |
michael@0 | 297 | // |
michael@0 | 298 | // mCumulativeMagnification keeps track of the total amount of |
michael@0 | 299 | // magnification peformed during a magnify gesture so that we can |
michael@0 | 300 | // send that value with the final MozMagnifyGesture event. |
michael@0 | 301 | // |
michael@0 | 302 | // mCumulativeRotation keeps track of the total amount of rotation |
michael@0 | 303 | // performed during a rotate gesture so we can send that value with |
michael@0 | 304 | // the final MozRotateGesture event. |
michael@0 | 305 | enum { |
michael@0 | 306 | eGestureState_None, |
michael@0 | 307 | eGestureState_StartGesture, |
michael@0 | 308 | eGestureState_MagnifyGesture, |
michael@0 | 309 | eGestureState_RotateGesture |
michael@0 | 310 | } mGestureState; |
michael@0 | 311 | float mCumulativeMagnification; |
michael@0 | 312 | float mCumulativeRotation; |
michael@0 | 313 | |
michael@0 | 314 | BOOL mDidForceRefreshOpenGL; |
michael@0 | 315 | BOOL mWaitingForPaint; |
michael@0 | 316 | |
michael@0 | 317 | #ifdef __LP64__ |
michael@0 | 318 | // Support for fluid swipe tracking. |
michael@0 | 319 | BOOL* mCancelSwipeAnimation; |
michael@0 | 320 | uint32_t mCurrentSwipeDir; |
michael@0 | 321 | #endif |
michael@0 | 322 | |
michael@0 | 323 | // Whether this uses off-main-thread compositing. |
michael@0 | 324 | BOOL mUsingOMTCompositor; |
michael@0 | 325 | |
michael@0 | 326 | // The mask image that's used when painting into the titlebar using basic |
michael@0 | 327 | // CGContext painting (i.e. non-accelerated). |
michael@0 | 328 | CGImageRef mTopLeftCornerMask; |
michael@0 | 329 | } |
michael@0 | 330 | |
michael@0 | 331 | // class initialization |
michael@0 | 332 | + (void)initialize; |
michael@0 | 333 | |
michael@0 | 334 | + (void)registerViewForDraggedTypes:(NSView*)aView; |
michael@0 | 335 | |
michael@0 | 336 | // these are sent to the first responder when the window key status changes |
michael@0 | 337 | - (void)viewsWindowDidBecomeKey; |
michael@0 | 338 | - (void)viewsWindowDidResignKey; |
michael@0 | 339 | |
michael@0 | 340 | // Stop NSView hierarchy being changed during [ChildView drawRect:] |
michael@0 | 341 | - (void)delayedTearDown; |
michael@0 | 342 | |
michael@0 | 343 | - (void)sendFocusEvent:(uint32_t)eventType; |
michael@0 | 344 | |
michael@0 | 345 | - (void)handleMouseMoved:(NSEvent*)aEvent; |
michael@0 | 346 | |
michael@0 | 347 | - (void)updateWindowDraggableStateOnMouseMove:(NSEvent*)theEvent; |
michael@0 | 348 | |
michael@0 | 349 | - (void)sendMouseEnterOrExitEvent:(NSEvent*)aEvent |
michael@0 | 350 | enter:(BOOL)aEnter |
michael@0 | 351 | type:(mozilla::WidgetMouseEvent::exitType)aType; |
michael@0 | 352 | |
michael@0 | 353 | - (void)updateGLContext; |
michael@0 | 354 | - (void)_surfaceNeedsUpdate:(NSNotification*)notification; |
michael@0 | 355 | |
michael@0 | 356 | - (BOOL)isPluginView; |
michael@0 | 357 | |
michael@0 | 358 | // Are we processing an NSLeftMouseDown event that will fail to click through? |
michael@0 | 359 | // If so, we shouldn't focus or unfocus a plugin. |
michael@0 | 360 | - (BOOL)isInFailingLeftClickThrough; |
michael@0 | 361 | |
michael@0 | 362 | - (void)setGLContext:(NSOpenGLContext *)aGLContext; |
michael@0 | 363 | - (bool)preRender:(NSOpenGLContext *)aGLContext; |
michael@0 | 364 | - (void)postRender:(NSOpenGLContext *)aGLContext; |
michael@0 | 365 | |
michael@0 | 366 | - (BOOL)isCoveringTitlebar; |
michael@0 | 367 | |
michael@0 | 368 | // Simple gestures support |
michael@0 | 369 | // |
michael@0 | 370 | // XXX - The swipeWithEvent, beginGestureWithEvent, magnifyWithEvent, |
michael@0 | 371 | // rotateWithEvent, and endGestureWithEvent methods are part of a |
michael@0 | 372 | // PRIVATE interface exported by nsResponder and reverse-engineering |
michael@0 | 373 | // was necessary to obtain the methods' prototypes. Thus, Apple may |
michael@0 | 374 | // change the interface in the future without notice. |
michael@0 | 375 | // |
michael@0 | 376 | // The prototypes were obtained from the following link: |
michael@0 | 377 | // http://cocoadex.com/2008/02/nsevent-modifications-swipe-ro.html |
michael@0 | 378 | - (void)swipeWithEvent:(NSEvent *)anEvent; |
michael@0 | 379 | - (void)beginGestureWithEvent:(NSEvent *)anEvent; |
michael@0 | 380 | - (void)magnifyWithEvent:(NSEvent *)anEvent; |
michael@0 | 381 | - (void)smartMagnifyWithEvent:(NSEvent *)anEvent; |
michael@0 | 382 | - (void)rotateWithEvent:(NSEvent *)anEvent; |
michael@0 | 383 | - (void)endGestureWithEvent:(NSEvent *)anEvent; |
michael@0 | 384 | |
michael@0 | 385 | - (void)scrollWheel:(NSEvent *)anEvent; |
michael@0 | 386 | |
michael@0 | 387 | // Helper function for Lion smart magnify events |
michael@0 | 388 | + (BOOL)isLionSmartMagnifyEvent:(NSEvent*)anEvent; |
michael@0 | 389 | |
michael@0 | 390 | // Support for fluid swipe tracking. |
michael@0 | 391 | #ifdef __LP64__ |
michael@0 | 392 | - (void)maybeTrackScrollEventAsSwipe:(NSEvent *)anEvent |
michael@0 | 393 | scrollOverflowX:(double)anOverflowX |
michael@0 | 394 | scrollOverflowY:(double)anOverflowY |
michael@0 | 395 | viewPortIsOverscrolled:(BOOL)aViewPortIsOverscrolled; |
michael@0 | 396 | #endif |
michael@0 | 397 | |
michael@0 | 398 | - (void)setUsingOMTCompositor:(BOOL)aUseOMTC; |
michael@0 | 399 | @end |
michael@0 | 400 | |
michael@0 | 401 | class ChildViewMouseTracker { |
michael@0 | 402 | |
michael@0 | 403 | public: |
michael@0 | 404 | |
michael@0 | 405 | static void MouseMoved(NSEvent* aEvent); |
michael@0 | 406 | static void MouseScrolled(NSEvent* aEvent); |
michael@0 | 407 | static void OnDestroyView(ChildView* aView); |
michael@0 | 408 | static void OnDestroyWindow(NSWindow* aWindow); |
michael@0 | 409 | static BOOL WindowAcceptsEvent(NSWindow* aWindow, NSEvent* aEvent, |
michael@0 | 410 | ChildView* aView, BOOL isClickThrough = NO); |
michael@0 | 411 | static void MouseExitedWindow(NSEvent* aEvent); |
michael@0 | 412 | static void MouseEnteredWindow(NSEvent* aEvent); |
michael@0 | 413 | static void ReEvaluateMouseEnterState(NSEvent* aEvent = nil, ChildView* aOldView = nil); |
michael@0 | 414 | static void ResendLastMouseMoveEvent(); |
michael@0 | 415 | static ChildView* ViewForEvent(NSEvent* aEvent); |
michael@0 | 416 | static void AttachPluginEvent(mozilla::WidgetMouseEventBase& aMouseEvent, |
michael@0 | 417 | ChildView* aView, |
michael@0 | 418 | NSEvent* aNativeMouseEvent, |
michael@0 | 419 | int aPluginEventType, |
michael@0 | 420 | void* aPluginEventHolder); |
michael@0 | 421 | |
michael@0 | 422 | static ChildView* sLastMouseEventView; |
michael@0 | 423 | static NSEvent* sLastMouseMoveEvent; |
michael@0 | 424 | static NSWindow* sWindowUnderMouse; |
michael@0 | 425 | static NSPoint sLastScrollEventScreenLocation; |
michael@0 | 426 | }; |
michael@0 | 427 | |
michael@0 | 428 | //------------------------------------------------------------------------- |
michael@0 | 429 | // |
michael@0 | 430 | // nsChildView |
michael@0 | 431 | // |
michael@0 | 432 | //------------------------------------------------------------------------- |
michael@0 | 433 | |
michael@0 | 434 | class nsChildView : public nsBaseWidget, |
michael@0 | 435 | public nsIPluginWidget |
michael@0 | 436 | { |
michael@0 | 437 | private: |
michael@0 | 438 | typedef nsBaseWidget Inherited; |
michael@0 | 439 | |
michael@0 | 440 | public: |
michael@0 | 441 | nsChildView(); |
michael@0 | 442 | virtual ~nsChildView(); |
michael@0 | 443 | |
michael@0 | 444 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 445 | |
michael@0 | 446 | // nsIWidget interface |
michael@0 | 447 | NS_IMETHOD Create(nsIWidget *aParent, |
michael@0 | 448 | nsNativeWidget aNativeParent, |
michael@0 | 449 | const nsIntRect &aRect, |
michael@0 | 450 | nsDeviceContext *aContext, |
michael@0 | 451 | nsWidgetInitData *aInitData = nullptr); |
michael@0 | 452 | |
michael@0 | 453 | NS_IMETHOD Destroy(); |
michael@0 | 454 | |
michael@0 | 455 | NS_IMETHOD Show(bool aState); |
michael@0 | 456 | virtual bool IsVisible() const; |
michael@0 | 457 | |
michael@0 | 458 | NS_IMETHOD SetParent(nsIWidget* aNewParent); |
michael@0 | 459 | virtual nsIWidget* GetParent(void); |
michael@0 | 460 | virtual float GetDPI(); |
michael@0 | 461 | |
michael@0 | 462 | NS_IMETHOD ConstrainPosition(bool aAllowSlop, |
michael@0 | 463 | int32_t *aX, int32_t *aY); |
michael@0 | 464 | NS_IMETHOD Move(double aX, double aY); |
michael@0 | 465 | NS_IMETHOD Resize(double aWidth, double aHeight, bool aRepaint); |
michael@0 | 466 | NS_IMETHOD Resize(double aX, double aY, |
michael@0 | 467 | double aWidth, double aHeight, bool aRepaint); |
michael@0 | 468 | |
michael@0 | 469 | NS_IMETHOD Enable(bool aState); |
michael@0 | 470 | virtual bool IsEnabled() const; |
michael@0 | 471 | NS_IMETHOD SetFocus(bool aRaise); |
michael@0 | 472 | NS_IMETHOD GetBounds(nsIntRect &aRect); |
michael@0 | 473 | NS_IMETHOD GetClientBounds(nsIntRect &aRect); |
michael@0 | 474 | NS_IMETHOD GetScreenBounds(nsIntRect &aRect); |
michael@0 | 475 | |
michael@0 | 476 | // Returns the "backing scale factor" of the view's window, which is the |
michael@0 | 477 | // ratio of pixels in the window's backing store to Cocoa points. Prior to |
michael@0 | 478 | // HiDPI support in OS X 10.7, this was always 1.0, but in HiDPI mode it |
michael@0 | 479 | // will be 2.0 (and might potentially other values as screen resolutions |
michael@0 | 480 | // evolve). This gives the relationship between what Gecko calls "device |
michael@0 | 481 | // pixels" and the Cocoa "points" coordinate system. |
michael@0 | 482 | CGFloat BackingScaleFactor(); |
michael@0 | 483 | |
michael@0 | 484 | // Call if the window's backing scale factor changes - i.e., it is moved |
michael@0 | 485 | // between HiDPI and non-HiDPI screens |
michael@0 | 486 | void BackingScaleFactorChanged(); |
michael@0 | 487 | |
michael@0 | 488 | virtual double GetDefaultScaleInternal(); |
michael@0 | 489 | |
michael@0 | 490 | virtual int32_t RoundsWidgetCoordinatesTo() MOZ_OVERRIDE; |
michael@0 | 491 | |
michael@0 | 492 | NS_IMETHOD Invalidate(const nsIntRect &aRect); |
michael@0 | 493 | |
michael@0 | 494 | virtual void* GetNativeData(uint32_t aDataType); |
michael@0 | 495 | virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations); |
michael@0 | 496 | virtual nsIntPoint WidgetToScreenOffset(); |
michael@0 | 497 | virtual bool ShowsResizeIndicator(nsIntRect* aResizerRect); |
michael@0 | 498 | |
michael@0 | 499 | static bool ConvertStatus(nsEventStatus aStatus) |
michael@0 | 500 | { return aStatus == nsEventStatus_eConsumeNoDefault; } |
michael@0 | 501 | NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent, |
michael@0 | 502 | nsEventStatus& aStatus); |
michael@0 | 503 | |
michael@0 | 504 | virtual bool ComputeShouldAccelerate(bool aDefault); |
michael@0 | 505 | virtual bool ShouldUseOffMainThreadCompositing() MOZ_OVERRIDE; |
michael@0 | 506 | |
michael@0 | 507 | NS_IMETHOD SetCursor(nsCursor aCursor); |
michael@0 | 508 | NS_IMETHOD SetCursor(imgIContainer* aCursor, uint32_t aHotspotX, uint32_t aHotspotY); |
michael@0 | 509 | |
michael@0 | 510 | NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, bool aDoCapture); |
michael@0 | 511 | NS_IMETHOD SetTitle(const nsAString& title); |
michael@0 | 512 | |
michael@0 | 513 | NS_IMETHOD GetAttention(int32_t aCycleCount); |
michael@0 | 514 | |
michael@0 | 515 | virtual bool HasPendingInputEvent(); |
michael@0 | 516 | |
michael@0 | 517 | NS_IMETHOD ActivateNativeMenuItemAt(const nsAString& indexString); |
michael@0 | 518 | NS_IMETHOD ForceUpdateNativeMenuAt(const nsAString& indexString); |
michael@0 | 519 | |
michael@0 | 520 | NS_IMETHOD NotifyIME(const IMENotification& aIMENotification) MOZ_OVERRIDE; |
michael@0 | 521 | NS_IMETHOD_(void) SetInputContext(const InputContext& aContext, |
michael@0 | 522 | const InputContextAction& aAction); |
michael@0 | 523 | NS_IMETHOD_(InputContext) GetInputContext(); |
michael@0 | 524 | NS_IMETHOD AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent); |
michael@0 | 525 | NS_IMETHOD_(bool) ExecuteNativeKeyBinding( |
michael@0 | 526 | NativeKeyBindingsType aType, |
michael@0 | 527 | const mozilla::WidgetKeyboardEvent& aEvent, |
michael@0 | 528 | DoCommandCallback aCallback, |
michael@0 | 529 | void* aCallbackData) MOZ_OVERRIDE; |
michael@0 | 530 | virtual nsIMEUpdatePreference GetIMEUpdatePreference() MOZ_OVERRIDE; |
michael@0 | 531 | NS_IMETHOD GetToggledKeyState(uint32_t aKeyCode, |
michael@0 | 532 | bool* aLEDState); |
michael@0 | 533 | |
michael@0 | 534 | // nsIPluginWidget |
michael@0 | 535 | // outClipRect and outOrigin are in display pixels (not device pixels) |
michael@0 | 536 | NS_IMETHOD GetPluginClipRect(nsIntRect& outClipRect, nsIntPoint& outOrigin, bool& outWidgetVisible); |
michael@0 | 537 | NS_IMETHOD StartDrawPlugin(); |
michael@0 | 538 | NS_IMETHOD EndDrawPlugin(); |
michael@0 | 539 | NS_IMETHOD SetPluginInstanceOwner(nsIPluginInstanceOwner* aInstanceOwner); |
michael@0 | 540 | |
michael@0 | 541 | NS_IMETHOD SetPluginEventModel(int inEventModel); |
michael@0 | 542 | NS_IMETHOD GetPluginEventModel(int* outEventModel); |
michael@0 | 543 | NS_IMETHOD SetPluginDrawingModel(int inDrawingModel); |
michael@0 | 544 | |
michael@0 | 545 | NS_IMETHOD StartComplexTextInputForCurrentEvent(); |
michael@0 | 546 | |
michael@0 | 547 | virtual nsTransparencyMode GetTransparencyMode(); |
michael@0 | 548 | virtual void SetTransparencyMode(nsTransparencyMode aMode); |
michael@0 | 549 | |
michael@0 | 550 | virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout, |
michael@0 | 551 | int32_t aNativeKeyCode, |
michael@0 | 552 | uint32_t aModifierFlags, |
michael@0 | 553 | const nsAString& aCharacters, |
michael@0 | 554 | const nsAString& aUnmodifiedCharacters); |
michael@0 | 555 | |
michael@0 | 556 | virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint, |
michael@0 | 557 | uint32_t aNativeMessage, |
michael@0 | 558 | uint32_t aModifierFlags); |
michael@0 | 559 | |
michael@0 | 560 | virtual nsresult SynthesizeNativeMouseMove(nsIntPoint aPoint) |
michael@0 | 561 | { return SynthesizeNativeMouseEvent(aPoint, NSMouseMoved, 0); } |
michael@0 | 562 | |
michael@0 | 563 | // Mac specific methods |
michael@0 | 564 | |
michael@0 | 565 | virtual bool DispatchWindowEvent(mozilla::WidgetGUIEvent& event); |
michael@0 | 566 | |
michael@0 | 567 | void WillPaintWindow(); |
michael@0 | 568 | bool PaintWindow(nsIntRegion aRegion); |
michael@0 | 569 | |
michael@0 | 570 | #ifdef ACCESSIBILITY |
michael@0 | 571 | already_AddRefed<mozilla::a11y::Accessible> GetDocumentAccessible(); |
michael@0 | 572 | #endif |
michael@0 | 573 | |
michael@0 | 574 | virtual void CreateCompositor(); |
michael@0 | 575 | virtual gfxASurface* GetThebesSurface(); |
michael@0 | 576 | virtual void PrepareWindowEffects() MOZ_OVERRIDE; |
michael@0 | 577 | virtual void CleanupWindowEffects() MOZ_OVERRIDE; |
michael@0 | 578 | virtual bool PreRender(LayerManagerComposite* aManager) MOZ_OVERRIDE; |
michael@0 | 579 | virtual void PostRender(LayerManagerComposite* aManager) MOZ_OVERRIDE; |
michael@0 | 580 | virtual void DrawWindowOverlay(LayerManagerComposite* aManager, nsIntRect aRect) MOZ_OVERRIDE; |
michael@0 | 581 | |
michael@0 | 582 | virtual void UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries); |
michael@0 | 583 | |
michael@0 | 584 | void HidePlugin(); |
michael@0 | 585 | void UpdatePluginPort(); |
michael@0 | 586 | |
michael@0 | 587 | void ResetParent(); |
michael@0 | 588 | |
michael@0 | 589 | static bool DoHasPendingInputEvent(); |
michael@0 | 590 | static uint32_t GetCurrentInputEventCount(); |
michael@0 | 591 | static void UpdateCurrentInputEventCount(); |
michael@0 | 592 | |
michael@0 | 593 | NSView<mozView>* GetEditorView(); |
michael@0 | 594 | |
michael@0 | 595 | bool IsPluginView() { return (mWindowType == eWindowType_plugin); } |
michael@0 | 596 | |
michael@0 | 597 | nsCocoaWindow* GetXULWindowWidget(); |
michael@0 | 598 | |
michael@0 | 599 | NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent); |
michael@0 | 600 | |
michael@0 | 601 | mozilla::widget::TextInputHandler* GetTextInputHandler() |
michael@0 | 602 | { |
michael@0 | 603 | return mTextInputHandler; |
michael@0 | 604 | } |
michael@0 | 605 | |
michael@0 | 606 | void NotifyDirtyRegion(const nsIntRegion& aDirtyRegion); |
michael@0 | 607 | |
michael@0 | 608 | // unit conversion convenience functions |
michael@0 | 609 | int32_t CocoaPointsToDevPixels(CGFloat aPts) { |
michael@0 | 610 | return nsCocoaUtils::CocoaPointsToDevPixels(aPts, BackingScaleFactor()); |
michael@0 | 611 | } |
michael@0 | 612 | nsIntPoint CocoaPointsToDevPixels(const NSPoint& aPt) { |
michael@0 | 613 | return nsCocoaUtils::CocoaPointsToDevPixels(aPt, BackingScaleFactor()); |
michael@0 | 614 | } |
michael@0 | 615 | nsIntRect CocoaPointsToDevPixels(const NSRect& aRect) { |
michael@0 | 616 | return nsCocoaUtils::CocoaPointsToDevPixels(aRect, BackingScaleFactor()); |
michael@0 | 617 | } |
michael@0 | 618 | CGFloat DevPixelsToCocoaPoints(int32_t aPixels) { |
michael@0 | 619 | return nsCocoaUtils::DevPixelsToCocoaPoints(aPixels, BackingScaleFactor()); |
michael@0 | 620 | } |
michael@0 | 621 | NSRect DevPixelsToCocoaPoints(const nsIntRect& aRect) { |
michael@0 | 622 | return nsCocoaUtils::DevPixelsToCocoaPoints(aRect, BackingScaleFactor()); |
michael@0 | 623 | } |
michael@0 | 624 | |
michael@0 | 625 | mozilla::TemporaryRef<mozilla::gfx::DrawTarget> StartRemoteDrawing() MOZ_OVERRIDE; |
michael@0 | 626 | void EndRemoteDrawing() MOZ_OVERRIDE; |
michael@0 | 627 | void CleanupRemoteDrawing() MOZ_OVERRIDE; |
michael@0 | 628 | |
michael@0 | 629 | protected: |
michael@0 | 630 | |
michael@0 | 631 | void ReportMoveEvent(); |
michael@0 | 632 | void ReportSizeEvent(); |
michael@0 | 633 | |
michael@0 | 634 | // override to create different kinds of child views. Autoreleases, so |
michael@0 | 635 | // caller must retain. |
michael@0 | 636 | virtual NSView* CreateCocoaView(NSRect inFrame); |
michael@0 | 637 | void TearDownView(); |
michael@0 | 638 | |
michael@0 | 639 | virtual already_AddRefed<nsIWidget> |
michael@0 | 640 | AllocateChildPopupWidget() |
michael@0 | 641 | { |
michael@0 | 642 | static NS_DEFINE_IID(kCPopUpCID, NS_POPUP_CID); |
michael@0 | 643 | nsCOMPtr<nsIWidget> widget = do_CreateInstance(kCPopUpCID); |
michael@0 | 644 | return widget.forget(); |
michael@0 | 645 | } |
michael@0 | 646 | |
michael@0 | 647 | void DoRemoteComposition(const nsIntRect& aRenderRect); |
michael@0 | 648 | |
michael@0 | 649 | // Overlay drawing functions for OpenGL drawing |
michael@0 | 650 | void DrawWindowOverlay(mozilla::layers::GLManager* aManager, nsIntRect aRect); |
michael@0 | 651 | void MaybeDrawResizeIndicator(mozilla::layers::GLManager* aManager, const nsIntRect& aRect); |
michael@0 | 652 | void MaybeDrawRoundedCorners(mozilla::layers::GLManager* aManager, const nsIntRect& aRect); |
michael@0 | 653 | void MaybeDrawTitlebar(mozilla::layers::GLManager* aManager, const nsIntRect& aRect); |
michael@0 | 654 | |
michael@0 | 655 | // Redraw the contents of mTitlebarCGContext on the main thread, as |
michael@0 | 656 | // determined by mDirtyTitlebarRegion. |
michael@0 | 657 | void UpdateTitlebarCGContext(); |
michael@0 | 658 | |
michael@0 | 659 | nsIntRect RectContainingTitlebarControls(); |
michael@0 | 660 | |
michael@0 | 661 | nsIWidget* GetWidgetForListenerEvents(); |
michael@0 | 662 | |
michael@0 | 663 | protected: |
michael@0 | 664 | |
michael@0 | 665 | NSView<mozView>* mView; // my parallel cocoa view (ChildView or NativeScrollbarView), [STRONG] |
michael@0 | 666 | nsRefPtr<mozilla::widget::TextInputHandler> mTextInputHandler; |
michael@0 | 667 | InputContext mInputContext; |
michael@0 | 668 | |
michael@0 | 669 | NSView<mozView>* mParentView; |
michael@0 | 670 | nsIWidget* mParentWidget; |
michael@0 | 671 | |
michael@0 | 672 | #ifdef ACCESSIBILITY |
michael@0 | 673 | // weak ref to this childview's associated mozAccessible for speed reasons |
michael@0 | 674 | // (we get queried for it *a lot* but don't want to own it) |
michael@0 | 675 | nsWeakPtr mAccessible; |
michael@0 | 676 | #endif |
michael@0 | 677 | |
michael@0 | 678 | nsRefPtr<gfxASurface> mTempThebesSurface; |
michael@0 | 679 | |
michael@0 | 680 | // Protects the view from being teared down while a composition is in |
michael@0 | 681 | // progress on the compositor thread. |
michael@0 | 682 | mozilla::Mutex mViewTearDownLock; |
michael@0 | 683 | |
michael@0 | 684 | mozilla::Mutex mEffectsLock; |
michael@0 | 685 | |
michael@0 | 686 | // May be accessed from any thread, protected |
michael@0 | 687 | // by mEffectsLock. |
michael@0 | 688 | bool mShowsResizeIndicator; |
michael@0 | 689 | nsIntRect mResizeIndicatorRect; |
michael@0 | 690 | bool mHasRoundedBottomCorners; |
michael@0 | 691 | int mDevPixelCornerRadius; |
michael@0 | 692 | bool mIsCoveringTitlebar; |
michael@0 | 693 | bool mIsFullscreen; |
michael@0 | 694 | nsIntRect mTitlebarRect; |
michael@0 | 695 | |
michael@0 | 696 | // The area of mTitlebarCGContext that needs to be redrawn during the next |
michael@0 | 697 | // transaction. Accessed from any thread, protected by mEffectsLock. |
michael@0 | 698 | nsIntRegion mUpdatedTitlebarRegion; |
michael@0 | 699 | CGContextRef mTitlebarCGContext; |
michael@0 | 700 | |
michael@0 | 701 | // Compositor thread only |
michael@0 | 702 | nsAutoPtr<RectTextureImage> mResizerImage; |
michael@0 | 703 | nsAutoPtr<RectTextureImage> mCornerMaskImage; |
michael@0 | 704 | nsAutoPtr<RectTextureImage> mTitlebarImage; |
michael@0 | 705 | nsAutoPtr<RectTextureImage> mBasicCompositorImage; |
michael@0 | 706 | |
michael@0 | 707 | // The area of mTitlebarCGContext that has changed and needs to be |
michael@0 | 708 | // uploaded to to mTitlebarImage. Main thread only. |
michael@0 | 709 | nsIntRegion mDirtyTitlebarRegion; |
michael@0 | 710 | |
michael@0 | 711 | // Cached value of [mView backingScaleFactor], to avoid sending two obj-c |
michael@0 | 712 | // messages (respondsToSelector, backingScaleFactor) every time we need to |
michael@0 | 713 | // use it. |
michael@0 | 714 | // ** We'll need to reinitialize this if the backing resolution changes. ** |
michael@0 | 715 | CGFloat mBackingScaleFactor; |
michael@0 | 716 | |
michael@0 | 717 | bool mVisible; |
michael@0 | 718 | bool mDrawing; |
michael@0 | 719 | bool mPluginDrawing; |
michael@0 | 720 | bool mIsDispatchPaint; // Is a paint event being dispatched |
michael@0 | 721 | |
michael@0 | 722 | NP_CGContext mPluginCGContext; |
michael@0 | 723 | nsIPluginInstanceOwner* mPluginInstanceOwner; // [WEAK] |
michael@0 | 724 | |
michael@0 | 725 | // Used in OMTC BasicLayers mode. Presents the BasicCompositor result |
michael@0 | 726 | // surface to the screen using an OpenGL context. |
michael@0 | 727 | nsAutoPtr<GLPresenter> mGLPresenter; |
michael@0 | 728 | |
michael@0 | 729 | static uint32_t sLastInputEventCount; |
michael@0 | 730 | |
michael@0 | 731 | void ReleaseTitlebarCGContext(); |
michael@0 | 732 | }; |
michael@0 | 733 | |
michael@0 | 734 | void NS_InstallPluginKeyEventsHandler(); |
michael@0 | 735 | void NS_RemovePluginKeyEventsHandler(); |
michael@0 | 736 | |
michael@0 | 737 | #endif // nsChildView_h_ |