Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / widget / cocoa / nsChildView.h
blob0827efa611e5c1487036a863c5bff4eb4c47c5bf
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"
29 #include "mozilla/UniquePtr.h"
31 #include "nsString.h"
32 #include "nsIDragService.h"
34 #include "npapi.h"
36 #import <Carbon/Carbon.h>
37 #import <Cocoa/Cocoa.h>
38 #import <AppKit/NSOpenGL.h>
40 // The header files QuickdrawAPI.h and QDOffscreen.h are missing on OS X 10.7
41 // and up (though the QuickDraw APIs defined in them are still present) -- so
42 // we need to supply the relevant parts of their contents here. It's likely
43 // that Apple will eventually remove the APIs themselves (probably in OS X
44 // 10.8), so we need to make them weak imports, and test for their presence
45 // before using them.
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 #if !defined(__QUICKDRAWAPI__)
51 extern void SetPort(GrafPtr port)
52 __attribute__((weak_import));
53 extern void SetOrigin(short h, short v)
54 __attribute__((weak_import));
55 extern RgnHandle NewRgn(void)
56 __attribute__((weak_import));
57 extern void DisposeRgn(RgnHandle rgn)
58 __attribute__((weak_import));
59 extern void RectRgn(RgnHandle rgn, const Rect * r)
60 __attribute__((weak_import));
61 extern GDHandle GetMainDevice(void)
62 __attribute__((weak_import));
63 extern Boolean IsPortOffscreen(CGrafPtr port)
64 __attribute__((weak_import));
65 extern void SetPortVisibleRegion(CGrafPtr port, RgnHandle visRgn)
66 __attribute__((weak_import));
67 extern void SetPortClipRegion(CGrafPtr port, RgnHandle clipRgn)
68 __attribute__((weak_import));
69 extern CGrafPtr GetQDGlobalsThePort(void)
70 __attribute__((weak_import));
72 #endif /* __QUICKDRAWAPI__ */
74 #if !defined(__QDOFFSCREEN__)
76 extern void GetGWorld(CGrafPtr * port, GDHandle * gdh)
77 __attribute__((weak_import));
78 extern void SetGWorld(CGrafPtr port, GDHandle gdh)
79 __attribute__((weak_import));
81 #endif /* __QDOFFSCREEN__ */
82 #ifdef __cplusplus
84 #endif
86 class gfxASurface;
87 class nsChildView;
88 class nsCocoaWindow;
89 union nsPluginPort;
91 namespace {
92 class GLPresenter;
93 class RectTextureImage;
96 namespace mozilla {
97 class VibrancyManager;
98 namespace layers {
99 class GLManager;
100 class APZCTreeManager;
104 @interface NSEvent (Undocumented)
106 // Return Cocoa event's corresponding Carbon event. Not initialized (on
107 // synthetic events) until the OS actually "sends" the event. This method
108 // has been present in the same form since at least OS X 10.2.8.
109 - (EventRef)_eventRef;
111 @end
113 @interface NSView (Undocumented)
115 // Draws the title string of a window.
116 // Present on NSThemeFrame since at least 10.6.
117 // _drawTitleBar is somewhat complex, and has changed over the years
118 // since OS X 10.6. But in that time it's never done anything that
119 // would break when called outside of -[NSView drawRect:] (which we
120 // sometimes do), or whose output can't be redirected to a
121 // CGContextRef object (which we also sometimes do). This is likely
122 // to remain true for the indefinite future. However we should
123 // check _drawTitleBar in each new major version of OS X. For more
124 // information see bug 877767.
125 - (void)_drawTitleBar:(NSRect)aRect;
127 // Returns an NSRect that is the bounding box for all an NSView's dirty
128 // rectangles (ones that need to be redrawn). The full list of dirty
129 // rectangles can be obtained by calling -[NSView _dirtyRegion] and then
130 // calling -[NSRegion getRects:count:] on what it returns. Both these
131 // methods have been present in the same form since at least OS X 10.5.
132 // Unlike -[NSView getRectsBeingDrawn:count:], these methods can be called
133 // outside a call to -[NSView drawRect:].
134 - (NSRect)_dirtyRect;
136 // Undocumented method of one or more of NSFrameView's subclasses. Called
137 // when one or more of the titlebar buttons needs to be repositioned, to
138 // disappear, or to reappear (say if the window's style changes). If
139 // 'redisplay' is true, the entire titlebar (the window's top 22 pixels) is
140 // marked as needing redisplay. This method has been present in the same
141 // format since at least OS X 10.5.
142 - (void)_tileTitlebarAndRedisplay:(BOOL)redisplay;
144 // The following undocumented methods are used to work around bug 1069658,
145 // which is an Apple bug or design flaw that effects Yosemite. None of them
146 // were present prior to Yosemite (OS X 10.10).
147 - (NSView *)titlebarView; // Method of NSThemeFrame
148 - (NSView *)titlebarContainerView; // Method of NSThemeFrame
149 - (BOOL)transparent; // Method of NSTitlebarView and NSTitlebarContainerView
150 - (void)setTransparent:(BOOL)transparent; // Method of NSTitlebarView and
151 // NSTitlebarContainerView
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).
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 NSFullScreenWindowMask = 1 << 14
182 @interface NSWindow (LionWindowFeatures)
183 - (NSRect)convertRectToScreen:(NSRect)aRect;
184 @end
186 #ifdef __LP64__
187 enum {
188 NSEventSwipeTrackingLockDirection = 0x1 << 0,
189 NSEventSwipeTrackingClampGestureAmount = 0x1 << 1
191 typedef NSUInteger NSEventSwipeTrackingOptions;
193 enum {
194 NSEventGestureAxisNone = 0,
195 NSEventGestureAxisHorizontal,
196 NSEventGestureAxisVertical
198 typedef NSInteger NSEventGestureAxis;
200 @interface NSEvent (FluidSwipeTracking)
201 + (BOOL)isSwipeTrackingFromScrollEventsEnabled;
202 - (BOOL)hasPreciseScrollingDeltas;
203 - (CGFloat)scrollingDeltaX;
204 - (CGFloat)scrollingDeltaY;
205 - (NSEventPhase)phase;
206 - (void)trackSwipeEventWithOptions:(NSEventSwipeTrackingOptions)options
207 dampenAmountThresholdMin:(CGFloat)minDampenThreshold
208 max:(CGFloat)maxDampenThreshold
209 usingHandler:(void (^)(CGFloat gestureAmount, NSEventPhase phase, BOOL isComplete, BOOL *stop))trackingHandler;
210 @end
211 #endif // #ifdef __LP64__
212 #endif // #if !defined(MAC_OS_X_VERSION_10_7) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
214 @interface ChildView : NSView<
215 #ifdef ACCESSIBILITY
216 mozAccessible,
217 #endif
218 mozView, NSTextInput, NSTextInputClient>
220 @private
221 // the nsChildView that created the view. It retains this NSView, so
222 // the link back to it must be weak.
223 nsChildView* mGeckoChild;
225 // Text input handler for mGeckoChild and us. Note that this is a weak
226 // reference. Ideally, this should be a strong reference but a ChildView
227 // object can live longer than the mGeckoChild that owns it. And if
228 // mTextInputHandler were a strong reference, this would make it difficult
229 // for Gecko's leak detector to detect leaked TextInputHandler objects.
230 // This is initialized by [mozView installTextInputHandler:aHandler] and
231 // cleared by [mozView uninstallTextInputHandler].
232 mozilla::widget::TextInputHandler* mTextInputHandler; // [WEAK]
234 BOOL mIsPluginView;
235 NPEventModel mPluginEventModel;
236 NPDrawingModel mPluginDrawingModel;
238 // when mouseDown: is called, we store its event here (strong)
239 NSEvent* mLastMouseDownEvent;
241 // Whether the last mouse down event was blocked from Gecko.
242 BOOL mBlockedLastMouseDown;
244 // when acceptsFirstMouse: is called, we store the event here (strong)
245 NSEvent* mClickThroughMouseDownEvent;
247 // rects that were invalidated during a draw, so have pending drawing
248 NSMutableArray* mPendingDirtyRects;
249 BOOL mPendingFullDisplay;
250 BOOL mPendingDisplay;
252 // WheelStart/Stop events should always come in pairs. This BOOL records the
253 // last received event so that, when we receive one of the events, we make sure
254 // to send its pair event first, in case we didn't yet for any reason.
255 BOOL mExpectingWheelStop;
257 // Holds our drag service across multiple drag calls. The reference to the
258 // service is obtained when the mouse enters the view and is released when
259 // the mouse exits or there is a drop. This prevents us from having to
260 // re-establish the connection to the service manager many times per second
261 // when handling |draggingUpdated:| messages.
262 nsIDragService* mDragService;
264 NSOpenGLContext *mGLContext;
266 // Simple gestures support
268 // mGestureState is used to detect when Cocoa has called both
269 // magnifyWithEvent and rotateWithEvent within the same
270 // beginGestureWithEvent and endGestureWithEvent sequence. We
271 // discard the spurious gesture event so as not to confuse Gecko.
273 // mCumulativeMagnification keeps track of the total amount of
274 // magnification peformed during a magnify gesture so that we can
275 // send that value with the final MozMagnifyGesture event.
277 // mCumulativeRotation keeps track of the total amount of rotation
278 // performed during a rotate gesture so we can send that value with
279 // the final MozRotateGesture event.
280 enum {
281 eGestureState_None,
282 eGestureState_StartGesture,
283 eGestureState_MagnifyGesture,
284 eGestureState_RotateGesture
285 } mGestureState;
286 float mCumulativeMagnification;
287 float mCumulativeRotation;
289 BOOL mDidForceRefreshOpenGL;
290 BOOL mWaitingForPaint;
292 #ifdef __LP64__
293 // Support for fluid swipe tracking.
294 BOOL* mCancelSwipeAnimation;
295 uint32_t mCurrentSwipeDir;
296 #endif
298 // Whether this uses off-main-thread compositing.
299 BOOL mUsingOMTCompositor;
301 // The mask image that's used when painting into the titlebar using basic
302 // CGContext painting (i.e. non-accelerated).
303 CGImageRef mTopLeftCornerMask;
306 // class initialization
307 + (void)initialize;
309 + (void)registerViewForDraggedTypes:(NSView*)aView;
311 // these are sent to the first responder when the window key status changes
312 - (void)viewsWindowDidBecomeKey;
313 - (void)viewsWindowDidResignKey;
315 // Stop NSView hierarchy being changed during [ChildView drawRect:]
316 - (void)delayedTearDown;
318 - (void)sendFocusEvent:(uint32_t)eventType;
320 - (void)handleMouseMoved:(NSEvent*)aEvent;
322 - (void)updateWindowDraggableStateOnMouseMove:(NSEvent*)theEvent;
324 - (void)sendMouseEnterOrExitEvent:(NSEvent*)aEvent
325 enter:(BOOL)aEnter
326 type:(mozilla::WidgetMouseEvent::exitType)aType;
328 - (void)updateGLContext;
329 - (void)_surfaceNeedsUpdate:(NSNotification*)notification;
331 - (BOOL)isPluginView;
333 // Are we processing an NSLeftMouseDown event that will fail to click through?
334 // If so, we shouldn't focus or unfocus a plugin.
335 - (BOOL)isInFailingLeftClickThrough;
337 - (void)setGLContext:(NSOpenGLContext *)aGLContext;
338 - (bool)preRender:(NSOpenGLContext *)aGLContext;
339 - (void)postRender:(NSOpenGLContext *)aGLContext;
341 - (BOOL)isCoveringTitlebar;
343 - (NSColor*)vibrancyFillColorForWidgetType:(uint8_t)aWidgetType;
345 // Simple gestures support
347 // XXX - The swipeWithEvent, beginGestureWithEvent, magnifyWithEvent,
348 // rotateWithEvent, and endGestureWithEvent methods are part of a
349 // PRIVATE interface exported by nsResponder and reverse-engineering
350 // was necessary to obtain the methods' prototypes. Thus, Apple may
351 // change the interface in the future without notice.
353 // The prototypes were obtained from the following link:
354 // http://cocoadex.com/2008/02/nsevent-modifications-swipe-ro.html
355 - (void)swipeWithEvent:(NSEvent *)anEvent;
356 - (void)beginGestureWithEvent:(NSEvent *)anEvent;
357 - (void)magnifyWithEvent:(NSEvent *)anEvent;
358 - (void)smartMagnifyWithEvent:(NSEvent *)anEvent;
359 - (void)rotateWithEvent:(NSEvent *)anEvent;
360 - (void)endGestureWithEvent:(NSEvent *)anEvent;
362 - (void)scrollWheel:(NSEvent *)anEvent;
363 - (void)handleAsyncScrollEvent:(CGEventRef)cgEvent ofType:(CGEventType)type;
365 // Helper function for Lion smart magnify events
366 + (BOOL)isLionSmartMagnifyEvent:(NSEvent*)anEvent;
368 // Support for fluid swipe tracking.
369 #ifdef __LP64__
370 - (void)maybeTrackScrollEventAsSwipe:(NSEvent *)anEvent
371 scrollOverflowX:(double)anOverflowX
372 scrollOverflowY:(double)anOverflowY
373 viewPortIsOverscrolled:(BOOL)aViewPortIsOverscrolled;
374 #endif
376 - (void)setUsingOMTCompositor:(BOOL)aUseOMTC;
377 @end
379 class ChildViewMouseTracker {
381 public:
383 static void MouseMoved(NSEvent* aEvent);
384 static void MouseScrolled(NSEvent* aEvent);
385 static void OnDestroyView(ChildView* aView);
386 static void OnDestroyWindow(NSWindow* aWindow);
387 static BOOL WindowAcceptsEvent(NSWindow* aWindow, NSEvent* aEvent,
388 ChildView* aView, BOOL isClickThrough = NO);
389 static void MouseExitedWindow(NSEvent* aEvent);
390 static void MouseEnteredWindow(NSEvent* aEvent);
391 static void ReEvaluateMouseEnterState(NSEvent* aEvent = nil, ChildView* aOldView = nil);
392 static void ResendLastMouseMoveEvent();
393 static ChildView* ViewForEvent(NSEvent* aEvent);
394 static void AttachPluginEvent(mozilla::WidgetMouseEventBase& aMouseEvent,
395 ChildView* aView,
396 NSEvent* aNativeMouseEvent,
397 int aPluginEventType,
398 void* aPluginEventHolder);
400 static ChildView* sLastMouseEventView;
401 static NSEvent* sLastMouseMoveEvent;
402 static NSWindow* sWindowUnderMouse;
403 static NSPoint sLastScrollEventScreenLocation;
406 //-------------------------------------------------------------------------
408 // nsChildView
410 //-------------------------------------------------------------------------
412 class nsChildView : public nsBaseWidget,
413 public nsIPluginWidget
415 private:
416 typedef nsBaseWidget Inherited;
417 typedef mozilla::layers::APZCTreeManager APZCTreeManager;
419 public:
420 nsChildView();
422 NS_DECL_ISUPPORTS_INHERITED
424 // nsIWidget interface
425 NS_IMETHOD Create(nsIWidget *aParent,
426 nsNativeWidget aNativeParent,
427 const nsIntRect &aRect,
428 nsDeviceContext *aContext,
429 nsWidgetInitData *aInitData = nullptr);
431 NS_IMETHOD Destroy();
433 NS_IMETHOD Show(bool aState);
434 virtual bool IsVisible() const;
436 NS_IMETHOD SetParent(nsIWidget* aNewParent);
437 virtual nsIWidget* GetParent(void);
438 virtual float GetDPI();
440 NS_IMETHOD ConstrainPosition(bool aAllowSlop,
441 int32_t *aX, int32_t *aY);
442 NS_IMETHOD Move(double aX, double aY);
443 NS_IMETHOD Resize(double aWidth, double aHeight, bool aRepaint);
444 NS_IMETHOD Resize(double aX, double aY,
445 double aWidth, double aHeight, bool aRepaint);
447 NS_IMETHOD Enable(bool aState);
448 virtual bool IsEnabled() const;
449 NS_IMETHOD SetFocus(bool aRaise);
450 NS_IMETHOD GetBounds(nsIntRect &aRect);
451 NS_IMETHOD GetClientBounds(nsIntRect &aRect);
452 NS_IMETHOD GetScreenBounds(nsIntRect &aRect);
454 // Returns the "backing scale factor" of the view's window, which is the
455 // ratio of pixels in the window's backing store to Cocoa points. Prior to
456 // HiDPI support in OS X 10.7, this was always 1.0, but in HiDPI mode it
457 // will be 2.0 (and might potentially other values as screen resolutions
458 // evolve). This gives the relationship between what Gecko calls "device
459 // pixels" and the Cocoa "points" coordinate system.
460 CGFloat BackingScaleFactor() const;
462 // Call if the window's backing scale factor changes - i.e., it is moved
463 // between HiDPI and non-HiDPI screens
464 void BackingScaleFactorChanged();
466 virtual double GetDefaultScaleInternal();
468 virtual int32_t RoundsWidgetCoordinatesTo() MOZ_OVERRIDE;
470 NS_IMETHOD Invalidate(const nsIntRect &aRect);
472 virtual void* GetNativeData(uint32_t aDataType);
473 virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations);
474 virtual nsIntPoint WidgetToScreenOffset();
475 virtual bool ShowsResizeIndicator(nsIntRect* aResizerRect);
477 static bool ConvertStatus(nsEventStatus aStatus)
478 { return aStatus == nsEventStatus_eConsumeNoDefault; }
479 NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent,
480 nsEventStatus& aStatus);
482 virtual bool ComputeShouldAccelerate(bool aDefault);
483 virtual bool ShouldUseOffMainThreadCompositing() MOZ_OVERRIDE;
485 NS_IMETHOD SetCursor(nsCursor aCursor);
486 NS_IMETHOD SetCursor(imgIContainer* aCursor, uint32_t aHotspotX, uint32_t aHotspotY);
488 NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, bool aDoCapture);
489 NS_IMETHOD SetTitle(const nsAString& title);
491 NS_IMETHOD GetAttention(int32_t aCycleCount);
493 virtual bool HasPendingInputEvent();
495 NS_IMETHOD ActivateNativeMenuItemAt(const nsAString& indexString);
496 NS_IMETHOD ForceUpdateNativeMenuAt(const nsAString& indexString);
498 NS_IMETHOD NotifyIME(const IMENotification& aIMENotification) MOZ_OVERRIDE;
499 NS_IMETHOD_(void) SetInputContext(const InputContext& aContext,
500 const InputContextAction& aAction);
501 NS_IMETHOD_(InputContext) GetInputContext();
502 NS_IMETHOD AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent);
503 NS_IMETHOD_(bool) ExecuteNativeKeyBinding(
504 NativeKeyBindingsType aType,
505 const mozilla::WidgetKeyboardEvent& aEvent,
506 DoCommandCallback aCallback,
507 void* aCallbackData) MOZ_OVERRIDE;
508 virtual nsIMEUpdatePreference GetIMEUpdatePreference() MOZ_OVERRIDE;
509 NS_IMETHOD GetToggledKeyState(uint32_t aKeyCode,
510 bool* aLEDState);
512 // nsIPluginWidget
513 // outClipRect and outOrigin are in display pixels (not device pixels)
514 NS_IMETHOD GetPluginClipRect(nsIntRect& outClipRect, nsIntPoint& outOrigin, bool& outWidgetVisible);
515 NS_IMETHOD StartDrawPlugin();
516 NS_IMETHOD EndDrawPlugin();
517 NS_IMETHOD SetPluginInstanceOwner(nsIPluginInstanceOwner* aInstanceOwner);
519 NS_IMETHOD SetPluginEventModel(int inEventModel);
520 NS_IMETHOD GetPluginEventModel(int* outEventModel);
521 NS_IMETHOD SetPluginDrawingModel(int inDrawingModel);
523 NS_IMETHOD StartComplexTextInputForCurrentEvent();
525 virtual nsTransparencyMode GetTransparencyMode();
526 virtual void SetTransparencyMode(nsTransparencyMode aMode);
528 virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
529 int32_t aNativeKeyCode,
530 uint32_t aModifierFlags,
531 const nsAString& aCharacters,
532 const nsAString& aUnmodifiedCharacters);
534 virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint,
535 uint32_t aNativeMessage,
536 uint32_t aModifierFlags);
538 virtual nsresult SynthesizeNativeMouseMove(nsIntPoint aPoint)
539 { return SynthesizeNativeMouseEvent(aPoint, NSMouseMoved, 0); }
541 // Mac specific methods
543 virtual bool DispatchWindowEvent(mozilla::WidgetGUIEvent& event);
545 void WillPaintWindow();
546 bool PaintWindow(nsIntRegion aRegion);
548 #ifdef ACCESSIBILITY
549 already_AddRefed<mozilla::a11y::Accessible> GetDocumentAccessible();
550 #endif
552 virtual CompositorParent* NewCompositorParent(int aSurfaceWidth, int aSurfaceHeight);
553 virtual void CreateCompositor();
554 virtual void PrepareWindowEffects() MOZ_OVERRIDE;
555 virtual void CleanupWindowEffects() MOZ_OVERRIDE;
556 virtual bool PreRender(LayerManagerComposite* aManager) MOZ_OVERRIDE;
557 virtual void PostRender(LayerManagerComposite* aManager) MOZ_OVERRIDE;
558 virtual void DrawWindowOverlay(LayerManagerComposite* aManager, nsIntRect aRect) MOZ_OVERRIDE;
560 virtual void UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries);
562 void HidePlugin();
563 void UpdatePluginPort();
565 void ResetParent();
567 static bool DoHasPendingInputEvent();
568 static uint32_t GetCurrentInputEventCount();
569 static void UpdateCurrentInputEventCount();
571 NSView<mozView>* GetEditorView();
573 bool IsPluginView() { return (mWindowType == eWindowType_plugin); }
575 nsCocoaWindow* GetXULWindowWidget();
577 NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent);
579 mozilla::widget::TextInputHandler* GetTextInputHandler()
581 return mTextInputHandler;
584 void NotifyDirtyRegion(const nsIntRegion& aDirtyRegion);
585 void ClearVibrantAreas();
586 NSColor* VibrancyFillColorForWidgetType(uint8_t aWidgetType);
588 // unit conversion convenience functions
589 int32_t CocoaPointsToDevPixels(CGFloat aPts) const {
590 return nsCocoaUtils::CocoaPointsToDevPixels(aPts, BackingScaleFactor());
592 nsIntPoint CocoaPointsToDevPixels(const NSPoint& aPt) const {
593 return nsCocoaUtils::CocoaPointsToDevPixels(aPt, BackingScaleFactor());
595 nsIntRect CocoaPointsToDevPixels(const NSRect& aRect) const {
596 return nsCocoaUtils::CocoaPointsToDevPixels(aRect, BackingScaleFactor());
598 CGFloat DevPixelsToCocoaPoints(int32_t aPixels) const {
599 return nsCocoaUtils::DevPixelsToCocoaPoints(aPixels, BackingScaleFactor());
601 NSRect DevPixelsToCocoaPoints(const nsIntRect& aRect) const {
602 return nsCocoaUtils::DevPixelsToCocoaPoints(aRect, BackingScaleFactor());
605 mozilla::TemporaryRef<mozilla::gfx::DrawTarget> StartRemoteDrawing() MOZ_OVERRIDE;
606 void EndRemoteDrawing() MOZ_OVERRIDE;
607 void CleanupRemoteDrawing() MOZ_OVERRIDE;
609 APZCTreeManager* APZCTM() { return mAPZCTreeManager; }
611 protected:
612 virtual ~nsChildView();
614 void ReportMoveEvent();
615 void ReportSizeEvent();
617 // override to create different kinds of child views. Autoreleases, so
618 // caller must retain.
619 virtual NSView* CreateCocoaView(NSRect inFrame);
620 void TearDownView();
622 virtual already_AddRefed<nsIWidget>
623 AllocateChildPopupWidget()
625 static NS_DEFINE_IID(kCPopUpCID, NS_POPUP_CID);
626 nsCOMPtr<nsIWidget> widget = do_CreateInstance(kCPopUpCID);
627 return widget.forget();
630 void DoRemoteComposition(const nsIntRect& aRenderRect);
632 // Overlay drawing functions for OpenGL drawing
633 void DrawWindowOverlay(mozilla::layers::GLManager* aManager, nsIntRect aRect);
634 void MaybeDrawResizeIndicator(mozilla::layers::GLManager* aManager, const nsIntRect& aRect);
635 void MaybeDrawRoundedCorners(mozilla::layers::GLManager* aManager, const nsIntRect& aRect);
636 void MaybeDrawTitlebar(mozilla::layers::GLManager* aManager, const nsIntRect& aRect);
638 // Redraw the contents of mTitlebarCGContext on the main thread, as
639 // determined by mDirtyTitlebarRegion.
640 void UpdateTitlebarCGContext();
642 nsIntRect RectContainingTitlebarControls();
643 void UpdateVibrancy(const nsTArray<ThemeGeometry>& aThemeGeometries);
644 mozilla::VibrancyManager& EnsureVibrancyManager();
646 nsIWidget* GetWidgetForListenerEvents();
648 protected:
650 NSView<mozView>* mView; // my parallel cocoa view (ChildView or NativeScrollbarView), [STRONG]
651 nsRefPtr<mozilla::widget::TextInputHandler> mTextInputHandler;
652 InputContext mInputContext;
654 NSView<mozView>* mParentView;
655 nsIWidget* mParentWidget;
657 #ifdef ACCESSIBILITY
658 // weak ref to this childview's associated mozAccessible for speed reasons
659 // (we get queried for it *a lot* but don't want to own it)
660 nsWeakPtr mAccessible;
661 #endif
663 // Protects the view from being teared down while a composition is in
664 // progress on the compositor thread.
665 mozilla::Mutex mViewTearDownLock;
667 mozilla::Mutex mEffectsLock;
669 // May be accessed from any thread, protected
670 // by mEffectsLock.
671 bool mShowsResizeIndicator;
672 nsIntRect mResizeIndicatorRect;
673 bool mHasRoundedBottomCorners;
674 int mDevPixelCornerRadius;
675 bool mIsCoveringTitlebar;
676 bool mIsFullscreen;
677 nsIntRect mTitlebarRect;
679 // The area of mTitlebarCGContext that needs to be redrawn during the next
680 // transaction. Accessed from any thread, protected by mEffectsLock.
681 nsIntRegion mUpdatedTitlebarRegion;
682 CGContextRef mTitlebarCGContext;
684 // Compositor thread only
685 nsAutoPtr<RectTextureImage> mResizerImage;
686 nsAutoPtr<RectTextureImage> mCornerMaskImage;
687 nsAutoPtr<RectTextureImage> mTitlebarImage;
688 nsAutoPtr<RectTextureImage> mBasicCompositorImage;
690 // The area of mTitlebarCGContext that has changed and needs to be
691 // uploaded to to mTitlebarImage. Main thread only.
692 nsIntRegion mDirtyTitlebarRegion;
694 // Cached value of [mView backingScaleFactor], to avoid sending two obj-c
695 // messages (respondsToSelector, backingScaleFactor) every time we need to
696 // use it.
697 // ** We'll need to reinitialize this if the backing resolution changes. **
698 mutable CGFloat mBackingScaleFactor;
700 bool mVisible;
701 bool mDrawing;
702 bool mPluginDrawing;
703 bool mIsDispatchPaint; // Is a paint event being dispatched
705 NP_CGContext mPluginCGContext;
706 nsIPluginInstanceOwner* mPluginInstanceOwner; // [WEAK]
708 // Used in OMTC BasicLayers mode. Presents the BasicCompositor result
709 // surface to the screen using an OpenGL context.
710 nsAutoPtr<GLPresenter> mGLPresenter;
712 nsRefPtr<APZCTreeManager> mAPZCTreeManager;
714 mozilla::UniquePtr<mozilla::VibrancyManager> mVibrancyManager;
716 static uint32_t sLastInputEventCount;
718 void ReleaseTitlebarCGContext();
721 void NS_InstallPluginKeyEventsHandler();
722 void NS_RemovePluginKeyEventsHandler();
724 #endif // nsChildView_h_