Bug 1694853 - Stop giving the nsMenuBarX a reference to the widget. r=harry

Differential Revision: https://phabricator.services.mozilla.com/D106379
This commit is contained in:
Markus Stange 2021-03-04 01:24:58 +00:00
Родитель 8ce2592621
Коммит 4c77fa1cb4
5 изменённых файлов: 12 добавлений и 24 удалений

Просмотреть файл

@ -6,6 +6,7 @@
#include "mozilla/widget/NativeMenuSupport.h"
#include "MainThreadUtils.h"
#include "nsCocoaWindow.h"
#include "nsMenuBarX.h"
namespace mozilla::widget {
@ -15,8 +16,11 @@ void NativeMenuSupport::CreateNativeMenuBar(nsIWidget* aParent, dom::Element* aM
RefPtr<nsMenuBarX> mb = new nsMenuBarX();
nsresult rv = mb->Create(aParent, aMenuBarElement);
nsresult rv = mb->Create(aMenuBarElement);
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
// Give the menubar to the parent window. The parent takes ownership.
static_cast<nsCocoaWindow*>(aParent)->SetMenuBar(std::move(mb));
}
} // namespace mozilla::widget

Просмотреть файл

@ -327,7 +327,7 @@ class nsCocoaWindow final : public nsBaseWidget, public nsPIWidgetCocoa {
bool HasModalDescendents() { return mNumModalDescendents > 0; }
NSWindow* GetCocoaWindow() { return mWindow; }
void SetMenuBar(nsMenuBarX* aMenuBar);
void SetMenuBar(RefPtr<nsMenuBarX>&& aMenuBar);
nsMenuBarX* GetMenuBar();
virtual void SetInputContext(const InputContext& aContext,

Просмотреть файл

@ -2130,13 +2130,12 @@ void nsCocoaWindow::ResumeCompositor() {
Unused << bc->SetExplicitActive(ExplicitActiveStatus::Active);
}
void nsCocoaWindow::SetMenuBar(nsMenuBarX* aMenuBar) {
if (mMenuBar) mMenuBar->SetParent(nullptr);
void nsCocoaWindow::SetMenuBar(RefPtr<nsMenuBarX>&& aMenuBar) {
if (!mWindow) {
mMenuBar = nullptr;
return;
}
mMenuBar = aMenuBar;
mMenuBar = std::move(aMenuBar);
// Only paint for active windows, or paint the hidden window menu bar if no
// other menu bar has been painted yet so that some reasonable menu bar is

Просмотреть файл

@ -97,8 +97,7 @@ class nsMenuBarX : public nsMenuGroupOwnerX, public nsChangeObserver {
nsMenuObjectTypeX MenuObjectType() override { return eMenuBarObjectType; }
// nsMenuBarX
nsresult Create(nsIWidget* aParent, mozilla::dom::Element* aElement);
void SetParent(nsIWidget* aParent);
nsresult Create(mozilla::dom::Element* aElement);
uint32_t GetMenuCount();
bool MenuContainsAppMenu();
nsMenuX* GetMenuAt(uint32_t aIndex);
@ -124,7 +123,6 @@ class nsMenuBarX : public nsMenuGroupOwnerX, public nsChangeObserver {
void CreateApplicationMenu(nsMenuX* aMenu);
nsTArray<mozilla::UniquePtr<nsMenuX>> mMenuArray;
nsIWidget* mParentWindow; // [weak]
GeckoNSMenu* mNativeMenu; // root menu, representing entire menu bar
bool mNeedsRebuild;
ApplicationMenuDelegate* mApplicationMenuDelegate;

Просмотреть файл

@ -11,7 +11,6 @@
#include "nsMenuItemX.h"
#include "nsMenuUtilsX.h"
#include "nsCocoaUtils.h"
#include "nsCocoaWindow.h"
#include "nsChildView.h"
#include "nsCOMPtr.h"
@ -32,6 +31,7 @@
#include "mozilla/dom/Element.h"
using namespace mozilla;
using mozilla::dom::Element;
NativeMenuItemTarget* nsMenuBarX::sNativeEventTarget = nil;
nsMenuBarX* nsMenuBarX::sLastGeckoMenuBarPainted = nullptr;
@ -73,10 +73,7 @@ static nsIContent* sQuitItemContent = nullptr;
@end
nsMenuBarX::nsMenuBarX()
: nsMenuGroupOwnerX(),
mParentWindow(nullptr),
mNeedsRebuild(false),
mApplicationMenuDelegate(nil) {
: nsMenuGroupOwnerX(), mNeedsRebuild(false), mApplicationMenuDelegate(nil) {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
mNativeMenu = [[GeckoNSMenu alloc] initWithTitle:@"MainMenuBar"];
@ -123,14 +120,9 @@ nsMenuBarX::~nsMenuBarX() {
NS_OBJC_END_TRY_ABORT_BLOCK;
}
nsresult nsMenuBarX::Create(nsIWidget* aParent, Element* aContent) {
nsresult nsMenuBarX::Create(Element* aContent) {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
if (!aParent) {
return NS_ERROR_INVALID_ARG;
}
mParentWindow = aParent;
mContent = aContent;
if (mContent) {
@ -147,9 +139,6 @@ nsresult nsMenuBarX::Create(nsIWidget* aParent, Element* aContent) {
ConstructFallbackNativeMenus();
}
// Give this to the parent window. The parent takes ownership.
static_cast<nsCocoaWindow*>(mParentWindow)->SetMenuBar(this);
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK;
@ -792,8 +781,6 @@ void nsMenuBarX::CreateApplicationMenu(nsMenuX* aMenu) {
NS_OBJC_END_TRY_ABORT_BLOCK;
}
void nsMenuBarX::SetParent(nsIWidget* aParent) { mParentWindow = aParent; }
//
// Objective-C class used to allow us to have keyboard commands
// look like they are doing something but actually do nothing.