1 /* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #import <Cocoa/Cocoa.h>
8 #include "nsStandaloneNativeMenu.h"
10 #include "mozilla/dom/Element.h"
11 #include "NativeMenuMac.h"
12 #include "nsISupports.h"
13 #include "nsGkAtoms.h"
15 using namespace mozilla;
17 using mozilla::dom::Element;
19 NS_IMPL_ISUPPORTS(nsStandaloneNativeMenu, nsIStandaloneNativeMenu)
21 nsStandaloneNativeMenu::nsStandaloneNativeMenu() = default;
23 nsStandaloneNativeMenu::~nsStandaloneNativeMenu() = default;
26 nsStandaloneNativeMenu::Init(Element* aElement) {
27 NS_ASSERTION(mMenu == nullptr, "nsNativeMenu::Init - mMenu not null!");
29 NS_ENSURE_ARG(aElement);
31 if (!aElement->IsAnyOfXULElements(nsGkAtoms::menu, nsGkAtoms::menupopup)) {
32 return NS_ERROR_FAILURE;
35 mMenu = new mozilla::widget::NativeMenuMac(aElement);
41 nsStandaloneNativeMenu::MenuWillOpen(bool* aResult) {
42 NS_ASSERTION(mMenu != nullptr,
43 "nsStandaloneNativeMenu::OnOpen - mMenu is null!");
45 mMenu->MenuWillOpen();
52 nsStandaloneNativeMenu::ActivateNativeMenuItemAt(
53 const nsAString& aIndexString) {
55 return NS_ERROR_NOT_INITIALIZED;
58 if (mMenu->ActivateNativeMenuItemAt(aIndexString)) {
62 return NS_ERROR_FAILURE;
66 nsStandaloneNativeMenu::ForceUpdateNativeMenuAt(const nsAString& aIndexString) {
68 return NS_ERROR_NOT_INITIALIZED;
71 mMenu->ForceUpdateNativeMenuAt(aIndexString);
77 nsStandaloneNativeMenu::Dump() {