Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/widget/nsBaseWidget.h
Line
Count
Source (jump to first uncovered line)
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
#ifndef nsBaseWidget_h__
6
#define nsBaseWidget_h__
7
8
#include "InputData.h"
9
#include "mozilla/EventForwards.h"
10
#include "mozilla/Mutex.h"
11
#include "mozilla/RefPtr.h"
12
#include "mozilla/UniquePtr.h"
13
#include "mozilla/WidgetUtils.h"
14
#include "mozilla/layers/APZCCallbackHelper.h"
15
#include "mozilla/layers/CompositorOptions.h"
16
#include "nsRect.h"
17
#include "nsIWidget.h"
18
#include "nsWidgetsCID.h"
19
#include "nsIFile.h"
20
#include "nsString.h"
21
#include "nsCOMPtr.h"
22
#include "nsIRollupListener.h"
23
#include "nsIObserver.h"
24
#include "nsIWidgetListener.h"
25
#include "nsPIDOMWindow.h"
26
#include "nsWeakReference.h"
27
#include <algorithm>
28
29
#if defined(XP_WIN)
30
// Scroll capture constants
31
const uint32_t kScrollCaptureFillColor = 0xFFa0a0a0; // gray
32
const mozilla::gfx::SurfaceFormat kScrollCaptureFormat =
33
  mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32;
34
#endif
35
36
class nsIContent;
37
class gfxContext;
38
39
namespace mozilla {
40
class CompositorVsyncDispatcher;
41
class LiveResizeListener;
42
43
#ifdef ACCESSIBILITY
44
namespace a11y {
45
class Accessible;
46
}
47
#endif
48
49
namespace gfx {
50
class DrawTarget;
51
class SourceSurface;
52
} // namespace gfx
53
54
namespace layers {
55
class BasicLayerManager;
56
class CompositorBridgeChild;
57
class CompositorBridgeParent;
58
class IAPZCTreeManager;
59
class GeckoContentController;
60
class APZEventState;
61
class CompositorSession;
62
class ImageContainer;
63
struct ScrollableLayerGuid;
64
class RemoteCompositorSession;
65
} // namespace layers
66
67
namespace widget {
68
class CompositorWidgetDelegate;
69
class InProcessCompositorWidget;
70
class WidgetRenderingContext;
71
} // namespace widget
72
73
class CompositorVsyncDispatcher;
74
} // namespace mozilla
75
76
namespace base {
77
class Thread;
78
} // namespace base
79
80
// Windows specific constant indicating the maximum number of touch points the
81
// inject api will allow. This also sets the maximum numerical value for touch
82
// ids we can use when injecting touch points on Windows.
83
0
#define TOUCH_INJECT_MAX_POINTS 256
84
85
class nsBaseWidget;
86
87
// Helper class used in shutting down gfx related code.
88
class WidgetShutdownObserver final : public nsIObserver
89
{
90
  ~WidgetShutdownObserver();
91
92
public:
93
  explicit WidgetShutdownObserver(nsBaseWidget* aWidget);
94
95
  NS_DECL_ISUPPORTS
96
  NS_DECL_NSIOBSERVER
97
98
  void Register();
99
  void Unregister();
100
101
  nsBaseWidget *mWidget;
102
  bool mRegistered;
103
};
104
105
/**
106
 * Common widget implementation used as base class for native
107
 * or crossplatform implementations of Widgets.
108
 * All cross-platform behavior that all widgets need to implement
109
 * should be placed in this class.
110
 * (Note: widget implementations are not required to use this
111
 * class, but it gives them a head start.)
112
 */
