diff options
author | garykac@chromium.org <garykac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-26 23:03:19 +0000 |
---|---|---|
committer | garykac@chromium.org <garykac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-26 23:03:19 +0000 |
commit | 6730b450fb21fbb7560091b1943ed3be1c757852 (patch) | |
tree | c8c25191d6f5c6adc1a616d8bafb85d7c6094cda /remoting/client/input_handler.cc | |
parent | 234cd85cf6d9d4dd868c2a21bffe2ec575bb6ffc (diff) | |
download | chromium_src-6730b450fb21fbb7560091b1943ed3be1c757852.zip chromium_src-6730b450fb21fbb7560091b1943ed3be1c757852.tar.gz chromium_src-6730b450fb21fbb7560091b1943ed3be1c757852.tar.bz2 |
Add mouse event support to Chromoting client (Pepper and X11).
BUG=none
TEST=remoting unittests
Review URL: http://codereview.chromium.org/3175028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57598 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/client/input_handler.cc')
-rw-r--r-- | remoting/client/input_handler.cc | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/remoting/client/input_handler.cc b/remoting/client/input_handler.cc new file mode 100644 index 0000000..dd0fd7a --- /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 |