mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 06:09:19 +00:00
Bug 1691213 - DeCOMtaminate nsINativeMenuService and rename it to mozilla::widget::NativeMenuSupport. r=spohl
Differential Revision: https://phabricator.services.mozilla.com/D104311
This commit is contained in:
parent
e3e650928b
commit
3866ebf163
31
widget/cocoa/NativeMenuSupport.h
Normal file
31
widget/cocoa/NativeMenuSupport.h
Normal file
@ -0,0 +1,31 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_widget_NativeMenuSupport_h
|
||||
#define mozilla_widget_NativeMenuSupport_h
|
||||
|
||||
class nsIWidget;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace dom {
|
||||
class Element;
|
||||
}
|
||||
|
||||
namespace widget {
|
||||
|
||||
class NativeMenuSupport final {
|
||||
public:
|
||||
// Given a top-level window widget and a menu bar DOM node, sets up native
|
||||
// menus. Once created, native menus are controlled via the DOM, including
|
||||
// destruction.
|
||||
static void CreateNativeMenuBar(nsIWidget* aParent,
|
||||
dom::Element* aMenuBarElement);
|
||||
};
|
||||
|
||||
} // namespace widget
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_widget_NativeMenuSupport_h
|
22
widget/cocoa/NativeMenuSupport.mm
Normal file
22
widget/cocoa/NativeMenuSupport.mm
Normal file
@ -0,0 +1,22 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/widget/NativeMenuSupport.h"
|
||||
|
||||
#include "MainThreadUtils.h"
|
||||
#include "nsMenuBarX.h"
|
||||
|
||||
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(aParent, aMenuBarElement);
|
||||
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
|
||||
}
|
||||
|
||||
} // namespace mozilla::widget
|
@ -29,10 +29,15 @@ EXPORTS += [
|
||||
"nsCocoaUtils.h",
|
||||
]
|
||||
|
||||
EXPORTS.mozilla.widget += [
|
||||
"NativeMenuSupport.h",
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
"GfxInfo.mm",
|
||||
"IconLoaderHelperCocoa.mm",
|
||||
"NativeKeyBindings.mm",
|
||||
"NativeMenuSupport.mm",
|
||||
"nsAppShell.mm",
|
||||
"nsBidiKeyboard.mm",
|
||||
"nsCocoaFeatures.mm",
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "nsMenuBaseX.h"
|
||||
#include "nsMenuGroupOwnerX.h"
|
||||
#include "nsChangeObserver.h"
|
||||
#include "nsINativeMenuService.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsMenuBarX;
|
||||
@ -34,19 +33,6 @@ class Element;
|
||||
- (id)initWithApplicationMenu:(nsMenuBarX*)aApplicationMenu;
|
||||
@end
|
||||
|
||||
// The native menu service for creating native menu bars.
|
||||
class nsNativeMenuServiceX : public nsINativeMenuService {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsNativeMenuServiceX() {}
|
||||
|
||||
NS_IMETHOD CreateNativeMenuBar(nsIWidget* aParent, mozilla::dom::Element* aMenuBarNode) override;
|
||||
|
||||
protected:
|
||||
virtual ~nsNativeMenuServiceX() {}
|
||||
};
|
||||
|
||||
// Objective-C class used to allow us to intervene with keyboard event handling.
|
||||
// We allow mouse actions to work normally.
|
||||
@interface GeckoNSMenu : NSMenu {
|
||||
|
@ -47,18 +47,6 @@ static nsIContent* sAboutItemContent = nullptr;
|
||||
static nsIContent* sPrefItemContent = nullptr;
|
||||
static nsIContent* sQuitItemContent = nullptr;
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsNativeMenuServiceX, nsINativeMenuService)
|
||||
|
||||
NS_IMETHODIMP nsNativeMenuServiceX::CreateNativeMenuBar(nsIWidget* aParent,
|
||||
mozilla::dom::Element* aMenuBarElement) {
|
||||
NS_ASSERTION(NS_IsMainThread(), "Attempting to create native menu bar on wrong thread!");
|
||||
|
||||
RefPtr<nsMenuBarX> mb = new nsMenuBarX();
|
||||
if (!mb) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return mb->Create(aParent, aMenuBarElement);
|
||||
}
|
||||
|
||||
//
|
||||
// ApplicationMenuDelegate Objective-C class
|
||||
//
|
||||
|
@ -71,9 +71,6 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsUserIdleServiceX, nsUserIdleServiceX:
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(ScreenManager, ScreenManager::GetAddRefedSingleton)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(OSXNotificationCenter, Init)
|
||||
|
||||
#include "nsMenuBarX.h"
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeMenuServiceX)
|
||||
|
||||
#include "nsMacDockSupport.h"
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMacDockSupport)
|
||||
|
||||
@ -119,7 +116,6 @@ NS_DEFINE_NAMED_CID(NS_PRINTSETTINGSSERVICE_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_PRINTDIALOGSERVICE_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_IDLE_SERVICE_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_SYSTEMALERTSSERVICE_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_NATIVEMENUSERVICE_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_MACDOCKSUPPORT_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_MACFINDERPROGRESS_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_MACSHARINGSERVICE_CID);
|
||||
@ -151,7 +147,6 @@ static const mozilla::Module::CIDEntry kWidgetCIDs[] = {
|
||||
{&kNS_PRINTDIALOGSERVICE_CID, false, NULL, nsPrintDialogServiceXConstructor},
|
||||
{&kNS_IDLE_SERVICE_CID, false, NULL, nsUserIdleServiceXConstructor},
|
||||
{&kNS_SYSTEMALERTSSERVICE_CID, false, NULL, OSXNotificationCenterConstructor},
|
||||
{&kNS_NATIVEMENUSERVICE_CID, false, NULL, nsNativeMenuServiceXConstructor},
|
||||
{&kNS_MACDOCKSUPPORT_CID, false, NULL, nsMacDockSupportConstructor},
|
||||
{&kNS_MACFINDERPROGRESS_CID, false, NULL, nsMacFinderProgressConstructor},
|
||||
{&kNS_MACSHARINGSERVICE_CID, false, NULL, nsMacSharingServiceConstructor},
|
||||
@ -181,7 +176,6 @@ static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
|
||||
{NS_PRINTDIALOGSERVICE_CONTRACTID, &kNS_PRINTDIALOGSERVICE_CID},
|
||||
{"@mozilla.org/widget/useridleservice;1", &kNS_IDLE_SERVICE_CID},
|
||||
{"@mozilla.org/system-alerts-service;1", &kNS_SYSTEMALERTSSERVICE_CID},
|
||||
{"@mozilla.org/widget/nativemenuservice;1", &kNS_NATIVEMENUSERVICE_CID},
|
||||
{"@mozilla.org/widget/macdocksupport;1", &kNS_MACDOCKSUPPORT_CID},
|
||||
{"@mozilla.org/widget/macfinderprogress;1", &kNS_MACFINDERPROGRESS_CID},
|
||||
{"@mozilla.org/widget/macsharingservice;1", &kNS_MACSHARINGSERVICE_CID},
|
||||
|
@ -68,9 +68,6 @@ elif toolkit == "cocoa":
|
||||
"nsITouchBarInput.idl",
|
||||
"nsITouchBarUpdater.idl",
|
||||
]
|
||||
EXPORTS += [
|
||||
"nsINativeMenuService.h",
|
||||
]
|
||||
|
||||
TEST_DIRS += ["tests", "tests/gtest"]
|
||||
|
||||
|
@ -1,39 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef nsINativeMenuService_h_
|
||||
#define nsINativeMenuService_h_
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIWidget;
|
||||
class nsIContent;
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
class Element;
|
||||
}
|
||||
} // namespace mozilla
|
||||
|
||||
// {90DF88F9-F084-4EF3-829A-49496E636DED}
|
||||
#define NS_INATIVEMENUSERVICE_IID \
|
||||
{ \
|
||||
0x90DF88F9, 0xF084, 0x4EF3, { \
|
||||
0x82, 0x9A, 0x49, 0x49, 0x6E, 0x63, 0x6D, 0xED \
|
||||
} \
|
||||
}
|
||||
|
||||
class nsINativeMenuService : public nsISupports {
|
||||
public:
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_INATIVEMENUSERVICE_IID)
|
||||
// Given a top-level window widget and a menu bar DOM node, sets up native
|
||||
// menus. Once created, native menus are controlled via the DOM, including
|
||||
// destruction.
|
||||
NS_IMETHOD CreateNativeMenuBar(nsIWidget* aParent,
|
||||
mozilla::dom::Element* aMenuBarNode) = 0;
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsINativeMenuService, NS_INATIVEMENUSERVICE_IID)
|
||||
|
||||
#endif // nsINativeMenuService_h_
|
@ -80,7 +80,7 @@
|
||||
#include "mozilla/dom/DocumentL10n.h"
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
# include "nsINativeMenuService.h"
|
||||
# include "mozilla/widget/NativeMenuSupport.h"
|
||||
# define USE_NATIVE_MENUS
|
||||
#endif
|
||||
|
||||
@ -2987,11 +2987,6 @@ static void LoadNativeMenus(Document* aDoc, nsIWidget* aParentWindow) {
|
||||
if (gfxPlatform::IsHeadless()) {
|
||||
return;
|
||||
}
|
||||
nsCOMPtr<nsINativeMenuService> nms =
|
||||
do_GetService("@mozilla.org/widget/nativemenuservice;1");
|
||||
if (!nms) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the menubar tag (if there is more than one, we ignore all but
|
||||
// the first).
|
||||
@ -3005,11 +3000,12 @@ static void LoadNativeMenus(Document* aDoc, nsIWidget* aParentWindow) {
|
||||
menubarNode = menubarElements->Item(0);
|
||||
}
|
||||
|
||||
using widget::NativeMenuSupport;
|
||||
if (menubarNode) {
|
||||
nsCOMPtr<Element> menubarContent(do_QueryInterface(menubarNode));
|
||||
nms->CreateNativeMenuBar(aParentWindow, menubarContent);
|
||||
NativeMenuSupport::CreateNativeMenuBar(aParentWindow, menubarContent);
|
||||
} else {
|
||||
nms->CreateNativeMenuBar(aParentWindow, nullptr);
|
||||
NativeMenuSupport::CreateNativeMenuBar(aParentWindow, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user