113
114
class nsBaseWidget : public nsIWidget, public nsSupportsWeakReference
115
{
116
  friend class DispatchWheelEventOnMainThread;
117
  friend class mozilla::widget::InProcessCompositorWidget;
118
  friend class mozilla::layers::RemoteCompositorSession;
119
120
protected:
121
  typedef base::Thread Thread;
122
  typedef mozilla::gfx::DrawTarget DrawTarget;
123
  typedef mozilla::gfx::SourceSurface SourceSurface;
124
  typedef mozilla::layers::BasicLayerManager BasicLayerManager;
125
  typedef mozilla::layers::BufferMode BufferMode;
126
  typedef mozilla::layers::CompositorBridgeChild CompositorBridgeChild;
127
  typedef mozilla::layers::CompositorBridgeParent CompositorBridgeParent;
128
  typedef mozilla::layers::IAPZCTreeManager IAPZCTreeManager;
129
  typedef mozilla::layers::GeckoContentController GeckoContentController;
130
  typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid;
131
  typedef mozilla::layers::APZEventState APZEventState;
132
  typedef mozilla::layers::SetAllowedTouchBehaviorCallback SetAllowedTouchBehaviorCallback;
133
  typedef mozilla::CSSIntRect CSSIntRect;
134
  typedef mozilla::CSSRect CSSRect;
135
  typedef mozilla::ScreenRotation ScreenRotation;
136
  typedef mozilla::widget::CompositorWidgetDelegate CompositorWidgetDelegate;
137
  typedef mozilla::layers::CompositorSession CompositorSession;
138
  typedef mozilla::layers::ImageContainer ImageContainer;
139
140
  virtual ~nsBaseWidget();
141
142
public:
143
  nsBaseWidget();
144
145
  NS_DECL_ISUPPORTS
146
147
  // nsIWidget interface
148
0
  virtual void            CaptureMouse(bool aCapture) override {}
149
  virtual void            CaptureRollupEvents(nsIRollupListener* aListener,
150
0
                                              bool aDoCapture) override {}
151
  virtual nsIWidgetListener*  GetWidgetListener() override;
152
  virtual void            SetWidgetListener(nsIWidgetListener* alistener) override;
153
  virtual void            Destroy() override;
154
0
  virtual void            SetParent(nsIWidget* aNewParent) override {};
155
  virtual nsIWidget*      GetParent(void) override;
156
  virtual nsIWidget*      GetTopLevelWidget() override;
157
  virtual nsIWidget*      GetSheetWindowParent(void) override;
158
  virtual float           GetDPI() override;
159
  virtual void            AddChild(nsIWidget* aChild) override;
160
  virtual void            RemoveChild(nsIWidget* aChild) override;
161
162
  void                    SetZIndex(int32_t aZIndex) override;
163
  virtual void            PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
164
                                      nsIWidget *aWidget, bool aActivate)
165
0
                                      override {}
166
167
  virtual void            SetSizeMode(nsSizeMode aMode) override;
168
  virtual nsSizeMode      SizeMode() override
169
0
  {
170
0
    return mSizeMode;
171
0
  }
172
173
  virtual bool            IsFullyOccluded() const override
174
0
  {
175
0
    return mIsFullyOccluded;
176
0
  }
177
178
  virtual void            SetCursor(nsCursor aCursor) override;
179
  virtual nsresult        SetCursor(imgIContainer* aCursor,
180
                                    uint32_t aHotspotX, uint32_t aHotspotY) override;
181
0
  virtual void            ClearCachedCursor() override { mUpdateCursor = true; }
182
  virtual void            SetTransparencyMode(nsTransparencyMode aMode) override;
183
  virtual nsTransparencyMode GetTransparencyMode() override;
184
  virtual void            GetWindowClipRegion(nsTArray<LayoutDeviceIntRect>* aRects) override;
185
0
  virtual void            SetWindowShadowStyle(int32_t aStyle) override {}
186
0
  virtual void            SetShowsToolbarButton(bool aShow) override {}
187
0
  virtual void            SetShowsFullScreenButton(bool aShow) override {}
188
0
  virtual void            SetWindowAnimationType(WindowAnimationType aType) override {}
189
0
  virtual void            HideWindowChrome(bool aShouldHide) override {}
190
0
  virtual bool PrepareForFullscreenTransition(nsISupports** aData) override { return false; }
191
  virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage,
192
                                           uint16_t aDuration,
193
                                           nsISupports* aData,
194
                                           nsIRunnable* aCallback) override;
195
0
  virtual void CleanupFullscreenTransition() override {};
196
  virtual already_AddRefed<nsIScreen> GetWidgetScreen() override;
197
  virtual nsresult        MakeFullScreen(bool aFullScreen,
198
                                         nsIScreen* aScreen = nullptr) override;
199
  void                    InfallibleMakeFullScreen(bool aFullScreen,
200
                                                   nsIScreen* aScreen = nullptr);
201
202
  virtual LayerManager*   GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr,
203
                                          LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE,
204
                                          LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT) override;
205
206
  // A remote compositor session tied to this window has been lost and IPC
207
  // messages will no longer work. The widget must clean up any lingering
208
  // resources and possibly schedule another paint.
209
  //
210
  // A reference to the session object is held until this function has
211
  // returned.
212
  void NotifyCompositorSessionLost(mozilla::layers::CompositorSession* aSession);
