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/cpp/input_event.h" | 5 #include "ppapi/cpp/input_event.h" |
6 | 6 |
7 #include "ppapi/cpp/instance_handle.h" | 7 #include "ppapi/cpp/instance_handle.h" |
8 #include "ppapi/cpp/module.h" | 8 #include "ppapi/cpp/module.h" |
9 #include "ppapi/cpp/module_impl.h" | 9 #include "ppapi/cpp/module_impl.h" |
10 #include "ppapi/cpp/point.h" | 10 #include "ppapi/cpp/point.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 } | 28 } |
29 | 29 |
30 template <> const char* interface_name<PPB_WheelInputEvent_1_0>() { | 30 template <> const char* interface_name<PPB_WheelInputEvent_1_0>() { |
31 return PPB_WHEEL_INPUT_EVENT_INTERFACE_1_0; | 31 return PPB_WHEEL_INPUT_EVENT_INTERFACE_1_0; |
32 } | 32 } |
33 | 33 |
34 template <> const char* interface_name<PPB_TouchInputEvent_1_0>() { | 34 template <> const char* interface_name<PPB_TouchInputEvent_1_0>() { |
35 return PPB_TOUCH_INPUT_EVENT_INTERFACE_1_0; | 35 return PPB_TOUCH_INPUT_EVENT_INTERFACE_1_0; |
36 } | 36 } |
37 | 37 |
| 38 template <> const char* interface_name<PPB_IMEInputEvent_1_0>() { |
| 39 return PPB_IME_INPUT_EVENT_INTERFACE_1_0; |
| 40 } |
| 41 |
38 } // namespace | 42 } // namespace |
39 | 43 |
40 // InputEvent ------------------------------------------------------------------ | 44 // InputEvent ------------------------------------------------------------------ |
41 | 45 |
42 InputEvent::InputEvent() : Resource() { | 46 InputEvent::InputEvent() : Resource() { |
43 } | 47 } |
44 | 48 |
45 InputEvent::InputEvent(PP_Resource input_event_resource) : Resource() { | 49 InputEvent::InputEvent(PP_Resource input_event_resource) : Resource() { |
46 // Type check the input event before setting it. | 50 // Type check the input event before setting it. |
47 if (!has_interface<PPB_InputEvent_1_0>()) | 51 if (!has_interface<PPB_InputEvent_1_0>()) |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 } | 277 } |
274 | 278 |
275 TouchPoint TouchInputEvent::GetTouchByIndex(PP_TouchListType list, | 279 TouchPoint TouchInputEvent::GetTouchByIndex(PP_TouchListType list, |
276 uint32_t index) const { | 280 uint32_t index) const { |
277 if (!has_interface<PPB_TouchInputEvent_1_0>()) | 281 if (!has_interface<PPB_TouchInputEvent_1_0>()) |
278 return TouchPoint(); | 282 return TouchPoint(); |
279 return TouchPoint(get_interface<PPB_TouchInputEvent_1_0>()-> | 283 return TouchPoint(get_interface<PPB_TouchInputEvent_1_0>()-> |
280 GetTouchByIndex(pp_resource(), list, index)); | 284 GetTouchByIndex(pp_resource(), list, index)); |
281 } | 285 } |
282 | 286 |
| 287 // IMEInputEvent ------------------------------------------------------- |
| 288 |
| 289 IMEInputEvent::IMEInputEvent() : InputEvent() { |
| 290 } |
| 291 |
| 292 IMEInputEvent::IMEInputEvent(const InputEvent& event) : InputEvent() { |
| 293 bool is_ime_event = false; |
| 294 if (has_interface<PPB_IMEInputEvent_1_0>()) { |
| 295 if (get_interface<PPB_IMEInputEvent_1_0>()->IsIMEInputEvent( |
| 296 event.pp_resource())) { |
| 297 is_ime_event = true; |
| 298 } |
| 299 } |
| 300 if (is_ime_event) { |
| 301 Module::Get()->core()->AddRefResource(event.pp_resource()); |
| 302 PassRefFromConstructor(event.pp_resource()); |
| 303 } |
| 304 } |
| 305 |
| 306 IMEInputEvent::IMEInputEvent( |
| 307 const InstanceHandle& instance, |
| 308 PP_InputEvent_Type type, |
| 309 PP_TimeTicks time_stamp, |
| 310 const Var& text, |
| 311 const std::vector<uint32_t>& segment_offsets, |
| 312 int32_t target_segment, |
| 313 const std::pair<uint32_t, uint32_t>& selection) : InputEvent() { |
| 314 if (!has_interface<PPB_IMEInputEvent_1_0>()) |
| 315 return; |
| 316 uint32_t dummy = 0; |
| 317 PassRefFromConstructor(get_interface<PPB_IMEInputEvent_1_0>()->Create( |
| 318 instance.pp_instance(), type, time_stamp, text.pp_var(), |
| 319 segment_offsets.empty() ? 0 : segment_offsets.size() - 1, |
| 320 segment_offsets.empty() ? &dummy : &segment_offsets[0], |
| 321 target_segment, selection.first, selection.second)); |
| 322 } |
| 323 |
| 324 |
| 325 Var IMEInputEvent::GetText() const { |
| 326 if (has_interface<PPB_IMEInputEvent_1_0>()) { |
| 327 return Var(PASS_REF, |
| 328 get_interface<PPB_IMEInputEvent_1_0>()->GetText( |
| 329 pp_resource())); |
| 330 } |
| 331 return Var(); |
| 332 } |
| 333 |
| 334 uint32_t IMEInputEvent::GetSegmentNumber() const { |
| 335 if (has_interface<PPB_IMEInputEvent_1_0>()) { |
| 336 return get_interface<PPB_IMEInputEvent_1_0>()->GetSegmentNumber( |
| 337 pp_resource()); |
| 338 } |
| 339 return 0; |
| 340 } |
| 341 |
| 342 uint32_t IMEInputEvent::GetSegmentOffset(uint32_t index) const { |
| 343 if (has_interface<PPB_IMEInputEvent_1_0>()) { |
| 344 return get_interface<PPB_IMEInputEvent_1_0>()->GetSegmentOffset( |
| 345 pp_resource(), index); |
| 346 } |
| 347 return 0; |
| 348 } |
| 349 |
| 350 int32_t IMEInputEvent::GetTargetSegment() const { |
| 351 if (has_interface<PPB_IMEInputEvent_1_0>()) { |
| 352 return get_interface<PPB_IMEInputEvent_1_0>()->GetTargetSegment( |
| 353 pp_resource()); |
| 354 } |
| 355 return 0; |
| 356 } |
| 357 |
| 358 std::pair<uint32_t, uint32_t> IMEInputEvent::GetSelection() const { |
| 359 std::pair<uint32_t, uint32_t> range(0, 0); |
| 360 if (has_interface<PPB_IMEInputEvent_1_0>()) { |
| 361 get_interface<PPB_IMEInputEvent_1_0>()->GetSelection(pp_resource(), |
| 362 &range.first, |
| 363 &range.second); |
| 364 } |
| 365 return range; |
| 366 } |
| 367 |
283 } // namespace pp | 368 } // namespace pp |
OLD | NEW |