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
;
45 // The key event's |code| attribute as defined in:
46 // http://www.w3.org/TR/uievents/
49 std::string character_text
;
51 std::vector
<uint32_t> composition_segment_offsets
;
52 int32_t composition_target_segment
;
53 uint32_t composition_selection_start
;
54 uint32_t composition_selection_end
;
56 std::vector
<PP_TouchPoint
> touches
;
57 std::vector
<PP_TouchPoint
> changed_touches
;
58 std::vector
<PP_TouchPoint
> target_touches
;
61 // This simple class implements the PPB_InputEvent_API in terms of the
62 // shared InputEventData structure
63 class PPAPI_SHARED_EXPORT PPB_InputEvent_Shared
65 public thunk::PPB_InputEvent_API
{
67 PPB_InputEvent_Shared(ResourceObjectType type
,
69 const InputEventData
& data
);
71 // Resource overrides.
72 PPB_InputEvent_API
* AsPPB_InputEvent_API() override
;
74 // PPB_InputEvent_API implementation.
75 const InputEventData
& GetInputEventData() const override
;
76 PP_InputEvent_Type
GetType() override
;
77 PP_TimeTicks
GetTimeStamp() override
;
78 uint32_t GetModifiers() override
;
79 PP_InputEvent_MouseButton
GetMouseButton() override
;
80 PP_Point
GetMousePosition() override
;
81 int32_t GetMouseClickCount() override
;
82 PP_Point
GetMouseMovement() override
;
83 PP_FloatPoint
GetWheelDelta() override
;
84 PP_FloatPoint
GetWheelTicks() override
;
85 PP_Bool
GetWheelScrollByPage() override
;
86 uint32_t GetKeyCode() override
;
87 PP_Var
GetCharacterText() override
;
88 PP_Var
GetCode() override
;
89 uint32_t GetIMESegmentNumber() override
;
90 uint32_t GetIMESegmentOffset(uint32_t index
) override
;
91 int32_t GetIMETargetSegment() override
;
92 void GetIMESelection(uint32_t* start
, uint32_t* end
) override
;
93 void AddTouchPoint(PP_TouchListType list
,
94 const PP_TouchPoint
& point
) override
;
95 uint32_t GetTouchCount(PP_TouchListType list
) override
;
96 PP_TouchPoint
GetTouchByIndex(PP_TouchListType list
, uint32_t index
) override
;
97 PP_TouchPoint
GetTouchById(PP_TouchListType list
, 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
,
118 static PP_Resource
CreateMouseInputEvent(
119 ResourceObjectType type
,
120 PP_Instance instance
,
121 PP_InputEvent_Type event_type
,
122 PP_TimeTicks time_stamp
,
124 PP_InputEvent_MouseButton mouse_button
,
125 const PP_Point
* mouse_position
,
127 const PP_Point
* mouse_movement
);
128 static PP_Resource
CreateWheelInputEvent(ResourceObjectType type
,
129 PP_Instance instance
,
130 PP_TimeTicks time_stamp
,
132 const PP_FloatPoint
* wheel_delta
,
133 const PP_FloatPoint
* wheel_ticks
,
134 PP_Bool scroll_by_page
);
135 static PP_Resource
CreateTouchInputEvent(ResourceObjectType type
,
136 PP_Instance instance
,
137 PP_InputEvent_Type event_type
,
138 PP_TimeTicks time_stamp
,
142 InputEventData data_
;
144 DISALLOW_IMPLICIT_CONSTRUCTORS(PPB_InputEvent_Shared
);
149 #endif // PPAPI_SHARED_IMPL_PPB_INPUT_EVENT_SHARED_H_