213
214
  already_AddRefed<mozilla::CompositorVsyncDispatcher> GetCompositorVsyncDispatcher();
215
  void            CreateCompositorVsyncDispatcher();
216
  virtual void            CreateCompositor();
217
  virtual void            CreateCompositor(int aWidth, int aHeight);
218
0
  virtual void            SetCompositorWidgetDelegate(CompositorWidgetDelegate* delegate) {}
219
0
  virtual void            PrepareWindowEffects() override {}
220
0
  virtual void            UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries) override {}
221
0
  virtual void            SetModal(bool aModal) override {}
222
  virtual uint32_t        GetMaxTouchPoints() const override;
223
  virtual void            SetWindowClass(const nsAString& xulWinType)
224
0
                            override {}
225
  virtual nsresult        SetWindowClipRegion(const nsTArray<LayoutDeviceIntRect>& aRects, bool aIntersectWithExisting) override;
226
  // Return whether this widget interprets parameters to Move and Resize APIs
227
  // as "desktop pixels" rather than "device pixels", and therefore
228
  // applies its GetDefaultScale() value to them before using them as mBounds
229
  // etc (which are always stored in device pixels).
230
  // Note that APIs that -get- the widget's position/size/bounds, rather than
231
  // -setting- them (i.e. moving or resizing the widget) will always return
232
  // values in the widget's device pixels.
233
0
  bool                    BoundsUseDesktopPixels() const {
234
0
    return mWindowType <= eWindowType_popup;
235
0
  }
236
  // Default implementation, to be overridden by platforms where desktop coords
237
  // are virtualized and may not correspond to device pixels on the screen.
238
0
  mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() override {
239
0
    return mozilla::DesktopToLayoutDeviceScale(1.0);
240
0
  }
241
  virtual void            ConstrainPosition(bool aAllowSlop,
242
                                            int32_t *aX,
243
0
                                            int32_t *aY) override {}
244
  virtual void            MoveClient(double aX, double aY) override;
245
  virtual void            ResizeClient(double aWidth, double aHeight, bool aRepaint) override;
246
  virtual void            ResizeClient(double aX, double aY, double aWidth, double aHeight, bool aRepaint) override;
247
  virtual LayoutDeviceIntRect GetBounds() override;
248
  virtual LayoutDeviceIntRect GetClientBounds() override;
249
  virtual LayoutDeviceIntRect GetScreenBounds() override;
250
  virtual MOZ_MUST_USE nsresult GetRestoredBounds(LayoutDeviceIntRect& aRect) override;
251
  virtual nsresult        SetNonClientMargins(LayoutDeviceIntMargin& aMargins) override;
252
  virtual LayoutDeviceIntPoint GetClientOffset() override;
253
0
  virtual void            EnableDragDrop(bool aEnable) override {};
254
  virtual nsresult        AsyncEnableDragDrop(bool aEnable) override;
255
  virtual MOZ_MUST_USE nsresult
256
                          GetAttention(int32_t aCycleCount) override
257
0
                          { return NS_OK; }
258
  virtual bool            HasPendingInputEvent() override;
259
0
  virtual void            SetIcon(const nsAString &aIconSpec) override {}
260
0
  virtual void            SetDrawsInTitlebar(bool aState) override {}
261
  virtual bool            ShowsResizeIndicator(LayoutDeviceIntRect* aResizerRect) override;
262
0
  virtual void            FreeNativeData(void * data, uint32_t aDataType) override {}
263
  virtual MOZ_MUST_USE nsresult
264
                          BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent,
265
                                          int32_t aHorizontal,
266
                                          int32_t aVertical) override
267
0
                          { return NS_ERROR_NOT_IMPLEMENTED; }
268
  virtual MOZ_MUST_USE nsresult
269
                          BeginMoveDrag(mozilla::WidgetMouseEvent* aEvent) override
270
0
                          { return NS_ERROR_NOT_IMPLEMENTED; }
271
0
  virtual nsresult        ActivateNativeMenuItemAt(const nsAString& indexString) override { return NS_ERROR_NOT_IMPLEMENTED; }
272
0
  virtual nsresult        ForceUpdateNativeMenuAt(const nsAString& indexString) override { return NS_ERROR_NOT_IMPLEMENTED; }
273
  nsresult                NotifyIME(const IMENotification& aIMENotification)
274
                            final;
275
  virtual MOZ_MUST_USE nsresult
276
                          StartPluginIME(const mozilla::WidgetKeyboardEvent& aKeyboardEvent,
277
                                         int32_t aPanelX, int32_t aPanelY,
278
                                         nsString& aCommitted) override
