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/. */
5 
6 #ifndef nsChildView_h_
7 #define nsChildView_h_
8 
9 // formal protocols
10 #include "mozView.h"
11 #ifdef ACCESSIBILITY
12 #include "mozilla/a11y/Accessible.h"
13 #include "mozAccessibleProtocol.h"
14 #endif
15 
16 #include "nsISupports.h"
17 #include "nsBaseWidget.h"
18 #include "nsWeakPtr.h"
19 #include "TextInputHandler.h"
20 #include "nsCocoaUtils.h"
21 #include "gfxQuartzSurface.h"
22 #include "GLContextTypes.h"
23 #include "mozilla/Mutex.h"
24 #include "nsRegion.h"
25 #include "mozilla/MouseEvents.h"
26 #include "mozilla/UniquePtr.h"
27 
28 #include "nsString.h"
29 #include "nsIDragService.h"
30 #include "ViewRegion.h"
31 
32 #import <Carbon/Carbon.h>
33 #import <Cocoa/Cocoa.h>
34 #import <AppKit/NSOpenGL.h>
35 
36 class nsChildView;
37 class nsCocoaWindow;
38 
39 namespace {
40 class GLPresenter;
41 } // namespace
42 
43 namespace mozilla {
44 class InputData;
45 class PanGestureInput;
46 class SwipeTracker;
47 struct SwipeEventQueue;
48 class VibrancyManager;
49 namespace layers {
50 class GLManager;
51 class IAPZCTreeManager;
52 } // namespace layers
53 namespace widget {
54 class RectTextureImage;
55 class WidgetRenderingContext;
56 } // namespace widget
57 } // namespace mozilla
58 
59 @interface NSEvent (Undocumented)
60 
61 // Return Cocoa event's corresponding Carbon event.  Not initialized (on
62 // synthetic events) until the OS actually "sends" the event.  This method
63 // has been present in the same form since at least OS X 10.2.8.
64 - (EventRef)_eventRef;
65 
66 @end
67 
68 @interface NSView (Undocumented)
69 
70 // Draws the title string of a window.
71 // Present on NSThemeFrame since at least 10.6.
72 // _drawTitleBar is somewhat complex, and has changed over the years
73 // since OS X 10.6.  But in that time it's never done anything that
74 // would break when called outside of -[NSView drawRect:] (which we
75 // sometimes do), or whose output can't be redirected to a
76 // CGContextRef object (which we also sometimes do).  This is likely
77 // to remain true for the indefinite future.  However we should
78 // check _drawTitleBar in each new major version of OS X.  For more
79 // information see bug 877767.
80 - (void)_drawTitleBar:(NSRect)aRect;
81 
82 // Returns an NSRect that is the bounding box for all an NSView's dirty
83 // rectangles (ones that need to be redrawn).  The full list of dirty
84 // rectangles can be obtained by calling -[NSView _dirtyRegion] and then
85 // calling -[NSRegion getRects:count:] on what it returns.  Both these
86 // methods have been present in the same form since at least OS X 10.5.
87 // Unlike -[NSView getRectsBeingDrawn:count:], these methods can be called
88 // outside a call to -[NSView drawRect:].
89 - (NSRect)_dirtyRect;
90 
91 // Undocumented method of one or more of NSFrameView's subclasses.  Called
92 // when one or more of the titlebar buttons needs to be repositioned, to
93 // disappear, or to reappear (say if the window's style changes).  If
94 // 'redisplay' is true, the entire titlebar (the window's top 22 pixels) is
95 // marked as needing redisplay.  This method has been present in the same
96 // format since at least OS X 10.5.
97 - (void)_tileTitlebarAndRedisplay:(BOOL)redisplay;
98 
99 // The following undocumented methods are used to work around bug 1069658,
100 // which is an Apple bug or design flaw that effects Yosemite.  None of them
101 // were present prior to Yosemite (OS X 10.10).
102 - (NSView *)titlebarView; // Method of NSThemeFrame
103 - (NSView *)titlebarContainerView; // Method of NSThemeFrame
104 - (BOOL)transparent; // Method of NSTitlebarView and NSTitlebarContainerView
105 - (void)setTransparent:(BOOL)transparent; // Method of NSTitlebarView and
106                                           // NSTitlebarContainerView
107 
108 @end
109 
110 @interface ChildView : NSView<
111 #ifdef ACCESSIBILITY
112                               mozAccessible,
113 #endif
114                               mozView, NSTextInputClient>
115 {
116 @private
117   // the nsChildView that created the view. It retains this NSView, so
118   // the link back to it must be weak.
119   nsChildView* mGeckoChild;
120 
121   // Text input handler for mGeckoChild and us.  Note that this is a weak
122   // reference.  Ideally, this should be a strong reference but a ChildView
123   // object can live longer than the mGeckoChild that owns it.  And if
124   // mTextInputHandler were a strong reference, this would make it difficult
125   // for Gecko's leak detector to detect leaked TextInputHandler objects.
126   // This is initialized by [mozView installTextInputHandler:aHandler] and
127   // cleared by [mozView uninstallTextInputHandler].
128   mozilla::widget::TextInputHandler* mTextInputHandler;  // [WEAK]
129 
130   // when mouseDown: is called, we store its event here (strong)
131   NSEvent* mLastMouseDownEvent;
132 
133   // Needed for IME support in e10s mode.  Strong.
134   NSEvent* mLastKeyDownEvent;
135 
136   // Whether the last mouse down event was blocked from Gecko.
137   BOOL mBlockedLastMouseDown;
138 
139   // when acceptsFirstMouse: is called, we store the event here (strong)
140   NSEvent* mClickThroughMouseDownEvent;
141 
142   // rects that were invalidated during a draw, so have pending drawing
143   NSMutableArray* mPendingDirtyRects;
144   BOOL mPendingFullDisplay;
145   BOOL mPendingDisplay;
146 
147   // WheelStart/Stop events should always come in pairs. This BOOL records the
148   // last received event so that, when we receive one of the events, we make sure
149   // to send its pair event first, in case we didn't yet for any reason.
150   BOOL mExpectingWheelStop;
151 
152   // Set to YES when our GL surface has been updated and we need to call
153   // updateGLContext before we composite.
154   BOOL mNeedsGLUpdate;
155 
156   // Holds our drag service across multiple drag calls. The reference to the
157   // service is obtained when the mouse enters the view and is released when
158   // the mouse exits or there is a drop. This prevents us from having to
159   // re-establish the connection to the service manager many times per second
160   // when handling |draggingUpdated:| messages.
161   nsIDragService* mDragService;
162 
163   NSOpenGLContext *mGLContext;
164 
165   // Simple gestures support
166   //
167   // mGestureState is used to detect when Cocoa has called both
168   // magnifyWithEvent and rotateWithEvent within the same
169   // beginGestureWithEvent and endGestureWithEvent sequence. We
170   // discard the spurious gesture event so as not to confuse Gecko.
171   //
172   // mCumulativeMagnification keeps track of the total amount of
173   // magnification peformed during a magnify gesture so that we can
174   // send that value with the final MozMagnifyGesture event.
175   //
176   // mCumulativeRotation keeps track of the total amount of rotation
177   // performed during a rotate gesture so we can send that value with
178   // the final MozRotateGesture event.
179   enum {
180     eGestureState_None,
181     eGestureState_StartGesture,
182     eGestureState_MagnifyGesture,
183     eGestureState_RotateGesture
184   } mGestureState;
185   float mCumulativeMagnification;
186   float mCumulativeRotation;
187 
188   BOOL mWaitingForPaint;
189 
190 #ifdef __LP64__
191   // Support for fluid swipe tracking.
192   BOOL* mCancelSwipeAnimation;
193 #endif
194 
195   // Whether this uses off-main-thread compositing.
196   BOOL mUsingOMTCompositor;
197 
198   // The mask image that's used when painting into the titlebar using basic
199   // CGContext painting (i.e. non-accelerated).
200   CGImageRef mTopLeftCornerMask;
201 }
202 
203 // class initialization
204 + (void)initialize;
205 
206 + (void)registerViewForDraggedTypes:(NSView*)aView;
207 
208 // these are sent to the first responder when the window key status changes
209 - (void)viewsWindowDidBecomeKey;
210 - (void)viewsWindowDidResignKey;
211 
212 // Stop NSView hierarchy being changed during [ChildView drawRect:]
213 - (void)delayedTearDown;
214 
215 - (void)sendFocusEvent:(mozilla::EventMessage)eventMessage;
216 
217 - (void)handleMouseMoved:(NSEvent*)aEvent;
218 
219 - (void)sendMouseEnterOrExitEvent:(NSEvent*)aEvent
220                             enter:(BOOL)aEnter
221                          exitFrom:(mozilla::WidgetMouseEvent::ExitFrom)aExitFrom;
222 
223 - (void)updateGLContext;
224 - (void)_surfaceNeedsUpdate:(NSNotification*)notification;
225 
226 - (bool)preRender:(NSOpenGLContext *)aGLContext;
227 - (void)postRender:(NSOpenGLContext *)aGLContext;
228 
229 - (BOOL)isCoveringTitlebar;
230 
231 - (void)viewWillStartLiveResize;
232 - (void)viewDidEndLiveResize;
233 
234 - (NSColor*)vibrancyFillColorForThemeGeometryType:(nsITheme::ThemeGeometryType)aThemeGeometryType;
235 - (NSColor*)vibrancyFontSmoothingBackgroundColorForThemeGeometryType:(nsITheme::ThemeGeometryType)aThemeGeometryType;
236 
237 // Simple gestures support
238 //
239 // XXX - The swipeWithEvent, beginGestureWithEvent, magnifyWithEvent,
240 // rotateWithEvent, and endGestureWithEvent methods are part of a
241 // PRIVATE interface exported by nsResponder and reverse-engineering
242 // was necessary to obtain the methods' prototypes. Thus, Apple may
243 // change the interface in the future without notice.
244 //
245 // The prototypes were obtained from the following link:
246 // http://cocoadex.com/2008/02/nsevent-modifications-swipe-ro.html
247 - (void)swipeWithEvent:(NSEvent *)anEvent;
248 - (void)beginGestureWithEvent:(NSEvent *)anEvent;
249 - (void)magnifyWithEvent:(NSEvent *)anEvent;
250 - (void)smartMagnifyWithEvent:(NSEvent *)anEvent;
251 - (void)rotateWithEvent:(NSEvent *)anEvent;
252 - (void)endGestureWithEvent:(NSEvent *)anEvent;
253 
254 - (void)scrollWheel:(NSEvent *)anEvent;
255 - (void)handleAsyncScrollEvent:(CGEventRef)cgEvent ofType:(CGEventType)type;
256 
257 - (void)setUsingOMTCompositor:(BOOL)aUseOMTC;
258 
259 - (NSEvent*)lastKeyDownEvent;
260 @end
261 
262 class ChildViewMouseTracker {
263 
264 public:
265 
266   static void MouseMoved(NSEvent* aEvent);
267   static void MouseScrolled(NSEvent* aEvent);
268   static void OnDestroyView(ChildView* aView);
269   static void OnDestroyWindow(NSWindow* aWindow);
270   static BOOL WindowAcceptsEvent(NSWindow* aWindow, NSEvent* aEvent,
271                                  ChildView* aView, BOOL isClickThrough = NO);
272   static void MouseExitedWindow(NSEvent* aEvent);
273   static void MouseEnteredWindow(NSEvent* aEvent);
274   static void ReEvaluateMouseEnterState(NSEvent* aEvent = nil, ChildView* aOldView = nil);
275   static void ResendLastMouseMoveEvent();
276   static ChildView* ViewForEvent(NSEvent* aEvent);
277 
278   static ChildView* sLastMouseEventView;
279   static NSEvent* sLastMouseMoveEvent;
280   static NSWindow* sWindowUnderMouse;
281   static NSPoint sLastScrollEventScreenLocation;
282 };
283 
284 //-------------------------------------------------------------------------
285 //
286 // nsChildView
287 //
288 //-------------------------------------------------------------------------
289 
290 class nsChildView : public nsBaseWidget
291 {
292 private:
293   typedef nsBaseWidget Inherited;
294   typedef mozilla::layers::IAPZCTreeManager IAPZCTreeManager;
295 
296 public:
297   nsChildView();
298 
299   // nsIWidget interface
300   virtual MOZ_MUST_USE nsresult Create(nsIWidget* aParent,
301                                        nsNativeWidget aNativeParent,
302                                        const LayoutDeviceIntRect& aRect,
303                                        nsWidgetInitData* aInitData = nullptr)
304                                        override;
305 
306   virtual void            Destroy() override;
307 
308   NS_IMETHOD              Show(bool aState) override;
309   virtual bool            IsVisible() const override;
310 
311   NS_IMETHOD              SetParent(nsIWidget* aNewParent) override;
312   virtual nsIWidget*      GetParent(void) override;
313   virtual float           GetDPI() override;
314 
315   NS_IMETHOD              Move(double aX, double aY) override;
316   NS_IMETHOD              Resize(double aWidth, double aHeight, bool aRepaint) override;
317   NS_IMETHOD              Resize(double aX, double aY,
318                                  double aWidth, double aHeight, bool aRepaint) override;
319 
320   NS_IMETHOD              Enable(bool aState) override;
321   virtual bool            IsEnabled() const override;
322   NS_IMETHOD              SetFocus(bool aRaise) override;
323   virtual LayoutDeviceIntRect GetBounds() override;
324   virtual LayoutDeviceIntRect GetClientBounds() override;
325   virtual LayoutDeviceIntRect GetScreenBounds() override;
326 
327   // Returns the "backing scale factor" of the view's window, which is the
328   // ratio of pixels in the window's backing store to Cocoa points. Prior to
329   // HiDPI support in OS X 10.7, this was always 1.0, but in HiDPI mode it
330   // will be 2.0 (and might potentially other values as screen resolutions
331   // evolve). This gives the relationship between what Gecko calls "device
332   // pixels" and the Cocoa "points" coordinate system.
333   CGFloat                 BackingScaleFactor() const;
334 
GetDesktopToDeviceScale()335   mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() final {
336     return mozilla::DesktopToLayoutDeviceScale(BackingScaleFactor());
337   }
338 
339   // Call if the window's backing scale factor changes - i.e., it is moved
340   // between HiDPI and non-HiDPI screens
341   void                    BackingScaleFactorChanged();
342 
343   virtual double          GetDefaultScaleInternal() override;
344 
345   virtual int32_t         RoundsWidgetCoordinatesTo() override;
346 
347   NS_IMETHOD              Invalidate(const LayoutDeviceIntRect &aRect) override;
348 
349   virtual void*           GetNativeData(uint32_t aDataType) override;
350   virtual nsresult        ConfigureChildren(const nsTArray<Configuration>& aConfigurations) override;
351   virtual LayoutDeviceIntPoint WidgetToScreenOffset() override;
352   virtual bool            ShowsResizeIndicator(LayoutDeviceIntRect* aResizerRect) override;
353 
ConvertStatus(nsEventStatus aStatus)354   static  bool            ConvertStatus(nsEventStatus aStatus)
355                           { return aStatus == nsEventStatus_eConsumeNoDefault; }
356   NS_IMETHOD              DispatchEvent(mozilla::WidgetGUIEvent* aEvent,
357                                         nsEventStatus& aStatus) override;
358 
359   virtual bool            WidgetTypeSupportsAcceleration() override;
360   virtual bool            ShouldUseOffMainThreadCompositing() override;
361 
362   NS_IMETHOD        SetCursor(nsCursor aCursor) override;
363   NS_IMETHOD        SetCursor(imgIContainer* aCursor, uint32_t aHotspotX, uint32_t aHotspotY) override;
364 
365   NS_IMETHOD        SetTitle(const nsAString& title) override;
366 
367   NS_IMETHOD        GetAttention(int32_t aCycleCount) override;
368 
369   virtual bool HasPendingInputEvent() override;
370 
371   NS_IMETHOD        ActivateNativeMenuItemAt(const nsAString& indexString) override;
372   NS_IMETHOD        ForceUpdateNativeMenuAt(const nsAString& indexString) override;
373   NS_IMETHOD        GetSelectionAsPlaintext(nsAString& aResult) override;
374 
375   NS_IMETHOD_(void) SetInputContext(const InputContext& aContext,
376                                     const InputContextAction& aAction) override;
377   NS_IMETHOD_(InputContext) GetInputContext() override;
378   NS_IMETHOD_(TextEventDispatcherListener*)
379     GetNativeTextEventDispatcherListener() override;
380   NS_IMETHOD        AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent) override;
381   NS_IMETHOD_(bool) ExecuteNativeKeyBinding(
382                       NativeKeyBindingsType aType,
383                       const mozilla::WidgetKeyboardEvent& aEvent,
384                       DoCommandCallback aCallback,
385                       void* aCallbackData) override;
386   bool ExecuteNativeKeyBindingRemapped(
387                       NativeKeyBindingsType aType,
388                       const mozilla::WidgetKeyboardEvent& aEvent,
389                       DoCommandCallback aCallback,
390                       void* aCallbackData,
391                       uint32_t aGeckoKeyCode,
392                       uint32_t aCocoaKeyCode);
393   virtual nsIMEUpdatePreference GetIMEUpdatePreference() override;
394 
395   virtual nsTransparencyMode GetTransparencyMode() override;
396   virtual void                SetTransparencyMode(nsTransparencyMode aMode) override;
397 
398   virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
399                                             int32_t aNativeKeyCode,
400                                             uint32_t aModifierFlags,
401                                             const nsAString& aCharacters,
402                                             const nsAString& aUnmodifiedCharacters,
403                                             nsIObserver* aObserver) override;
404 
405   virtual nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
406                                               uint32_t aNativeMessage,
407                                               uint32_t aModifierFlags,
408                                               nsIObserver* aObserver) override;
409 
SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,nsIObserver * aObserver)410   virtual nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
411                                              nsIObserver* aObserver) override
412   { return SynthesizeNativeMouseEvent(aPoint, NSMouseMoved, 0, aObserver); }
413   virtual nsresult SynthesizeNativeMouseScrollEvent(LayoutDeviceIntPoint aPoint,
414                                                     uint32_t aNativeMessage,
415                                                     double aDeltaX,
416                                                     double aDeltaY,
417                                                     double aDeltaZ,
418                                                     uint32_t aModifierFlags,
419                                                     uint32_t aAdditionalFlags,
420                                                     nsIObserver* aObserver) override;
421   virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
422                                               TouchPointerState aPointerState,
423                                               LayoutDeviceIntPoint aPoint,
424                                               double aPointerPressure,
425                                               uint32_t aPointerOrientation,
426                                               nsIObserver* aObserver) override;
427 
428   // Mac specific methods
429 
430   virtual bool      DispatchWindowEvent(mozilla::WidgetGUIEvent& event);
431 
432   void WillPaintWindow();
433   bool PaintWindow(LayoutDeviceIntRegion aRegion);
434   bool PaintWindowInContext(CGContextRef aContext, const LayoutDeviceIntRegion& aRegion,
435                             mozilla::gfx::IntSize aSurfaceSize);
436 
437 #ifdef ACCESSIBILITY
438   already_AddRefed<mozilla::a11y::Accessible> GetDocumentAccessible();
439 #endif
440 
441   virtual void CreateCompositor() override;
442   virtual void PrepareWindowEffects() override;
443   virtual void CleanupWindowEffects() override;
444   virtual bool PreRender(mozilla::widget::WidgetRenderingContext* aContext) override;
445   virtual void PostRender(mozilla::widget::WidgetRenderingContext* aContext) override;
446   virtual void DrawWindowOverlay(mozilla::widget::WidgetRenderingContext* aManager,
447                                  LayoutDeviceIntRect aRect) override;
448 
449   virtual void UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries) override;
450 
451   virtual void UpdateWindowDraggingRegion(const LayoutDeviceIntRegion& aRegion) override;
GetNonDraggableRegion()452   LayoutDeviceIntRegion GetNonDraggableRegion() { return mNonDraggableRegion.Region(); }
453 
454   virtual void ReportSwipeStarted(uint64_t aInputBlockId, bool aStartSwipe) override;
455 
456   virtual void LookUpDictionary(
457                  const nsAString& aText,
458                  const nsTArray<mozilla::FontRange>& aFontRangeArray,
459                  const bool aIsVertical,
460                  const LayoutDeviceIntPoint& aPoint) override;
461 
462   void              ResetParent();
463 
464   static bool DoHasPendingInputEvent();
465   static uint32_t GetCurrentInputEventCount();
466   static void UpdateCurrentInputEventCount();
467 
468   NSView<mozView>* GetEditorView();
469 
470   nsCocoaWindow*    GetXULWindowWidget();
471 
472   virtual void      ReparentNativeWidget(nsIWidget* aNewParent) override;
473 
GetTextInputHandler()474   mozilla::widget::TextInputHandler* GetTextInputHandler()
475   {
476     return mTextInputHandler;
477   }
478 
479   void              ClearVibrantAreas();
480   NSColor*          VibrancyFillColorForThemeGeometryType(nsITheme::ThemeGeometryType aThemeGeometryType);
481   NSColor*          VibrancyFontSmoothingBackgroundColorForThemeGeometryType(nsITheme::ThemeGeometryType aThemeGeometryType);
482 
483   // unit conversion convenience functions
CocoaPointsToDevPixels(CGFloat aPts)484   int32_t           CocoaPointsToDevPixels(CGFloat aPts) const {
485     return nsCocoaUtils::CocoaPointsToDevPixels(aPts, BackingScaleFactor());
486   }
CocoaPointsToDevPixels(const NSPoint & aPt)487   LayoutDeviceIntPoint CocoaPointsToDevPixels(const NSPoint& aPt) const {
488     return nsCocoaUtils::CocoaPointsToDevPixels(aPt, BackingScaleFactor());
489   }
CocoaPointsToDevPixelsRoundDown(const NSPoint & aPt)490   LayoutDeviceIntPoint CocoaPointsToDevPixelsRoundDown(const NSPoint& aPt) const {
491     return nsCocoaUtils::CocoaPointsToDevPixelsRoundDown(aPt, BackingScaleFactor());
492   }
CocoaPointsToDevPixels(const NSRect & aRect)493   LayoutDeviceIntRect CocoaPointsToDevPixels(const NSRect& aRect) const {
494     return nsCocoaUtils::CocoaPointsToDevPixels(aRect, BackingScaleFactor());
495   }
DevPixelsToCocoaPoints(int32_t aPixels)496   CGFloat           DevPixelsToCocoaPoints(int32_t aPixels) const {
497     return nsCocoaUtils::DevPixelsToCocoaPoints(aPixels, BackingScaleFactor());
498   }
DevPixelsToCocoaPoints(const LayoutDeviceIntRect & aRect)499   NSRect            DevPixelsToCocoaPoints(const LayoutDeviceIntRect& aRect) const {
500     return nsCocoaUtils::DevPixelsToCocoaPoints(aRect, BackingScaleFactor());
501   }
502 
503   already_AddRefed<mozilla::gfx::DrawTarget>
504     StartRemoteDrawingInRegion(LayoutDeviceIntRegion& aInvalidRegion,
505                                mozilla::layers::BufferMode* aBufferMode) override;
506   void EndRemoteDrawing() override;
507   void CleanupRemoteDrawing() override;
508   bool InitCompositor(mozilla::layers::Compositor* aCompositor) override;
509 
APZCTM()510   IAPZCTreeManager* APZCTM() { return mAPZC ; }
511 
512   NS_IMETHOD StartPluginIME(const mozilla::WidgetKeyboardEvent& aKeyboardEvent,
513                             int32_t aPanelX, int32_t aPanelY,
514                             nsString& aCommitted) override;
515 
516   virtual void SetPluginFocused(bool& aFocused) override;
517 
IsPluginFocused()518   bool IsPluginFocused() { return mPluginFocused; }
519 
520   virtual LayoutDeviceIntPoint GetClientOffset() override;
521 
522   void DispatchAPZWheelInputEvent(mozilla::InputData& aEvent, bool aCanTriggerSwipe);
523 
524   void SwipeFinished();
525 
526 protected:
527   virtual ~nsChildView();
528 
529   void              ReportMoveEvent();
530   void              ReportSizeEvent();
531 
532   // override to create different kinds of child views. Autoreleases, so
533   // caller must retain.
534   virtual NSView*   CreateCocoaView(NSRect inFrame);
535   void              TearDownView();
536 
537   virtual already_AddRefed<nsIWidget>
AllocateChildPopupWidget()538   AllocateChildPopupWidget() override
539   {
540     static NS_DEFINE_IID(kCPopUpCID, NS_POPUP_CID);
541     nsCOMPtr<nsIWidget> widget = do_CreateInstance(kCPopUpCID);
542     return widget.forget();
543   }
544 
545   void ConfigureAPZCTreeManager() override;
546   void ConfigureAPZControllerThread() override;
547 
548   void DoRemoteComposition(const LayoutDeviceIntRect& aRenderRect);
549 
550   // Overlay drawing functions for OpenGL drawing
551   void DrawWindowOverlay(mozilla::layers::GLManager* aManager, LayoutDeviceIntRect aRect);
552   void MaybeDrawResizeIndicator(mozilla::layers::GLManager* aManager);
553   void MaybeDrawRoundedCorners(mozilla::layers::GLManager* aManager, const LayoutDeviceIntRect& aRect);
554   void MaybeDrawTitlebar(mozilla::layers::GLManager* aManager);
555 
556   // Redraw the contents of mTitlebarCGContext on the main thread, as
557   // determined by mDirtyTitlebarRegion.
558   void UpdateTitlebarCGContext();
559 
560   LayoutDeviceIntRect RectContainingTitlebarControls();
561   void UpdateVibrancy(const nsTArray<ThemeGeometry>& aThemeGeometries);
562   mozilla::VibrancyManager& EnsureVibrancyManager();
563 
564   nsIWidget* GetWidgetForListenerEvents();
565 
566   struct SwipeInfo {
567     bool wantsSwipe;
568     uint32_t allowedDirections;
569   };
570 
571   SwipeInfo SendMayStartSwipe(const mozilla::PanGestureInput& aSwipeStartEvent);
572   void TrackScrollEventAsSwipe(const mozilla::PanGestureInput& aSwipeStartEvent,
573                                uint32_t aAllowedDirections);
574 
575 protected:
576 
577   NSView<mozView>*      mView;      // my parallel cocoa view (ChildView or NativeScrollbarView), [STRONG]
578   RefPtr<mozilla::widget::TextInputHandler> mTextInputHandler;
579   InputContext          mInputContext;
580 
581   NSView<mozView>*      mParentView;
582   nsIWidget*            mParentWidget;
583 
584 #ifdef ACCESSIBILITY
585   // weak ref to this childview's associated mozAccessible for speed reasons
586   // (we get queried for it *a lot* but don't want to own it)
587   nsWeakPtr             mAccessible;
588 #endif
589 
590   // Protects the view from being teared down while a composition is in
591   // progress on the compositor thread.
592   mozilla::Mutex mViewTearDownLock;
593 
594   mozilla::Mutex mEffectsLock;
595 
596   // May be accessed from any thread, protected
597   // by mEffectsLock.
598   bool mShowsResizeIndicator;
599   LayoutDeviceIntRect mResizeIndicatorRect;
600   bool mHasRoundedBottomCorners;
601   int mDevPixelCornerRadius;
602   bool mIsCoveringTitlebar;
603   bool mIsFullscreen;
604   bool mIsOpaque;
605   LayoutDeviceIntRect mTitlebarRect;
606 
607   // The area of mTitlebarCGContext that needs to be redrawn during the next
608   // transaction. Accessed from any thread, protected by mEffectsLock.
609   LayoutDeviceIntRegion mUpdatedTitlebarRegion;
610   CGContextRef mTitlebarCGContext;
611 
612   // Compositor thread only
613   mozilla::UniquePtr<mozilla::widget::RectTextureImage> mResizerImage;
614   mozilla::UniquePtr<mozilla::widget::RectTextureImage> mCornerMaskImage;
615   mozilla::UniquePtr<mozilla::widget::RectTextureImage> mTitlebarImage;
616   mozilla::UniquePtr<mozilla::widget::RectTextureImage> mBasicCompositorImage;
617 
618   // The area of mTitlebarCGContext that has changed and needs to be
619   // uploaded to to mTitlebarImage. Main thread only.
620   nsIntRegion           mDirtyTitlebarRegion;
621 
622   mozilla::ViewRegion   mNonDraggableRegion;
623 
624   // Cached value of [mView backingScaleFactor], to avoid sending two obj-c
625   // messages (respondsToSelector, backingScaleFactor) every time we need to
626   // use it.
627   // ** We'll need to reinitialize this if the backing resolution changes. **
628   mutable CGFloat       mBackingScaleFactor;
629 
630   bool                  mVisible;
631   bool                  mDrawing;
632   bool                  mIsDispatchPaint; // Is a paint event being dispatched
633 
634   bool mPluginFocused;
635 
636   // Used in OMTC BasicLayers mode. Presents the BasicCompositor result
637   // surface to the screen using an OpenGL context.
638   mozilla::UniquePtr<GLPresenter> mGLPresenter;
639 
640   mozilla::UniquePtr<mozilla::VibrancyManager> mVibrancyManager;
641   RefPtr<mozilla::SwipeTracker> mSwipeTracker;
642   mozilla::UniquePtr<mozilla::SwipeEventQueue> mSwipeEventQueue;
643 
644   // Only used for drawRect-based painting in popups.
645   RefPtr<mozilla::gfx::DrawTarget> mBackingSurface;
646 
647   // This flag is only used when APZ is off. It indicates that the current pan
648   // gesture was processed as a swipe. Sometimes the swipe animation can finish
649   // before momentum events of the pan gesture have stopped firing, so this
650   // flag tells us that we shouldn't allow the remaining events to cause
651   // scrolling. It is reset to false once a new gesture starts (as indicated by
652   // a PANGESTURE_(MAY)START event).
653   bool mCurrentPanGestureBelongsToSwipe;
654 
655   static uint32_t sLastInputEventCount;
656 
657   void ReleaseTitlebarCGContext();
658 
659   // This is used by SynthesizeNativeTouchPoint to maintain state between
660   // multiple synthesized points
661   mozilla::UniquePtr<mozilla::MultiTouchInput> mSynthesizedTouchInput;
662 };
663 
664 #endif // nsChildView_h_
665