Bug 1876295 - Update symbol scrapping for firefox archlinux packages r=gsvelto
[gecko.git] / widget / NativeMenu.h
blobef1808c7f929767aa3d3582a5bafe2b203dd932b
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"
10 #include "Units.h"
12 class nsIFrame;
13 class nsPresContext;
15 namespace mozilla {
16 using Modifiers = uint16_t;
17 class ErrorResult;
18 } // namespace mozilla
20 namespace mozilla::dom {
21 class Element;
24 namespace mozilla::widget {
26 class NativeMenu {
27 public:
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,
35 bool aIsContextMenu) = 0;
37 // Close the menu and synchronously fire popuphiding / popuphidden events.
38 // Returns false if the menu wasn't open.
39 virtual bool Close() = 0;
41 // Activate aItemElement and close this menu.
42 // aItemElement can be nested arbitrarily deeply within submenus inside this
43 // menu. Only works while this menu (and any submenus on the path to the
44 // item) is open, otherwise aRv reports an error.
45 virtual void ActivateItem(dom::Element* aItemElement, Modifiers aModifiers,
46 int16_t aButton, ErrorResult& aRv) = 0;
48 // Open, or simulate the opening of, a submenu.
49 // aMenuElement can be nested arbitrarily deeply within submenus inside this
50 // menu. Only works while this menu (and any submenus on the path to the
51 // submenu) is open.
52 virtual void OpenSubmenu(dom::Element* aMenuElement) = 0;
54 // Closing, or simulate the closing of, a submenu.
55 // aMenuElement can be nested arbitrarily deeply within submenus inside this
56 // menu. Only works while this menu (and any submenus on the path to the
57 // submenu) is open.
58 virtual void CloseSubmenu(dom::Element* aMenuElement) = 0;
60 // Return this NativeMenu's DOM element.
61 virtual RefPtr<dom::Element> Element() = 0;
63 class Observer {
64 public:
65 // Called when the menu opened, after popupshown.
66 // No strong reference is held to the observer during the call.
67 virtual void OnNativeMenuOpened() = 0;
69 // Called when the menu closed, after popuphidden.
70 // No strong reference is held to the observer during the call.
71 virtual void OnNativeMenuClosed() = 0;
73 // Called before the popupshowing event of a submenu fires.
74 virtual void OnNativeSubMenuWillOpen(dom::Element* aPopupElement) = 0;
76 // Called after the popupshown event of a submenu fired.
77 virtual void OnNativeSubMenuDidOpen(dom::Element* aPopupElement) = 0;
79 // Called after the popuphidden event of a submenu fired.
80 virtual void OnNativeSubMenuClosed(dom::Element* aPopupElement) = 0;
82 // Called before the command event of an activated menu item fires.
83 virtual void OnNativeMenuWillActivateItem(
84 dom::Element* aMenuItemElement) = 0;
87 // Add an observer that gets notified of menu opening and closing.
88 // The menu does not keep a strong reference the observer. The observer must
89 // remove itself before it is destroyed.
90 virtual void AddObserver(Observer* aObserver) = 0;
92 // Remove an observer that was previously added with AddObserver.
93 virtual void RemoveObserver(Observer* aObserver) = 0;
95 protected:
96 virtual ~NativeMenu() = default;
99 } // namespace mozilla::widget
101 #endif // mozilla_widget_NativeMenu_h