Bug 1874684 - Part 20: Tag stack classes with MOZ_STACK_CLASS. r=allstarschh
[gecko.git] / widget / windows / nsWindow.h
bloba2b2a701bd985ad20de63fb733e09a46c399cc11
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 void PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, nsIWidget* aWidget,
179 bool aActivate) override;
180 void SetSizeMode(nsSizeMode aMode) override;
181 nsSizeMode SizeMode() override;
182 void GetWorkspaceID(nsAString& workspaceID) override;
183 void MoveToWorkspace(const nsAString& workspaceID) override;
184 void SuppressAnimation(bool aSuppress) override;
185 void Enable(bool aState) override;
186 bool IsEnabled() const override;
187 void SetFocus(Raise, mozilla::dom::CallerType aCallerType) override;
188 LayoutDeviceIntRect GetBounds() override;
189 LayoutDeviceIntRect GetScreenBounds() override;
190 [[nodiscard]] nsresult GetRestoredBounds(LayoutDeviceIntRect& aRect) override;
191 LayoutDeviceIntRect GetClientBounds() override;
192 LayoutDeviceIntPoint GetClientOffset() override;
193 void SetBackgroundColor(const nscolor& aColor) override;
194 void SetCursor(const Cursor&) override;
195 bool PrepareForFullscreenTransition(nsISupports** aData) override;
196 void PerformFullscreenTransition(FullscreenTransitionStage aStage,
197 uint16_t aDuration, nsISupports* aData,
198 nsIRunnable* aCallback) override;
199 void CleanupFullscreenTransition() override;
200 nsresult MakeFullScreen(bool aFullScreen) override;
201 void HideWindowChrome(bool aShouldHide) override;
202 void Invalidate(bool aEraseBackground = false, bool aUpdateNCArea = false,
203 bool aIncludeChildren = false);
204 void Invalidate(const LayoutDeviceIntRect& aRect) override;
205 void* GetNativeData(uint32_t aDataType) override;
206 void FreeNativeData(void* data, uint32_t aDataType) override;
207 nsresult SetTitle(const nsAString& aTitle) override;
208 void SetIcon(const nsAString& aIconSpec) override;
209 LayoutDeviceIntPoint WidgetToScreenOffset() override;
210 LayoutDeviceIntMargin ClientToWindowMargin() override;
211 nsresult DispatchEvent(mozilla::WidgetGUIEvent* aEvent,
212 nsEventStatus& aStatus) override;
213 void EnableDragDrop(bool aEnable) override;
214 void CaptureMouse(bool aCapture);
215 void CaptureRollupEvents(bool aDoCapture) override;
216 [[nodiscard]] nsresult GetAttention(int32_t aCycleCount) override;
217 bool HasPendingInputEvent() override;
218 WindowRenderer* GetWindowRenderer() override;
219 void SetCompositorWidgetDelegate(CompositorWidgetDelegate* delegate) override;
220 [[nodiscard]] nsresult OnDefaultButtonLoaded(
221 const LayoutDeviceIntRect& aButtonRect) override;
222 nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
223 int32_t aNativeKeyCode,
224 uint32_t aModifierFlags,
225 const nsAString& aCharacters,
226 const nsAString& aUnmodifiedCharacters,
227 nsIObserver* aObserver) override;
228 nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
229 NativeMouseMessage aNativeMessage,
230 mozilla::MouseButton aButton,
231 nsIWidget::Modifiers aModifierFlags,
232 nsIObserver* aObserver) override;
234 nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
235 nsIObserver* aObserver) override {
236 return SynthesizeNativeMouseEvent(
237 aPoint, NativeMouseMessage::Move, mozilla::MouseButton::eNotPressed,
238 nsIWidget::Modifiers::NO_MODIFIERS, aObserver);
241 nsresult SynthesizeNativeMouseScrollEvent(
242 LayoutDeviceIntPoint aPoint, uint32_t aNativeMessage, double aDeltaX,
243 double aDeltaY, double aDeltaZ, uint32_t aModifierFlags,
244 uint32_t aAdditionalFlags, nsIObserver* aObserver) override;
246 nsresult SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase,
247 LayoutDeviceIntPoint aPoint,
248 double aDeltaX, double aDeltaY,
249 int32_t aModifierFlagsn,
250 nsIObserver* aObserver) override;
252 void SetInputContext(const InputContext& aContext,
253 const InputContextAction& aAction) override;
254 InputContext GetInputContext() override;
255 TextEventDispatcherListener* GetNativeTextEventDispatcherListener() override;
256 void SetTransparencyMode(TransparencyMode aMode) override;
257 TransparencyMode GetTransparencyMode() override;
258 nsresult SetNonClientMargins(const LayoutDeviceIntMargin&) override;
259 void SetResizeMargin(mozilla::LayoutDeviceIntCoord aResizeMargin) override;
260 void UpdateWindowDraggingRegion(
261 const LayoutDeviceIntRegion& aRegion) override;
263 uint32_t GetMaxTouchPoints() const override;
264 void SetWindowClass(const nsAString& xulWinType, const nsAString& xulWinClass,
265 const nsAString& xulWinName) override;
268 * Event helpers
270 bool DispatchMouseEvent(mozilla::EventMessage aEventMessage, WPARAM wParam,
271 LPARAM lParam, bool aIsContextMenuKey,
272 int16_t aButton, uint16_t aInputSource,
273 WinPointerInfo* aPointerInfo = nullptr,
274 bool aIgnoreAPZ = false);
275 void DispatchPendingEvents();
276 void DispatchCustomEvent(const nsString& eventName);
278 #ifdef ACCESSIBILITY
280 * Return an accessible associated with the window.
282 mozilla::a11y::LocalAccessible* GetAccessible();
283 #endif // ACCESSIBILITY
286 * Window utilities
288 nsWindow* GetTopLevelWindow(bool aStopOnDialogOrPopup);
289 WNDPROC GetPrevWindowProc() { return mPrevWndProc.valueOr(nullptr); }
290 WindowHook& GetWindowHook() { return mWindowHook; }
291 nsWindow* GetParentWindow(bool aIncludeOwner);
294 * Misc.
296 bool WidgetTypeSupportsAcceleration() override;
298 void ForcePresent();
299 bool TouchEventShouldStartDrag(mozilla::EventMessage aEventMessage,
300 LayoutDeviceIntPoint aEventPoint);
302 void SetSmallIcon(HICON aIcon);
303 void SetBigIcon(HICON aIcon);
304 void SetSmallIconNoData();
305 void SetBigIconNoData();
307 static void SetIsRestoringSession(const bool aIsRestoringSession) {
308 sIsRestoringSession = aIsRestoringSession;
311 bool IsRTL() const { return mIsRTL; }
314 * AssociateDefaultIMC() associates or disassociates the default IMC for
315 * the window.
317 * @param aAssociate TRUE, associates the default IMC with the window.
318 * Otherwise, disassociates the default IMC from the
319 * window.
320 * @return TRUE if this method associated the default IMC with
321 * disassociated window or disassociated the default IMC
322 * from associated window.
323 * Otherwise, i.e., if this method did nothing actually,
324 * FALSE.
326 bool AssociateDefaultIMC(bool aAssociate);
328 bool HasTaskbarIconBeenCreated() { return mHasTaskbarIconBeenCreated; }
329 // Called when either the nsWindow or an nsITaskbarTabPreview receives the
330 // noticiation that this window has its icon placed on the taskbar.
331 void SetHasTaskbarIconBeenCreated(bool created = true) {
332 mHasTaskbarIconBeenCreated = created;
335 // Getter/setter for the nsITaskbarWindowPreview for this nsWindow
336 already_AddRefed<nsITaskbarWindowPreview> GetTaskbarPreview() {
337 nsCOMPtr<nsITaskbarWindowPreview> preview(
338 do_QueryReferent(mTaskbarPreview));
339 return preview.forget();
341 void SetTaskbarPreview(nsITaskbarWindowPreview* preview) {
342 mTaskbarPreview = do_GetWeakReference(preview);
345 void ReparentNativeWidget(nsIWidget* aNewParent) override;
347 // Open file picker tracking
348 void PickerOpen();
349 void PickerClosed();
351 bool DestroyCalled() { return mDestroyCalled; }
353 bool IsPopup();
354 bool ShouldUseOffMainThreadCompositing() override;
356 const IMEContext& DefaultIMC() const { return mDefaultIMC; }
358 void GetCompositorWidgetInitData(
359 mozilla::widget::CompositorWidgetInitData* aInitData) override;
360 bool IsTouchWindow() const { return mTouchWindow; }
361 bool SynchronouslyRepaintOnResize() override;
362 void MaybeDispatchInitialFocusEvent() override;
364 void LocalesChanged() override;
366 void NotifyOcclusionState(mozilla::widget::OcclusionState aState) override;
367 void MaybeEnableWindowOcclusion(bool aEnable);
370 * Return the HWND or null for this widget.
372 HWND GetWindowHandle() {
373 return static_cast<HWND>(GetNativeData(NS_NATIVE_WINDOW));
377 * Touch input injection apis
379 nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
380 TouchPointerState aPointerState,
381 LayoutDeviceIntPoint aPoint,
382 double aPointerPressure,
383 uint32_t aPointerOrientation,
384 nsIObserver* aObserver) override;
385 nsresult ClearNativeTouchSequence(nsIObserver* aObserver) override;
387 nsresult SynthesizeNativePenInput(uint32_t aPointerId,
388 TouchPointerState aPointerState,
389 LayoutDeviceIntPoint aPoint,
390 double aPressure, uint32_t aRotation,
391 int32_t aTiltX, int32_t aTiltY,
392 int32_t aButton,
393 nsIObserver* aObserver) override;
396 * WM_APPCOMMAND common handler.
397 * Sends events via NativeKey::HandleAppCommandMessage().
399 bool HandleAppCommandMsg(const MSG& aAppCommandMsg, LRESULT* aRetValue);
401 const InputContext& InputContextRef() const { return mInputContext; }
403 private:
404 using TimeStamp = mozilla::TimeStamp;
405 using TimeDuration = mozilla::TimeDuration;
406 using TaskbarWindowPreview = mozilla::widget::TaskbarWindowPreview;
407 using NativeKey = mozilla::widget::NativeKey;
408 using MSGResult = mozilla::widget::MSGResult;
409 using PlatformCompositorWidgetDelegate =
410 mozilla::widget::PlatformCompositorWidgetDelegate;
412 struct Desktop {
413 // Cached GUID of the virtual desktop this window should be on.
414 // This value may be stale.
415 nsString mID;
416 bool mUpdateIsQueued = false;
419 class PointerInfo {
420 public:
421 enum class PointerType : uint8_t {
422 TOUCH,
423 PEN,
426 PointerInfo(int32_t aPointerId, LayoutDeviceIntPoint& aPoint,
427 PointerType aType)
428 : mPointerId(aPointerId), mPosition(aPoint), mType(aType) {}
430 int32_t mPointerId;
431 LayoutDeviceIntPoint mPosition;
432 PointerType mType;
435 class FrameState {
436 public:
437 explicit FrameState(nsWindow* aWindow);
439 void ConsumePreXULSkeletonState(bool aWasMaximized);
441 // Whether we should call ShowWindow with the relevant size mode if needed.
442 // We want to avoid that when Windows is already performing the change for
443 // us (via the SWP_FRAMECHANGED messages).
444 enum class DoShowWindow : bool { No, Yes };
446 void EnsureSizeMode(nsSizeMode, DoShowWindow = DoShowWindow::Yes);
447 void EnsureFullscreenMode(bool, DoShowWindow = DoShowWindow::Yes);
448 void OnFrameChanging();
449 void OnFrameChanged();
451 nsSizeMode GetSizeMode() const;
453 void CheckInvariant() const;
455 private:
456 void SetSizeModeInternal(nsSizeMode, DoShowWindow);
458 nsSizeMode mSizeMode = nsSizeMode_Normal;
459 // XXX mLastSizeMode is rather bizarre and needs some documentation.
460 nsSizeMode mLastSizeMode = nsSizeMode_Normal;
461 // The old size mode before going into fullscreen mode. This should never
462 // be nsSizeMode_Fullscreen.
463 nsSizeMode mPreFullscreenSizeMode = nsSizeMode_Normal;
464 // Whether we're in fullscreen. We need to keep this state out of band,
465 // rather than just using mSizeMode, because a window can be minimized
466 // while fullscreen, and we don't store the fullscreen state anywhere else.
467 bool mFullscreenMode = false;
468 nsWindow* mWindow;
471 // Manager for taskbar-hiding. No persistent state.
472 class TaskbarConcealer;
474 // A magic number to identify the FAKETRACKPOINTSCROLLABLE window created
475 // when the trackpoint hack is enabled.
476 enum { eFakeTrackPointScrollableID = 0x46545053 };
478 // Used for displayport suppression during window resize
479 enum ResizeState { NOT_RESIZING, IN_SIZEMOVE, RESIZING, MOVING };
481 ~nsWindow() override;
483 void WindowUsesOMTC() override;
484 void RegisterTouchWindow() override;
487 * Callbacks
489 static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam,
490 LPARAM lParam);
491 static LRESULT CALLBACK WindowProcInternal(HWND hWnd, UINT msg, WPARAM wParam,
492 LPARAM lParam);
494 static BOOL CALLBACK DispatchStarvedPaints(HWND aTopWindow, LPARAM aMsg);
495 static BOOL CALLBACK RegisterTouchForDescendants(HWND aTopWindow,
496 LPARAM aMsg);
497 static BOOL CALLBACK UnregisterTouchForDescendants(HWND aTopWindow,
498 LPARAM aMsg);
499 static LRESULT CALLBACK MozSpecialMsgFilter(int code, WPARAM wParam,
500 LPARAM lParam);
501 static LRESULT CALLBACK MozSpecialWndProc(int code, WPARAM wParam,
502 LPARAM lParam);
503 static LRESULT CALLBACK MozSpecialMouseProc(int code, WPARAM wParam,
504 LPARAM lParam);
505 static VOID CALLBACK HookTimerForPopups(HWND hwnd, UINT uMsg, UINT idEvent,
506 DWORD dwTime);
509 * Window utilities
511 LPARAM lParamToScreen(LPARAM lParam);
512 LPARAM lParamToClient(LPARAM lParam);
514 WPARAM wParamFromGlobalMouseState();
516 bool AssociateWithNativeWindow();
517 void DissociateFromNativeWindow();
518 bool CanTakeFocus();
519 bool UpdateNonClientMargins(bool aReflowWindow = true);
520 void UpdateDarkModeToolbar();
521 void UpdateGetWindowInfoCaptionStatus(bool aActiveCaption);
522 void ResetLayout();
523 void InvalidateNonClientRegion();
524 static const wchar_t* GetMainWindowClass();
525 HWND GetOwnerWnd() const { return ::GetWindow(mWnd, GW_OWNER); }
526 bool IsOwnerForegroundWindow() const {
527 HWND owner = GetOwnerWnd();
528 return owner && owner == ::GetForegroundWindow();
530 bool IsForegroundWindow() const { return mWnd == ::GetForegroundWindow(); }
531 bool IsPopup() const { return mWindowType == WindowType::Popup; }
532 bool IsCloaked() const { return mIsCloaked; }
535 * Event processing helpers
537 HWND GetTopLevelForFocus(HWND aCurWnd);
538 void DispatchFocusToTopLevelWindow(bool aIsActivate);
539 bool DispatchStandardEvent(mozilla::EventMessage aMsg);
540 void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam);
541 bool ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam,
542 LRESULT* aRetValue);
543 // We wrap this in ProcessMessage so we can log the return value
544 bool ProcessMessageInternal(UINT msg, WPARAM& wParam, LPARAM& lParam,
545 LRESULT* aRetValue);
546 bool ExternalHandlerProcessMessage(UINT aMessage, WPARAM& aWParam,
547 LPARAM& aLParam, MSGResult& aResult);
548 LRESULT ProcessCharMessage(const MSG& aMsg, bool* aEventDispatched);
549 LRESULT ProcessKeyUpMessage(const MSG& aMsg, bool* aEventDispatched);
550 LRESULT ProcessKeyDownMessage(const MSG& aMsg, bool* aEventDispatched);
551 static bool EventIsInsideWindow(
552 nsWindow* aWindow,
553 mozilla::Maybe<POINT> aEventPoint = mozilla::Nothing());
554 static void PostSleepWakeNotification(const bool aIsSleepMode);
555 int32_t ClientMarginHitTestPoint(int32_t mx, int32_t my);
556 void SetWindowButtonRect(WindowButtonType aButtonType,
557 const LayoutDeviceIntRect& aClientRect) override {
558 mWindowBtnRect[aButtonType] = aClientRect;
560 TimeStamp GetMessageTimeStamp(LONG aEventTime) const;
561 static void UpdateFirstEventTime(DWORD aEventTime);
562 void FinishLiveResizing(ResizeState aNewState);
563 mozilla::Maybe<mozilla::PanGestureInput> ConvertTouchToPanGesture(
564 const mozilla::MultiTouchInput& aTouchInput, PTOUCHINPUT aOriginalEvent);
565 void DispatchTouchOrPanGestureInput(mozilla::MultiTouchInput& aTouchInput,
566 PTOUCHINPUT aOSEvent);
569 * Event handlers
571 void OnDestroy() override;
572 bool OnResize(const LayoutDeviceIntSize& aSize);
573 void OnSizeModeChange();
574 bool OnGesture(WPARAM wParam, LPARAM lParam);
575 bool OnTouch(WPARAM wParam, LPARAM lParam);
576 bool OnHotKey(WPARAM wParam, LPARAM lParam);
577 bool OnPaint(uint32_t aNestingLevel);
578 void OnWindowPosChanging(WINDOWPOS* info);
579 void OnWindowPosChanged(WINDOWPOS* wp);
580 void OnSysColorChanged();
581 void OnDPIChanged(int32_t x, int32_t y, int32_t width, int32_t height);
582 bool OnPointerEvents(UINT msg, WPARAM wParam, LPARAM lParam);
585 * Function that registers when the user has been active (used for detecting
586 * when the user is idle).
588 void UserActivity();
590 int32_t GetHeight(int32_t aProposedHeight);
592 DWORD WindowStyle();
593 DWORD WindowExStyle();
595 static const wchar_t* ChooseWindowClass(WindowType);
596 // This method registers the given window class, and returns the class name.
597 static const wchar_t* RegisterWindowClass(const wchar_t* aClassName,
598 UINT aExtraStyle, LPWSTR aIconID);
601 * Popup hooks
603 static void ScheduleHookTimer(HWND aWnd, UINT aMsgId);
604 static void RegisterSpecialDropdownHooks();
605 static void UnregisterSpecialDropdownHooks();
606 static bool GetPopupsToRollup(
607 nsIRollupListener* aRollupListener, uint32_t* aPopupsToRollup,
608 mozilla::Maybe<POINT> aEventPoint = mozilla::Nothing());
609 static bool NeedsToHandleNCActivateDelayed(HWND aWnd);
610 static bool DealWithPopups(HWND inWnd, UINT inMsg, WPARAM inWParam,
611 LPARAM inLParam, LRESULT* outResult);
614 * Window transparency helpers
616 void SetWindowTranslucencyInner(TransparencyMode aMode);
617 TransparencyMode GetWindowTranslucencyInner() const {
618 return mTransparencyMode;
620 bool IsSimulatedClientArea(int32_t clientX, int32_t clientY);
621 bool IsWindowButton(int32_t hitTestResult);
623 bool DispatchTouchEventFromWMPointer(UINT msg, LPARAM aLParam,
624 const WinPointerInfo& aPointerInfo,
625 mozilla::MouseButton aButton);
627 static bool IsAsyncResponseEvent(UINT aMsg, LRESULT& aResult);
628 void IPCWindowProcHandler(UINT& msg, WPARAM& wParam, LPARAM& lParam);
631 * Misc.
633 void StopFlashing();
634 static HWND WindowAtMouse();
635 static bool IsTopLevelMouseExit(HWND aWnd);
636 LayoutDeviceIntRegion GetRegionToPaint(bool aForceFullRepaint, PAINTSTRUCT ps,
637 HDC aDC);
638 nsIWidgetListener* GetPaintListener();
640 void CreateCompositor() override;
641 void DestroyCompositor() override;
642 void RequestFxrOutput() override;
644 void RecreateDirectManipulationIfNeeded();
645 void ResizeDirectManipulationViewport();
646 void DestroyDirectManipulation();
648 bool NeedsToTrackWindowOcclusionState();
650 void AsyncUpdateWorkspaceID(Desktop& aDesktop);
652 // See bug 603793
653 static bool HasBogusPopupsDropShadowOnMultiMonitor();
655 static void InitMouseWheelScrollData();
657 void ChangedDPI();
659 static bool InitTouchInjection();
661 bool InjectTouchPoint(uint32_t aId, LayoutDeviceIntPoint& aPoint,
662 POINTER_FLAGS aFlags, uint32_t aPressure = 1024,
663 uint32_t aOrientation = 90);
665 void OnFullscreenChanged(nsSizeMode aOldSizeMode, bool aFullScreen);
666 void TryDwmResizeHack();
668 static void OnCloakEvent(HWND aWnd, bool aCloaked);
669 void OnCloakChanged(bool aCloaked);
671 #ifdef DEBUG
672 virtual nsresult SetHiDPIMode(bool aHiDPI) override;
673 virtual nsresult RestoreHiDPIMode() override;
674 #endif
676 // Get the orientation of the hidden taskbar, on the screen that this window
677 // is on, or Nothing if taskbar isn't hidden.
678 mozilla::Maybe<UINT> GetHiddenTaskbarEdge();
680 static bool sTouchInjectInitialized;
681 static InjectTouchInputPtr sInjectTouchFuncPtr;
682 static uint32_t sInstanceCount;
683 static nsWindow* sCurrentWindow;
684 static bool sIsOleInitialized;
685 static Cursor sCurrentCursor;
686 static bool sJustGotDeactivate;
687 static bool sJustGotActivate;
688 static bool sIsInMouseCapture;
689 static bool sIsRestoringSession;
691 // Message postponement hack. See the definition-site of
692 // WndProcUrgentInvocation::sDepth for details.
693 struct MOZ_STACK_CLASS WndProcUrgentInvocation {
694 struct Marker {
695 Marker() { ++sDepth; }
696 ~Marker() { --sDepth; }
698 inline static bool IsActive() { return sDepth > 0; }
699 static size_t sDepth;
702 // Hook Data Members for Dropdowns. sProcessHook Tells the
703 // hook methods whether they should be processing the hook
704 // messages.
705 static HHOOK sMsgFilterHook;
706 static HHOOK sCallProcHook;
707 static HHOOK sCallMouseHook;
708 static bool sProcessHook;
709 static UINT sRollupMsgId;
710 static HWND sRollupMsgWnd;
711 static UINT sHookTimerId;
713 // Used to prevent dispatching mouse events that do not originate from user
714 // input.
715 static POINT sLastMouseMovePoint;
717 nsClassHashtable<nsUint32HashKey, PointerInfo> mActivePointers;
719 // This is used by SynthesizeNativeTouchPoint to maintain state between
720 // multiple synthesized points, in the case where we can't call InjectTouch
721 // directly.
722 mozilla::UniquePtr<mozilla::MultiTouchInput> mSynthesizedTouchInput;
724 InputContext mInputContext;
726 nsCOMPtr<nsIWidget> mParent;
727 nsIntSize mLastSize = nsIntSize(0, 0);
728 nsIntPoint mLastPoint;
729 HWND mWnd = nullptr;
730 HWND mTransitionWnd = nullptr;
731 mozilla::Maybe<WNDPROC> mPrevWndProc;
732 HBRUSH mBrush;
733 IMEContext mDefaultIMC;
734 HDEVNOTIFY mDeviceNotifyHandle = nullptr;
735 bool mIsTopWidgetWindow = false;
736 bool mInDtor = false;
737 bool mIsVisible = false;
738 bool mIsCloaked = false;
739 bool mTouchWindow = false;
740 bool mDisplayPanFeedback = false;
741 bool mHideChrome = false;
742 bool mIsRTL;
743 bool mMousePresent = false;
744 bool mSimulatedClientArea = false;
745 bool mDestroyCalled = false;
746 bool mOpeningAnimationSuppressed;
747 bool mAlwaysOnTop;
748 bool mIsEarlyBlankWindow = false;
749 bool mIsShowingPreXULSkeletonUI = false;
750 bool mResizable = false;
751 // Whether we're an alert window. Alert windows don't have taskbar icons and
752 // don't steal focus from other windows when opened. They're also expected to
753 // be of type WindowType::Dialog.
754 bool mIsAlert = false;
755 bool mIsPerformingDwmFlushHack = false;
756 bool mDraggingWindowWithMouse = false;
757 // Partial cached window-styles, for when going fullscreen. (Only window-
758 // decoration-related flags are saved here.)
759 struct WindowStyles {
760 LONG_PTR style, exStyle;
762 mozilla::Maybe<WindowStyles> mOldStyles;
763 nsNativeDragTarget* mNativeDragTarget = nullptr;
764 HKL mLastKeyboardLayout = 0;
765 mozilla::CheckInvariantWrapper<FrameState> mFrameState;
766 WindowHook mWindowHook;
767 uint32_t mPickerDisplayCount = 0;
768 HICON mIconSmall = nullptr;
769 HICON mIconBig = nullptr;
770 HWND mLastKillFocusWindow = nullptr;
771 PlatformCompositorWidgetDelegate* mCompositorWidgetDelegate = nullptr;
773 LayoutDeviceIntMargin NonClientSizeMargin() const {
774 return NonClientSizeMargin(mNonClientOffset);
776 LayoutDeviceIntMargin NonClientSizeMargin(
777 const LayoutDeviceIntMargin& aNonClientOffset) const;
778 LayoutDeviceIntMargin NormalWindowNonClientOffset() const;
780 // Non-client margin settings
781 // Pre-calculated outward offset applied to default frames
782 LayoutDeviceIntMargin mNonClientOffset;
783 // Margins set by the owner
784 LayoutDeviceIntMargin mNonClientMargins;
785 // Margins we'd like to set once chrome is reshown:
786 LayoutDeviceIntMargin mFutureMarginsOnceChromeShows;
787 // Indicates we need to apply margins once toggling chrome into showing:
788 bool mFutureMarginsToUse = false;
790 // Indicates custom frames are enabled
791 bool mCustomNonClient = false;
792 // Indicates custom resize margins are in effect
793 bool mUseResizeMarginOverrides = false;
794 // Width of the left and right portions of the resize region
795 mozilla::LayoutDeviceIntCoord mHorResizeMargin;
796 // Height of the top and bottom portions of the resize region
797 mozilla::LayoutDeviceIntCoord mVertResizeMargin;
798 // Height of the caption plus border
799 mozilla::LayoutDeviceIntCoord mCaptionHeight;
801 // not yet set, will be calculated on first use
802 double mDefaultScale = -1.0;
804 // not yet set, will be calculated on first use
805 float mAspectRatio = 0.0;
807 nsCOMPtr<nsIUserIdleServiceInternal> mIdleService;
809 // Draggable titlebar region maintained by UpdateWindowDraggingRegion
810 LayoutDeviceIntRegion mDraggableRegion;
812 // Graphics
813 LayoutDeviceIntRect mLastPaintBounds;
815 ResizeState mResizeState = NOT_RESIZING;
817 // Transparency
818 TransparencyMode mTransparencyMode = TransparencyMode::Opaque;
819 nsIntRegion mPossiblyTransparentRegion;
821 // Win7 Gesture processing and management
822 nsWinGesture mGesture;
824 // Weak ref to the nsITaskbarWindowPreview associated with this window
825 nsWeakPtr mTaskbarPreview = nullptr;
827 // The input region that determines whether mouse events should be ignored
828 // and pass through to the window below. This is currently only used for
829 // popups.
830 InputRegion mInputRegion;
832 // True if the taskbar (possibly through the tab preview) tells us that the
833 // icon has been created on the taskbar.
834 bool mHasTaskbarIconBeenCreated = false;
836 // Whether we're in the process of sending a WM_SETTEXT ourselves
837 bool mSendingSetText = false;
839 // Whether we were created as a child window (aka ChildWindow) or not.
840 bool mIsChildWindow : 1;
842 int32_t mCachedHitTestResult = 0;
844 // The point in time at which the last paint completed. We use this to avoid
845 // painting too rapidly in response to frequent input events.
846 TimeStamp mLastPaintEndTime;
848 // Caching for hit test results (in client coordinates)
849 LayoutDeviceIntPoint mCachedHitTestPoint;
850 TimeStamp mCachedHitTestTime;
852 RefPtr<mozilla::widget::InProcessWinCompositorWidget> mBasicLayersSurface;
854 double mSizeConstraintsScale; // scale in effect when setting constraints
856 // Will be calculated when layer manager is created.
857 int32_t mMaxTextureSize = -1;
859 // Pointer events processing and management
860 WinPointerEvents mPointerEvents;
862 ScreenPoint mLastPanGestureFocus;
864 // When true, used to indicate an async call to RequestFxrOutput to the GPU
865 // process after the Compositor is created
866 bool mRequestFxrOutputPending = false;
868 // A stack based class used in DispatchMouseEvent() to tell whether we should
869 // NOT open context menu when we receives WM_CONTEXTMENU after the
870 // DispatchMouseEvent calls.
871 // This class now works only in the case where a mouse up event happened in
872 // the overscroll gutter.
873 class MOZ_STACK_CLASS ContextMenuPreventer final {
874 public:
875 explicit ContextMenuPreventer(nsWindow* aWindow)
876 : mWindow(aWindow), mNeedsToPreventContextMenu(false){};
877 ~ContextMenuPreventer() {
878 mWindow->mNeedsToPreventContextMenu = mNeedsToPreventContextMenu;
880 void Update(const mozilla::WidgetMouseEvent& aEvent,
881 const nsIWidget::ContentAndAPZEventStatus& aEventStatus);
883 private:
884 nsWindow* mWindow;
885 bool mNeedsToPreventContextMenu = false;
887 friend class ContextMenuPreventer;
888 bool mNeedsToPreventContextMenu = false;
890 mozilla::UniquePtr<mozilla::widget::DirectManipulationOwner> mDmOwner;
892 // Client rect for minimize, maximize and close buttons.
893 mozilla::EnumeratedArray<WindowButtonType, LayoutDeviceIntRect,
894 size_t(WindowButtonType::Count)>
895 mWindowBtnRect;
897 mozilla::DataMutex<Desktop> mDesktopId;
899 // If set, indicates the edge of the NC region we should clear to black
900 // on next paint. One of: ABE_TOP, ABE_BOTTOM, ABE_LEFT or ABE_RIGHT.
901 mozilla::Maybe<UINT> mClearNCEdge;
903 friend class nsWindowGfx;
905 static constexpr int kHiddenTaskbarSize = 2;
908 #endif // WIDGET_WINDOWS_NSWINDOW_H_