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
3 // found in the LICENSE file.
5 #include "ppapi/c/pp_errors.h"
6 #include "ppapi/thunk/enter.h"
7 #include "ppapi/thunk/ppb_input_event_api.h"
8 #include "ppapi/thunk/ppb_instance_api.h"
9 #include "ppapi/thunk/resource_creation_api.h"
10 #include "ppapi/thunk/thunk.h"
17 typedef EnterResource
<PPB_InputEvent_API
> EnterInputEvent
;
19 // InputEvent ------------------------------------------------------------------
21 int32_t RequestInputEvents(PP_Instance instance
, uint32_t event_classes
) {
22 VLOG(4) << "PPB_InputEvent::RequestInputEvents()";
23 EnterInstance
enter(instance
);
25 return enter
.retval();
26 return enter
.functions()->RequestInputEvents(instance
, event_classes
);
29 int32_t RequestFilteringInputEvents(PP_Instance instance
,
30 uint32_t event_classes
) {
31 VLOG(4) << "PPB_InputEvent::RequestFilteringInputEvents()";
32 EnterInstance
enter(instance
);
34 return enter
.retval();
35 return enter
.functions()->RequestFilteringInputEvents(instance
,
39 void ClearInputEventRequest(PP_Instance instance
,
40 uint32_t event_classes
) {
41 VLOG(4) << "PPB_InputEvent::ClearInputEventRequest()";
42 EnterInstance
enter(instance
);
43 if (enter
.succeeded())
44 enter
.functions()->ClearInputEventRequest(instance
, event_classes
);
47 PP_Bool
IsInputEvent(PP_Resource resource
) {
48 VLOG(4) << "PPB_InputEvent::IsInputEvent()";
49 EnterInputEvent
enter(resource
, false);
50 return enter
.succeeded() ? PP_TRUE
: PP_FALSE
;
53 PP_InputEvent_Type
GetType(PP_Resource event
) {
54 VLOG(4) << "PPB_InputEvent::GetType()";
55 EnterInputEvent
enter(event
, true);
57 return PP_INPUTEVENT_TYPE_UNDEFINED
;
58 return enter
.object()->GetType();
61 PP_TimeTicks
GetTimeStamp(PP_Resource event
) {
62 VLOG(4) << "PPB_InputEvent::GetTimeStamp()";
63 EnterInputEvent
enter(event
, true);
66 return enter
.object()->GetTimeStamp();
69 uint32_t GetModifiers(PP_Resource event
) {
70 VLOG(4) << "PPB_InputEvent::GetModifiers()";
71 EnterInputEvent
enter(event
, true);
74 return enter
.object()->GetModifiers();
77 const PPB_InputEvent g_ppb_input_event_thunk
= {
79 &RequestFilteringInputEvents
,
80 &ClearInputEventRequest
,
87 // Mouse -----------------------------------------------------------------------
89 PP_Resource
CreateMouseInputEvent1_0(PP_Instance instance
,
90 PP_InputEvent_Type type
,
91 PP_TimeTicks time_stamp
,
93 PP_InputEvent_MouseButton mouse_button
,
94 const PP_Point
* mouse_position
,
95 int32_t click_count
) {
96 VLOG(4) << "PPB_MouseInputEvent::Create()";
97 EnterResourceCreation
enter(instance
);
101 PP_Point mouse_movement
= PP_MakePoint(0, 0);
102 return enter
.functions()->CreateMouseInputEvent(instance
, type
, time_stamp
,
103 modifiers
, mouse_button
,
104 mouse_position
, click_count
,
108 PP_Resource
CreateMouseInputEvent1_1(PP_Instance instance
,
109 PP_InputEvent_Type type
,
110 PP_TimeTicks time_stamp
,
112 PP_InputEvent_MouseButton mouse_button
,
113 const PP_Point
* mouse_position
,
115 const PP_Point
* mouse_movement
) {
116 VLOG(4) << "PPB_MouseInputEvent::Create()";
117 EnterResourceCreation
enter(instance
);
120 return enter
.functions()->CreateMouseInputEvent(instance
, type
, time_stamp
,
121 modifiers
, mouse_button
,
122 mouse_position
, click_count
,
126 PP_Bool
IsMouseInputEvent(PP_Resource resource
) {
127 VLOG(4) << "PPB_MouseInputEvent::IsMouseInputEvent()";
128 if (!IsInputEvent(resource
))
129 return PP_FALSE
; // Prevent warning log in GetType.
130 PP_InputEvent_Type type
= GetType(resource
);
131 return PP_FromBool(type
== PP_INPUTEVENT_TYPE_MOUSEDOWN
||
132 type
== PP_INPUTEVENT_TYPE_MOUSEUP
||
133 type
== PP_INPUTEVENT_TYPE_MOUSEMOVE
||
134 type
== PP_INPUTEVENT_TYPE_MOUSEENTER
||
135 type
== PP_INPUTEVENT_TYPE_MOUSELEAVE
||
136 type
== PP_INPUTEVENT_TYPE_CONTEXTMENU
);
139 PP_InputEvent_MouseButton
GetMouseButton(PP_Resource mouse_event
) {
140 VLOG(4) << "PPB_MouseInputEvent::GetButton()";
141 EnterInputEvent
enter(mouse_event
, true);
143 return PP_INPUTEVENT_MOUSEBUTTON_NONE
;
144 return enter
.object()->GetMouseButton();
147 PP_Point
GetMousePosition(PP_Resource mouse_event
) {
148 VLOG(4) << "PPB_MouseInputEvent::GetPosition()";
149 EnterInputEvent
enter(mouse_event
, true);
151 return PP_MakePoint(0, 0);
152 return enter
.object()->GetMousePosition();
155 int32_t GetMouseClickCount(PP_Resource mouse_event
) {
156 VLOG(4) << "PPB_MouseInputEvent::GetClickCount()";
157 EnterInputEvent
enter(mouse_event
, true);
160 return enter
.object()->GetMouseClickCount();
163 PP_Point
GetMouseMovement(PP_Resource mouse_event
) {
164 VLOG(4) << "PPB_MouseInputEvent::GetMovement()";
165 EnterInputEvent
enter(mouse_event
, true);
167 return PP_MakePoint(0, 0);
168 return enter
.object()->GetMouseMovement();
171 const PPB_MouseInputEvent_1_0 g_ppb_mouse_input_event_1_0_thunk
= {
172 &CreateMouseInputEvent1_0
,
179 const PPB_MouseInputEvent g_ppb_mouse_input_event_1_1_thunk
= {
180 &CreateMouseInputEvent1_1
,
188 // Wheel -----------------------------------------------------------------------
190 PP_Resource
CreateWheelInputEvent(PP_Instance instance
,
191 PP_TimeTicks time_stamp
,
193 const PP_FloatPoint
* wheel_delta
,
194 const PP_FloatPoint
* wheel_ticks
,
195 PP_Bool scroll_by_page
) {
196 VLOG(4) << "PPB_WheelInputEvent::Create()";
197 EnterResourceCreation
enter(instance
);
200 return enter
.functions()->CreateWheelInputEvent(instance
, time_stamp
,
201 modifiers
, wheel_delta
,
202 wheel_ticks
, scroll_by_page
);
205 PP_Bool
IsWheelInputEvent(PP_Resource resource
) {
206 VLOG(4) << "PPB_WheelInputEvent::IsWheelInputEvent()";
207 if (!IsInputEvent(resource
))
208 return PP_FALSE
; // Prevent warning log in GetType.
209 PP_InputEvent_Type type
= GetType(resource
);
210 return PP_FromBool(type
== PP_INPUTEVENT_TYPE_WHEEL
);
213 PP_FloatPoint
GetWheelDelta(PP_Resource wheel_event
) {
214 VLOG(4) << "PPB_WheelInputEvent::GetDelta()";
215 EnterInputEvent
enter(wheel_event
, true);
217 return PP_MakeFloatPoint(0.0f
, 0.0f
);
218 return enter
.object()->GetWheelDelta();
221 PP_FloatPoint
GetWheelTicks(PP_Resource wheel_event
) {
222 VLOG(4) << "PPB_WheelInputEvent::GetTicks()";
223 EnterInputEvent
enter(wheel_event
, true);
225 return PP_MakeFloatPoint(0.0f
, 0.0f
);
226 return enter
.object()->GetWheelTicks();
229 PP_Bool
GetWheelScrollByPage(PP_Resource wheel_event
) {
230 VLOG(4) << "PPB_WheelInputEvent::GetScrollByPage()";
231 EnterInputEvent
enter(wheel_event
, true);
234 return enter
.object()->GetWheelScrollByPage();
237 const PPB_WheelInputEvent g_ppb_wheel_input_event_thunk
= {
238 &CreateWheelInputEvent
,
242 &GetWheelScrollByPage
245 // Keyboard --------------------------------------------------------------------
247 PP_Resource
CreateKeyboardInputEvent(PP_Instance instance
,
248 PP_InputEvent_Type type
,
249 PP_TimeTicks time_stamp
,
252 struct PP_Var character_text
) {
253 VLOG(4) << "PPB_KeyboardInputEvent::Create()";
254 EnterResourceCreation
enter(instance
);
257 return enter
.functions()->CreateKeyboardInputEvent(instance
, type
, time_stamp
,
262 PP_Bool
IsKeyboardInputEvent(PP_Resource resource
) {
263 VLOG(4) << "PPB_KeyboardInputEvent::IsKeyboardInputEvent()";
264 if (!IsInputEvent(resource
))
265 return PP_FALSE
; // Prevent warning log in GetType.
266 PP_InputEvent_Type type
= GetType(resource
);
267 return PP_FromBool(type
== PP_INPUTEVENT_TYPE_KEYDOWN
||
268 type
== PP_INPUTEVENT_TYPE_KEYUP
||
269 type
== PP_INPUTEVENT_TYPE_RAWKEYDOWN
||
270 type
== PP_INPUTEVENT_TYPE_CHAR
);
273 uint32_t GetKeyCode(PP_Resource key_event
) {
274 VLOG(4) << "PPB_KeyboardInputEvent::GetKeyCode()";
275 EnterInputEvent
enter(key_event
, true);
278 return enter
.object()->GetKeyCode();
281 PP_Var
GetCharacterText(PP_Resource character_event
) {
282 VLOG(4) << "PPB_KeyboardInputEvent::GetCharacterText()";
283 EnterInputEvent
enter(character_event
, true);
285 return PP_MakeUndefined();
286 return enter
.object()->GetCharacterText();
289 const PPB_KeyboardInputEvent g_ppb_keyboard_input_event_thunk
= {
290 &CreateKeyboardInputEvent
,
291 &IsKeyboardInputEvent
,
298 PP_Bool
SetUsbKeyCode(PP_Resource key_event
, uint32_t usb_key_code
) {
299 VLOG(4) << "PPB_KeyboardInputEvent_Dev::SetUsbKeyCode()";
300 EnterInputEvent
enter(key_event
, true);
303 return enter
.object()->SetUsbKeyCode(usb_key_code
);
306 uint32_t GetUsbKeyCode(PP_Resource key_event
) {
307 VLOG(4) << "PPB_KeyboardInputEvent_Dev::GetUsbKeyCode()";
308 EnterInputEvent
enter(key_event
, true);
311 return enter
.object()->GetUsbKeyCode();
314 const PPB_KeyboardInputEvent_Dev g_ppb_keyboard_input_event_dev_thunk
= {
319 // Composition -----------------------------------------------------------------
321 PP_Resource
CreateIMEInputEvent(PP_Instance instance
,
322 PP_InputEvent_Type type
,
323 PP_TimeTicks time_stamp
,
325 uint32_t segment_number
,
326 const uint32_t segment_offsets
[],
327 int32_t target_segment
,
328 uint32_t selection_start
,
329 uint32_t selection_end
) {
330 VLOG(4) << "PPB_IMEInputEvent_Dev::Create()";
331 EnterResourceCreation
enter(instance
);
334 return enter
.functions()->CreateIMEInputEvent(instance
, type
, time_stamp
,
335 text
, segment_number
,
342 PP_Bool
IsIMEInputEvent(PP_Resource resource
) {
343 VLOG(4) << "PPB_IMEInputEvent_Dev::IsIMEInputEvent()";
344 if (!IsInputEvent(resource
))
345 return PP_FALSE
; // Prevent warning log in GetType.
346 PP_InputEvent_Type type
= GetType(resource
);
347 return PP_FromBool(type
== PP_INPUTEVENT_TYPE_IME_COMPOSITION_START
||
348 type
== PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE
||
349 type
== PP_INPUTEVENT_TYPE_IME_COMPOSITION_END
||
350 type
== PP_INPUTEVENT_TYPE_IME_TEXT
);
353 PP_Var
GetIMEText(PP_Resource ime_event
) {
354 VLOG(4) << "PPB_IMEInputEvent_Dev::GetText()";
355 return GetCharacterText(ime_event
);
358 uint32_t GetIMESegmentNumber(PP_Resource ime_event
) {
359 VLOG(4) << "PPB_IMEInputEvent_Dev::GetSegmentNumber()";
360 EnterInputEvent
enter(ime_event
, true);
363 return enter
.object()->GetIMESegmentNumber();
366 uint32_t GetIMESegmentOffset(PP_Resource ime_event
, uint32_t index
) {
367 VLOG(4) << "PPB_IMEInputEvent_Dev::GetSegmentOffset()";
368 EnterInputEvent
enter(ime_event
, true);
371 return enter
.object()->GetIMESegmentOffset(index
);
374 int32_t GetIMETargetSegment(PP_Resource ime_event
) {
375 VLOG(4) << "PPB_IMEInputEvent_Dev::GetTargetSegment()";
376 EnterInputEvent
enter(ime_event
, true);
379 return enter
.object()->GetIMETargetSegment();
382 void GetIMESelection(PP_Resource ime_event
, uint32_t* start
, uint32_t* end
) {
383 VLOG(4) << "PPB_IMEInputEvent_Dev::GetSelection()";
384 EnterInputEvent
enter(ime_event
, true);
385 if (enter
.failed()) {
392 enter
.object()->GetIMESelection(start
, end
);
395 const PPB_IMEInputEvent_Dev_0_1 g_ppb_ime_input_event_0_1_thunk
= {
398 &GetIMESegmentNumber
,
399 &GetIMESegmentOffset
,
400 &GetIMETargetSegment
,
404 const PPB_IMEInputEvent_Dev_0_2 g_ppb_ime_input_event_0_2_thunk
= {
405 &CreateIMEInputEvent
,
408 &GetIMESegmentNumber
,
409 &GetIMESegmentOffset
,
410 &GetIMETargetSegment
,
414 const PPB_IMEInputEvent_1_0 g_ppb_ime_input_event_1_0_thunk
= {
415 &CreateIMEInputEvent
,
418 &GetIMESegmentNumber
,
419 &GetIMESegmentOffset
,
420 &GetIMETargetSegment
,
424 // Touch -----------------------------------------------------------------------
426 PP_Resource
CreateTouchInputEvent(PP_Instance instance
,
427 PP_InputEvent_Type type
,
428 PP_TimeTicks time_stamp
,
429 uint32_t modifiers
) {
430 VLOG(4) << "PPB_TouchInputEvent::Create()";
431 EnterResourceCreation
enter(instance
);
434 return enter
.functions()->CreateTouchInputEvent(instance
, type
, time_stamp
,
438 void AddTouchPoint(PP_Resource touch_event
,
439 PP_TouchListType list
,
440 const PP_TouchPoint
* point
) {
441 VLOG(4) << "PPB_TouchInputEvent::AddTouchPoint()";
442 EnterInputEvent
enter(touch_event
, true);
445 return enter
.object()->AddTouchPoint(list
, *point
);
448 PP_Bool
IsTouchInputEvent(PP_Resource resource
) {
449 VLOG(4) << "PPB_TouchInputEvent::IsTouchInputEvent()";
450 if (!IsInputEvent(resource
))
451 return PP_FALSE
; // Prevent warning log in GetType.
452 PP_InputEvent_Type type
= GetType(resource
);
453 return PP_FromBool(type
== PP_INPUTEVENT_TYPE_TOUCHSTART
||
454 type
== PP_INPUTEVENT_TYPE_TOUCHMOVE
||
455 type
== PP_INPUTEVENT_TYPE_TOUCHEND
||
456 type
== PP_INPUTEVENT_TYPE_TOUCHCANCEL
);
459 uint32_t GetTouchCount(PP_Resource touch_event
, PP_TouchListType list
) {
460 VLOG(4) << "PPB_TouchInputEvent::GetTouchCount()";
461 EnterInputEvent
enter(touch_event
, true);
464 return enter
.object()->GetTouchCount(list
);
467 struct PP_TouchPoint
GetTouchByIndex(PP_Resource touch_event
,
468 PP_TouchListType list
,
470 VLOG(4) << "PPB_TouchInputEvent::GetTouchByIndex()";
471 EnterInputEvent
enter(touch_event
, true);
473 return PP_MakeTouchPoint();
474 return enter
.object()->GetTouchByIndex(list
, index
);
477 struct PP_TouchPoint
GetTouchById(PP_Resource touch_event
,
478 PP_TouchListType list
,
480 VLOG(4) << "PPB_TouchInputEvent::GetTouchById()";
481 EnterInputEvent
enter(touch_event
, true);
483 return PP_MakeTouchPoint();
484 return enter
.object()->GetTouchById(list
, id
);
487 const PPB_TouchInputEvent_1_0 g_ppb_touch_input_event_thunk
= {
488 &CreateTouchInputEvent
,
498 const PPB_InputEvent_1_0
* GetPPB_InputEvent_1_0_Thunk() {
499 return &g_ppb_input_event_thunk
;
502 const PPB_MouseInputEvent_1_0
* GetPPB_MouseInputEvent_1_0_Thunk() {
503 return &g_ppb_mouse_input_event_1_0_thunk
;
506 const PPB_MouseInputEvent_1_1
* GetPPB_MouseInputEvent_1_1_Thunk() {
507 return &g_ppb_mouse_input_event_1_1_thunk
;
510 const PPB_KeyboardInputEvent_1_0
* GetPPB_KeyboardInputEvent_1_0_Thunk() {
511 return &g_ppb_keyboard_input_event_thunk
;
514 const PPB_KeyboardInputEvent_Dev_0_1
*
515 GetPPB_KeyboardInputEvent_Dev_0_1_Thunk() {
516 return &g_ppb_keyboard_input_event_dev_thunk
;
519 const PPB_WheelInputEvent_1_0
* GetPPB_WheelInputEvent_1_0_Thunk() {
520 return &g_ppb_wheel_input_event_thunk
;
523 const PPB_IMEInputEvent_Dev_0_1
* GetPPB_IMEInputEvent_Dev_0_1_Thunk() {
524 return &g_ppb_ime_input_event_0_1_thunk
;
527 const PPB_IMEInputEvent_Dev_0_2
* GetPPB_IMEInputEvent_Dev_0_2_Thunk() {
528 return &g_ppb_ime_input_event_0_2_thunk
;
531 const PPB_IMEInputEvent_1_0
* GetPPB_IMEInputEvent_1_0_Thunk() {
532 return &g_ppb_ime_input_event_1_0_thunk
;
535 const PPB_TouchInputEvent_1_0
* GetPPB_TouchInputEvent_1_0_Thunk() {
536 return &g_ppb_touch_input_event_thunk
;