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

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

Issue 10025001: Add APIs to the client plugin to re-map and trap key events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 8 years, 8 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 | Annotate | Revision Log
« 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 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 in_usb_keycode, uint32 out_usb_keycode) {
33 if (in_usb_keycode == out_usb_keycode) {
34 mapped_keys.erase(in_usb_keycode);
35 } else {
36 mapped_keys[in_usb_keycode] = out_usb_keycode;
37 }
38 }
39
40 void KeyEventMapper::InjectKeyEvent(const protocol::KeyEvent& event) {
41 if (event.has_usb_keycode()) {
42 // Deliver trapped keys to the callback, not the next stub.
43 if (!trap_callback.is_null() && event.has_pressed() &&
44 (trapped_keys.find(event.usb_keycode()) != trapped_keys.end())) {
45 trap_callback.Run(event.usb_keycode(), event.pressed());
46 return;
47 }
48
49 // Re-map mapped keys to the new value before passing them on.
50 std::map<uint32,uint32>::iterator mapped =
51 mapped_keys.find(event.usb_keycode());
52 if (mapped != mapped_keys.end()) {
53 protocol::KeyEvent new_event(event);
54 new_event.set_usb_keycode(mapped->second);
55 InputFilter::InjectKeyEvent(new_event);
56 return;
57 }
58 }
59
60 InputFilter::InjectKeyEvent(event);
61 }
62
63 } // 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