diff options
author | wez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-24 10:00:56 +0000 |
---|---|---|
committer | wez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-24 10:00:56 +0000 |
commit | 331ec7df0ee1194a8fe88c6fc5c6d26edfdb8f21 (patch) | |
tree | 76b94150788613a353f99b5506b705f67cf3eb31 /remoting | |
parent | a5847a4354de4df88135d3bbada8d1fdf32ca6e2 (diff) | |
download | chromium_src-331ec7df0ee1194a8fe88c6fc5c6d26edfdb8f21.zip chromium_src-331ec7df0ee1194a8fe88c6fc5c6d26edfdb8f21.tar.gz chromium_src-331ec7df0ee1194a8fe88c6fc5c6d26edfdb8f21.tar.bz2 |
Support MouseEvent input in Chromoting host for Mac.
BUG=73847
TEST=Connect to Chromoting host for Mac and try to click or drag a window.
Review URL: http://codereview.chromium.org/6580001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75865 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/host/event_executor_mac.cc | 65 | ||||
-rw-r--r-- | remoting/host/event_executor_mac.h | 1 |
2 files changed, 65 insertions, 1 deletions
diff --git a/remoting/host/event_executor_mac.cc b/remoting/host/event_executor_mac.cc index 71a9eda..d51669e 100644 --- a/remoting/host/event_executor_mac.cc +++ b/remoting/host/event_executor_mac.cc @@ -4,9 +4,13 @@ #include "remoting/host/event_executor_mac.h" +#include <ApplicationServices/ApplicationServices.h> + #include "base/message_loop.h" #include "base/task.h" +#include "remoting/host/capturer.h" #include "remoting/protocol/message_decoder.h" +#include "remoting/proto/internal.pb.h" namespace remoting { @@ -16,7 +20,7 @@ using protocol::KeyEvent; EventExecutorMac::EventExecutorMac( MessageLoopForUI* message_loop, Capturer* capturer) : message_loop_(message_loop), - capturer_(capturer) { + capturer_(capturer), last_x_(0), last_y_(0) { } EventExecutorMac::~EventExecutorMac() { @@ -28,6 +32,65 @@ void EventExecutorMac::InjectKeyEvent(const KeyEvent* event, Task* done) { } void EventExecutorMac::InjectMouseEvent(const MouseEvent* event, Task* done) { + CGEventType event_type = kCGEventNull; + + if (event->has_x() && event->has_y()) { + // TODO(wez): Checking the validity of the MouseEvent should be done in core + // cross-platform code, not here! + // TODO(wez): This code assumes that MouseEvent(0,0) (top-left of client view) + // corresponds to local (0,0) (top-left of primary monitor). That won't in + // general be true on multi-monitor systems, though. + int width = capturer_->width(); + int height = capturer_->height(); + if (event->x() >= 0 || event->y() >= 0 || + event->x() < width || event->y() < height) { + + VLOG(3) << "Moving mouse to " << event->x() << "," << event->y(); + + event_type = kCGEventMouseMoved; + last_x_ = event->x(); + last_y_ = event->y(); + } + } + + CGPoint position = CGPointMake(last_x_, last_y_); + CGMouseButton mouse_button = 0; + + if (event->has_button() && event->has_button_down()) { + + VLOG(2) << "Button " << event->button() + << (event->button_down() ? " down" : " up"); + + event_type = event->button_down() ? kCGEventOtherMouseDown + : kCGEventOtherMouseUp; + if (MouseEvent::BUTTON_LEFT == event->button()) { + event_type = event->button_down() ? kCGEventLeftMouseDown + : kCGEventLeftMouseUp; + mouse_button = kCGMouseButtonLeft; // not strictly necessary + } else if (MouseEvent::BUTTON_RIGHT == event->button()) { + event_type = event->button_down() ? kCGEventRightMouseDown + : kCGEventRightMouseUp; + mouse_button = kCGMouseButtonRight; // not strictly necessary + } else if (MouseEvent::BUTTON_MIDDLE == event->button()) { + mouse_button = kCGMouseButtonCenter; + } else { + VLOG(1) << "Unknown mouse button!" << event->button(); + } + } + + if (event->has_wheel_offset_x() && event->has_wheel_offset_y()) { + // TODO(wez): Should set event_type == kCGEventScrollWheel and + // populate fields for a CGEventCreateScrollWheelEvent() here. + NOTIMPLEMENTED() << "No scroll wheel support yet."; + } + + if (event_type != kCGEventNull) { + CGEventRef mouse_event = CGEventCreateMouseEvent(NULL, event_type, + position, mouse_button); + CGEventPost(kCGSessionEventTap, mouse_event); + CFRelease(mouse_event); + } + done->Run(); delete done; } diff --git a/remoting/host/event_executor_mac.h b/remoting/host/event_executor_mac.h index 66288a0..6b3054d9 100644 --- a/remoting/host/event_executor_mac.h +++ b/remoting/host/event_executor_mac.h @@ -25,6 +25,7 @@ class EventExecutorMac : public protocol::InputStub { private: MessageLoopForUI* message_loop_; Capturer* capturer_; + int last_x_, last_y_; DISALLOW_COPY_AND_ASSIGN(EventExecutorMac); }; |