| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "remoting/client/input_handler.h" | |
| 6 | |
| 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" | |
| 11 | |
| 12 namespace remoting { | |
| 13 | |
| 14 using protocol::KeyEvent; | |
| 15 using protocol::MouseEvent; | |
| 16 | |
| 17 InputHandler::InputHandler(ClientContext* context, | |
| 18 protocol::ConnectionToHost* connection, | |
| 19 ChromotingView* view) | |
| 20 : context_(context), | |
| 21 connection_(connection), | |
| 22 view_(view) { | |
| 23 } | |
| 24 | |
| 25 InputHandler::~InputHandler() { | |
| 26 } | |
| 27 | |
| 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); | |
| 35 } | |
| 36 | |
| 37 KeyEvent event; | |
| 38 event.set_keycode(keycode); | |
| 39 event.set_pressed(press); | |
| 40 stub->InjectKeyEvent(event); | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 void InputHandler::SendMouseMoveEvent(int x, int y) { | |
| 45 protocol::InputStub* stub = connection_->input_stub(); | |
| 46 if (stub) { | |
| 47 MouseEvent event; | |
| 48 event.set_x(x); | |
| 49 event.set_y(y); | |
| 50 stub->InjectMouseEvent(event); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 void InputHandler::SendMouseButtonEvent(bool button_down, | |
| 55 MouseEvent::MouseButton button) { | |
| 56 protocol::InputStub* stub = connection_->input_stub(); | |
| 57 if (stub) { | |
| 58 MouseEvent event; | |
| 59 event.set_button(button); | |
| 60 event.set_button_down(button_down); | |
| 61 stub->InjectMouseEvent(event); | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 void InputHandler::SendMouseWheelEvent(int dx, int dy) { | |
| 66 protocol::InputStub* stub = connection_->input_stub(); | |
| 67 if (stub) { | |
| 68 MouseEvent event; | |
| 69 event.set_wheel_offset_x(dx); | |
| 70 event.set_wheel_offset_y(dy); | |
| 71 stub->InjectMouseEvent(event); | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 void InputHandler::ReleaseAllKeys() { | |
| 76 std::set<int> pressed_keys_copy = pressed_keys_; | |
| 77 std::set<int>::iterator i; | |
| 78 for (i = pressed_keys_copy.begin(); i != pressed_keys_copy.end(); ++i) { | |
| 79 SendKeyEvent(false, *i); | |
| 80 } | |
| 81 pressed_keys_.clear(); | |
| 82 } | |
| 83 | |
| 84 } // namespace remoting | |
| OLD | NEW |