Source code

Revision control

Other Tools

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