Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Unified Diff: remoting/protocol/input_event_tracker.cc

Issue 9465035: Move ClientSession's input logic into separate components. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/protocol/input_event_tracker.h ('k') | remoting/protocol/input_event_tracker_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/protocol/input_event_tracker.cc
diff --git a/remoting/protocol/input_event_tracker.cc b/remoting/protocol/input_event_tracker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..130670b8546abc19225b12d8226ca5c45a1b8bf8
--- /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
« no previous file with comments | « remoting/protocol/input_event_tracker.h ('k') | remoting/protocol/input_event_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698