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/. */ 5 6 #ifndef Window_h__ 7 #define Window_h__ 8 9 /* 10 * nsWindow - Native window management and event handling. 11 */ 12 13 #include "mozilla/RefPtr.h" 14 #include "nsBaseWidget.h" 15 #include "CompositorWidget.h" 16 #include "nsWindowBase.h" 17 #include "nsdefs.h" 18 #include "nsUserIdleService.h" 19 #include "nsToolkit.h" 20 #include "nsString.h" 21 #include "nsTArray.h" 22 #include "gfxWindowsPlatform.h" 23 #include "gfxWindowsSurface.h" 24 #include "nsWindowDbg.h" 25 #include "cairo.h" 26 #include "nsRegion.h" 27 #include "mozilla/EventForwards.h" 28 #include "mozilla/Maybe.h" 29 #include "mozilla/MouseEvents.h" 30 #include "mozilla/TimeStamp.h" 31 #include "mozilla/webrender/WebRenderTypes.h" 32 #include "mozilla/dom/MouseEventBinding.h" 33 #include "mozilla/UniquePtr.h" 34 #include "nsMargin.h" 35 #include "nsRegionFwd.h" 36 37 #include "nsWinGesture.h" 38 #include "WinPointerEvents.h" 39 #include "WinUtils.h" 40 #include "WindowHook.h" 41 #include "TaskbarWindowPreview.h" 42 43 #ifdef ACCESSIBILITY 44 # include "oleacc.h" 45 # include "mozilla/a11y/LocalAccessible.h" 46 #endif 47 48 #include "nsUXThemeData.h" 49 #include "nsIUserIdleServiceInternal.h" 50 51 #include "IMMHandler.h" 52 53 /** 54 * Forward class definitions 55 */ 56 57 class nsNativeDragTarget; 58 class nsIRollupListener; 59 class imgIContainer; 60 61 namespace mozilla { 62 namespace widget { 63 class NativeKey; 64 class InProcessWinCompositorWidget; 65 struct MSGResult; 66 class DirectManipulationOwner; 67 } // namespace widget 68 } // namespace mozilla 69 70 /** 71 * Forward Windows-internal definitions of otherwise incomplete ones provided by 72 * the SDK. 73 */ 74 const CLSID CLSID_ImmersiveShell = { 75 0xC2F03A33, 76 0x21F5, 77 0x47FA, 78 {0xB4, 0xBB, 0x15, 0x63, 0x62, 0xA2, 0xF2, 0x39}}; 79 80 // Virtual Desktop. 81 82 EXTERN_C const IID IID_IVirtualDesktopManager; 83 MIDL_INTERFACE("a5cd92ff-29be-454c-8d04-d82879fb3f1b") 84 IVirtualDesktopManager : public IUnknown { 85 public: 86 virtual HRESULT STDMETHODCALLTYPE GetWindowDesktopId( 87 __RPC__in HWND topLevelWindow, __RPC__out GUID * desktopId) = 0; 88 virtual HRESULT STDMETHODCALLTYPE MoveWindowToDesktop( 89 __RPC__in HWND topLevelWindow, __RPC__in REFGUID desktopId) = 0; 90 }; 91 92 /** 93 * Native WIN32 window wrapper. 94 */ 95 96 class nsWindow final : public nsWindowBase { 97 typedef mozilla::TimeStamp TimeStamp; 98 typedef mozilla::TimeDuration TimeDuration; 99 typedef mozilla::widget::WindowHook WindowHook; 100 typedef mozilla::widget::TaskbarWindowPreview TaskbarWindowPreview; 101 typedef mozilla::widget::NativeKey NativeKey; 102 typedef mozilla::widget::MSGResult MSGResult; 103 typedef mozilla::widget::IMEContext IMEContext; 104 typedef mozilla::widget::PlatformCompositorWidgetDelegate 105 PlatformCompositorWidgetDelegate; 106 107 public: 108 explicit nsWindow(bool aIsChildWindow = false); 109 110 NS_INLINE_DECL_REFCOUNTING_INHERITED(nsWindow, nsWindowBase) 111 112 friend class nsWindowGfx; 113 114 void SendAnAPZEvent(mozilla::InputData& aEvent); 115 116 // nsWindowBase 117 virtual void InitEvent(mozilla::WidgetGUIEvent& aEvent, 118 LayoutDeviceIntPoint* aPoint = nullptr) override; 119 virtual WidgetEventTime CurrentMessageWidgetEventTime() const override; 120 virtual bool DispatchWindowEvent(mozilla::WidgetGUIEvent* aEvent) override; 121 virtual bool DispatchKeyboardEvent( 122 mozilla::WidgetKeyboardEvent* aEvent) override; 123 virtual bool DispatchWheelEvent(mozilla::WidgetWheelEvent* aEvent) override; 124 virtual bool DispatchContentCommandEvent( 125 mozilla::WidgetContentCommandEvent* aEvent) override; 126 virtual nsWindowBase* GetParentWindowBase(bool aIncludeOwner) override; IsTopLevelWidget()127 virtual bool IsTopLevelWidget() override { return mIsTopWidgetWindow; } 128 129 // nsIWidget interface 130 using nsWindowBase::Create; // for Create signature not overridden here 131 [[nodiscard]] virtual nsresult Create( 132 nsIWidget* aParent, nsNativeWidget aNativeParent, 133 const LayoutDeviceIntRect& aRect, 134 nsWidgetInitData* aInitData = nullptr) override; 135 virtual void Destroy() override; 136 virtual void SetParent(nsIWidget* aNewParent) override; 137 virtual nsIWidget* GetParent(void) override; 138 virtual float GetDPI() override; 139 double GetDefaultScaleInternal() final; 140 int32_t LogToPhys(double aValue) final; GetDesktopToDeviceScale()141 mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() final { 142 if (mozilla::widget::WinUtils::IsPerMonitorDPIAware()) { 143 return mozilla::DesktopToLayoutDeviceScale(1.0); 144 } else { 145 return mozilla::DesktopToLayoutDeviceScale(GetDefaultScaleInternal()); 146 } 147 } 148 149 virtual void Show(bool aState) override; 150 virtual bool IsVisible() const override; 151 virtual void ConstrainPosition(bool aAllowSlop, int32_t* aX, 152 int32_t* aY) override; 153 virtual void SetSizeConstraints(const SizeConstraints& aConstraints) override; 154 virtual void LockAspectRatio(bool aShouldLock) override; 155 virtual const SizeConstraints GetSizeConstraints() override; 156 virtual void SetWindowMouseTransparent(bool aIsTransparent) override; 157 virtual void Move(double aX, double aY) override; 158 virtual void Resize(double aWidth, double aHeight, bool aRepaint) override; 159 virtual void Resize(double aX, double aY, double aWidth, double aHeight, 160 bool aRepaint) override; 161 virtual mozilla::Maybe<bool> IsResizingNativeWidget() override; 162 [[nodiscard]] virtual nsresult BeginResizeDrag( 163 mozilla::WidgetGUIEvent* aEvent, int32_t aHorizontal, 164 int32_t aVertical) override; 165 virtual void PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, 166 nsIWidget* aWidget, bool aActivate) override; 167 virtual void SetSizeMode(nsSizeMode aMode) override; 168 virtual void GetWorkspaceID(nsAString& workspaceID) override; 169 virtual void MoveToWorkspace(const nsAString& workspaceID) override; 170 virtual void SuppressAnimation(bool aSuppress) override; 171 virtual void Enable(bool aState) override; 172 virtual bool IsEnabled() const override; 173 virtual void SetFocus(Raise, mozilla::dom::CallerType aCallerType) override; 174 virtual LayoutDeviceIntRect GetBounds() override; 175 virtual LayoutDeviceIntRect GetScreenBounds() override; 176 [[nodiscard]] virtual nsresult GetRestoredBounds( 177 LayoutDeviceIntRect& aRect) override; 178 virtual LayoutDeviceIntRect GetClientBounds() override; 179 virtual LayoutDeviceIntPoint GetClientOffset() override; 180 void SetBackgroundColor(const nscolor& aColor) override; 181 virtual void SetCursor(const Cursor&) override; 182 virtual nsresult ConfigureChildren( 183 const nsTArray<Configuration>& aConfigurations) override; 184 virtual bool PrepareForFullscreenTransition(nsISupports** aData) override; 185 virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage, 186 uint16_t aDuration, 187 nsISupports* aData, 188 nsIRunnable* aCallback) override; 189 virtual void CleanupFullscreenTransition() override; 190 virtual nsresult MakeFullScreen(bool aFullScreen, 191 nsIScreen* aScreen = nullptr) override; 192 virtual void HideWindowChrome(bool aShouldHide) override; 193 virtual void Invalidate(bool aEraseBackground = false, 194 bool aUpdateNCArea = false, 195 bool aIncludeChildren = false); 196 virtual void Invalidate(const LayoutDeviceIntRect& aRect); 197 virtual void* GetNativeData(uint32_t aDataType) override; 198 void SetNativeData(uint32_t aDataType, uintptr_t aVal) override; 199 virtual void FreeNativeData(void* data, uint32_t aDataType) override; 200 virtual nsresult SetTitle(const nsAString& aTitle) override; 201 virtual void SetIcon(const nsAString& aIconSpec) override; 202 virtual LayoutDeviceIntPoint WidgetToScreenOffset() override; 203 virtual LayoutDeviceIntSize ClientToWindowSize( 204 const LayoutDeviceIntSize& aClientSize) override; 205 virtual nsresult DispatchEvent(mozilla::WidgetGUIEvent* aEvent, 206 nsEventStatus& aStatus) override; 207 virtual void EnableDragDrop(bool aEnable) override; 208 virtual void CaptureMouse(bool aCapture) override; 209 virtual void CaptureRollupEvents(nsIRollupListener* aListener, 210 bool aDoCapture) override; 211 [[nodiscard]] virtual nsresult GetAttention(int32_t aCycleCount) override; 212 virtual bool HasPendingInputEvent() override; 213 virtual LayerManager* GetLayerManager( 214 PLayerTransactionChild* aShadowManager = nullptr, 215 LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE, 216 LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT) override; 217 void SetCompositorWidgetDelegate(CompositorWidgetDelegate* delegate) override; 218 [[nodiscard]] virtual nsresult OnDefaultButtonLoaded( 219 const LayoutDeviceIntRect& aButtonRect) override; 220 virtual nsresult SynthesizeNativeKeyEvent( 221 int32_t aNativeKeyboardLayout, int32_t aNativeKeyCode, 222 uint32_t aModifierFlags, const nsAString& aCharacters, 223 const nsAString& aUnmodifiedCharacters, nsIObserver* aObserver) override; 224 virtual nsresult SynthesizeNativeMouseEvent( 225 LayoutDeviceIntPoint aPoint, NativeMouseMessage aNativeMessage, 226 mozilla::MouseButton aButton, nsIWidget::Modifiers aModifierFlags, 227 nsIObserver* aObserver) override; 228 SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,nsIObserver * aObserver)229 virtual nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint, 230 nsIObserver* aObserver) override { 231 return SynthesizeNativeMouseEvent( 232 aPoint, NativeMouseMessage::Move, mozilla::MouseButton::eNotPressed, 233 nsIWidget::Modifiers::NO_MODIFIERS, aObserver); 234 } 235 236 virtual nsresult SynthesizeNativeMouseScrollEvent( 237 LayoutDeviceIntPoint aPoint, uint32_t aNativeMessage, double aDeltaX, 238 double aDeltaY, double aDeltaZ, uint32_t aModifierFlags, 239 uint32_t aAdditionalFlags, nsIObserver* aObserver) override; 240 virtual void SetInputContext(const InputContext& aContext, 241 const InputContextAction& aAction) override; 242 virtual InputContext GetInputContext() override; 243 virtual TextEventDispatcherListener* GetNativeTextEventDispatcherListener() 244 override; 245 #ifdef MOZ_XUL 246 virtual void SetTransparencyMode(nsTransparencyMode aMode) override; 247 virtual nsTransparencyMode GetTransparencyMode() override; 248 virtual void UpdateOpaqueRegion( 249 const LayoutDeviceIntRegion& aOpaqueRegion) override; 250 #endif // MOZ_XUL 251 virtual nsresult SetNonClientMargins( 252 LayoutDeviceIntMargin& aMargins) override; 253 void SetDrawsInTitlebar(bool aState) override; 254 virtual void UpdateWindowDraggingRegion( 255 const LayoutDeviceIntRegion& aRegion) override; 256 257 virtual void UpdateThemeGeometries( 258 const nsTArray<ThemeGeometry>& aThemeGeometries) override; 259 virtual uint32_t GetMaxTouchPoints() const override; 260 virtual void SetWindowClass(const nsAString& xulWinType) override; 261 262 /** 263 * Event helpers 264 */ 265 virtual bool DispatchMouseEvent(mozilla::EventMessage aEventMessage, 266 WPARAM wParam, LPARAM lParam, 267 bool aIsContextMenuKey, int16_t aButton, 268 uint16_t aInputSource, 269 WinPointerInfo* aPointerInfo = nullptr); 270 virtual bool DispatchWindowEvent(mozilla::WidgetGUIEvent* aEvent, 271 nsEventStatus& aStatus); 272 void DispatchPendingEvents(); 273 void DispatchCustomEvent(const nsString& eventName); 274 275 #ifdef ACCESSIBILITY 276 /** 277 * Return an accessible associated with the window. 278 */ 279 mozilla::a11y::LocalAccessible* GetAccessible(); 280 #endif // ACCESSIBILITY 281 282 /** 283 * Window utilities 284 */ 285 nsWindow* GetTopLevelWindow(bool aStopOnDialogOrPopup); GetPrevWindowProc()286 WNDPROC GetPrevWindowProc() { return mPrevWndProc; } GetWindowHook()287 WindowHook& GetWindowHook() { return mWindowHook; } 288 nsWindow* GetParentWindow(bool aIncludeOwner); 289 // Get an array of all nsWindow*s on the main thread. 290 static nsTArray<nsWindow*> EnumAllWindows(); 291 292 /** 293 * Misc. 294 */ 295 virtual bool AutoErase(HDC dc); 296 bool WidgetTypeSupportsAcceleration() override; 297 298 void ForcePresent(); 299 bool TouchEventShouldStartDrag(mozilla::EventMessage aEventMessage, 300 LayoutDeviceIntPoint aEventPoint); 301 302 void SetSmallIcon(HICON aIcon); 303 void SetBigIcon(HICON aIcon); 304 SetIsRestoringSession(const bool aIsRestoringSession)305 static void SetIsRestoringSession(const bool aIsRestoringSession) { 306 sIsRestoringSession = aIsRestoringSession; 307 } 308 309 /** 310 * AssociateDefaultIMC() associates or disassociates the default IMC for 311 * the window. 312 * 313 * @param aAssociate TRUE, associates the default IMC with the window. 314 * Otherwise, disassociates the default IMC from the 315 * window. 316 * @return TRUE if this method associated the default IMC with 317 * disassociated window or disassociated the default IMC 318 * from associated window. 319 * Otherwise, i.e., if this method did nothing actually, 320 * FALSE. 321 */ 322 bool AssociateDefaultIMC(bool aAssociate); 323 HasTaskbarIconBeenCreated()324 bool HasTaskbarIconBeenCreated() { return mHasTaskbarIconBeenCreated; } 325 // Called when either the nsWindow or an nsITaskbarTabPreview receives the 326 // noticiation that this window has its icon placed on the taskbar. 327 void SetHasTaskbarIconBeenCreated(bool created = true) { 328 mHasTaskbarIconBeenCreated = created; 329 } 330 331 // Getter/setter for the nsITaskbarWindowPreview for this nsWindow GetTaskbarPreview()332 already_AddRefed<nsITaskbarWindowPreview> GetTaskbarPreview() { 333 nsCOMPtr<nsITaskbarWindowPreview> preview( 334 do_QueryReferent(mTaskbarPreview)); 335 return preview.forget(); 336 } SetTaskbarPreview(nsITaskbarWindowPreview * preview)337 void SetTaskbarPreview(nsITaskbarWindowPreview* preview) { 338 mTaskbarPreview = do_GetWeakReference(preview); 339 } 340 341 virtual void ReparentNativeWidget(nsIWidget* aNewParent) override; 342 343 // Open file picker tracking 344 void PickerOpen(); 345 void PickerClosed(); 346 DestroyCalled()347 bool const DestroyCalled() { return mDestroyCalled; } 348 349 bool IsPopup(); 350 virtual bool ShouldUseOffMainThreadCompositing() override; 351 DefaultIMC()352 const IMEContext& DefaultIMC() const { return mDefaultIMC; } 353 354 void GetCompositorWidgetInitData( 355 mozilla::widget::CompositorWidgetInitData* aInitData) override; IsTouchWindow()356 bool IsTouchWindow() const { return mTouchWindow; } 357 bool SynchronouslyRepaintOnResize() override; 358 virtual void MaybeDispatchInitialFocusEvent() override; 359 360 virtual void LocalesChanged() override; 361 362 protected: 363 virtual ~nsWindow(); 364 365 virtual void WindowUsesOMTC() override; 366 virtual void RegisterTouchWindow() override; 367 368 // A magic number to identify the FAKETRACKPOINTSCROLLABLE window created 369 // when the trackpoint hack is enabled. 370 enum { eFakeTrackPointScrollableID = 0x46545053 }; 371 372 // Used for displayport suppression during window resize 373 enum ResizeState { NOT_RESIZING, IN_SIZEMOVE, RESIZING, MOVING }; 374 375 /** 376 * Callbacks 377 */ 378 static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, 379 LPARAM lParam); 380 static LRESULT CALLBACK WindowProcInternal(HWND hWnd, UINT msg, WPARAM wParam, 381 LPARAM lParam); 382 383 static BOOL CALLBACK BroadcastMsgToChildren(HWND aWnd, LPARAM aMsg); 384 static BOOL CALLBACK BroadcastMsg(HWND aTopWindow, LPARAM aMsg); 385 static BOOL CALLBACK DispatchStarvedPaints(HWND aTopWindow, LPARAM aMsg); 386 static BOOL CALLBACK RegisterTouchForDescendants(HWND aTopWindow, 387 LPARAM aMsg); 388 static BOOL CALLBACK UnregisterTouchForDescendants(HWND aTopWindow, 389 LPARAM aMsg); 390 static LRESULT CALLBACK MozSpecialMsgFilter(int code, WPARAM wParam, 391 LPARAM lParam); 392 static LRESULT CALLBACK MozSpecialWndProc(int code, WPARAM wParam, 393 LPARAM lParam); 394 static LRESULT CALLBACK MozSpecialMouseProc(int code, WPARAM wParam, 395 LPARAM lParam); 396 static VOID CALLBACK HookTimerForPopups(HWND hwnd, UINT uMsg, UINT idEvent, 397 DWORD dwTime); 398 static BOOL CALLBACK ClearResourcesCallback(HWND aChild, LPARAM aParam); 399 static BOOL CALLBACK EnumAllChildWindProc(HWND aWnd, LPARAM aParam); 400 static BOOL CALLBACK EnumAllThreadWindowProc(HWND aWnd, LPARAM aParam); 401 402 /** 403 * Window utilities 404 */ 405 LPARAM lParamToScreen(LPARAM lParam); 406 LPARAM lParamToClient(LPARAM lParam); 407 virtual void SubclassWindow(BOOL bState); 408 bool CanTakeFocus(); 409 bool UpdateNonClientMargins(int32_t aSizeMode = -1, 410 bool aReflowWindow = true); 411 void UpdateGetWindowInfoCaptionStatus(bool aActiveCaption); 412 void ResetLayout(); 413 void InvalidateNonClientRegion(); 414 HRGN ExcludeNonClientFromPaintRegion(HRGN aRegion); 415 static const wchar_t* GetMainWindowClass(); HasGlass()416 bool HasGlass() const { 417 return mTransparencyMode == eTransparencyGlass || 418 mTransparencyMode == eTransparencyBorderlessGlass; 419 } GetOwnerWnd()420 HWND GetOwnerWnd() const { return ::GetWindow(mWnd, GW_OWNER); } IsOwnerForegroundWindow()421 bool IsOwnerForegroundWindow() const { 422 HWND owner = GetOwnerWnd(); 423 return owner && owner == ::GetForegroundWindow(); 424 } IsPopup()425 bool IsPopup() const { return mWindowType == eWindowType_popup; } 426 427 /** 428 * Event processing helpers 429 */ 430 HWND GetTopLevelForFocus(HWND aCurWnd); 431 void DispatchFocusToTopLevelWindow(bool aIsActivate); 432 bool DispatchStandardEvent(mozilla::EventMessage aMsg); 433 void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam); 434 virtual bool ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, 435 LRESULT* aRetValue); 436 bool ExternalHandlerProcessMessage(UINT aMessage, WPARAM& aWParam, 437 LPARAM& aLParam, MSGResult& aResult); 438 LRESULT ProcessCharMessage(const MSG& aMsg, bool* aEventDispatched); 439 LRESULT ProcessKeyUpMessage(const MSG& aMsg, bool* aEventDispatched); 440 LRESULT ProcessKeyDownMessage(const MSG& aMsg, bool* aEventDispatched); 441 static bool EventIsInsideWindow( 442 nsWindow* aWindow, 443 mozilla::Maybe<POINT> aEventPoint = mozilla::Nothing()); 444 // Convert nsEventStatus value to a windows boolean 445 static bool ConvertStatus(nsEventStatus aStatus); 446 static void PostSleepWakeNotification(const bool aIsSleepMode); 447 int32_t ClientMarginHitTestPoint(int32_t mx, int32_t my); 448 TimeStamp GetMessageTimeStamp(LONG aEventTime) const; 449 static void UpdateFirstEventTime(DWORD aEventTime); 450 void FinishLiveResizing(ResizeState aNewState); 451 LayoutDeviceIntPoint GetTouchCoordinates(WPARAM wParam, LPARAM lParam); 452 mozilla::Maybe<mozilla::PanGestureInput> ConvertTouchToPanGesture( 453 const mozilla::MultiTouchInput& aTouchInput, PTOUCHINPUT aOriginalEvent); 454 void DispatchTouchOrPanGestureInput(mozilla::MultiTouchInput& aTouchInput, 455 PTOUCHINPUT aOSEvent); 456 457 /** 458 * Event handlers 459 */ 460 virtual void OnDestroy() override; 461 bool OnResize(const LayoutDeviceIntSize& aSize); 462 void OnSizeModeChange(nsSizeMode aSizeMode); 463 bool OnGesture(WPARAM wParam, LPARAM lParam); 464 bool OnTouch(WPARAM wParam, LPARAM lParam); 465 bool OnHotKey(WPARAM wParam, LPARAM lParam); 466 bool OnPaint(HDC aDC, uint32_t aNestingLevel); 467 void OnWindowPosChanged(WINDOWPOS* wp); 468 void OnWindowPosChanging(LPWINDOWPOS& info); 469 void OnSysColorChanged(); 470 void OnDPIChanged(int32_t x, int32_t y, int32_t width, int32_t height); 471 bool OnPointerEvents(UINT msg, WPARAM wParam, LPARAM lParam); 472 473 /** 474 * Function that registers when the user has been active (used for detecting 475 * when the user is idle). 476 */ 477 void UserActivity(); 478 479 int32_t GetHeight(int32_t aProposedHeight); 480 const wchar_t* GetWindowClass() const; 481 const wchar_t* GetWindowPopupClass() const; 482 virtual DWORD WindowStyle(); 483 DWORD WindowExStyle(); 484 485 // This method registers the given window class, and returns the class name. 486 const wchar_t* RegisterWindowClass(const wchar_t* aClassName, 487 UINT aExtraStyle, LPWSTR aIconID) const; 488 489 /** 490 * XP and Vista theming support for windows with rounded edges 491 */ 492 void ClearThemeRegion(); 493 void SetThemeRegion(); 494 495 /** 496 * Popup hooks 497 */ 498 static void ScheduleHookTimer(HWND aWnd, UINT aMsgId); 499 static void RegisterSpecialDropdownHooks(); 500 static void UnregisterSpecialDropdownHooks(); 501 static bool GetPopupsToRollup( 502 nsIRollupListener* aRollupListener, uint32_t* aPopupsToRollup, 503 mozilla::Maybe<POINT> aEventPoint = mozilla::Nothing()); 504 static bool NeedsToHandleNCActivateDelayed(HWND aWnd); 505 static bool DealWithPopups(HWND inWnd, UINT inMsg, WPARAM inWParam, 506 LPARAM inLParam, LRESULT* outResult); 507 508 /** 509 * Window transparency helpers 510 */ 511 #ifdef MOZ_XUL 512 private: 513 void SetWindowTranslucencyInner(nsTransparencyMode aMode); GetWindowTranslucencyInner()514 nsTransparencyMode GetWindowTranslucencyInner() const { 515 return mTransparencyMode; 516 } 517 void UpdateGlass(); 518 bool WithinDraggableRegion(int32_t clientX, int32_t clientY); 519 520 bool DispatchTouchEventFromWMPointer(UINT msg, LPARAM aLParam, 521 const WinPointerInfo& aPointerInfo, 522 mozilla::MouseButton aButton); 523 524 void SetSizeModeInternal(nsSizeMode aMode); 525 526 protected: 527 #endif // MOZ_XUL 528 529 static bool IsAsyncResponseEvent(UINT aMsg, LRESULT& aResult); 530 void IPCWindowProcHandler(UINT& msg, WPARAM& wParam, LPARAM& lParam); 531 532 /** 533 * Misc. 534 */ 535 void StopFlashing(); 536 static HWND WindowAtMouse(); 537 static bool IsTopLevelMouseExit(HWND aWnd); 538 virtual nsresult SetWindowClipRegion( 539 const nsTArray<LayoutDeviceIntRect>& aRects, 540 bool aIntersectWithExisting) override; 541 LayoutDeviceIntRegion GetRegionToPaint(bool aForceFullRepaint, PAINTSTRUCT ps, 542 HDC aDC); 543 void ClearCachedResources(); 544 nsIWidgetListener* GetPaintListener(); 545 546 virtual void AddWindowOverlayWebRenderCommands( 547 mozilla::layers::WebRenderBridgeChild* aWrBridge, 548 mozilla::wr::DisplayListBuilder& aBuilder, 549 mozilla::wr::IpcResourceUpdateQueue& aResourceUpdates) override; 550 551 already_AddRefed<SourceSurface> CreateScrollSnapshot() override; 552 553 struct ScrollSnapshot { 554 RefPtr<gfxWindowsSurface> surface; 555 bool surfaceHasSnapshot = false; 556 RECT clip; 557 }; 558 559 ScrollSnapshot* EnsureSnapshotSurface(ScrollSnapshot& aSnapshotData, 560 const mozilla::gfx::IntSize& aSize); 561 562 ScrollSnapshot mFullSnapshot; 563 ScrollSnapshot mPartialSnapshot; 564 ScrollSnapshot* mCurrentSnapshot = nullptr; 565 566 already_AddRefed<SourceSurface> GetFallbackScrollSnapshot( 567 const RECT& aRequiredClip); 568 569 void CreateCompositor() override; 570 void RequestFxrOutput(); 571 572 void RecreateDirectManipulationIfNeeded(); 573 void ResizeDirectManipulationViewport(); 574 void DestroyDirectManipulation(); 575 576 protected: 577 nsCOMPtr<nsIWidget> mParent; 578 nsIntSize mLastSize; 579 nsIntPoint mLastPoint; 580 HWND mWnd; 581 HWND mTransitionWnd; 582 WNDPROC mPrevWndProc; 583 HBRUSH mBrush; 584 IMEContext mDefaultIMC; 585 HDEVNOTIFY mDeviceNotifyHandle; 586 bool mIsTopWidgetWindow; 587 bool mInDtor; 588 bool mIsVisible; 589 bool mPainting; 590 bool mTouchWindow; 591 bool mDisplayPanFeedback; 592 bool mHideChrome; 593 bool mIsRTL; 594 bool mFullscreenMode; 595 bool mMousePresent; 596 bool mMouseInDraggableArea; 597 bool mDestroyCalled; 598 bool mOpeningAnimationSuppressed; 599 bool mAlwaysOnTop; 600 bool mIsEarlyBlankWindow; 601 bool mIsShowingPreXULSkeletonUI; 602 bool mResizable; 603 DWORD_PTR mOldStyle; 604 DWORD_PTR mOldExStyle; 605 nsNativeDragTarget* mNativeDragTarget; 606 HKL mLastKeyboardLayout; 607 nsSizeMode mOldSizeMode; 608 nsSizeMode mLastSizeMode; 609 WindowHook mWindowHook; 610 uint32_t mPickerDisplayCount; 611 HICON mIconSmall; 612 HICON mIconBig; 613 HWND mLastKillFocusWindow; 614 static bool sDropShadowEnabled; 615 static uint32_t sInstanceCount; 616 static TriStateBool sCanQuit; 617 static nsWindow* sCurrentWindow; 618 static BOOL sIsOleInitialized; 619 static HCURSOR sCustomHCursor; 620 static Cursor sCurrentCursor; 621 static bool sSwitchKeyboardLayout; 622 static bool sJustGotDeactivate; 623 static bool sJustGotActivate; 624 static bool sIsInMouseCapture; 625 static bool sHaveInitializedPrefs; 626 static bool sIsRestoringSession; 627 static bool sFirstTopLevelWindowCreated; 628 629 PlatformCompositorWidgetDelegate* mCompositorWidgetDelegate; 630 631 // Always use the helper method to read this property. See bug 603793. 632 static TriStateBool sHasBogusPopupsDropShadowOnMultiMonitor; 633 static bool HasBogusPopupsDropShadowOnMultiMonitor(); 634 635 // Non-client margin settings 636 // Pre-calculated outward offset applied to default frames 637 LayoutDeviceIntMargin mNonClientOffset; 638 // Margins set by the owner 639 LayoutDeviceIntMargin mNonClientMargins; 640 // Margins we'd like to set once chrome is reshown: 641 LayoutDeviceIntMargin mFutureMarginsOnceChromeShows; 642 // Indicates we need to apply margins once toggling chrome into showing: 643 bool mFutureMarginsToUse; 644 645 // Indicates custom frames are enabled 646 bool mCustomNonClient; 647 // Cached copy of L&F's resize border 648 int32_t mHorResizeMargin; 649 int32_t mVertResizeMargin; 650 // Height of the caption plus border 651 int32_t mCaptionHeight; 652 653 double mDefaultScale; 654 655 float mAspectRatio; 656 657 nsCOMPtr<nsIUserIdleServiceInternal> mIdleService; 658 659 // Draggable titlebar region maintained by UpdateWindowDraggingRegion 660 LayoutDeviceIntRegion mDraggableRegion; 661 662 // Hook Data Memebers for Dropdowns. sProcessHook Tells the 663 // hook methods whether they should be processing the hook 664 // messages. 665 static HHOOK sMsgFilterHook; 666 static HHOOK sCallProcHook; 667 static HHOOK sCallMouseHook; 668 static bool sProcessHook; 669 static UINT sRollupMsgId; 670 static HWND sRollupMsgWnd; 671 static UINT sHookTimerId; 672 673 // Mouse Clicks - static variable definitions for figuring 674 // out 1 - 3 Clicks. 675 static POINT sLastMousePoint; 676 static POINT sLastMouseMovePoint; 677 static LONG sLastMouseDownTime; 678 static LONG sLastClickCount; 679 static BYTE sLastMouseButton; 680 681 // Graphics 682 HDC mPaintDC; // only set during painting 683 684 LayoutDeviceIntRect mLastPaintBounds; 685 686 ResizeState mResizeState; 687 688 // Transparency 689 #ifdef MOZ_XUL 690 nsTransparencyMode mTransparencyMode; 691 nsIntRegion mPossiblyTransparentRegion; 692 MARGINS mGlassMargins; 693 #endif // MOZ_XUL 694 695 // Win7 Gesture processing and management 696 nsWinGesture mGesture; 697 698 // Weak ref to the nsITaskbarWindowPreview associated with this window 699 nsWeakPtr mTaskbarPreview; 700 // True if the taskbar (possibly through the tab preview) tells us that the 701 // icon has been created on the taskbar. 702 bool mHasTaskbarIconBeenCreated; 703 704 // Indicates that mouse events should be ignored and pass through to the 705 // window below. This is currently only used for popups. 706 bool mMouseTransparent; 707 708 // Whether we're in the process of sending a WM_SETTEXT ourselves 709 bool mSendingSetText; 710 711 // Whether we we're created as a child window (aka ChildWindow) or not. 712 bool mIsChildWindow : 1; 713 714 int32_t mCachedHitTestResult; 715 716 // The point in time at which the last paint completed. We use this to avoid 717 // painting too rapidly in response to frequent input events. 718 TimeStamp mLastPaintEndTime; 719 720 // The location of the window buttons in the window. 721 mozilla::Maybe<LayoutDeviceIntRect> mWindowButtonsRect; 722 723 // Caching for hit test results 724 POINT mCachedHitTestPoint; 725 TimeStamp mCachedHitTestTime; 726 727 RefPtr<mozilla::widget::InProcessWinCompositorWidget> mBasicLayersSurface; 728 729 static bool sNeedsToInitMouseWheelSettings; 730 static void InitMouseWheelScrollData(); 731 732 double mSizeConstraintsScale; // scale in effect when setting constraints 733 int32_t mMaxTextureSize; 734 735 // Pointer events processing and management 736 WinPointerEvents mPointerEvents; 737 738 ScreenPoint mLastPanGestureFocus; 739 740 // When true, used to indicate an async call to RequestFxrOutput to the GPU 741 // process after the Compositor is created 742 bool mRequestFxrOutputPending; 743 744 mozilla::UniquePtr<mozilla::widget::DirectManipulationOwner> mDmOwner; 745 }; 746 747 #endif // Window_h__ 748