279
0
                          { return NS_ERROR_NOT_IMPLEMENTED; }
280
0
  virtual void            SetPluginFocused(bool& aFocused) override {}
281
  virtual void            SetCandidateWindowForPlugin(
282
                            const mozilla::widget::CandidateWindowPosition&
283
                              aPosition) override
284
0
                          { }
285
  virtual void            DefaultProcOfPluginEvent(
286
                            const mozilla::WidgetPluginEvent& aEvent) override
287
0
                          { }
288
0
  virtual MOZ_MUST_USE nsresult AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent) override { return NS_ERROR_NOT_IMPLEMENTED; }
289
  bool                    ComputeShouldAccelerate();
290
0
  virtual bool            WidgetTypeSupportsAcceleration() { return true; }
291
0
  virtual MOZ_MUST_USE nsresult OnDefaultButtonLoaded(const LayoutDeviceIntRect& aButtonRect) override { return NS_ERROR_NOT_IMPLEMENTED; }
292
  virtual already_AddRefed<nsIWidget>
293
  CreateChild(const LayoutDeviceIntRect& aRect,
294
              nsWidgetInitData* aInitData = nullptr,
295
              bool aForceUseIWidgetParent = false) override;
296
  virtual void            AttachViewToTopLevel(bool aUseAttachedEvents) override;
297
  virtual nsIWidgetListener* GetAttachedWidgetListener() override;
298
  virtual void               SetAttachedWidgetListener(nsIWidgetListener* aListener) override;
299
  virtual nsIWidgetListener* GetPreviouslyAttachedWidgetListener() override;
300
  virtual void               SetPreviouslyAttachedWidgetListener(nsIWidgetListener* aListener) override;
301
  virtual NativeIMEContext GetNativeIMEContext() override;
302
  TextEventDispatcher* GetTextEventDispatcher() final;
303
  virtual TextEventDispatcherListener*
304
    GetNativeTextEventDispatcherListener() override;
305
  virtual void ZoomToRect(const uint32_t& aPresShellId,
306
                          const FrameMetrics::ViewID& aViewId,
307
                          const CSSRect& aRect,
308
                          const uint32_t& aFlags) override;
309
  // Dispatch an event that must be first be routed through APZ.
310
  nsEventStatus DispatchInputEvent(mozilla::WidgetInputEvent* aEvent) override;
311
  void DispatchEventToAPZOnly(mozilla::WidgetInputEvent* aEvent) override;
312
313
  void SetConfirmedTargetAPZC(uint64_t aInputBlockId,
314
                              const nsTArray<ScrollableLayerGuid>& aTargets) const override;
315
316
  void UpdateZoomConstraints(const uint32_t& aPresShellId,
317
                             const FrameMetrics::ViewID& aViewId,
318
                             const mozilla::Maybe<ZoomConstraints>& aConstraints) override;
319
320
  bool AsyncPanZoomEnabled() const override;
321
322
  typedef void (nsIPresShell::*NotificationFunc)(void);
323
  void NotifyPresShell(NotificationFunc aNotificationFunc);
324
325
  void NotifyWindowDestroyed();
326
  void NotifySizeMoveDone();
327
  void NotifyWindowMoved(int32_t aX, int32_t aY);
328
329
  // Register plugin windows for remote updates from the compositor
330
  virtual void RegisterPluginWindowForRemoteUpdates() override;
331
  virtual void UnregisterPluginWindowForRemoteUpdates() override;
332
333
0
  virtual void SetNativeData(uint32_t aDataType, uintptr_t aVal) override {};
334
335
  // Should be called by derived implementations to notify on system color and
336
  // theme changes.
337
  void NotifySysColorChanged();
338
  void NotifyThemeChanged();
339
  void NotifyUIStateChanged(UIStateChangeType aShowAccelerators,
340
                            UIStateChangeType aShowFocusRings);
341
342
#ifdef ACCESSIBILITY
343
  // Get the accessible for the window.
344
  mozilla::a11y::Accessible* GetRootAccessible();
345
#endif
346
347
  // Return true if this is a simple widget (that is typically not worth
348
  // accelerating)
349
  bool IsSmallPopup() const;
350
351
  nsPopupLevel PopupLevel() { return mPopupLevel; }
352
353
  virtual LayoutDeviceIntSize
354
  ClientToWindowSize(const LayoutDeviceIntSize& aClientSize) override
355
0
  {
356
0
    return aClientSize;
357
0
  }
