Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Side by Side Diff: remoting/client/plugin/pepper_input_handler.cc

Issue 292103004: Enable keyboard filters in PNaCl client (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/client/plugin/pepper_input_handler.h ('k') | remoting/remoting_client.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/cpp/image_data.h" 8 #include "ppapi/cpp/image_data.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/mouse_cursor.h" 11 #include "ppapi/cpp/mouse_cursor.h"
12 #include "ppapi/cpp/point.h" 12 #include "ppapi/cpp/point.h"
13 #include "ppapi/cpp/var.h" 13 #include "ppapi/cpp/var.h"
14 #include "remoting/proto/event.pb.h" 14 #include "remoting/proto/event.pb.h"
15 #include "ui/events/keycodes/dom4/keycode_converter.h" 15 #include "ui/events/keycodes/dom4/keycode_converter.h"
16 16
17 namespace remoting { 17 namespace remoting {
18 18
19 PepperInputHandler::PepperInputHandler( 19 PepperInputHandler::PepperInputHandler(
20 pp::Instance* instance, 20 pp::Instance* instance)
21 protocol::InputStub* input_stub)
22 : pp::MouseLock(instance), 21 : pp::MouseLock(instance),
23 instance_(instance), 22 instance_(instance),
24 input_stub_(input_stub), 23 input_stub_(NULL),
25 callback_factory_(this), 24 callback_factory_(this),
26 has_focus_(false), 25 has_focus_(false),
27 mouse_lock_state_(MouseLockDisallowed), 26 mouse_lock_state_(MouseLockDisallowed),
28 wheel_delta_x_(0), 27 wheel_delta_x_(0),
29 wheel_delta_y_(0), 28 wheel_delta_y_(0),
30 wheel_ticks_x_(0), 29 wheel_ticks_x_(0),
31 wheel_ticks_y_(0) { 30 wheel_ticks_y_(0) {
32 } 31 }
33 32
34 PepperInputHandler::~PepperInputHandler() { 33 PepperInputHandler::~PepperInputHandler() {}
35 }
36 34
37 // Helper function to get the USB key code using the Dev InputEvent interface. 35 // Helper function to get the USB key code using the Dev InputEvent interface.
38 uint32_t GetUsbKeyCode(pp::KeyboardInputEvent pp_key_event) { 36 uint32_t GetUsbKeyCode(pp::KeyboardInputEvent pp_key_event) {
39 // Get the DOM3 |code| as a string. 37 // Get the DOM3 |code| as a string.
40 std::string codestr = pp_key_event.GetCode().AsString(); 38 std::string codestr = pp_key_event.GetCode().AsString();
41 39
42 // Convert the |code| string into a USB keycode. 40 // Convert the |code| string into a USB keycode.
43 ui::KeycodeConverter* key_converter = ui::KeycodeConverter::GetInstance(); 41 ui::KeycodeConverter* key_converter = ui::KeycodeConverter::GetInstance();
44 return key_converter->CodeToUsbKeycode(codestr.c_str()); 42 return key_converter->CodeToUsbKeycode(codestr.c_str());
45 } 43 }
(...skipping 16 matching lines...) Expand all
62 lock_states |= protocol::KeyEvent::LOCK_STATES_CAPSLOCK; 60 lock_states |= protocol::KeyEvent::LOCK_STATES_CAPSLOCK;
63 61
64 if (modifiers & PP_INPUTEVENT_MODIFIER_NUMLOCKKEY) 62 if (modifiers & PP_INPUTEVENT_MODIFIER_NUMLOCKKEY)
65 lock_states |= protocol::KeyEvent::LOCK_STATES_NUMLOCK; 63 lock_states |= protocol::KeyEvent::LOCK_STATES_NUMLOCK;
66 64
67 protocol::KeyEvent key_event; 65 protocol::KeyEvent key_event;
68 key_event.set_usb_keycode(GetUsbKeyCode(pp_key_event)); 66 key_event.set_usb_keycode(GetUsbKeyCode(pp_key_event));
69 key_event.set_pressed(event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN); 67 key_event.set_pressed(event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN);
70 key_event.set_lock_states(lock_states); 68 key_event.set_lock_states(lock_states);
71 69
72 input_stub_->InjectKeyEvent(key_event); 70 if (input_stub_)
71 input_stub_->InjectKeyEvent(key_event);
73 return true; 72 return true;
74 } 73 }
75 74
76 case PP_INPUTEVENT_TYPE_MOUSEDOWN: 75 case PP_INPUTEVENT_TYPE_MOUSEDOWN:
77 case PP_INPUTEVENT_TYPE_MOUSEUP: { 76 case PP_INPUTEVENT_TYPE_MOUSEUP: {
78 if (!has_focus_) 77 if (!has_focus_)
79 return false; 78 return false;
80 79
81 pp::MouseInputEvent pp_mouse_event(event); 80 pp::MouseInputEvent pp_mouse_event(event);
82 protocol::MouseEvent mouse_event; 81 protocol::MouseEvent mouse_event;
(...skipping 16 matching lines...) Expand all
99 mouse_event.set_x(pp_mouse_event.GetPosition().x()); 98 mouse_event.set_x(pp_mouse_event.GetPosition().x());
100 mouse_event.set_y(pp_mouse_event.GetPosition().y()); 99 mouse_event.set_y(pp_mouse_event.GetPosition().y());
101 100
102 // Add relative movement if the mouse is locked. 101 // Add relative movement if the mouse is locked.
103 if (mouse_lock_state_ == MouseLockOn) { 102 if (mouse_lock_state_ == MouseLockOn) {
104 pp::Point delta = pp_mouse_event.GetMovement(); 103 pp::Point delta = pp_mouse_event.GetMovement();
105 mouse_event.set_delta_x(delta.x()); 104 mouse_event.set_delta_x(delta.x());
106 mouse_event.set_delta_y(delta.y()); 105 mouse_event.set_delta_y(delta.y());
107 } 106 }
108 107
109 input_stub_->InjectMouseEvent(mouse_event); 108 if (input_stub_)
109 input_stub_->InjectMouseEvent(mouse_event);
110 } 110 }
111 return true; 111 return true;
112 } 112 }
113 113
114 case PP_INPUTEVENT_TYPE_MOUSEMOVE: 114 case PP_INPUTEVENT_TYPE_MOUSEMOVE:
115 case PP_INPUTEVENT_TYPE_MOUSEENTER: 115 case PP_INPUTEVENT_TYPE_MOUSEENTER:
116 case PP_INPUTEVENT_TYPE_MOUSELEAVE: { 116 case PP_INPUTEVENT_TYPE_MOUSELEAVE: {
117 if (!has_focus_) 117 if (!has_focus_)
118 return false; 118 return false;
119 119
120 pp::MouseInputEvent pp_mouse_event(event); 120 pp::MouseInputEvent pp_mouse_event(event);
121 protocol::MouseEvent mouse_event; 121 protocol::MouseEvent mouse_event;
122 mouse_event.set_x(pp_mouse_event.GetPosition().x()); 122 mouse_event.set_x(pp_mouse_event.GetPosition().x());
123 mouse_event.set_y(pp_mouse_event.GetPosition().y()); 123 mouse_event.set_y(pp_mouse_event.GetPosition().y());
124 124
125 // Add relative movement if the mouse is locked. 125 // Add relative movement if the mouse is locked.
126 if (mouse_lock_state_ == MouseLockOn) { 126 if (mouse_lock_state_ == MouseLockOn) {
127 pp::Point delta = pp_mouse_event.GetMovement(); 127 pp::Point delta = pp_mouse_event.GetMovement();
128 mouse_event.set_delta_x(delta.x()); 128 mouse_event.set_delta_x(delta.x());
129 mouse_event.set_delta_y(delta.y()); 129 mouse_event.set_delta_y(delta.y());
130 } 130 }
131 131
132 input_stub_->InjectMouseEvent(mouse_event); 132 if (input_stub_)
133 input_stub_->InjectMouseEvent(mouse_event);
133 return true; 134 return true;
134 } 135 }
135 136
136 case PP_INPUTEVENT_TYPE_WHEEL: { 137 case PP_INPUTEVENT_TYPE_WHEEL: {
137 if (!has_focus_) 138 if (!has_focus_)
138 return false; 139 return false;
139 140
140 pp::WheelInputEvent pp_wheel_event(event); 141 pp::WheelInputEvent pp_wheel_event(event);
141 142
142 // Don't handle scroll-by-page events, for now. 143 // Don't handle scroll-by-page events, for now.
(...skipping 25 matching lines...) Expand all
168 // that can't inject pixel-based scroll events that the client will 169 // that can't inject pixel-based scroll events that the client will
169 // accumulate them into tick-based scrolling, which gives a better 170 // accumulate them into tick-based scrolling, which gives a better
170 // overall experience than trying to do this host-side. 171 // overall experience than trying to do this host-side.
171 int ticks_x = static_cast<int>(wheel_ticks_x_); 172 int ticks_x = static_cast<int>(wheel_ticks_x_);
172 int ticks_y = static_cast<int>(wheel_ticks_y_); 173 int ticks_y = static_cast<int>(wheel_ticks_y_);
173 wheel_ticks_x_ -= ticks_x; 174 wheel_ticks_x_ -= ticks_x;
174 wheel_ticks_y_ -= ticks_y; 175 wheel_ticks_y_ -= ticks_y;
175 mouse_event.set_wheel_ticks_x(ticks_x); 176 mouse_event.set_wheel_ticks_x(ticks_x);
176 mouse_event.set_wheel_ticks_y(ticks_y); 177 mouse_event.set_wheel_ticks_y(ticks_y);
177 178
178 input_stub_->InjectMouseEvent(mouse_event); 179 if (input_stub_)
180 input_stub_->InjectMouseEvent(mouse_event);
179 } 181 }
180 return true; 182 return true;
181 } 183 }
182 184
183 case PP_INPUTEVENT_TYPE_CHAR: 185 case PP_INPUTEVENT_TYPE_CHAR:
184 // Consume but ignore character input events. 186 // Consume but ignore character input events.
185 return true; 187 return true;
186 188
187 default: { 189 default: {
188 VLOG(0) << "Unhandled input event: " << event.GetType(); 190 VLOG(0) << "Unhandled input event: " << event.GetType();
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 mouse_lock_state_ = MouseLockOff; 300 mouse_lock_state_ = MouseLockOff;
299 UpdateMouseCursor(); 301 UpdateMouseCursor();
300 } 302 }
301 303
302 // Cancel as needed. 304 // Cancel as needed.
303 if (should_cancel) 305 if (should_cancel)
304 CancelMouseLock(); 306 CancelMouseLock();
305 } 307 }
306 308
307 } // namespace remoting 309 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/plugin/pepper_input_handler.h ('k') | remoting/remoting_client.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698