OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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/input/simple_keyboard_input_strategy.h" | |
6 | |
7 #include "remoting/client/native_device_keymap.h" | |
8 #include "ui/events/keycodes/dom/dom_code.h" | |
9 | |
10 namespace remoting { | |
11 | |
12 SimpleKeyboardInputStrategy::SimpleKeyboardInputStrategy( | |
13 ChromotingSession* input_stub) | |
14 : input_stub_(input_stub) {} | |
15 | |
16 SimpleKeyboardInputStrategy::~SimpleKeyboardInputStrategy() {} | |
17 | |
18 // KeyboardInputStrategy | |
19 | |
20 void SimpleKeyboardInputStrategy::HandleTextEvent(const std::string& text, | |
21 uint8_t modifiers) { | |
22 std::queue<KeyEvent> keys = ConvertTextEvent(text, modifiers); | |
23 while (!keys.empty()) { | |
24 KeyEvent key = keys.front(); | |
25 input_stub_->SendKeyEvent(key.keycode, key.keydown); | |
26 keys.pop(); | |
27 } | |
28 } | |
29 | |
30 void SimpleKeyboardInputStrategy::HandleDeleteEvent(uint8_t modifiers) { | |
31 std::queue<KeyEvent> keys = ConvertDeleteEvent(modifiers); | |
32 while (!keys.empty()) { | |
33 KeyEvent key = keys.front(); | |
34 input_stub_->SendKeyEvent(0, key.keycode, key.keydown); | |
Yuwei
2017/05/15 19:38:06
In case of the backspace key, could we just call S
| |
35 keys.pop(); | |
36 } | |
37 } | |
38 | |
39 // Private | |
40 | |
41 std::queue<KeyEvent> SimpleKeyboardInputStrategy::ConvertTextEvent( | |
42 const std::string& text, | |
43 uint8_t modifiers) { | |
44 std::queue<KeyEvent> keys; | |
45 for (size_t i = 0; i < text.size(); i++) { | |
46 KeycodeWithModifier keycode = AsciiToUsbKeycodeWithModifier(text.at(i)); | |
47 if (keycode.modifier) { | |
48 // Key modifier press. | |
49 KeyEvent modifier_down; | |
50 modifier_down.keycode = keycode.modifier; | |
51 modifier_down.keydown = true; | |
52 keys.push(modifier_down); | |
Yuwei
2017/05/15 19:38:06
Could you just use list-initialization, i.e. `keys
nicholss
2017/05/15 23:06:11
fancy!
| |
53 } | |
54 | |
55 // Key press. | |
56 KeyEvent key_down; | |
57 key_down.keycode = keycode.keycode; | |
58 key_down.keydown = true; | |
59 keys.push(key_down); | |
60 | |
61 // Key release. | |
62 KeyEvent key_up; | |
63 key_up.keycode = keycode.keycode; | |
64 key_up.keydown = false; | |
65 keys.push(key_up); | |
66 | |
67 if (keycode.modifier) { | |
68 // Key modifier release. | |
69 KeyEvent modifier; | |
70 modifier.keycode = keycode.modifier; | |
71 modifier.keydown = false; | |
72 keys.push(modifier); | |
73 } | |
74 } | |
75 return keys; | |
76 } | |
77 | |
78 std::queue<KeyEvent> SimpleKeyboardInputStrategy::ConvertDeleteEvent( | |
79 uint8_t modifiers) { | |
80 std::queue<KeyEvent> keys; | |
81 // TODO(nicholss): Handle modifers. | |
82 // Key press. | |
83 KeyEvent key_down; | |
84 key_down.keycode = static_cast<uint32_t>(ui::DomCode::BACKSPACE); | |
85 key_down.keydown = true; | |
86 keys.push(key_down); | |
87 | |
88 // Key release. | |
89 KeyEvent key_up; | |
90 key_up.keycode = static_cast<uint32_t>(ui::DomCode::BACKSPACE); | |
91 key_up.keydown = false; | |
92 keys.push(key_up); | |
93 | |
94 return keys; | |
95 } | |
96 | |
97 } // namespace remoting | |
OLD | NEW |