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

Unified Diff: remoting/client/input/simple_keyboard_input_strategy.cc

Issue 2868383003: [CRD iOS] Send key events to the session. (Closed)
Patch Set: Adding backspace support to the keyboard. 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 side-by-side diff with in-line comments
Download patch
Index: remoting/client/input/simple_keyboard_input_strategy.cc
diff --git a/remoting/client/input/simple_keyboard_input_strategy.cc b/remoting/client/input/simple_keyboard_input_strategy.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0da6eaff07c027accd8722c0469f1f7f558a73fe
--- /dev/null
+++ b/remoting/client/input/simple_keyboard_input_strategy.cc
@@ -0,0 +1,97 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/client/input/simple_keyboard_input_strategy.h"
+
+#include "remoting/client/native_device_keymap.h"
+#include "ui/events/keycodes/dom/dom_code.h"
+
+namespace remoting {
+
+SimpleKeyboardInputStrategy::SimpleKeyboardInputStrategy(
+ ChromotingSession* input_stub)
+ : input_stub_(input_stub) {}
+
+SimpleKeyboardInputStrategy::~SimpleKeyboardInputStrategy() {}
+
+// KeyboardInputStrategy
+
+void SimpleKeyboardInputStrategy::HandleTextEvent(const std::string& text,
+ uint8_t modifiers) {
+ std::queue<KeyEvent> keys = ConvertTextEvent(text, modifiers);
+ while (!keys.empty()) {
+ KeyEvent key = keys.front();
+ input_stub_->SendKeyEvent(key.keycode, key.keydown);
+ keys.pop();
+ }
+}
+
+void SimpleKeyboardInputStrategy::HandleDeleteEvent(uint8_t modifiers) {
+ std::queue<KeyEvent> keys = ConvertDeleteEvent(modifiers);
+ while (!keys.empty()) {
+ KeyEvent key = keys.front();
+ 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
+ keys.pop();
+ }
+}
+
+// Private
+
+std::queue<KeyEvent> SimpleKeyboardInputStrategy::ConvertTextEvent(
+ const std::string& text,
+ uint8_t modifiers) {
+ std::queue<KeyEvent> keys;
+ for (size_t i = 0; i < text.size(); i++) {
+ KeycodeWithModifier keycode = AsciiToUsbKeycodeWithModifier(text.at(i));
+ if (keycode.modifier) {
+ // Key modifier press.
+ KeyEvent modifier_down;
+ modifier_down.keycode = keycode.modifier;
+ modifier_down.keydown = true;
+ 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!
+ }
+
+ // Key press.
+ KeyEvent key_down;
+ key_down.keycode = keycode.keycode;
+ key_down.keydown = true;
+ keys.push(key_down);
+
+ // Key release.
+ KeyEvent key_up;
+ key_up.keycode = keycode.keycode;
+ key_up.keydown = false;
+ keys.push(key_up);
+
+ if (keycode.modifier) {
+ // Key modifier release.
+ KeyEvent modifier;
+ modifier.keycode = keycode.modifier;
+ modifier.keydown = false;
+ keys.push(modifier);
+ }
+ }
+ return keys;
+}
+
+std::queue<KeyEvent> SimpleKeyboardInputStrategy::ConvertDeleteEvent(
+ uint8_t modifiers) {
+ std::queue<KeyEvent> keys;
+ // TODO(nicholss): Handle modifers.
+ // Key press.
+ KeyEvent key_down;
+ key_down.keycode = static_cast<uint32_t>(ui::DomCode::BACKSPACE);
+ key_down.keydown = true;
+ keys.push(key_down);
+
+ // Key release.
+ KeyEvent key_up;
+ key_up.keycode = static_cast<uint32_t>(ui::DomCode::BACKSPACE);
+ key_up.keydown = false;
+ keys.push(key_up);
+
+ return keys;
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698