зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1694853 - Use UniquePtr in more places. r=harry
Differential Revision: https://phabricator.services.mozilla.com/D106370
This commit is contained in:
Родитель
107415a9dd
Коммит
48c3f3447c
|
@ -115,13 +115,13 @@ class nsMenuBarX : public nsMenuGroupOwnerX, public nsChangeObserver {
|
|||
protected:
|
||||
void ConstructNativeMenus();
|
||||
void ConstructFallbackNativeMenus();
|
||||
nsresult InsertMenuAtIndex(nsMenuX* aMenu, uint32_t aIndex);
|
||||
void InsertMenuAtIndex(mozilla::UniquePtr<nsMenuX>&& aMenu, uint32_t aIndex);
|
||||
void RemoveMenuAtIndex(uint32_t aIndex);
|
||||
void HideItem(mozilla::dom::Document* inDoc, const nsAString& inID, nsIContent** outHiddenNode);
|
||||
void AquifyMenuBar();
|
||||
NSMenuItem* CreateNativeAppMenuItem(nsMenuX* inMenu, const nsAString& nodeID, SEL action, int tag,
|
||||
NativeMenuItemTarget* target);
|
||||
nsresult CreateApplicationMenu(nsMenuX* inMenu);
|
||||
void CreateApplicationMenu(nsMenuX* inMenu);
|
||||
|
||||
nsTArray<mozilla::UniquePtr<nsMenuX>> mMenuArray;
|
||||
nsIWidget* mParentWindow; // [weak]
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include "mozilla/Components.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
NativeMenuItemTarget* nsMenuBarX::sNativeEventTarget = nil;
|
||||
nsMenuBarX* nsMenuBarX::sLastGeckoMenuBarPainted = nullptr;
|
||||
NSMenu* sApplicationMenu = nil;
|
||||
|
@ -156,8 +158,7 @@ void nsMenuBarX::ConstructNativeMenus() {
|
|||
for (nsIContent* menuContent = mContent->GetFirstChild(); menuContent;
|
||||
menuContent = menuContent->GetNextSibling()) {
|
||||
if (menuContent->IsXULElement(nsGkAtoms::menu)) {
|
||||
nsMenuX* newMenu = new nsMenuX(this, this, menuContent->AsElement());
|
||||
InsertMenuAtIndex(newMenu, GetMenuCount());
|
||||
InsertMenuAtIndex(MakeUnique<nsMenuX>(this, this, menuContent->AsElement()), GetMenuCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -223,7 +224,7 @@ bool nsMenuBarX::MenuContainsAppMenu() {
|
|||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
nsresult nsMenuBarX::InsertMenuAtIndex(nsMenuX* aMenu, uint32_t aIndex) {
|
||||
void nsMenuBarX::InsertMenuAtIndex(UniquePtr<nsMenuX>&& aMenu, uint32_t aIndex) {
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
// If we've only yet created a fallback global Application menu (using
|
||||
|
@ -233,9 +234,7 @@ nsresult nsMenuBarX::InsertMenuAtIndex(nsMenuX* aMenu, uint32_t aIndex) {
|
|||
}
|
||||
// If we haven't created a global Application menu yet, do it.
|
||||
if (!sApplicationMenu) {
|
||||
nsresult rv = NS_OK; // avoid warning about rv being unused
|
||||
rv = CreateApplicationMenu(aMenu);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create Application menu");
|
||||
CreateApplicationMenu(aMenu.get());
|
||||
|
||||
// Hook the new Application menu up to the menu bar.
|
||||
NSMenu* mainMenu = [NSApp mainMenu];
|
||||
|
@ -245,20 +244,19 @@ nsresult nsMenuBarX::InsertMenuAtIndex(nsMenuX* aMenu, uint32_t aIndex) {
|
|||
}
|
||||
|
||||
// add menu to array that owns our menus
|
||||
mMenuArray.InsertElementAt(aIndex, aMenu);
|
||||
nsMenuX* menu = aMenu.get();
|
||||
mMenuArray.InsertElementAt(aIndex, std::move(aMenu));
|
||||
|
||||
// hook up submenus
|
||||
nsIContent* menuContent = aMenu->Content();
|
||||
nsIContent* menuContent = menu->Content();
|
||||
if (menuContent->GetChildCount() > 0 && !nsMenuUtilsX::NodeIsHiddenOrCollapsed(menuContent)) {
|
||||
int insertionIndex = nsMenuUtilsX::CalculateNativeInsertionPoint(this, aMenu);
|
||||
int insertionIndex = nsMenuUtilsX::CalculateNativeInsertionPoint(this, menu);
|
||||
if (MenuContainsAppMenu()) {
|
||||
insertionIndex++;
|
||||
}
|
||||
[mNativeMenu insertItem:aMenu->NativeMenuItem() atIndex:insertionIndex];
|
||||
[mNativeMenu insertItem:menu->NativeMenuItem() atIndex:insertionIndex];
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
@ -297,8 +295,7 @@ void nsMenuBarX::ObserveContentRemoved(mozilla::dom::Document* aDocument, nsICon
|
|||
|
||||
void nsMenuBarX::ObserveContentInserted(mozilla::dom::Document* aDocument, nsIContent* aContainer,
|
||||
nsIContent* aChild) {
|
||||
nsMenuX* newMenu = new nsMenuX(this, this, aChild);
|
||||
InsertMenuAtIndex(newMenu, aContainer->ComputeIndexOf(aChild));
|
||||
InsertMenuAtIndex(MakeUnique<nsMenuX>(this, this, aChild), aContainer->ComputeIndexOf(aChild));
|
||||
}
|
||||
|
||||
void nsMenuBarX::ForceUpdateNativeMenuAt(const nsAString& indexString) {
|
||||
|
@ -605,7 +602,7 @@ NSMenuItem* nsMenuBarX::CreateNativeAppMenuItem(nsMenuX* inMenu, const nsAString
|
|||
}
|
||||
|
||||
// build the Application menu shared by all menu bars
|
||||
nsresult nsMenuBarX::CreateApplicationMenu(nsMenuX* inMenu) {
|
||||
void nsMenuBarX::CreateApplicationMenu(nsMenuX* inMenu) {
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
// At this point, the application menu is the application menu from
|
||||
|
@ -792,8 +789,6 @@ nsresult nsMenuBarX::CreateApplicationMenu(nsMenuX* inMenu) {
|
|||
}
|
||||
}
|
||||
|
||||
return (sApplicationMenu) ? NS_OK : NS_ERROR_FAILURE;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,8 +71,8 @@ class nsMenuX final : public nsMenuObjectX, public nsChangeObserver {
|
|||
void GetMenuPopupContent(nsIContent** aResult);
|
||||
bool OnOpen();
|
||||
bool OnClose();
|
||||
nsresult AddMenuItem(nsMenuItemX* aMenuItem);
|
||||
nsMenuX* AddMenu(mozilla::UniquePtr<nsMenuX> aMenu);
|
||||
void AddMenuItem(mozilla::UniquePtr<nsMenuItemX>&& aMenuItem);
|
||||
void AddMenu(mozilla::UniquePtr<nsMenuX>&& aMenu);
|
||||
void LoadMenuItem(nsIContent* inMenuItemContent);
|
||||
void LoadSubMenu(nsIContent* inMenuContent);
|
||||
GeckoNSMenu* CreateMenuWithGeckoString(nsString& menuTitle);
|
||||
|
|
|
@ -187,20 +187,19 @@ nsMenuX::~nsMenuX() {
|
|||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
nsresult nsMenuX::AddMenuItem(nsMenuItemX* aMenuItem) {
|
||||
void nsMenuX::AddMenuItem(UniquePtr<nsMenuItemX>&& aMenuItem) {
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
if (!aMenuItem) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
nsMenuItemX* menuItem = aMenuItem.get();
|
||||
mMenuObjectsArray.AppendElement(std::move(aMenuItem));
|
||||
|
||||
if (nsMenuUtilsX::NodeIsHiddenOrCollapsed(menuItem->Content())) {
|
||||
return;
|
||||
}
|
||||
|
||||
mMenuObjectsArray.AppendElement(aMenuItem);
|
||||
if (nsMenuUtilsX::NodeIsHiddenOrCollapsed(aMenuItem->Content())) {
|
||||
return NS_OK;
|
||||
}
|
||||
++mVisibleItemsCount;
|
||||
|
||||
NSMenuItem* newNativeMenuItem = (NSMenuItem*)aMenuItem->NativeData();
|
||||
NSMenuItem* newNativeMenuItem = (NSMenuItem*)menuItem->NativeData();
|
||||
|
||||
// add the menu item to this menu
|
||||
[mNativeMenu addItem:newNativeMenuItem];
|
||||
|
@ -210,17 +209,17 @@ nsresult nsMenuX::AddMenuItem(nsMenuItemX* aMenuItem) {
|
|||
[newNativeMenuItem setAction:@selector(menuItemHit:)];
|
||||
|
||||
// set its command. we get the unique command id from the menubar
|
||||
[newNativeMenuItem setTag:mMenuGroupOwner->RegisterForCommand(aMenuItem)];
|
||||
[newNativeMenuItem setTag:mMenuGroupOwner->RegisterForCommand(menuItem)];
|
||||
MenuItemInfo* info = [[MenuItemInfo alloc] initWithMenuGroupOwner:mMenuGroupOwner];
|
||||
[newNativeMenuItem setRepresentedObject:info];
|
||||
[info release];
|
||||
|
||||
return NS_OK;
|
||||
menuItem->SetupIcon();
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
nsMenuX* nsMenuX::AddMenu(UniquePtr<nsMenuX> aMenu) {
|
||||
void nsMenuX::AddMenu(UniquePtr<nsMenuX>&& aMenu) {
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
// aMenu transfers ownership to mMenuObjectsArray and becomes nullptr, so
|
||||
|
@ -229,7 +228,7 @@ nsMenuX* nsMenuX::AddMenu(UniquePtr<nsMenuX> aMenu) {
|
|||
mMenuObjectsArray.AppendElement(std::move(aMenu));
|
||||
|
||||
if (nsMenuUtilsX::NodeIsHiddenOrCollapsed(menu->Content())) {
|
||||
return menu;
|
||||
return;
|
||||
}
|
||||
|
||||
++mVisibleItemsCount;
|
||||
|
@ -241,7 +240,7 @@ nsMenuX* nsMenuX::AddMenu(UniquePtr<nsMenuX> aMenu) {
|
|||
[newNativeMenuItem setSubmenu:(NSMenu*)menu->NativeData()];
|
||||
}
|
||||
|
||||
return menu;
|
||||
menu->SetupIcon();
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
@ -486,28 +485,12 @@ void nsMenuX::LoadMenuItem(nsIContent* inMenuItemContent) {
|
|||
}
|
||||
}
|
||||
|
||||
// Create the item.
|
||||
nsMenuItemX* menuItem =
|
||||
new nsMenuItemX(this, menuitemName, itemType, mMenuGroupOwner, inMenuItemContent);
|
||||
AddMenuItem(menuItem);
|
||||
|
||||
// This needs to happen after the nsIMenuItem object is inserted into
|
||||
// our item array in AddMenuItem()
|
||||
menuItem->SetupIcon();
|
||||
AddMenuItem(
|
||||
MakeUnique<nsMenuItemX>(this, menuitemName, itemType, mMenuGroupOwner, inMenuItemContent));
|
||||
}
|
||||
|
||||
void nsMenuX::LoadSubMenu(nsIContent* inMenuContent) {
|
||||
auto menu = MakeUnique<nsMenuX>(this, mMenuGroupOwner, inMenuContent);
|
||||
|
||||
// |menu|'s ownership is transfer to AddMenu but, if it is successfully
|
||||
// added, we can access it via the returned raw pointer.
|
||||
nsMenuX* menu_ptr = AddMenu(std::move(menu));
|
||||
|
||||
// This needs to happen after the nsIMenu object is inserted into
|
||||
// our item array in AddMenu()
|
||||
if (menu_ptr) {
|
||||
menu_ptr->SetupIcon();
|
||||
}
|
||||
AddMenu(MakeUnique<nsMenuX>(this, mMenuGroupOwner, inMenuContent));
|
||||
}
|
||||
|
||||
// This menu is about to open. Returns TRUE if we should keep processing the event,
|
||||
|
|
|
@ -27,7 +27,7 @@ class nsStandaloneNativeMenu : public nsMenuGroupOwnerX,
|
|||
}
|
||||
virtual void IconUpdated() override;
|
||||
|
||||
nsMenuX* GetMenuXObject() { return mMenu; }
|
||||
nsMenuX* GetMenuXObject() { return mMenu.get(); }
|
||||
|
||||
// If this menu is the menu of a system status bar item (NSStatusItem),
|
||||
// let the menu know about the status item so that it can propagate
|
||||
|
@ -37,7 +37,7 @@ class nsStandaloneNativeMenu : public nsMenuGroupOwnerX,
|
|||
protected:
|
||||
virtual ~nsStandaloneNativeMenu();
|
||||
|
||||
nsMenuX* mMenu;
|
||||
mozilla::UniquePtr<nsMenuX> mMenu;
|
||||
NSStatusItem* mContainerStatusBarItem;
|
||||
};
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#include "nsObjCExceptions.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
using mozilla::dom::Element;
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED(nsStandaloneNativeMenu, nsMenuGroupOwnerX, nsIMutationObserver,
|
||||
|
@ -19,11 +21,7 @@ NS_IMPL_ISUPPORTS_INHERITED(nsStandaloneNativeMenu, nsMenuGroupOwnerX, nsIMutati
|
|||
|
||||
nsStandaloneNativeMenu::nsStandaloneNativeMenu() : mMenu(nullptr), mContainerStatusBarItem(nil) {}
|
||||
|
||||
nsStandaloneNativeMenu::~nsStandaloneNativeMenu() {
|
||||
if (mMenu) {
|
||||
delete mMenu;
|
||||
}
|
||||
}
|
||||
nsStandaloneNativeMenu::~nsStandaloneNativeMenu() {}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsStandaloneNativeMenu::Init(Element* aElement) {
|
||||
|
@ -40,7 +38,7 @@ nsStandaloneNativeMenu::Init(Element* aElement) {
|
|||
return rv;
|
||||
}
|
||||
|
||||
mMenu = new nsMenuX(this, this, aElement);
|
||||
mMenu = MakeUnique<nsMenuX>(this, this, aElement);
|
||||
mMenu->SetupIcon();
|
||||
|
||||
return NS_OK;
|
||||
|
@ -65,7 +63,7 @@ nsStandaloneNativeMenu::MenuWillOpen(bool* aResult) {
|
|||
|
||||
// Force an update on the mMenu by faking an open/close on all of
|
||||
// its submenus.
|
||||
UpdateMenu(mMenu);
|
||||
UpdateMenu(mMenu.get());
|
||||
|
||||
*aResult = true;
|
||||
return NS_OK;
|
||||
|
@ -134,7 +132,7 @@ nsStandaloneNativeMenu::ForceUpdateNativeMenuAt(const nsAString& indexString) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsMenuX* currentMenu = mMenu;
|
||||
nsMenuX* currentMenu = mMenu.get();
|
||||
|
||||
// now find the correct submenu
|
||||
for (unsigned int i = 1; currentMenu && i < indexCount; i++) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче