michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsChildView_h_ michael@0: #define nsChildView_h_ michael@0: michael@0: // formal protocols michael@0: #include "mozView.h" michael@0: #ifdef ACCESSIBILITY michael@0: #include "mozilla/a11y/Accessible.h" michael@0: #include "mozAccessibleProtocol.h" michael@0: #endif michael@0: michael@0: #include "nsAutoPtr.h" michael@0: #include "nsISupports.h" michael@0: #include "nsBaseWidget.h" michael@0: #include "nsIPluginInstanceOwner.h" michael@0: #include "nsIPluginWidget.h" michael@0: #include "nsWeakPtr.h" michael@0: #include "TextInputHandler.h" michael@0: #include "nsCocoaUtils.h" michael@0: #include "gfxQuartzSurface.h" michael@0: #include "GLContextTypes.h" michael@0: #include "mozilla/Mutex.h" michael@0: #include "nsRegion.h" michael@0: #include "mozilla/MouseEvents.h" michael@0: michael@0: #include "nsString.h" michael@0: #include "nsIDragService.h" michael@0: michael@0: #include "npapi.h" michael@0: michael@0: #import michael@0: #import michael@0: #import michael@0: michael@0: // The header files QuickdrawAPI.h and QDOffscreen.h are missing on OS X 10.7 michael@0: // and up (though the QuickDraw APIs defined in them are still present) -- so michael@0: // we need to supply the relevant parts of their contents here. It's likely michael@0: // that Apple will eventually remove the APIs themselves (probably in OS X michael@0: // 10.8), so we need to make them weak imports, and test for their presence michael@0: // before using them. michael@0: #ifdef __cplusplus michael@0: extern "C" { michael@0: #endif michael@0: #if !defined(__QUICKDRAWAPI__) michael@0: michael@0: extern void SetPort(GrafPtr port) michael@0: __attribute__((weak_import)); michael@0: extern void SetOrigin(short h, short v) michael@0: __attribute__((weak_import)); michael@0: extern RgnHandle NewRgn(void) michael@0: __attribute__((weak_import)); michael@0: extern void DisposeRgn(RgnHandle rgn) michael@0: __attribute__((weak_import)); michael@0: extern void RectRgn(RgnHandle rgn, const Rect * r) michael@0: __attribute__((weak_import)); michael@0: extern GDHandle GetMainDevice(void) michael@0: __attribute__((weak_import)); michael@0: extern Boolean IsPortOffscreen(CGrafPtr port) michael@0: __attribute__((weak_import)); michael@0: extern void SetPortVisibleRegion(CGrafPtr port, RgnHandle visRgn) michael@0: __attribute__((weak_import)); michael@0: extern void SetPortClipRegion(CGrafPtr port, RgnHandle clipRgn) michael@0: __attribute__((weak_import)); michael@0: extern CGrafPtr GetQDGlobalsThePort(void) michael@0: __attribute__((weak_import)); michael@0: michael@0: #endif /* __QUICKDRAWAPI__ */ michael@0: michael@0: #if !defined(__QDOFFSCREEN__) michael@0: michael@0: extern void GetGWorld(CGrafPtr * port, GDHandle * gdh) michael@0: __attribute__((weak_import)); michael@0: extern void SetGWorld(CGrafPtr port, GDHandle gdh) michael@0: __attribute__((weak_import)); michael@0: michael@0: #endif /* __QDOFFSCREEN__ */ michael@0: #ifdef __cplusplus michael@0: } michael@0: #endif michael@0: michael@0: class gfxASurface; michael@0: class nsChildView; michael@0: class nsCocoaWindow; michael@0: union nsPluginPort; michael@0: michael@0: namespace { michael@0: class GLPresenter; michael@0: class RectTextureImage; michael@0: } michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: class GLManager; michael@0: } michael@0: } michael@0: michael@0: @interface NSEvent (Undocumented) michael@0: michael@0: // Return Cocoa event's corresponding Carbon event. Not initialized (on michael@0: // synthetic events) until the OS actually "sends" the event. This method michael@0: // has been present in the same form since at least OS X 10.2.8. michael@0: - (EventRef)_eventRef; michael@0: michael@0: @end michael@0: michael@0: @interface NSView (Undocumented) michael@0: michael@0: // Draws the title string of a window. michael@0: // Present on NSThemeFrame since at least 10.6. michael@0: // _drawTitleBar is somewhat complex, and has changed over the years michael@0: // since OS X 10.6. But in that time it's never done anything that michael@0: // would break when called outside of -[NSView drawRect:] (which we michael@0: // sometimes do), or whose output can't be redirected to a michael@0: // CGContextRef object (which we also sometimes do). This is likely michael@0: // to remain true for the indefinite future. However we should michael@0: // check _drawTitleBar in each new major version of OS X. For more michael@0: // information see bug 877767. michael@0: - (void)_drawTitleBar:(NSRect)aRect; michael@0: michael@0: // Returns an NSRect that is the bounding box for all an NSView's dirty michael@0: // rectangles (ones that need to be redrawn). The full list of dirty michael@0: // rectangles can be obtained by calling -[NSView _dirtyRegion] and then michael@0: // calling -[NSRegion getRects:count:] on what it returns. Both these michael@0: // methods have been present in the same form since at least OS X 10.5. michael@0: // Unlike -[NSView getRectsBeingDrawn:count:], these methods can be called michael@0: // outside a call to -[NSView drawRect:]. michael@0: - (NSRect)_dirtyRect; michael@0: michael@0: // Undocumented method of one or more of NSFrameView's subclasses. Called michael@0: // when one or more of the titlebar buttons needs to be repositioned, to michael@0: // disappear, or to reappear (say if the window's style changes). If michael@0: // 'redisplay' is true, the entire titlebar (the window's top 22 pixels) is michael@0: // marked as needing redisplay. This method has been present in the same michael@0: // format since at least OS X 10.5. michael@0: - (void)_tileTitlebarAndRedisplay:(BOOL)redisplay; michael@0: michael@0: @end michael@0: michael@0: // Support for pixel scroll deltas, not part of NSEvent.h michael@0: // See http://lists.apple.com/archives/cocoa-dev/2007/Feb/msg00050.html michael@0: @interface NSEvent (DeviceDelta) michael@0: // Leopard and SnowLeopard michael@0: - (CGFloat)deviceDeltaX; michael@0: - (CGFloat)deviceDeltaY; michael@0: // Lion and above michael@0: - (CGFloat)scrollingDeltaX; michael@0: - (CGFloat)scrollingDeltaY; michael@0: - (BOOL)hasPreciseScrollingDeltas; michael@0: @end michael@0: michael@0: #if !defined(MAC_OS_X_VERSION_10_6) || \ michael@0: MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 michael@0: @interface NSEvent (SnowLeopardEventFeatures) michael@0: + (NSUInteger)pressedMouseButtons; michael@0: + (NSUInteger)modifierFlags; michael@0: @end michael@0: #endif michael@0: michael@0: // The following section, required to support fluid swipe tracking on OS X 10.7 michael@0: // and up, contains defines/declarations that are only available on 10.7 and up. michael@0: // [NSEvent trackSwipeEventWithOptions:...] also requires that the compiler michael@0: // support "blocks" michael@0: // (http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html) michael@0: // -- which it does on 10.6 and up (using the 10.6 SDK or higher). michael@0: // michael@0: // MAC_OS_X_VERSION_MAX_ALLOWED "controls which OS functionality, if used, michael@0: // will result in a compiler error because that functionality is not michael@0: // available" (quoting from AvailabilityMacros.h). The compiler initializes michael@0: // it to the version of the SDK being used. Its value does *not* prevent the michael@0: // binary from running on higher OS versions. MAC_OS_X_VERSION_10_7 and michael@0: // friends are defined (in AvailabilityMacros.h) as decimal numbers (not michael@0: // hexadecimal numbers). michael@0: #if !defined(MAC_OS_X_VERSION_10_7) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 michael@0: enum { michael@0: NSEventPhaseNone = 0, michael@0: NSEventPhaseBegan = 0x1 << 0, michael@0: NSEventPhaseStationary = 0x1 << 1, michael@0: NSEventPhaseChanged = 0x1 << 2, michael@0: NSEventPhaseEnded = 0x1 << 3, michael@0: NSEventPhaseCancelled = 0x1 << 4, michael@0: }; michael@0: typedef NSUInteger NSEventPhase; michael@0: michael@0: enum { michael@0: NSFullScreenWindowMask = 1 << 14 michael@0: }; michael@0: michael@0: @interface NSWindow (LionWindowFeatures) michael@0: - (NSRect)convertRectToScreen:(NSRect)aRect; michael@0: @end michael@0: michael@0: #ifdef __LP64__ michael@0: enum { michael@0: NSEventSwipeTrackingLockDirection = 0x1 << 0, michael@0: NSEventSwipeTrackingClampGestureAmount = 0x1 << 1 michael@0: }; michael@0: typedef NSUInteger NSEventSwipeTrackingOptions; michael@0: michael@0: enum { michael@0: NSEventGestureAxisNone = 0, michael@0: NSEventGestureAxisHorizontal, michael@0: NSEventGestureAxisVertical michael@0: }; michael@0: typedef NSInteger NSEventGestureAxis; michael@0: michael@0: @interface NSEvent (FluidSwipeTracking) michael@0: + (BOOL)isSwipeTrackingFromScrollEventsEnabled; michael@0: - (BOOL)hasPreciseScrollingDeltas; michael@0: - (CGFloat)scrollingDeltaX; michael@0: - (CGFloat)scrollingDeltaY; michael@0: - (NSEventPhase)phase; michael@0: - (void)trackSwipeEventWithOptions:(NSEventSwipeTrackingOptions)options michael@0: dampenAmountThresholdMin:(CGFloat)minDampenThreshold michael@0: max:(CGFloat)maxDampenThreshold michael@0: usingHandler:(void (^)(CGFloat gestureAmount, NSEventPhase phase, BOOL isComplete, BOOL *stop))trackingHandler; michael@0: @end michael@0: #endif // #ifdef __LP64__ michael@0: #endif // #if !defined(MAC_OS_X_VERSION_10_7) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 michael@0: michael@0: #if !defined(MAC_OS_X_VERSION_10_8) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_8 michael@0: enum { michael@0: NSEventPhaseMayBegin = 0x1 << 5 michael@0: }; michael@0: #endif // #if !defined(MAC_OS_X_VERSION_10_8) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_8 michael@0: michael@0: // Undocumented scrollPhase flag that lets us discern between real scrolls and michael@0: // automatically firing momentum scroll events. michael@0: @interface NSEvent (ScrollPhase) michael@0: // Leopard and SnowLeopard michael@0: - (long long)_scrollPhase; michael@0: // Lion and above michael@0: - (NSEventPhase)momentumPhase; michael@0: @end michael@0: michael@0: @interface ChildView : NSView< michael@0: #ifdef ACCESSIBILITY michael@0: mozAccessible, michael@0: #endif michael@0: mozView, NSTextInput, NSTextInputClient> michael@0: { michael@0: @private michael@0: // the nsChildView that created the view. It retains this NSView, so michael@0: // the link back to it must be weak. michael@0: nsChildView* mGeckoChild; michael@0: michael@0: // Text input handler for mGeckoChild and us. Note that this is a weak michael@0: // reference. Ideally, this should be a strong reference but a ChildView michael@0: // object can live longer than the mGeckoChild that owns it. And if michael@0: // mTextInputHandler were a strong reference, this would make it difficult michael@0: // for Gecko's leak detector to detect leaked TextInputHandler objects. michael@0: // This is initialized by [mozView installTextInputHandler:aHandler] and michael@0: // cleared by [mozView uninstallTextInputHandler]. michael@0: mozilla::widget::TextInputHandler* mTextInputHandler; // [WEAK] michael@0: michael@0: BOOL mIsPluginView; michael@0: NPEventModel mPluginEventModel; michael@0: NPDrawingModel mPluginDrawingModel; michael@0: michael@0: // when mouseDown: is called, we store its event here (strong) michael@0: NSEvent* mLastMouseDownEvent; michael@0: michael@0: // Whether the last mouse down event was blocked from Gecko. michael@0: BOOL mBlockedLastMouseDown; michael@0: michael@0: // when acceptsFirstMouse: is called, we store the event here (strong) michael@0: NSEvent* mClickThroughMouseDownEvent; michael@0: michael@0: // rects that were invalidated during a draw, so have pending drawing michael@0: NSMutableArray* mPendingDirtyRects; michael@0: BOOL mPendingFullDisplay; michael@0: BOOL mPendingDisplay; michael@0: michael@0: // WheelStart/Stop events should always come in pairs. This BOOL records the michael@0: // last received event so that, when we receive one of the events, we make sure michael@0: // to send its pair event first, in case we didn't yet for any reason. michael@0: BOOL mExpectingWheelStop; michael@0: michael@0: // Holds our drag service across multiple drag calls. The reference to the michael@0: // service is obtained when the mouse enters the view and is released when michael@0: // the mouse exits or there is a drop. This prevents us from having to michael@0: // re-establish the connection to the service manager many times per second michael@0: // when handling |draggingUpdated:| messages. michael@0: nsIDragService* mDragService; michael@0: michael@0: NSOpenGLContext *mGLContext; michael@0: michael@0: // Simple gestures support michael@0: // michael@0: // mGestureState is used to detect when Cocoa has called both michael@0: // magnifyWithEvent and rotateWithEvent within the same michael@0: // beginGestureWithEvent and endGestureWithEvent sequence. We michael@0: // discard the spurious gesture event so as not to confuse Gecko. michael@0: // michael@0: // mCumulativeMagnification keeps track of the total amount of michael@0: // magnification peformed during a magnify gesture so that we can michael@0: // send that value with the final MozMagnifyGesture event. michael@0: // michael@0: // mCumulativeRotation keeps track of the total amount of rotation michael@0: // performed during a rotate gesture so we can send that value with michael@0: // the final MozRotateGesture event. michael@0: enum { michael@0: eGestureState_None, michael@0: eGestureState_StartGesture, michael@0: eGestureState_MagnifyGesture, michael@0: eGestureState_RotateGesture michael@0: } mGestureState; michael@0: float mCumulativeMagnification; michael@0: float mCumulativeRotation; michael@0: michael@0: BOOL mDidForceRefreshOpenGL; michael@0: BOOL mWaitingForPaint; michael@0: michael@0: #ifdef __LP64__ michael@0: // Support for fluid swipe tracking. michael@0: BOOL* mCancelSwipeAnimation; michael@0: uint32_t mCurrentSwipeDir; michael@0: #endif michael@0: michael@0: // Whether this uses off-main-thread compositing. michael@0: BOOL mUsingOMTCompositor; michael@0: michael@0: // The mask image that's used when painting into the titlebar using basic michael@0: // CGContext painting (i.e. non-accelerated). michael@0: CGImageRef mTopLeftCornerMask; michael@0: } michael@0: michael@0: // class initialization michael@0: + (void)initialize; michael@0: michael@0: + (void)registerViewForDraggedTypes:(NSView*)aView; michael@0: michael@0: // these are sent to the first responder when the window key status changes michael@0: - (void)viewsWindowDidBecomeKey; michael@0: - (void)viewsWindowDidResignKey; michael@0: michael@0: // Stop NSView hierarchy being changed during [ChildView drawRect:] michael@0: - (void)delayedTearDown; michael@0: michael@0: - (void)sendFocusEvent:(uint32_t)eventType; michael@0: michael@0: - (void)handleMouseMoved:(NSEvent*)aEvent; michael@0: michael@0: - (void)updateWindowDraggableStateOnMouseMove:(NSEvent*)theEvent; michael@0: michael@0: - (void)sendMouseEnterOrExitEvent:(NSEvent*)aEvent michael@0: enter:(BOOL)aEnter michael@0: type:(mozilla::WidgetMouseEvent::exitType)aType; michael@0: michael@0: - (void)updateGLContext; michael@0: - (void)_surfaceNeedsUpdate:(NSNotification*)notification; michael@0: michael@0: - (BOOL)isPluginView; michael@0: michael@0: // Are we processing an NSLeftMouseDown event that will fail to click through? michael@0: // If so, we shouldn't focus or unfocus a plugin. michael@0: - (BOOL)isInFailingLeftClickThrough; michael@0: michael@0: - (void)setGLContext:(NSOpenGLContext *)aGLContext; michael@0: - (bool)preRender:(NSOpenGLContext *)aGLContext; michael@0: - (void)postRender:(NSOpenGLContext *)aGLContext; michael@0: michael@0: - (BOOL)isCoveringTitlebar; michael@0: michael@0: // Simple gestures support michael@0: // michael@0: // XXX - The swipeWithEvent, beginGestureWithEvent, magnifyWithEvent, michael@0: // rotateWithEvent, and endGestureWithEvent methods are part of a michael@0: // PRIVATE interface exported by nsResponder and reverse-engineering michael@0: // was necessary to obtain the methods' prototypes. Thus, Apple may michael@0: // change the interface in the future without notice. michael@0: // michael@0: // The prototypes were obtained from the following link: michael@0: // http://cocoadex.com/2008/02/nsevent-modifications-swipe-ro.html michael@0: - (void)swipeWithEvent:(NSEvent *)anEvent; michael@0: - (void)beginGestureWithEvent:(NSEvent *)anEvent; michael@0: - (void)magnifyWithEvent:(NSEvent *)anEvent; michael@0: - (void)smartMagnifyWithEvent:(NSEvent *)anEvent; michael@0: - (void)rotateWithEvent:(NSEvent *)anEvent; michael@0: - (void)endGestureWithEvent:(NSEvent *)anEvent; michael@0: michael@0: - (void)scrollWheel:(NSEvent *)anEvent; michael@0: michael@0: // Helper function for Lion smart magnify events michael@0: + (BOOL)isLionSmartMagnifyEvent:(NSEvent*)anEvent; michael@0: michael@0: // Support for fluid swipe tracking. michael@0: #ifdef __LP64__ michael@0: - (void)maybeTrackScrollEventAsSwipe:(NSEvent *)anEvent michael@0: scrollOverflowX:(double)anOverflowX michael@0: scrollOverflowY:(double)anOverflowY michael@0: viewPortIsOverscrolled:(BOOL)aViewPortIsOverscrolled; michael@0: #endif michael@0: michael@0: - (void)setUsingOMTCompositor:(BOOL)aUseOMTC; michael@0: @end michael@0: michael@0: class ChildViewMouseTracker { michael@0: michael@0: public: michael@0: michael@0: static void MouseMoved(NSEvent* aEvent); michael@0: static void MouseScrolled(NSEvent* aEvent); michael@0: static void OnDestroyView(ChildView* aView); michael@0: static void OnDestroyWindow(NSWindow* aWindow); michael@0: static BOOL WindowAcceptsEvent(NSWindow* aWindow, NSEvent* aEvent, michael@0: ChildView* aView, BOOL isClickThrough = NO); michael@0: static void MouseExitedWindow(NSEvent* aEvent); michael@0: static void MouseEnteredWindow(NSEvent* aEvent); michael@0: static void ReEvaluateMouseEnterState(NSEvent* aEvent = nil, ChildView* aOldView = nil); michael@0: static void ResendLastMouseMoveEvent(); michael@0: static ChildView* ViewForEvent(NSEvent* aEvent); michael@0: static void AttachPluginEvent(mozilla::WidgetMouseEventBase& aMouseEvent, michael@0: ChildView* aView, michael@0: NSEvent* aNativeMouseEvent, michael@0: int aPluginEventType, michael@0: void* aPluginEventHolder); michael@0: michael@0: static ChildView* sLastMouseEventView; michael@0: static NSEvent* sLastMouseMoveEvent; michael@0: static NSWindow* sWindowUnderMouse; michael@0: static NSPoint sLastScrollEventScreenLocation; michael@0: }; michael@0: michael@0: //------------------------------------------------------------------------- michael@0: // michael@0: // nsChildView michael@0: // michael@0: //------------------------------------------------------------------------- michael@0: michael@0: class nsChildView : public nsBaseWidget, michael@0: public nsIPluginWidget michael@0: { michael@0: private: michael@0: typedef nsBaseWidget Inherited; michael@0: michael@0: public: michael@0: nsChildView(); michael@0: virtual ~nsChildView(); michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: michael@0: // nsIWidget interface michael@0: NS_IMETHOD Create(nsIWidget *aParent, michael@0: nsNativeWidget aNativeParent, michael@0: const nsIntRect &aRect, michael@0: nsDeviceContext *aContext, michael@0: nsWidgetInitData *aInitData = nullptr); michael@0: michael@0: NS_IMETHOD Destroy(); michael@0: michael@0: NS_IMETHOD Show(bool aState); michael@0: virtual bool IsVisible() const; michael@0: michael@0: NS_IMETHOD SetParent(nsIWidget* aNewParent); michael@0: virtual nsIWidget* GetParent(void); michael@0: virtual float GetDPI(); michael@0: michael@0: NS_IMETHOD ConstrainPosition(bool aAllowSlop, michael@0: int32_t *aX, int32_t *aY); michael@0: NS_IMETHOD Move(double aX, double aY); michael@0: NS_IMETHOD Resize(double aWidth, double aHeight, bool aRepaint); michael@0: NS_IMETHOD Resize(double aX, double aY, michael@0: double aWidth, double aHeight, bool aRepaint); michael@0: michael@0: NS_IMETHOD Enable(bool aState); michael@0: virtual bool IsEnabled() const; michael@0: NS_IMETHOD SetFocus(bool aRaise); michael@0: NS_IMETHOD GetBounds(nsIntRect &aRect); michael@0: NS_IMETHOD GetClientBounds(nsIntRect &aRect); michael@0: NS_IMETHOD GetScreenBounds(nsIntRect &aRect); michael@0: michael@0: // Returns the "backing scale factor" of the view's window, which is the michael@0: // ratio of pixels in the window's backing store to Cocoa points. Prior to michael@0: // HiDPI support in OS X 10.7, this was always 1.0, but in HiDPI mode it michael@0: // will be 2.0 (and might potentially other values as screen resolutions michael@0: // evolve). This gives the relationship between what Gecko calls "device michael@0: // pixels" and the Cocoa "points" coordinate system. michael@0: CGFloat BackingScaleFactor(); michael@0: michael@0: // Call if the window's backing scale factor changes - i.e., it is moved michael@0: // between HiDPI and non-HiDPI screens michael@0: void BackingScaleFactorChanged(); michael@0: michael@0: virtual double GetDefaultScaleInternal(); michael@0: michael@0: virtual int32_t RoundsWidgetCoordinatesTo() MOZ_OVERRIDE; michael@0: michael@0: NS_IMETHOD Invalidate(const nsIntRect &aRect); michael@0: michael@0: virtual void* GetNativeData(uint32_t aDataType); michael@0: virtual nsresult ConfigureChildren(const nsTArray& aConfigurations); michael@0: virtual nsIntPoint WidgetToScreenOffset(); michael@0: virtual bool ShowsResizeIndicator(nsIntRect* aResizerRect); michael@0: michael@0: static bool ConvertStatus(nsEventStatus aStatus) michael@0: { return aStatus == nsEventStatus_eConsumeNoDefault; } michael@0: NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent, michael@0: nsEventStatus& aStatus); michael@0: michael@0: virtual bool ComputeShouldAccelerate(bool aDefault); michael@0: virtual bool ShouldUseOffMainThreadCompositing() MOZ_OVERRIDE; michael@0: michael@0: NS_IMETHOD SetCursor(nsCursor aCursor); michael@0: NS_IMETHOD SetCursor(imgIContainer* aCursor, uint32_t aHotspotX, uint32_t aHotspotY); michael@0: michael@0: NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, bool aDoCapture); michael@0: NS_IMETHOD SetTitle(const nsAString& title); michael@0: michael@0: NS_IMETHOD GetAttention(int32_t aCycleCount); michael@0: michael@0: virtual bool HasPendingInputEvent(); michael@0: michael@0: NS_IMETHOD ActivateNativeMenuItemAt(const nsAString& indexString); michael@0: NS_IMETHOD ForceUpdateNativeMenuAt(const nsAString& indexString); michael@0: michael@0: NS_IMETHOD NotifyIME(const IMENotification& aIMENotification) MOZ_OVERRIDE; michael@0: NS_IMETHOD_(void) SetInputContext(const InputContext& aContext, michael@0: const InputContextAction& aAction); michael@0: NS_IMETHOD_(InputContext) GetInputContext(); michael@0: NS_IMETHOD AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent); michael@0: NS_IMETHOD_(bool) ExecuteNativeKeyBinding( michael@0: NativeKeyBindingsType aType, michael@0: const mozilla::WidgetKeyboardEvent& aEvent, michael@0: DoCommandCallback aCallback, michael@0: void* aCallbackData) MOZ_OVERRIDE; michael@0: virtual nsIMEUpdatePreference GetIMEUpdatePreference() MOZ_OVERRIDE; michael@0: NS_IMETHOD GetToggledKeyState(uint32_t aKeyCode, michael@0: bool* aLEDState); michael@0: michael@0: // nsIPluginWidget michael@0: // outClipRect and outOrigin are in display pixels (not device pixels) michael@0: NS_IMETHOD GetPluginClipRect(nsIntRect& outClipRect, nsIntPoint& outOrigin, bool& outWidgetVisible); michael@0: NS_IMETHOD StartDrawPlugin(); michael@0: NS_IMETHOD EndDrawPlugin(); michael@0: NS_IMETHOD SetPluginInstanceOwner(nsIPluginInstanceOwner* aInstanceOwner); michael@0: michael@0: NS_IMETHOD SetPluginEventModel(int inEventModel); michael@0: NS_IMETHOD GetPluginEventModel(int* outEventModel); michael@0: NS_IMETHOD SetPluginDrawingModel(int inDrawingModel); michael@0: michael@0: NS_IMETHOD StartComplexTextInputForCurrentEvent(); michael@0: michael@0: virtual nsTransparencyMode GetTransparencyMode(); michael@0: virtual void SetTransparencyMode(nsTransparencyMode aMode); michael@0: michael@0: virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout, michael@0: int32_t aNativeKeyCode, michael@0: uint32_t aModifierFlags, michael@0: const nsAString& aCharacters, michael@0: const nsAString& aUnmodifiedCharacters); michael@0: michael@0: virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint, michael@0: uint32_t aNativeMessage, michael@0: uint32_t aModifierFlags); michael@0: michael@0: virtual nsresult SynthesizeNativeMouseMove(nsIntPoint aPoint) michael@0: { return SynthesizeNativeMouseEvent(aPoint, NSMouseMoved, 0); } michael@0: michael@0: // Mac specific methods michael@0: michael@0: virtual bool DispatchWindowEvent(mozilla::WidgetGUIEvent& event); michael@0: michael@0: void WillPaintWindow(); michael@0: bool PaintWindow(nsIntRegion aRegion); michael@0: michael@0: #ifdef ACCESSIBILITY michael@0: already_AddRefed GetDocumentAccessible(); michael@0: #endif michael@0: michael@0: virtual void CreateCompositor(); michael@0: virtual gfxASurface* GetThebesSurface(); michael@0: virtual void PrepareWindowEffects() MOZ_OVERRIDE; michael@0: virtual void CleanupWindowEffects() MOZ_OVERRIDE; michael@0: virtual bool PreRender(LayerManagerComposite* aManager) MOZ_OVERRIDE; michael@0: virtual void PostRender(LayerManagerComposite* aManager) MOZ_OVERRIDE; michael@0: virtual void DrawWindowOverlay(LayerManagerComposite* aManager, nsIntRect aRect) MOZ_OVERRIDE; michael@0: michael@0: virtual void UpdateThemeGeometries(const nsTArray& aThemeGeometries); michael@0: michael@0: void HidePlugin(); michael@0: void UpdatePluginPort(); michael@0: michael@0: void ResetParent(); michael@0: michael@0: static bool DoHasPendingInputEvent(); michael@0: static uint32_t GetCurrentInputEventCount(); michael@0: static void UpdateCurrentInputEventCount(); michael@0: michael@0: NSView* GetEditorView(); michael@0: michael@0: bool IsPluginView() { return (mWindowType == eWindowType_plugin); } michael@0: michael@0: nsCocoaWindow* GetXULWindowWidget(); michael@0: michael@0: NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent); michael@0: michael@0: mozilla::widget::TextInputHandler* GetTextInputHandler() michael@0: { michael@0: return mTextInputHandler; michael@0: } michael@0: michael@0: void NotifyDirtyRegion(const nsIntRegion& aDirtyRegion); michael@0: michael@0: // unit conversion convenience functions michael@0: int32_t CocoaPointsToDevPixels(CGFloat aPts) { michael@0: return nsCocoaUtils::CocoaPointsToDevPixels(aPts, BackingScaleFactor()); michael@0: } michael@0: nsIntPoint CocoaPointsToDevPixels(const NSPoint& aPt) { michael@0: return nsCocoaUtils::CocoaPointsToDevPixels(aPt, BackingScaleFactor()); michael@0: } michael@0: nsIntRect CocoaPointsToDevPixels(const NSRect& aRect) { michael@0: return nsCocoaUtils::CocoaPointsToDevPixels(aRect, BackingScaleFactor()); michael@0: } michael@0: CGFloat DevPixelsToCocoaPoints(int32_t aPixels) { michael@0: return nsCocoaUtils::DevPixelsToCocoaPoints(aPixels, BackingScaleFactor()); michael@0: } michael@0: NSRect DevPixelsToCocoaPoints(const nsIntRect& aRect) { michael@0: return nsCocoaUtils::DevPixelsToCocoaPoints(aRect, BackingScaleFactor()); michael@0: } michael@0: michael@0: mozilla::TemporaryRef StartRemoteDrawing() MOZ_OVERRIDE; michael@0: void EndRemoteDrawing() MOZ_OVERRIDE; michael@0: void CleanupRemoteDrawing() MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: michael@0: void ReportMoveEvent(); michael@0: void ReportSizeEvent(); michael@0: michael@0: // override to create different kinds of child views. Autoreleases, so michael@0: // caller must retain. michael@0: virtual NSView* CreateCocoaView(NSRect inFrame); michael@0: void TearDownView(); michael@0: michael@0: virtual already_AddRefed michael@0: AllocateChildPopupWidget() michael@0: { michael@0: static NS_DEFINE_IID(kCPopUpCID, NS_POPUP_CID); michael@0: nsCOMPtr widget = do_CreateInstance(kCPopUpCID); michael@0: return widget.forget(); michael@0: } michael@0: michael@0: void DoRemoteComposition(const nsIntRect& aRenderRect); michael@0: michael@0: // Overlay drawing functions for OpenGL drawing michael@0: void DrawWindowOverlay(mozilla::layers::GLManager* aManager, nsIntRect aRect); michael@0: void MaybeDrawResizeIndicator(mozilla::layers::GLManager* aManager, const nsIntRect& aRect); michael@0: void MaybeDrawRoundedCorners(mozilla::layers::GLManager* aManager, const nsIntRect& aRect); michael@0: void MaybeDrawTitlebar(mozilla::layers::GLManager* aManager, const nsIntRect& aRect); michael@0: michael@0: // Redraw the contents of mTitlebarCGContext on the main thread, as michael@0: // determined by mDirtyTitlebarRegion. michael@0: void UpdateTitlebarCGContext(); michael@0: michael@0: nsIntRect RectContainingTitlebarControls(); michael@0: michael@0: nsIWidget* GetWidgetForListenerEvents(); michael@0: michael@0: protected: michael@0: michael@0: NSView* mView; // my parallel cocoa view (ChildView or NativeScrollbarView), [STRONG] michael@0: nsRefPtr mTextInputHandler; michael@0: InputContext mInputContext; michael@0: michael@0: NSView* mParentView; michael@0: nsIWidget* mParentWidget; michael@0: michael@0: #ifdef ACCESSIBILITY michael@0: // weak ref to this childview's associated mozAccessible for speed reasons michael@0: // (we get queried for it *a lot* but don't want to own it) michael@0: nsWeakPtr mAccessible; michael@0: #endif michael@0: michael@0: nsRefPtr mTempThebesSurface; michael@0: michael@0: // Protects the view from being teared down while a composition is in michael@0: // progress on the compositor thread. michael@0: mozilla::Mutex mViewTearDownLock; michael@0: michael@0: mozilla::Mutex mEffectsLock; michael@0: michael@0: // May be accessed from any thread, protected michael@0: // by mEffectsLock. michael@0: bool mShowsResizeIndicator; michael@0: nsIntRect mResizeIndicatorRect; michael@0: bool mHasRoundedBottomCorners; michael@0: int mDevPixelCornerRadius; michael@0: bool mIsCoveringTitlebar; michael@0: bool mIsFullscreen; michael@0: nsIntRect mTitlebarRect; michael@0: michael@0: // The area of mTitlebarCGContext that needs to be redrawn during the next michael@0: // transaction. Accessed from any thread, protected by mEffectsLock. michael@0: nsIntRegion mUpdatedTitlebarRegion; michael@0: CGContextRef mTitlebarCGContext; michael@0: michael@0: // Compositor thread only michael@0: nsAutoPtr mResizerImage; michael@0: nsAutoPtr mCornerMaskImage; michael@0: nsAutoPtr mTitlebarImage; michael@0: nsAutoPtr mBasicCompositorImage; michael@0: michael@0: // The area of mTitlebarCGContext that has changed and needs to be michael@0: // uploaded to to mTitlebarImage. Main thread only. michael@0: nsIntRegion mDirtyTitlebarRegion; michael@0: michael@0: // Cached value of [mView backingScaleFactor], to avoid sending two obj-c michael@0: // messages (respondsToSelector, backingScaleFactor) every time we need to michael@0: // use it. michael@0: // ** We'll need to reinitialize this if the backing resolution changes. ** michael@0: CGFloat mBackingScaleFactor; michael@0: michael@0: bool mVisible; michael@0: bool mDrawing; michael@0: bool mPluginDrawing; michael@0: bool mIsDispatchPaint; // Is a paint event being dispatched michael@0: michael@0: NP_CGContext mPluginCGContext; michael@0: nsIPluginInstanceOwner* mPluginInstanceOwner; // [WEAK] michael@0: michael@0: // Used in OMTC BasicLayers mode. Presents the BasicCompositor result michael@0: // surface to the screen using an OpenGL context. michael@0: nsAutoPtr mGLPresenter; michael@0: michael@0: static uint32_t sLastInputEventCount; michael@0: michael@0: void ReleaseTitlebarCGContext(); michael@0: }; michael@0: michael@0: void NS_InstallPluginKeyEventsHandler(); michael@0: void NS_RemovePluginKeyEventsHandler(); michael@0: michael@0: #endif // nsChildView_h_