1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef WIDGET_WINDOWS_NSWINDOW_H_
7 #define WIDGET_WINDOWS_NSWINDOW_H_
10 * nsWindow - Native window management and event handling.
13 #include "mozilla/RefPtr.h"
14 #include "nsBaseWidget.h"
15 #include "CompositorWidget.h"
16 #include "mozilla/EventForwards.h"
17 #include "nsClassHashtable.h"
19 #include "touchinjection_sdk80.h"
21 #include "nsUserIdleService.h"
22 #include "nsToolkit.h"
25 #include "gfxWindowsPlatform.h"
26 #include "gfxWindowsSurface.h"
27 #include "nsWindowDbg.h"
30 #include "mozilla/EnumeratedArray.h"
31 #include "mozilla/Maybe.h"
32 #include "mozilla/MouseEvents.h"
33 #include "mozilla/TimeStamp.h"
34 #include "mozilla/webrender/WebRenderTypes.h"
35 #include "mozilla/dom/MouseEventBinding.h"
36 #include "mozilla/DataMutex.h"
37 #include "mozilla/UniquePtr.h"
39 #include "nsRegionFwd.h"
41 #include "nsWinGesture.h"
42 #include "WinPointerEvents.h"
44 #include "WindowHook.h"
45 #include "TaskbarWindowPreview.h"
49 # include "mozilla/a11y/LocalAccessible.h"
52 #include "nsUXThemeData.h"
53 #include "nsIUserIdleServiceInternal.h"
55 #include "IMMHandler.h"
56 #include "CheckInvariantWrapper.h"
59 * Forward class definitions
62 class nsNativeDragTarget
;
63 class nsIRollupListener
;
67 class WidgetMouseEvent
;
70 class InProcessWinCompositorWidget
;
72 class DirectManipulationOwner
;
74 } // namespace mozilla
77 * Forward Windows-internal definitions of otherwise incomplete ones provided by
80 const CLSID CLSID_ImmersiveShell
= {
84 {0xB4, 0xBB, 0x15, 0x63, 0x62, 0xA2, 0xF2, 0x39}};
87 * Native WIN32 window wrapper.
90 class nsWindow final
: public nsBaseWidget
{
92 using WindowHook
= mozilla::widget::WindowHook
;
93 using IMEContext
= mozilla::widget::IMEContext
;
94 using WidgetEventTime
= mozilla::WidgetEventTime
;
96 NS_INLINE_DECL_REFCOUNTING_INHERITED(nsWindow
, nsBaseWidget
)
98 explicit nsWindow(bool aIsChildWindow
= false);
100 void SendAnAPZEvent(mozilla::InputData
& aEvent
);
103 * Init a standard gecko event for this widget.
104 * @param aEvent the event to initialize.
105 * @param aPoint message position in physical coordinates.
107 void InitEvent(mozilla::WidgetGUIEvent
& aEvent
,
108 LayoutDeviceIntPoint
* aPoint
= nullptr);
111 * Returns WidgetEventTime instance which is initialized with current message
114 WidgetEventTime
CurrentMessageWidgetEventTime() const;
117 * Dispatch a gecko keyboard event for this widget. This
118 * is called by KeyboardLayout to dispatch gecko events.
119 * Returns true if it's consumed. Otherwise, false.
121 bool DispatchKeyboardEvent(mozilla::WidgetKeyboardEvent
* aEvent
);
124 * Dispatch a gecko wheel event for this widget. This
125 * is called by ScrollHandler to dispatch gecko events.
126 * Returns true if it's consumed. Otherwise, false.
128 bool DispatchWheelEvent(mozilla::WidgetWheelEvent
* aEvent
);
131 * Dispatch a gecko content command event for this widget. This
132 * is called by ScrollHandler to dispatch gecko events.
133 * Returns true if it's consumed. Otherwise, false.
135 bool DispatchContentCommandEvent(mozilla::WidgetContentCommandEvent
* aEvent
);
138 * Return the parent window, if it exists.
140 nsWindow
* GetParentWindowBase(bool aIncludeOwner
);
143 * Return true if this is a top level widget.
145 bool IsTopLevelWidget() { return mIsTopWidgetWindow
; }
147 // nsIWidget interface
148 using nsBaseWidget::Create
; // for Create signature not overridden here
149 [[nodiscard
]] nsresult
Create(nsIWidget
* aParent
,
150 nsNativeWidget aNativeParent
,
151 const LayoutDeviceIntRect
& aRect
,
152 InitData
* aInitData
= nullptr) override
;
153 void Destroy() override
;
154 void SetParent(nsIWidget
* aNewParent
) override
;
155 nsIWidget
* GetParent(void) override
;
156 float GetDPI() override
;
157 double GetDefaultScaleInternal() override
;
158 int32_t LogToPhys(double aValue
);
159 mozilla::DesktopToLayoutDeviceScale
GetDesktopToDeviceScale() override
{
160 if (mozilla::widget::WinUtils::IsPerMonitorDPIAware()) {
161 return mozilla::DesktopToLayoutDeviceScale(1.0);
163 return mozilla::DesktopToLayoutDeviceScale(GetDefaultScaleInternal());
167 void Show(bool aState
) override
;
168 bool IsVisible() const override
;
169 void ConstrainPosition(DesktopIntPoint
&) override
;
170 void SetSizeConstraints(const SizeConstraints
& aConstraints
) override
;
171 void LockAspectRatio(bool aShouldLock
) override
;
172 const SizeConstraints
GetSizeConstraints() override
;
173 void SetInputRegion(const InputRegion
&) override
;
174 void Move(double aX
, double aY
) override
;
175 void Resize(double aWidth
, double aHeight
, bool aRepaint
) override
;
176 void Resize(double aX
, double aY
, double aWidth
, double aHeight
,
177 bool aRepaint
) override
;
178 mozilla::Maybe
<bool> IsResizingNativeWidget() override
;
179 void PlaceBehind(nsTopLevelWidgetZPlacement aPlacement
, nsIWidget
* aWidget
,
180 bool aActivate
) override
;
181 void SetSizeMode(nsSizeMode aMode
) override
;
182 nsSizeMode
SizeMode() override
;
183 void GetWorkspaceID(nsAString
& workspaceID
) override
;
184 void MoveToWorkspace(const nsAString
& workspaceID
) override
;
185 void SuppressAnimation(bool aSuppress
) override
;
186 void Enable(bool aState
) override
;
187 bool IsEnabled() const override
;
188 void SetFocus(Raise
, mozilla::dom::CallerType aCallerType
) override
;
189 LayoutDeviceIntRect
GetBounds() override
;
190 LayoutDeviceIntRect
GetScreenBounds() override
;
191 [[nodiscard
]] nsresult
GetRestoredBounds(LayoutDeviceIntRect
& aRect
) override
;
192 LayoutDeviceIntRect
GetClientBounds() override
;
193 LayoutDeviceIntPoint
GetClientOffset() override
;
194 void SetBackgroundColor(const nscolor
& aColor
) override
;
195 void SetCursor(const Cursor
&) override
;
196 bool PrepareForFullscreenTransition(nsISupports
** aData
) override
;
197 void PerformFullscreenTransition(FullscreenTransitionStage aStage
,
198 uint16_t aDuration
, nsISupports
* aData
,
199 nsIRunnable
* aCallback
) override
;
200 void CleanupFullscreenTransition() override
;
201 nsresult
MakeFullScreen(bool aFullScreen
) override
;
202 void HideWindowChrome(bool aShouldHide
) override
;
203 void Invalidate(bool aEraseBackground
= false, bool aUpdateNCArea
= false,
204 bool aIncludeChildren
= false);
205 void Invalidate(const LayoutDeviceIntRect
& aRect
) override
;
206 void* GetNativeData(uint32_t aDataType
) override
;
207 void FreeNativeData(void* data
, uint32_t aDataType
) override
;
208 nsresult
SetTitle(const nsAString
& aTitle
) override
;
209 void SetIcon(const nsAString
& aIconSpec
) override
;
210 LayoutDeviceIntPoint
WidgetToScreenOffset() override
;
211 LayoutDeviceIntMargin
ClientToWindowMargin() override
;
212 nsresult
DispatchEvent(mozilla::WidgetGUIEvent
* aEvent
,
213 nsEventStatus
& aStatus
) override
;
214 void EnableDragDrop(bool aEnable
) override
;
215 void CaptureMouse(bool aCapture
);
216 void CaptureRollupEvents(bool aDoCapture
) override
;
217 [[nodiscard
]] nsresult
GetAttention(int32_t aCycleCount
) override
;
218 bool HasPendingInputEvent() override
;
219 WindowRenderer
* GetWindowRenderer() override
;
220 void SetCompositorWidgetDelegate(CompositorWidgetDelegate
* delegate
) override
;
221 [[nodiscard
]] nsresult
OnDefaultButtonLoaded(
222 const LayoutDeviceIntRect
& aButtonRect
) override
;
223 nsresult
SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout
,
224 int32_t aNativeKeyCode
,
225 uint32_t aModifierFlags
,
226 const nsAString
& aCharacters
,
227 const nsAString
& aUnmodifiedCharacters
,
228 nsIObserver
* aObserver
) override
;
229 nsresult
SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint
,
230 NativeMouseMessage aNativeMessage
,
231 mozilla::MouseButton aButton
,
232 nsIWidget::Modifiers aModifierFlags
,
233 nsIObserver
* aObserver
) override
;
235 nsresult
SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint
,
236 nsIObserver
* aObserver
) override
{
237 return SynthesizeNativeMouseEvent(
238 aPoint
, NativeMouseMessage::Move
, mozilla::MouseButton::eNotPressed
,
239 nsIWidget::Modifiers::NO_MODIFIERS
, aObserver
);
242 nsresult
SynthesizeNativeMouseScrollEvent(
243 LayoutDeviceIntPoint aPoint
, uint32_t aNativeMessage
, double aDeltaX
,
244 double aDeltaY
, double aDeltaZ
, uint32_t aModifierFlags
,
245 uint32_t aAdditionalFlags
, nsIObserver
* aObserver
) override
;
247 nsresult
SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase
,
248 LayoutDeviceIntPoint aPoint
,
249 double aDeltaX
, double aDeltaY
,
250 int32_t aModifierFlagsn
,
251 nsIObserver
* aObserver
) override
;
253 void SetInputContext(const InputContext
& aContext
,
254 const InputContextAction
& aAction
) override
;
255 InputContext
GetInputContext() override
;
256 TextEventDispatcherListener
* GetNativeTextEventDispatcherListener() override
;
257 void SetTransparencyMode(TransparencyMode aMode
) override
;
258 TransparencyMode
GetTransparencyMode() override
;
259 nsresult
SetNonClientMargins(const LayoutDeviceIntMargin
&) override
;
260 void SetResizeMargin(mozilla::LayoutDeviceIntCoord aResizeMargin
) override
;
261 void UpdateWindowDraggingRegion(
262 const LayoutDeviceIntRegion
& aRegion
) override
;
264 uint32_t GetMaxTouchPoints() const override
;
265 void SetWindowClass(const nsAString
& xulWinType
, const nsAString
& xulWinClass
,
266 const nsAString
& xulWinName
) override
;
271 bool DispatchMouseEvent(mozilla::EventMessage aEventMessage
, WPARAM wParam
,
272 LPARAM lParam
, bool aIsContextMenuKey
,
273 int16_t aButton
, uint16_t aInputSource
,
274 WinPointerInfo
* aPointerInfo
= nullptr,
275 bool aIgnoreAPZ
= false);
276 void DispatchPendingEvents();
277 void DispatchCustomEvent(const nsString
& eventName
);
281 * Return an accessible associated with the window.
283 mozilla::a11y::LocalAccessible
* GetAccessible();
284 #endif // ACCESSIBILITY
289 nsWindow
* GetTopLevelWindow(bool aStopOnDialogOrPopup
);
290 WNDPROC
GetPrevWindowProc() { return mPrevWndProc
.valueOr(nullptr); }
291 WindowHook
& GetWindowHook() { return mWindowHook
; }
292 nsWindow
* GetParentWindow(bool aIncludeOwner
);
297 bool WidgetTypeSupportsAcceleration() override
;
300 bool TouchEventShouldStartDrag(mozilla::EventMessage aEventMessage
,
301 LayoutDeviceIntPoint aEventPoint
);
303 void SetSmallIcon(HICON aIcon
);
304 void SetBigIcon(HICON aIcon
);
305 void SetSmallIconNoData();
306 void SetBigIconNoData();
308 static void SetIsRestoringSession(const bool aIsRestoringSession
) {
309 sIsRestoringSession
= aIsRestoringSession
;
312 bool IsRTL() const { return mIsRTL
; }
315 * AssociateDefaultIMC() associates or disassociates the default IMC for
318 * @param aAssociate TRUE, associates the default IMC with the window.
319 * Otherwise, disassociates the default IMC from the
321 * @return TRUE if this method associated the default IMC with
322 * disassociated window or disassociated the default IMC
323 * from associated window.
324 * Otherwise, i.e., if this method did nothing actually,
327 bool AssociateDefaultIMC(bool aAssociate
);
329 bool HasTaskbarIconBeenCreated() { return mHasTaskbarIconBeenCreated
; }
330 // Called when either the nsWindow or an nsITaskbarTabPreview receives the
331 // noticiation that this window has its icon placed on the taskbar.
332 void SetHasTaskbarIconBeenCreated(bool created
= true) {
333 mHasTaskbarIconBeenCreated
= created
;
336 // Getter/setter for the nsITaskbarWindowPreview for this nsWindow
337 already_AddRefed
<nsITaskbarWindowPreview
> GetTaskbarPreview() {
338 nsCOMPtr
<nsITaskbarWindowPreview
> preview(
339 do_QueryReferent(mTaskbarPreview
));
340 return preview
.forget();
342 void SetTaskbarPreview(nsITaskbarWindowPreview
* preview
) {
343 mTaskbarPreview
= do_GetWeakReference(preview
);
346 void ReparentNativeWidget(nsIWidget
* aNewParent
) override
;
348 // Open file picker tracking
352 bool DestroyCalled() { return mDestroyCalled
; }
355 bool ShouldUseOffMainThreadCompositing() override
;
357 const IMEContext
& DefaultIMC() const { return mDefaultIMC
; }
359 void GetCompositorWidgetInitData(
360 mozilla::widget::CompositorWidgetInitData
* aInitData
) override
;
361 bool IsTouchWindow() const { return mTouchWindow
; }
362 bool SynchronouslyRepaintOnResize() override
;
363 void MaybeDispatchInitialFocusEvent() override
;
365 void LocalesChanged() override
;
367 void NotifyOcclusionState(mozilla::widget::OcclusionState aState
) override
;
368 void MaybeEnableWindowOcclusion(bool aEnable
);
371 * Return the HWND or null for this widget.
373 HWND
GetWindowHandle() {
374 return static_cast<HWND
>(GetNativeData(NS_NATIVE_WINDOW
));
378 * Touch input injection apis
380 nsresult
SynthesizeNativeTouchPoint(uint32_t aPointerId
,
381 TouchPointerState aPointerState
,
382 LayoutDeviceIntPoint aPoint
,
383 double aPointerPressure
,
384 uint32_t aPointerOrientation
,
385 nsIObserver
* aObserver
) override
;
386 nsresult
ClearNativeTouchSequence(nsIObserver
* aObserver
) override
;
388 nsresult
SynthesizeNativePenInput(uint32_t aPointerId
,
389 TouchPointerState aPointerState
,
390 LayoutDeviceIntPoint aPoint
,
391 double aPressure
, uint32_t aRotation
,
392 int32_t aTiltX
, int32_t aTiltY
,
394 nsIObserver
* aObserver
) override
;
397 * WM_APPCOMMAND common handler.
398 * Sends events via NativeKey::HandleAppCommandMessage().
400 bool HandleAppCommandMsg(const MSG
& aAppCommandMsg
, LRESULT
* aRetValue
);
402 const InputContext
& InputContextRef() const { return mInputContext
; }
405 using TimeStamp
= mozilla::TimeStamp
;
406 using TimeDuration
= mozilla::TimeDuration
;
407 using TaskbarWindowPreview
= mozilla::widget::TaskbarWindowPreview
;
408 using NativeKey
= mozilla::widget::NativeKey
;
409 using MSGResult
= mozilla::widget::MSGResult
;
410 using PlatformCompositorWidgetDelegate
=
411 mozilla::widget::PlatformCompositorWidgetDelegate
;
414 // Cached GUID of the virtual desktop this window should be on.
415 // This value may be stale.
417 bool mUpdateIsQueued
= false;
422 enum class PointerType
: uint8_t {
427 PointerInfo(int32_t aPointerId
, LayoutDeviceIntPoint
& aPoint
,
429 : mPointerId(aPointerId
), mPosition(aPoint
), mType(aType
) {}
432 LayoutDeviceIntPoint mPosition
;
438 explicit FrameState(nsWindow
* aWindow
);
440 void ConsumePreXULSkeletonState(bool aWasMaximized
);
442 // Whether we should call ShowWindow with the relevant size mode if needed.
443 // We want to avoid that when Windows is already performing the change for
444 // us (via the SWP_FRAMECHANGED messages).
445 enum class DoShowWindow
: bool { No
, Yes
};
447 void EnsureSizeMode(nsSizeMode
, DoShowWindow
= DoShowWindow::Yes
);
448 void EnsureFullscreenMode(bool, DoShowWindow
= DoShowWindow::Yes
);
449 void OnFrameChanging();
450 void OnFrameChanged();
452 nsSizeMode
GetSizeMode() const;
454 void CheckInvariant() const;
457 void SetSizeModeInternal(nsSizeMode
, DoShowWindow
);
459 nsSizeMode mSizeMode
= nsSizeMode_Normal
;
460 // XXX mLastSizeMode is rather bizarre and needs some documentation.
461 nsSizeMode mLastSizeMode
= nsSizeMode_Normal
;
462 // The old size mode before going into fullscreen mode. This should never
463 // be nsSizeMode_Fullscreen.
464 nsSizeMode mPreFullscreenSizeMode
= nsSizeMode_Normal
;
465 // Whether we're in fullscreen. We need to keep this state out of band,
466 // rather than just using mSizeMode, because a window can be minimized
467 // while fullscreen, and we don't store the fullscreen state anywhere else.
468 bool mFullscreenMode
= false;
472 // Manager for taskbar-hiding. No persistent state.
473 class TaskbarConcealer
;
475 // A magic number to identify the FAKETRACKPOINTSCROLLABLE window created
476 // when the trackpoint hack is enabled.
477 enum { eFakeTrackPointScrollableID
= 0x46545053 };
479 // Used for displayport suppression during window resize
480 enum ResizeState
{ NOT_RESIZING
, IN_SIZEMOVE
, RESIZING
, MOVING
};
482 ~nsWindow() override
;
484 void WindowUsesOMTC() override
;
485 void RegisterTouchWindow() override
;
490 static LRESULT CALLBACK
WindowProc(HWND hWnd
, UINT msg
, WPARAM wParam
,
492 static LRESULT CALLBACK
WindowProcInternal(HWND hWnd
, UINT msg
, WPARAM wParam
,
495 static BOOL CALLBACK
DispatchStarvedPaints(HWND aTopWindow
, LPARAM aMsg
);
496 static BOOL CALLBACK
RegisterTouchForDescendants(HWND aTopWindow
,
498 static BOOL CALLBACK
UnregisterTouchForDescendants(HWND aTopWindow
,
500 static LRESULT CALLBACK
MozSpecialMsgFilter(int code
, WPARAM wParam
,
502 static LRESULT CALLBACK
MozSpecialWndProc(int code
, WPARAM wParam
,
504 static LRESULT CALLBACK
MozSpecialMouseProc(int code
, WPARAM wParam
,
506 static VOID CALLBACK
HookTimerForPopups(HWND hwnd
, UINT uMsg
, UINT idEvent
,
512 LPARAM
lParamToScreen(LPARAM lParam
);
513 LPARAM
lParamToClient(LPARAM lParam
);
515 WPARAM
wParamFromGlobalMouseState();
517 bool AssociateWithNativeWindow();
518 void DissociateFromNativeWindow();
520 bool UpdateNonClientMargins(bool aReflowWindow
= true);
521 void UpdateDarkModeToolbar();
522 void UpdateGetWindowInfoCaptionStatus(bool aActiveCaption
);
524 void InvalidateNonClientRegion();
525 static const wchar_t* GetMainWindowClass();
526 HWND
GetOwnerWnd() const { return ::GetWindow(mWnd
, GW_OWNER
); }
527 bool IsOwnerForegroundWindow() const {
528 HWND owner
= GetOwnerWnd();
529 return owner
&& owner
== ::GetForegroundWindow();
531 bool IsForegroundWindow() const { return mWnd
== ::GetForegroundWindow(); }
532 bool IsPopup() const { return mWindowType
== WindowType::Popup
; }
533 bool IsCloaked() const { return mIsCloaked
; }
536 * Event processing helpers
538 HWND
GetTopLevelForFocus(HWND aCurWnd
);
539 void DispatchFocusToTopLevelWindow(bool aIsActivate
);
540 bool DispatchStandardEvent(mozilla::EventMessage aMsg
);
541 void RelayMouseEvent(UINT aMsg
, WPARAM wParam
, LPARAM lParam
);
542 bool ProcessMessage(UINT msg
, WPARAM
& wParam
, LPARAM
& lParam
,
544 // We wrap this in ProcessMessage so we can log the return value
545 bool ProcessMessageInternal(UINT msg
, WPARAM
& wParam
, LPARAM
& lParam
,
547 bool ExternalHandlerProcessMessage(UINT aMessage
, WPARAM
& aWParam
,
548 LPARAM
& aLParam
, MSGResult
& aResult
);
549 LRESULT
ProcessCharMessage(const MSG
& aMsg
, bool* aEventDispatched
);
550 LRESULT
ProcessKeyUpMessage(const MSG
& aMsg
, bool* aEventDispatched
);
551 LRESULT
ProcessKeyDownMessage(const MSG
& aMsg
, bool* aEventDispatched
);
552 static bool EventIsInsideWindow(
554 mozilla::Maybe
<POINT
> aEventPoint
= mozilla::Nothing());
555 static void PostSleepWakeNotification(const bool aIsSleepMode
);
556 int32_t ClientMarginHitTestPoint(int32_t mx
, int32_t my
);
557 void SetWindowButtonRect(WindowButtonType aButtonType
,
558 const LayoutDeviceIntRect
& aClientRect
) override
{
559 mWindowBtnRect
[aButtonType
] = aClientRect
;
561 TimeStamp
GetMessageTimeStamp(LONG aEventTime
) const;
562 static void UpdateFirstEventTime(DWORD aEventTime
);
563 void FinishLiveResizing(ResizeState aNewState
);
564 mozilla::Maybe
<mozilla::PanGestureInput
> ConvertTouchToPanGesture(
565 const mozilla::MultiTouchInput
& aTouchInput
, PTOUCHINPUT aOriginalEvent
);
566 void DispatchTouchOrPanGestureInput(mozilla::MultiTouchInput
& aTouchInput
,
567 PTOUCHINPUT aOSEvent
);
572 void OnDestroy() override
;
573 bool OnResize(const LayoutDeviceIntSize
& aSize
);
574 void OnSizeModeChange();
575 bool OnGesture(WPARAM wParam
, LPARAM lParam
);
576 bool OnTouch(WPARAM wParam
, LPARAM lParam
);
577 bool OnHotKey(WPARAM wParam
, LPARAM lParam
);
578 bool OnPaint(uint32_t aNestingLevel
);
579 void OnWindowPosChanging(WINDOWPOS
* info
);
580 void OnWindowPosChanged(WINDOWPOS
* wp
);
581 void OnSysColorChanged();
582 void OnDPIChanged(int32_t x
, int32_t y
, int32_t width
, int32_t height
);
583 bool OnPointerEvents(UINT msg
, WPARAM wParam
, LPARAM lParam
);
586 * Function that registers when the user has been active (used for detecting
587 * when the user is idle).
591 int32_t GetHeight(int32_t aProposedHeight
);
594 DWORD
WindowExStyle();
596 static const wchar_t* ChooseWindowClass(WindowType
);
597 // This method registers the given window class, and returns the class name.
598 static const wchar_t* RegisterWindowClass(const wchar_t* aClassName
,
599 UINT aExtraStyle
, LPWSTR aIconID
);
602 * XP and Vista theming support for windows with rounded edges
604 void ClearThemeRegion();
609 static void ScheduleHookTimer(HWND aWnd
, UINT aMsgId
);
610 static void RegisterSpecialDropdownHooks();
611 static void UnregisterSpecialDropdownHooks();
612 static bool GetPopupsToRollup(
613 nsIRollupListener
* aRollupListener
, uint32_t* aPopupsToRollup
,
614 mozilla::Maybe
<POINT
> aEventPoint
= mozilla::Nothing());
615 static bool NeedsToHandleNCActivateDelayed(HWND aWnd
);
616 static bool DealWithPopups(HWND inWnd
, UINT inMsg
, WPARAM inWParam
,
617 LPARAM inLParam
, LRESULT
* outResult
);
620 * Window transparency helpers
622 void SetWindowTranslucencyInner(TransparencyMode aMode
);
623 TransparencyMode
GetWindowTranslucencyInner() const {
624 return mTransparencyMode
;
626 bool IsSimulatedClientArea(int32_t clientX
, int32_t clientY
);
627 bool IsWindowButton(int32_t hitTestResult
);
629 bool DispatchTouchEventFromWMPointer(UINT msg
, LPARAM aLParam
,
630 const WinPointerInfo
& aPointerInfo
,
631 mozilla::MouseButton aButton
);
633 static bool IsAsyncResponseEvent(UINT aMsg
, LRESULT
& aResult
);
634 void IPCWindowProcHandler(UINT
& msg
, WPARAM
& wParam
, LPARAM
& lParam
);
640 static HWND
WindowAtMouse();
641 static bool IsTopLevelMouseExit(HWND aWnd
);
642 LayoutDeviceIntRegion
GetRegionToPaint(bool aForceFullRepaint
, PAINTSTRUCT ps
,
644 nsIWidgetListener
* GetPaintListener();
646 void CreateCompositor() override
;
647 void DestroyCompositor() override
;
648 void RequestFxrOutput() override
;
650 void RecreateDirectManipulationIfNeeded();
651 void ResizeDirectManipulationViewport();
652 void DestroyDirectManipulation();
654 bool NeedsToTrackWindowOcclusionState();
656 void AsyncUpdateWorkspaceID(Desktop
& aDesktop
);
659 static bool HasBogusPopupsDropShadowOnMultiMonitor();
661 static void InitMouseWheelScrollData();
665 static bool InitTouchInjection();
667 bool InjectTouchPoint(uint32_t aId
, LayoutDeviceIntPoint
& aPoint
,
668 POINTER_FLAGS aFlags
, uint32_t aPressure
= 1024,
669 uint32_t aOrientation
= 90);
671 void OnFullscreenChanged(nsSizeMode aOldSizeMode
, bool aFullScreen
);
672 void TryDwmResizeHack();
674 static void OnCloakEvent(HWND aWnd
, bool aCloaked
);
675 void OnCloakChanged(bool aCloaked
);
678 virtual nsresult
SetHiDPIMode(bool aHiDPI
) override
;
679 virtual nsresult
RestoreHiDPIMode() override
;
682 // Get the orientation of the hidden taskbar, on the screen that this window
683 // is on, or Nothing if taskbar isn't hidden.
684 mozilla::Maybe
<UINT
> GetHiddenTaskbarEdge();
686 static bool sTouchInjectInitialized
;
687 static InjectTouchInputPtr sInjectTouchFuncPtr
;
688 static uint32_t sInstanceCount
;
689 static nsWindow
* sCurrentWindow
;
690 static bool sIsOleInitialized
;
691 static Cursor sCurrentCursor
;
692 static bool sJustGotDeactivate
;
693 static bool sJustGotActivate
;
694 static bool sIsInMouseCapture
;
695 static bool sIsRestoringSession
;
697 // Message postponement hack. See the definition-site of
698 // WndProcUrgentInvocation::sDepth for details.
699 struct MOZ_STACK_CLASS WndProcUrgentInvocation
{
701 Marker() { ++sDepth
; }
702 ~Marker() { --sDepth
; }
704 inline static bool IsActive() { return sDepth
> 0; }
705 static size_t sDepth
;
708 // Hook Data Members for Dropdowns. sProcessHook Tells the
709 // hook methods whether they should be processing the hook
711 static HHOOK sMsgFilterHook
;
712 static HHOOK sCallProcHook
;
713 static HHOOK sCallMouseHook
;
714 static bool sProcessHook
;
715 static UINT sRollupMsgId
;
716 static HWND sRollupMsgWnd
;
717 static UINT sHookTimerId
;
719 // Used to prevent dispatching mouse events that do not originate from user
721 static POINT sLastMouseMovePoint
;
723 nsClassHashtable
<nsUint32HashKey
, PointerInfo
> mActivePointers
;
725 // This is used by SynthesizeNativeTouchPoint to maintain state between
726 // multiple synthesized points, in the case where we can't call InjectTouch
728 mozilla::UniquePtr
<mozilla::MultiTouchInput
> mSynthesizedTouchInput
;
730 InputContext mInputContext
;
732 nsCOMPtr
<nsIWidget
> mParent
;
733 nsIntSize mLastSize
= nsIntSize(0, 0);
734 nsIntPoint mLastPoint
;
736 HWND mTransitionWnd
= nullptr;
737 mozilla::Maybe
<WNDPROC
> mPrevWndProc
;
739 IMEContext mDefaultIMC
;
740 HDEVNOTIFY mDeviceNotifyHandle
= nullptr;
741 bool mIsTopWidgetWindow
= false;
742 bool mInDtor
= false;
743 bool mIsVisible
= false;
744 bool mIsCloaked
= false;
745 bool mTouchWindow
= false;
746 bool mDisplayPanFeedback
= false;
747 bool mHideChrome
= false;
749 bool mMousePresent
= false;
750 bool mSimulatedClientArea
= false;
751 bool mDestroyCalled
= false;
752 bool mOpeningAnimationSuppressed
;
754 bool mIsEarlyBlankWindow
= false;
755 bool mIsShowingPreXULSkeletonUI
= false;
756 bool mResizable
= false;
757 // Whether we're an alert window. Alert windows don't have taskbar icons and
758 // don't steal focus from other windows when opened. They're also expected to
759 // be of type WindowType::Dialog.
760 bool mIsAlert
= false;
761 bool mIsPerformingDwmFlushHack
= false;
762 bool mDraggingWindowWithMouse
= false;
763 DWORD_PTR mOldStyle
= 0;
764 DWORD_PTR mOldExStyle
= 0;
765 nsNativeDragTarget
* mNativeDragTarget
= nullptr;
766 HKL mLastKeyboardLayout
= 0;
767 mozilla::CheckInvariantWrapper
<FrameState
> mFrameState
;
768 WindowHook mWindowHook
;
769 uint32_t mPickerDisplayCount
= 0;
770 HICON mIconSmall
= nullptr;
771 HICON mIconBig
= nullptr;
772 HWND mLastKillFocusWindow
= nullptr;
773 PlatformCompositorWidgetDelegate
* mCompositorWidgetDelegate
= nullptr;
775 LayoutDeviceIntMargin
NonClientSizeMargin() const {
776 return NonClientSizeMargin(mNonClientOffset
);
778 LayoutDeviceIntMargin
NonClientSizeMargin(
779 const LayoutDeviceIntMargin
& aNonClientOffset
) const;
780 LayoutDeviceIntMargin
NormalWindowNonClientOffset() const;
782 // Non-client margin settings
783 // Pre-calculated outward offset applied to default frames
784 LayoutDeviceIntMargin mNonClientOffset
;
785 // Margins set by the owner
786 LayoutDeviceIntMargin mNonClientMargins
;
787 // Margins we'd like to set once chrome is reshown:
788 LayoutDeviceIntMargin mFutureMarginsOnceChromeShows
;
789 // Indicates we need to apply margins once toggling chrome into showing:
790 bool mFutureMarginsToUse
= false;
792 // Indicates custom frames are enabled
793 bool mCustomNonClient
= false;
794 // Indicates custom resize margins are in effect
795 bool mUseResizeMarginOverrides
= false;
796 // Width of the left and right portions of the resize region
797 mozilla::LayoutDeviceIntCoord mHorResizeMargin
;
798 // Height of the top and bottom portions of the resize region
799 mozilla::LayoutDeviceIntCoord mVertResizeMargin
;
800 // Height of the caption plus border
801 mozilla::LayoutDeviceIntCoord mCaptionHeight
;
803 // not yet set, will be calculated on first use
804 double mDefaultScale
= -1.0;
806 // not yet set, will be calculated on first use
807 float mAspectRatio
= 0.0;
809 nsCOMPtr
<nsIUserIdleServiceInternal
> mIdleService
;
811 // Draggable titlebar region maintained by UpdateWindowDraggingRegion
812 LayoutDeviceIntRegion mDraggableRegion
;
815 LayoutDeviceIntRect mLastPaintBounds
;
817 ResizeState mResizeState
= NOT_RESIZING
;
820 TransparencyMode mTransparencyMode
= TransparencyMode::Opaque
;
821 nsIntRegion mPossiblyTransparentRegion
;
823 // Win7 Gesture processing and management
824 nsWinGesture mGesture
;
826 // Weak ref to the nsITaskbarWindowPreview associated with this window
827 nsWeakPtr mTaskbarPreview
= nullptr;
829 // The input region that determines whether mouse events should be ignored
830 // and pass through to the window below. This is currently only used for
832 InputRegion mInputRegion
;
834 // True if the taskbar (possibly through the tab preview) tells us that the
835 // icon has been created on the taskbar.
836 bool mHasTaskbarIconBeenCreated
= false;
838 // Whether we're in the process of sending a WM_SETTEXT ourselves
839 bool mSendingSetText
= false;
841 // Whether we were created as a child window (aka ChildWindow) or not.
842 bool mIsChildWindow
: 1;
844 int32_t mCachedHitTestResult
= 0;
846 // The point in time at which the last paint completed. We use this to avoid
847 // painting too rapidly in response to frequent input events.
848 TimeStamp mLastPaintEndTime
;
850 // Caching for hit test results (in client coordinates)
851 LayoutDeviceIntPoint mCachedHitTestPoint
;
852 TimeStamp mCachedHitTestTime
;
854 RefPtr
<mozilla::widget::InProcessWinCompositorWidget
> mBasicLayersSurface
;
856 double mSizeConstraintsScale
; // scale in effect when setting constraints
858 // Will be calculated when layer manager is created.
859 int32_t mMaxTextureSize
= -1;
861 // Pointer events processing and management
862 WinPointerEvents mPointerEvents
;
864 ScreenPoint mLastPanGestureFocus
;
866 // When true, used to indicate an async call to RequestFxrOutput to the GPU
867 // process after the Compositor is created
868 bool mRequestFxrOutputPending
= false;
870 // A stack based class used in DispatchMouseEvent() to tell whether we should
871 // NOT open context menu when we receives WM_CONTEXTMENU after the
872 // DispatchMouseEvent calls.
873 // This class now works only in the case where a mouse up event happened in
874 // the overscroll gutter.
875 class MOZ_STACK_CLASS ContextMenuPreventer final
{
877 explicit ContextMenuPreventer(nsWindow
* aWindow
)
878 : mWindow(aWindow
), mNeedsToPreventContextMenu(false){};
879 ~ContextMenuPreventer() {
880 mWindow
->mNeedsToPreventContextMenu
= mNeedsToPreventContextMenu
;
882 void Update(const mozilla::WidgetMouseEvent
& aEvent
,
883 const nsIWidget::ContentAndAPZEventStatus
& aEventStatus
);
887 bool mNeedsToPreventContextMenu
= false;
889 friend class ContextMenuPreventer
;
890 bool mNeedsToPreventContextMenu
= false;
892 mozilla::UniquePtr
<mozilla::widget::DirectManipulationOwner
> mDmOwner
;
894 // Client rect for minimize, maximize and close buttons.
895 mozilla::EnumeratedArray
<WindowButtonType
, WindowButtonType::Count
,
899 mozilla::DataMutex
<Desktop
> mDesktopId
;
901 // If set, indicates the edge of the NC region we should clear to black
902 // on next paint. One of: ABE_TOP, ABE_BOTTOM, ABE_LEFT or ABE_RIGHT.
903 mozilla::Maybe
<UINT
> mClearNCEdge
;
905 friend class nsWindowGfx
;
907 static constexpr int kHiddenTaskbarSize
= 2;
910 #endif // WIDGET_WINDOWS_NSWINDOW_H_