summaryrefslogtreecommitdiffstats
path: root/remoting/protocol/input_event_tracker.cc
diff options
context:
space:
mode:
authorwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-03 00:56:18 +0000
committerwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-03 00:56:18 +0000
commit86cbe6bb069e557edbf00d4464fdcaae48fee0f4 (patch)
tree628639ab01ab4a58496204f2eb43f172645ce5f6 /remoting/protocol/input_event_tracker.cc
parentc65e2cc1411776492160cc34ca9bc433a94a8a8a (diff)
downloadchromium_src-86cbe6bb069e557edbf00d4464fdcaae48fee0f4.zip
chromium_src-86cbe6bb069e557edbf00d4464fdcaae48fee0f4.tar.gz
chromium_src-86cbe6bb069e557edbf00d4464fdcaae48fee0f4.tar.bz2
This CL moves much of the input tracking logic out of ClientSession, which means:
* We can re-use existing client-side input pipeline components. * Individual features of the input pipeline are isolated from one another. * It'll be easier to move some portions of the pipeline into ChromotingHost, where they belong. The CL makes the following changes: * Moves KeyEventTracker to InputEventTracker and has it release mouse buttons as well as keys. * Moves blocking of events when there is local input to a new RemoteInputFilter component. * Simplifies ClientSession to enable/disable events by setting and clearing the output InputStub on an InputFilter. * Simplifies ClientSession's SetDisableInputs() (used to temporarily disable inputs during the Continue dialog for IT2Me) to use the InputFilter mechanism. * Releases keys and buttons when entering the input-blocking state. BUG=118511 Review URL: http://codereview.chromium.org/9465035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130263 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol/input_event_tracker.cc')
-rw-r--r--remoting/protocol/input_event_tracker.cc80
1 files changed, 80 insertions, 0 deletions
diff --git a/remoting/protocol/input_event_tracker.cc b/remoting/protocol/input_event_tracker.cc
new file mode 100644
index 0000000..130670b
--- /dev/null
+++ b/remoting/protocol/input_event_tracker.cc
@@ -0,0 +1,80 @@
+// Copyright (c) 2012 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/protocol/input_event_tracker.h"
+
+#include "base/logging.h"
+#include "remoting/proto/event.pb.h"
+
+namespace remoting {
+namespace protocol {
+
+InputEventTracker::InputEventTracker(InputStub* input_stub)
+ : input_stub_(input_stub),
+ mouse_pos_(SkIPoint::Make(0, 0)),
+ mouse_button_state_(0) {
+}
+
+InputEventTracker::~InputEventTracker() {
+}
+
+void InputEventTracker::InjectKeyEvent(const KeyEvent& event) {
+ DCHECK(event.has_pressed());
+ DCHECK(event.has_keycode());
+ if (event.pressed()) {
+ pressed_keys_.insert(event.keycode());
+ } else {
+ pressed_keys_.erase(event.keycode());
+ }
+ input_stub_->InjectKeyEvent(event);
+}
+
+void InputEventTracker::InjectMouseEvent(const MouseEvent& event) {
+ if (event.has_x() && event.has_y()) {
+ mouse_pos_ = SkIPoint::Make(event.x(), event.y());
+ }
+ if (event.has_button() && event.has_button_down()) {
+ // Button values are defined in remoting/proto/event.proto.
+ if (event.button() >= 1 && event.button() < MouseEvent::BUTTON_MAX) {
+ uint32 button_change = 1 << (event.button() - 1);
+ if (event.button_down()) {
+ mouse_button_state_ |= button_change;
+ } else {
+ mouse_button_state_ &= ~button_change;
+ }
+ }
+ }
+ input_stub_->InjectMouseEvent(event);
+}
+
+void InputEventTracker::ReleaseAll() {
+ std::set<int>::iterator i;
+ for (i = pressed_keys_.begin(); i != pressed_keys_.end(); ++i) {
+ KeyEvent event;
+ event.set_keycode(*i);
+ event.set_pressed(false);
+ input_stub_->InjectKeyEvent(event);
+ }
+ pressed_keys_.clear();
+
+ for (int i = MouseEvent::BUTTON_UNDEFINED + 1;
+ i < MouseEvent::BUTTON_MAX; ++i) {
+ if (mouse_button_state_ & (1 << (i - 1))) {
+ MouseEvent mouse;
+
+ // TODO(wez): EventInjectors should cope with positionless events by
+ // using the current cursor position, and we wouldn't set position here.
+ mouse.set_x(mouse_pos_.x());
+ mouse.set_y(mouse_pos_.y());
+
+ mouse.set_button((MouseEvent::MouseButton)i);
+ mouse.set_button_down(false);
+ input_stub_->InjectMouseEvent(mouse);
+ }
+ }
+ mouse_button_state_ = 0;
+}
+
+} // namespace protocol
+} // namespace remoting