1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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/. */
5
6#include "mozilla/widget/NativeMenuSupport.h"
7
8#include "MainThreadUtils.h"
9#include "mozilla/StaticPrefs_browser.h"
10#include "mozilla/StaticPrefs_widget.h"
11#include "NativeMenuMac.h"
12#include "nsCocoaWindow.h"
13#include "nsMenuBarX.h"
14
15namespace mozilla::widget {
16
17void NativeMenuSupport::CreateNativeMenuBar(nsIWidget* aParent, dom::Element* aMenuBarElement) {
18  MOZ_RELEASE_ASSERT(NS_IsMainThread(), "Attempting to create native menu bar on wrong thread!");
19
20  // Create the menubar and give it to the parent window. The parent takes ownership.
21  static_cast<nsCocoaWindow*>(aParent)->SetMenuBar(MakeRefPtr<nsMenuBarX>(aMenuBarElement));
22}
23
24already_AddRefed<NativeMenu> NativeMenuSupport::CreateNativeContextMenu(dom::Element* aPopup) {
25  return MakeAndAddRef<NativeMenuMac>(aPopup);
26}
27
28bool NativeMenuSupport::ShouldUseNativeContextMenus() {
29  return StaticPrefs::widget_macos_native_context_menus() && StaticPrefs::browser_proton_enabled();
30}
31
32}  // namespace mozilla::widget
33