Bug 1959023 Part 2: Prevent macOS menubar from flickering when quitting Firefox. r=spohl a=RyanVM

This also prevents the momentary appearance of a gray, disabled-looking
menubar when quitting.

Differential Revision: https://phabricator.services.mozilla.com/D255244
This commit is contained in:
Brad Werth
2025-06-30 00:53:24 +00:00
committed by rvandermeulen@mozilla.com
parent a27e723b0b
commit 1142ca05c0
3 changed files with 26 additions and 3 deletions

View File

@@ -621,6 +621,12 @@ nsAppStartup::GetShuttingDown(bool* aResult) {
return NS_OK;
}
NS_IMETHODIMP
nsAppStartup::GetAttemptingQuit(bool* aResult) {
*aResult = mAttemptingQuit;
return NS_OK;
}
NS_IMETHODIMP
nsAppStartup::GetStartingUp(bool* aResult) {
*aResult = mStartingUp;

View File

@@ -202,6 +202,13 @@ interface nsIAppStartup : nsISupports
*/
[infallible] readonly attribute boolean shuttingDown;
/**
* True if the application is attempting to quit (Quit has been called). This
* is an early signal that we are headed to shutdown. It becomes true just
* before we start closing windows.
*/
[infallible] readonly attribute boolean attemptingQuit;
/**
* True if the application is in the process of starting up.
*

View File

@@ -8,12 +8,14 @@
#include "nsArrayUtils.h"
#include "nsCursorManager.h"
#include "nsIAppStartup.h"
#include "nsIDOMWindowUtils.h"
#include "nsILocalFileMac.h"
#include "GLContextCGL.h"
#include "MacThemeGeometryType.h"
#include "NativeMenuSupport.h"
#include "WindowRenderer.h"
#include "mozilla/Components.h"
#include "mozilla/MiscEvents.h"
#include "mozilla/SwipeTracker.h"
#include "mozilla/layers/APZInputBridge.h"
@@ -7109,9 +7111,17 @@ void nsCocoaWindow::CocoaWindowDidResize() {
RefPtr<nsMenuBarX> hiddenWindowMenuBar =
nsMenuUtilsX::GetHiddenWindowMenuBar();
if (hiddenWindowMenuBar) {
// We do an async paint in order to prevent crashes when macOS is actively
// enumerating the menu items in `NSApp.mainMenu`.
hiddenWindowMenuBar->PaintAsyncIfNeeded();
bool isTerminating = false;
nsCOMPtr<nsIAppStartup> appStartup(components::AppStartup::Service());
if (appStartup) {
appStartup->GetAttemptingQuit(&isTerminating);
}
if (!isTerminating) {
// We do an async paint in order to prevent crashes when macOS is actively
// enumerating the menu items in `NSApp.mainMenu`.
hiddenWindowMenuBar->PaintAsyncIfNeeded();
}
}
NSWindow* window = [aNotification object];