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