2021-03-23 16:40:32 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_widget_NativeMenu_h
|
|
|
|
#define mozilla_widget_NativeMenu_h
|
|
|
|
|
|
|
|
#include "nsISupportsImpl.h"
|
2021-03-23 17:38:29 +03:00
|
|
|
#include "Units.h"
|
2021-03-23 16:40:32 +03:00
|
|
|
|
2023-02-03 01:13:54 +03:00
|
|
|
class nsIFrame;
|
2022-02-28 17:53:24 +03:00
|
|
|
class nsPresContext;
|
|
|
|
|
2021-04-13 05:52:40 +03:00
|
|
|
namespace mozilla {
|
|
|
|
using Modifiers = uint16_t;
|
|
|
|
class ErrorResult;
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2021-03-31 20:41:56 +03:00
|
|
|
namespace mozilla::dom {
|
|
|
|
class Element;
|
|
|
|
}
|
|
|
|
|
2021-03-23 16:40:32 +03:00
|
|
|
namespace mozilla::widget {
|
|
|
|
|
|
|
|
class NativeMenu {
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(NativeMenu)
|
|
|
|
|
2021-03-23 17:38:29 +03:00
|
|
|
// Show this menu as a context menu at the specified position.
|
2021-04-10 04:26:24 +03:00
|
|
|
// This call assumes that the popupshowing event for the root popup has
|
|
|
|
// already been sent and "approved", i.e. preventDefault() was not called.
|
2023-02-03 01:13:54 +03:00
|
|
|
virtual void ShowAsContextMenu(nsIFrame* aClickedFrame,
|
2023-05-18 08:51:19 +03:00
|
|
|
const CSSIntPoint& aPosition,
|
|
|
|
bool aIsContextMenu) = 0;
|
2021-03-23 17:38:29 +03:00
|
|
|
|
2021-03-31 20:41:55 +03:00
|
|
|
// Close the menu and synchronously fire popuphiding / popuphidden events.
|
|
|
|
// Returns false if the menu wasn't open.
|
|
|
|
virtual bool Close() = 0;
|
|
|
|
|
2021-04-13 05:52:40 +03:00
|
|
|
// Activate aItemElement and close this menu.
|
|
|
|
// aItemElement can be nested arbitrarily deeply within submenus inside this
|
|
|
|
// menu. Only works while this menu (and any submenus on the path to the
|
|
|
|
// item) is open, otherwise aRv reports an error.
|
|
|
|
virtual void ActivateItem(dom::Element* aItemElement, Modifiers aModifiers,
|
2021-04-21 06:45:27 +03:00
|
|
|
int16_t aButton, ErrorResult& aRv) = 0;
|
2021-04-13 05:52:40 +03:00
|
|
|
|
2021-04-13 05:52:42 +03:00
|
|
|
// Open, or simulate the opening of, a submenu.
|
|
|
|
// aMenuElement can be nested arbitrarily deeply within submenus inside this
|
|
|
|
// menu. Only works while this menu (and any submenus on the path to the
|
|
|
|
// submenu) is open.
|
|
|
|
virtual void OpenSubmenu(dom::Element* aMenuElement) = 0;
|
|
|
|
|
2021-04-13 05:52:44 +03:00
|
|
|
// Closing, or simulate the closing of, a submenu.
|
|
|
|
// aMenuElement can be nested arbitrarily deeply within submenus inside this
|
|
|
|
// menu. Only works while this menu (and any submenus on the path to the
|
|
|
|
// submenu) is open.
|
|
|
|
virtual void CloseSubmenu(dom::Element* aMenuElement) = 0;
|
|
|
|
|
2021-03-31 20:41:56 +03:00
|
|
|
// Return this NativeMenu's DOM element.
|
|
|
|
virtual RefPtr<dom::Element> Element() = 0;
|
|
|
|
|
2021-03-23 17:38:27 +03:00
|
|
|
class Observer {
|
|
|
|
public:
|
|
|
|
// Called when the menu opened, after popupshown.
|
|
|
|
// No strong reference is held to the observer during the call.
|
|
|
|
virtual void OnNativeMenuOpened() = 0;
|
|
|
|
|
|
|
|
// Called when the menu closed, after popuphidden.
|
|
|
|
// No strong reference is held to the observer during the call.
|
|
|
|
virtual void OnNativeMenuClosed() = 0;
|
2021-04-16 19:18:29 +03:00
|
|
|
|
|
|
|
// Called before the popupshowing event of a submenu fires.
|
|
|
|
virtual void OnNativeSubMenuWillOpen(dom::Element* aPopupElement) = 0;
|
|
|
|
|
|
|
|
// Called after the popupshown event of a submenu fired.
|
|
|
|
virtual void OnNativeSubMenuDidOpen(dom::Element* aPopupElement) = 0;
|
|
|
|
|
|
|
|
// Called after the popuphidden event of a submenu fired.
|
|
|
|
virtual void OnNativeSubMenuClosed(dom::Element* aPopupElement) = 0;
|
2021-05-07 20:00:21 +03:00
|
|
|
|
|
|
|
// Called before the command event of an activated menu item fires.
|
|
|
|
virtual void OnNativeMenuWillActivateItem(
|
|
|
|
dom::Element* aMenuItemElement) = 0;
|
2021-03-23 17:38:27 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Add an observer that gets notified of menu opening and closing.
|
|
|
|
// The menu does not keep a strong reference the observer. The observer must
|
|
|
|
// remove itself before it is destroyed.
|
|
|
|
virtual void AddObserver(Observer* aObserver) = 0;
|
|
|
|
|
|
|
|
// Remove an observer that was previously added with AddObserver.
|
|
|
|
virtual void RemoveObserver(Observer* aObserver) = 0;
|
|
|
|
|
2021-03-23 16:40:32 +03:00
|
|
|
protected:
|
|
|
|
virtual ~NativeMenu() = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla::widget
|
|
|
|
|
|
|
|
#endif // mozilla_widget_NativeMenu_h
|