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 "content/renderer/pepper/event_conversion.h" | 5 #include "content/renderer/pepper/event_conversion.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/i18n/char_iterator.h" | 10 #include "base/i18n/char_iterator.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 using blink::WebUChar; | 36 using blink::WebUChar; |
37 | 37 |
38 namespace content { | 38 namespace content { |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 // Verify the modifier flags WebKit uses match the Pepper ones. If these start | 42 // Verify the modifier flags WebKit uses match the Pepper ones. If these start |
43 // not matching, we'll need to write conversion code to preserve the Pepper | 43 // not matching, we'll need to write conversion code to preserve the Pepper |
44 // values (since plugins will be depending on them). | 44 // values (since plugins will be depending on them). |
45 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_SHIFTKEY) == | 45 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_SHIFTKEY) == |
46 static_cast<int>(WebInputEvent::ShiftKey), | 46 static_cast<int>(WebInputEvent::ShiftKey), |
47 ShiftKeyMatches); | 47 ShiftKeyMatches); |
48 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_CONTROLKEY) == | 48 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_CONTROLKEY) == |
49 static_cast<int>(WebInputEvent::ControlKey), | 49 static_cast<int>(WebInputEvent::ControlKey), |
50 ControlKeyMatches); | 50 ControlKeyMatches); |
51 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_ALTKEY) == | 51 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_ALTKEY) == |
52 static_cast<int>(WebInputEvent::AltKey), | 52 static_cast<int>(WebInputEvent::AltKey), |
53 AltKeyMatches); | 53 AltKeyMatches); |
54 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_METAKEY) == | 54 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_METAKEY) == |
55 static_cast<int>(WebInputEvent::MetaKey), | 55 static_cast<int>(WebInputEvent::MetaKey), |
56 MetaKeyMatches); | 56 MetaKeyMatches); |
57 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISKEYPAD) == | 57 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISKEYPAD) == |
58 static_cast<int>(WebInputEvent::IsKeyPad), | 58 static_cast<int>(WebInputEvent::IsKeyPad), |
59 KeyPadMatches); | 59 KeyPadMatches); |
60 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT) == | 60 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT) == |
61 static_cast<int>(WebInputEvent::IsAutoRepeat), | 61 static_cast<int>(WebInputEvent::IsAutoRepeat), |
62 AutoRepeatMatches); | 62 AutoRepeatMatches); |
63 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN) == | 63 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN) == |
64 static_cast<int>(WebInputEvent::LeftButtonDown), | 64 static_cast<int>(WebInputEvent::LeftButtonDown), |
65 LeftButtonMatches); | 65 LeftButtonMatches); |
66 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN) == | 66 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN) == |
67 static_cast<int>(WebInputEvent::MiddleButtonDown), | 67 static_cast<int>(WebInputEvent::MiddleButtonDown), |
68 MiddleButtonMatches); | 68 MiddleButtonMatches); |
69 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN) == | 69 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN) == |
70 static_cast<int>(WebInputEvent::RightButtonDown), | 70 static_cast<int>(WebInputEvent::RightButtonDown), |
71 RightButtonMatches); | 71 RightButtonMatches); |
72 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY) == | 72 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY) == |
73 static_cast<int>(WebInputEvent::CapsLockOn), | 73 static_cast<int>(WebInputEvent::CapsLockOn), |
74 CapsLockMatches); | 74 CapsLockMatches); |
75 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_NUMLOCKKEY) == | 75 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_NUMLOCKKEY) == |
76 static_cast<int>(WebInputEvent::NumLockOn), | 76 static_cast<int>(WebInputEvent::NumLockOn), |
77 NumLockMatches); | 77 NumLockMatches); |
78 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISLEFT) == | 78 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISLEFT) == |
79 static_cast<int>(WebInputEvent::IsLeft), | 79 static_cast<int>(WebInputEvent::IsLeft), |
80 LeftMatches); | 80 LeftMatches); |
81 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISRIGHT) == | 81 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISRIGHT) == |
82 static_cast<int>(WebInputEvent::IsRight), | 82 static_cast<int>(WebInputEvent::IsRight), |
83 RightMatches); | 83 RightMatches); |
84 | 84 |
85 PP_InputEvent_Type ConvertEventTypes(WebInputEvent::Type wetype) { | 85 PP_InputEvent_Type ConvertEventTypes(WebInputEvent::Type wetype) { |
86 switch (wetype) { | 86 switch (wetype) { |
87 case WebInputEvent::MouseDown: | 87 case WebInputEvent::MouseDown: |
88 return PP_INPUTEVENT_TYPE_MOUSEDOWN; | 88 return PP_INPUTEVENT_TYPE_MOUSEDOWN; |
89 case WebInputEvent::MouseUp: | 89 case WebInputEvent::MouseUp: |
90 return PP_INPUTEVENT_TYPE_MOUSEUP; | 90 return PP_INPUTEVENT_TYPE_MOUSEUP; |
91 case WebInputEvent::MouseMove: | 91 case WebInputEvent::MouseMove: |
92 return PP_INPUTEVENT_TYPE_MOUSEMOVE; | 92 return PP_INPUTEVENT_TYPE_MOUSEMOVE; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 base::WriteUnicodeCharacter(iter.get(), &result.character_text); | 165 base::WriteUnicodeCharacter(iter.get(), &result.character_text); |
166 | 166 |
167 result_events->push_back(result); | 167 result_events->push_back(result); |
168 iter.Advance(); | 168 iter.Advance(); |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 void AppendMouseEvent(const WebInputEvent& event, | 172 void AppendMouseEvent(const WebInputEvent& event, |
173 std::vector<InputEventData>* result_events) { | 173 std::vector<InputEventData>* result_events) { |
174 COMPILE_ASSERT(static_cast<int>(WebMouseEvent::ButtonNone) == | 174 COMPILE_ASSERT(static_cast<int>(WebMouseEvent::ButtonNone) == |
175 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_NONE), | 175 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_NONE), |
176 MouseNone); | 176 MouseNone); |
177 COMPILE_ASSERT(static_cast<int>(WebMouseEvent::ButtonLeft) == | 177 COMPILE_ASSERT(static_cast<int>(WebMouseEvent::ButtonLeft) == |
178 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_LEFT), | 178 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_LEFT), |
179 MouseLeft); | 179 MouseLeft); |
180 COMPILE_ASSERT(static_cast<int>(WebMouseEvent::ButtonRight) == | 180 COMPILE_ASSERT(static_cast<int>(WebMouseEvent::ButtonRight) == |
181 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_RIGHT), | 181 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_RIGHT), |
182 MouseRight); | 182 MouseRight); |
183 COMPILE_ASSERT(static_cast<int>(WebMouseEvent::ButtonMiddle) == | 183 COMPILE_ASSERT(static_cast<int>(WebMouseEvent::ButtonMiddle) == |
184 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_MIDDLE), | 184 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_MIDDLE), |
185 MouseMiddle); | 185 MouseMiddle); |
186 | 186 |
187 const WebMouseEvent& mouse_event = | 187 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); |
188 static_cast<const WebMouseEvent&>(event); | |
189 InputEventData result = GetEventWithCommonFieldsAndType(event); | 188 InputEventData result = GetEventWithCommonFieldsAndType(event); |
190 result.event_modifiers = mouse_event.modifiers; | 189 result.event_modifiers = mouse_event.modifiers; |
191 if (mouse_event.type == WebInputEvent::MouseDown || | 190 if (mouse_event.type == WebInputEvent::MouseDown || |
192 mouse_event.type == WebInputEvent::MouseMove || | 191 mouse_event.type == WebInputEvent::MouseMove || |
193 mouse_event.type == WebInputEvent::MouseUp) { | 192 mouse_event.type == WebInputEvent::MouseUp) { |
194 result.mouse_button = | 193 result.mouse_button = |
195 static_cast<PP_InputEvent_MouseButton>(mouse_event.button); | 194 static_cast<PP_InputEvent_MouseButton>(mouse_event.button); |
196 } | 195 } |
197 result.mouse_position.x = mouse_event.x; | 196 result.mouse_position.x = mouse_event.x; |
198 result.mouse_position.y = mouse_event.y; | 197 result.mouse_position.y = mouse_event.y; |
(...skipping 10 matching lines...) Expand all Loading... | |
209 InputEventData result = GetEventWithCommonFieldsAndType(event); | 208 InputEventData result = GetEventWithCommonFieldsAndType(event); |
210 result.event_modifiers = mouse_wheel_event.modifiers; | 209 result.event_modifiers = mouse_wheel_event.modifiers; |
211 result.wheel_delta.x = mouse_wheel_event.deltaX; | 210 result.wheel_delta.x = mouse_wheel_event.deltaX; |
212 result.wheel_delta.y = mouse_wheel_event.deltaY; | 211 result.wheel_delta.y = mouse_wheel_event.deltaY; |
213 result.wheel_ticks.x = mouse_wheel_event.wheelTicksX; | 212 result.wheel_ticks.x = mouse_wheel_event.wheelTicksX; |
214 result.wheel_ticks.y = mouse_wheel_event.wheelTicksY; | 213 result.wheel_ticks.y = mouse_wheel_event.wheelTicksY; |
215 result.wheel_scroll_by_page = !!mouse_wheel_event.scrollByPage; | 214 result.wheel_scroll_by_page = !!mouse_wheel_event.scrollByPage; |
216 result_events->push_back(result); | 215 result_events->push_back(result); |
217 } | 216 } |
218 | 217 |
219 void SetPPTouchPoints(const WebTouchPoint* touches, uint32_t touches_length, | 218 void SetPPTouchPoints(const WebTouchPoint* touches, |
219 uint32_t touches_length, | |
220 std::vector<PP_TouchPoint>* result) { | 220 std::vector<PP_TouchPoint>* result) { |
221 for (uint32_t i = 0; i < touches_length; i++) { | 221 for (uint32_t i = 0; i < touches_length; i++) { |
222 const WebTouchPoint& touch_point = touches[i]; | 222 const WebTouchPoint& touch_point = touches[i]; |
223 PP_TouchPoint pp_pt; | 223 PP_TouchPoint pp_pt; |
224 pp_pt.id = touch_point.id; | 224 pp_pt.id = touch_point.id; |
225 pp_pt.position.x = touch_point.position.x; | 225 pp_pt.position.x = touch_point.position.x; |
226 pp_pt.position.y = touch_point.position.y; | 226 pp_pt.position.y = touch_point.position.y; |
227 pp_pt.radius.x = touch_point.radiusX; | 227 pp_pt.radius.x = touch_point.radiusX; |
228 pp_pt.radius.y = touch_point.radiusY; | 228 pp_pt.radius.y = touch_point.radiusY; |
229 pp_pt.rotation_angle = touch_point.rotationAngle; | 229 pp_pt.rotation_angle = touch_point.rotationAngle; |
230 pp_pt.pressure = touch_point.force; | 230 pp_pt.pressure = touch_point.force; |
231 result->push_back(pp_pt); | 231 result->push_back(pp_pt); |
232 } | 232 } |
233 } | 233 } |
234 | 234 |
235 void AppendTouchEvent(const WebInputEvent& event, | 235 void AppendTouchEvent(const WebInputEvent& event, |
236 std::vector<InputEventData>* result_events) { | 236 std::vector<InputEventData>* result_events) { |
237 const WebTouchEvent& touch_event = | 237 const WebTouchEvent& touch_event = |
238 reinterpret_cast<const WebTouchEvent&>(event); | 238 reinterpret_cast<const WebTouchEvent&>(event); |
239 | 239 |
240 InputEventData result = GetEventWithCommonFieldsAndType(event); | 240 InputEventData result = GetEventWithCommonFieldsAndType(event); |
241 SetPPTouchPoints(touch_event.touches, touch_event.touchesLength, | 241 SetPPTouchPoints( |
242 &result.touches); | 242 touch_event.touches, touch_event.touchesLength, &result.touches); |
243 SetPPTouchPoints(touch_event.changedTouches, touch_event.changedTouchesLength, | 243 SetPPTouchPoints(touch_event.changedTouches, |
244 touch_event.changedTouchesLength, | |
244 &result.changed_touches); | 245 &result.changed_touches); |
245 SetPPTouchPoints(touch_event.targetTouches, touch_event.targetTouchesLength, | 246 SetPPTouchPoints(touch_event.targetTouches, |
247 touch_event.targetTouchesLength, | |
246 &result.target_touches); | 248 &result.target_touches); |
247 | 249 |
248 result_events->push_back(result); | 250 result_events->push_back(result); |
249 } | 251 } |
250 | 252 |
251 // Structure used to map touch point id's to touch states. Since the pepper | 253 // Structure used to map touch point id's to touch states. Since the pepper |
252 // touch event structure does not have states for individual touch points and | 254 // touch event structure does not have states for individual touch points and |
253 // instead relies on the event type in combination with the set of touch lists, | 255 // instead relies on the event type in combination with the set of touch lists, |
254 // we have to set the state for the changed touches to be the same as the event | 256 // we have to set the state for the changed touches to be the same as the event |
255 // type and all others to be 'stationary.' | 257 // type and all others to be 'stationary.' |
256 typedef std::map<uint32_t, WebTouchPoint::State> TouchStateMap; | 258 typedef std::map<uint32_t, WebTouchPoint::State> TouchStateMap; |
257 | 259 |
258 void SetWebTouchPoints(const std::vector<PP_TouchPoint>& pp_touches, | 260 void SetWebTouchPoints(const std::vector<PP_TouchPoint>& pp_touches, |
259 const TouchStateMap& states_map, | 261 const TouchStateMap& states_map, |
260 WebTouchPoint* web_touches, | 262 WebTouchPoint* web_touches, |
261 uint32_t* web_touches_length) { | 263 uint32_t* web_touches_length) { |
262 | 264 |
263 for (uint32_t i = 0; i < pp_touches.size() && | 265 for (uint32_t i = 0; |
264 i < WebTouchEvent::touchesLengthCap; i++) { | 266 i < pp_touches.size() && i < WebTouchEvent::touchesLengthCap; |
267 i++) { | |
265 WebTouchPoint pt; | 268 WebTouchPoint pt; |
266 const PP_TouchPoint& pp_pt = pp_touches[i]; | 269 const PP_TouchPoint& pp_pt = pp_touches[i]; |
267 pt.id = pp_pt.id; | 270 pt.id = pp_pt.id; |
268 | 271 |
269 if (states_map.find(pt.id) == states_map.end()) | 272 if (states_map.find(pt.id) == states_map.end()) |
270 pt.state = WebTouchPoint::StateStationary; | 273 pt.state = WebTouchPoint::StateStationary; |
271 else | 274 else |
272 pt.state = states_map.find(pt.id)->second; | 275 pt.state = states_map.find(pt.id)->second; |
273 | 276 |
274 pt.position.x = pp_pt.position.x; | 277 pt.position.x = pp_pt.position.x; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 default: | 311 default: |
309 NOTREACHED(); | 312 NOTREACHED(); |
310 } | 313 } |
311 | 314 |
312 TouchStateMap states_map; | 315 TouchStateMap states_map; |
313 for (uint32_t i = 0; i < event.changed_touches.size(); i++) | 316 for (uint32_t i = 0; i < event.changed_touches.size(); i++) |
314 states_map[event.changed_touches[i].id] = state; | 317 states_map[event.changed_touches[i].id] = state; |
315 | 318 |
316 web_event->timeStampSeconds = PPTimeTicksToEventTime(event.event_time_stamp); | 319 web_event->timeStampSeconds = PPTimeTicksToEventTime(event.event_time_stamp); |
317 | 320 |
318 SetWebTouchPoints(event.changed_touches, states_map, | 321 SetWebTouchPoints(event.changed_touches, |
322 states_map, | |
319 web_event->changedTouches, | 323 web_event->changedTouches, |
320 &web_event->changedTouchesLength); | 324 &web_event->changedTouchesLength); |
321 | 325 |
322 SetWebTouchPoints(event.touches, states_map, web_event->touches, | 326 SetWebTouchPoints( |
323 &web_event->touchesLength); | 327 event.touches, states_map, web_event->touches, &web_event->touchesLength); |
324 | 328 |
325 SetWebTouchPoints(event.target_touches, states_map, web_event->targetTouches, | 329 SetWebTouchPoints(event.target_touches, |
330 states_map, | |
331 web_event->targetTouches, | |
326 &web_event->targetTouchesLength); | 332 &web_event->targetTouchesLength); |
327 | 333 |
328 if (web_event->type == WebInputEvent::TouchEnd || | 334 if (web_event->type == WebInputEvent::TouchEnd || |
329 web_event->type == WebInputEvent::TouchCancel) { | 335 web_event->type == WebInputEvent::TouchCancel) { |
330 SetWebTouchPoints(event.changed_touches, states_map, | 336 SetWebTouchPoints(event.changed_touches, |
331 web_event->touches, &web_event->touchesLength); | 337 states_map, |
332 SetWebTouchPoints(event.changed_touches, states_map, | 338 web_event->touches, |
339 &web_event->touchesLength); | |
340 SetWebTouchPoints(event.changed_touches, | |
341 states_map, | |
333 web_event->targetTouches, | 342 web_event->targetTouches, |
334 &web_event->targetTouchesLength); | 343 &web_event->targetTouchesLength); |
335 } | 344 } |
336 | 345 |
337 return web_event; | 346 return web_event; |
338 } | 347 } |
339 | 348 |
340 WebKeyboardEvent* BuildKeyEvent(const InputEventData& event) { | 349 WebKeyboardEvent* BuildKeyEvent(const InputEventData& event) { |
341 WebKeyboardEvent* key_event = new WebKeyboardEvent(); | 350 WebKeyboardEvent* key_event = new WebKeyboardEvent(); |
342 switch (event.event_type) { | 351 switch (event.event_type) { |
(...skipping 22 matching lines...) Expand all Loading... | |
365 key_event->timeStampSeconds = PPTimeTicksToEventTime(event.event_time_stamp); | 374 key_event->timeStampSeconds = PPTimeTicksToEventTime(event.event_time_stamp); |
366 key_event->modifiers = event.event_modifiers; | 375 key_event->modifiers = event.event_modifiers; |
367 | 376 |
368 // Make sure to not read beyond the buffer in case some bad code doesn't | 377 // Make sure to not read beyond the buffer in case some bad code doesn't |
369 // NULL-terminate it (this is called from plugins). | 378 // NULL-terminate it (this is called from plugins). |
370 size_t text_length_cap = WebKeyboardEvent::textLengthCap; | 379 size_t text_length_cap = WebKeyboardEvent::textLengthCap; |
371 base::string16 text16 = base::UTF8ToUTF16(event.character_text); | 380 base::string16 text16 = base::UTF8ToUTF16(event.character_text); |
372 | 381 |
373 memset(key_event->text, 0, text_length_cap); | 382 memset(key_event->text, 0, text_length_cap); |
374 memset(key_event->unmodifiedText, 0, text_length_cap); | 383 memset(key_event->unmodifiedText, 0, text_length_cap); |
375 for (size_t i = 0; | 384 for (size_t i = 0; i < std::min(text_length_cap, text16.size()); ++i) |
376 i < std::min(text_length_cap, text16.size()); | |
377 ++i) | |
378 key_event->text[i] = text16[i]; | 385 key_event->text[i] = text16[i]; |
379 return key_event; | 386 return key_event; |
380 } | 387 } |
381 | 388 |
382 WebMouseEvent* BuildMouseEvent(const InputEventData& event) { | 389 WebMouseEvent* BuildMouseEvent(const InputEventData& event) { |
383 WebMouseEvent* mouse_event = new WebMouseEvent(); | 390 WebMouseEvent* mouse_event = new WebMouseEvent(); |
384 switch (event.event_type) { | 391 switch (event.event_type) { |
385 case PP_INPUTEVENT_TYPE_MOUSEDOWN: | 392 case PP_INPUTEVENT_TYPE_MOUSEDOWN: |
386 mouse_event->type = WebInputEvent::MouseDown; | 393 mouse_event->type = WebInputEvent::MouseDown; |
387 break; | 394 break; |
(...skipping 11 matching lines...) Expand all Loading... | |
399 break; | 406 break; |
400 case PP_INPUTEVENT_TYPE_CONTEXTMENU: | 407 case PP_INPUTEVENT_TYPE_CONTEXTMENU: |
401 mouse_event->type = WebInputEvent::ContextMenu; | 408 mouse_event->type = WebInputEvent::ContextMenu; |
402 break; | 409 break; |
403 default: | 410 default: |
404 NOTREACHED(); | 411 NOTREACHED(); |
405 } | 412 } |
406 mouse_event->timeStampSeconds = | 413 mouse_event->timeStampSeconds = |
407 PPTimeTicksToEventTime(event.event_time_stamp); | 414 PPTimeTicksToEventTime(event.event_time_stamp); |
408 mouse_event->modifiers = event.event_modifiers; | 415 mouse_event->modifiers = event.event_modifiers; |
409 mouse_event->button = | 416 mouse_event->button = static_cast<WebMouseEvent::Button>(event.mouse_button); |
410 static_cast<WebMouseEvent::Button>(event.mouse_button); | |
411 if (mouse_event->type == WebInputEvent::MouseMove) { | 417 if (mouse_event->type == WebInputEvent::MouseMove) { |
412 if (mouse_event->modifiers & WebInputEvent::LeftButtonDown) | 418 if (mouse_event->modifiers & WebInputEvent::LeftButtonDown) |
413 mouse_event->button = WebMouseEvent::ButtonLeft; | 419 mouse_event->button = WebMouseEvent::ButtonLeft; |
414 else if (mouse_event->modifiers & WebInputEvent::MiddleButtonDown) | 420 else if (mouse_event->modifiers & WebInputEvent::MiddleButtonDown) |
415 mouse_event->button = WebMouseEvent::ButtonMiddle; | 421 mouse_event->button = WebMouseEvent::ButtonMiddle; |
416 else if (mouse_event->modifiers & WebInputEvent::RightButtonDown) | 422 else if (mouse_event->modifiers & WebInputEvent::RightButtonDown) |
417 mouse_event->button = WebMouseEvent::ButtonRight; | 423 mouse_event->button = WebMouseEvent::ButtonRight; |
418 } | 424 } |
419 mouse_event->x = event.mouse_position.x; | 425 mouse_event->x = event.mouse_position.x; |
420 mouse_event->y = event.mouse_position.y; | 426 mouse_event->y = event.mouse_position.y; |
(...skipping 11 matching lines...) Expand all Loading... | |
432 mouse_wheel_event->modifiers = event.event_modifiers; | 438 mouse_wheel_event->modifiers = event.event_modifiers; |
433 mouse_wheel_event->deltaX = event.wheel_delta.x; | 439 mouse_wheel_event->deltaX = event.wheel_delta.x; |
434 mouse_wheel_event->deltaY = event.wheel_delta.y; | 440 mouse_wheel_event->deltaY = event.wheel_delta.y; |
435 mouse_wheel_event->wheelTicksX = event.wheel_ticks.x; | 441 mouse_wheel_event->wheelTicksX = event.wheel_ticks.x; |
436 mouse_wheel_event->wheelTicksY = event.wheel_ticks.y; | 442 mouse_wheel_event->wheelTicksY = event.wheel_ticks.y; |
437 mouse_wheel_event->scrollByPage = event.wheel_scroll_by_page; | 443 mouse_wheel_event->scrollByPage = event.wheel_scroll_by_page; |
438 return mouse_wheel_event; | 444 return mouse_wheel_event; |
439 } | 445 } |
440 | 446 |
441 #if !defined(OS_WIN) | 447 #if !defined(OS_WIN) |
442 #define VK_RETURN 0x0D | 448 #define VK_RETURN 0x0D |
443 | 449 |
444 #define VK_PRIOR 0x21 | 450 #define VK_PRIOR 0x21 |
445 #define VK_NEXT 0x22 | 451 #define VK_NEXT 0x22 |
446 #define VK_END 0x23 | 452 #define VK_END 0x23 |
447 #define VK_HOME 0x24 | 453 #define VK_HOME 0x24 |
448 #define VK_LEFT 0x25 | 454 #define VK_LEFT 0x25 |
449 #define VK_UP 0x26 | 455 #define VK_UP 0x26 |
450 #define VK_RIGHT 0x27 | 456 #define VK_RIGHT 0x27 |
451 #define VK_DOWN 0x28 | 457 #define VK_DOWN 0x28 |
452 #define VK_SNAPSHOT 0x2C | 458 #define VK_SNAPSHOT 0x2C |
453 #define VK_INSERT 0x2D | 459 #define VK_INSERT 0x2D |
454 #define VK_DELETE 0x2E | 460 #define VK_DELETE 0x2E |
455 | 461 |
456 #define VK_APPS 0x5D | 462 #define VK_APPS 0x5D |
457 | 463 |
458 #define VK_F1 0x70 | 464 #define VK_F1 0x70 |
bbudge
2014/04/07 17:02:17
Aligning defines is now impossible - I'm OK with t
| |
459 #endif | 465 #endif |
460 | 466 |
461 // Convert a character string to a Windows virtual key code. Adapted from | 467 // Convert a character string to a Windows virtual key code. Adapted from |
462 // src/content/shell/renderer/test_runner/event_sender.cc. This | 468 // src/content/shell/renderer/test_runner/event_sender.cc. This |
463 // is used by CreateSimulatedWebInputEvents to convert keyboard events. | 469 // is used by CreateSimulatedWebInputEvents to convert keyboard events. |
464 void GetKeyCode(const std::string& char_text, | 470 void GetKeyCode(const std::string& char_text, |
465 WebUChar* code, | 471 WebUChar* code, |
466 WebUChar* text, | 472 WebUChar* text, |
467 bool* needs_shift_modifier, | 473 bool* needs_shift_modifier, |
468 bool* generate_char) { | 474 bool* generate_char) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 } | 514 } |
509 } | 515 } |
510 if (!vk_code) { | 516 if (!vk_code) { |
511 WebString web_char_text = | 517 WebString web_char_text = |
512 WebString::fromUTF8(char_text.data(), char_text.size()); | 518 WebString::fromUTF8(char_text.data(), char_text.size()); |
513 DCHECK_EQ(web_char_text.length(), 1U); | 519 DCHECK_EQ(web_char_text.length(), 1U); |
514 vk_text = vk_code = web_char_text.at(0); | 520 vk_text = vk_code = web_char_text.at(0); |
515 *needs_shift_modifier = | 521 *needs_shift_modifier = |
516 (vk_code & 0xFF) >= 'A' && (vk_code & 0xFF) <= 'Z'; | 522 (vk_code & 0xFF) >= 'A' && (vk_code & 0xFF) <= 'Z'; |
517 if ((vk_code & 0xFF) >= 'a' && (vk_code & 0xFF) <= 'z') | 523 if ((vk_code & 0xFF) >= 'a' && (vk_code & 0xFF) <= 'z') |
518 vk_code -= 'a' - 'A'; | 524 vk_code -= 'a' - 'A'; |
519 *generate_char = true; | 525 *generate_char = true; |
520 } | 526 } |
521 } | 527 } |
522 | 528 |
523 *code = vk_code; | 529 *code = vk_code; |
524 *text = vk_text; | 530 *text = vk_text; |
525 } | 531 } |
526 | 532 |
527 } // namespace | 533 } // namespace |
528 | 534 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
632 static_cast<WebMouseWheelEvent*>(original_event.get()); | 638 static_cast<WebMouseWheelEvent*>(original_event.get()); |
633 web_mouse_wheel_event->x = plugin_x; | 639 web_mouse_wheel_event->x = plugin_x; |
634 web_mouse_wheel_event->y = plugin_y; | 640 web_mouse_wheel_event->y = plugin_y; |
635 events.push_back(original_event); | 641 events.push_back(original_event); |
636 break; | 642 break; |
637 } | 643 } |
638 | 644 |
639 case PP_INPUTEVENT_TYPE_RAWKEYDOWN: | 645 case PP_INPUTEVENT_TYPE_RAWKEYDOWN: |
640 case PP_INPUTEVENT_TYPE_KEYDOWN: | 646 case PP_INPUTEVENT_TYPE_KEYDOWN: |
641 case PP_INPUTEVENT_TYPE_KEYUP: { | 647 case PP_INPUTEVENT_TYPE_KEYUP: { |
642 // Windows key down events should always be "raw" to avoid an ASSERT. | 648 // Windows key down events should always be "raw" to avoid an ASSERT. |
bbudge
2014/04/07 17:02:17
Surprising that it "knows" this pertains to the #i
| |
643 #if defined(OS_WIN) | 649 #if defined(OS_WIN) |
644 WebKeyboardEvent* web_keyboard_event = | 650 WebKeyboardEvent* web_keyboard_event = |
645 static_cast<WebKeyboardEvent*>(original_event.get()); | 651 static_cast<WebKeyboardEvent*>(original_event.get()); |
646 if (web_keyboard_event->type == WebInputEvent::KeyDown) | 652 if (web_keyboard_event->type == WebInputEvent::KeyDown) |
647 web_keyboard_event->type = WebInputEvent::RawKeyDown; | 653 web_keyboard_event->type = WebInputEvent::RawKeyDown; |
648 #endif | 654 #endif |
649 events.push_back(original_event); | 655 events.push_back(original_event); |
650 break; | 656 break; |
651 } | 657 } |
652 | 658 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
723 case WebInputEvent::TouchStart: | 729 case WebInputEvent::TouchStart: |
724 return PP_INPUTEVENT_CLASS_TOUCH; | 730 return PP_INPUTEVENT_CLASS_TOUCH; |
725 case WebInputEvent::Undefined: | 731 case WebInputEvent::Undefined: |
726 default: | 732 default: |
727 NOTREACHED(); | 733 NOTREACHED(); |
728 return PP_InputEvent_Class(0); | 734 return PP_InputEvent_Class(0); |
729 } | 735 } |
730 } | 736 } |
731 | 737 |
732 } // namespace content | 738 } // namespace content |
OLD | NEW |