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"
14 using protocol::KeyEvent
;
15 using protocol::MouseEvent
;
17 InputHandler::InputHandler(ClientContext
* context
,
18 protocol::ConnectionToHost
* connection
,
21 connection_(connection
),
25 InputHandler::~InputHandler() {
28 void InputHandler::SendKeyEvent(bool press
, int keycode
) {
29 protocol::InputStub
* stub
= connection_
->input_stub();
32 pressed_keys_
.insert(keycode
);
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();
48 MouseEvent
* event
= new MouseEvent();
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();
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