blob: dd0fd7aa558c34ef14629a6856750df8faad2867 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// Copyright (c) 2010 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_handler.h"
#include "remoting/client/chromoting_view.h"
#include "remoting/client/host_connection.h"
namespace remoting {
InputHandler::InputHandler(ClientContext* context,
HostConnection* connection,
ChromotingView* view)
: context_(context),
connection_(connection),
view_(view),
send_absolute_mouse_(true),
mouse_x_(0),
mouse_y_(0) {
}
void InputHandler::SendMouseMoveEvent(int x, int y) {
ChromotingClientMessage msg;
if (send_absolute_mouse_) {
MouseSetPositionEvent *event = msg.mutable_mouse_set_position_event();
event->set_x(x);
event->set_y(y);
int width, height;
view_->GetScreenSize(&width, &height);
event->set_width(width);
event->set_height(height);
// TODO(garykac): Fix drift problem with relative mouse events and
// then re-add this line.
//send_absolute_mouse_ = false;
} else {
MouseMoveEvent *event = msg.mutable_mouse_move_event();
int dx = x - mouse_x_;
int dy = y - mouse_y_;
if (dx == 0 && dy == 0) {
return;
}
event->set_offset_x(dx);
event->set_offset_y(dy);
}
// Record current mouse position.
mouse_x_ = x;
mouse_y_ = y;
connection_->SendEvent(msg);
}
void InputHandler::SendMouseButtonEvent(bool button_down,
MouseButton button) {
ChromotingClientMessage msg;
if (button_down) {
msg.mutable_mouse_down_event()->set_button(button);
} else {
msg.mutable_mouse_up_event()->set_button(button);
}
connection_->SendEvent(msg);
}
} // namespace remoting
|