Bug 1880582: Use more correct teardown semantics in nsCocoaWindow::Destroy. r=mstange

This patch moves the call to BaseWindow::Destroy() and ::OnDestroy() to
the end of nsCocoaWindow::Destroy(). It adds a death grip on this before
remove this from mParent. This should keep the window in a more stable
state throughout the function scope.

Differential Revision: https://phabricator.services.mozilla.com/D216066
This commit is contained in:
Brad Werth
2024-09-03 16:14:17 +00:00
parent cc585d1c01
commit 2c4a6baa42

View File

@@ -584,21 +584,15 @@ void nsCocoaWindow::Destroy() {
// (Bug 891424)
Show(false);
if (mPopupContentView) mPopupContentView->Destroy();
if (mPopupContentView) {
mPopupContentView->Destroy();
}
if (mFullscreenTransitionAnimation) {
[mFullscreenTransitionAnimation stopAnimation];
ReleaseFullscreenTransitionAnimation();
}
nsBaseWidget::Destroy();
// nsBaseWidget::Destroy() calls GetParent()->RemoveChild(this). But we
// don't implement GetParent(), so we need to do the equivalent here.
if (mParent) {
mParent->RemoveChild(this);
}
nsBaseWidget::OnDestroy();
if (mInFullScreenMode && !mInNativeFullScreenMode) {
// Keep these calls balanced for emulated fullscreen.
nsCocoaUtils::HideOSChromeOnScreen(false);
@@ -612,6 +606,17 @@ void nsCocoaWindow::Destroy() {
CancelAllTransitions();
DestroyNativeWindow();
}
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
nsBaseWidget::OnDestroy();
nsBaseWidget::Destroy();
// nsBaseWidget::Destroy() calls GetParent()->RemoveChild(this). But we
// don't implement GetParent(), so we need to do the equivalent here.
if (mParent) {
mParent->RemoveChild(this);
}
}
void* nsCocoaWindow::GetNativeData(uint32_t aDataType) {