/work/obj-fuzz/dist/include/mozilla/layers/KeyboardMap.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
7 | | #ifndef mozilla_layers_KeyboardMap_h |
8 | | #define mozilla_layers_KeyboardMap_h |
9 | | |
10 | | #include <stdint.h> // for uint32_t |
11 | | |
12 | | #include "InputData.h" // for KeyboardInput |
13 | | #include "nsIScrollableFrame.h" // for nsIScrollableFrame::ScrollUnit |
14 | | #include "nsTArray.h" // for nsTArray |
15 | | #include "mozilla/Maybe.h" // for mozilla::Maybe |
16 | | #include "KeyboardScrollAction.h" // for KeyboardScrollAction |
17 | | |
18 | | namespace mozilla { |
19 | | |
20 | | struct IgnoreModifierState; |
21 | | |
22 | | namespace layers { |
23 | | |
24 | | class KeyboardMap; |
25 | | |
26 | | /** |
27 | | * This class is an off main-thread <xul:handler> for scrolling commands. |
28 | | */ |
29 | | class KeyboardShortcut final |
30 | | { |
31 | | public: |
32 | | KeyboardShortcut(); |
33 | | |
34 | | /** |
35 | | * Create a keyboard shortcut that when matched can be handled by executing |
36 | | * the specified keyboard action. |
37 | | */ |
38 | | KeyboardShortcut(KeyboardInput::KeyboardEventType aEventType, |
39 | | uint32_t aKeyCode, |
40 | | uint32_t aCharCode, |
41 | | Modifiers aModifiers, |
42 | | Modifiers aModifiersMask, |
43 | | const KeyboardScrollAction& aAction); |
44 | | |
45 | | /** |
46 | | * Create a keyboard shortcut that when matched should be handled by ignoring |
47 | | * the keyboard event and dispatching it to content. |
48 | | */ |
49 | | KeyboardShortcut(KeyboardInput::KeyboardEventType aEventType, |
50 | | uint32_t aKeyCode, |
51 | | uint32_t aCharCode, |
52 | | Modifiers aModifiers, |
53 | | Modifiers aModifiersMask); |
54 | | |
55 | | /** |
56 | | * There are some default actions for keyboard inputs that are hardcoded in |
57 | | * EventStateManager instead of being represented as XBL handlers. This adds |
58 | | * keyboard shortcuts to match these inputs and dispatch them to content. |
59 | | */ |
60 | | static void AppendHardcodedShortcuts(nsTArray<KeyboardShortcut>& aShortcuts); |
61 | | |
62 | | protected: |
63 | | friend mozilla::layers::KeyboardMap; |
64 | | |
65 | | bool Matches(const KeyboardInput& aInput, |
66 | | const IgnoreModifierState& aIgnore, |
67 | | uint32_t aOverrideCharCode = 0) const; |
68 | | |
69 | | private: |
70 | | bool MatchesKey(const KeyboardInput& aInput, |
71 | | uint32_t aOverrideCharCode) const; |
72 | | bool MatchesModifiers(const KeyboardInput& aInput, |
73 | | const IgnoreModifierState& aIgnore) const; |
74 | | |
75 | | public: |
76 | | // The action to perform when this shortcut is matched, |
77 | | // and not flagged to be dispatched to content |
78 | | KeyboardScrollAction mAction; |
79 | | |
80 | | // Only one of mKeyCode or mCharCode may be non-zero |
81 | | // whichever one is non-zero is the one to compare when matching |
82 | | uint32_t mKeyCode; |
83 | | uint32_t mCharCode; |
84 | | |
85 | | // The modifiers that must be active for this shortcut |
86 | | Modifiers mModifiers; |
87 | | // The modifiers to compare when matching this shortcut |
88 | | Modifiers mModifiersMask; |
89 | | |
90 | | // The type of keyboard event to match against |
91 | | KeyboardInput::KeyboardEventType mEventType; |
92 | | |
93 | | // Whether events matched by this must be dispatched to content |
94 | | bool mDispatchToContent; |
95 | | }; |
96 | | |
97 | | /** |
98 | | * A keyboard map is an off main-thread <xul:binding> for scrolling commands. |
99 | | */ |
100 | | class KeyboardMap final |
101 | | { |
102 | | public: |
103 | | KeyboardMap(); |
104 | | explicit KeyboardMap(nsTArray<KeyboardShortcut>&& aShortcuts); |
105 | | |
106 | 0 | const nsTArray<KeyboardShortcut>& Shortcuts() const { return mShortcuts; } |
107 | | |
108 | | /** |
109 | | * Search through the internal list of shortcuts for a match for the input event |
110 | | */ |
111 | | Maybe<KeyboardShortcut> FindMatch(const KeyboardInput& aEvent) const; |
112 | | |
113 | | private: |
114 | | Maybe<KeyboardShortcut> FindMatchInternal(const KeyboardInput& aEvent, |
115 | | const IgnoreModifierState& aIgnore, |
116 | | uint32_t aOverrideCharCode = 0) const; |
117 | | |
118 | | nsTArray<KeyboardShortcut> mShortcuts; |
119 | | }; |
120 | | |
121 | | } // namespace layers |
122 | | } // namespace mozilla |
123 | | |
124 | | #endif // mozilla_layers_KeyboardMap_h |