tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ShortcutKeys.h (1794B)


      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 struct ShortcutKeyData {
     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 };
     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  static void Shutdown();
     44 
     45 protected:
     46  ShortcutKeys();
     47  virtual ~ShortcutKeys();
     48 
     49  // Returns a pointer to the first handler for the given type.
     50  KeyEventHandler* EnsureHandlers(HandlerType aType);
     51 
     52  // Maintains a strong reference to the only instance.
     53  static StaticRefPtr<ShortcutKeys> sInstance;
     54 
     55  // Shortcut keys for different elements.
     56  static ShortcutKeyData sBrowserHandlers[];
     57  static ShortcutKeyData sEditorHandlers[];
     58  static ShortcutKeyData sInputHandlers[];
     59  static ShortcutKeyData sTextAreaHandlers[];
     60 
     61  // Cached event handlers generated from the above data.
     62  KeyEventHandler* mBrowserHandlers;
     63  KeyEventHandler* mEditorHandlers;
     64  KeyEventHandler* mInputHandlers;
     65  KeyEventHandler* mTextAreaHandlers;
     66 };
     67 
     68 }  // namespace mozilla
     69 
     70 #endif  // #ifndef mozilla_ShortcutKeys_h