Skip to content

Commit

Permalink
Bug 1883287 - Don't wait for the hidden window to be created on Linux…
Browse files Browse the repository at this point in the history
… to load the native menus. r=smaug

The hidden window is created lazily on Linux, and it's not needed like
on macOS:

  https://searchfox.org/mozilla-central/rev/6b1e306175c2284958fb185bab388021e2890ed0/toolkit/xre/nsAppRunner.cpp#5537-5556

Differential Revision: https://phabricator.services.mozilla.com/D203904
  • Loading branch information
emilio committed Mar 7, 2024
1 parent 7c14126 commit df18f24
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions xpfe/appshell/AppWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3129,7 +3129,16 @@ struct LoadNativeMenusListener {
nsCOMPtr<nsIWidget> mParentWindow;
};

static bool sHiddenWindowLoadedNativeMenus = false;
// On macOS the hidden window is created eagerly, and we want to wait for it to
// load the native menus.
static bool sWaitingForHiddenWindowToLoadNativeMenus =
# ifdef XP_MACOSX
true
# else
false
# endif
;

static nsTArray<LoadNativeMenusListener> sLoadNativeMenusListeners;

static void BeginLoadNativeMenus(Document* aDoc, nsIWidget* aParentWindow);
Expand All @@ -3150,8 +3159,8 @@ static void LoadNativeMenus(Document* aDoc, nsIWidget* aParentWindow) {

widget::NativeMenuSupport::CreateNativeMenuBar(aParentWindow, menubar);

if (!sHiddenWindowLoadedNativeMenus) {
sHiddenWindowLoadedNativeMenus = true;
if (sWaitingForHiddenWindowToLoadNativeMenus) {
sWaitingForHiddenWindowToLoadNativeMenus = false;
for (auto& listener : sLoadNativeMenusListeners) {
BeginLoadNativeMenus(listener.mDocument, listener.mParentWindow);
}
Expand Down Expand Up @@ -3305,16 +3314,11 @@ AppWindow::OnStateChange(nsIWebProgress* aProgress, nsIRequest* aRequest,
// commands
///////////////////////////////
if (!gfxPlatform::IsHeadless()) {
nsCOMPtr<nsIDocumentViewer> viewer;
mDocShell->GetDocViewer(getter_AddRefs(viewer));
if (viewer) {
RefPtr<Document> menubarDoc = viewer->GetDocument();
if (menubarDoc) {
if (mIsHiddenWindow || sHiddenWindowLoadedNativeMenus) {
BeginLoadNativeMenus(menubarDoc, mWindow);
} else {
sLoadNativeMenusListeners.EmplaceBack(menubarDoc, mWindow);
}
if (RefPtr<Document> menubarDoc = mDocShell->GetExtantDocument()) {
if (mIsHiddenWindow || !sWaitingForHiddenWindowToLoadNativeMenus) {
BeginLoadNativeMenus(menubarDoc, mWindow);
} else {
sLoadNativeMenusListeners.EmplaceBack(menubarDoc, mWindow);
}
}
}
Expand Down

0 comments on commit df18f24

Please sign in to comment.