OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/shared_impl/ppb_input_event_shared.h" | 5 #include "ppapi/shared_impl/ppb_input_event_shared.h" |
6 | 6 |
7 #include "ppapi/shared_impl/var.h" | 7 #include "ppapi/shared_impl/var.h" |
8 | 8 |
9 using ppapi::thunk::PPB_InputEvent_API; | 9 using ppapi::thunk::PPB_InputEvent_API; |
10 | 10 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 return data_.composition_target_segment; | 120 return data_.composition_target_segment; |
121 } | 121 } |
122 | 122 |
123 void PPB_InputEvent_Shared::GetIMESelection(uint32_t* start, uint32_t* end) { | 123 void PPB_InputEvent_Shared::GetIMESelection(uint32_t* start, uint32_t* end) { |
124 if (start) | 124 if (start) |
125 *start = data_.composition_selection_start; | 125 *start = data_.composition_selection_start; |
126 if (end) | 126 if (end) |
127 *end = data_.composition_selection_end; | 127 *end = data_.composition_selection_end; |
128 } | 128 } |
129 | 129 |
| 130 //static |
| 131 PP_Resource PPB_InputEvent_Shared::CreateIMEInputEvent( |
| 132 ResourceObjectType type, |
| 133 PP_Instance instance, |
| 134 PP_InputEvent_Type event_type, |
| 135 PP_TimeTicks time_stamp, |
| 136 struct PP_Var text, |
| 137 uint32_t segment_number, |
| 138 const uint32_t* segment_offsets, |
| 139 int32_t target_segment, |
| 140 uint32_t selection_start, |
| 141 uint32_t selection_end) { |
| 142 if (event_type != PP_INPUTEVENT_TYPE_IME_COMPOSITION_START && |
| 143 event_type != PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE && |
| 144 event_type != PP_INPUTEVENT_TYPE_IME_COMPOSITION_END && |
| 145 event_type != PP_INPUTEVENT_TYPE_IME_TEXT) |
| 146 return 0; |
| 147 |
| 148 InputEventData data; |
| 149 data.event_type = event_type; |
| 150 data.event_time_stamp = time_stamp; |
| 151 if (text.type == PP_VARTYPE_STRING) { |
| 152 StringVar* text_str = StringVar::FromPPVar(text); |
| 153 if (!text_str) |
| 154 return 0; |
| 155 data.character_text = text_str->value(); |
| 156 } |
| 157 data.composition_target_segment = target_segment; |
| 158 if (segment_number != 0) { |
| 159 data.composition_segment_offsets.assign( |
| 160 &segment_offsets[0], &segment_offsets[segment_number + 1]); |
| 161 } |
| 162 data.composition_selection_start = selection_start; |
| 163 data.composition_selection_end = selection_end; |
| 164 |
| 165 return (new PPB_InputEvent_Shared(type, instance, data))->GetReference(); |
| 166 } |
| 167 |
| 168 //static |
| 169 PP_Resource PPB_InputEvent_Shared::CreateKeyboardInputEvent( |
| 170 ResourceObjectType type, |
| 171 PP_Instance instance, |
| 172 PP_InputEvent_Type event_type, |
| 173 PP_TimeTicks time_stamp, |
| 174 uint32_t modifiers, |
| 175 uint32_t key_code, |
| 176 struct PP_Var character_text) { |
| 177 if (event_type != PP_INPUTEVENT_TYPE_RAWKEYDOWN && |
| 178 event_type != PP_INPUTEVENT_TYPE_KEYDOWN && |
| 179 event_type != PP_INPUTEVENT_TYPE_KEYUP && |
| 180 event_type != PP_INPUTEVENT_TYPE_CHAR) |
| 181 return 0; |
| 182 |
| 183 InputEventData data; |
| 184 data.event_type = event_type; |
| 185 data.event_time_stamp = time_stamp; |
| 186 data.event_modifiers = modifiers; |
| 187 data.key_code = key_code; |
| 188 if (character_text.type == PP_VARTYPE_STRING) { |
| 189 StringVar* text_str = StringVar::FromPPVar(character_text); |
| 190 if (!text_str) |
| 191 return 0; |
| 192 data.character_text = text_str->value(); |
| 193 } |
| 194 |
| 195 return (new PPB_InputEvent_Shared(type, instance, data))->GetReference(); |
| 196 } |
| 197 |
| 198 //static |
| 199 PP_Resource PPB_InputEvent_Shared::CreateMouseInputEvent( |
| 200 ResourceObjectType type, |
| 201 PP_Instance instance, |
| 202 PP_InputEvent_Type event_type, |
| 203 PP_TimeTicks time_stamp, |
| 204 uint32_t modifiers, |
| 205 PP_InputEvent_MouseButton mouse_button, |
| 206 const PP_Point* mouse_position, |
| 207 int32_t click_count, |
| 208 const PP_Point* mouse_movement) { |
| 209 if (event_type != PP_INPUTEVENT_TYPE_MOUSEDOWN && |
| 210 event_type != PP_INPUTEVENT_TYPE_MOUSEUP && |
| 211 event_type != PP_INPUTEVENT_TYPE_MOUSEMOVE && |
| 212 event_type != PP_INPUTEVENT_TYPE_MOUSEENTER && |
| 213 event_type != PP_INPUTEVENT_TYPE_MOUSELEAVE) |
| 214 return 0; |
| 215 |
| 216 InputEventData data; |
| 217 data.event_type = event_type; |
| 218 data.event_time_stamp = time_stamp; |
| 219 data.event_modifiers = modifiers; |
| 220 data.mouse_button = mouse_button; |
| 221 data.mouse_position = *mouse_position; |
| 222 data.mouse_click_count = click_count; |
| 223 data.mouse_movement = *mouse_movement; |
| 224 |
| 225 return (new PPB_InputEvent_Shared(type, instance, data))->GetReference(); |
| 226 } |
| 227 |
| 228 //static |
| 229 PP_Resource PPB_InputEvent_Shared::CreateWheelInputEvent( |
| 230 ResourceObjectType type, |
| 231 PP_Instance instance, |
| 232 PP_TimeTicks time_stamp, |
| 233 uint32_t modifiers, |
| 234 const PP_FloatPoint* wheel_delta, |
| 235 const PP_FloatPoint* wheel_ticks, |
| 236 PP_Bool scroll_by_page) { |
| 237 InputEventData data; |
| 238 data.event_type = PP_INPUTEVENT_TYPE_WHEEL; |
| 239 data.event_time_stamp = time_stamp; |
| 240 data.event_modifiers = modifiers; |
| 241 data.wheel_delta = *wheel_delta; |
| 242 data.wheel_ticks = *wheel_ticks; |
| 243 data.wheel_scroll_by_page = PP_ToBool(scroll_by_page); |
| 244 |
| 245 return (new PPB_InputEvent_Shared(type, instance, data))->GetReference(); |
| 246 } |
| 247 |
130 } // namespace ppapi | 248 } // namespace ppapi |
OLD | NEW |