OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/logging.h" |
8 #include "ppapi/c/dev/ppb_keyboard_input_event_dev.h" | 8 #include "ppapi/c/dev/ppb_keyboard_input_event_dev.h" |
9 #include "ppapi/cpp/input_event.h" | 9 #include "ppapi/cpp/input_event.h" |
10 #include "ppapi/cpp/module_impl.h" | 10 #include "ppapi/cpp/module_impl.h" |
11 #include "ppapi/cpp/point.h" | 11 #include "ppapi/cpp/point.h" |
12 #include "remoting/proto/event.pb.h" | 12 #include "remoting/proto/event.pb.h" |
13 | 13 |
14 namespace remoting { | 14 namespace remoting { |
15 | 15 |
16 PepperInputHandler::PepperInputHandler(protocol::InputStub* input_stub) | 16 PepperInputHandler::PepperInputHandler(protocol::InputStub* input_stub) |
17 : input_stub_(input_stub), | 17 : input_stub_(input_stub), |
18 has_focus_(false), | |
19 wheel_delta_x_(0), | 18 wheel_delta_x_(0), |
20 wheel_delta_y_(0) { | 19 wheel_delta_y_(0) { |
21 } | 20 } |
22 | 21 |
23 PepperInputHandler::~PepperInputHandler() { | 22 PepperInputHandler::~PepperInputHandler() { |
24 } | 23 } |
25 | 24 |
26 // Helper function to get the USB key code using the Dev InputEvent interface. | 25 // Helper function to get the USB key code using the Dev InputEvent interface. |
27 uint32_t GetUsbKeyCode(pp::KeyboardInputEvent pp_key_event) { | 26 uint32_t GetUsbKeyCode(pp::KeyboardInputEvent pp_key_event) { |
28 const PPB_KeyboardInputEvent_Dev* key_event_interface = | 27 const PPB_KeyboardInputEvent_Dev* key_event_interface = |
29 reinterpret_cast<const PPB_KeyboardInputEvent_Dev*>( | 28 reinterpret_cast<const PPB_KeyboardInputEvent_Dev*>( |
30 pp::Module::Get()->GetBrowserInterface( | 29 pp::Module::Get()->GetBrowserInterface( |
31 PPB_KEYBOARD_INPUT_EVENT_DEV_INTERFACE)); | 30 PPB_KEYBOARD_INPUT_EVENT_DEV_INTERFACE)); |
32 if (!key_event_interface) | 31 if (!key_event_interface) |
33 return 0; | 32 return 0; |
34 return key_event_interface->GetUsbKeyCode(pp_key_event.pp_resource()); | 33 return key_event_interface->GetUsbKeyCode(pp_key_event.pp_resource()); |
35 } | 34 } |
36 | 35 |
37 void PepperInputHandler::OnFocusChanged(bool has_focus) { | |
38 has_focus_ = has_focus; | |
39 } | |
40 | |
41 bool PepperInputHandler::HandleInputEvent(const pp::InputEvent& event) { | 36 bool PepperInputHandler::HandleInputEvent(const pp::InputEvent& event) { |
42 switch (event.GetType()) { | 37 switch (event.GetType()) { |
43 case PP_INPUTEVENT_TYPE_CONTEXTMENU: { | 38 case PP_INPUTEVENT_TYPE_CONTEXTMENU: { |
44 // We need to return true here or else we'll get a local (plugin) context | 39 // We need to return true here or else we'll get a local (plugin) context |
45 // menu instead of the mouseup event for the right click. | 40 // menu instead of the mouseup event for the right click. |
46 return true; | 41 return true; |
47 } | 42 } |
48 | 43 |
49 case PP_INPUTEVENT_TYPE_KEYDOWN: | 44 case PP_INPUTEVENT_TYPE_KEYDOWN: |
50 case PP_INPUTEVENT_TYPE_KEYUP: { | 45 case PP_INPUTEVENT_TYPE_KEYUP: { |
(...skipping 28 matching lines...) Expand all Loading... |
79 mouse_event.set_x(pp_mouse_event.GetPosition().x()); | 74 mouse_event.set_x(pp_mouse_event.GetPosition().x()); |
80 mouse_event.set_y(pp_mouse_event.GetPosition().y()); | 75 mouse_event.set_y(pp_mouse_event.GetPosition().y()); |
81 input_stub_->InjectMouseEvent(mouse_event); | 76 input_stub_->InjectMouseEvent(mouse_event); |
82 } | 77 } |
83 return true; | 78 return true; |
84 } | 79 } |
85 | 80 |
86 case PP_INPUTEVENT_TYPE_MOUSEMOVE: | 81 case PP_INPUTEVENT_TYPE_MOUSEMOVE: |
87 case PP_INPUTEVENT_TYPE_MOUSEENTER: | 82 case PP_INPUTEVENT_TYPE_MOUSEENTER: |
88 case PP_INPUTEVENT_TYPE_MOUSELEAVE: { | 83 case PP_INPUTEVENT_TYPE_MOUSELEAVE: { |
89 // Don't pass these mouse events through when the | 84 pp::MouseInputEvent pp_mouse_event(event); |
90 // client doesn't have focus. | 85 protocol::MouseEvent mouse_event; |
91 if (has_focus_) { | 86 mouse_event.set_x(pp_mouse_event.GetPosition().x()); |
92 pp::MouseInputEvent pp_mouse_event(event); | 87 mouse_event.set_y(pp_mouse_event.GetPosition().y()); |
| 88 input_stub_->InjectMouseEvent(mouse_event); |
| 89 return true; |
| 90 } |
| 91 |
| 92 case PP_INPUTEVENT_TYPE_WHEEL: { |
| 93 pp::WheelInputEvent pp_wheel_event(event); |
| 94 |
| 95 // Don't handle scroll-by-page events, for now. |
| 96 if (pp_wheel_event.GetScrollByPage()) |
| 97 return false; |
| 98 |
| 99 // Add this event to our accumulated sub-pixel deltas. |
| 100 pp::FloatPoint delta = pp_wheel_event.GetDelta(); |
| 101 wheel_delta_x_ += delta.x(); |
| 102 wheel_delta_y_ += delta.y(); |
| 103 |
| 104 // If there is at least a pixel's movement, emit an event. |
| 105 int delta_x = static_cast<int>(wheel_delta_x_); |
| 106 int delta_y = static_cast<int>(wheel_delta_y_); |
| 107 if (delta_x != 0 || delta_y != 0) { |
| 108 wheel_delta_x_ -= delta_x; |
| 109 wheel_delta_y_ -= delta_y; |
93 protocol::MouseEvent mouse_event; | 110 protocol::MouseEvent mouse_event; |
94 mouse_event.set_x(pp_mouse_event.GetPosition().x()); | 111 mouse_event.set_wheel_delta_x(delta_x); |
95 mouse_event.set_y(pp_mouse_event.GetPosition().y()); | 112 mouse_event.set_wheel_delta_y(delta_y); |
| 113 |
96 input_stub_->InjectMouseEvent(mouse_event); | 114 input_stub_->InjectMouseEvent(mouse_event); |
97 } | 115 } |
98 return true; | 116 return true; |
99 } | 117 } |
100 | |
101 case PP_INPUTEVENT_TYPE_WHEEL: { | |
102 // Don't pass wheel events through when the | |
103 // client doesn't have focus. | |
104 if (has_focus_) { | |
105 pp::WheelInputEvent pp_wheel_event(event); | |
106 | |
107 // Don't handle scroll-by-page events, for now. | |
108 if (pp_wheel_event.GetScrollByPage()) | |
109 return false; | |
110 | |
111 // Add this event to our accumulated sub-pixel deltas. | |
112 pp::FloatPoint delta = pp_wheel_event.GetDelta(); | |
113 wheel_delta_x_ += delta.x(); | |
114 wheel_delta_y_ += delta.y(); | |
115 | |
116 // If there is at least a pixel's movement, emit an event. | |
117 int delta_x = static_cast<int>(wheel_delta_x_); | |
118 int delta_y = static_cast<int>(wheel_delta_y_); | |
119 if (delta_x != 0 || delta_y != 0) { | |
120 wheel_delta_x_ -= delta_x; | |
121 wheel_delta_y_ -= delta_y; | |
122 protocol::MouseEvent mouse_event; | |
123 mouse_event.set_wheel_delta_x(delta_x); | |
124 mouse_event.set_wheel_delta_y(delta_y); | |
125 | |
126 input_stub_->InjectMouseEvent(mouse_event); | |
127 } | |
128 } | |
129 return true; | |
130 } | |
131 | 118 |
132 case PP_INPUTEVENT_TYPE_CHAR: | 119 case PP_INPUTEVENT_TYPE_CHAR: |
133 // Consume but ignore character input events. | 120 // Consume but ignore character input events. |
134 return true; | 121 return true; |
135 | 122 |
136 default: { | 123 default: { |
137 LOG(INFO) << "Unhandled input event: " << event.GetType(); | 124 LOG(INFO) << "Unhandled input event: " << event.GetType(); |
138 break; | 125 break; |
139 } | 126 } |
140 } | 127 } |
141 | 128 |
142 return false; | 129 return false; |
143 } | 130 } |
144 | 131 |
145 } // namespace remoting | 132 } // namespace remoting |
OLD | NEW |