forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CRD iOS] Send key events to the session.
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
Showing
24 changed files
with
294 additions
and
732 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.