| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/client/plugin/pepper_input_handler.h" | 5 #include "remoting/client/plugin/pepper_input_handler.h" |
| 6 | 6 |
| 7 #include "base/logging.h" |
| 7 #include "ppapi/cpp/input_event.h" | 8 #include "ppapi/cpp/input_event.h" |
| 8 #include "ppapi/cpp/point.h" | 9 #include "ppapi/cpp/point.h" |
| 9 #include "remoting/client/plugin/pepper_view_proxy.h" | 10 #include "remoting/proto/event.pb.h" |
| 10 | 11 |
| 11 namespace remoting { | 12 namespace remoting { |
| 12 | 13 |
| 13 using protocol::MouseEvent; | 14 PepperInputHandler::PepperInputHandler(protocol::InputStub* input_stub) |
| 14 | 15 : input_stub_(input_stub), wheel_ticks_x_(0), wheel_ticks_y_(0) |
| 15 PepperInputHandler::PepperInputHandler(ClientContext* context, | 16 { |
| 16 protocol::ConnectionToHost* connection, | |
| 17 PepperViewProxy* view) | |
| 18 : InputHandler(context, connection, view), | |
| 19 pepper_view_(view), | |
| 20 wheel_ticks_x_(0), | |
| 21 wheel_ticks_y_(0) { | |
| 22 } | 17 } |
| 23 | 18 |
| 24 PepperInputHandler::~PepperInputHandler() { | 19 PepperInputHandler::~PepperInputHandler() { |
| 25 } | 20 } |
| 26 | 21 |
| 27 void PepperInputHandler::Initialize() { | 22 bool PepperInputHandler::HandleInputEvent(const pp::InputEvent& event) { |
| 28 } | 23 switch (event.GetType()) { |
| 24 case PP_INPUTEVENT_TYPE_CONTEXTMENU: { |
| 25 // We need to return true here or else we'll get a local (plugin) context |
| 26 // menu instead of the mouseup event for the right click. |
| 27 return true; |
| 28 } |
| 29 | 29 |
| 30 void PepperInputHandler::HandleKeyEvent(bool keydown, | 30 case PP_INPUTEVENT_TYPE_KEYDOWN: |
| 31 const pp::KeyboardInputEvent& event) { | 31 case PP_INPUTEVENT_TYPE_KEYUP: { |
| 32 SendKeyEvent(keydown, event.GetKeyCode()); | 32 pp::KeyboardInputEvent pp_key_event(event); |
| 33 } | 33 protocol::KeyEvent key_event; |
| 34 key_event.set_keycode(pp_key_event.GetKeyCode()); |
| 35 key_event.set_pressed(event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN); |
| 36 input_stub_->InjectKeyEvent(key_event); |
| 37 return true; |
| 38 } |
| 34 | 39 |
| 35 void PepperInputHandler::HandleCharacterEvent( | 40 case PP_INPUTEVENT_TYPE_MOUSEDOWN: |
| 36 const pp::KeyboardInputEvent& event) { | 41 case PP_INPUTEVENT_TYPE_MOUSEUP: { |
| 37 // TODO(garykac): Coordinate key and char events. | 42 pp::MouseInputEvent pp_mouse_event(event); |
| 38 } | 43 protocol::MouseEvent mouse_event; |
| 44 switch (pp_mouse_event.GetButton()) { |
| 45 case PP_INPUTEVENT_MOUSEBUTTON_LEFT: |
| 46 mouse_event.set_button(protocol::MouseEvent::BUTTON_LEFT); |
| 47 break; |
| 48 case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE: |
| 49 mouse_event.set_button(protocol::MouseEvent::BUTTON_MIDDLE); |
| 50 break; |
| 51 case PP_INPUTEVENT_MOUSEBUTTON_RIGHT: |
| 52 mouse_event.set_button(protocol::MouseEvent::BUTTON_RIGHT); |
| 53 break; |
| 54 case PP_INPUTEVENT_MOUSEBUTTON_NONE: |
| 55 break; |
| 56 } |
| 57 if (mouse_event.has_button()) { |
| 58 bool is_down = (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN); |
| 59 mouse_event.set_button_down(is_down); |
| 60 input_stub_->InjectMouseEvent(mouse_event); |
| 61 } |
| 62 return true; |
| 63 } |
| 39 | 64 |
| 40 void PepperInputHandler::HandleMouseMoveEvent( | 65 case PP_INPUTEVENT_TYPE_MOUSEMOVE: |
| 41 const pp::MouseInputEvent& event) { | 66 case PP_INPUTEVENT_TYPE_MOUSEENTER: |
| 42 SkIPoint p(SkIPoint::Make(event.GetPosition().x(), event.GetPosition().y())); | 67 case PP_INPUTEVENT_TYPE_MOUSELEAVE: { |
| 43 // Pepper gives co-ordinates in the plugin instance's co-ordinate system, | 68 pp::MouseInputEvent pp_mouse_event(event); |
| 44 // which may be different from the host desktop's co-ordinate system. | 69 protocol::MouseEvent mouse_event; |
| 45 double horizontal_ratio = view_->GetHorizontalScaleRatio(); | 70 mouse_event.set_x(pp_mouse_event.GetPosition().x()); |
| 46 double vertical_ratio = view_->GetVerticalScaleRatio(); | 71 mouse_event.set_y(pp_mouse_event.GetPosition().y()); |
| 72 input_stub_->InjectMouseEvent(mouse_event); |
| 73 return true; |
| 74 } |
| 47 | 75 |
| 48 if (horizontal_ratio == 0.0) | 76 case PP_INPUTEVENT_TYPE_WHEEL: { |
| 49 horizontal_ratio = 1.0; | 77 pp::WheelInputEvent pp_wheel_event(event); |
| 50 if (vertical_ratio == 0.0) | |
| 51 vertical_ratio = 1.0; | |
| 52 | 78 |
| 53 SendMouseMoveEvent(p.x() / horizontal_ratio, p.y() / vertical_ratio); | 79 pp::FloatPoint ticks = pp_wheel_event.GetTicks(); |
| 54 } | 80 wheel_ticks_x_ += ticks.x(); |
| 81 wheel_ticks_y_ += ticks.y(); |
| 55 | 82 |
| 56 void PepperInputHandler::HandleMouseButtonEvent( | 83 int ticks_x = static_cast<int>(wheel_ticks_x_); |
| 57 bool button_down, | 84 int ticks_y = static_cast<int>(wheel_ticks_y_); |
| 58 const pp::MouseInputEvent& event) { | 85 if (ticks_x != 0 || ticks_y != 0) { |
| 59 MouseEvent::MouseButton button = MouseEvent::BUTTON_UNDEFINED; | 86 wheel_ticks_x_ -= ticks_x; |
| 60 switch (event.GetButton()) { | 87 wheel_ticks_y_ -= ticks_y; |
| 61 case PP_INPUTEVENT_MOUSEBUTTON_LEFT: | 88 protocol::MouseEvent mouse_event; |
| 62 button = MouseEvent::BUTTON_LEFT; | 89 mouse_event.set_wheel_offset_x(wheel_ticks_x_); |
| 90 mouse_event.set_wheel_offset_y(wheel_ticks_y_); |
| 91 input_stub_->InjectMouseEvent(mouse_event); |
| 92 } |
| 93 return true; |
| 94 } |
| 95 |
| 96 default: { |
| 97 LOG(INFO) << "Unhandled input event: " << event.GetType(); |
| 63 break; | 98 break; |
| 64 case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE: | 99 } |
| 65 button = MouseEvent::BUTTON_MIDDLE; | |
| 66 break; | |
| 67 case PP_INPUTEVENT_MOUSEBUTTON_RIGHT: | |
| 68 button = MouseEvent::BUTTON_RIGHT; | |
| 69 break; | |
| 70 case PP_INPUTEVENT_MOUSEBUTTON_NONE: | |
| 71 // Leave button undefined. | |
| 72 break; | |
| 73 } | 100 } |
| 74 | 101 |
| 75 if (button != MouseEvent::BUTTON_UNDEFINED) { | 102 return false; |
| 76 SendMouseButtonEvent(button_down, button); | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 void PepperInputHandler::HandleMouseWheelEvent( | |
| 81 const pp::WheelInputEvent& event) { | |
| 82 pp::FloatPoint ticks = event.GetTicks(); | |
| 83 wheel_ticks_x_ += ticks.x(); | |
| 84 wheel_ticks_y_ += ticks.y(); | |
| 85 int ticks_x = static_cast<int>(wheel_ticks_x_); | |
| 86 int ticks_y = static_cast<int>(wheel_ticks_y_); | |
| 87 if (ticks_x != 0 || ticks_y != 0) { | |
| 88 wheel_ticks_x_ -= ticks_x; | |
| 89 wheel_ticks_y_ -= ticks_y; | |
| 90 SendMouseWheelEvent(ticks_x, ticks_y); | |
| 91 } | |
| 92 } | 103 } |
| 93 | 104 |
| 94 } // namespace remoting | 105 } // namespace remoting |
| OLD | NEW |