widget/cocoa/nsChildView.h

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

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

mercurial