Backed out 7 changesets (bug 1881620) for causing frequent media crashes. CLOSED...
[gecko.git] / widget / windows / nsWindow.h
blob3a521fb97832ded71c1b6d44d94990a2da514f85
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);
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 * Popup hooks
604 static void ScheduleHookTimer(HWND aWnd, UINT aMsgId);
605 static void RegisterSpecialDropdownHooks();
606 static void UnregisterSpecialDropdownHooks();
607 static bool GetPopupsToRollup(
608 nsIRollupListener* aRollupListener, uint32_t* aPopupsToRollup,
609 mozilla::Maybe<POINT> aEventPoint = mozilla::Nothing());
610 static bool NeedsToHandleNCActivateDelayed(HWND aWnd);
611 static bool DealWithPopups(HWND inWnd, UINT inMsg, WPARAM inWParam,
612 LPARAM inLParam, LRESULT* outResult);
615 * Window transparency helpers
617 void SetWindowTranslucencyInner(TransparencyMode aMode);
618 TransparencyMode GetWindowTranslucencyInner() const {
619 return mTransparencyMode;
621 bool IsSimulatedClientArea(int32_t clientX, int32_t clientY);
622 bool IsWindowButton(int32_t hitTestResult);
624 bool DispatchTouchEventFromWMPointer(UINT msg, LPARAM aLParam,
625 const WinPointerInfo& aPointerInfo,
626 mozilla::MouseButton aButton);
628 static bool IsAsyncResponseEvent(UINT aMsg, LRESULT& aResult);
629 void IPCWindowProcHandler(UINT& msg, WPARAM& wParam, LPARAM& lParam);
632 * Misc.
634 void StopFlashing();
635 static HWND WindowAtMouse();
636 static bool IsTopLevelMouseExit(HWND aWnd);
637 LayoutDeviceIntRegion GetRegionToPaint(bool aForceFullRepaint, PAINTSTRUCT ps,
638 HDC aDC);
639 nsIWidgetListener* GetPaintListener();
641 void CreateCompositor() override;
642 void DestroyCompositor() override;
643 void RequestFxrOutput() override;
645 void RecreateDirectManipulationIfNeeded();
646 void ResizeDirectManipulationViewport();
647 void DestroyDirectManipulation();
649 bool NeedsToTrackWindowOcclusionState();
651 void AsyncUpdateWorkspaceID(Desktop& aDesktop);
653 // See bug 603793
654 static bool HasBogusPopupsDropShadowOnMultiMonitor();
656 static void InitMouseWheelScrollData();
658 void ChangedDPI();
660 static bool InitTouchInjection();
662 bool InjectTouchPoint(uint32_t aId, LayoutDeviceIntPoint& aPoint,
663 POINTER_FLAGS aFlags, uint32_t aPressure = 1024,
664 uint32_t aOrientation = 90);
666 void OnFullscreenChanged(nsSizeMode aOldSizeMode, bool aFullScreen);
667 void TryDwmResizeHack();
669 static void OnCloakEvent(HWND aWnd, bool aCloaked);
670 void OnCloakChanged(bool aCloaked);
672 #ifdef DEBUG
673 virtual nsresult SetHiDPIMode(bool aHiDPI) override;
674 virtual nsresult RestoreHiDPIMode() override;
675 #endif
677 // Get the orientation of the hidden taskbar, on the screen that this window
678 // is on, or Nothing if taskbar isn't hidden.
679 mozilla::Maybe<UINT> GetHiddenTaskbarEdge();
681 static bool sTouchInjectInitialized;
682 static InjectTouchInputPtr sInjectTouchFuncPtr;
683 static uint32_t sInstanceCount;
684 static nsWindow* sCurrentWindow;
685 static bool sIsOleInitialized;
686 static Cursor sCurrentCursor;
687 static bool sJustGotDeactivate;
688 static bool sJustGotActivate;
689 static bool sIsInMouseCapture;
690 static bool sIsRestoringSession;
692 // Message postponement hack. See the definition-site of
693 // WndProcUrgentInvocation::sDepth for details.
694 struct MOZ_STACK_CLASS WndProcUrgentInvocation {
695 struct Marker {
696 Marker() { ++sDepth; }
697 ~Marker() { --sDepth; }
699 inline static bool IsActive() { return sDepth > 0; }
700 static size_t sDepth;
703 // Hook Data Members for Dropdowns. sProcessHook Tells the
704 // hook methods whether they should be processing the hook
705 // messages.
706 static HHOOK sMsgFilterHook;
707 static HHOOK sCallProcHook;
708 static HHOOK sCallMouseHook;
709 static bool sProcessHook;
710 static UINT sRollupMsgId;
711 static HWND sRollupMsgWnd;
712 static UINT sHookTimerId;
714 // Used to prevent dispatching mouse events that do not originate from user
715 // input.
716 static POINT sLastMouseMovePoint;
718 nsClassHashtable<nsUint32HashKey, PointerInfo> mActivePointers;
720 // This is used by SynthesizeNativeTouchPoint to maintain state between
721 // multiple synthesized points, in the case where we can't call InjectTouch
722 // directly.
723 mozilla::UniquePtr<mozilla::MultiTouchInput> mSynthesizedTouchInput;
725 InputContext mInputContext;
727 nsCOMPtr<nsIWidget> mParent;
728 nsIntSize mLastSize = nsIntSize(0, 0);
729 nsIntPoint mLastPoint;
730 HWND mWnd = nullptr;
731 HWND mTransitionWnd = nullptr;
732 mozilla::Maybe<WNDPROC> mPrevWndProc;
733 HBRUSH mBrush;
734 IMEContext mDefaultIMC;
735 HDEVNOTIFY mDeviceNotifyHandle = nullptr;
736 bool mIsTopWidgetWindow = false;
737 bool mInDtor = false;
738 bool mIsVisible = false;
739 bool mIsCloaked = false;
740 bool mTouchWindow = false;
741 bool mDisplayPanFeedback = false;
742 bool mHideChrome = false;
743 bool mIsRTL;
744 bool mMousePresent = false;
745 bool mSimulatedClientArea = false;
746 bool mDestroyCalled = false;
747 bool mOpeningAnimationSuppressed;
748 bool mAlwaysOnTop;
749 bool mIsEarlyBlankWindow = false;
750 bool mIsShowingPreXULSkeletonUI = false;
751 bool mResizable = false;
752 // Whether we're an alert window. Alert windows don't have taskbar icons and
753 // don't steal focus from other windows when opened. They're also expected to
754 // be of type WindowType::Dialog.
755 bool mIsAlert = false;
756 bool mIsPerformingDwmFlushHack = false;
757 bool mDraggingWindowWithMouse = false;
758 DWORD_PTR mOldStyle = 0;
759 DWORD_PTR mOldExStyle = 0;
760 nsNativeDragTarget* mNativeDragTarget = nullptr;
761 HKL mLastKeyboardLayout = 0;
762 mozilla::CheckInvariantWrapper<FrameState> mFrameState;
763 WindowHook mWindowHook;
764 uint32_t mPickerDisplayCount = 0;
765 HICON mIconSmall = nullptr;
766 HICON mIconBig = nullptr;
767 HWND mLastKillFocusWindow = nullptr;
768 PlatformCompositorWidgetDelegate* mCompositorWidgetDelegate = nullptr;
770 LayoutDeviceIntMargin NonClientSizeMargin() const {
771 return NonClientSizeMargin(mNonClientOffset);
773 LayoutDeviceIntMargin NonClientSizeMargin(
774 const LayoutDeviceIntMargin& aNonClientOffset) const;
775 LayoutDeviceIntMargin NormalWindowNonClientOffset() const;
777 // Non-client margin settings
778 // Pre-calculated outward offset applied to default frames
779 LayoutDeviceIntMargin mNonClientOffset;
780 // Margins set by the owner
781 LayoutDeviceIntMargin mNonClientMargins;
782 // Margins we'd like to set once chrome is reshown:
783 LayoutDeviceIntMargin mFutureMarginsOnceChromeShows;
784 // Indicates we need to apply margins once toggling chrome into showing:
785 bool mFutureMarginsToUse = false;
787 // Indicates custom frames are enabled
788 bool mCustomNonClient = false;
789 // Indicates custom resize margins are in effect
790 bool mUseResizeMarginOverrides = false;
791 // Width of the left and right portions of the resize region
792 mozilla::LayoutDeviceIntCoord mHorResizeMargin;
793 // Height of the top and bottom portions of the resize region
794 mozilla::LayoutDeviceIntCoord mVertResizeMargin;
795 // Height of the caption plus border
796 mozilla::LayoutDeviceIntCoord mCaptionHeight;
798 // not yet set, will be calculated on first use
799 double mDefaultScale = -1.0;
801 // not yet set, will be calculated on first use
802 float mAspectRatio = 0.0;
804 nsCOMPtr<nsIUserIdleServiceInternal> mIdleService;
806 // Draggable titlebar region maintained by UpdateWindowDraggingRegion
807 LayoutDeviceIntRegion mDraggableRegion;
809 // Graphics
810 LayoutDeviceIntRect mLastPaintBounds;
812 ResizeState mResizeState = NOT_RESIZING;
814 // Transparency
815 TransparencyMode mTransparencyMode = TransparencyMode::Opaque;
816 nsIntRegion mPossiblyTransparentRegion;
818 // Win7 Gesture processing and management
819 nsWinGesture mGesture;
821 // Weak ref to the nsITaskbarWindowPreview associated with this window
822 nsWeakPtr mTaskbarPreview = nullptr;
824 // The input region that determines whether mouse events should be ignored
825 // and pass through to the window below. This is currently only used for
826 // popups.
827 InputRegion mInputRegion;
829 // True if the taskbar (possibly through the tab preview) tells us that the
830 // icon has been created on the taskbar.
831 bool mHasTaskbarIconBeenCreated = false;
833 // Whether we're in the process of sending a WM_SETTEXT ourselves
834 bool mSendingSetText = false;
836 // Whether we were created as a child window (aka ChildWindow) or not.
837 bool mIsChildWindow : 1;
839 int32_t mCachedHitTestResult = 0;
841 // The point in time at which the last paint completed. We use this to avoid
842 // painting too rapidly in response to frequent input events.
843 TimeStamp mLastPaintEndTime;
845 // Caching for hit test results (in client coordinates)
846 LayoutDeviceIntPoint mCachedHitTestPoint;
847 TimeStamp mCachedHitTestTime;
849 RefPtr<mozilla::widget::InProcessWinCompositorWidget> mBasicLayersSurface;
851 double mSizeConstraintsScale; // scale in effect when setting constraints
853 // Will be calculated when layer manager is created.
854 int32_t mMaxTextureSize = -1;
856 // Pointer events processing and management
857 WinPointerEvents mPointerEvents;
859 ScreenPoint mLastPanGestureFocus;
861 // When true, used to indicate an async call to RequestFxrOutput to the GPU
862 // process after the Compositor is created
863 bool mRequestFxrOutputPending = false;
865 // A stack based class used in DispatchMouseEvent() to tell whether we should
866 // NOT open context menu when we receives WM_CONTEXTMENU after the
867 // DispatchMouseEvent calls.
868 // This class now works only in the case where a mouse up event happened in
869 // the overscroll gutter.
870 class MOZ_STACK_CLASS ContextMenuPreventer final {
871 public:
872 explicit ContextMenuPreventer(nsWindow* aWindow)
873 : mWindow(aWindow), mNeedsToPreventContextMenu(false){};
874 ~ContextMenuPreventer() {
875 mWindow->mNeedsToPreventContextMenu = mNeedsToPreventContextMenu;
877 void Update(const mozilla::WidgetMouseEvent& aEvent,
878 const nsIWidget::ContentAndAPZEventStatus& aEventStatus);
880 private:
881 nsWindow* mWindow;
882 bool mNeedsToPreventContextMenu = false;
884 friend class ContextMenuPreventer;
885 bool mNeedsToPreventContextMenu = false;
887 mozilla::UniquePtr<mozilla::widget::DirectManipulationOwner> mDmOwner;
889 // Client rect for minimize, maximize and close buttons.
890 mozilla::EnumeratedArray<WindowButtonType, LayoutDeviceIntRect,
891 size_t(WindowButtonType::Count)>
892 mWindowBtnRect;
894 mozilla::DataMutex<Desktop> mDesktopId;
896 // If set, indicates the edge of the NC region we should clear to black
897 // on next paint. One of: ABE_TOP, ABE_BOTTOM, ABE_LEFT or ABE_RIGHT.
898 mozilla::Maybe<UINT> mClearNCEdge;
900 friend class nsWindowGfx;
902 static constexpr int kHiddenTaskbarSize = 2;
905 #endif // WIDGET_WINDOWS_NSWINDOW_H_