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. 4 5 #ifndef PPAPI_SHARED_IMPL_PPB_INPUT_EVENT_SHARED_H_ 6 #define PPAPI_SHARED_IMPL_PPB_INPUT_EVENT_SHARED_H_ 7 8 #include <string> 9 #include <vector> 10 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" 16 17 namespace ppapi { 18 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(); 25 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; 29 30 PP_InputEvent_Type event_type; 31 PP_TimeTicks event_time_stamp; 32 uint32_t event_modifiers; 33 34 PP_InputEvent_MouseButton mouse_button; 35 PP_Point mouse_position; 36 int32_t mouse_click_count; 37 PP_Point mouse_movement; 38 39 PP_FloatPoint wheel_delta; 40 PP_FloatPoint wheel_ticks; 41 bool wheel_scroll_by_page; 42 43 uint32_t key_code; 44 uint32_t usb_key_code; 45 46 // The key event's |code| attribute as defined in: 47 // http://www.w3.org/TR/uievents/ 48 std::string code; 49 50 std::string character_text; 51 52 std::vector<uint32_t> composition_segment_offsets; 53 int32_t composition_target_segment; 54 uint32_t composition_selection_start; 55 uint32_t composition_selection_end; 56 57 std::vector<PP_TouchPoint> touches; 58 std::vector<PP_TouchPoint> changed_touches; 59 std::vector<PP_TouchPoint> target_touches; 60 }; 61 62 // This simple class implements the PPB_InputEvent_API in terms of the 63 // shared InputEventData structure 64 class PPAPI_SHARED_EXPORT PPB_InputEvent_Shared 65 : public Resource, 66 public thunk::PPB_InputEvent_API { 67 public: 68 PPB_InputEvent_Shared(ResourceObjectType type, 69 PP_Instance instance, 70 const InputEventData& data); 71 72 // Resource overrides. 73 virtual PPB_InputEvent_API* AsPPB_InputEvent_API() OVERRIDE; 74 75 // PPB_InputEvent_API implementation. 76 virtual const InputEventData& GetInputEventData() const OVERRIDE; 77 virtual PP_InputEvent_Type GetType() OVERRIDE; 78 virtual PP_TimeTicks GetTimeStamp() OVERRIDE; 79 virtual uint32_t GetModifiers() OVERRIDE; 80 virtual PP_InputEvent_MouseButton GetMouseButton() OVERRIDE; 81 virtual PP_Point GetMousePosition() OVERRIDE; 82 virtual int32_t GetMouseClickCount() OVERRIDE; 83 virtual PP_Point GetMouseMovement() OVERRIDE; 84 virtual PP_FloatPoint GetWheelDelta() OVERRIDE; 85 virtual PP_FloatPoint GetWheelTicks() OVERRIDE; 86 virtual PP_Bool GetWheelScrollByPage() OVERRIDE; 87 virtual uint32_t GetKeyCode() OVERRIDE; 88 virtual PP_Var GetCharacterText() OVERRIDE; 89 virtual PP_Bool SetUsbKeyCode(uint32_t usb_key_code) OVERRIDE; 90 virtual uint32_t GetUsbKeyCode() OVERRIDE; 91 virtual PP_Var GetCode() OVERRIDE; 92 virtual uint32_t GetIMESegmentNumber() OVERRIDE; 93 virtual uint32_t GetIMESegmentOffset(uint32_t index) OVERRIDE; 94 virtual int32_t GetIMETargetSegment() OVERRIDE; 95 virtual void GetIMESelection(uint32_t* start, uint32_t* end) OVERRIDE; 96 virtual void AddTouchPoint(PP_TouchListType list, 97 const PP_TouchPoint& point) OVERRIDE; 98 virtual uint32_t GetTouchCount(PP_TouchListType list) OVERRIDE; 99 virtual PP_TouchPoint GetTouchByIndex(PP_TouchListType list, 100 uint32_t index) OVERRIDE; 101 virtual PP_TouchPoint GetTouchById(PP_TouchListType list, 102 uint32_t id) OVERRIDE; 103 104 // Implementations for event creation. 105 static PP_Resource CreateIMEInputEvent(ResourceObjectType type, 106 PP_Instance instance, 107 PP_InputEvent_Type event_type, 108 PP_TimeTicks time_stamp, 109 struct PP_Var text, 110 uint32_t segment_number, 111 const uint32_t* segment_offsets, 112 int32_t target_segment, 113 uint32_t selection_start, 114 uint32_t selection_end); 115 static PP_Resource CreateKeyboardInputEvent(ResourceObjectType type, 116 PP_Instance instance, 117 PP_InputEvent_Type event_type, 118 PP_TimeTicks time_stamp, 119 uint32_t modifiers, 120 uint32_t key_code, 121 struct PP_Var character_text); 122 static PP_Resource CreateMouseInputEvent( 123 ResourceObjectType type, 124 PP_Instance instance, 125 PP_InputEvent_Type event_type, 126 PP_TimeTicks time_stamp, 127 uint32_t modifiers, 128 PP_InputEvent_MouseButton mouse_button, 129 const PP_Point* mouse_position, 130 int32_t click_count, 131 const PP_Point* mouse_movement); 132 static PP_Resource CreateWheelInputEvent(ResourceObjectType type, 133 PP_Instance instance, 134 PP_TimeTicks time_stamp, 135 uint32_t modifiers, 136 const PP_FloatPoint* wheel_delta, 137 const PP_FloatPoint* wheel_ticks, 138 PP_Bool scroll_by_page); 139 static PP_Resource CreateTouchInputEvent(ResourceObjectType type, 140 PP_Instance instance, 141 PP_InputEvent_Type event_type, 142 PP_TimeTicks time_stamp, 143 uint32_t modifiers); 144 145 private: 146 InputEventData data_; 147 148 DISALLOW_IMPLICIT_CONSTRUCTORS(PPB_InputEvent_Shared); 149 }; 150 151 } // namespace ppapi 152 153 #endif // PPAPI_SHARED_IMPL_PPB_INPUT_EVENT_SHARED_H_ 154