MenuBarListener.h (2564B)
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 8 9 #include "mozilla/Attributes.h" 10 #include "mozilla/EventForwards.h" 11 #include "nsIDOMEventListener.h" 12 13 namespace mozilla::dom { 14 class Document; 15 class EventTarget; 16 class KeyboardEvent; 17 class XULMenuBarElement; 18 class XULButtonElement; 19 20 class MenuBarListener final : public nsIDOMEventListener { 21 public: 22 explicit MenuBarListener(XULMenuBarElement&); 23 24 NS_DECL_ISUPPORTS 25 26 NS_DECL_NSIDOMEVENTLISTENER 27 28 // Should be called when unbound from the document and so on. 29 void Detach(); 30 31 protected: 32 virtual ~MenuBarListener(); 33 34 bool IsMenuOpen() const; 35 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); 43 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. 48 */ 49 XULButtonElement* GetMenuForKeyEvent(KeyboardEvent& aKeyEvent); 50 51 /** 52 * Call MarkAsReservedByChrome if the user's preferences indicate that 53 * the key should be chrome-only. 54 */ 55 void ReserveKeyIfNeeded(Event* aKeyEvent); 56 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); 60 61 bool Destroyed() const { return !mMenuBar; } 62 63 // The menu bar object. Safe because it keeps us alive. 64 XULMenuBarElement* mMenuBar; 65 // The event target to listen to the events. 66 // 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; 74 }; 75 76 } // namespace mozilla::dom 77 78 #endif // #ifndef mozilla_dom_MenuBarListener_h