Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: remoting/client/key_event_mapper.cc

Issue 2900203002: Moving input filter files and keymap to input directory. (Closed)
Patch Set: Fix include for input. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/client/key_event_mapper.h ('k') | remoting/client/key_event_mapper_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "remoting/client/key_event_mapper.h"
6
7 #include "remoting/proto/event.pb.h"
8
9 namespace remoting {
10
11 KeyEventMapper::KeyEventMapper() {
12 }
13
14 KeyEventMapper::KeyEventMapper(InputStub* stub) : protocol::InputFilter(stub) {
15 }
16
17 KeyEventMapper::~KeyEventMapper() {
18 }
19
20 void KeyEventMapper::SetTrapCallback(KeyTrapCallback callback) {
21 trap_callback = callback;
22 }
23
24 void KeyEventMapper::TrapKey(uint32_t usb_keycode, bool trap_key) {
25 if (trap_key) {
26 trapped_keys.insert(usb_keycode);
27 } else {
28 trapped_keys.erase(usb_keycode);
29 }
30 }
31
32 void KeyEventMapper::RemapKey(uint32_t in_usb_keycode,
33 uint32_t out_usb_keycode) {
34 if (in_usb_keycode == out_usb_keycode) {
35 mapped_keys.erase(in_usb_keycode);
36 } else {
37 mapped_keys[in_usb_keycode] = out_usb_keycode;
38 }
39 }
40
41 void KeyEventMapper::InjectKeyEvent(const protocol::KeyEvent& event) {
42 if (event.has_usb_keycode()) {
43 // Deliver trapped keys to the callback, not the next stub.
44 if (!trap_callback.is_null() && event.has_pressed() &&
45 (trapped_keys.find(event.usb_keycode()) != trapped_keys.end())) {
46 trap_callback.Run(event);
47 return;
48 }
49
50 // Re-map mapped keys to the new value before passing them on.
51 std::map<uint32_t, uint32_t>::iterator mapped =
52 mapped_keys.find(event.usb_keycode());
53 if (mapped != mapped_keys.end()) {
54 protocol::KeyEvent new_event(event);
55 new_event.set_usb_keycode(mapped->second);
56 InputFilter::InjectKeyEvent(new_event);
57 return;
58 }
59 }
60
61 InputFilter::InjectKeyEvent(event);
62 }
63
64 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/key_event_mapper.h ('k') | remoting/client/key_event_mapper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698