Bug 1861709 replace AudioCallbackDriver::ThreadRunning() assertions that mean to...
[gecko.git] / widget / windows / nsWindow.h
blobed318a1d7b6e00c4645984c68651f8afc758b618
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_
9 /*
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"
18 #include <windows.h>
19 #include "touchinjection_sdk80.h"
20 #include "nsdefs.h"
21 #include "nsUserIdleService.h"
22 #include "nsToolkit.h"
23 #include "nsString.h"
24 #include "nsTArray.h"
25 #include "gfxWindowsPlatform.h"
26 #include "gfxWindowsSurface.h"
27 #include "nsWindowDbg.h"
28 #include "cairo.h"
29 #include "nsRegion.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"
38 #include "nsMargin.h"
39 #include "nsRegionFwd.h"
41 #include "nsWinGesture.h"
42 #include "WinPointerEvents.h"
43 #include "WinUtils.h"
44 #include "WindowHook.h"
45 #include "TaskbarWindowPreview.h"
47 #ifdef ACCESSIBILITY
48 # include "oleacc.h"
49 # include "mozilla/a11y/LocalAccessible.h"
50 #endif
52 #include "nsUXThemeData.h"
53 #include "nsIUserIdleServiceInternal.h"
55 #include "IMMHandler.h"
56 #include "CheckInvariantWrapper.h"
58 /**
59 * Forward class definitions
62 class nsNativeDragTarget;
63 class nsIRollupListener;
64 class imgIContainer;
66 namespace mozilla {
67 class WidgetMouseEvent;
68 namespace widget {
69 class NativeKey;
70 class InProcessWinCompositorWidget;
71 struct MSGResult;
72 class DirectManipulationOwner;
73 } // namespace widget
74 } // namespace mozilla
76 /**
77 * Forward Windows-internal definitions of otherwise incomplete ones provided by
78 * the SDK.
80 const CLSID CLSID_ImmersiveShell = {
81 0xC2F03A33,
82 0x21F5,
83 0x47FA,
84 {0xB4, 0xBB, 0x15, 0x63, 0x62, 0xA2, 0xF2, 0x39}};
86 /**
87 * Native WIN32 window wrapper.
90 class nsWindow final : public nsBaseWidget {
91 public:
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
112 * time.
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);
162 } else {
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;
269 * Event helpers
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);
279 #ifdef ACCESSIBILITY
281 * Return an accessible associated with the window.
283 mozilla::a11y::LocalAccessible* GetAccessible();
284 #endif // ACCESSIBILITY
287 * Window utilities
289 nsWindow* GetTopLevelWindow(bool aStopOnDialogOrPopup);
290 WNDPROC GetPrevWindowProc() { return mPrevWndProc.valueOr(nullptr); }
291 WindowHook& GetWindowHook() { return mWindowHook; }
292 nsWindow* GetParentWindow(bool aIncludeOwner);
295 * Misc.
297 bool WidgetTypeSupportsAcceleration() override;
299 void ForcePresent();
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
316 * the window.
318 * @param aAssociate TRUE, associates the default IMC with the window.
319 * Otherwise, disassociates the default IMC from the
320 * window.
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,
325 * FALSE.
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
349 void PickerOpen();
350 void PickerClosed();
352 bool DestroyCalled() { return mDestroyCalled; }
354 bool IsPopup();
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,
393 int32_t aButton,
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; }
404 private:
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;
413 struct Desktop {
414 // Cached GUID of the virtual desktop this window should be on.
415 // This value may be stale.
416 nsString mID;
417 bool mUpdateIsQueued = false;
420 class PointerInfo {
421 public:
422 enum class PointerType : uint8_t {
423 TOUCH,
424 PEN,
427 PointerInfo(int32_t aPointerId, LayoutDeviceIntPoint& aPoint,
428 PointerType aType)
429 : mPointerId(aPointerId), mPosition(aPoint), mType(aType) {}
431 int32_t mPointerId;
432 LayoutDeviceIntPoint mPosition;
433 PointerType mType;
436 class FrameState {
437 public:
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;
456 private:
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;
469 nsWindow* mWindow;
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;
488 * Callbacks
490 static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam,
491 LPARAM lParam);
492 static LRESULT CALLBACK WindowProcInternal(HWND hWnd, UINT msg, WPARAM wParam,
493 LPARAM lParam);
495 static BOOL CALLBACK DispatchStarvedPaints(HWND aTopWindow, LPARAM aMsg);
496 static BOOL CALLBACK RegisterTouchForDescendants(HWND aTopWindow,
497 LPARAM aMsg);
498 static BOOL CALLBACK UnregisterTouchForDescendants(HWND aTopWindow,
499 LPARAM aMsg);
500 static LRESULT CALLBACK MozSpecialMsgFilter(int code, WPARAM wParam,
501 LPARAM lParam);
502 static LRESULT CALLBACK MozSpecialWndProc(int code, WPARAM wParam,
503 LPARAM lParam);
504 static LRESULT CALLBACK MozSpecialMouseProc(int code, WPARAM wParam,
505 LPARAM lParam);
506 static VOID CALLBACK HookTimerForPopups(HWND hwnd, UINT uMsg, UINT idEvent,
507 DWORD dwTime);
510 * Window utilities
512 LPARAM lParamToScreen(LPARAM lParam);
513 LPARAM lParamToClient(LPARAM lParam);
515 WPARAM wParamFromGlobalMouseState();
517 bool AssociateWithNativeWindow();
518 void DissociateFromNativeWindow();
519 bool CanTakeFocus();
520 bool UpdateNonClientMargins(bool aReflowWindow = true);
521 void UpdateDarkModeToolbar();
522 void UpdateGetWindowInfoCaptionStatus(bool aActiveCaption);
523 void ResetLayout();
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,
543 LRESULT* aRetValue);
544 // We wrap this in ProcessMessage so we can log the return value
545 bool ProcessMessageInternal(UINT msg, WPARAM& wParam, LPARAM& lParam,
546 LRESULT* aRetValue);
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(
553 nsWindow* aWindow,
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);
570 * Event handlers
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).
589 void UserActivity();
591 int32_t GetHeight(int32_t aProposedHeight);
593 DWORD WindowStyle();
594 DWORD WindowExStyle();
596 static const wchar_t* ChooseWindowClass(WindowType, bool aForMenupopupFrame);
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();
607 * Popup hooks
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);
637 * Misc.
639 void StopFlashing();
640 static HWND WindowAtMouse();
641 static bool IsTopLevelMouseExit(HWND aWnd);
642 LayoutDeviceIntRegion GetRegionToPaint(bool aForceFullRepaint, PAINTSTRUCT ps,
643 HDC aDC);
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);
658 // See bug 603793
659 static bool HasBogusPopupsDropShadowOnMultiMonitor();
661 static void InitMouseWheelScrollData();
663 void ChangedDPI();
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);
677 #ifdef DEBUG
678 virtual nsresult SetHiDPIMode(bool aHiDPI) override;
679 virtual nsresult RestoreHiDPIMode() override;
680 #endif
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 {
700 struct Marker {
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
710 // messages.
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
720 // input.
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
727 // directly.
728 mozilla::UniquePtr<mozilla::MultiTouchInput> mSynthesizedTouchInput;
730 InputContext mInputContext;
732 nsCOMPtr<nsIWidget> mParent;
733 nsIntSize mLastSize = nsIntSize(0, 0);
734 nsIntPoint mLastPoint;
735 HWND mWnd = nullptr;
736 HWND mTransitionWnd = nullptr;
737 mozilla::Maybe<WNDPROC> mPrevWndProc;
738 HBRUSH mBrush;
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;
748 bool mIsRTL;
749 bool mMousePresent = false;
750 bool mSimulatedClientArea = false;
751 bool mDestroyCalled = false;
752 bool mOpeningAnimationSuppressed;
753 bool mAlwaysOnTop;
754 bool mIsEarlyBlankWindow = false;
755 bool mIsShowingPreXULSkeletonUI = false;
756 bool mResizable = false;
757 bool mForMenupopupFrame = false;
758 bool mIsPerformingDwmFlushHack = false;
759 bool mDraggingWindowWithMouse = false;
760 DWORD_PTR mOldStyle = 0;
761 DWORD_PTR mOldExStyle = 0;
762 nsNativeDragTarget* mNativeDragTarget = nullptr;
763 HKL mLastKeyboardLayout = 0;
764 mozilla::CheckInvariantWrapper<FrameState> mFrameState;
765 WindowHook mWindowHook;
766 uint32_t mPickerDisplayCount = 0;
767 HICON mIconSmall = nullptr;
768 HICON mIconBig = nullptr;
769 HWND mLastKillFocusWindow = nullptr;
770 PlatformCompositorWidgetDelegate* mCompositorWidgetDelegate = nullptr;
772 LayoutDeviceIntMargin NonClientSizeMargin() const {
773 return NonClientSizeMargin(mNonClientOffset);
775 LayoutDeviceIntMargin NonClientSizeMargin(
776 const LayoutDeviceIntMargin& aNonClientOffset) const;
777 LayoutDeviceIntMargin NormalWindowNonClientOffset() const;
779 // Non-client margin settings
780 // Pre-calculated outward offset applied to default frames
781 LayoutDeviceIntMargin mNonClientOffset;
782 // Margins set by the owner
783 LayoutDeviceIntMargin mNonClientMargins;
784 // Margins we'd like to set once chrome is reshown:
785 LayoutDeviceIntMargin mFutureMarginsOnceChromeShows;
786 // Indicates we need to apply margins once toggling chrome into showing:
787 bool mFutureMarginsToUse = false;
789 // Indicates custom frames are enabled
790 bool mCustomNonClient = false;
791 // Indicates custom resize margins are in effect
792 bool mUseResizeMarginOverrides = false;
793 // Width of the left and right portions of the resize region
794 mozilla::LayoutDeviceIntCoord mHorResizeMargin;
795 // Height of the top and bottom portions of the resize region
796 mozilla::LayoutDeviceIntCoord mVertResizeMargin;
797 // Height of the caption plus border
798 mozilla::LayoutDeviceIntCoord mCaptionHeight;
800 // not yet set, will be calculated on first use
801 double mDefaultScale = -1.0;
803 // not yet set, will be calculated on first use
804 float mAspectRatio = 0.0;
806 nsCOMPtr<nsIUserIdleServiceInternal> mIdleService;
808 // Draggable titlebar region maintained by UpdateWindowDraggingRegion
809 LayoutDeviceIntRegion mDraggableRegion;
811 // Graphics
812 LayoutDeviceIntRect mLastPaintBounds;
814 ResizeState mResizeState = NOT_RESIZING;
816 // Transparency
817 TransparencyMode mTransparencyMode = TransparencyMode::Opaque;
818 nsIntRegion mPossiblyTransparentRegion;
820 // Win7 Gesture processing and management
821 nsWinGesture mGesture;
823 // Weak ref to the nsITaskbarWindowPreview associated with this window
824 nsWeakPtr mTaskbarPreview = nullptr;
826 // The input region that determines whether mouse events should be ignored
827 // and pass through to the window below. This is currently only used for
828 // popups.
829 InputRegion mInputRegion;
831 // True if the taskbar (possibly through the tab preview) tells us that the
832 // icon has been created on the taskbar.
833 bool mHasTaskbarIconBeenCreated = false;
835 // Whether we're in the process of sending a WM_SETTEXT ourselves
836 bool mSendingSetText = false;
838 // Whether we we're created as a child window (aka ChildWindow) or not.
839 bool mIsChildWindow : 1;
841 int32_t mCachedHitTestResult = 0;
843 // The point in time at which the last paint completed. We use this to avoid
844 // painting too rapidly in response to frequent input events.
845 TimeStamp mLastPaintEndTime;
847 // Caching for hit test results (in client coordinates)
848 LayoutDeviceIntPoint mCachedHitTestPoint;
849 TimeStamp mCachedHitTestTime;
851 RefPtr<mozilla::widget::InProcessWinCompositorWidget> mBasicLayersSurface;
853 double mSizeConstraintsScale; // scale in effect when setting constraints
855 // Will be calculated when layer manager is created.
856 int32_t mMaxTextureSize = -1;
858 // Pointer events processing and management
859 WinPointerEvents mPointerEvents;
861 ScreenPoint mLastPanGestureFocus;
863 // When true, used to indicate an async call to RequestFxrOutput to the GPU
864 // process after the Compositor is created
865 bool mRequestFxrOutputPending = false;
867 // A stack based class used in DispatchMouseEvent() to tell whether we should
868 // NOT open context menu when we receives WM_CONTEXTMENU after the
869 // DispatchMouseEvent calls.
870 // This class now works only in the case where a mouse up event happened in
871 // the overscroll gutter.
872 class MOZ_STACK_CLASS ContextMenuPreventer final {
873 public:
874 explicit ContextMenuPreventer(nsWindow* aWindow)
875 : mWindow(aWindow), mNeedsToPreventContextMenu(false){};
876 ~ContextMenuPreventer() {
877 mWindow->mNeedsToPreventContextMenu = mNeedsToPreventContextMenu;
879 void Update(const mozilla::WidgetMouseEvent& aEvent,
880 const nsIWidget::ContentAndAPZEventStatus& aEventStatus);
882 private:
883 nsWindow* mWindow;
884 bool mNeedsToPreventContextMenu = false;
886 friend class ContextMenuPreventer;
887 bool mNeedsToPreventContextMenu = false;
889 mozilla::UniquePtr<mozilla::widget::DirectManipulationOwner> mDmOwner;
891 // Client rect for minimize, maximize and close buttons.
892 mozilla::EnumeratedArray<WindowButtonType, WindowButtonType::Count,
893 LayoutDeviceIntRect>
894 mWindowBtnRect;
896 mozilla::DataMutex<Desktop> mDesktopId;
898 // If set, indicates the edge of the NC region we should clear to black
899 // on next paint. One of: ABE_TOP, ABE_BOTTOM, ABE_LEFT or ABE_RIGHT.
900 mozilla::Maybe<UINT> mClearNCEdge;
902 friend class nsWindowGfx;
904 static constexpr int kHiddenTaskbarSize = 2;
907 #endif // WIDGET_WINDOWS_NSWINDOW_H_