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_1_0(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_1_0(instance
, type
,
263 PP_Resource
CreateKeyboardInputEvent_1_2(PP_Instance instance
,
264 PP_InputEvent_Type type
,
265 PP_TimeTicks time_stamp
,
268 struct PP_Var character_text
,
269 struct PP_Var code
) {
270 VLOG(4) << "PPB_KeyboardInputEvent::Create()";
271 EnterResourceCreation
enter(instance
);
274 return enter
.functions()->CreateKeyboardInputEvent_1_2(instance
, type
,
277 character_text
, code
);
280 PP_Bool
IsKeyboardInputEvent(PP_Resource resource
) {
281 VLOG(4) << "PPB_KeyboardInputEvent::IsKeyboardInputEvent()";
282 if (!IsInputEvent(resource
))
283 return PP_FALSE
; // Prevent warning log in GetType.
284 PP_InputEvent_Type type
= GetType(resource
);
285 return PP_FromBool(type
== PP_INPUTEVENT_TYPE_KEYDOWN
||
286 type
== PP_INPUTEVENT_TYPE_KEYUP
||
287 type
== PP_INPUTEVENT_TYPE_RAWKEYDOWN
||
288 type
== PP_INPUTEVENT_TYPE_CHAR
);
291 uint32_t GetKeyCode(PP_Resource key_event
) {
292 VLOG(4) << "PPB_KeyboardInputEvent::GetKeyCode()";
293 EnterInputEvent
enter(key_event
, true);
296 return enter
.object()->GetKeyCode();
299 PP_Var
GetCharacterText(PP_Resource character_event
) {
300 VLOG(4) << "PPB_KeyboardInputEvent::GetCharacterText()";
301 EnterInputEvent
enter(character_event
, true);
303 return PP_MakeUndefined();
304 return enter
.object()->GetCharacterText();
307 PP_Var
GetCode(PP_Resource key_event
) {
308 VLOG(4) << "PPB_KeyboardInputEvent::GetCode()";
309 EnterInputEvent
enter(key_event
, true);
311 return PP_MakeUndefined();
312 return enter
.object()->GetCode();
315 const PPB_KeyboardInputEvent_1_0 g_ppb_keyboard_input_event_1_0_thunk
= {
316 &CreateKeyboardInputEvent_1_0
,
317 &IsKeyboardInputEvent
,
322 const PPB_KeyboardInputEvent g_ppb_keyboard_input_event_thunk
= {
323 &CreateKeyboardInputEvent_1_2
,
324 &IsKeyboardInputEvent
,
330 // Composition -----------------------------------------------------------------
332 PP_Resource
CreateIMEInputEvent(PP_Instance instance
,
333 PP_InputEvent_Type type
,
334 PP_TimeTicks time_stamp
,
336 uint32_t segment_number
,
337 const uint32_t segment_offsets
[],
338 int32_t target_segment
,
339 uint32_t selection_start
,
340 uint32_t selection_end
) {
341 VLOG(4) << "PPB_IMEInputEvent_Dev::Create()";
342 EnterResourceCreation
enter(instance
);
345 return enter
.functions()->CreateIMEInputEvent(instance
, type
, time_stamp
,
346 text
, segment_number
,
353 PP_Bool
IsIMEInputEvent(PP_Resource resource
) {
354 VLOG(4) << "PPB_IMEInputEvent_Dev::IsIMEInputEvent()";
355 if (!IsInputEvent(resource
))
356 return PP_FALSE
; // Prevent warning log in GetType.
357 PP_InputEvent_Type type
= GetType(resource
);
358 return PP_FromBool(type
== PP_INPUTEVENT_TYPE_IME_COMPOSITION_START
||
359 type
== PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE
||
360 type
== PP_INPUTEVENT_TYPE_IME_COMPOSITION_END
||
361 type
== PP_INPUTEVENT_TYPE_IME_TEXT
);
364 PP_Var
GetIMEText(PP_Resource ime_event
) {
365 VLOG(4) << "PPB_IMEInputEvent_Dev::GetText()";
366 return GetCharacterText(ime_event
);
369 uint32_t GetIMESegmentNumber(PP_Resource ime_event
) {
370 VLOG(4) << "PPB_IMEInputEvent_Dev::GetSegmentNumber()";
371 EnterInputEvent
enter(ime_event
, true);
374 return enter
.object()->GetIMESegmentNumber();
377 uint32_t GetIMESegmentOffset(PP_Resource ime_event
, uint32_t index
) {
378 VLOG(4) << "PPB_IMEInputEvent_Dev::GetSegmentOffset()";
379 EnterInputEvent
enter(ime_event
, true);
382 return enter
.object()->GetIMESegmentOffset(index
);
385 int32_t GetIMETargetSegment(PP_Resource ime_event
) {
386 VLOG(4) << "PPB_IMEInputEvent_Dev::GetTargetSegment()";
387 EnterInputEvent
enter(ime_event
, true);
390 return enter
.object()->GetIMETargetSegment();
393 void GetIMESelection(PP_Resource ime_event
, uint32_t* start
, uint32_t* end
) {
394 VLOG(4) << "PPB_IMEInputEvent_Dev::GetSelection()";
395 EnterInputEvent
enter(ime_event
, true);
396 if (enter
.failed()) {
403 enter
.object()->GetIMESelection(start
, end
);
406 const PPB_IMEInputEvent_Dev_0_1 g_ppb_ime_input_event_0_1_thunk
= {
409 &GetIMESegmentNumber
,
410 &GetIMESegmentOffset
,
411 &GetIMETargetSegment
,
415 const PPB_IMEInputEvent_Dev_0_2 g_ppb_ime_input_event_0_2_thunk
= {
416 &CreateIMEInputEvent
,
419 &GetIMESegmentNumber
,
420 &GetIMESegmentOffset
,
421 &GetIMETargetSegment
,
425 const PPB_IMEInputEvent_1_0 g_ppb_ime_input_event_1_0_thunk
= {
426 &CreateIMEInputEvent
,
429 &GetIMESegmentNumber
,
430 &GetIMESegmentOffset
,
431 &GetIMETargetSegment
,
435 // Touch -----------------------------------------------------------------------
437 PP_Resource
CreateTouchInputEvent(PP_Instance instance
,
438 PP_InputEvent_Type type
,
439 PP_TimeTicks time_stamp
,
440 uint32_t modifiers
) {
441 VLOG(4) << "PPB_TouchInputEvent::Create()";
442 EnterResourceCreation
enter(instance
);
445 return enter
.functions()->CreateTouchInputEvent(instance
, type
, time_stamp
,
449 void AddTouchPoint(PP_Resource touch_event
,
450 PP_TouchListType list
,
451 const PP_TouchPoint
* point
) {
452 VLOG(4) << "PPB_TouchInputEvent::AddTouchPoint()";
453 EnterInputEvent
enter(touch_event
, true);
456 return enter
.object()->AddTouchPoint(list
, *point
);
459 PP_Bool
IsTouchInputEvent(PP_Resource resource
) {
460 VLOG(4) << "PPB_TouchInputEvent::IsTouchInputEvent()";
461 if (!IsInputEvent(resource
))
462 return PP_FALSE
; // Prevent warning log in GetType.
463 PP_InputEvent_Type type
= GetType(resource
);
464 return PP_FromBool(type
== PP_INPUTEVENT_TYPE_TOUCHSTART
||
465 type
== PP_INPUTEVENT_TYPE_TOUCHMOVE
||
466 type
== PP_INPUTEVENT_TYPE_TOUCHEND
||
467 type
== PP_INPUTEVENT_TYPE_TOUCHCANCEL
);
470 uint32_t GetTouchCount(PP_Resource touch_event
, PP_TouchListType list
) {
471 VLOG(4) << "PPB_TouchInputEvent::GetTouchCount()";
472 EnterInputEvent
enter(touch_event
, true);
475 return enter
.object()->GetTouchCount(list
);
478 struct PP_TouchPoint
GetTouchByIndex(PP_Resource touch_event
,
479 PP_TouchListType list
,
481 VLOG(4) << "PPB_TouchInputEvent::GetTouchByIndex()";
482 EnterInputEvent
enter(touch_event
, true);
484 return PP_MakeTouchPoint();
485 return enter
.object()->GetTouchByIndex(list
, index
);
488 struct PP_TouchPoint
GetTouchById(PP_Resource touch_event
,
489 PP_TouchListType list
,
491 VLOG(4) << "PPB_TouchInputEvent::GetTouchById()";
492 EnterInputEvent
enter(touch_event
, true);
494 return PP_MakeTouchPoint();
495 return enter
.object()->GetTouchById(list
, id
);
498 const PPB_TouchInputEvent_1_0 g_ppb_touch_input_event_thunk
= {
499 &CreateTouchInputEvent
,
509 const PPB_InputEvent_1_0
* GetPPB_InputEvent_1_0_Thunk() {
510 return &g_ppb_input_event_thunk
;
513 const PPB_MouseInputEvent_1_0
* GetPPB_MouseInputEvent_1_0_Thunk() {
514 return &g_ppb_mouse_input_event_1_0_thunk
;
517 const PPB_MouseInputEvent_1_1
* GetPPB_MouseInputEvent_1_1_Thunk() {
518 return &g_ppb_mouse_input_event_1_1_thunk
;
521 const PPB_KeyboardInputEvent_1_0
* GetPPB_KeyboardInputEvent_1_0_Thunk() {
522 return &g_ppb_keyboard_input_event_1_0_thunk
;
525 const PPB_KeyboardInputEvent_1_2
* GetPPB_KeyboardInputEvent_1_2_Thunk() {
526 return &g_ppb_keyboard_input_event_thunk
;
529 const PPB_WheelInputEvent_1_0
* GetPPB_WheelInputEvent_1_0_Thunk() {
530 return &g_ppb_wheel_input_event_thunk
;
533 const PPB_IMEInputEvent_Dev_0_1
* GetPPB_IMEInputEvent_Dev_0_1_Thunk() {
534 return &g_ppb_ime_input_event_0_1_thunk
;
537 const PPB_IMEInputEvent_Dev_0_2
* GetPPB_IMEInputEvent_Dev_0_2_Thunk() {
538 return &g_ppb_ime_input_event_0_2_thunk
;
541 const PPB_IMEInputEvent_1_0
* GetPPB_IMEInputEvent_1_0_Thunk() {
542 return &g_ppb_ime_input_event_1_0_thunk
;
545 const PPB_TouchInputEvent_1_0
* GetPPB_TouchInputEvent_1_0_Thunk() {
546 return &g_ppb_touch_input_event_thunk
;