Chromium Code Reviews| 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 #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); | |
|
Sergey Ulanov
2012/04/07 01:50:14
Add {}
Wez
2012/04/08 00:12:41
Done.
| |
| 27 else | |
| 28 trapped_keys.erase(usb_keycode); | |
| 29 } | |
| 30 | |
| 31 void KeyEventMapper::RemapKey(uint32 in_usb_keycode, uint32 out_usb_keycode) { | |
| 32 if (in_usb_keycode == out_usb_keycode) | |
| 33 mapped_keys.erase(in_usb_keycode); | |
|
Sergey Ulanov
2012/04/07 01:50:14
add {}
Wez
2012/04/08 00:12:41
Done.
| |
| 34 else | |
| 35 mapped_keys[in_usb_keycode] = out_usb_keycode; | |
| 36 } | |
| 37 | |
| 38 void KeyEventMapper::InjectKeyEvent(const protocol::KeyEvent& event) { | |
| 39 if (event.has_usb_keycode()) { | |
| 40 // Deliver trapped keys to the callback, not the next stub. | |
| 41 if (!trap_callback.is_null() && | |
| 42 (trapped_keys.find(event.usb_keycode()) != trapped_keys.end())) { | |
| 43 trap_callback.Run(event.usb_keycode(), event.pressed()); | |
| 44 return; | |
| 45 } | |
| 46 | |
| 47 // Re-map mapped keys to the new value before passing them on. | |
| 48 std::map<uint32,uint32>::iterator mapped = | |
| 49 mapped_keys.find(event.usb_keycode()); | |
| 50 if (mapped != mapped_keys.end()) { | |
| 51 protocol::KeyEvent new_event(event); | |
| 52 new_event.set_usb_keycode(mapped->second); | |
| 53 InputFilter::InjectKeyEvent(new_event); | |
|
Sergey Ulanov
2012/04/07 01:50:14
Do we want to trap remapped keys? Probably not, ju
Wez
2012/04/08 00:12:41
I couldn't think of any situation where that would
| |
| 54 return; | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 InputFilter::InjectKeyEvent(event); | |
| 59 } | |
| 60 | |
| 61 } // namespace remoting | |
| OLD | NEW |