nsBaseWidget.h 31 KB

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