Skip to content

Commit

Permalink
[CRD iOS] Send key events to the session.
Browse files Browse the repository at this point in the history
This CL enables the iOS client to send key events (keyboard interactions) to
the remote host. This is the first pass for milestone 1, with the goal of a rough
session experience and a follow up CL will come at a later date to polish this.

Review-Url: https://codereview.chromium.org/2868383003
Cr-Commit-Position: refs/heads/master@{#473677}
  • Loading branch information
nicholss authored and Commit bot committed May 22, 2017
1 parent 894bec4 commit 1e49b61
Show file tree
Hide file tree
Showing 24 changed files with 294 additions and 732 deletions.
1 change: 1 addition & 0 deletions remoting/client/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ static_library("client") {

deps = [
"//remoting/base",
"//remoting/client/input",
"//remoting/codec:decoder",
"//remoting/protocol",
"//third_party/libyuv",
Expand Down
11 changes: 6 additions & 5 deletions remoting/client/chromoting_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "remoting/client/client_telemetry_logger.h"
#include "remoting/client/client_user_interface.h"
#include "remoting/client/connect_to_host_info.h"
#include "remoting/client/input/client_input_injector.h"
#include "remoting/proto/control.pb.h"
#include "remoting/proto/event.pb.h"
#include "remoting/protocol/clipboard_stub.h"
Expand All @@ -39,7 +40,8 @@ class ChromotingClientRuntime;
// destroyed on the network thread. Except where indicated, all methods are
// called on the network thread.
class ChromotingSession : public ClientUserInterface,
public protocol::ClipboardStub {
public protocol::ClipboardStub,
public ClientInputInjector {
public:
class Delegate {
public:
Expand Down Expand Up @@ -114,10 +116,9 @@ class ChromotingSession : public ClientUserInterface,
bool button_down);
void SendMouseWheelEvent(int delta_x, int delta_y);

// Sends the provided keyboard scan code to the host.
bool SendKeyEvent(int scan_code, int key_code, bool key_down);

void SendTextEvent(const std::string& text);
// ClientInputInjector implementation.
bool SendKeyEvent(int scan_code, int key_code, bool key_down) override;
void SendTextEvent(const std::string& text) override;

// Sends the provided touch event payload to the host.
void SendTouchEvent(const protocol::TouchEvent& touch_event);
Expand Down
20 changes: 20 additions & 0 deletions remoting/client/input/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2014 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.

source_set("input") {
sources = [
"client_input_injector.h",
"keyboard_input_strategy.h",
"keyboard_interpreter.cc",
"keyboard_interpreter.h",
"text_keyboard_input_strategy.cc",
"text_keyboard_input_strategy.h",
]

deps = [
"//remoting/base",
"//third_party/webrtc/base:rtc_base_approved",
"//ui/events:dom_keycode_converter",
]
}
27 changes: 27 additions & 0 deletions remoting/client/input/client_input_injector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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.

#ifndef REMOTING_CLIENT_INPUT_CLIENT_INPUT_INJECTOR_H_
#define REMOTING_CLIENT_INPUT_CLIENT_INPUT_INJECTOR_H_

#include <stdint.h>
#include <string>

namespace remoting {

// This is an interface used by key input strategies to send processed key
// events to the client side input injector.
class ClientInputInjector {
public:
virtual ~ClientInputInjector() {}

// Sends the provided keyboard scan code to the host.
virtual bool SendKeyEvent(int scan_code, int key_code, bool key_down) = 0;

// Send utf8 encoded text to the host.
virtual void SendTextEvent(const std::string& text) = 0;
};

} // namespace remoting
#endif // REMOTING_CLIENT_INPUT_CLIENT_INPUT_INJECTOR_H_
31 changes: 31 additions & 0 deletions remoting/client/input/keyboard_input_strategy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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.

#ifndef REMOTING_CLIENT_INPUT_KEYBOARD_INPUT_STRATEGY_H_
#define REMOTING_CLIENT_INPUT_KEYBOARD_INPUT_STRATEGY_H_

#include <stdint.h>
#include <string>

namespace remoting {

struct KeyEvent {
uint32_t keycode;
bool keydown;
};

// This is an interface used by |KeyboardInterpreter| to customize how keyboard
// input is handled.
class KeyboardInputStrategy {
public:
virtual ~KeyboardInputStrategy() {}

// Handle a text event.
virtual void HandleTextEvent(const std::string& text, uint8_t modifiers) = 0;
// Handle delete event.
virtual void HandleDeleteEvent(uint8_t modifiers) = 0;
};

} // namespace remoting
#endif // REMOTING_CLIENT_INPUT_KEYBOARD_INPUT_STRATEGY_H_
28 changes: 28 additions & 0 deletions remoting/client/input/keyboard_interpreter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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/keyboard_interpreter.h"

#include "base/logging.h"
#include "remoting/client/input/text_keyboard_input_strategy.h"

namespace remoting {

KeyboardInterpreter::KeyboardInterpreter(ClientInputInjector* input_injector) {
// TODO(nicholss): This should be configurable.
input_strategy_.reset(new TextKeyboardInputStrategy(input_injector));
}

KeyboardInterpreter::~KeyboardInterpreter() {}

void KeyboardInterpreter::HandleTextEvent(const std::string& text,
uint8_t modifiers) {
input_strategy_->HandleTextEvent(text, modifiers);
}

void KeyboardInterpreter::HandleDeleteEvent(uint8_t modifiers) {
input_strategy_->HandleDeleteEvent(modifiers);
}

} // namespace remoting
37 changes: 37 additions & 0 deletions remoting/client/input/keyboard_interpreter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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.

#ifndef REMOTING_CLIENT_INPUT_KEYBOARD_INTERPRETER_H_
#define REMOTING_CLIENT_INPUT_KEYBOARD_INTERPRETER_H_

#include <memory>
#include <string>

#include "base/macros.h"

namespace remoting {

class KeyboardInputStrategy;
class ClientInputInjector;

// This is a class for interpreting raw keyboard input, it will delegate
// handling of text events to the selected keyboard input strategy.
class KeyboardInterpreter {
public:
explicit KeyboardInterpreter(ClientInputInjector* input_injector);
~KeyboardInterpreter();

// Delegates to |KeyboardInputStrategy| to covert and send the input.
void HandleTextEvent(const std::string& text, uint8_t modifiers);
// Delegates to |KeyboardInputStrategy| to covert and send the delete.
void HandleDeleteEvent(uint8_t modifiers);

private:
std::unique_ptr<KeyboardInputStrategy> input_strategy_;

DISALLOW_COPY_AND_ASSIGN(KeyboardInterpreter);
};

} // namespace remoting
#endif // REMOTING_CLIENT_INPUT_KEYBOARD_INTERPRETER_H_
49 changes: 49 additions & 0 deletions remoting/client/input/text_keyboard_input_strategy.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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/text_keyboard_input_strategy.h"

#include "remoting/client/input/client_input_injector.h"
#include "remoting/client/native_device_keymap.h"
#include "ui/events/keycodes/dom/dom_code.h"

namespace remoting {

TextKeyboardInputStrategy::TextKeyboardInputStrategy(
ClientInputInjector* input_injector)
: input_injector_(input_injector) {}

TextKeyboardInputStrategy::~TextKeyboardInputStrategy() {}

// KeyboardInputStrategy

void TextKeyboardInputStrategy::HandleTextEvent(const std::string& text,
uint8_t modifiers) {
// TODO(nicholss): Handle modifers.
input_injector_->SendTextEvent(text);
}

void TextKeyboardInputStrategy::HandleDeleteEvent(uint8_t modifiers) {
std::queue<KeyEvent> keys = ConvertDeleteEvent(modifiers);
while (!keys.empty()) {
KeyEvent key = keys.front();
input_injector_->SendKeyEvent(0, key.keycode, key.keydown);
keys.pop();
}
}

std::queue<KeyEvent> TextKeyboardInputStrategy::ConvertDeleteEvent(
uint8_t modifiers) {
std::queue<KeyEvent> keys;
// TODO(nicholss): Handle modifers.
// Key press.
keys.push({static_cast<uint32_t>(ui::DomCode::BACKSPACE), true});

// Key release.
keys.push({static_cast<uint32_t>(ui::DomCode::BACKSPACE), false});

return keys;
}

} // namespace remoting
35 changes: 35 additions & 0 deletions remoting/client/input/text_keyboard_input_strategy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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.

#ifndef REMOTING_CLIENT_INPUT_TEXT_KEYBOARD_INPUT_STRATEGY_H_
#define REMOTING_CLIENT_INPUT_TEXT_KEYBOARD_INPUT_STRATEGY_H_

#include <queue>

#include "base/macros.h"
#include "remoting/client/input/keyboard_input_strategy.h"

namespace remoting {

class ClientInputInjector;

class TextKeyboardInputStrategy : public KeyboardInputStrategy {
public:
explicit TextKeyboardInputStrategy(ClientInputInjector* input_injector);
~TextKeyboardInputStrategy() override;

// KeyboardInputStrategy overrides.
void HandleTextEvent(const std::string& text, uint8_t modifiers) override;
void HandleDeleteEvent(uint8_t modifiers) override;

private:
std::queue<KeyEvent> ConvertDeleteEvent(uint8_t modifiers);

ClientInputInjector* input_injector_;

DISALLOW_COPY_AND_ASSIGN(TextKeyboardInputStrategy);
};

} // namespace remoting
#endif // REMOTING_CLIENT_INPUT_TEXT_KEYBOARD_INPUT_STRATEGY_H_
3 changes: 3 additions & 0 deletions remoting/client/native_device_keymap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

#include "remoting/client/native_device_keymap.h"

#include "base/logging.h"

namespace remoting {

// Default implementation.
uint32_t NativeDeviceKeycodeToUsbKeycode(size_t device_keycode) {
NOTIMPLEMENTED();
return device_keycode;
}

Expand Down
Loading

0 comments on commit 1e49b61

Please sign in to comment.