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/. */
6 #ifndef mozilla_widget_NativeMenu_h
7 #define mozilla_widget_NativeMenu_h
9 #include "nsISupportsImpl.h"
15 using Modifiers
= uint16_t;
17 } // namespace mozilla
19 namespace mozilla::dom
{
23 namespace mozilla::widget
{
27 NS_INLINE_DECL_REFCOUNTING(NativeMenu
)
29 // Show this menu as a context menu at the specified position.
30 // This call assumes that the popupshowing event for the root popup has
31 // already been sent and "approved", i.e. preventDefault() was not called.
32 virtual void ShowAsContextMenu(nsPresContext
* aPc
,
33 const CSSIntPoint
& aPosition
) = 0;
35 // Close the menu and synchronously fire popuphiding / popuphidden events.
36 // Returns false if the menu wasn't open.
37 virtual bool Close() = 0;
39 // Activate aItemElement and close this menu.
40 // aItemElement can be nested arbitrarily deeply within submenus inside this
41 // menu. Only works while this menu (and any submenus on the path to the
42 // item) is open, otherwise aRv reports an error.
43 virtual void ActivateItem(dom::Element
* aItemElement
, Modifiers aModifiers
,
44 int16_t aButton
, ErrorResult
& aRv
) = 0;
46 // Open, or simulate the opening of, a submenu.
47 // aMenuElement can be nested arbitrarily deeply within submenus inside this
48 // menu. Only works while this menu (and any submenus on the path to the
50 virtual void OpenSubmenu(dom::Element
* aMenuElement
) = 0;
52 // Closing, or simulate the closing of, a submenu.
53 // aMenuElement can be nested arbitrarily deeply within submenus inside this
54 // menu. Only works while this menu (and any submenus on the path to the
56 virtual void CloseSubmenu(dom::Element
* aMenuElement
) = 0;
58 // Return this NativeMenu's DOM element.
59 virtual RefPtr
<dom::Element
> Element() = 0;
63 // Called when the menu opened, after popupshown.
64 // No strong reference is held to the observer during the call.
65 virtual void OnNativeMenuOpened() = 0;
67 // Called when the menu closed, after popuphidden.
68 // No strong reference is held to the observer during the call.
69 virtual void OnNativeMenuClosed() = 0;
71 // Called before the popupshowing event of a submenu fires.
72 virtual void OnNativeSubMenuWillOpen(dom::Element
* aPopupElement
) = 0;
74 // Called after the popupshown event of a submenu fired.
75 virtual void OnNativeSubMenuDidOpen(dom::Element
* aPopupElement
) = 0;
77 // Called after the popuphidden event of a submenu fired.
78 virtual void OnNativeSubMenuClosed(dom::Element
* aPopupElement
) = 0;
80 // Called before the command event of an activated menu item fires.
81 virtual void OnNativeMenuWillActivateItem(
82 dom::Element
* aMenuItemElement
) = 0;
85 // Add an observer that gets notified of menu opening and closing.
86 // The menu does not keep a strong reference the observer. The observer must
87 // remove itself before it is destroyed.
88 virtual void AddObserver(Observer
* aObserver
) = 0;
90 // Remove an observer that was previously added with AddObserver.
91 virtual void RemoveObserver(Observer
* aObserver
) = 0;
94 virtual ~NativeMenu() = default;
97 } // namespace mozilla::widget
99 #endif // mozilla_widget_NativeMenu_h