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 #ifndef PPAPI_SHARED_IMPL_PPB_INPUT_EVENT_SHARED_H_
6 #define PPAPI_SHARED_IMPL_PPB_INPUT_EVENT_SHARED_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "ppapi/c/ppb_input_event.h"
14 #include "ppapi/shared_impl/resource.h"
15 #include "ppapi/thunk/ppb_input_event_api.h"
19 // IF YOU ADD STUFF TO THIS CLASS
20 // ==============================
21 // Be sure to add it to the STRUCT_TRAITS at the top of ppapi_messages.h
22 struct PPAPI_SHARED_EXPORT InputEventData
{
26 // Internal-only value. Set to true when this input event is filtered, that
27 // is, should be delivered synchronously. This is used by the proxy.
30 PP_InputEvent_Type event_type
;
31 PP_TimeTicks event_time_stamp
;
32 uint32_t event_modifiers
;
34 PP_InputEvent_MouseButton mouse_button
;
35 PP_Point mouse_position
;
36 int32_t mouse_click_count
;
37 PP_Point mouse_movement
;
39 PP_FloatPoint wheel_delta
;
40 PP_FloatPoint wheel_ticks
;
41 bool wheel_scroll_by_page
;
44 uint32_t usb_key_code
;
46 std::string character_text
;
48 std::vector
<uint32_t> composition_segment_offsets
;
49 int32_t composition_target_segment
;
50 uint32_t composition_selection_start
;
51 uint32_t composition_selection_end
;
53 std::vector
<PP_TouchPoint
> touches
;
54 std::vector
<PP_TouchPoint
> changed_touches
;
55 std::vector
<PP_TouchPoint
> target_touches
;
58 // This simple class implements the PPB_InputEvent_API in terms of the
59 // shared InputEventData structure
60 class PPAPI_SHARED_EXPORT PPB_InputEvent_Shared
62 public thunk::PPB_InputEvent_API
{
64 PPB_InputEvent_Shared(ResourceObjectType type
,
66 const InputEventData
& data
);
68 // Resource overrides.
69 virtual PPB_InputEvent_API
* AsPPB_InputEvent_API() OVERRIDE
;
71 // PPB_InputEvent_API implementation.
72 virtual const InputEventData
& GetInputEventData() const OVERRIDE
;
73 virtual PP_InputEvent_Type
GetType() OVERRIDE
;
74 virtual PP_TimeTicks
GetTimeStamp() OVERRIDE
;
75 virtual uint32_t GetModifiers() OVERRIDE
;
76 virtual PP_InputEvent_MouseButton
GetMouseButton() OVERRIDE
;
77 virtual PP_Point
GetMousePosition() OVERRIDE
;
78 virtual int32_t GetMouseClickCount() OVERRIDE
;
79 virtual PP_Point
GetMouseMovement() OVERRIDE
;
80 virtual PP_FloatPoint
GetWheelDelta() OVERRIDE
;
81 virtual PP_FloatPoint
GetWheelTicks() OVERRIDE
;
82 virtual PP_Bool
GetWheelScrollByPage() OVERRIDE
;
83 virtual uint32_t GetKeyCode() OVERRIDE
;
84 virtual PP_Var
GetCharacterText() OVERRIDE
;
85 virtual PP_Bool
SetUsbKeyCode(uint32_t usb_key_code
) OVERRIDE
;
86 virtual uint32_t GetUsbKeyCode() OVERRIDE
;
87 virtual uint32_t GetIMESegmentNumber() OVERRIDE
;
88 virtual uint32_t GetIMESegmentOffset(uint32_t index
) OVERRIDE
;
89 virtual int32_t GetIMETargetSegment() OVERRIDE
;
90 virtual void GetIMESelection(uint32_t* start
, uint32_t* end
) OVERRIDE
;
91 virtual void AddTouchPoint(PP_TouchListType list
,
92 const PP_TouchPoint
& point
) OVERRIDE
;
93 virtual uint32_t GetTouchCount(PP_TouchListType list
) OVERRIDE
;
94 virtual PP_TouchPoint
GetTouchByIndex(PP_TouchListType list
,
95 uint32_t index
) OVERRIDE
;
96 virtual PP_TouchPoint
GetTouchById(PP_TouchListType list
,
97 uint32_t id
) OVERRIDE
;
99 // Implementations for event creation.
100 static PP_Resource
CreateIMEInputEvent(ResourceObjectType type
,
101 PP_Instance instance
,
102 PP_InputEvent_Type event_type
,
103 PP_TimeTicks time_stamp
,
105 uint32_t segment_number
,
106 const uint32_t* segment_offsets
,
107 int32_t target_segment
,
108 uint32_t selection_start
,
109 uint32_t selection_end
);
110 static PP_Resource
CreateKeyboardInputEvent(ResourceObjectType type
,
111 PP_Instance instance
,
112 PP_InputEvent_Type event_type
,
113 PP_TimeTicks time_stamp
,
116 struct PP_Var character_text
);
117 static PP_Resource
CreateMouseInputEvent(
118 ResourceObjectType type
,
119 PP_Instance instance
,
120 PP_InputEvent_Type event_type
,
121 PP_TimeTicks time_stamp
,
123 PP_InputEvent_MouseButton mouse_button
,
124 const PP_Point
* mouse_position
,
126 const PP_Point
* mouse_movement
);
127 static PP_Resource
CreateWheelInputEvent(ResourceObjectType type
,
128 PP_Instance instance
,
129 PP_TimeTicks time_stamp
,
131 const PP_FloatPoint
* wheel_delta
,
132 const PP_FloatPoint
* wheel_ticks
,
133 PP_Bool scroll_by_page
);
134 static PP_Resource
CreateTouchInputEvent(ResourceObjectType type
,
135 PP_Instance instance
,
136 PP_InputEvent_Type event_type
,
137 PP_TimeTicks time_stamp
,
141 InputEventData data_
;
143 DISALLOW_IMPLICIT_CONSTRUCTORS(PPB_InputEvent_Shared
);
148 #endif // PPAPI_SHARED_IMPL_PPB_INPUT_EVENT_SHARED_H_