OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/client/input_handler.h" | 5 #include "remoting/client/input_handler.h" |
6 | 6 |
7 #include "remoting/client/chromoting_view.h" | 7 #include "remoting/client/chromoting_view.h" |
8 #include "remoting/proto/event.pb.h" | 8 #include "remoting/proto/event.pb.h" |
9 #include "remoting/protocol/connection_to_host.h" | 9 #include "remoting/protocol/connection_to_host.h" |
10 #include "remoting/protocol/input_stub.h" | 10 #include "remoting/protocol/input_stub.h" |
11 | 11 |
12 namespace remoting { | 12 namespace remoting { |
13 | 13 |
14 using protocol::KeyEvent; | 14 using protocol::KeyEvent; |
15 using protocol::MouseEvent; | 15 using protocol::MouseEvent; |
16 | 16 |
17 InputHandler::InputHandler(ClientContext* context, | 17 InputHandler::InputHandler(ClientContext* context, |
18 protocol::ConnectionToHost* connection, | 18 protocol::ConnectionToHost* connection, |
19 ChromotingView* view) | 19 ChromotingView* view) |
20 : context_(context), | 20 : context_(context), |
21 connection_(connection), | 21 connection_(connection), |
22 view_(view) { | 22 view_(view) { |
23 } | 23 } |
24 | 24 |
| 25 InputHandler::~InputHandler() { |
| 26 } |
| 27 |
25 void InputHandler::SendKeyEvent(bool press, int keycode) { | 28 void InputHandler::SendKeyEvent(bool press, int keycode) { |
26 protocol::InputStub* stub = connection_->input_stub(); | 29 protocol::InputStub* stub = connection_->input_stub(); |
27 if (stub) { | 30 if (stub) { |
| 31 if (press) { |
| 32 pressed_keys_.insert(keycode); |
| 33 } else { |
| 34 pressed_keys_.erase(keycode); |
| 35 } |
| 36 |
28 KeyEvent* event = new KeyEvent(); | 37 KeyEvent* event = new KeyEvent(); |
29 event->set_keycode(keycode); | 38 event->set_keycode(keycode); |
30 event->set_pressed(press); | 39 event->set_pressed(press); |
31 | 40 |
32 stub->InjectKeyEvent(event, new DeleteTask<KeyEvent>(event)); | 41 stub->InjectKeyEvent(event, new DeleteTask<KeyEvent>(event)); |
33 } | 42 } |
34 } | 43 } |
35 | 44 |
36 void InputHandler::SendMouseMoveEvent(int x, int y) { | 45 void InputHandler::SendMouseMoveEvent(int x, int y) { |
37 protocol::InputStub* stub = connection_->input_stub(); | 46 protocol::InputStub* stub = connection_->input_stub(); |
(...skipping 11 matching lines...) Expand all Loading... |
49 protocol::InputStub* stub = connection_->input_stub(); | 58 protocol::InputStub* stub = connection_->input_stub(); |
50 if (stub) { | 59 if (stub) { |
51 MouseEvent* event = new MouseEvent(); | 60 MouseEvent* event = new MouseEvent(); |
52 event->set_button(button); | 61 event->set_button(button); |
53 event->set_button_down(button_down); | 62 event->set_button_down(button_down); |
54 | 63 |
55 stub->InjectMouseEvent(event, new DeleteTask<MouseEvent>(event)); | 64 stub->InjectMouseEvent(event, new DeleteTask<MouseEvent>(event)); |
56 } | 65 } |
57 } | 66 } |
58 | 67 |
| 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); |
| 73 } |
| 74 pressed_keys_.clear(); |
| 75 } |
| 76 |
59 } // namespace remoting | 77 } // namespace remoting |
OLD | NEW |