diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-29 21:56:12 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-29 21:56:12 +0000 |
commit | 65f86878792c6e8bb5b78e98ed96dd99ce2c30bb (patch) | |
tree | b0c3a97fd2250b3fdbd254a4dc82c02c08bb04f4 /remoting/host | |
parent | bfc031f0f5f833f293b489bf1a2d1c873341fdda (diff) | |
download | chromium_src-65f86878792c6e8bb5b78e98ed96dd99ce2c30bb.zip chromium_src-65f86878792c6e8bb5b78e98ed96dd99ce2c30bb.tar.gz chromium_src-65f86878792c6e8bb5b78e98ed96dd99ce2c30bb.tar.bz2 |
Hook up client events to new protocol stubs.
Patch by garykac@chromium.com.
Original review: http://codereview.chromium.org/5062001
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/5345007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67594 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host')
-rw-r--r-- | remoting/host/event_executor_linux.cc | 111 | ||||
-rw-r--r-- | remoting/host/event_executor_win.cc | 173 | ||||
-rw-r--r-- | remoting/host/event_executor_win.h | 13 |
3 files changed, 110 insertions, 187 deletions
diff --git a/remoting/host/event_executor_linux.cc b/remoting/host/event_executor_linux.cc index dcc7dc0..f540d44 100644 --- a/remoting/host/event_executor_linux.cc +++ b/remoting/host/event_executor_linux.cc @@ -206,11 +206,6 @@ class EventExecutorLinuxPimpl { void HandleKey(const KeyEvent* key_event); private: - void HandleMouseSetPosition(const MouseSetPositionEvent& position_event); - void HandleMouseMove(const MouseMoveEvent& move_event); - void HandleMouseWheel(const MouseWheelEvent& wheel_event); - void HandleMouseButtonDown(const MouseDownEvent& mouse_down_event); - void HandleMouseButtonUp(const MouseUpEvent& mouse_up_event); void DeinitXlib(); // Reference to containing class so we can access friend functions. @@ -290,75 +285,6 @@ bool EventExecutorLinuxPimpl::Init() { return true; } -void EventExecutorLinuxPimpl::HandleMouse( - const MouseEvent* mouse_event) { - if (mouse_event->has_set_position()) { - HandleMouseSetPosition(mouse_event->set_position()); - } else if (mouse_event->has_wheel()) { - HandleMouseWheel(mouse_event->wheel()); - } else if (mouse_event->has_down()) { - HandleMouseButtonDown(mouse_event->down()); - } else if (mouse_event->has_up()) { - HandleMouseButtonUp(mouse_event->up()); - } -} - -void EventExecutorLinuxPimpl::HandleMouseSetPosition( - const MouseSetPositionEvent& position_event) { - if (position_event.x() < 0 || position_event.y() < 0 || - position_event.x() > width_ || position_event.y() > height_) { - // A misbehaving client may send these. Drop events that are out of range. - // TODO(ajwong): How can we log this sanely? We don't want to DOS the server - // with a misbehaving client by logging like crazy. - return; - } - - VLOG(3) << "Moving mouse to " << position_event.x() - << "," << position_event.y(); - XTestFakeMotionEvent(display_, DefaultScreen(display_), - position_event.x(), position_event.y(), - CurrentTime); -} -void EventExecutorLinuxPimpl::HandleMouseMove( - const MouseMoveEvent& move_event) { - NOTIMPLEMENTED() << "We shouldn't be using relative moves."; -} - -void EventExecutorLinuxPimpl::HandleMouseWheel( - const MouseWheelEvent& wheel_event) { - NOTIMPLEMENTED() << "No scroll wheel support yet."; -} - -void EventExecutorLinuxPimpl::HandleMouseButtonDown( - const MouseDownEvent& mouse_down_event) { - int button_number = MouseButtonToX11ButtonNumber(mouse_down_event.button()); - - if (button_number < 0) { - LOG(WARNING) << "Ignoring unknown button type: " - << mouse_down_event.button(); - return; - } - - VLOG(3) << "Button " << mouse_down_event.button() - << " received, sending down " << button_number; - XTestFakeButtonEvent(display_, button_number, True, CurrentTime); -} - -void EventExecutorLinuxPimpl::HandleMouseButtonUp( - const MouseUpEvent& mouse_up_event) { - int button_number = MouseButtonToX11ButtonNumber(mouse_up_event.button()); - - if (button_number < 0) { - LOG(WARNING) << "Ignoring unknown button type: " - << mouse_up_event.button(); - return; - } - - VLOG(3) << "Button " << mouse_up_event.button() - << " received, sending up " << button_number; - XTestFakeButtonEvent(display_, button_number, False, CurrentTime); -} - void EventExecutorLinuxPimpl::HandleKey(const KeyEvent* key_event) { // TODO(ajwong): This will only work for QWERTY keyboards. int keysym = ChromotocolKeycodeToX11Keysym(key_event->key()); @@ -382,6 +308,43 @@ void EventExecutorLinuxPimpl::HandleKey(const KeyEvent* key_event) { XTestFakeKeyEvent(display_, keycode, key_event->pressed(), CurrentTime); } +void EventExecutorLinuxPimpl::HandleMouse(const MouseEvent* event) { + if (event->has_x() && event->has_y()) { + if (event->x() < 0 || event->y() < 0 || + event->x() > width_ || event->y() > height_) { + // A misbehaving client may send these. Drop events that are out of range. + // TODO(ajwong): How can we log this sanely? We don't want to DOS the + // server with a misbehaving client by logging like crazy. + return; + } + + VLOG(3) << "Moving mouse to " << event->x() + << "," << event->y(); + XTestFakeMotionEvent(display_, DefaultScreen(display_), + event->x(), event->y(), + CurrentTime); + } + + if (event->has_button() && event->has_button_down()) { + int button_number = MouseButtonToX11ButtonNumber(event->button()); + + if (button_number < 0) { + LOG(WARNING) << "Ignoring unknown button type: " + << event->button(); + return; + } + + VLOG(3) << "Button " << event->button() + << " received, sending down " << button_number; + XTestFakeButtonEvent(display_, button_number, event->button_down(), + CurrentTime); + } + + if (event->has_wheel_offset_x() && event->has_wheel_offset_y()) { + NOTIMPLEMENTED() << "No scroll wheel support yet."; + } +} + void EventExecutorLinuxPimpl::DeinitXlib() { // TODO(ajwong): We should expose a "close" or "shutdown" method. if (gc_) { diff --git a/remoting/host/event_executor_win.cc b/remoting/host/event_executor_win.cc index 9cabeb1..f79d9eb 100644 --- a/remoting/host/event_executor_win.cc +++ b/remoting/host/event_executor_win.cc @@ -16,7 +16,8 @@ namespace remoting { EventExecutorWin::EventExecutorWin( MessageLoop* message_loop, Capturer* capturer) - : message_loop_(message_loop), capturer_(capturer) { + : message_loop_(message_loop), + capturer_(capturer) { } EventExecutorWin::~EventExecutorWin() { @@ -30,7 +31,7 @@ void EventExecutorWin::InjectKeyEvent(const KeyEvent* event, Task* done) { event, done)); return; } - HandleKey(*event); + HandleKey(event); done->Run(); delete done; } @@ -44,111 +45,14 @@ void EventExecutorWin::InjectMouseEvent(const MouseEvent* event, event, done)); return; } - if (event->has_set_position()) { - HandleMouseSetPosition(event->set_position()); - } else if (event->has_wheel()) { - HandleMouseWheel(event->wheel()); - } else if (event->has_down()) { - HandleMouseButtonDown(event->down()); - } else if (event->has_up()) { - HandleMouseButtonUp(event->up()); - } + HandleMouse(event); done->Run(); delete done; } -void EventExecutorWin::HandleMouseSetPosition( - const MouseSetPositionEvent& event) { - int x = event.x(); - int y = event.y(); - int width = event.width(); - int height = event.height(); - - // Get width and height from the capturer if they are missing from the - // message. - if (width == 0 || height == 0) { - width = capturer_->width(); - height = capturer_->height(); - } - if (width == 0 || height == 0) { - return; - } - - INPUT input; - input.type = INPUT_MOUSE; - input.mi.time = 0; - input.mi.dx = static_cast<int>((x * 65535) / width); - input.mi.dy = static_cast<int>((y * 65535) / height); - input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE; - SendInput(1, &input, sizeof(INPUT)); -} - -void EventExecutorWin::HandleMouseWheel( - const MouseWheelEvent& event) { - INPUT input; - input.type = INPUT_MOUSE; - input.mi.time = 0; - - int dx = event.offset_x(); - int dy = event.offset_y(); - - if (dx != 0) { - input.mi.mouseData = dx; - input.mi.dwFlags = MOUSEEVENTF_HWHEEL; - SendInput(1, &input, sizeof(INPUT)); - } - if (dy != 0) { - input.mi.mouseData = dy; - input.mi.dwFlags = MOUSEEVENTF_WHEEL; - SendInput(1, &input, sizeof(INPUT)); - } -} - -void EventExecutorWin::HandleMouseButtonDown(const MouseDownEvent& event) { - INPUT input; - input.type = INPUT_MOUSE; - input.mi.time = 0; - input.mi.dx = 0; - input.mi.dy = 0; - - MouseButton button = event.button(); - if (button == MouseButtonLeft) { - input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN; - } else if (button == MouseButtonMiddle) { - input.mi.dwFlags = MOUSEEVENTF_MIDDLEDOWN; - } else if (button == MouseButtonRight) { - input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN; - } else { - input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN; - } - - SendInput(1, &input, sizeof(INPUT)); -} - -void EventExecutorWin::HandleMouseButtonUp(const MouseUpEvent& event) { - INPUT input; - input.type = INPUT_MOUSE; - input.mi.time = 0; - input.mi.dx = 0; - input.mi.dy = 0; - - MouseButton button = event.button(); - if (button == MouseButtonLeft) { - input.mi.dwFlags = MOUSEEVENTF_LEFTUP; - } else if (button == MouseButtonMiddle) { - input.mi.dwFlags = MOUSEEVENTF_MIDDLEUP; - } else if (button == MouseButtonRight) { - input.mi.dwFlags = MOUSEEVENTF_RIGHTUP; - } else { - input.mi.dwFlags = MOUSEEVENTF_LEFTUP; - } - - SendInput(1, &input, sizeof(INPUT)); -} - -void EventExecutorWin::HandleKey(const KeyEvent& event) { - int key = event.key(); - bool down = event.pressed(); +void EventExecutorWin::HandleKey(const KeyEvent* event) { + int key = event->key(); + bool down = event->pressed(); // Calculate scan code from virtual key. HKL hkl = GetKeyboardLayout(0); @@ -179,4 +83,67 @@ protocol::InputStub* CreateEventExecutor(MessageLoop* message_loop, return new EventExecutorWin(message_loop, capturer); } +void EventExecutorWin::HandleMouse(const MouseEvent* event) { + // TODO(garykac) Collapse mouse (x,y) and button events into a single + // input event when possible. + if (event->has_x() && event->has_y()) { + int x = event->x(); + int y = event->y(); + + INPUT input; + input.type = INPUT_MOUSE; + input.mi.time = 0; + input.mi.dx = static_cast<int>((x * 65535) / capturer_->width()); + input.mi.dy = static_cast<int>((y * 65535) / capturer_->height()); + input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE; + SendInput(1, &input, sizeof(INPUT)); + } + + if (event->has_wheel_offset_x() && event->has_wheel_offset_y()) { + INPUT wheel; + wheel.type = INPUT_MOUSE; + wheel.mi.time = 0; + + int dx = event->wheel_offset_x(); + int dy = event->wheel_offset_y(); + + if (dx != 0) { + wheel.mi.mouseData = dx; + wheel.mi.dwFlags = MOUSEEVENTF_HWHEEL; + SendInput(1, &wheel, sizeof(INPUT)); + } + if (dy != 0) { + wheel.mi.mouseData = dy; + wheel.mi.dwFlags = MOUSEEVENTF_WHEEL; + SendInput(1, &wheel, sizeof(INPUT)); + } + } + + if (event->has_button() && event->has_button_down()) { + INPUT button_event; + button_event.type = INPUT_MOUSE; + button_event.mi.time = 0; + button_event.mi.dx = 0; + button_event.mi.dy = 0; + + MouseButton button = event->button(); + bool down = event->button_down(); + if (button == MouseButtonLeft) { + button_event.mi.dwFlags = + down ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP; + } else if (button == MouseButtonMiddle) { + button_event.mi.dwFlags = + down ? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP; + } else if (button == MouseButtonRight) { + button_event.mi.dwFlags = + down ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP; + } else { + button_event.mi.dwFlags = + down ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP; + } + + SendInput(1, &button_event, sizeof(INPUT)); + } +} + } // namespace remoting diff --git a/remoting/host/event_executor_win.h b/remoting/host/event_executor_win.h index 3e2ddc6..b7be3c8 100644 --- a/remoting/host/event_executor_win.h +++ b/remoting/host/event_executor_win.h @@ -15,11 +15,7 @@ namespace remoting { -class KeyEvent; -class MouseDownEvent; -class MouseSetPositionEvent; -class MouseUpEvent; -class MouseWheelEvent; +class EventExecutorWinPimpl; // A class to generate events on Windows. class EventExecutorWin : public protocol::InputStub { @@ -31,11 +27,8 @@ class EventExecutorWin : public protocol::InputStub { virtual void InjectMouseEvent(const MouseEvent* event, Task* done); private: - void HandleMouseSetPosition(const MouseSetPositionEvent& event); - void HandleMouseWheel(const MouseWheelEvent& event); - void HandleMouseButtonDown(const MouseDownEvent& event); - void HandleMouseButtonUp(const MouseUpEvent& event); - void HandleKey(const KeyEvent& event); + void HandleKey(const KeyEvent* event); + void HandleMouse(const MouseEvent* event); MessageLoop* message_loop_; Capturer* capturer_; |