[email protected] | 9a57839 | 2011-12-07 18:59:27 | [diff] [blame] | 1 | // Copyright (c) 2011 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 | #include "ppapi/shared_impl/ppb_input_event_shared.h" |
| 6 | |
[email protected] | 9a57839 | 2011-12-07 18:59:27 | [diff] [blame] | 7 | #include "ppapi/shared_impl/var.h" |
| 8 | |
| 9 | using ppapi::thunk::PPB_InputEvent_API; |
| 10 | |
| 11 | namespace ppapi { |
| 12 | |
| 13 | InputEventData::InputEventData() |
| 14 | : is_filtered(false), |
| 15 | event_type(PP_INPUTEVENT_TYPE_UNDEFINED), |
| 16 | event_time_stamp(0.0), |
| 17 | event_modifiers(0), |
| 18 | mouse_button(PP_INPUTEVENT_MOUSEBUTTON_NONE), |
| 19 | mouse_position(PP_MakePoint(0, 0)), |
| 20 | mouse_click_count(0), |
| 21 | mouse_movement(PP_MakePoint(0, 0)), |
| 22 | wheel_delta(PP_MakeFloatPoint(0.0f, 0.0f)), |
| 23 | wheel_ticks(PP_MakeFloatPoint(0.0f, 0.0f)), |
| 24 | wheel_scroll_by_page(false), |
| 25 | key_code(0), |
| 26 | character_text(), |
| 27 | composition_target_segment(-1), |
| 28 | composition_selection_start(0), |
| 29 | composition_selection_end(0) { |
| 30 | } |
| 31 | |
| 32 | InputEventData::~InputEventData() { |
| 33 | } |
| 34 | |
| 35 | PPB_InputEvent_Shared::PPB_InputEvent_Shared(const InitAsImpl&, |
| 36 | PP_Instance instance, |
| 37 | const InputEventData& data) |
| 38 | : Resource(instance), |
| 39 | data_(data) { |
| 40 | } |
| 41 | |
| 42 | PPB_InputEvent_Shared::PPB_InputEvent_Shared(const InitAsProxy&, |
| 43 | PP_Instance instance, |
| 44 | const InputEventData& data) |
| 45 | : Resource(HostResource::MakeInstanceOnly(instance)), |
| 46 | data_(data) { |
| 47 | } |
| 48 | |
| 49 | PPB_InputEvent_API* PPB_InputEvent_Shared::AsPPB_InputEvent_API() { |
| 50 | return this; |
| 51 | } |
| 52 | |
| 53 | const InputEventData& PPB_InputEvent_Shared::GetInputEventData() const { |
| 54 | return data_; |
| 55 | } |
| 56 | |
| 57 | PP_InputEvent_Type PPB_InputEvent_Shared::GetType() { |
| 58 | return data_.event_type; |
| 59 | } |
| 60 | |
| 61 | PP_TimeTicks PPB_InputEvent_Shared::GetTimeStamp() { |
| 62 | return data_.event_time_stamp; |
| 63 | } |
| 64 | |
| 65 | uint32_t PPB_InputEvent_Shared::GetModifiers() { |
| 66 | return data_.event_modifiers; |
| 67 | } |
| 68 | |
| 69 | PP_InputEvent_MouseButton PPB_InputEvent_Shared::GetMouseButton() { |
| 70 | return data_.mouse_button; |
| 71 | } |
| 72 | |
| 73 | PP_Point PPB_InputEvent_Shared::GetMousePosition() { |
| 74 | return data_.mouse_position; |
| 75 | } |
| 76 | |
| 77 | int32_t PPB_InputEvent_Shared::GetMouseClickCount() { |
| 78 | return data_.mouse_click_count; |
| 79 | } |
| 80 | |
| 81 | PP_Point PPB_InputEvent_Shared::GetMouseMovement() { |
| 82 | return data_.mouse_movement; |
| 83 | } |
| 84 | |
| 85 | PP_FloatPoint PPB_InputEvent_Shared::GetWheelDelta() { |
| 86 | return data_.wheel_delta; |
| 87 | } |
| 88 | |
| 89 | PP_FloatPoint PPB_InputEvent_Shared::GetWheelTicks() { |
| 90 | return data_.wheel_ticks; |
| 91 | } |
| 92 | |
| 93 | PP_Bool PPB_InputEvent_Shared::GetWheelScrollByPage() { |
| 94 | return PP_FromBool(data_.wheel_scroll_by_page); |
| 95 | } |
| 96 | |
| 97 | uint32_t PPB_InputEvent_Shared::GetKeyCode() { |
| 98 | return data_.key_code; |
| 99 | } |
| 100 | |
| 101 | PP_Var PPB_InputEvent_Shared::GetCharacterText() { |
[email protected] | 872caf56 | 2011-12-07 22:50:43 | [diff] [blame] | 102 | return StringVar::StringToPPVar(data_.character_text); |
[email protected] | 9a57839 | 2011-12-07 18:59:27 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | uint32_t PPB_InputEvent_Shared::GetIMESegmentNumber() { |
| 106 | if (data_.composition_segment_offsets.empty()) |
| 107 | return 0; |
| 108 | return data_.composition_segment_offsets.size() - 1; |
| 109 | } |
| 110 | |
| 111 | uint32_t PPB_InputEvent_Shared::GetIMESegmentOffset(uint32_t index) { |
| 112 | if (index >= data_.composition_segment_offsets.size()) |
| 113 | return 0; |
| 114 | return data_.composition_segment_offsets[index]; |
| 115 | } |
| 116 | |
| 117 | int32_t PPB_InputEvent_Shared::GetIMETargetSegment() { |
| 118 | return data_.composition_target_segment; |
| 119 | } |
| 120 | |
| 121 | void PPB_InputEvent_Shared::GetIMESelection(uint32_t* start, uint32_t* end) { |
| 122 | if (start) |
| 123 | *start = data_.composition_selection_start; |
| 124 | if (end) |
| 125 | *end = data_.composition_selection_end; |
| 126 | } |
| 127 | |
| 128 | } // namespace ppapi |