Bug 1704628 Part 5: Avoid use of ESC to close context menu in browser_toolbox_textbox...
[gecko.git] / widget / NativeMenu.h
blob7ee0a34c049100a70d893a20cb1efe6905c7c880
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 namespace mozilla {
13 using Modifiers = uint16_t;
14 class ErrorResult;
15 } // namespace mozilla
17 namespace mozilla::dom {
18 class Element;
21 namespace mozilla::widget {
23 class NativeMenu {
24 public:
25 NS_INLINE_DECL_REFCOUNTING(NativeMenu)
27 // Show this menu as a context menu at the specified position.
28 // This call assumes that the popupshowing event for the root popup has
29 // already been sent and "approved", i.e. preventDefault() was not called.
30 virtual void ShowAsContextMenu(const mozilla::DesktopPoint& aPosition) = 0;
32 // Close the menu and synchronously fire popuphiding / popuphidden events.
33 // Returns false if the menu wasn't open.
34 virtual bool Close() = 0;
36 // Activate aItemElement and close this menu.
37 // aItemElement can be nested arbitrarily deeply within submenus inside this
38 // menu. Only works while this menu (and any submenus on the path to the
39 // item) is open, otherwise aRv reports an error.
40 virtual void ActivateItem(dom::Element* aItemElement, Modifiers aModifiers,
41 int16_t aButton, ErrorResult& aRv) = 0;
43 // Open, or simulate the opening of, a submenu.
44 // aMenuElement can be nested arbitrarily deeply within submenus inside this
45 // menu. Only works while this menu (and any submenus on the path to the
46 // submenu) is open.
47 virtual void OpenSubmenu(dom::Element* aMenuElement) = 0;
49 // Closing, or simulate the closing of, a submenu.
50 // aMenuElement can be nested arbitrarily deeply within submenus inside this
51 // menu. Only works while this menu (and any submenus on the path to the
52 // submenu) is open.
53 virtual void CloseSubmenu(dom::Element* aMenuElement) = 0;
55 // Return this NativeMenu's DOM element.
56 virtual RefPtr<dom::Element> Element() = 0;
58 class Observer {
59 public:
60 // Called when the menu opened, after popupshown.
61 // No strong reference is held to the observer during the call.
62 virtual void OnNativeMenuOpened() = 0;
64 // Called when the menu closed, after popuphidden.
65 // No strong reference is held to the observer during the call.
66 virtual void OnNativeMenuClosed() = 0;
68 // Called before the popupshowing event of a submenu fires.
69 virtual void OnNativeSubMenuWillOpen(dom::Element* aPopupElement) = 0;
71 // Called after the popupshown event of a submenu fired.
72 virtual void OnNativeSubMenuDidOpen(dom::Element* aPopupElement) = 0;
74 // Called after the popuphidden event of a submenu fired.
75 virtual void OnNativeSubMenuClosed(dom::Element* aPopupElement) = 0;
78 // Add an observer that gets notified of menu opening and closing.
79 // The menu does not keep a strong reference the observer. The observer must
80 // remove itself before it is destroyed.
81 virtual void AddObserver(Observer* aObserver) = 0;
83 // Remove an observer that was previously added with AddObserver.
84 virtual void RemoveObserver(Observer* aObserver) = 0;
86 protected:
87 virtual ~NativeMenu() = default;
90 } // namespace mozilla::widget
92 #endif // mozilla_widget_NativeMenu_h