cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / ppapi / thunk / ppb_input_event_thunk.cc
blobf54eefa8a02326e6932ead0e97919d1913f8dc40
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"
12 namespace ppapi {
13 namespace thunk {
15 namespace {
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);
24 if (enter.failed())
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);
33 if (enter.failed())
34 return enter.retval();
35 return enter.functions()->RequestFilteringInputEvents(instance,
36 event_classes);
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);
56 if (enter.failed())
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);
64 if (enter.failed())
65 return 0.0;
66 return enter.object()->GetTimeStamp();
69 uint32_t GetModifiers(PP_Resource event) {
70 VLOG(4) << "PPB_InputEvent::GetModifiers()";
71 EnterInputEvent enter(event, true);
72 if (enter.failed())
73 return 0;
74 return enter.object()->GetModifiers();
77 const PPB_InputEvent g_ppb_input_event_thunk = {
78 &RequestInputEvents,
79 &RequestFilteringInputEvents,
80 &ClearInputEventRequest,
81 &IsInputEvent,
82 &GetType,
83 &GetTimeStamp,
84 &GetModifiers
87 // Mouse -----------------------------------------------------------------------
89 PP_Resource CreateMouseInputEvent1_0(PP_Instance instance,
90 PP_InputEvent_Type type,
91 PP_TimeTicks time_stamp,
92 uint32_t modifiers,
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);
98 if (enter.failed())
99 return 0;
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,
105 &mouse_movement);
108 PP_Resource CreateMouseInputEvent1_1(PP_Instance instance,
109 PP_InputEvent_Type type,
110 PP_TimeTicks time_stamp,
111 uint32_t modifiers,
112 PP_InputEvent_MouseButton mouse_button,
113 const PP_Point* mouse_position,
114 int32_t click_count,
115 const PP_Point* mouse_movement) {
116 VLOG(4) << "PPB_MouseInputEvent::Create()";
117 EnterResourceCreation enter(instance);
118 if (enter.failed())
119 return 0;
120 return enter.functions()->CreateMouseInputEvent(instance, type, time_stamp,
121 modifiers, mouse_button,
122 mouse_position, click_count,
123 mouse_movement);
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);
142 if (enter.failed())
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);
150 if (enter.failed())
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);
158 if (enter.failed())
159 return 0;
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);
166 if (enter.failed())
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,
173 &IsMouseInputEvent,
174 &GetMouseButton,
175 &GetMousePosition,
176 &GetMouseClickCount
179 const PPB_MouseInputEvent g_ppb_mouse_input_event_1_1_thunk = {
180 &CreateMouseInputEvent1_1,
181 &IsMouseInputEvent,
182 &GetMouseButton,
183 &GetMousePosition,
184 &GetMouseClickCount,
185 &GetMouseMovement
188 // Wheel -----------------------------------------------------------------------
190 PP_Resource CreateWheelInputEvent(PP_Instance instance,
191 PP_TimeTicks time_stamp,
192 uint32_t modifiers,
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);
198 if (enter.failed())
199 return 0;
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);
216 if (enter.failed())
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);
224 if (enter.failed())
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);
232 if (enter.failed())
233 return PP_FALSE;
234 return enter.object()->GetWheelScrollByPage();
237 const PPB_WheelInputEvent g_ppb_wheel_input_event_thunk = {
238 &CreateWheelInputEvent,
239 &IsWheelInputEvent,
240 &GetWheelDelta,
241 &GetWheelTicks,
242 &GetWheelScrollByPage
245 // Keyboard --------------------------------------------------------------------
247 PP_Resource CreateKeyboardInputEvent(PP_Instance instance,
248 PP_InputEvent_Type type,
249 PP_TimeTicks time_stamp,
250 uint32_t modifiers,
251 uint32_t key_code,
252 struct PP_Var character_text) {
253 VLOG(4) << "PPB_KeyboardInputEvent::Create()";
254 EnterResourceCreation enter(instance);
255 if (enter.failed())
256 return 0;
257 return enter.functions()->CreateKeyboardInputEvent(instance, type, time_stamp,
258 modifiers, key_code,
259 character_text);
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);
276 if (enter.failed())
277 return 0;
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);
284 if (enter.failed())
285 return PP_MakeUndefined();
286 return enter.object()->GetCharacterText();
289 const PPB_KeyboardInputEvent g_ppb_keyboard_input_event_thunk = {
290 &CreateKeyboardInputEvent,
291 &IsKeyboardInputEvent,
292 &GetKeyCode,
293 &GetCharacterText
296 // _Dev interface.
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);
301 if (enter.failed())
302 return PP_FALSE;
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);
309 if (enter.failed())
310 return 0;
311 return enter.object()->GetUsbKeyCode();
314 const PPB_KeyboardInputEvent_Dev g_ppb_keyboard_input_event_dev_thunk = {
315 &SetUsbKeyCode,
316 &GetUsbKeyCode,
319 // Composition -----------------------------------------------------------------
321 PP_Resource CreateIMEInputEvent(PP_Instance instance,
322 PP_InputEvent_Type type,
323 PP_TimeTicks time_stamp,
324 PP_Var text,
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);
332 if (enter.failed())
333 return 0;
334 return enter.functions()->CreateIMEInputEvent(instance, type, time_stamp,
335 text, segment_number,
336 segment_offsets,
337 target_segment,
338 selection_start,
339 selection_end);
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);
361 if (enter.failed())
362 return 0;
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);
369 if (enter.failed())
370 return 0;
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);
377 if (enter.failed())
378 return -1;
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()) {
386 if (start)
387 *start = 0;
388 if (end)
389 *end = 0;
390 return;
392 enter.object()->GetIMESelection(start, end);
395 const PPB_IMEInputEvent_Dev_0_1 g_ppb_ime_input_event_0_1_thunk = {
396 &IsIMEInputEvent,
397 &GetIMEText,
398 &GetIMESegmentNumber,
399 &GetIMESegmentOffset,
400 &GetIMETargetSegment,
401 &GetIMESelection
404 const PPB_IMEInputEvent_Dev_0_2 g_ppb_ime_input_event_0_2_thunk = {
405 &CreateIMEInputEvent,
406 &IsIMEInputEvent,
407 &GetIMEText,
408 &GetIMESegmentNumber,
409 &GetIMESegmentOffset,
410 &GetIMETargetSegment,
411 &GetIMESelection
414 const PPB_IMEInputEvent_1_0 g_ppb_ime_input_event_1_0_thunk = {
415 &CreateIMEInputEvent,
416 &IsIMEInputEvent,
417 &GetIMEText,
418 &GetIMESegmentNumber,
419 &GetIMESegmentOffset,
420 &GetIMETargetSegment,
421 &GetIMESelection
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);
432 if (enter.failed())
433 return 0;
434 return enter.functions()->CreateTouchInputEvent(instance, type, time_stamp,
435 modifiers);
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);
443 if (enter.failed())
444 return;
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);
462 if (enter.failed())
463 return 0;
464 return enter.object()->GetTouchCount(list);
467 struct PP_TouchPoint GetTouchByIndex(PP_Resource touch_event,
468 PP_TouchListType list,
469 uint32_t index) {
470 VLOG(4) << "PPB_TouchInputEvent::GetTouchByIndex()";
471 EnterInputEvent enter(touch_event, true);
472 if (enter.failed())
473 return PP_MakeTouchPoint();
474 return enter.object()->GetTouchByIndex(list, index);
477 struct PP_TouchPoint GetTouchById(PP_Resource touch_event,
478 PP_TouchListType list,
479 uint32_t id) {
480 VLOG(4) << "PPB_TouchInputEvent::GetTouchById()";
481 EnterInputEvent enter(touch_event, true);
482 if (enter.failed())
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,
489 &AddTouchPoint,
490 &IsTouchInputEvent,
491 &GetTouchCount,
492 &GetTouchByIndex,
493 &GetTouchById
496 } // namespace
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;
539 } // namespace thunk
540 } // namespace ppapi