1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef mozilla_ShortcutKeys_h 6 #define mozilla_ShortcutKeys_h 7 8 #include "nsIObserver.h" 9 10 class nsAtom; 11 12 namespace mozilla { 13 class KeyEventHandler; 14 class WidgetKeyboardEvent; 15 16 typedef struct { 17 const char16_t* event; 18 const char16_t* keycode; 19 const char16_t* key; 20 const char16_t* modifiers; 21 const char16_t* command; 22 } ShortcutKeyData; 23 24 enum class HandlerType { 25 eInput, 26 eTextArea, 27 eBrowser, 28 eEditor, 29 }; 30 31 class ShortcutKeys : public nsIObserver { 32 public: 33 NS_DECL_ISUPPORTS 34 NS_DECL_NSIOBSERVER 35 36 // Returns a pointer to the first handler for the given type. 37 static KeyEventHandler* GetHandlers(HandlerType aType); 38 39 // Gets the event type for a widget keyboard event. 40 static nsAtom* ConvertEventToDOMEventType( 41 const WidgetKeyboardEvent* aWidgetKeyboardEvent); 42 43 protected: 44 ShortcutKeys(); 45 virtual ~ShortcutKeys(); 46 47 // Returns a pointer to the first handler for the given type. 48 KeyEventHandler* EnsureHandlers(HandlerType aType); 49 50 // Maintains a strong reference to the only instance. 51 static StaticRefPtr<ShortcutKeys> sInstance; 52 53 // Shortcut keys for different elements. 54 static ShortcutKeyData sBrowserHandlers[]; 55 static ShortcutKeyData sEditorHandlers[]; 56 static ShortcutKeyData sInputHandlers[]; 57 static ShortcutKeyData sTextAreaHandlers[]; 58 59 // Cached event handlers generated from the above data. 60 KeyEventHandler* mBrowserHandlers; 61 KeyEventHandler* mEditorHandlers; 62 KeyEventHandler* mInputHandlers; 63 KeyEventHandler* mTextAreaHandlers; 64 }; 65 66 } // namespace mozilla 67 68 #endif // #ifndef mozilla_ShortcutKeys_h 69