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) { |
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 | |
30 case PP_INPUTEVENT_TYPE_KEYDOWN: | |
31 case PP_INPUTEVENT_TYPE_KEYUP: { | |
32 pp::KeyboardInputEvent pp_key_event(event); | |
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 } | |
39 | |
40 case PP_INPUTEVENT_TYPE_MOUSEDOWN: | |
41 case PP_INPUTEVENT_TYPE_MOUSEUP: { | |
42 pp::MouseInputEvent pp_mouse_event(event); | |
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 } | |
64 | |
65 case PP_INPUTEVENT_TYPE_MOUSEMOVE: | |
66 case PP_INPUTEVENT_TYPE_MOUSEENTER: | |
67 case PP_INPUTEVENT_TYPE_MOUSELEAVE: { | |
68 pp::MouseInputEvent pp_mouse_event(event); | |
69 protocol::MouseEvent mouse_event; | |
70 mouse_event.set_x(pp_mouse_event.GetPosition().x()); | |
71 mouse_event.set_y(pp_mouse_event.GetPosition().y()); | |
72 input_stub_->InjectMouseEvent(mouse_event); | |
73 return true; | |
74 } | |
75 | |
76 case PP_INPUTEVENT_TYPE_WHEEL: { | |
77 pp::WheelInputEvent pp_wheel_event(event); | |
78 | |
79 pp::FloatPoint ticks = pp_wheel_event.GetTicks(); | |
80 wheel_ticks_x_ += ticks.x(); | |
81 wheel_ticks_y_ += ticks.y(); | |
82 | |
83 int ticks_x = static_cast<int>(wheel_ticks_x_); | |
84 int ticks_y = static_cast<int>(wheel_ticks_y_); | |
85 if (ticks_x != 0 || ticks_y != 0) { | |
86 wheel_ticks_x_ -= ticks_x; | |
87 wheel_ticks_y_ -= ticks_y; | |
88 protocol::MouseEvent mouse_event; | |
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(); | |
98 break; | |
99 } | |
100 } | |
101 | |
102 return false; | |
28 } | 103 } |
29 | 104 |
30 void PepperInputHandler::HandleKeyEvent(bool keydown, | 105 #if 0 |
Sergey Ulanov
2011/12/20 00:05:35
Remove this code?
Wez
2011/12/20 07:14:14
Done.
| |
31 const pp::KeyboardInputEvent& event) { | |
32 SendKeyEvent(keydown, event.GetKeyCode()); | |
33 } | |
34 | |
35 void PepperInputHandler::HandleCharacterEvent( | |
36 const pp::KeyboardInputEvent& event) { | |
37 // TODO(garykac): Coordinate key and char events. | |
38 } | |
39 | |
40 void PepperInputHandler::HandleMouseMoveEvent( | 106 void PepperInputHandler::HandleMouseMoveEvent( |
41 const pp::MouseInputEvent& event) { | 107 const pp::MouseInputEvent& event) { |
42 SkIPoint p(SkIPoint::Make(event.GetPosition().x(), event.GetPosition().y())); | 108 SkIPoint p(SkIPoint::Make(event.GetPosition().x(), event.GetPosition().y())); |
43 // Pepper gives co-ordinates in the plugin instance's co-ordinate system, | 109 // Pepper gives co-ordinates in the plugin instance's co-ordinate system, |
44 // which may be different from the host desktop's co-ordinate system. | 110 // which may be different from the host desktop's co-ordinate system. |
45 double horizontal_ratio = view_->GetHorizontalScaleRatio(); | 111 double horizontal_ratio = view_->GetHorizontalScaleRatio(); |
46 double vertical_ratio = view_->GetVerticalScaleRatio(); | 112 double vertical_ratio = view_->GetVerticalScaleRatio(); |
47 | 113 |
48 if (horizontal_ratio == 0.0) | 114 if (horizontal_ratio == 0.0) |
49 horizontal_ratio = 1.0; | 115 horizontal_ratio = 1.0; |
50 if (vertical_ratio == 0.0) | 116 if (vertical_ratio == 0.0) |
51 vertical_ratio = 1.0; | 117 vertical_ratio = 1.0; |
52 | 118 |
53 SendMouseMoveEvent(p.x() / horizontal_ratio, p.y() / vertical_ratio); | 119 SendMouseMoveEvent(p.x() / horizontal_ratio, p.y() / vertical_ratio); |
54 } | 120 } |
55 | 121 #endif |
56 void PepperInputHandler::HandleMouseButtonEvent( | |
57 bool button_down, | |
58 const pp::MouseInputEvent& event) { | |
59 MouseEvent::MouseButton button = MouseEvent::BUTTON_UNDEFINED; | |
60 switch (event.GetButton()) { | |
61 case PP_INPUTEVENT_MOUSEBUTTON_LEFT: | |
62 button = MouseEvent::BUTTON_LEFT; | |
63 break; | |
64 case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE: | |
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 } | |
74 | |
75 if (button != MouseEvent::BUTTON_UNDEFINED) { | |
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 } | |
93 | 122 |
94 } // namespace remoting | 123 } // namespace remoting |
OLD | NEW |