358
359
  // return true if this is a popup widget with a native titlebar
360
  bool IsPopupWithTitleBar() const
361
  {
362
    return (mWindowType == eWindowType_popup &&
363
            mBorderStyle != eBorderStyle_default &&
364
            mBorderStyle & eBorderStyle_title);
365
  }
366
367
0
  virtual void ReparentNativeWidget(nsIWidget* aNewParent) override {}
368
369
  virtual const SizeConstraints GetSizeConstraints() override;
370
  virtual void SetSizeConstraints(const SizeConstraints& aConstraints) override;
371
372
  virtual void StartAsyncScrollbarDrag(const AsyncDragMetrics& aDragMetrics) override;
373
374
  virtual bool StartAsyncAutoscroll(const ScreenPoint& aAnchorLocation,
375
                                    const ScrollableLayerGuid& aGuid) override;
376
377
  virtual void StopAsyncAutoscroll(const ScrollableLayerGuid& aGuid) override;
378
379
  /**
380
   * Use this when GetLayerManager() returns a BasicLayerManager
381
   * (nsBaseWidget::GetLayerManager() does). This sets up the widget's
382
   * layer manager to temporarily render into aTarget.
383
   *
384
   * |aNaturalWidgetBounds| is the un-rotated bounds of |aWidget|.
385
   * |aRotation| is the "virtual rotation" to apply when rendering to
386
   * the target.  When |aRotation| is ROTATION_0,
387
   * |aNaturalWidgetBounds| is not used.
388
   */
389
  class AutoLayerManagerSetup {
390
  public:
391
    AutoLayerManagerSetup(nsBaseWidget* aWidget, gfxContext* aTarget,
392
                          BufferMode aDoubleBuffering,
393
                          ScreenRotation aRotation = mozilla::ROTATION_0);
394
    ~AutoLayerManagerSetup();
395
  private:
396
    nsBaseWidget* mWidget;
397
    RefPtr<BasicLayerManager> mLayerManager;
398
  };
399
  friend class AutoLayerManagerSetup;
400
401
  virtual bool            ShouldUseOffMainThreadCompositing();
402
403
  static nsIRollupListener* GetActiveRollupListener();
404
405
  void Shutdown();
406
407
#if defined(XP_WIN)
408
  uint64_t CreateScrollCaptureContainer() override;
409
#endif
410
411
  // These functions should be called at the start and end of a "live" widget
412
  // resize (i.e. when the window contents are repainting during the resize,
413
  // such as when the user drags a window border). It will suppress the
414
  // displayport during the live resize to avoid unneccessary overpainting.
415
  void NotifyLiveResizeStarted();
416
  void NotifyLiveResizeStopped();
417
418
#if defined(MOZ_WIDGET_ANDROID)
419
  void RecvToolbarAnimatorMessageFromCompositor(int32_t) override {};
420
  void UpdateRootFrameMetrics(const ScreenPoint& aScrollOffset, const CSSToScreenScale& aZoom) override {};
421
  void RecvScreenPixels(mozilla::ipc::Shmem&& aMem, const ScreenIntSize& aSize) override {};
422
#endif
423
424
  /**
425
   * Whether context menus should only appear on mouseup instead of mousedown,
426
   * on OSes where they normally appear on mousedown (macOS, *nix).
427
   */
428
  static bool ShowContextMenuAfterMouseUp();
429
430
protected:
431
  // These are methods for CompositorWidgetWrapper, and should only be
432
  // accessed from that class. Derived widgets can choose which methods to
433
  // implement, or none if supporting out-of-process compositing.
434
0
  virtual bool PreRender(mozilla::widget::WidgetRenderingContext* aContext) {
435
0
    return true;
436
0
  }
437
  virtual void PostRender(mozilla::widget::WidgetRenderingContext* aContext)
438
0
  {}
439
  virtual void DrawWindowUnderlay(mozilla::widget::WidgetRenderingContext* aContext,
440
                                  LayoutDeviceIntRect aRect)
441
0
  {}
442
  virtual void DrawWindowOverlay(mozilla::widget::WidgetRenderingContext* aContext,
443
                                 LayoutDeviceIntRect aRect)
444
0
  {}
445
  virtual already_AddRefed<DrawTarget> StartRemoteDrawing();
446
  virtual already_AddRefed<DrawTarget>
447
  StartRemoteDrawingInRegion(LayoutDeviceIntRegion& aInvalidRegion, BufferMode* aBufferMode)
448
0
  {
449
0
    return StartRemoteDrawing();
450
0
  }
