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 "ppapi/c/pp_input_event.h" | |
8 #include "ppapi/cpp/input_event.h" | 7 #include "ppapi/cpp/input_event.h" |
9 #include "ppapi/cpp/point.h" | 8 #include "ppapi/cpp/point.h" |
10 #include "remoting/client/chromoting_view.h" | 9 #include "remoting/client/plugin/pepper_view_proxy.h" |
11 #include "ui/gfx/point.h" | |
12 | 10 |
13 namespace remoting { | 11 namespace remoting { |
14 | 12 |
15 using pp::KeyboardInputEvent; | 13 using pp::KeyboardInputEvent; |
16 using pp::MouseInputEvent; | 14 using pp::MouseInputEvent; |
17 using protocol::KeyEvent; | 15 using protocol::KeyEvent; |
18 using protocol::MouseEvent; | 16 using protocol::MouseEvent; |
19 | 17 |
20 PepperInputHandler::PepperInputHandler(ClientContext* context, | 18 PepperInputHandler::PepperInputHandler(ClientContext* context, |
21 protocol::ConnectionToHost* connection, | 19 protocol::ConnectionToHost* connection, |
22 ChromotingView* view) | 20 PepperViewProxy* view) |
23 : InputHandler(context, connection, view) { | 21 : InputHandler(context, connection, view), |
| 22 pepper_view_(view) { |
24 } | 23 } |
25 | 24 |
26 PepperInputHandler::~PepperInputHandler() { | 25 PepperInputHandler::~PepperInputHandler() { |
27 } | 26 } |
28 | 27 |
29 void PepperInputHandler::Initialize() { | 28 void PepperInputHandler::Initialize() { |
30 } | 29 } |
31 | 30 |
32 void PepperInputHandler::HandleKeyEvent(bool keydown, | 31 void PepperInputHandler::HandleKeyEvent(bool keydown, |
33 const KeyboardInputEvent& event) { | 32 const pp::KeyboardInputEvent& event) { |
34 SendKeyEvent(keydown, event.GetKeyCode()); | 33 SendKeyEvent(keydown, event.GetKeyCode()); |
35 } | 34 } |
36 | 35 |
37 void PepperInputHandler::HandleCharacterEvent(const KeyboardInputEvent& event) { | 36 void PepperInputHandler::HandleCharacterEvent( |
| 37 const pp::KeyboardInputEvent& event) { |
38 // TODO(garykac): Coordinate key and char events. | 38 // TODO(garykac): Coordinate key and char events. |
39 } | 39 } |
40 | 40 |
41 void PepperInputHandler::HandleMouseMoveEvent(const MouseInputEvent& event) { | 41 void PepperInputHandler::HandleMouseMoveEvent( |
42 gfx::Point p(static_cast<int>(event.GetPosition().x()), | 42 const pp::MouseInputEvent& event) { |
43 static_cast<int>(event.GetPosition().y())); | |
44 // Pepper gives co-ordinates in the plugin instance's co-ordinate system, | 43 // Pepper gives co-ordinates in the plugin instance's co-ordinate system, |
45 // which may be different from the host desktop's co-ordinate system. | 44 // which may be different from the host desktop's co-ordinate system. |
46 p = view_->ConvertScreenToHost(p); | 45 pp::Point p = pepper_view_->ConvertScreenToHost(event.GetPosition()); |
47 SendMouseMoveEvent(p.x(), p.y()); | 46 SendMouseMoveEvent(p.x(), p.y()); |
48 } | 47 } |
49 | 48 |
50 void PepperInputHandler::HandleMouseButtonEvent(bool button_down, | 49 void PepperInputHandler::HandleMouseButtonEvent( |
51 const MouseInputEvent& event) { | 50 bool button_down, |
| 51 const pp::MouseInputEvent& event) { |
52 MouseEvent::MouseButton button = MouseEvent::BUTTON_UNDEFINED; | 52 MouseEvent::MouseButton button = MouseEvent::BUTTON_UNDEFINED; |
53 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT) { | 53 switch (event.GetButton()) { |
54 button = MouseEvent::BUTTON_LEFT; | 54 case PP_INPUTEVENT_MOUSEBUTTON_LEFT: |
55 } else if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) { | 55 button = MouseEvent::BUTTON_LEFT; |
56 button = MouseEvent::BUTTON_MIDDLE; | 56 break; |
57 } else if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_RIGHT) { | 57 case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE: |
58 button = MouseEvent::BUTTON_RIGHT; | 58 button = MouseEvent::BUTTON_MIDDLE; |
| 59 break; |
| 60 case PP_INPUTEVENT_MOUSEBUTTON_RIGHT: |
| 61 button = MouseEvent::BUTTON_RIGHT; |
| 62 break; |
| 63 case PP_INPUTEVENT_MOUSEBUTTON_NONE: |
| 64 // Leave button undefined. |
| 65 break; |
59 } | 66 } |
60 | 67 |
61 if (button != MouseEvent::BUTTON_UNDEFINED) { | 68 if (button != MouseEvent::BUTTON_UNDEFINED) { |
62 SendMouseButtonEvent(button_down, button); | 69 SendMouseButtonEvent(button_down, button); |
63 } | 70 } |
64 } | 71 } |
65 | 72 |
66 } // namespace remoting | 73 } // namespace remoting |
OLD | NEW |