| Index: remoting/client/input_handler.cc
|
| diff --git a/remoting/client/input_handler.cc b/remoting/client/input_handler.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..dd0fd7aa558c34ef14629a6856750df8faad2867
|
| --- /dev/null
|
| +++ b/remoting/client/input_handler.cc
|
| @@ -0,0 +1,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
|
|
|