451
  virtual void EndRemoteDrawing()
452
0
  {}
453
  virtual void EndRemoteDrawingInRegion(DrawTarget* aDrawTarget,
454
                                        LayoutDeviceIntRegion& aInvalidRegion)
455
0
  {
456
0
    EndRemoteDrawing();
457
0
  }
458
  virtual void CleanupRemoteDrawing()
459
0
  {}
460
  virtual void CleanupWindowEffects()
461
0
  {}
462
0
  virtual bool InitCompositor(mozilla::layers::Compositor* aCompositor) {
463
0
    return true;
464
0
  }
465
  virtual uint32_t GetGLFrameBufferFormat();
466
467
protected:
468
  void            ResolveIconName(const nsAString &aIconName,
469
                                  const nsAString &aIconSuffix,
470
                                  nsIFile **aResult);
471
  virtual void    OnDestroy();
472
  void            BaseCreate(nsIWidget *aParent,
473
                             nsWidgetInitData* aInitData);
474
475
  virtual void ConfigureAPZCTreeManager();
476
  virtual void ConfigureAPZControllerThread();
477
  virtual already_AddRefed<GeckoContentController> CreateRootContentController();
478
479
  // Dispatch an event that has already been routed through APZ.
480
  nsEventStatus ProcessUntransformedAPZEvent(mozilla::WidgetInputEvent* aEvent,
481
                                             const ScrollableLayerGuid& aGuid,
482
                                             uint64_t aInputBlockId,
483
                                             nsEventStatus aApzResponse);
484
485
  const LayoutDeviceIntRegion RegionFromArray(const nsTArray<LayoutDeviceIntRect>& aRects);
486
  void ArrayFromRegion(const LayoutDeviceIntRegion& aRegion,
487
                       nsTArray<LayoutDeviceIntRect>& aRects);
488
489
  virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
490
                                            int32_t aNativeKeyCode,
491
                                            uint32_t aModifierFlags,
492
                                            const nsAString& aCharacters,
493
                                            const nsAString& aUnmodifiedCharacters,
494
                                            nsIObserver* aObserver) override
495
0
  {
496
0
    mozilla::widget::AutoObserverNotifier notifier(aObserver, "keyevent");
497
0
    return NS_ERROR_UNEXPECTED;
498
0
  }
499
500
  virtual nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
501
                                              uint32_t aNativeMessage,
502
                                              uint32_t aModifierFlags,
503
                                              nsIObserver* aObserver) override
504
0
  {
505
0
    mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
506
0
    return NS_ERROR_UNEXPECTED;
507
0
  }
508
509
  virtual nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
510
                                             nsIObserver* aObserver) override
511
0
  {
512
0
    mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
513
0
    return NS_ERROR_UNEXPECTED;
514
0
  }
515
516
  virtual nsresult SynthesizeNativeMouseScrollEvent(LayoutDeviceIntPoint aPoint,
517
                                                    uint32_t aNativeMessage,
518
                                                    double aDeltaX,
519
                                                    double aDeltaY,
520
                                                    double aDeltaZ,
521
                                                    uint32_t aModifierFlags,
522
                                                    uint32_t aAdditionalFlags,
523
                                                    nsIObserver* aObserver) override
524
0
  {
525
0
    mozilla::widget::AutoObserverNotifier notifier(aObserver, "mousescrollevent");
526
0
    return NS_ERROR_UNEXPECTED;
527
0
  }
528
529
  virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
530
                                              TouchPointerState aPointerState,
531
                                              LayoutDeviceIntPoint aPoint,
532
                                              double aPointerPressure,
533
                                              uint32_t aPointerOrientation,
534
                                              nsIObserver* aObserver) override
535
0
  {
536
0
    mozilla::widget::AutoObserverNotifier notifier(aObserver, "touchpoint");
537
0
    return NS_ERROR_UNEXPECTED;
538
0
  }
539
540
  /**
541
   * GetPseudoIMEContext() returns pseudo IME context when TextEventDispatcher
542
   * has non-native input transaction.  Otherwise, returns nullptr.
543
   */
544
  void* GetPseudoIMEContext();
545
546
protected:
547
  // Utility to check if an array of clip rects is equal to our
548
  // internally stored clip rect array mClipRects.
549
  bool IsWindowClipRegionEqual(const nsTArray<LayoutDeviceIntRect>& aRects);
550
551
  // Stores the clip rectangles in aRects into mClipRects.
