editing/selection/regional-indicators.html timing out on Linux
[chromium-blink-merge.git] / remoting / client / input_handler.cc
blob690ce04bd03e7bac4fa18f08d078ee2a62ffedea
1 // Copyright (c) 2011 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.
5 #include "remoting/client/input_handler.h"
7 #include "remoting/client/chromoting_view.h"
8 #include "remoting/proto/event.pb.h"
9 #include "remoting/protocol/connection_to_host.h"
10 #include "remoting/protocol/input_stub.h"
12 namespace remoting {
14 using protocol::KeyEvent;
15 using protocol::MouseEvent;
17 InputHandler::InputHandler(ClientContext* context,
18 protocol::ConnectionToHost* connection,
19 ChromotingView* view)
20 : context_(context),
21 connection_(connection),
22 view_(view) {
25 InputHandler::~InputHandler() {
28 void InputHandler::SendKeyEvent(bool press, int keycode) {
29 protocol::InputStub* stub = connection_->input_stub();
30 if (stub) {
31 if (press) {
32 pressed_keys_.insert(keycode);
33 } else {
34 pressed_keys_.erase(keycode);
37 KeyEvent* event = new KeyEvent();
38 event->set_keycode(keycode);
39 event->set_pressed(press);
41 stub->InjectKeyEvent(event, new DeleteTask<KeyEvent>(event));
45 void InputHandler::SendMouseMoveEvent(int x, int y) {
46 protocol::InputStub* stub = connection_->input_stub();
47 if (stub) {
48 MouseEvent* event = new MouseEvent();
49 event->set_x(x);
50 event->set_y(y);
52 stub->InjectMouseEvent(event, new DeleteTask<MouseEvent>(event));
56 void InputHandler::SendMouseButtonEvent(bool button_down,
57 MouseEvent::MouseButton button) {
58 protocol::InputStub* stub = connection_->input_stub();
59 if (stub) {
60 MouseEvent* event = new MouseEvent();
61 event->set_button(button);
62 event->set_button_down(button_down);
64 stub->InjectMouseEvent(event, new DeleteTask<MouseEvent>(event));
68 void InputHandler::ReleaseAllKeys() {
69 std::set<int> pressed_keys_copy = pressed_keys_;
70 std::set<int>::iterator i;
71 for (i = pressed_keys_copy.begin(); i != pressed_keys_copy.end(); ++i) {
72 SendKeyEvent(false, *i);
74 pressed_keys_.clear();
77 } // namespace remoting