OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef REMOTING_CLIENT_KEY_EVENT_MAPPER_H_ | |
6 #define REMOTING_CLIENT_KEY_EVENT_MAPPER_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <map> | |
11 #include <set> | |
12 | |
13 #include "base/callback.h" | |
14 #include "base/compiler_specific.h" | |
15 #include "base/macros.h" | |
16 #include "remoting/protocol/input_filter.h" | |
17 | |
18 namespace remoting { | |
19 | |
20 // Filtering InputStub which can be used to re-map the USB keycodes of events | |
21 // before they are passed on to the next InputStub in the chain, or to trap | |
22 // events with specific USB keycodes for special handling. | |
23 class KeyEventMapper : public protocol::InputFilter { | |
24 public: | |
25 KeyEventMapper(); | |
26 explicit KeyEventMapper(InputStub* input_stub); | |
27 ~KeyEventMapper() override; | |
28 | |
29 // Callback type for use with SetTrapCallback(), below. | |
30 typedef base::Callback<void(const protocol::KeyEvent&)> KeyTrapCallback; | |
31 | |
32 // Sets the callback to which trapped keys will be delivered. | |
33 void SetTrapCallback(KeyTrapCallback callback); | |
34 | |
35 // Causes events matching |usb_keycode| to be delivered to the trap callback. | |
36 // Trapped events are not dispatched to the next InputStub in the chain. | |
37 void TrapKey(uint32_t usb_keycode, bool trap_key); | |
38 | |
39 // Causes events matching |in_usb_keycode| to be mapped to |out_usb_keycode|. | |
40 // Keys are remapped at most once. Traps are processed before remapping. | |
41 void RemapKey(uint32_t in_usb_keycode, uint32_t out_usb_keycode); | |
42 | |
43 // InputFilter overrides. | |
44 void InjectKeyEvent(const protocol::KeyEvent& event) override; | |
45 | |
46 private: | |
47 std::map<uint32_t, uint32_t> mapped_keys; | |
48 std::set<uint32_t> trapped_keys; | |
49 KeyTrapCallback trap_callback; | |
50 | |
51 DISALLOW_COPY_AND_ASSIGN(KeyEventMapper); | |
52 }; | |
53 | |
54 } // namespace remoting | |
55 | |
56 #endif // REMOTING_CLIENT_KEY_EVENT_MAPPER_H_ | |
OLD | NEW |