552
  void StoreWindowClipRegion(const nsTArray<LayoutDeviceIntRect>& aRects);
553
554
  virtual already_AddRefed<nsIWidget>
555
  AllocateChildPopupWidget()
556
0
  {
557
0
    return nsIWidget::CreateChildWindow();
558
0
  }
559
560
  LayerManager* CreateBasicLayerManager();
561
562
  nsPopupType PopupType() const { return mPopupType; }
563
564
0
  bool HasRemoteContent() const { return mHasRemoteContent; }
565
566
  void NotifyRollupGeometryChange()
567
0
  {
568
0
    // XULPopupManager isn't interested in this notification, so only
569
0
    // send it if gRollupListener is set.
570
0
    if (gRollupListener) {
571
0
      gRollupListener->NotifyGeometryChange();
572
0
    }
573
0
  }
574
575
  /**
576
   * Apply the current size constraints to the given size.
577
   *
578
   * @param aWidth width to constrain
579
   * @param aHeight height to constrain
580
   */
581
  void ConstrainSize(int32_t* aWidth, int32_t* aHeight)
582
0
  {
583
0
    SizeConstraints c = GetSizeConstraints();
584
0
    *aWidth = std::max(c.mMinSize.width,
585
0
                       std::min(c.mMaxSize.width, *aWidth));
586
0
    *aHeight = std::max(c.mMinSize.height,
587
0
                        std::min(c.mMaxSize.height, *aHeight));
588
0
  }
589
590
  virtual CompositorBridgeChild* GetRemoteRenderer() override;
591
592
  /**
593
   * Notify the widget that this window is being used with OMTC.
594
   */
595
0
  virtual void WindowUsesOMTC() {}
596
0
  virtual void RegisterTouchWindow() {}
597
598
  nsIDocument* GetDocument() const;
599
600
  void EnsureTextEventDispatcher();
601
602
  // Notify the compositor that a device reset has occurred.
603
  void OnRenderingDeviceReset();
604
605
  bool UseAPZ();
606
607
  bool AllowWebRenderForThisWindow();
608
609
  /**
610
   * For widgets that support synthesizing native touch events, this function
611
   * can be used to manage the current state of synthetic pointers. Each widget
612
   * must maintain its own MultiTouchInput instance and pass it in as the state,
613
   * along with the desired parameters for the changes. This function returns
614
   * a new MultiTouchInput object that is ready to be dispatched.
615
   */
616
  mozilla::MultiTouchInput
617
  UpdateSynthesizedTouchState(mozilla::MultiTouchInput* aState,
618
                              uint32_t aTime,
619
                              mozilla::TimeStamp aTimeStamp,
620
                              uint32_t aPointerId,
621
                              TouchPointerState aPointerState,
622
                              LayoutDeviceIntPoint aPoint,
623
                              double aPointerPressure,
624
                              uint32_t aPointerOrientation);
625
626
  /**
627
   * Dispatch the given MultiTouchInput through APZ to Gecko (if APZ is enabled)
628
   * or directly to gecko (if APZ is not enabled). This function must only
629
   * be called from the main thread, and if APZ is enabled, that must also be
630
   * the APZ controller thread.
631
   */
632
  void DispatchTouchInput(mozilla::MultiTouchInput& aInput);
633
634
#if defined(XP_WIN)
635
  void UpdateScrollCapture() override;
636
637
  /**
638
   * To be overridden by derived classes to return a snapshot that can be used
639
   * during scrolling. Returning null means we won't update the container.
640
   * @return an already AddRefed SourceSurface containing the snapshot
641
   */
642
  virtual already_AddRefed<SourceSurface> CreateScrollSnapshot()
643
  {
644
    return nullptr;
645
  };
646
647
  /**
648
   * Used by derived classes to create a fallback scroll image.
649
   * @param aSnapshotDrawTarget DrawTarget to fill with fallback image.
650
   */
651
  void DefaultFillScrollCapture(DrawTarget* aSnapshotDrawTarget);
652
653
  RefPtr<ImageContainer> mScrollCaptureContainer;
654
#endif
655
656
protected:
657
  // Returns whether compositing should use an external surface size.
658
0
  virtual bool UseExternalCompositingSurface() const {
659
0
    return false;
660
0
  }
661
662
  /**
663
   * Starts the OMTC compositor destruction sequence.
664
   *
665
   * When this function returns, the compositor should not be
666
   * able to access the opengl context anymore.
667
   * It is safe to call it several times if platform implementations
668
   * require the compositor to be destroyed before ~nsBaseWidget is
669
   * reached (This is the case with gtk2 for instance).
670
   */
