mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1699792 - Move nsMenuBarX::Create into the constructor. r=harry
Depends on D109174 Differential Revision: https://phabricator.services.mozilla.com/D109175
This commit is contained in:
parent
ed80258ead
commit
27c0002558
@ -14,13 +14,8 @@ namespace mozilla::widget {
|
||||
void NativeMenuSupport::CreateNativeMenuBar(nsIWidget* aParent, dom::Element* aMenuBarElement) {
|
||||
MOZ_RELEASE_ASSERT(NS_IsMainThread(), "Attempting to create native menu bar on wrong thread!");
|
||||
|
||||
RefPtr<nsMenuBarX> mb = new nsMenuBarX();
|
||||
|
||||
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));
|
||||
// Create the menubar and give it to the parent window. The parent takes ownership.
|
||||
static_cast<nsCocoaWindow*>(aParent)->SetMenuBar(MakeRefPtr<nsMenuBarX>(aMenuBarElement));
|
||||
}
|
||||
|
||||
} // namespace mozilla::widget
|
||||
|
@ -81,7 +81,7 @@ class Element;
|
||||
// Do not hold references to this, they can become invalid any time the DOM node can be destroyed.
|
||||
class nsMenuBarX : public nsMenuParentX, public nsChangeObserver, public mozilla::SupportsWeakPtr {
|
||||
public:
|
||||
nsMenuBarX();
|
||||
explicit nsMenuBarX(mozilla::dom::Element* aElement);
|
||||
|
||||
NS_INLINE_DECL_REFCOUNTING(nsMenuBarX)
|
||||
|
||||
@ -101,7 +101,6 @@ class nsMenuBarX : public nsMenuParentX, public nsChangeObserver, public mozilla
|
||||
nsMenuBarX* AsMenuBar() override { return this; }
|
||||
|
||||
// nsMenuBarX
|
||||
nsresult Create(mozilla::dom::Element* aElement);
|
||||
uint32_t GetMenuCount();
|
||||
bool MenuContainsAppMenu();
|
||||
nsMenuX* GetMenuAt(uint32_t aIndex);
|
||||
|
@ -71,12 +71,25 @@ static nsIContent* sQuitItemContent = nullptr;
|
||||
|
||||
@end
|
||||
|
||||
nsMenuBarX::nsMenuBarX() : mNeedsRebuild(false), mApplicationMenuDelegate(nil) {
|
||||
nsMenuBarX::nsMenuBarX(mozilla::dom::Element* aElement)
|
||||
: mNeedsRebuild(false), mApplicationMenuDelegate(nil) {
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
mMenuGroupOwner = new nsMenuGroupOwnerX(this);
|
||||
mNativeMenu = [[GeckoNSMenu alloc] initWithTitle:@"MainMenuBar"];
|
||||
|
||||
mContent = aElement;
|
||||
|
||||
if (mContent) {
|
||||
AquifyMenuBar();
|
||||
|
||||
mMenuGroupOwner->Create(aElement);
|
||||
mMenuGroupOwner->RegisterForContentChanges(mContent, this);
|
||||
ConstructNativeMenus();
|
||||
} else {
|
||||
ConstructFallbackNativeMenus();
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
@ -118,26 +131,6 @@ nsMenuBarX::~nsMenuBarX() {
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
nsresult nsMenuBarX::Create(Element* aContent) {
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
mContent = aContent;
|
||||
|
||||
if (mContent) {
|
||||
AquifyMenuBar();
|
||||
|
||||
mMenuGroupOwner->Create(aContent);
|
||||
mMenuGroupOwner->RegisterForContentChanges(mContent, this);
|
||||
ConstructNativeMenus();
|
||||
} else {
|
||||
ConstructFallbackNativeMenus();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
void nsMenuBarX::ConstructNativeMenus() {
|
||||
for (nsIContent* menuContent = mContent->GetFirstChild(); menuContent;
|
||||
menuContent = menuContent->GetNextSibling()) {
|
||||
|
Loading…
Reference in New Issue
Block a user