[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / ppapi / shared_impl / ppb_input_event_shared.h
blobb3e8e61629fd396c7a640ac5810da508a17b169a
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_
8 #include <string>
9 #include <vector>
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"
17 namespace ppapi {
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 {
23 InputEventData();
24 ~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.
28 bool is_filtered;
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;
43 uint32_t key_code;
45 // The key event's |code| attribute as defined in:
46 // http://www.w3.org/TR/uievents/
47 std::string code;
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
64 : public Resource,
65 public thunk::PPB_InputEvent_API {
66 public:
67 PPB_InputEvent_Shared(ResourceObjectType type,
68 PP_Instance instance,
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,
104 struct PP_Var text,
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,
114 uint32_t modifiers,
115 uint32_t key_code,
116 struct PP_Var character_text,
117 struct PP_Var code);
118 static PP_Resource CreateMouseInputEvent(
119 ResourceObjectType type,
120 PP_Instance instance,
121 PP_InputEvent_Type event_type,
122 PP_TimeTicks time_stamp,
123 uint32_t modifiers,
124 PP_InputEvent_MouseButton mouse_button,
125 const PP_Point* mouse_position,
126 int32_t click_count,
127 const PP_Point* mouse_movement);
128 static PP_Resource CreateWheelInputEvent(ResourceObjectType type,
129 PP_Instance instance,
130 PP_TimeTicks time_stamp,
131 uint32_t modifiers,
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,
139 uint32_t modifiers);
141 private:
142 InputEventData data_;
144 DISALLOW_IMPLICIT_CONSTRUCTORS(PPB_InputEvent_Shared);
147 } // namespace ppapi
149 #endif // PPAPI_SHARED_IMPL_PPB_INPUT_EVENT_SHARED_H_