671
  virtual void DestroyCompositor();
672
  void DestroyLayerManager();
673
  void ReleaseContentController();
674
  void RevokeTransactionIdAllocator();
675
676
  void FreeShutdownObserver();
677
678
  nsIWidgetListener* mWidgetListener;
679
  nsIWidgetListener* mAttachedWidgetListener;
680
  nsIWidgetListener* mPreviouslyAttachedWidgetListener;
681
  RefPtr<LayerManager> mLayerManager;
682
  RefPtr<CompositorSession> mCompositorSession;
683
  RefPtr<CompositorBridgeChild> mCompositorBridgeChild;
684
685
  mozilla::UniquePtr<mozilla::Mutex> mCompositorVsyncDispatcherLock;
686
  RefPtr<mozilla::CompositorVsyncDispatcher> mCompositorVsyncDispatcher;
687
688
  RefPtr<IAPZCTreeManager> mAPZC;
689
  RefPtr<GeckoContentController> mRootContentController;
690
  RefPtr<APZEventState> mAPZEventState;
691
  SetAllowedTouchBehaviorCallback mSetAllowedTouchBehaviorCallback;
692
  RefPtr<WidgetShutdownObserver> mShutdownObserver;
693
  RefPtr<TextEventDispatcher> mTextEventDispatcher;
694
  nsCursor          mCursor;
695
  nsBorderStyle     mBorderStyle;
696
  LayoutDeviceIntRect mBounds;
697
  LayoutDeviceIntRect* mOriginalBounds;
698
  // When this pointer is null, the widget is not clipped
699
  mozilla::UniquePtr<LayoutDeviceIntRect[]> mClipRects;
700
  uint32_t          mClipRectCount;
701
  nsSizeMode        mSizeMode;
702
  nsPopupLevel      mPopupLevel;
703
  nsPopupType       mPopupType;
704
  SizeConstraints   mSizeConstraints;
705
  bool              mHasRemoteContent;
706
707
  bool              mUpdateCursor;
708
  bool              mUseAttachedEvents;
709
  bool              mIMEHasFocus;
710
  bool              mIsFullyOccluded;
711
  static nsIRollupListener* gRollupListener;
712
713
  struct InitialZoomConstraints {
714
    InitialZoomConstraints(const uint32_t& aPresShellID,
715
                           const FrameMetrics::ViewID& aViewID,
716
                           const ZoomConstraints& aConstraints)
717
      : mPresShellID(aPresShellID), mViewID(aViewID), mConstraints(aConstraints)
718
0
    {
719
0
    }
720
721
    uint32_t mPresShellID;
722
    FrameMetrics::ViewID mViewID;
723
    ZoomConstraints mConstraints;
724
  };
725
726
  mozilla::Maybe<InitialZoomConstraints> mInitialZoomConstraints;
727
728
  // This points to the resize listeners who have been notified that a live
729
  // resize is in progress. This should always be empty when a live-resize is
730
  // not in progress.
731
  nsTArray<RefPtr<mozilla::LiveResizeListener>> mLiveResizeListeners;
732
733
#ifdef DEBUG
734
protected:
735
  static nsAutoString debug_GuiEventToString(mozilla::WidgetGUIEvent* aGuiEvent);
736
  static bool debug_WantPaintFlashing();
737
738
  static void debug_DumpInvalidate(FILE* aFileOut,
739
                                   nsIWidget* aWidget,
740
                                   const LayoutDeviceIntRect* aRect,
741
                                   const char* aWidgetName,
742
                                   int32_t aWindowID);
743
744
  static void debug_DumpEvent(FILE* aFileOut,
745
                              nsIWidget* aWidget,
746
                              mozilla::WidgetGUIEvent* aGuiEvent,
747
                              const char* aWidgetName,
748
                              int32_t aWindowID);
749
750
  static void debug_DumpPaintEvent(FILE *                aFileOut,
751
                                   nsIWidget *           aWidget,
752
                                   const nsIntRegion &   aPaintEvent,
753
                                   const char *          aWidgetName,
754
                                   int32_t               aWindowID);
755
756
  static bool debug_GetCachedBoolPref(const char* aPrefName);
757
#endif
758
759
private:
760
  already_AddRefed<LayerManager>
761
  CreateCompositorSession(int aWidth, int aHeight,
762
                          mozilla::layers::CompositorOptions* aOptionsOut);
763
};
764
765
#endif // nsBaseWidget_h__