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 EnterInstance
enter(instance
);
24 return enter
.retval();
25 return enter
.functions()->RequestInputEvents(instance
, event_classes
);
28 int32_t RequestFilteringInputEvents(PP_Instance instance
,
29 uint32_t event_classes
) {
30 EnterInstance
enter(instance
);
32 return enter
.retval();
33 return enter
.functions()->RequestFilteringInputEvents(instance
,
37 void ClearInputEventRequest(PP_Instance instance
,
38 uint32_t event_classes
) {
39 EnterInstance
enter(instance
);
40 if (enter
.succeeded())
41 enter
.functions()->ClearInputEventRequest(instance
, event_classes
);
44 PP_Bool
IsInputEvent(PP_Resource resource
) {
45 EnterInputEvent
enter(resource
, false);
46 return enter
.succeeded() ? PP_TRUE
: PP_FALSE
;
49 PP_InputEvent_Type
GetType(PP_Resource event
) {
50 EnterInputEvent
enter(event
, true);
52 return PP_INPUTEVENT_TYPE_UNDEFINED
;
53 return enter
.object()->GetType();
56 PP_TimeTicks
GetTimeStamp(PP_Resource event
) {
57 EnterInputEvent
enter(event
, true);
60 return enter
.object()->GetTimeStamp();
63 uint32_t GetModifiers(PP_Resource event
) {
64 EnterInputEvent
enter(event
, true);
67 return enter
.object()->GetModifiers();
70 const PPB_InputEvent g_ppb_input_event_thunk
= {
72 &RequestFilteringInputEvents
,
73 &ClearInputEventRequest
,
80 // Mouse -----------------------------------------------------------------------
82 PP_Resource
CreateMouseInputEvent1_0(PP_Instance instance
,
83 PP_InputEvent_Type type
,
84 PP_TimeTicks time_stamp
,
86 PP_InputEvent_MouseButton mouse_button
,
87 const PP_Point
* mouse_position
,
88 int32_t click_count
) {
89 EnterResourceCreation
enter(instance
);
93 PP_Point mouse_movement
= PP_MakePoint(0, 0);
94 return enter
.functions()->CreateMouseInputEvent(instance
, type
, time_stamp
,
95 modifiers
, mouse_button
,
96 mouse_position
, click_count
,
100 PP_Resource
CreateMouseInputEvent1_1(PP_Instance instance
,
101 PP_InputEvent_Type type
,
102 PP_TimeTicks time_stamp
,
104 PP_InputEvent_MouseButton mouse_button
,
105 const PP_Point
* mouse_position
,
107 const PP_Point
* mouse_movement
) {
108 EnterResourceCreation
enter(instance
);
111 return enter
.functions()->CreateMouseInputEvent(instance
, type
, time_stamp
,
112 modifiers
, mouse_button
,
113 mouse_position
, click_count
,
117 PP_Bool
IsMouseInputEvent(PP_Resource resource
) {
118 if (!IsInputEvent(resource
))
119 return PP_FALSE
; // Prevent warning log in GetType.
120 PP_InputEvent_Type type
= GetType(resource
);
121 return PP_FromBool(type
== PP_INPUTEVENT_TYPE_MOUSEDOWN
||
122 type
== PP_INPUTEVENT_TYPE_MOUSEUP
||
123 type
== PP_INPUTEVENT_TYPE_MOUSEMOVE
||
124 type
== PP_INPUTEVENT_TYPE_MOUSEENTER
||
125 type
== PP_INPUTEVENT_TYPE_MOUSELEAVE
||
126 type
== PP_INPUTEVENT_TYPE_CONTEXTMENU
);
129 PP_InputEvent_MouseButton
GetMouseButton(PP_Resource mouse_event
) {
130 EnterInputEvent
enter(mouse_event
, true);
132 return PP_INPUTEVENT_MOUSEBUTTON_NONE
;
133 return enter
.object()->GetMouseButton();
136 PP_Point
GetMousePosition(PP_Resource mouse_event
) {
137 EnterInputEvent
enter(mouse_event
, true);
139 return PP_MakePoint(0, 0);
140 return enter
.object()->GetMousePosition();
143 int32_t GetMouseClickCount(PP_Resource mouse_event
) {
144 EnterInputEvent
enter(mouse_event
, true);
147 return enter
.object()->GetMouseClickCount();
150 PP_Point
GetMouseMovement(PP_Resource mouse_event
) {
151 EnterInputEvent
enter(mouse_event
, true);
153 return PP_MakePoint(0, 0);
154 return enter
.object()->GetMouseMovement();
157 const PPB_MouseInputEvent_1_0 g_ppb_mouse_input_event_1_0_thunk
= {
158 &CreateMouseInputEvent1_0
,
165 const PPB_MouseInputEvent g_ppb_mouse_input_event_1_1_thunk
= {
166 &CreateMouseInputEvent1_1
,
174 // Wheel -----------------------------------------------------------------------
176 PP_Resource
CreateWheelInputEvent(PP_Instance instance
,
177 PP_TimeTicks time_stamp
,
179 const PP_FloatPoint
* wheel_delta
,
180 const PP_FloatPoint
* wheel_ticks
,
181 PP_Bool scroll_by_page
) {
182 EnterResourceCreation
enter(instance
);
185 return enter
.functions()->CreateWheelInputEvent(instance
, time_stamp
,
186 modifiers
, wheel_delta
,
187 wheel_ticks
, scroll_by_page
);
190 PP_Bool
IsWheelInputEvent(PP_Resource resource
) {
191 if (!IsInputEvent(resource
))
192 return PP_FALSE
; // Prevent warning log in GetType.
193 PP_InputEvent_Type type
= GetType(resource
);
194 return PP_FromBool(type
== PP_INPUTEVENT_TYPE_WHEEL
);
197 PP_FloatPoint
GetWheelDelta(PP_Resource wheel_event
) {
198 EnterInputEvent
enter(wheel_event
, true);
200 return PP_MakeFloatPoint(0.0f
, 0.0f
);
201 return enter
.object()->GetWheelDelta();
204 PP_FloatPoint
GetWheelTicks(PP_Resource wheel_event
) {
205 EnterInputEvent
enter(wheel_event
, true);
207 return PP_MakeFloatPoint(0.0f
, 0.0f
);
208 return enter
.object()->GetWheelTicks();
211 PP_Bool
GetWheelScrollByPage(PP_Resource wheel_event
) {
212 EnterInputEvent
enter(wheel_event
, true);
215 return enter
.object()->GetWheelScrollByPage();
218 const PPB_WheelInputEvent g_ppb_wheel_input_event_thunk
= {
219 &CreateWheelInputEvent
,
223 &GetWheelScrollByPage
226 // Keyboard --------------------------------------------------------------------
228 PP_Resource
CreateKeyboardInputEvent(PP_Instance instance
,
229 PP_InputEvent_Type type
,
230 PP_TimeTicks time_stamp
,
233 struct PP_Var character_text
) {
234 EnterResourceCreation
enter(instance
);
237 return enter
.functions()->CreateKeyboardInputEvent(instance
, type
, time_stamp
,
242 PP_Bool
IsKeyboardInputEvent(PP_Resource resource
) {
243 if (!IsInputEvent(resource
))
244 return PP_FALSE
; // Prevent warning log in GetType.
245 PP_InputEvent_Type type
= GetType(resource
);
246 return PP_FromBool(type
== PP_INPUTEVENT_TYPE_KEYDOWN
||
247 type
== PP_INPUTEVENT_TYPE_KEYUP
||
248 type
== PP_INPUTEVENT_TYPE_RAWKEYDOWN
||
249 type
== PP_INPUTEVENT_TYPE_CHAR
);
252 uint32_t GetKeyCode(PP_Resource key_event
) {
253 EnterInputEvent
enter(key_event
, true);
256 return enter
.object()->GetKeyCode();
259 PP_Var
GetCharacterText(PP_Resource character_event
) {
260 EnterInputEvent
enter(character_event
, true);
262 return PP_MakeUndefined();
263 return enter
.object()->GetCharacterText();
266 const PPB_KeyboardInputEvent g_ppb_keyboard_input_event_thunk
= {
267 &CreateKeyboardInputEvent
,
268 &IsKeyboardInputEvent
,
275 PP_Bool
SetUsbKeyCode(PP_Resource key_event
, uint32_t usb_key_code
) {
276 EnterInputEvent
enter(key_event
, true);
279 return enter
.object()->SetUsbKeyCode(usb_key_code
);
282 uint32_t GetUsbKeyCode(PP_Resource key_event
) {
283 EnterInputEvent
enter(key_event
, true);
286 return enter
.object()->GetUsbKeyCode();
289 const PPB_KeyboardInputEvent_Dev g_ppb_keyboard_input_event_dev_thunk
= {
294 // Composition -----------------------------------------------------------------
296 PP_Resource
CreateIMEInputEvent(PP_Instance instance
,
297 PP_InputEvent_Type type
,
298 PP_TimeTicks time_stamp
,
300 uint32_t segment_number
,
301 const uint32_t segment_offsets
[],
302 int32_t target_segment
,
303 uint32_t selection_start
,
304 uint32_t selection_end
) {
305 EnterResourceCreation
enter(instance
);
308 return enter
.functions()->CreateIMEInputEvent(instance
, type
, time_stamp
,
309 text
, segment_number
,
316 PP_Bool
IsIMEInputEvent(PP_Resource resource
) {
317 if (!IsInputEvent(resource
))
318 return PP_FALSE
; // Prevent warning log in GetType.
319 PP_InputEvent_Type type
= GetType(resource
);
320 return PP_FromBool(type
== PP_INPUTEVENT_TYPE_IME_COMPOSITION_START
||
321 type
== PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE
||
322 type
== PP_INPUTEVENT_TYPE_IME_COMPOSITION_END
||
323 type
== PP_INPUTEVENT_TYPE_IME_TEXT
);
326 PP_Var
GetIMEText(PP_Resource ime_event
) {
327 return GetCharacterText(ime_event
);
330 uint32_t GetIMESegmentNumber(PP_Resource ime_event
) {
331 EnterInputEvent
enter(ime_event
, true);
334 return enter
.object()->GetIMESegmentNumber();
337 uint32_t GetIMESegmentOffset(PP_Resource ime_event
, uint32_t index
) {
338 EnterInputEvent
enter(ime_event
, true);
341 return enter
.object()->GetIMESegmentOffset(index
);
344 int32_t GetIMETargetSegment(PP_Resource ime_event
) {
345 EnterInputEvent
enter(ime_event
, true);
348 return enter
.object()->GetIMETargetSegment();
351 void GetIMESelection(PP_Resource ime_event
, uint32_t* start
, uint32_t* end
) {
352 EnterInputEvent
enter(ime_event
, true);
353 if (enter
.failed()) {
360 enter
.object()->GetIMESelection(start
, end
);
363 const PPB_IMEInputEvent_Dev_0_1 g_ppb_ime_input_event_0_1_thunk
= {
366 &GetIMESegmentNumber
,
367 &GetIMESegmentOffset
,
368 &GetIMETargetSegment
,
372 const PPB_IMEInputEvent_Dev_0_2 g_ppb_ime_input_event_0_2_thunk
= {
373 &CreateIMEInputEvent
,
376 &GetIMESegmentNumber
,
377 &GetIMESegmentOffset
,
378 &GetIMETargetSegment
,
382 // Touch -----------------------------------------------------------------------
384 PP_Resource
CreateTouchInputEvent(PP_Instance instance
,
385 PP_InputEvent_Type type
,
386 PP_TimeTicks time_stamp
,
387 uint32_t modifiers
) {
388 EnterResourceCreation
enter(instance
);
391 return enter
.functions()->CreateTouchInputEvent(instance
, type
, time_stamp
,
395 void AddTouchPoint(PP_Resource touch_event
,
396 PP_TouchListType list
,
397 const PP_TouchPoint
* point
) {
398 EnterInputEvent
enter(touch_event
, true);
401 return enter
.object()->AddTouchPoint(list
, *point
);
404 PP_Bool
IsTouchInputEvent(PP_Resource resource
) {
405 if (!IsInputEvent(resource
))
406 return PP_FALSE
; // Prevent warning log in GetType.
407 PP_InputEvent_Type type
= GetType(resource
);
408 return PP_FromBool(type
== PP_INPUTEVENT_TYPE_TOUCHSTART
||
409 type
== PP_INPUTEVENT_TYPE_TOUCHMOVE
||
410 type
== PP_INPUTEVENT_TYPE_TOUCHEND
||
411 type
== PP_INPUTEVENT_TYPE_TOUCHCANCEL
);
414 uint32_t GetTouchCount(PP_Resource touch_event
, PP_TouchListType list
) {
415 EnterInputEvent
enter(touch_event
, true);
418 return enter
.object()->GetTouchCount(list
);
421 struct PP_TouchPoint
GetTouchByIndex(PP_Resource touch_event
,
422 PP_TouchListType list
,
424 EnterInputEvent
enter(touch_event
, true);
426 return PP_MakeTouchPoint();
427 return enter
.object()->GetTouchByIndex(list
, index
);
430 struct PP_TouchPoint
GetTouchById(PP_Resource touch_event
,
431 PP_TouchListType list
,
433 EnterInputEvent
enter(touch_event
, true);
435 return PP_MakeTouchPoint();
436 return enter
.object()->GetTouchById(list
, id
);
439 const PPB_TouchInputEvent_1_0 g_ppb_touch_input_event_thunk
= {
440 &CreateTouchInputEvent
,
450 const PPB_InputEvent_1_0
* GetPPB_InputEvent_1_0_Thunk() {
451 return &g_ppb_input_event_thunk
;
454 const PPB_MouseInputEvent_1_0
* GetPPB_MouseInputEvent_1_0_Thunk() {
455 return &g_ppb_mouse_input_event_1_0_thunk
;
458 const PPB_MouseInputEvent_1_1
* GetPPB_MouseInputEvent_1_1_Thunk() {
459 return &g_ppb_mouse_input_event_1_1_thunk
;
462 const PPB_KeyboardInputEvent_1_0
* GetPPB_KeyboardInputEvent_1_0_Thunk() {
463 return &g_ppb_keyboard_input_event_thunk
;
466 const PPB_KeyboardInputEvent_Dev_0_1
*
467 GetPPB_KeyboardInputEvent_Dev_0_1_Thunk() {
468 return &g_ppb_keyboard_input_event_dev_thunk
;
471 const PPB_WheelInputEvent_1_0
* GetPPB_WheelInputEvent_1_0_Thunk() {
472 return &g_ppb_wheel_input_event_thunk
;
475 const PPB_IMEInputEvent_Dev_0_1
* GetPPB_IMEInputEvent_Dev_0_1_Thunk() {
476 return &g_ppb_ime_input_event_0_1_thunk
;
479 const PPB_IMEInputEvent_Dev_0_2
* GetPPB_IMEInputEvent_Dev_0_2_Thunk() {
480 return &g_ppb_ime_input_event_0_2_thunk
;
483 const PPB_TouchInputEvent_1_0
* GetPPB_TouchInputEvent_1_0_Thunk() {
484 return &g_ppb_touch_input_event_thunk
;