Bug 1879816: Make nsCocoaWindow::Destroy close the window and let destruction happen...
commit914d7dfb6a8381c874cce91782cc0721f24d511b
authorBrad Werth <bwerth@mozilla.com>
Thu, 22 Feb 2024 16:25:53 +0000 (22 16:25 +0000)
committerBrad Werth <bwerth@mozilla.com>
Thu, 22 Feb 2024 16:25:53 +0000 (22 16:25 +0000)
tree80319b26384ceedbb536147e276fb8b154e7e3cc
parentda249afc6479e441609475fc9688af4e8679afdf
Bug 1879816: Make nsCocoaWindow::Destroy close the window and let destruction happen later. r=mstange

This allows mWindow to stay alive as long as there are still references
to the nsCocoaWindow that owns it. This was the original intent before
the landing of Bug 1865372, which instead destroyed mWindow as soon as
possible. The important behavior in Destroy() is that the native window
becomes not visible. There are at least two ways to hide the window:
orderOut, which merely hides the window, and close (used here) which has
some additional semantic meaning and posts NSWindowWillCloseNotification.
That notification is detected by our window state save/restore code, so
closing the window is a trigger to update the window state. It's
appropriate to update this state during Destroy().

The alternative of hiding the window with orderOut also seems to confuse
the window  manager when closing a fullscreen window (which was the
issue addressed  by Bug 1865372). So we use close. In order to make this
work, we have to ensure that all new native windows have the property
releaseWhenClosed set to NO, and that we explicitly release mWindow in
DestroyNativeWindow().

Differential Revision: https://phabricator.services.mozilla.com/D202363
widget/cocoa/nsCocoaWindow.mm