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}};
88 EXTERN_C
const IID IID_IVirtualDesktopManager
;
89 MIDL_INTERFACE("a5cd92ff-29be-454c-8d04-d82879fb3f1b")
90 IVirtualDesktopManager
: public IUnknown
{
92 virtual HRESULT STDMETHODCALLTYPE
IsWindowOnCurrentVirtualDesktop(
93 __RPC__in HWND topLevelWindow
, __RPC__out BOOL
* onCurrentDesktop
) = 0;
94 virtual HRESULT STDMETHODCALLTYPE
GetWindowDesktopId(
95 __RPC__in HWND topLevelWindow
, __RPC__out GUID
* desktopId
) = 0;
96 virtual HRESULT STDMETHODCALLTYPE
MoveWindowToDesktop(
97 __RPC__in HWND topLevelWindow
, __RPC__in REFGUID desktopId
) = 0;
101 __CRT_UUID_DECL(IVirtualDesktopManager
, 0xa5cd92ff, 0x29be, 0x454c, 0x8d, 0x04,
102 0xd8, 0x28, 0x79, 0xfb, 0x3f, 0x1b)
106 * Native WIN32 window wrapper.
109 class nsWindow final
: public nsBaseWidget
{
111 using WindowHook
= mozilla::widget::WindowHook
;
112 using IMEContext
= mozilla::widget::IMEContext
;
113 using WidgetEventTime
= mozilla::WidgetEventTime
;
115 NS_INLINE_DECL_REFCOUNTING_INHERITED(nsWindow
, nsBaseWidget
)
117 explicit nsWindow(bool aIsChildWindow
= false);
119 void SendAnAPZEvent(mozilla::InputData
& aEvent
);
122 * Init a standard gecko event for this widget.
123 * @param aEvent the event to initialize.
124 * @param aPoint message position in physical coordinates.
126 void InitEvent(mozilla::WidgetGUIEvent
& aEvent
,
127 LayoutDeviceIntPoint
* aPoint
= nullptr);
130 * Returns WidgetEventTime instance which is initialized with current message
133 WidgetEventTime
CurrentMessageWidgetEventTime() const;
136 * Dispatch a gecko keyboard event for this widget. This
137 * is called by KeyboardLayout to dispatch gecko events.
138 * Returns true if it's consumed. Otherwise, false.
140 bool DispatchKeyboardEvent(mozilla::WidgetKeyboardEvent
* aEvent
);
143 * Dispatch a gecko wheel event for this widget. This
144 * is called by ScrollHandler to dispatch gecko events.
145 * Returns true if it's consumed. Otherwise, false.
147 bool DispatchWheelEvent(mozilla::WidgetWheelEvent
* aEvent
);
150 * Dispatch a gecko content command event for this widget. This
151 * is called by ScrollHandler to dispatch gecko events.
152 * Returns true if it's consumed. Otherwise, false.
154 bool DispatchContentCommandEvent(mozilla::WidgetContentCommandEvent
* aEvent
);
157 * Return the parent window, if it exists.
159 nsWindow
* GetParentWindowBase(bool aIncludeOwner
);
162 * Return true if this is a top level widget.
164 bool IsTopLevelWidget() { return mIsTopWidgetWindow
; }
166 // nsIWidget interface
167 using nsBaseWidget::Create
; // for Create signature not overridden here
168 [[nodiscard
]] nsresult
Create(nsIWidget
* aParent
,
169 nsNativeWidget aNativeParent
,
170 const LayoutDeviceIntRect
& aRect
,
171 InitData
* aInitData
= nullptr) override
;
172 void Destroy() override
;
173 void SetParent(nsIWidget
* aNewParent
) override
;
174 nsIWidget
* GetParent(void) override
;
175 float GetDPI() override
;
176 double GetDefaultScaleInternal() override
;
177 int32_t LogToPhys(double aValue
);
178 mozilla::DesktopToLayoutDeviceScale
GetDesktopToDeviceScale() override
{
179 if (mozilla::widget::WinUtils::IsPerMonitorDPIAware()) {
180 return mozilla::DesktopToLayoutDeviceScale(1.0);
182 return mozilla::DesktopToLayoutDeviceScale(GetDefaultScaleInternal());
186 void Show(bool aState
) override
;
187 bool IsVisible() const override
;
188 void ConstrainPosition(bool aAllowSlop
, int32_t* aX
, int32_t* aY
) override
;
189 void SetSizeConstraints(const SizeConstraints
& aConstraints
) override
;
190 void LockAspectRatio(bool aShouldLock
) override
;
191 const SizeConstraints
GetSizeConstraints() override
;
192 void SetInputRegion(const InputRegion
&) override
;
193 void Move(double aX
, double aY
) override
;
194 void Resize(double aWidth
, double aHeight
, bool aRepaint
) override
;
195 void Resize(double aX
, double aY
, double aWidth
, double aHeight
,
196 bool aRepaint
) override
;
197 mozilla::Maybe
<bool> IsResizingNativeWidget() override
;
198 void PlaceBehind(nsTopLevelWidgetZPlacement aPlacement
, nsIWidget
* aWidget
,
199 bool aActivate
) override
;
200 void SetSizeMode(nsSizeMode aMode
) override
;
201 nsSizeMode
SizeMode() override
;
202 void GetWorkspaceID(nsAString
& workspaceID
) override
;
203 void MoveToWorkspace(const nsAString
& workspaceID
) override
;
204 void SuppressAnimation(bool aSuppress
) override
;
205 void Enable(bool aState
) override
;
206 bool IsEnabled() const override
;
207 void SetFocus(Raise
, mozilla::dom::CallerType aCallerType
) override
;
208 LayoutDeviceIntRect
GetBounds() override
;
209 LayoutDeviceIntRect
GetScreenBounds() override
;
210 [[nodiscard
]] nsresult
GetRestoredBounds(LayoutDeviceIntRect
& aRect
) override
;
211 LayoutDeviceIntRect
GetClientBounds() override
;
212 LayoutDeviceIntPoint
GetClientOffset() override
;
213 void SetBackgroundColor(const nscolor
& aColor
) override
;
214 void SetCursor(const Cursor
&) override
;
215 bool PrepareForFullscreenTransition(nsISupports
** aData
) override
;
216 void PerformFullscreenTransition(FullscreenTransitionStage aStage
,
217 uint16_t aDuration
, nsISupports
* aData
,
218 nsIRunnable
* aCallback
) override
;
219 void CleanupFullscreenTransition() override
;
220 nsresult
MakeFullScreen(bool aFullScreen
) override
;
221 void HideWindowChrome(bool aShouldHide
) override
;
222 void Invalidate(bool aEraseBackground
= false, bool aUpdateNCArea
= false,
223 bool aIncludeChildren
= false);
224 void Invalidate(const LayoutDeviceIntRect
& aRect
) override
;
225 void* GetNativeData(uint32_t aDataType
) override
;
226 void SetNativeData(uint32_t aDataType
, uintptr_t aVal
) override
;
227 void FreeNativeData(void* data
, uint32_t aDataType
) override
;
228 nsresult
SetTitle(const nsAString
& aTitle
) override
;
229 void SetIcon(const nsAString
& aIconSpec
) override
;
230 LayoutDeviceIntPoint
WidgetToScreenOffset() override
;
231 LayoutDeviceIntMargin
ClientToWindowMargin() override
;
232 nsresult
DispatchEvent(mozilla::WidgetGUIEvent
* aEvent
,
233 nsEventStatus
& aStatus
) override
;
234 void EnableDragDrop(bool aEnable
) override
;
235 void CaptureMouse(bool aCapture
);
236 void CaptureRollupEvents(bool aDoCapture
) override
;
237 [[nodiscard
]] nsresult
GetAttention(int32_t aCycleCount
) override
;
238 bool HasPendingInputEvent() override
;
239 WindowRenderer
* GetWindowRenderer() override
;
240 void SetCompositorWidgetDelegate(CompositorWidgetDelegate
* delegate
) override
;
241 [[nodiscard
]] nsresult
OnDefaultButtonLoaded(
242 const LayoutDeviceIntRect
& aButtonRect
) override
;
243 nsresult
SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout
,
244 int32_t aNativeKeyCode
,
245 uint32_t aModifierFlags
,
246 const nsAString
& aCharacters
,
247 const nsAString
& aUnmodifiedCharacters
,
248 nsIObserver
* aObserver
) override
;
249 nsresult
SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint
,
250 NativeMouseMessage aNativeMessage
,
251 mozilla::MouseButton aButton
,
252 nsIWidget::Modifiers aModifierFlags
,
253 nsIObserver
* aObserver
) override
;
255 nsresult
SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint
,
256 nsIObserver
* aObserver
) override
{
257 return SynthesizeNativeMouseEvent(
258 aPoint
, NativeMouseMessage::Move
, mozilla::MouseButton::eNotPressed
,
259 nsIWidget::Modifiers::NO_MODIFIERS
, aObserver
);
262 nsresult
SynthesizeNativeMouseScrollEvent(
263 LayoutDeviceIntPoint aPoint
, uint32_t aNativeMessage
, double aDeltaX
,
264 double aDeltaY
, double aDeltaZ
, uint32_t aModifierFlags
,
265 uint32_t aAdditionalFlags
, nsIObserver
* aObserver
) override
;
267 nsresult
SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase
,
268 LayoutDeviceIntPoint aPoint
,
269 double aDeltaX
, double aDeltaY
,
270 int32_t aModifierFlagsn
,
271 nsIObserver
* aObserver
) override
;
273 void SetInputContext(const InputContext
& aContext
,
274 const InputContextAction
& aAction
) override
;
275 InputContext
GetInputContext() override
;
276 TextEventDispatcherListener
* GetNativeTextEventDispatcherListener() override
;
277 void SetTransparencyMode(TransparencyMode aMode
) override
;
278 TransparencyMode
GetTransparencyMode() override
;
279 void UpdateOpaqueRegion(const LayoutDeviceIntRegion
& aOpaqueRegion
) override
;
280 nsresult
SetNonClientMargins(const LayoutDeviceIntMargin
&) override
;
281 void SetResizeMargin(mozilla::LayoutDeviceIntCoord aResizeMargin
) override
;
282 void SetDrawsInTitlebar(bool aState
) override
;
283 void UpdateWindowDraggingRegion(
284 const LayoutDeviceIntRegion
& aRegion
) override
;
286 void UpdateThemeGeometries(
287 const nsTArray
<ThemeGeometry
>& aThemeGeometries
) override
;
288 uint32_t GetMaxTouchPoints() const override
;
289 void SetWindowClass(const nsAString
& xulWinType
, const nsAString
& xulWinClass
,
290 const nsAString
& xulWinName
) override
;
295 bool DispatchMouseEvent(mozilla::EventMessage aEventMessage
, WPARAM wParam
,
296 LPARAM lParam
, bool aIsContextMenuKey
,
297 int16_t aButton
, uint16_t aInputSource
,
298 WinPointerInfo
* aPointerInfo
= nullptr,
299 bool aIgnoreAPZ
= false);
300 void DispatchPendingEvents();
301 void DispatchCustomEvent(const nsString
& eventName
);
305 * Return an accessible associated with the window.
307 mozilla::a11y::LocalAccessible
* GetAccessible();
308 #endif // ACCESSIBILITY
313 nsWindow
* GetTopLevelWindow(bool aStopOnDialogOrPopup
);
314 WNDPROC
GetPrevWindowProc() { return mPrevWndProc
.valueOr(nullptr); }
315 WindowHook
& GetWindowHook() { return mWindowHook
; }
316 nsWindow
* GetParentWindow(bool aIncludeOwner
);
321 bool WidgetTypeSupportsAcceleration() override
;
324 bool TouchEventShouldStartDrag(mozilla::EventMessage aEventMessage
,
325 LayoutDeviceIntPoint aEventPoint
);
327 void SetSmallIcon(HICON aIcon
);
328 void SetBigIcon(HICON aIcon
);
329 void SetSmallIconNoData();
330 void SetBigIconNoData();
332 static void SetIsRestoringSession(const bool aIsRestoringSession
) {
333 sIsRestoringSession
= aIsRestoringSession
;
337 * AssociateDefaultIMC() associates or disassociates the default IMC for
340 * @param aAssociate TRUE, associates the default IMC with the window.
341 * Otherwise, disassociates the default IMC from the
343 * @return TRUE if this method associated the default IMC with
344 * disassociated window or disassociated the default IMC
345 * from associated window.
346 * Otherwise, i.e., if this method did nothing actually,
349 bool AssociateDefaultIMC(bool aAssociate
);
351 bool HasTaskbarIconBeenCreated() { return mHasTaskbarIconBeenCreated
; }
352 // Called when either the nsWindow or an nsITaskbarTabPreview receives the
353 // noticiation that this window has its icon placed on the taskbar.
354 void SetHasTaskbarIconBeenCreated(bool created
= true) {
355 mHasTaskbarIconBeenCreated
= created
;
358 // Getter/setter for the nsITaskbarWindowPreview for this nsWindow
359 already_AddRefed
<nsITaskbarWindowPreview
> GetTaskbarPreview() {
360 nsCOMPtr
<nsITaskbarWindowPreview
> preview(
361 do_QueryReferent(mTaskbarPreview
));
362 return preview
.forget();
364 void SetTaskbarPreview(nsITaskbarWindowPreview
* preview
) {
365 mTaskbarPreview
= do_GetWeakReference(preview
);
368 void ReparentNativeWidget(nsIWidget
* aNewParent
) override
;
370 // Open file picker tracking
374 bool DestroyCalled() { return mDestroyCalled
; }
377 bool ShouldUseOffMainThreadCompositing() override
;
379 const IMEContext
& DefaultIMC() const { return mDefaultIMC
; }
381 void GetCompositorWidgetInitData(
382 mozilla::widget::CompositorWidgetInitData
* aInitData
) override
;
383 bool IsTouchWindow() const { return mTouchWindow
; }
384 bool SynchronouslyRepaintOnResize() override
;
385 void MaybeDispatchInitialFocusEvent() override
;
387 void LocalesChanged() override
;
389 void NotifyOcclusionState(mozilla::widget::OcclusionState aState
) override
;
390 void MaybeEnableWindowOcclusion(bool aEnable
);
393 * Return the HWND or null for this widget.
395 HWND
GetWindowHandle() {
396 return static_cast<HWND
>(GetNativeData(NS_NATIVE_WINDOW
));
400 * Touch input injection apis
402 nsresult
SynthesizeNativeTouchPoint(uint32_t aPointerId
,
403 TouchPointerState aPointerState
,
404 LayoutDeviceIntPoint aPoint
,
405 double aPointerPressure
,
406 uint32_t aPointerOrientation
,
407 nsIObserver
* aObserver
) override
;
408 nsresult
ClearNativeTouchSequence(nsIObserver
* aObserver
) override
;
410 nsresult
SynthesizeNativePenInput(uint32_t aPointerId
,
411 TouchPointerState aPointerState
,
412 LayoutDeviceIntPoint aPoint
,
413 double aPressure
, uint32_t aRotation
,
414 int32_t aTiltX
, int32_t aTiltY
,
416 nsIObserver
* aObserver
) override
;
419 * WM_APPCOMMAND common handler.
420 * Sends events via NativeKey::HandleAppCommandMessage().
422 bool HandleAppCommandMsg(const MSG
& aAppCommandMsg
, LRESULT
* aRetValue
);
424 const InputContext
& InputContextRef() const { return mInputContext
; }
427 using TimeStamp
= mozilla::TimeStamp
;
428 using TimeDuration
= mozilla::TimeDuration
;
429 using TaskbarWindowPreview
= mozilla::widget::TaskbarWindowPreview
;
430 using NativeKey
= mozilla::widget::NativeKey
;
431 using MSGResult
= mozilla::widget::MSGResult
;
432 using PlatformCompositorWidgetDelegate
=
433 mozilla::widget::PlatformCompositorWidgetDelegate
;
436 // Cached GUID of the virtual desktop this window should be on.
437 // This value may be stale.
439 bool mUpdateIsQueued
= false;
444 enum class PointerType
: uint8_t {
449 PointerInfo(int32_t aPointerId
, LayoutDeviceIntPoint
& aPoint
,
451 : mPointerId(aPointerId
), mPosition(aPoint
), mType(aType
) {}
454 LayoutDeviceIntPoint mPosition
;
460 explicit FrameState(nsWindow
* aWindow
);
462 void ConsumePreXULSkeletonState(bool aWasMaximized
);
464 // Whether we should call ShowWindow with the relevant size mode if needed.
465 // We want to avoid that when Windows is already performing the change for
466 // us (via the SWP_FRAMECHANGED messages).
467 enum class DoShowWindow
: bool { No
, Yes
};
469 void EnsureSizeMode(nsSizeMode
, DoShowWindow
= DoShowWindow::Yes
);
470 void EnsureFullscreenMode(bool, DoShowWindow
= DoShowWindow::Yes
);
471 void OnFrameChanging();
472 void OnFrameChanged();
474 nsSizeMode
GetSizeMode() const;
476 void CheckInvariant() const;
479 void SetSizeModeInternal(nsSizeMode
, DoShowWindow
);
481 nsSizeMode mSizeMode
= nsSizeMode_Normal
;
482 // XXX mLastSizeMode is rather bizarre and needs some documentation.
483 nsSizeMode mLastSizeMode
= nsSizeMode_Normal
;
484 // The old size mode before going into fullscreen mode. This should never
485 // be nsSizeMode_Fullscreen.
486 nsSizeMode mPreFullscreenSizeMode
= nsSizeMode_Normal
;
487 // Whether we're in fullscreen. We need to keep this state out of band,
488 // rather than just using mSizeMode, because a window can be minimized
489 // while fullscreen, and we don't store the fullscreen state anywhere else.
490 bool mFullscreenMode
= false;
494 // Manager for taskbar-hiding. No persistent state.
495 class TaskbarConcealer
;
497 // A magic number to identify the FAKETRACKPOINTSCROLLABLE window created
498 // when the trackpoint hack is enabled.
499 enum { eFakeTrackPointScrollableID
= 0x46545053 };
501 // Used for displayport suppression during window resize
502 enum ResizeState
{ NOT_RESIZING
, IN_SIZEMOVE
, RESIZING
, MOVING
};
504 ~nsWindow() override
;
506 void WindowUsesOMTC() override
;
507 void RegisterTouchWindow() override
;
512 static LRESULT CALLBACK
WindowProc(HWND hWnd
, UINT msg
, WPARAM wParam
,
514 static LRESULT CALLBACK
WindowProcInternal(HWND hWnd
, UINT msg
, WPARAM wParam
,
517 static BOOL CALLBACK
BroadcastMsgToChildren(HWND aWnd
, LPARAM aMsg
);
518 static BOOL CALLBACK
BroadcastMsg(HWND aTopWindow
, LPARAM aMsg
);
519 static BOOL CALLBACK
DispatchStarvedPaints(HWND aTopWindow
, LPARAM aMsg
);
520 static BOOL CALLBACK
RegisterTouchForDescendants(HWND aTopWindow
,
522 static BOOL CALLBACK
UnregisterTouchForDescendants(HWND aTopWindow
,
524 static LRESULT CALLBACK
MozSpecialMsgFilter(int code
, WPARAM wParam
,
526 static LRESULT CALLBACK
MozSpecialWndProc(int code
, WPARAM wParam
,
528 static LRESULT CALLBACK
MozSpecialMouseProc(int code
, WPARAM wParam
,
530 static VOID CALLBACK
HookTimerForPopups(HWND hwnd
, UINT uMsg
, UINT idEvent
,
536 LPARAM
lParamToScreen(LPARAM lParam
);
537 LPARAM
lParamToClient(LPARAM lParam
);
539 WPARAM
wParamFromGlobalMouseState();
541 bool AssociateWithNativeWindow();
542 void DissociateFromNativeWindow();
544 bool UpdateNonClientMargins(bool aReflowWindow
= true);
545 void UpdateDarkModeToolbar();
546 void UpdateGetWindowInfoCaptionStatus(bool aActiveCaption
);
548 void InvalidateNonClientRegion();
549 HRGN
ExcludeNonClientFromPaintRegion(HRGN aRegion
);
550 static const wchar_t* GetMainWindowClass();
551 bool HasGlass() const {
552 return mTransparencyMode
== TransparencyMode::BorderlessGlass
;
554 HWND
GetOwnerWnd() const { return ::GetWindow(mWnd
, GW_OWNER
); }
555 bool IsOwnerForegroundWindow() const {
556 HWND owner
= GetOwnerWnd();
557 return owner
&& owner
== ::GetForegroundWindow();
559 bool IsPopup() const { return mWindowType
== WindowType::Popup
; }
560 bool IsCloaked() const { return mIsCloaked
; }
563 * Event processing helpers
565 HWND
GetTopLevelForFocus(HWND aCurWnd
);
566 void DispatchFocusToTopLevelWindow(bool aIsActivate
);
567 bool DispatchStandardEvent(mozilla::EventMessage aMsg
);
568 void RelayMouseEvent(UINT aMsg
, WPARAM wParam
, LPARAM lParam
);
569 bool ProcessMessage(UINT msg
, WPARAM
& wParam
, LPARAM
& lParam
,
571 // We wrap this in ProcessMessage so we can log the return value
572 bool ProcessMessageInternal(UINT msg
, WPARAM
& wParam
, LPARAM
& lParam
,
574 bool ExternalHandlerProcessMessage(UINT aMessage
, WPARAM
& aWParam
,
575 LPARAM
& aLParam
, MSGResult
& aResult
);
576 LRESULT
ProcessCharMessage(const MSG
& aMsg
, bool* aEventDispatched
);
577 LRESULT
ProcessKeyUpMessage(const MSG
& aMsg
, bool* aEventDispatched
);
578 LRESULT
ProcessKeyDownMessage(const MSG
& aMsg
, bool* aEventDispatched
);
579 static bool EventIsInsideWindow(
581 mozilla::Maybe
<POINT
> aEventPoint
= mozilla::Nothing());
582 static void PostSleepWakeNotification(const bool aIsSleepMode
);
583 int32_t ClientMarginHitTestPoint(int32_t mx
, int32_t my
);
584 void SetWindowButtonRect(WindowButtonType aButtonType
,
585 const LayoutDeviceIntRect
& aClientRect
) override
{
586 mWindowBtnRect
[aButtonType
] = aClientRect
;
588 TimeStamp
GetMessageTimeStamp(LONG aEventTime
) const;
589 static void UpdateFirstEventTime(DWORD aEventTime
);
590 void FinishLiveResizing(ResizeState aNewState
);
591 mozilla::Maybe
<mozilla::PanGestureInput
> ConvertTouchToPanGesture(
592 const mozilla::MultiTouchInput
& aTouchInput
, PTOUCHINPUT aOriginalEvent
);
593 void DispatchTouchOrPanGestureInput(mozilla::MultiTouchInput
& aTouchInput
,
594 PTOUCHINPUT aOSEvent
);
599 void OnDestroy() override
;
600 bool OnResize(const LayoutDeviceIntSize
& aSize
);
601 void OnSizeModeChange();
602 bool OnGesture(WPARAM wParam
, LPARAM lParam
);
603 bool OnTouch(WPARAM wParam
, LPARAM lParam
);
604 bool OnHotKey(WPARAM wParam
, LPARAM lParam
);
605 bool OnPaint(HDC aDC
, uint32_t aNestingLevel
);
606 void OnWindowPosChanging(WINDOWPOS
* info
);
607 void OnWindowPosChanged(WINDOWPOS
* wp
);
608 void OnSysColorChanged();
609 void OnDPIChanged(int32_t x
, int32_t y
, int32_t width
, int32_t height
);
610 bool OnPointerEvents(UINT msg
, WPARAM wParam
, LPARAM lParam
);
613 * Function that registers when the user has been active (used for detecting
614 * when the user is idle).
618 int32_t GetHeight(int32_t aProposedHeight
);
621 DWORD
WindowExStyle();
623 static const wchar_t* ChooseWindowClass(WindowType
, bool aForMenupopupFrame
);
624 // This method registers the given window class, and returns the class name.
625 static const wchar_t* RegisterWindowClass(const wchar_t* aClassName
,
626 UINT aExtraStyle
, LPWSTR aIconID
);
629 * XP and Vista theming support for windows with rounded edges
631 void ClearThemeRegion();
636 static void ScheduleHookTimer(HWND aWnd
, UINT aMsgId
);
637 static void RegisterSpecialDropdownHooks();
638 static void UnregisterSpecialDropdownHooks();
639 static bool GetPopupsToRollup(
640 nsIRollupListener
* aRollupListener
, uint32_t* aPopupsToRollup
,
641 mozilla::Maybe
<POINT
> aEventPoint
= mozilla::Nothing());
642 static bool NeedsToHandleNCActivateDelayed(HWND aWnd
);
643 static bool DealWithPopups(HWND inWnd
, UINT inMsg
, WPARAM inWParam
,
644 LPARAM inLParam
, LRESULT
* outResult
);
647 * Window transparency helpers
649 void SetWindowTranslucencyInner(TransparencyMode aMode
);
650 TransparencyMode
GetWindowTranslucencyInner() const {
651 return mTransparencyMode
;
654 bool IsSimulatedClientArea(int32_t clientX
, int32_t clientY
);
655 bool IsWindowButton(int32_t hitTestResult
);
657 bool DispatchTouchEventFromWMPointer(UINT msg
, LPARAM aLParam
,
658 const WinPointerInfo
& aPointerInfo
,
659 mozilla::MouseButton aButton
);
661 static bool IsAsyncResponseEvent(UINT aMsg
, LRESULT
& aResult
);
662 void IPCWindowProcHandler(UINT
& msg
, WPARAM
& wParam
, LPARAM
& lParam
);
668 static HWND
WindowAtMouse();
669 static bool IsTopLevelMouseExit(HWND aWnd
);
670 LayoutDeviceIntRegion
GetRegionToPaint(bool aForceFullRepaint
, PAINTSTRUCT ps
,
672 nsIWidgetListener
* GetPaintListener();
674 void AddWindowOverlayWebRenderCommands(
675 mozilla::layers::WebRenderBridgeChild
* aWrBridge
,
676 mozilla::wr::DisplayListBuilder
& aBuilder
,
677 mozilla::wr::IpcResourceUpdateQueue
& aResourceUpdates
) override
;
679 void CreateCompositor() override
;
680 void DestroyCompositor() override
;
681 void RequestFxrOutput() override
;
683 void RecreateDirectManipulationIfNeeded();
684 void ResizeDirectManipulationViewport();
685 void DestroyDirectManipulation();
687 bool NeedsToTrackWindowOcclusionState();
689 void AsyncUpdateWorkspaceID(Desktop
& aDesktop
);
692 static bool HasBogusPopupsDropShadowOnMultiMonitor();
694 static void InitMouseWheelScrollData();
698 static bool InitTouchInjection();
700 bool InjectTouchPoint(uint32_t aId
, LayoutDeviceIntPoint
& aPoint
,
701 POINTER_FLAGS aFlags
, uint32_t aPressure
= 1024,
702 uint32_t aOrientation
= 90);
704 void OnFullscreenChanged(nsSizeMode aOldSizeMode
, bool aFullScreen
);
705 void TryDwmResizeHack();
707 static void OnCloakEvent(HWND aWnd
, bool aCloaked
);
708 void OnCloakChanged(bool aCloaked
);
711 virtual nsresult
SetHiDPIMode(bool aHiDPI
) override
;
712 virtual nsresult
RestoreHiDPIMode() override
;
715 // Get the orientation of the hidden taskbar, on the screen that this window
716 // is on, or Nothing if taskbar isn't hidden.
717 mozilla::Maybe
<UINT
> GetHiddenTaskbarEdge();
719 static bool sTouchInjectInitialized
;
720 static InjectTouchInputPtr sInjectTouchFuncPtr
;
721 static uint32_t sInstanceCount
;
722 static nsWindow
* sCurrentWindow
;
723 static bool sIsOleInitialized
;
724 static Cursor sCurrentCursor
;
725 static bool sJustGotDeactivate
;
726 static bool sJustGotActivate
;
727 static bool sIsInMouseCapture
;
728 static bool sIsRestoringSession
;
730 // Hook Data Members for Dropdowns. sProcessHook Tells the
731 // hook methods whether they should be processing the hook
733 static HHOOK sMsgFilterHook
;
734 static HHOOK sCallProcHook
;
735 static HHOOK sCallMouseHook
;
736 static bool sProcessHook
;
737 static UINT sRollupMsgId
;
738 static HWND sRollupMsgWnd
;
739 static UINT sHookTimerId
;
741 // Used to prevent dispatching mouse events that do not originate from user
743 static POINT sLastMouseMovePoint
;
745 nsClassHashtable
<nsUint32HashKey
, PointerInfo
> mActivePointers
;
747 // This is used by SynthesizeNativeTouchPoint to maintain state between
748 // multiple synthesized points, in the case where we can't call InjectTouch
750 mozilla::UniquePtr
<mozilla::MultiTouchInput
> mSynthesizedTouchInput
;
752 InputContext mInputContext
;
754 nsCOMPtr
<nsIWidget
> mParent
;
755 nsIntSize mLastSize
= nsIntSize(0, 0);
756 nsIntPoint mLastPoint
;
758 HWND mTransitionWnd
= nullptr;
759 mozilla::Maybe
<WNDPROC
> mPrevWndProc
;
761 IMEContext mDefaultIMC
;
762 HDEVNOTIFY mDeviceNotifyHandle
= nullptr;
763 bool mIsTopWidgetWindow
= false;
764 bool mInDtor
= false;
765 bool mIsVisible
= false;
766 bool mIsCloaked
= false;
767 bool mTouchWindow
= false;
768 bool mDisplayPanFeedback
= false;
769 bool mHideChrome
= false;
771 bool mMousePresent
= false;
772 bool mSimulatedClientArea
= false;
773 bool mDestroyCalled
= false;
774 bool mOpeningAnimationSuppressed
;
776 bool mIsEarlyBlankWindow
= false;
777 bool mIsShowingPreXULSkeletonUI
= false;
778 bool mResizable
= false;
779 bool mForMenupopupFrame
= false;
780 bool mIsPerformingDwmFlushHack
= false;
781 DWORD_PTR mOldStyle
= 0;
782 DWORD_PTR mOldExStyle
= 0;
783 nsNativeDragTarget
* mNativeDragTarget
= nullptr;
784 HKL mLastKeyboardLayout
= 0;
785 mozilla::CheckInvariantWrapper
<FrameState
> mFrameState
;
786 WindowHook mWindowHook
;
787 uint32_t mPickerDisplayCount
= 0;
788 HICON mIconSmall
= nullptr;
789 HICON mIconBig
= nullptr;
790 HWND mLastKillFocusWindow
= nullptr;
791 PlatformCompositorWidgetDelegate
* mCompositorWidgetDelegate
= nullptr;
793 LayoutDeviceIntMargin
NonClientSizeMargin() const {
794 return NonClientSizeMargin(mNonClientOffset
);
796 LayoutDeviceIntMargin
NonClientSizeMargin(
797 const LayoutDeviceIntMargin
& aNonClientOffset
) const;
798 LayoutDeviceIntMargin
NormalWindowNonClientOffset() const;
800 // Non-client margin settings
801 // Pre-calculated outward offset applied to default frames
802 LayoutDeviceIntMargin mNonClientOffset
;
803 // Margins set by the owner
804 LayoutDeviceIntMargin mNonClientMargins
;
805 // Margins we'd like to set once chrome is reshown:
806 LayoutDeviceIntMargin mFutureMarginsOnceChromeShows
;
807 // Indicates we need to apply margins once toggling chrome into showing:
808 bool mFutureMarginsToUse
= false;
810 // Indicates custom frames are enabled
811 bool mCustomNonClient
= false;
812 // Indicates custom resize margins are in effect
813 bool mUseResizeMarginOverrides
= false;
814 // Width of the left and right portions of the resize region
815 int32_t mHorResizeMargin
;
816 // Height of the top and bottom portions of the resize region
817 int32_t mVertResizeMargin
;
818 // Height of the caption plus border
819 int32_t mCaptionHeight
;
821 // not yet set, will be calculated on first use
822 double mDefaultScale
= -1.0;
824 // not yet set, will be calculated on first use
825 float mAspectRatio
= 0.0;
827 nsCOMPtr
<nsIUserIdleServiceInternal
> mIdleService
;
829 // Draggable titlebar region maintained by UpdateWindowDraggingRegion
830 LayoutDeviceIntRegion mDraggableRegion
;
833 HDC mPaintDC
= nullptr; // only set during painting
835 LayoutDeviceIntRect mLastPaintBounds
;
837 ResizeState mResizeState
= NOT_RESIZING
;
840 TransparencyMode mTransparencyMode
= TransparencyMode::Opaque
;
841 nsIntRegion mPossiblyTransparentRegion
;
842 MARGINS mGlassMargins
= {0, 0, 0, 0};
844 // Win7 Gesture processing and management
845 nsWinGesture mGesture
;
847 // Weak ref to the nsITaskbarWindowPreview associated with this window
848 nsWeakPtr mTaskbarPreview
= nullptr;
850 // The input region that determines whether mouse events should be ignored
851 // and pass through to the window below. This is currently only used for
853 InputRegion mInputRegion
;
855 // True if the taskbar (possibly through the tab preview) tells us that the
856 // icon has been created on the taskbar.
857 bool mHasTaskbarIconBeenCreated
= false;
859 // Whether we're in the process of sending a WM_SETTEXT ourselves
860 bool mSendingSetText
= false;
862 // Whether we we're created as a child window (aka ChildWindow) or not.
863 bool mIsChildWindow
: 1;
865 int32_t mCachedHitTestResult
= 0;
867 // The point in time at which the last paint completed. We use this to avoid
868 // painting too rapidly in response to frequent input events.
869 TimeStamp mLastPaintEndTime
;
871 // The location of the window buttons in the window.
872 mozilla::Maybe
<LayoutDeviceIntRect
> mWindowButtonsRect
;
874 // Caching for hit test results (in client coordinates)
875 LayoutDeviceIntPoint mCachedHitTestPoint
;
876 TimeStamp mCachedHitTestTime
;
878 RefPtr
<mozilla::widget::InProcessWinCompositorWidget
> mBasicLayersSurface
;
880 double mSizeConstraintsScale
; // scale in effect when setting constraints
882 // Will be calculated when layer manager is created.
883 int32_t mMaxTextureSize
= -1;
885 // Pointer events processing and management
886 WinPointerEvents mPointerEvents
;
888 ScreenPoint mLastPanGestureFocus
;
890 // When true, used to indicate an async call to RequestFxrOutput to the GPU
891 // process after the Compositor is created
892 bool mRequestFxrOutputPending
= false;
894 // A stack based class used in DispatchMouseEvent() to tell whether we should
895 // NOT open context menu when we receives WM_CONTEXTMENU after the
896 // DispatchMouseEvent calls.
897 // This class now works only in the case where a mouse up event happened in
898 // the overscroll gutter.
899 class MOZ_STACK_CLASS ContextMenuPreventer final
{
901 explicit ContextMenuPreventer(nsWindow
* aWindow
)
902 : mWindow(aWindow
), mNeedsToPreventContextMenu(false){};
903 ~ContextMenuPreventer() {
904 mWindow
->mNeedsToPreventContextMenu
= mNeedsToPreventContextMenu
;
906 void Update(const mozilla::WidgetMouseEvent
& aEvent
,
907 const nsIWidget::ContentAndAPZEventStatus
& aEventStatus
);
911 bool mNeedsToPreventContextMenu
= false;
913 friend class ContextMenuPreventer
;
914 bool mNeedsToPreventContextMenu
= false;
916 mozilla::UniquePtr
<mozilla::widget::DirectManipulationOwner
> mDmOwner
;
918 // Client rect for minimize, maximize and close buttons.
919 mozilla::EnumeratedArray
<WindowButtonType
, WindowButtonType::Count
,
923 mozilla::DataMutex
<Desktop
> mDesktopId
;
925 // If set, indicates the edge of the NC region we should clear to black
926 // on next paint. One of: ABE_TOP, ABE_BOTTOM, ABE_LEFT or ABE_RIGHT.
927 mozilla::Maybe
<UINT
> mClearNCEdge
;
929 friend class nsWindowGfx
;
931 static constexpr int kHiddenTaskbarSize
= 2;
934 #endif // WIDGET_WINDOWS_NSWINDOW_H_