Bug 1838234 - Implement Quarantine controls in extensions panel and context menus...
[gecko.git] / widget / windows / nsWindow.h
blob0554af3181ad248c91337d460e46fe654734592c
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 // Virtual Desktop.
88 EXTERN_C const IID IID_IVirtualDesktopManager;
89 MIDL_INTERFACE("a5cd92ff-29be-454c-8d04-d82879fb3f1b")
90 IVirtualDesktopManager : public IUnknown {
91 public:
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;
100 #ifdef __MINGW32__
101 __CRT_UUID_DECL(IVirtualDesktopManager, 0xa5cd92ff, 0x29be, 0x454c, 0x8d, 0x04,
102 0xd8, 0x28, 0x79, 0xfb, 0x3f, 0x1b)
103 #endif
106 * Native WIN32 window wrapper.
109 class nsWindow final : public nsBaseWidget {
110 public:
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
131 * time.
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);
181 } else {
182 return mozilla::DesktopToLayoutDeviceScale(GetDefaultScaleInternal());
186 void Show(bool aState) override;
187 bool IsVisible() const override;
188 void ConstrainPosition(DesktopIntPoint&) 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 FreeNativeData(void* data, uint32_t aDataType) override;
227 nsresult SetTitle(const nsAString& aTitle) override;
228 void SetIcon(const nsAString& aIconSpec) override;
229 LayoutDeviceIntPoint WidgetToScreenOffset() override;
230 LayoutDeviceIntMargin ClientToWindowMargin() override;
231 nsresult DispatchEvent(mozilla::WidgetGUIEvent* aEvent,
232 nsEventStatus& aStatus) override;
233 void EnableDragDrop(bool aEnable) override;
234 void CaptureMouse(bool aCapture);
235 void CaptureRollupEvents(bool aDoCapture) override;
236 [[nodiscard]] nsresult GetAttention(int32_t aCycleCount) override;
237 bool HasPendingInputEvent() override;
238 WindowRenderer* GetWindowRenderer() override;
239 void SetCompositorWidgetDelegate(CompositorWidgetDelegate* delegate) override;
240 [[nodiscard]] nsresult OnDefaultButtonLoaded(
241 const LayoutDeviceIntRect& aButtonRect) override;
242 nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
243 int32_t aNativeKeyCode,
244 uint32_t aModifierFlags,
245 const nsAString& aCharacters,
246 const nsAString& aUnmodifiedCharacters,
247 nsIObserver* aObserver) override;
248 nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
249 NativeMouseMessage aNativeMessage,
250 mozilla::MouseButton aButton,
251 nsIWidget::Modifiers aModifierFlags,
252 nsIObserver* aObserver) override;
254 nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
255 nsIObserver* aObserver) override {
256 return SynthesizeNativeMouseEvent(
257 aPoint, NativeMouseMessage::Move, mozilla::MouseButton::eNotPressed,
258 nsIWidget::Modifiers::NO_MODIFIERS, aObserver);
261 nsresult SynthesizeNativeMouseScrollEvent(
262 LayoutDeviceIntPoint aPoint, uint32_t aNativeMessage, double aDeltaX,
263 double aDeltaY, double aDeltaZ, uint32_t aModifierFlags,
264 uint32_t aAdditionalFlags, nsIObserver* aObserver) override;
266 nsresult SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase,
267 LayoutDeviceIntPoint aPoint,
268 double aDeltaX, double aDeltaY,
269 int32_t aModifierFlagsn,
270 nsIObserver* aObserver) override;
272 void SetInputContext(const InputContext& aContext,
273 const InputContextAction& aAction) override;
274 InputContext GetInputContext() override;
275 TextEventDispatcherListener* GetNativeTextEventDispatcherListener() override;
276 void SetTransparencyMode(TransparencyMode aMode) override;
277 TransparencyMode GetTransparencyMode() override;
278 nsresult SetNonClientMargins(const LayoutDeviceIntMargin&) override;
279 void SetResizeMargin(mozilla::LayoutDeviceIntCoord aResizeMargin) override;
280 void SetDrawsInTitlebar(bool aState) override;
281 void UpdateWindowDraggingRegion(
282 const LayoutDeviceIntRegion& aRegion) override;
284 uint32_t GetMaxTouchPoints() const override;
285 void SetWindowClass(const nsAString& xulWinType, const nsAString& xulWinClass,
286 const nsAString& xulWinName) override;
289 * Event helpers
291 bool DispatchMouseEvent(mozilla::EventMessage aEventMessage, WPARAM wParam,
292 LPARAM lParam, bool aIsContextMenuKey,
293 int16_t aButton, uint16_t aInputSource,
294 WinPointerInfo* aPointerInfo = nullptr,
295 bool aIgnoreAPZ = false);
296 void DispatchPendingEvents();
297 void DispatchCustomEvent(const nsString& eventName);
299 #ifdef ACCESSIBILITY
301 * Return an accessible associated with the window.
303 mozilla::a11y::LocalAccessible* GetAccessible();
304 #endif // ACCESSIBILITY
307 * Window utilities
309 nsWindow* GetTopLevelWindow(bool aStopOnDialogOrPopup);
310 WNDPROC GetPrevWindowProc() { return mPrevWndProc.valueOr(nullptr); }
311 WindowHook& GetWindowHook() { return mWindowHook; }
312 nsWindow* GetParentWindow(bool aIncludeOwner);
315 * Misc.
317 bool WidgetTypeSupportsAcceleration() override;
319 void ForcePresent();
320 bool TouchEventShouldStartDrag(mozilla::EventMessage aEventMessage,
321 LayoutDeviceIntPoint aEventPoint);
323 void SetSmallIcon(HICON aIcon);
324 void SetBigIcon(HICON aIcon);
325 void SetSmallIconNoData();
326 void SetBigIconNoData();
328 static void SetIsRestoringSession(const bool aIsRestoringSession) {
329 sIsRestoringSession = aIsRestoringSession;
332 bool IsRTL() const { return mIsRTL; }
335 * AssociateDefaultIMC() associates or disassociates the default IMC for
336 * the window.
338 * @param aAssociate TRUE, associates the default IMC with the window.
339 * Otherwise, disassociates the default IMC from the
340 * window.
341 * @return TRUE if this method associated the default IMC with
342 * disassociated window or disassociated the default IMC
343 * from associated window.
344 * Otherwise, i.e., if this method did nothing actually,
345 * FALSE.
347 bool AssociateDefaultIMC(bool aAssociate);
349 bool HasTaskbarIconBeenCreated() { return mHasTaskbarIconBeenCreated; }
350 // Called when either the nsWindow or an nsITaskbarTabPreview receives the
351 // noticiation that this window has its icon placed on the taskbar.
352 void SetHasTaskbarIconBeenCreated(bool created = true) {
353 mHasTaskbarIconBeenCreated = created;
356 // Getter/setter for the nsITaskbarWindowPreview for this nsWindow
357 already_AddRefed<nsITaskbarWindowPreview> GetTaskbarPreview() {
358 nsCOMPtr<nsITaskbarWindowPreview> preview(
359 do_QueryReferent(mTaskbarPreview));
360 return preview.forget();
362 void SetTaskbarPreview(nsITaskbarWindowPreview* preview) {
363 mTaskbarPreview = do_GetWeakReference(preview);
366 void ReparentNativeWidget(nsIWidget* aNewParent) override;
368 // Open file picker tracking
369 void PickerOpen();
370 void PickerClosed();
372 bool DestroyCalled() { return mDestroyCalled; }
374 bool IsPopup();
375 bool ShouldUseOffMainThreadCompositing() override;
377 const IMEContext& DefaultIMC() const { return mDefaultIMC; }
379 void GetCompositorWidgetInitData(
380 mozilla::widget::CompositorWidgetInitData* aInitData) override;
381 bool IsTouchWindow() const { return mTouchWindow; }
382 bool SynchronouslyRepaintOnResize() override;
383 void MaybeDispatchInitialFocusEvent() override;
385 void LocalesChanged() override;
387 void NotifyOcclusionState(mozilla::widget::OcclusionState aState) override;
388 void MaybeEnableWindowOcclusion(bool aEnable);
391 * Return the HWND or null for this widget.
393 HWND GetWindowHandle() {
394 return static_cast<HWND>(GetNativeData(NS_NATIVE_WINDOW));
398 * Touch input injection apis
400 nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
401 TouchPointerState aPointerState,
402 LayoutDeviceIntPoint aPoint,
403 double aPointerPressure,
404 uint32_t aPointerOrientation,
405 nsIObserver* aObserver) override;
406 nsresult ClearNativeTouchSequence(nsIObserver* aObserver) override;
408 nsresult SynthesizeNativePenInput(uint32_t aPointerId,
409 TouchPointerState aPointerState,
410 LayoutDeviceIntPoint aPoint,
411 double aPressure, uint32_t aRotation,
412 int32_t aTiltX, int32_t aTiltY,
413 int32_t aButton,
414 nsIObserver* aObserver) override;
417 * WM_APPCOMMAND common handler.
418 * Sends events via NativeKey::HandleAppCommandMessage().
420 bool HandleAppCommandMsg(const MSG& aAppCommandMsg, LRESULT* aRetValue);
422 const InputContext& InputContextRef() const { return mInputContext; }
424 private:
425 using TimeStamp = mozilla::TimeStamp;
426 using TimeDuration = mozilla::TimeDuration;
427 using TaskbarWindowPreview = mozilla::widget::TaskbarWindowPreview;
428 using NativeKey = mozilla::widget::NativeKey;
429 using MSGResult = mozilla::widget::MSGResult;
430 using PlatformCompositorWidgetDelegate =
431 mozilla::widget::PlatformCompositorWidgetDelegate;
433 struct Desktop {
434 // Cached GUID of the virtual desktop this window should be on.
435 // This value may be stale.
436 nsString mID;
437 bool mUpdateIsQueued = false;
440 class PointerInfo {
441 public:
442 enum class PointerType : uint8_t {
443 TOUCH,
444 PEN,
447 PointerInfo(int32_t aPointerId, LayoutDeviceIntPoint& aPoint,
448 PointerType aType)
449 : mPointerId(aPointerId), mPosition(aPoint), mType(aType) {}
451 int32_t mPointerId;
452 LayoutDeviceIntPoint mPosition;
453 PointerType mType;
456 class FrameState {
457 public:
458 explicit FrameState(nsWindow* aWindow);
460 void ConsumePreXULSkeletonState(bool aWasMaximized);
462 // Whether we should call ShowWindow with the relevant size mode if needed.
463 // We want to avoid that when Windows is already performing the change for
464 // us (via the SWP_FRAMECHANGED messages).
465 enum class DoShowWindow : bool { No, Yes };
467 void EnsureSizeMode(nsSizeMode, DoShowWindow = DoShowWindow::Yes);
468 void EnsureFullscreenMode(bool, DoShowWindow = DoShowWindow::Yes);
469 void OnFrameChanging();
470 void OnFrameChanged();
472 nsSizeMode GetSizeMode() const;
474 void CheckInvariant() const;
476 private:
477 void SetSizeModeInternal(nsSizeMode, DoShowWindow);
479 nsSizeMode mSizeMode = nsSizeMode_Normal;
480 // XXX mLastSizeMode is rather bizarre and needs some documentation.
481 nsSizeMode mLastSizeMode = nsSizeMode_Normal;
482 // The old size mode before going into fullscreen mode. This should never
483 // be nsSizeMode_Fullscreen.
484 nsSizeMode mPreFullscreenSizeMode = nsSizeMode_Normal;
485 // Whether we're in fullscreen. We need to keep this state out of band,
486 // rather than just using mSizeMode, because a window can be minimized
487 // while fullscreen, and we don't store the fullscreen state anywhere else.
488 bool mFullscreenMode = false;
489 nsWindow* mWindow;
492 // Manager for taskbar-hiding. No persistent state.
493 class TaskbarConcealer;
495 // A magic number to identify the FAKETRACKPOINTSCROLLABLE window created
496 // when the trackpoint hack is enabled.
497 enum { eFakeTrackPointScrollableID = 0x46545053 };
499 // Used for displayport suppression during window resize
500 enum ResizeState { NOT_RESIZING, IN_SIZEMOVE, RESIZING, MOVING };
502 ~nsWindow() override;
504 void WindowUsesOMTC() override;
505 void RegisterTouchWindow() override;
508 * Callbacks
510 static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam,
511 LPARAM lParam);
512 static LRESULT CALLBACK WindowProcInternal(HWND hWnd, UINT msg, WPARAM wParam,
513 LPARAM lParam);
515 static BOOL CALLBACK BroadcastMsgToChildren(HWND aWnd, LPARAM aMsg);
516 static BOOL CALLBACK BroadcastMsg(HWND aTopWindow, LPARAM aMsg);
517 static BOOL CALLBACK DispatchStarvedPaints(HWND aTopWindow, LPARAM aMsg);
518 static BOOL CALLBACK RegisterTouchForDescendants(HWND aTopWindow,
519 LPARAM aMsg);
520 static BOOL CALLBACK UnregisterTouchForDescendants(HWND aTopWindow,
521 LPARAM aMsg);
522 static LRESULT CALLBACK MozSpecialMsgFilter(int code, WPARAM wParam,
523 LPARAM lParam);
524 static LRESULT CALLBACK MozSpecialWndProc(int code, WPARAM wParam,
525 LPARAM lParam);
526 static LRESULT CALLBACK MozSpecialMouseProc(int code, WPARAM wParam,
527 LPARAM lParam);
528 static VOID CALLBACK HookTimerForPopups(HWND hwnd, UINT uMsg, UINT idEvent,
529 DWORD dwTime);
532 * Window utilities
534 LPARAM lParamToScreen(LPARAM lParam);
535 LPARAM lParamToClient(LPARAM lParam);
537 WPARAM wParamFromGlobalMouseState();
539 bool AssociateWithNativeWindow();
540 void DissociateFromNativeWindow();
541 bool CanTakeFocus();
542 bool UpdateNonClientMargins(bool aReflowWindow = true);
543 void UpdateDarkModeToolbar();
544 void UpdateGetWindowInfoCaptionStatus(bool aActiveCaption);
545 void ResetLayout();
546 void InvalidateNonClientRegion();
547 HRGN ExcludeNonClientFromPaintRegion(HRGN aRegion);
548 static const wchar_t* GetMainWindowClass();
549 HWND GetOwnerWnd() const { return ::GetWindow(mWnd, GW_OWNER); }
550 bool IsOwnerForegroundWindow() const {
551 HWND owner = GetOwnerWnd();
552 return owner && owner == ::GetForegroundWindow();
554 bool IsForegroundWindow() const { return mWnd == ::GetForegroundWindow(); }
555 bool IsPopup() const { return mWindowType == WindowType::Popup; }
556 bool IsCloaked() const { return mIsCloaked; }
559 * Event processing helpers
561 HWND GetTopLevelForFocus(HWND aCurWnd);
562 void DispatchFocusToTopLevelWindow(bool aIsActivate);
563 bool DispatchStandardEvent(mozilla::EventMessage aMsg);
564 void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam);
565 bool ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam,
566 LRESULT* aRetValue);
567 // We wrap this in ProcessMessage so we can log the return value
568 bool ProcessMessageInternal(UINT msg, WPARAM& wParam, LPARAM& lParam,
569 LRESULT* aRetValue);
570 bool ExternalHandlerProcessMessage(UINT aMessage, WPARAM& aWParam,
571 LPARAM& aLParam, MSGResult& aResult);
572 LRESULT ProcessCharMessage(const MSG& aMsg, bool* aEventDispatched);
573 LRESULT ProcessKeyUpMessage(const MSG& aMsg, bool* aEventDispatched);
574 LRESULT ProcessKeyDownMessage(const MSG& aMsg, bool* aEventDispatched);
575 static bool EventIsInsideWindow(
576 nsWindow* aWindow,
577 mozilla::Maybe<POINT> aEventPoint = mozilla::Nothing());
578 static void PostSleepWakeNotification(const bool aIsSleepMode);
579 int32_t ClientMarginHitTestPoint(int32_t mx, int32_t my);
580 void SetWindowButtonRect(WindowButtonType aButtonType,
581 const LayoutDeviceIntRect& aClientRect) override {
582 mWindowBtnRect[aButtonType] = aClientRect;
584 TimeStamp GetMessageTimeStamp(LONG aEventTime) const;
585 static void UpdateFirstEventTime(DWORD aEventTime);
586 void FinishLiveResizing(ResizeState aNewState);
587 mozilla::Maybe<mozilla::PanGestureInput> ConvertTouchToPanGesture(
588 const mozilla::MultiTouchInput& aTouchInput, PTOUCHINPUT aOriginalEvent);
589 void DispatchTouchOrPanGestureInput(mozilla::MultiTouchInput& aTouchInput,
590 PTOUCHINPUT aOSEvent);
593 * Event handlers
595 void OnDestroy() override;
596 bool OnResize(const LayoutDeviceIntSize& aSize);
597 void OnSizeModeChange();
598 bool OnGesture(WPARAM wParam, LPARAM lParam);
599 bool OnTouch(WPARAM wParam, LPARAM lParam);
600 bool OnHotKey(WPARAM wParam, LPARAM lParam);
601 bool OnPaint(HDC aDC, uint32_t aNestingLevel);
602 void OnWindowPosChanging(WINDOWPOS* info);
603 void OnWindowPosChanged(WINDOWPOS* wp);
604 void OnSysColorChanged();
605 void OnDPIChanged(int32_t x, int32_t y, int32_t width, int32_t height);
606 bool OnPointerEvents(UINT msg, WPARAM wParam, LPARAM lParam);
609 * Function that registers when the user has been active (used for detecting
610 * when the user is idle).
612 void UserActivity();
614 int32_t GetHeight(int32_t aProposedHeight);
616 DWORD WindowStyle();
617 DWORD WindowExStyle();
619 static const wchar_t* ChooseWindowClass(WindowType, bool aForMenupopupFrame);
620 // This method registers the given window class, and returns the class name.
621 static const wchar_t* RegisterWindowClass(const wchar_t* aClassName,
622 UINT aExtraStyle, LPWSTR aIconID);
625 * XP and Vista theming support for windows with rounded edges
627 void ClearThemeRegion();
630 * Popup hooks
632 static void ScheduleHookTimer(HWND aWnd, UINT aMsgId);
633 static void RegisterSpecialDropdownHooks();
634 static void UnregisterSpecialDropdownHooks();
635 static bool GetPopupsToRollup(
636 nsIRollupListener* aRollupListener, uint32_t* aPopupsToRollup,
637 mozilla::Maybe<POINT> aEventPoint = mozilla::Nothing());
638 static bool NeedsToHandleNCActivateDelayed(HWND aWnd);
639 static bool DealWithPopups(HWND inWnd, UINT inMsg, WPARAM inWParam,
640 LPARAM inLParam, LRESULT* outResult);
643 * Window transparency helpers
645 void SetWindowTranslucencyInner(TransparencyMode aMode);
646 TransparencyMode GetWindowTranslucencyInner() const {
647 return mTransparencyMode;
649 bool IsSimulatedClientArea(int32_t clientX, int32_t clientY);
650 bool IsWindowButton(int32_t hitTestResult);
652 bool DispatchTouchEventFromWMPointer(UINT msg, LPARAM aLParam,
653 const WinPointerInfo& aPointerInfo,
654 mozilla::MouseButton aButton);
656 static bool IsAsyncResponseEvent(UINT aMsg, LRESULT& aResult);
657 void IPCWindowProcHandler(UINT& msg, WPARAM& wParam, LPARAM& lParam);
660 * Misc.
662 void StopFlashing();
663 static HWND WindowAtMouse();
664 static bool IsTopLevelMouseExit(HWND aWnd);
665 LayoutDeviceIntRegion GetRegionToPaint(bool aForceFullRepaint, PAINTSTRUCT ps,
666 HDC aDC);
667 nsIWidgetListener* GetPaintListener();
669 void CreateCompositor() override;
670 void DestroyCompositor() override;
671 void RequestFxrOutput() override;
673 void RecreateDirectManipulationIfNeeded();
674 void ResizeDirectManipulationViewport();
675 void DestroyDirectManipulation();
677 bool NeedsToTrackWindowOcclusionState();
679 void AsyncUpdateWorkspaceID(Desktop& aDesktop);
681 // See bug 603793
682 static bool HasBogusPopupsDropShadowOnMultiMonitor();
684 static void InitMouseWheelScrollData();
686 void ChangedDPI();
688 static bool InitTouchInjection();
690 bool InjectTouchPoint(uint32_t aId, LayoutDeviceIntPoint& aPoint,
691 POINTER_FLAGS aFlags, uint32_t aPressure = 1024,
692 uint32_t aOrientation = 90);
694 void OnFullscreenChanged(nsSizeMode aOldSizeMode, bool aFullScreen);
695 void TryDwmResizeHack();
697 static void OnCloakEvent(HWND aWnd, bool aCloaked);
698 void OnCloakChanged(bool aCloaked);
700 #ifdef DEBUG
701 virtual nsresult SetHiDPIMode(bool aHiDPI) override;
702 virtual nsresult RestoreHiDPIMode() override;
703 #endif
705 // Get the orientation of the hidden taskbar, on the screen that this window
706 // is on, or Nothing if taskbar isn't hidden.
707 mozilla::Maybe<UINT> GetHiddenTaskbarEdge();
709 static bool sTouchInjectInitialized;
710 static InjectTouchInputPtr sInjectTouchFuncPtr;
711 static uint32_t sInstanceCount;
712 static nsWindow* sCurrentWindow;
713 static bool sIsOleInitialized;
714 static Cursor sCurrentCursor;
715 static bool sJustGotDeactivate;
716 static bool sJustGotActivate;
717 static bool sIsInMouseCapture;
718 static bool sIsRestoringSession;
720 // Hook Data Members for Dropdowns. sProcessHook Tells the
721 // hook methods whether they should be processing the hook
722 // messages.
723 static HHOOK sMsgFilterHook;
724 static HHOOK sCallProcHook;
725 static HHOOK sCallMouseHook;
726 static bool sProcessHook;
727 static UINT sRollupMsgId;
728 static HWND sRollupMsgWnd;
729 static UINT sHookTimerId;
731 // Used to prevent dispatching mouse events that do not originate from user
732 // input.
733 static POINT sLastMouseMovePoint;
735 nsClassHashtable<nsUint32HashKey, PointerInfo> mActivePointers;
737 // This is used by SynthesizeNativeTouchPoint to maintain state between
738 // multiple synthesized points, in the case where we can't call InjectTouch
739 // directly.
740 mozilla::UniquePtr<mozilla::MultiTouchInput> mSynthesizedTouchInput;
742 InputContext mInputContext;
744 nsCOMPtr<nsIWidget> mParent;
745 nsIntSize mLastSize = nsIntSize(0, 0);
746 nsIntPoint mLastPoint;
747 HWND mWnd = nullptr;
748 HWND mTransitionWnd = nullptr;
749 mozilla::Maybe<WNDPROC> mPrevWndProc;
750 HBRUSH mBrush;
751 IMEContext mDefaultIMC;
752 HDEVNOTIFY mDeviceNotifyHandle = nullptr;
753 bool mIsTopWidgetWindow = false;
754 bool mInDtor = false;
755 bool mIsVisible = false;
756 bool mIsCloaked = false;
757 bool mTouchWindow = false;
758 bool mDisplayPanFeedback = false;
759 bool mHideChrome = false;
760 bool mIsRTL;
761 bool mMousePresent = false;
762 bool mSimulatedClientArea = false;
763 bool mDestroyCalled = false;
764 bool mOpeningAnimationSuppressed;
765 bool mAlwaysOnTop;
766 bool mIsEarlyBlankWindow = false;
767 bool mIsShowingPreXULSkeletonUI = false;
768 bool mResizable = false;
769 bool mForMenupopupFrame = false;
770 bool mIsPerformingDwmFlushHack = false;
771 DWORD_PTR mOldStyle = 0;
772 DWORD_PTR mOldExStyle = 0;
773 nsNativeDragTarget* mNativeDragTarget = nullptr;
774 HKL mLastKeyboardLayout = 0;
775 mozilla::CheckInvariantWrapper<FrameState> mFrameState;
776 WindowHook mWindowHook;
777 uint32_t mPickerDisplayCount = 0;
778 HICON mIconSmall = nullptr;
779 HICON mIconBig = nullptr;
780 HWND mLastKillFocusWindow = nullptr;
781 PlatformCompositorWidgetDelegate* mCompositorWidgetDelegate = nullptr;
783 LayoutDeviceIntMargin NonClientSizeMargin() const {
784 return NonClientSizeMargin(mNonClientOffset);
786 LayoutDeviceIntMargin NonClientSizeMargin(
787 const LayoutDeviceIntMargin& aNonClientOffset) const;
788 LayoutDeviceIntMargin NormalWindowNonClientOffset() const;
790 // Non-client margin settings
791 // Pre-calculated outward offset applied to default frames
792 LayoutDeviceIntMargin mNonClientOffset;
793 // Margins set by the owner
794 LayoutDeviceIntMargin mNonClientMargins;
795 // Margins we'd like to set once chrome is reshown:
796 LayoutDeviceIntMargin mFutureMarginsOnceChromeShows;
797 // Indicates we need to apply margins once toggling chrome into showing:
798 bool mFutureMarginsToUse = false;
800 // Indicates custom frames are enabled
801 bool mCustomNonClient = false;
802 // Indicates custom resize margins are in effect
803 bool mUseResizeMarginOverrides = false;
804 // Width of the left and right portions of the resize region
805 mozilla::LayoutDeviceIntCoord mHorResizeMargin;
806 // Height of the top and bottom portions of the resize region
807 mozilla::LayoutDeviceIntCoord mVertResizeMargin;
808 // Height of the caption plus border
809 mozilla::LayoutDeviceIntCoord mCaptionHeight;
811 // not yet set, will be calculated on first use
812 double mDefaultScale = -1.0;
814 // not yet set, will be calculated on first use
815 float mAspectRatio = 0.0;
817 nsCOMPtr<nsIUserIdleServiceInternal> mIdleService;
819 // Draggable titlebar region maintained by UpdateWindowDraggingRegion
820 LayoutDeviceIntRegion mDraggableRegion;
822 // Graphics
823 HDC mPaintDC = nullptr; // only set during painting
825 LayoutDeviceIntRect mLastPaintBounds;
827 ResizeState mResizeState = NOT_RESIZING;
829 // Transparency
830 TransparencyMode mTransparencyMode = TransparencyMode::Opaque;
831 nsIntRegion mPossiblyTransparentRegion;
833 // Win7 Gesture processing and management
834 nsWinGesture mGesture;
836 // Weak ref to the nsITaskbarWindowPreview associated with this window
837 nsWeakPtr mTaskbarPreview = nullptr;
839 // The input region that determines whether mouse events should be ignored
840 // and pass through to the window below. This is currently only used for
841 // popups.
842 InputRegion mInputRegion;
844 // True if the taskbar (possibly through the tab preview) tells us that the
845 // icon has been created on the taskbar.
846 bool mHasTaskbarIconBeenCreated = false;
848 // Whether we're in the process of sending a WM_SETTEXT ourselves
849 bool mSendingSetText = false;
851 // Whether we we're created as a child window (aka ChildWindow) or not.
852 bool mIsChildWindow : 1;
854 int32_t mCachedHitTestResult = 0;
856 // The point in time at which the last paint completed. We use this to avoid
857 // painting too rapidly in response to frequent input events.
858 TimeStamp mLastPaintEndTime;
860 // Caching for hit test results (in client coordinates)
861 LayoutDeviceIntPoint mCachedHitTestPoint;
862 TimeStamp mCachedHitTestTime;
864 RefPtr<mozilla::widget::InProcessWinCompositorWidget> mBasicLayersSurface;
866 double mSizeConstraintsScale; // scale in effect when setting constraints
868 // Will be calculated when layer manager is created.
869 int32_t mMaxTextureSize = -1;
871 // Pointer events processing and management
872 WinPointerEvents mPointerEvents;
874 ScreenPoint mLastPanGestureFocus;
876 // When true, used to indicate an async call to RequestFxrOutput to the GPU
877 // process after the Compositor is created
878 bool mRequestFxrOutputPending = false;
880 // A stack based class used in DispatchMouseEvent() to tell whether we should
881 // NOT open context menu when we receives WM_CONTEXTMENU after the
882 // DispatchMouseEvent calls.
883 // This class now works only in the case where a mouse up event happened in
884 // the overscroll gutter.
885 class MOZ_STACK_CLASS ContextMenuPreventer final {
886 public:
887 explicit ContextMenuPreventer(nsWindow* aWindow)
888 : mWindow(aWindow), mNeedsToPreventContextMenu(false){};
889 ~ContextMenuPreventer() {
890 mWindow->mNeedsToPreventContextMenu = mNeedsToPreventContextMenu;
892 void Update(const mozilla::WidgetMouseEvent& aEvent,
893 const nsIWidget::ContentAndAPZEventStatus& aEventStatus);
895 private:
896 nsWindow* mWindow;
897 bool mNeedsToPreventContextMenu = false;
899 friend class ContextMenuPreventer;
900 bool mNeedsToPreventContextMenu = false;
902 mozilla::UniquePtr<mozilla::widget::DirectManipulationOwner> mDmOwner;
904 // Client rect for minimize, maximize and close buttons.
905 mozilla::EnumeratedArray<WindowButtonType, WindowButtonType::Count,
906 LayoutDeviceIntRect>
907 mWindowBtnRect;
909 mozilla::DataMutex<Desktop> mDesktopId;
911 // If set, indicates the edge of the NC region we should clear to black
912 // on next paint. One of: ABE_TOP, ABE_BOTTOM, ABE_LEFT or ABE_RIGHT.
913 mozilla::Maybe<UINT> mClearNCEdge;
915 friend class nsWindowGfx;
917 static constexpr int kHiddenTaskbarSize = 2;
920 #endif // WIDGET_WINDOWS_NSWINDOW_H_