1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:expandtab:shiftwidth=4:tabstop=4: 3 */ 4 /* This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 7 8 #ifndef __nsWindow_h__ 9 #define __nsWindow_h__ 10 11 #include <gdk/gdk.h> 12 #include <gtk/gtk.h> 13 #ifdef MOZ_X11 14 # include <gdk/gdkx.h> 15 # include "X11UndefineNone.h" 16 #endif /* MOZ_X11 */ 17 #ifdef MOZ_WAYLAND 18 # include <gdk/gdkwayland.h> 19 # include "base/thread.h" 20 # include "WaylandVsyncSource.h" 21 #endif 22 #include "MozContainer.h" 23 #include "mozilla/RefPtr.h" 24 #include "mozilla/UniquePtr.h" 25 #include "nsIDragService.h" 26 #include "nsGkAtoms.h" 27 #include "nsRefPtrHashtable.h" 28 #include "nsIFrame.h" 29 #include "nsBaseWidget.h" 30 #include "CompositorWidget.h" 31 #include "mozilla/widget/WindowSurface.h" 32 #include "mozilla/widget/WindowSurfaceProvider.h" 33 34 #ifdef ACCESSIBILITY 35 # include "mozilla/a11y/Accessible.h" 36 #endif 37 #include "mozilla/EventForwards.h" 38 #include "mozilla/TouchEvents.h" 39 40 #include "IMContextWrapper.h" 41 42 #undef LOG 43 #ifdef MOZ_LOGGING 44 45 # include "mozilla/Logging.h" 46 # include "nsTArray.h" 47 # include "Units.h" 48 49 extern mozilla::LazyLogModule gWidgetLog; 50 extern mozilla::LazyLogModule gWidgetFocusLog; 51 extern mozilla::LazyLogModule gWidgetDragLog; 52 extern mozilla::LazyLogModule gWidgetDrawLog; 53 54 # define LOG(args) MOZ_LOG(gWidgetLog, mozilla::LogLevel::Debug, args) 55 # define LOGFOCUS(args) \ 56 MOZ_LOG(gWidgetFocusLog, mozilla::LogLevel::Debug, args) 57 # define LOGDRAG(args) MOZ_LOG(gWidgetDragLog, mozilla::LogLevel::Debug, args) 58 # define LOGDRAW(args) MOZ_LOG(gWidgetDrawLog, mozilla::LogLevel::Debug, args) 59 60 #else 61 62 # define LOG(args) 63 # define LOGFOCUS(args) 64 # define LOGDRAG(args) 65 # define LOGDRAW(args) 66 67 #endif /* MOZ_LOGGING */ 68 69 #ifdef MOZ_WAYLAND 70 class nsWaylandDragContext; 71 72 gboolean WindowDragMotionHandler(GtkWidget* aWidget, 73 GdkDragContext* aDragContext, 74 nsWaylandDragContext* aWaylandDragContext, 75 gint aX, gint aY, guint aTime); 76 gboolean WindowDragDropHandler(GtkWidget* aWidget, GdkDragContext* aDragContext, 77 nsWaylandDragContext* aWaylandDragContext, 78 gint aX, gint aY, guint aTime); 79 void WindowDragLeaveHandler(GtkWidget* aWidget); 80 #endif 81 82 class gfxPattern; 83 84 namespace mozilla { 85 class TimeStamp; 86 class CurrentX11TimeGetter; 87 88 } // namespace mozilla 89 90 class OpaqueRegionState { 91 public: OpaqueRegionState()92 OpaqueRegionState() : mRect({-1, -1, -1, -1}), mSubtractedCorners(false){}; 93 bool NeedsUpdate(GdkRectangle& aNewRect, bool aNewSubtractedCorners); 94 95 private: 96 GdkRectangle mRect; 97 bool mSubtractedCorners; 98 }; 99 100 class nsWindow final : public nsBaseWidget { 101 public: 102 typedef mozilla::gfx::DrawTarget DrawTarget; 103 typedef mozilla::WidgetEventTime WidgetEventTime; 104 typedef mozilla::WidgetKeyboardEvent WidgetKeyboardEvent; 105 typedef mozilla::widget::PlatformCompositorWidgetDelegate 106 PlatformCompositorWidgetDelegate; 107 108 nsWindow(); 109 110 static void ReleaseGlobals(); 111 112 NS_INLINE_DECL_REFCOUNTING_INHERITED(nsWindow, nsBaseWidget) 113 114 void CommonCreate(nsIWidget* aParent, bool aListenForResizes); 115 116 virtual nsresult DispatchEvent(mozilla::WidgetGUIEvent* aEvent, 117 nsEventStatus& aStatus) override; 118 119 // called when we are destroyed 120 virtual void OnDestroy(void) override; 121 122 // called to check and see if a widget's dimensions are sane 123 bool AreBoundsSane(void); 124 125 // nsIWidget 126 using nsBaseWidget::Create; // for Create signature not overridden here 127 [[nodiscard]] virtual nsresult Create(nsIWidget* aParent, 128 nsNativeWidget aNativeParent, 129 const LayoutDeviceIntRect& aRect, 130 nsWidgetInitData* aInitData) override; 131 virtual void Destroy() override; 132 virtual nsIWidget* GetParent() override; 133 virtual float GetDPI() override; 134 virtual double GetDefaultScaleInternal() override; 135 mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() override; 136 mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScaleByScreen() 137 override; 138 virtual void SetParent(nsIWidget* aNewParent) override; 139 virtual void SetModal(bool aModal) override; 140 virtual bool IsVisible() const override; 141 virtual void ConstrainPosition(bool aAllowSlop, int32_t* aX, 142 int32_t* aY) override; 143 virtual void SetSizeConstraints(const SizeConstraints& aConstraints) override; 144 virtual void LockAspectRatio(bool aShouldLock) override; 145 virtual void Move(double aX, double aY) override; 146 virtual void Show(bool aState) override; 147 virtual void Resize(double aWidth, double aHeight, bool aRepaint) override; 148 virtual void Resize(double aX, double aY, double aWidth, double aHeight, 149 bool aRepaint) override; 150 virtual bool IsEnabled() const override; 151 152 void SetZIndex(int32_t aZIndex) override; 153 virtual void SetSizeMode(nsSizeMode aMode) override; 154 virtual void GetWorkspaceID(nsAString& workspaceID) override; 155 virtual void MoveToWorkspace(const nsAString& workspaceID) override; 156 virtual void Enable(bool aState) override; 157 virtual void SetFocus(Raise, mozilla::dom::CallerType aCallerType) override; 158 virtual LayoutDeviceIntRect GetScreenBounds() override; 159 virtual LayoutDeviceIntRect GetClientBounds() override; 160 virtual LayoutDeviceIntSize GetClientSize() override; 161 virtual LayoutDeviceIntPoint GetClientOffset() override; 162 virtual void SetCursor(nsCursor aDefaultCursor, imgIContainer* aCursor, 163 uint32_t aHotspotX, uint32_t aHotspotY) override; 164 virtual void Invalidate(const LayoutDeviceIntRect& aRect) override; 165 virtual void* GetNativeData(uint32_t aDataType) override; 166 virtual nsresult SetTitle(const nsAString& aTitle) override; 167 virtual void SetIcon(const nsAString& aIconSpec) override; 168 virtual void SetWindowClass(const nsAString& xulWinType) override; 169 virtual LayoutDeviceIntPoint WidgetToScreenOffset() override; 170 virtual void CaptureMouse(bool aCapture) override; 171 virtual void CaptureRollupEvents(nsIRollupListener* aListener, 172 bool aDoCapture) override; 173 [[nodiscard]] virtual nsresult GetAttention(int32_t aCycleCount) override; 174 virtual nsresult SetWindowClipRegion( 175 const nsTArray<LayoutDeviceIntRect>& aRects, 176 bool aIntersectWithExisting) override; 177 virtual bool HasPendingInputEvent() override; 178 179 virtual bool PrepareForFullscreenTransition(nsISupports** aData) override; 180 virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage, 181 uint16_t aDuration, 182 nsISupports* aData, 183 nsIRunnable* aCallback) override; 184 virtual already_AddRefed<nsIScreen> GetWidgetScreen() override; 185 virtual nsresult MakeFullScreen(bool aFullScreen, 186 nsIScreen* aTargetScreen = nullptr) override; 187 virtual void HideWindowChrome(bool aShouldHide) override; 188 189 /** 190 * GetLastUserInputTime returns a timestamp for the most recent user input 191 * event. This is intended for pointer grab requests (including drags). 192 */ 193 static guint32 GetLastUserInputTime(); 194 195 // utility method, -1 if no change should be made, otherwise returns a 196 // value that can be passed to gdk_window_set_decorations 197 gint ConvertBorderStyles(nsBorderStyle aStyle); 198 199 GdkRectangle DevicePixelsToGdkRectRoundOut(LayoutDeviceIntRect aRect); 200 GetIMContext()201 mozilla::widget::IMContextWrapper* GetIMContext() const { return mIMContext; } 202 203 bool DispatchCommandEvent(nsAtom* aCommand); 204 bool DispatchContentCommandEvent(mozilla::EventMessage aMsg); 205 206 // event callbacks 207 gboolean OnExposeEvent(cairo_t* cr); 208 gboolean OnConfigureEvent(GtkWidget* aWidget, GdkEventConfigure* aEvent); 209 void OnContainerUnrealize(); 210 void OnSizeAllocate(GtkAllocation* aAllocation); 211 void OnDeleteEvent(); 212 void OnEnterNotifyEvent(GdkEventCrossing* aEvent); 213 void OnLeaveNotifyEvent(GdkEventCrossing* aEvent); 214 void OnMotionNotifyEvent(GdkEventMotion* aEvent); 215 void OnButtonPressEvent(GdkEventButton* aEvent); 216 void OnButtonReleaseEvent(GdkEventButton* aEvent); 217 void OnContainerFocusInEvent(GdkEventFocus* aEvent); 218 void OnContainerFocusOutEvent(GdkEventFocus* aEvent); 219 gboolean OnKeyPressEvent(GdkEventKey* aEvent); 220 gboolean OnKeyReleaseEvent(GdkEventKey* aEvent); 221 222 void OnScrollEvent(GdkEventScroll* aEvent); 223 void OnVisibilityNotifyEvent(GdkEventVisibility* aEvent); 224 void OnWindowStateEvent(GtkWidget* aWidget, GdkEventWindowState* aEvent); 225 void OnDragDataReceivedEvent(GtkWidget* aWidget, GdkDragContext* aDragContext, 226 gint aX, gint aY, 227 GtkSelectionData* aSelectionData, guint aInfo, 228 guint aTime, gpointer aData); 229 gboolean OnPropertyNotifyEvent(GtkWidget* aWidget, GdkEventProperty* aEvent); 230 #if GTK_CHECK_VERSION(3, 4, 0) 231 gboolean OnTouchEvent(GdkEventTouch* aEvent); 232 #endif 233 234 virtual already_AddRefed<mozilla::gfx::DrawTarget> StartRemoteDrawingInRegion( 235 LayoutDeviceIntRegion& aInvalidRegion, 236 mozilla::layers::BufferMode* aBufferMode) override; 237 virtual void EndRemoteDrawingInRegion( 238 mozilla::gfx::DrawTarget* aDrawTarget, 239 const LayoutDeviceIntRegion& aInvalidRegion) override; 240 241 void SetProgress(unsigned long progressPercent); 242 243 #ifdef MOZ_WAYLAND 244 void SetEGLNativeWindowSize(const LayoutDeviceIntSize& aEGLWindowSize); 245 static nsWindow* GetFocusedWindow(); 246 #endif 247 248 RefPtr<mozilla::gfx::VsyncSource> GetVsyncSource() override; 249 250 private: 251 void UpdateAlpha(mozilla::gfx::SourceSurface* aSourceSurface, 252 nsIntRect aBoundsRect); 253 254 void NativeMove(); 255 void NativeResize(); 256 void NativeMoveResize(); 257 258 void NativeShow(bool aAction); 259 void SetHasMappedToplevel(bool aState); 260 LayoutDeviceIntSize GetSafeWindowSize(LayoutDeviceIntSize aSize); 261 262 void EnsureGrabs(void); 263 void GrabPointer(guint32 aTime); 264 void ReleaseGrabs(void); 265 266 void UpdateClientOffsetFromFrameExtents(); 267 void UpdateClientOffsetFromCSDWindow(); 268 269 void DispatchContextMenuEventFromMouseEvent(uint16_t domButton, 270 GdkEventButton* aEvent); 271 #ifdef MOZ_WAYLAND 272 void MaybeResumeCompositor(); 273 #endif 274 275 void WaylandStartVsync(); 276 void WaylandStopVsync(); 277 278 public: 279 void ThemeChanged(void); 280 void OnDPIChanged(void); 281 void OnCheckResize(void); 282 void OnCompositedChanged(void); 283 void OnScaleChanged(GtkAllocation* aAllocation); 284 285 #ifdef MOZ_X11 286 Window mOldFocusWindow; 287 #endif /* MOZ_X11 */ 288 289 static guint32 sLastButtonPressTime; 290 291 [[nodiscard]] virtual nsresult BeginResizeDrag( 292 mozilla::WidgetGUIEvent* aEvent, int32_t aHorizontal, 293 int32_t aVertical) override; 294 GetMozContainer()295 MozContainer* GetMozContainer() { return mContainer; } 296 LayoutDeviceIntRect GetMozContainerSize(); 297 // GetMozContainerWidget returns the MozContainer even for undestroyed 298 // descendant windows 299 GtkWidget* GetMozContainerWidget(); GetGdkWindow()300 GdkWindow* GetGdkWindow() { return mGdkWindow; } GetGtkWidget()301 GtkWidget* GetGtkWidget() { return mShell; } 302 nsIFrame* GetFrame(); IsDestroyed()303 bool IsDestroyed() { return mIsDestroyed; } 304 bool IsWaylandPopup(); IsPIPWindow()305 bool IsPIPWindow() { return mIsPIPWindow; }; 306 307 void DispatchDragEvent(mozilla::EventMessage aMsg, 308 const LayoutDeviceIntPoint& aRefPoint, guint aTime); 309 static void UpdateDragStatus(GdkDragContext* aDragContext, 310 nsIDragService* aDragService); 311 312 WidgetEventTime GetWidgetEventTime(guint32 aEventTime); 313 mozilla::TimeStamp GetEventTimeStamp(guint32 aEventTime); 314 mozilla::CurrentX11TimeGetter* GetCurrentTimeGetter(); 315 316 virtual void SetInputContext(const InputContext& aContext, 317 const InputContextAction& aAction) override; 318 virtual InputContext GetInputContext() override; 319 virtual TextEventDispatcherListener* GetNativeTextEventDispatcherListener() 320 override; 321 void GetEditCommandsRemapped(NativeKeyBindingsType aType, 322 const mozilla::WidgetKeyboardEvent& aEvent, 323 nsTArray<mozilla::CommandInt>& aCommands, 324 uint32_t aGeckoKeyCode, uint32_t aNativeKeyCode); 325 virtual bool GetEditCommands( 326 NativeKeyBindingsType aType, const mozilla::WidgetKeyboardEvent& aEvent, 327 nsTArray<mozilla::CommandInt>& aCommands) override; 328 329 // These methods are for toplevel windows only. 330 void ResizeTransparencyBitmap(); 331 void ApplyTransparencyBitmap(); 332 void ClearTransparencyBitmap(); 333 334 virtual void SetTransparencyMode(nsTransparencyMode aMode) override; 335 virtual nsTransparencyMode GetTransparencyMode() override; 336 virtual void SetWindowMouseTransparent(bool aIsTransparent) override; 337 virtual void UpdateOpaqueRegion( 338 const LayoutDeviceIntRegion& aOpaqueRegion) override; 339 virtual nsresult ConfigureChildren( 340 const nsTArray<Configuration>& aConfigurations) override; 341 nsresult UpdateTranslucentWindowAlphaInternal(const nsIntRect& aRect, 342 uint8_t* aAlphas, 343 int32_t aStride); 344 void UpdateTitlebarTransparencyBitmap(); 345 346 virtual void ReparentNativeWidget(nsIWidget* aNewParent) override; 347 348 virtual nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint, 349 uint32_t aNativeMessage, 350 uint32_t aModifierFlags, 351 nsIObserver* aObserver) override; 352 SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,nsIObserver * aObserver)353 virtual nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint, 354 nsIObserver* aObserver) override { 355 return SynthesizeNativeMouseEvent(aPoint, GDK_MOTION_NOTIFY, 0, aObserver); 356 } 357 358 virtual nsresult SynthesizeNativeMouseScrollEvent( 359 LayoutDeviceIntPoint aPoint, uint32_t aNativeMessage, double aDeltaX, 360 double aDeltaY, double aDeltaZ, uint32_t aModifierFlags, 361 uint32_t aAdditionalFlags, nsIObserver* aObserver) override; 362 363 #if GTK_CHECK_VERSION(3, 4, 0) 364 virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId, 365 TouchPointerState aPointerState, 366 LayoutDeviceIntPoint aPoint, 367 double aPointerPressure, 368 uint32_t aPointerOrientation, 369 nsIObserver* aObserver) override; 370 #endif 371 372 #ifdef MOZ_X11 XDisplay()373 Display* XDisplay() { return mXDisplay; } 374 #endif 375 #ifdef MOZ_WAYLAND 376 wl_display* GetWaylandDisplay(); 377 wl_surface* GetWaylandSurface(); 378 bool WaylandSurfaceNeedsClear(); 379 virtual void CreateCompositorVsyncDispatcher() override; 380 #endif 381 virtual void GetCompositorWidgetInitData( 382 mozilla::widget::CompositorWidgetInitData* aInitData) override; 383 384 virtual nsresult SetNonClientMargins( 385 LayoutDeviceIntMargin& aMargins) override; 386 void SetDrawsInTitlebar(bool aState) override; 387 virtual void UpdateWindowDraggingRegion( 388 const LayoutDeviceIntRegion& aRegion) override; 389 390 // HiDPI scale conversion 391 gint GdkScaleFactor(); 392 393 // To GDK 394 gint DevicePixelsToGdkCoordRoundUp(int pixels); 395 gint DevicePixelsToGdkCoordRoundDown(int pixels); 396 GdkPoint DevicePixelsToGdkPointRoundDown(LayoutDeviceIntPoint point); 397 GdkRectangle DevicePixelsToGdkSizeRoundUp(LayoutDeviceIntSize pixelSize); 398 399 // From GDK 400 int GdkCoordToDevicePixels(gint coord); 401 LayoutDeviceIntPoint GdkPointToDevicePixels(GdkPoint point); 402 LayoutDeviceIntPoint GdkEventCoordsToDevicePixels(gdouble x, gdouble y); 403 LayoutDeviceIntRect GdkRectToDevicePixels(GdkRectangle rect); 404 405 virtual bool WidgetTypeSupportsAcceleration() override; 406 407 nsresult SetSystemFont(const nsCString& aFontName) override; 408 nsresult GetSystemFont(nsCString& aFontName) override; 409 410 typedef enum { 411 CSD_SUPPORT_SYSTEM, // CSD including shadows 412 CSD_SUPPORT_CLIENT, // CSD without shadows 413 CSD_SUPPORT_NONE, // WM does not support CSD at all 414 CSD_SUPPORT_UNKNOWN 415 } CSDSupportLevel; 416 /** 417 * Get the support of Client Side Decoration by checking 418 * the XDG_CURRENT_DESKTOP environment variable. 419 */ 420 static CSDSupportLevel GetSystemCSDSupportLevel(bool aIsPIPWindow = false); 421 422 static bool HideTitlebarByDefault(); 423 static bool GetTopLevelWindowActiveState(nsIFrame* aFrame); 424 static bool TitlebarCanUseShapeMask(); 425 #ifdef MOZ_WAYLAND 426 virtual nsresult GetScreenRect(LayoutDeviceIntRect* aRect) override; GetPreferredPopupRect()427 virtual nsRect GetPreferredPopupRect() override { 428 return mPreferredPopupRect; 429 }; FlushPreferredPopupRect()430 virtual void FlushPreferredPopupRect() override { 431 mPreferredPopupRect = nsRect(0, 0, 0, 0); 432 mPreferredPopupRectFlushed = true; 433 }; 434 #endif IsRemoteContent()435 bool IsRemoteContent() { return HasRemoteContent(); } 436 static void HideWaylandOpenedPopups(); 437 void NativeMoveResizeWaylandPopupCB(const GdkRectangle* aFinalSize, 438 bool aFlippedX, bool aFlippedY); 439 440 protected: 441 virtual ~nsWindow(); 442 443 // event handling code 444 void DispatchActivateEvent(void); 445 void DispatchDeactivateEvent(void); 446 void DispatchResized(); 447 void MaybeDispatchResized(); 448 449 virtual void RegisterTouchWindow() override; CompositorInitiallyPaused()450 virtual bool CompositorInitiallyPaused() override { 451 #ifdef MOZ_WAYLAND 452 return mCompositorInitiallyPaused; 453 #else 454 return false; 455 #endif 456 } 457 nsCOMPtr<nsIWidget> mParent; 458 // Is this a toplevel window? 459 bool mIsTopLevel; 460 // Has this widget been destroyed yet? 461 bool mIsDestroyed; 462 463 // Should we send resize events on all resizes? 464 bool mListenForResizes; 465 // Does WindowResized need to be called on listeners? 466 bool mNeedsDispatchResized; 467 // This flag tracks if we're hidden or shown. 468 bool mIsShown; 469 bool mNeedsShow; 470 // is this widget enabled? 471 bool mEnabled; 472 // has the native window for this been created yet? 473 bool mCreated; 474 #if GTK_CHECK_VERSION(3, 4, 0) 475 // whether we handle touch event 476 bool mHandleTouchEvent; 477 #endif 478 // true if this is a drag and drop feedback popup 479 bool mIsDragPopup; 480 // Can we access X? 481 bool mIsX11Display; 482 #ifdef MOZ_WAYLAND 483 bool mNeedsCompositorResume; 484 bool mCompositorInitiallyPaused; 485 #endif 486 bool mWindowScaleFactorChanged; 487 int mWindowScaleFactor; 488 bool mIsAccelerated; 489 490 private: 491 void DestroyChildWindows(); 492 GtkWidget* GetToplevelWidget(); 493 nsWindow* GetContainerWindow(); 494 void SetUrgencyHint(GtkWidget* top_window, bool state); 495 void SetDefaultIcon(void); 496 void SetWindowDecoration(nsBorderStyle aStyle); 497 void InitButtonEvent(mozilla::WidgetMouseEvent& aEvent, 498 GdkEventButton* aGdkEvent); 499 bool CheckForRollup(gdouble aMouseX, gdouble aMouseY, bool aIsWheel, 500 bool aAlwaysRollup); CheckForRollupDuringGrab()501 void CheckForRollupDuringGrab() { CheckForRollup(0, 0, false, true); } 502 503 bool GetDragInfo(mozilla::WidgetMouseEvent* aMouseEvent, GdkWindow** aWindow, 504 gint* aButton, gint* aRootX, gint* aRootY); 505 void ClearCachedResources(); 506 nsIWidgetListener* GetListener(); 507 508 #ifdef MOZ_WAYLAND 509 void UpdateTopLevelOpaqueRegionWayland(bool aSubtractCorners); 510 #endif 511 void UpdateTopLevelOpaqueRegionGtk(bool aSubtractCorners); 512 void UpdatePopupOpaqueRegion(const LayoutDeviceIntRegion& aOpaqueRegion); 513 514 nsWindow* GetTransientForWindowIfPopup(); 515 bool IsHandlingTouchSequence(GdkEventSequence* aSequence); 516 517 void ResizeInt(int aX, int aY, int aWidth, int aHeight, bool aMove, 518 bool aRepaint); 519 void NativeMoveResizeWaylandPopup(GdkPoint* aPosition, GdkRectangle* aSize); 520 521 GtkTextDirection GetTextDirection(); 522 523 #ifdef MOZ_X11 524 typedef enum {GTK_WIDGET_COMPOSIDED_DEFAULT = 0, 525 GTK_WIDGET_COMPOSIDED_DISABLED = 1, 526 GTK_WIDGET_COMPOSIDED_ENABLED = 2} WindowComposeRequest; 527 528 void SetCompositorHint(WindowComposeRequest aState); 529 #endif 530 nsCString mGtkWindowAppName; 531 nsCString mGtkWindowRoleName; 532 void RefreshWindowClass(); 533 534 GtkWidget* mShell; 535 MozContainer* mContainer; 536 GdkWindow* mGdkWindow; 537 bool mWindowShouldStartDragging = false; 538 PlatformCompositorWidgetDelegate* mCompositorWidgetDelegate; 539 540 uint32_t mHasMappedToplevel : 1, mIsFullyObscured : 1, mRetryPointerGrab : 1; 541 nsSizeMode mSizeState; 542 float mAspectRatio; 543 float mAspectRatioSaved; 544 nsIntPoint mClientOffset; 545 546 #if GTK_CHECK_VERSION(3, 4, 0) 547 // This field omits duplicate scroll events caused by GNOME bug 726878. 548 guint32 mLastScrollEventTime; 549 550 bool mPanInProgress = false; 551 552 // for touch event handling 553 nsRefPtrHashtable<nsPtrHashKey<GdkEventSequence>, mozilla::dom::Touch> 554 mTouches; 555 #endif 556 557 #ifdef MOZ_X11 558 Display* mXDisplay; 559 Window mXWindow; 560 Visual* mXVisual; 561 int mXDepth; 562 mozilla::widget::WindowSurfaceProvider mSurfaceProvider; 563 #endif 564 #ifdef MOZ_WAYLAND 565 RefPtr<mozilla::gfx::VsyncSource> mWaylandVsyncSource; 566 #endif 567 568 // Upper bound on pending ConfigureNotify events to be dispatched to the 569 // window. See bug 1225044. 570 unsigned int mPendingConfigures; 571 572 // Window titlebar rendering mode, CSD_SUPPORT_NONE if it's disabled 573 // for this window. 574 CSDSupportLevel mCSDSupportLevel; 575 // Use dedicated GdkWindow for mContainer 576 bool mDrawToContainer; 577 // If true, draw our own window titlebar. 578 bool mDrawInTitlebar; 579 // Draw titlebar with :backdrop css state (inactive/unfocused). 580 bool mTitlebarBackdropState; 581 // Draggable titlebar region maintained by UpdateWindowDraggingRegion 582 LayoutDeviceIntRegion mDraggableRegion; 583 // It's PictureInPicture window. 584 bool mIsPIPWindow; 585 bool mAlwaysOnTop; 586 587 #ifdef ACCESSIBILITY 588 RefPtr<mozilla::a11y::Accessible> mRootAccessible; 589 590 /** 591 * Request to create the accessible for this window if it is top level. 592 */ 593 void CreateRootAccessible(); 594 595 /** 596 * Dispatch accessible event for the top level window accessible. 597 * 598 * @param aEventType [in] the accessible event type to dispatch 599 */ 600 void DispatchEventToRootAccessible(uint32_t aEventType); 601 602 /** 603 * Dispatch accessible window activate event for the top level window 604 * accessible. 605 */ 606 void DispatchActivateEventAccessible(); 607 608 /** 609 * Dispatch accessible window deactivate event for the top level window 610 * accessible. 611 */ 612 void DispatchDeactivateEventAccessible(); 613 614 /** 615 * Dispatch accessible window maximize event for the top level window 616 * accessible. 617 */ 618 void DispatchMaximizeEventAccessible(); 619 620 /** 621 * Dispatch accessible window minize event for the top level window 622 * accessible. 623 */ 624 void DispatchMinimizeEventAccessible(); 625 626 /** 627 * Dispatch accessible window restore event for the top level window 628 * accessible. 629 */ 630 void DispatchRestoreEventAccessible(); 631 #endif 632 633 // The cursor cache 634 static GdkCursor* gsGtkCursorCache[eCursorCount]; 635 636 // Transparency 637 bool mIsTransparent; 638 // This bitmap tracks which pixels are transparent. We don't support 639 // full translucency at this time; each pixel is either fully opaque 640 // or fully transparent. 641 gchar* mTransparencyBitmap; 642 int32_t mTransparencyBitmapWidth; 643 int32_t mTransparencyBitmapHeight; 644 // The transparency bitmap is used instead of ARGB visual for toplevel 645 // window to draw titlebar. 646 bool mTransparencyBitmapForTitlebar; 647 648 // True when we're on compositing window manager and this 649 // window is using visual with alpha channel. 650 bool mHasAlphaVisual; 651 652 // all of our DND stuff 653 void InitDragEvent(mozilla::WidgetDragEvent& aEvent); 654 655 float mLastMotionPressure; 656 657 // Remember the last sizemode so that we can restore it when 658 // leaving fullscreen 659 nsSizeMode mLastSizeMode; 660 // We can't detect size state changes correctly so set this flag 661 // to force update mBounds after a size state change from a configure 662 // event. 663 bool mBoundsAreValid; 664 665 // Used to track opaque region changes for toplevel windows. 666 OpaqueRegionState mToplevelOpaqueRegionState; 667 668 static bool DragInProgress(void); 669 670 void DispatchMissedButtonReleases(GdkEventCrossing* aGdkEvent); 671 672 // nsBaseWidget 673 virtual LayerManager* GetLayerManager( 674 PLayerTransactionChild* aShadowManager = nullptr, 675 LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE, 676 LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT) override; 677 678 void SetCompositorWidgetDelegate(CompositorWidgetDelegate* delegate) override; 679 680 void CleanLayerManagerRecursive(); 681 682 virtual int32_t RoundsWidgetCoordinatesTo() override; 683 684 void UpdateMozWindowActive(); 685 686 void ForceTitlebarRedraw(); 687 688 void SetPopupWindowDecoration(bool aShowOnTaskbar); 689 690 void ApplySizeConstraints(void); 691 692 bool IsMainMenuWindow(); 693 GtkWidget* ConfigureWaylandPopupWindows(); 694 void PauseRemoteRenderer(); 695 void HideWaylandWindow(); 696 void HideWaylandTooltips(); 697 void HideWaylandPopupAndAllChildren(); 698 void CleanupWaylandPopups(); 699 GtkWindow* GetCurrentTopmostWindow(); 700 GtkWindow* GetCurrentWindow(); 701 GtkWindow* GetTopmostWindow(); 702 bool IsWidgetOverflowWindow(); 703 nsRect mPreferredPopupRect; 704 bool mPreferredPopupRectFlushed; 705 bool mWaitingForMoveToRectCB; 706 LayoutDeviceIntRect mPendingSizeRect; 707 708 /** 709 * |mIMContext| takes all IME related stuff. 710 * 711 * This is owned by the top-level nsWindow or the topmost child 712 * nsWindow embedded in a non-Gecko widget. 713 * 714 * The instance is created when the top level widget is created. And when 715 * the widget is destroyed, it's released. All child windows refer its 716 * ancestor widget's instance. So, one set of IM contexts is created for 717 * all windows in a hierarchy. If the children are released after the top 718 * level window is released, the children still have a valid pointer, 719 * however, IME doesn't work at that time. 720 */ 721 RefPtr<mozilla::widget::IMContextWrapper> mIMContext; 722 723 mozilla::UniquePtr<mozilla::CurrentX11TimeGetter> mCurrentTimeGetter; 724 static CSDSupportLevel sCSDSupportLevel; 725 }; 726 727 #endif /* __nsWindow_h__ */ 728