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"
16 using Modifiers
= uint16_t;
18 } // namespace mozilla
20 namespace mozilla::dom
{
24 namespace mozilla::widget
{
28 NS_INLINE_DECL_REFCOUNTING(NativeMenu
)
30 // Show this menu as a context menu at the specified position.
31 // This call assumes that the popupshowing event for the root popup has
32 // already been sent and "approved", i.e. preventDefault() was not called.
33 virtual void ShowAsContextMenu(nsIFrame
* aClickedFrame
,
34 const CSSIntPoint
& aPosition
) = 0;
36 // Close the menu and synchronously fire popuphiding / popuphidden events.
37 // Returns false if the menu wasn't open.
38 virtual bool Close() = 0;
40 // Activate aItemElement and close this menu.
41 // aItemElement can be nested arbitrarily deeply within submenus inside this
42 // menu. Only works while this menu (and any submenus on the path to the
43 // item) is open, otherwise aRv reports an error.
44 virtual void ActivateItem(dom::Element
* aItemElement
, Modifiers aModifiers
,
45 int16_t aButton
, ErrorResult
& aRv
) = 0;
47 // Open, or simulate the opening of, a submenu.
48 // aMenuElement can be nested arbitrarily deeply within submenus inside this
49 // menu. Only works while this menu (and any submenus on the path to the
51 virtual void OpenSubmenu(dom::Element
* aMenuElement
) = 0;
53 // Closing, or simulate the closing of, a submenu.
54 // aMenuElement can be nested arbitrarily deeply within submenus inside this
55 // menu. Only works while this menu (and any submenus on the path to the
57 virtual void CloseSubmenu(dom::Element
* aMenuElement
) = 0;
59 // Return this NativeMenu's DOM element.
60 virtual RefPtr
<dom::Element
> Element() = 0;
64 // Called when the menu opened, after popupshown.
65 // No strong reference is held to the observer during the call.
66 virtual void OnNativeMenuOpened() = 0;
68 // Called when the menu closed, after popuphidden.
69 // No strong reference is held to the observer during the call.
70 virtual void OnNativeMenuClosed() = 0;
72 // Called before the popupshowing event of a submenu fires.
73 virtual void OnNativeSubMenuWillOpen(dom::Element
* aPopupElement
) = 0;
75 // Called after the popupshown event of a submenu fired.
76 virtual void OnNativeSubMenuDidOpen(dom::Element
* aPopupElement
) = 0;
78 // Called after the popuphidden event of a submenu fired.
79 virtual void OnNativeSubMenuClosed(dom::Element
* aPopupElement
) = 0;
81 // Called before the command event of an activated menu item fires.
82 virtual void OnNativeMenuWillActivateItem(
83 dom::Element
* aMenuItemElement
) = 0;
86 // Add an observer that gets notified of menu opening and closing.
87 // The menu does not keep a strong reference the observer. The observer must
88 // remove itself before it is destroyed.
89 virtual void AddObserver(Observer
* aObserver
) = 0;
91 // Remove an observer that was previously added with AddObserver.
92 virtual void RemoveObserver(Observer
* aObserver
) = 0;
95 virtual ~NativeMenu() = default;
98 } // namespace mozilla::widget
100 #endif // mozilla_widget_NativeMenu_h