Bug 1828523 [wpt PR 39579] - Only restore dialog focus if focus is in the dialog...
[gecko.git] / dom / xul / MenuBarListener.h
blob2985a77079b5fe2a3f3c8fe1228c66cdeb20d0f9
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 {
14 class Document;
15 class EventTarget;
16 class KeyboardEvent;
17 class XULMenuBarElement;
18 class XULButtonElement;
20 class MenuBarListener final : public nsIDOMEventListener {
21 public:
22 explicit MenuBarListener(XULMenuBarElement&);
24 NS_DECL_ISUPPORTS
26 NS_DECL_NSIDOMEVENTLISTENER
28 // Should be called when unbound from the document and so on.
29 void Detach();
31 protected:
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);
44 /**
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);
51 /**
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
68 // document.
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