no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / widget / cocoa / nsStandaloneNativeMenu.mm
blobd5a70f817e59c07227b468c1a5ee2dbfbf871538
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;
25 NS_IMETHODIMP
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;
33   }
35   mMenu = new mozilla::widget::NativeMenuMac(aElement);
37   return NS_OK;
40 NS_IMETHODIMP
41 nsStandaloneNativeMenu::MenuWillOpen(bool* aResult) {
42   NS_ASSERTION(mMenu != nullptr,
43                "nsStandaloneNativeMenu::OnOpen - mMenu is null!");
45   mMenu->MenuWillOpen();
47   *aResult = true;
48   return NS_OK;
51 NS_IMETHODIMP
52 nsStandaloneNativeMenu::ActivateNativeMenuItemAt(
53     const nsAString& aIndexString) {
54   if (!mMenu) {
55     return NS_ERROR_NOT_INITIALIZED;
56   }
58   if (mMenu->ActivateNativeMenuItemAt(aIndexString)) {
59     return NS_OK;
60   }
62   return NS_ERROR_FAILURE;
65 NS_IMETHODIMP
66 nsStandaloneNativeMenu::ForceUpdateNativeMenuAt(const nsAString& aIndexString) {
67   if (!mMenu) {
68     return NS_ERROR_NOT_INITIALIZED;
69   }
71   mMenu->ForceUpdateNativeMenuAt(aIndexString);
73   return NS_OK;
76 NS_IMETHODIMP
77 nsStandaloneNativeMenu::Dump() {
78   mMenu->Dump();
80   return NS_OK;