1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_MenuBarListener_h
7 #define mozilla_dom_MenuBarListener_h
9 #include "mozilla/Attributes.h"
10 #include "mozilla/EventForwards.h"
11 #include "nsIDOMEventListener.h"
13 namespace mozilla::dom
{
17 class XULMenuBarElement
;
18 class XULButtonElement
;
20 class MenuBarListener final
: public nsIDOMEventListener
{
22 explicit MenuBarListener(XULMenuBarElement
&);
26 NS_DECL_NSIDOMEVENTLISTENER
28 // Should be called when unbound from the document and so on.
32 virtual ~MenuBarListener();
34 bool IsMenuOpen() const;
36 MOZ_CAN_RUN_SCRIPT nsresult
KeyUp(Event
* aMouseEvent
);
37 MOZ_CAN_RUN_SCRIPT nsresult
KeyDown(Event
* aMouseEvent
);
38 MOZ_CAN_RUN_SCRIPT nsresult
KeyPress(Event
* aMouseEvent
);
39 MOZ_CAN_RUN_SCRIPT nsresult
Blur(Event
* aEvent
);
40 MOZ_CAN_RUN_SCRIPT nsresult
OnWindowDeactivated(Event
* aEvent
);
41 MOZ_CAN_RUN_SCRIPT nsresult
MouseDown(Event
* aMouseEvent
);
42 MOZ_CAN_RUN_SCRIPT nsresult
Fullscreen(Event
* aEvent
);
45 * Given a key event for an Alt+shortcut combination,
46 * return the menu, if any, that would be opened. If aPeek
47 * is false, then play a beep and deactivate the menubar on Windows.
49 XULButtonElement
* GetMenuForKeyEvent(KeyboardEvent
& aKeyEvent
);
52 * Call MarkAsReservedByChrome if the user's preferences indicate that
53 * the key should be chrome-only.
55 void ReserveKeyIfNeeded(Event
* aKeyEvent
);
57 // This should only be called by the MenuBarListener during event dispatch.
58 enum class ByKeyboard
: bool { No
, Yes
};
59 MOZ_CAN_RUN_SCRIPT
void ToggleMenuActiveState(ByKeyboard
);
61 bool Destroyed() const { return !mMenuBar
; }
63 // The menu bar object. Safe because it keeps us alive.
64 XULMenuBarElement
* mMenuBar
;
65 // The event target to listen to the events.
67 // Weak reference is safe because we clear the listener on unbind from the
69 Document
* mEventTarget
;
70 // Whether or not the ALT key is currently down.
71 bool mAccessKeyDown
= false;
72 // Whether or not the ALT key down is canceled by other action.
73 bool mAccessKeyDownCanceled
= false;
76 } // namespace mozilla::dom
78 #endif // #ifndef mozilla_dom_MenuBarListener_h