[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 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/cpp/input_event.h" |
| 6 | |
[email protected] | 09af0f7 | 2012-02-27 20:23:19 | [diff] [blame] | 7 | #include "ppapi/cpp/instance_handle.h" |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 8 | #include "ppapi/cpp/module.h" |
| 9 | #include "ppapi/cpp/module_impl.h" |
| 10 | #include "ppapi/cpp/point.h" |
[email protected] | cdf4e91 | 2012-06-21 23:15:10 | [diff] [blame] | 11 | #include "ppapi/cpp/touch_point.h" |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 12 | #include "ppapi/cpp/var.h" |
| 13 | |
| 14 | namespace pp { |
| 15 | |
| 16 | namespace { |
| 17 | |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 18 | template <> const char* interface_name<PPB_InputEvent_1_0>() { |
| 19 | return PPB_INPUT_EVENT_INTERFACE_1_0; |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 20 | } |
| 21 | |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 22 | template <> const char* interface_name<PPB_KeyboardInputEvent_1_0>() { |
| 23 | return PPB_KEYBOARD_INPUT_EVENT_INTERFACE_1_0; |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 24 | } |
| 25 | |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 26 | template <> const char* interface_name<PPB_MouseInputEvent_1_1>() { |
| 27 | return PPB_MOUSE_INPUT_EVENT_INTERFACE_1_1; |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 28 | } |
| 29 | |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 30 | template <> const char* interface_name<PPB_WheelInputEvent_1_0>() { |
| 31 | return PPB_WHEEL_INPUT_EVENT_INTERFACE_1_0; |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 32 | } |
| 33 | |
[email protected] | 3bb9c6ac | 2012-08-26 11:58:20 | [diff] [blame] | 34 | template <> const char* interface_name<PPB_TouchInputEvent_1_0>() { |
| 35 | return PPB_TOUCH_INPUT_EVENT_INTERFACE_1_0; |
| 36 | } |
| 37 | |
[email protected] | 79cad34 | 2013-08-01 00:22:48 | [diff] [blame] | 38 | template <> const char* interface_name<PPB_IMEInputEvent_1_0>() { |
| 39 | return PPB_IME_INPUT_EVENT_INTERFACE_1_0; |
| 40 | } |
| 41 | |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 42 | } // namespace |
| 43 | |
| 44 | // InputEvent ------------------------------------------------------------------ |
| 45 | |
| 46 | InputEvent::InputEvent() : Resource() { |
| 47 | } |
| 48 | |
| 49 | InputEvent::InputEvent(PP_Resource input_event_resource) : Resource() { |
| 50 | // Type check the input event before setting it. |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 51 | if (!has_interface<PPB_InputEvent_1_0>()) |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 52 | return; |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 53 | if (get_interface<PPB_InputEvent_1_0>()->IsInputEvent(input_event_resource)) { |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 54 | Module::Get()->core()->AddRefResource(input_event_resource); |
| 55 | PassRefFromConstructor(input_event_resource); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | InputEvent::~InputEvent() { |
| 60 | } |
| 61 | |
| 62 | PP_InputEvent_Type InputEvent::GetType() const { |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 63 | if (!has_interface<PPB_InputEvent_1_0>()) |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 64 | return PP_INPUTEVENT_TYPE_UNDEFINED; |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 65 | return get_interface<PPB_InputEvent_1_0>()->GetType(pp_resource()); |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | PP_TimeTicks InputEvent::GetTimeStamp() const { |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 69 | if (!has_interface<PPB_InputEvent_1_0>()) |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 70 | return 0.0f; |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 71 | return get_interface<PPB_InputEvent_1_0>()->GetTimeStamp(pp_resource()); |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | uint32_t InputEvent::GetModifiers() const { |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 75 | if (!has_interface<PPB_InputEvent_1_0>()) |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 76 | return 0; |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 77 | return get_interface<PPB_InputEvent_1_0>()->GetModifiers(pp_resource()); |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | // MouseInputEvent ------------------------------------------------------------- |
| 81 | |
| 82 | MouseInputEvent::MouseInputEvent() : InputEvent() { |
| 83 | } |
| 84 | |
| 85 | MouseInputEvent::MouseInputEvent(const InputEvent& event) : InputEvent() { |
| 86 | // Type check the input event before setting it. |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 87 | if (!has_interface<PPB_MouseInputEvent_1_1>()) |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 88 | return; |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 89 | if (get_interface<PPB_MouseInputEvent_1_1>()->IsMouseInputEvent( |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 90 | event.pp_resource())) { |
| 91 | Module::Get()->core()->AddRefResource(event.pp_resource()); |
| 92 | PassRefFromConstructor(event.pp_resource()); |
| 93 | } |
| 94 | } |
| 95 | |
[email protected] | 09af0f7 | 2012-02-27 20:23:19 | [diff] [blame] | 96 | MouseInputEvent::MouseInputEvent(const InstanceHandle& instance, |
[email protected] | aa0c865 | 2011-07-19 19:33:55 | [diff] [blame] | 97 | PP_InputEvent_Type type, |
| 98 | PP_TimeTicks time_stamp, |
| 99 | uint32_t modifiers, |
| 100 | PP_InputEvent_MouseButton mouse_button, |
| 101 | const Point& mouse_position, |
[email protected] | 8047326 | 2011-08-31 17:15:18 | [diff] [blame] | 102 | int32_t click_count, |
| 103 | const Point& mouse_movement) { |
[email protected] | aa0c865 | 2011-07-19 19:33:55 | [diff] [blame] | 104 | // Type check the input event before setting it. |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 105 | if (!has_interface<PPB_MouseInputEvent_1_1>()) |
[email protected] | aa0c865 | 2011-07-19 19:33:55 | [diff] [blame] | 106 | return; |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 107 | PassRefFromConstructor(get_interface<PPB_MouseInputEvent_1_1>()->Create( |
[email protected] | 09af0f7 | 2012-02-27 20:23:19 | [diff] [blame] | 108 | instance.pp_instance(), type, time_stamp, modifiers, mouse_button, |
[email protected] | 8047326 | 2011-08-31 17:15:18 | [diff] [blame] | 109 | &mouse_position.pp_point(), click_count, &mouse_movement.pp_point())); |
[email protected] | aa0c865 | 2011-07-19 19:33:55 | [diff] [blame] | 110 | } |
| 111 | |
[email protected] | d912c698 | 2011-07-20 22:04:32 | [diff] [blame] | 112 | PP_InputEvent_MouseButton MouseInputEvent::GetButton() const { |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 113 | if (!has_interface<PPB_MouseInputEvent_1_1>()) |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 114 | return PP_INPUTEVENT_MOUSEBUTTON_NONE; |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 115 | return get_interface<PPB_MouseInputEvent_1_1>()->GetButton(pp_resource()); |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 116 | } |
| 117 | |
[email protected] | d912c698 | 2011-07-20 22:04:32 | [diff] [blame] | 118 | Point MouseInputEvent::GetPosition() const { |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 119 | if (!has_interface<PPB_MouseInputEvent_1_1>()) |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 120 | return Point(); |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 121 | return get_interface<PPB_MouseInputEvent_1_1>()->GetPosition(pp_resource()); |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 122 | } |
| 123 | |
[email protected] | d912c698 | 2011-07-20 22:04:32 | [diff] [blame] | 124 | int32_t MouseInputEvent::GetClickCount() const { |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 125 | if (!has_interface<PPB_MouseInputEvent_1_1>()) |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 126 | return 0; |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 127 | return get_interface<PPB_MouseInputEvent_1_1>()->GetClickCount(pp_resource()); |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 128 | } |
| 129 | |
[email protected] | 8047326 | 2011-08-31 17:15:18 | [diff] [blame] | 130 | Point MouseInputEvent::GetMovement() const { |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 131 | if (!has_interface<PPB_MouseInputEvent_1_1>()) |
[email protected] | 8047326 | 2011-08-31 17:15:18 | [diff] [blame] | 132 | return Point(); |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 133 | return get_interface<PPB_MouseInputEvent_1_1>()->GetMovement(pp_resource()); |
[email protected] | 8047326 | 2011-08-31 17:15:18 | [diff] [blame] | 134 | } |
| 135 | |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 136 | // WheelInputEvent ------------------------------------------------------------- |
| 137 | |
| 138 | WheelInputEvent::WheelInputEvent() : InputEvent() { |
| 139 | } |
| 140 | |
| 141 | WheelInputEvent::WheelInputEvent(const InputEvent& event) : InputEvent() { |
| 142 | // Type check the input event before setting it. |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 143 | if (!has_interface<PPB_WheelInputEvent_1_0>()) |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 144 | return; |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 145 | if (get_interface<PPB_WheelInputEvent_1_0>()->IsWheelInputEvent( |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 146 | event.pp_resource())) { |
| 147 | Module::Get()->core()->AddRefResource(event.pp_resource()); |
| 148 | PassRefFromConstructor(event.pp_resource()); |
| 149 | } |
| 150 | } |
| 151 | |
[email protected] | 09af0f7 | 2012-02-27 20:23:19 | [diff] [blame] | 152 | WheelInputEvent::WheelInputEvent(const InstanceHandle& instance, |
[email protected] | aa0c865 | 2011-07-19 19:33:55 | [diff] [blame] | 153 | PP_TimeTicks time_stamp, |
| 154 | uint32_t modifiers, |
| 155 | const FloatPoint& wheel_delta, |
| 156 | const FloatPoint& wheel_ticks, |
| 157 | bool scroll_by_page) { |
| 158 | // Type check the input event before setting it. |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 159 | if (!has_interface<PPB_WheelInputEvent_1_0>()) |
[email protected] | aa0c865 | 2011-07-19 19:33:55 | [diff] [blame] | 160 | return; |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 161 | PassRefFromConstructor(get_interface<PPB_WheelInputEvent_1_0>()->Create( |
[email protected] | 09af0f7 | 2012-02-27 20:23:19 | [diff] [blame] | 162 | instance.pp_instance(), time_stamp, modifiers, |
[email protected] | d912c698 | 2011-07-20 22:04:32 | [diff] [blame] | 163 | &wheel_delta.pp_float_point(), &wheel_ticks.pp_float_point(), |
| 164 | PP_FromBool(scroll_by_page))); |
[email protected] | aa0c865 | 2011-07-19 19:33:55 | [diff] [blame] | 165 | } |
| 166 | |
[email protected] | d912c698 | 2011-07-20 22:04:32 | [diff] [blame] | 167 | FloatPoint WheelInputEvent::GetDelta() const { |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 168 | if (!has_interface<PPB_WheelInputEvent_1_0>()) |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 169 | return FloatPoint(); |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 170 | return get_interface<PPB_WheelInputEvent_1_0>()->GetDelta(pp_resource()); |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 171 | } |
| 172 | |
[email protected] | d912c698 | 2011-07-20 22:04:32 | [diff] [blame] | 173 | FloatPoint WheelInputEvent::GetTicks() const { |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 174 | if (!has_interface<PPB_WheelInputEvent_1_0>()) |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 175 | return FloatPoint(); |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 176 | return get_interface<PPB_WheelInputEvent_1_0>()->GetTicks(pp_resource()); |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | bool WheelInputEvent::GetScrollByPage() const { |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 180 | if (!has_interface<PPB_WheelInputEvent_1_0>()) |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 181 | return false; |
| 182 | return PP_ToBool( |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 183 | get_interface<PPB_WheelInputEvent_1_0>()->GetScrollByPage(pp_resource())); |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | // KeyboardInputEvent ---------------------------------------------------------- |
| 187 | |
| 188 | KeyboardInputEvent::KeyboardInputEvent() : InputEvent() { |
| 189 | } |
| 190 | |
| 191 | KeyboardInputEvent::KeyboardInputEvent(const InputEvent& event) : InputEvent() { |
| 192 | // Type check the input event before setting it. |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 193 | if (!has_interface<PPB_KeyboardInputEvent_1_0>()) |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 194 | return; |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 195 | if (get_interface<PPB_KeyboardInputEvent_1_0>()->IsKeyboardInputEvent( |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 196 | event.pp_resource())) { |
| 197 | Module::Get()->core()->AddRefResource(event.pp_resource()); |
| 198 | PassRefFromConstructor(event.pp_resource()); |
| 199 | } |
| 200 | } |
| 201 | |
[email protected] | 09af0f7 | 2012-02-27 20:23:19 | [diff] [blame] | 202 | KeyboardInputEvent::KeyboardInputEvent(const InstanceHandle& instance, |
[email protected] | aa0c865 | 2011-07-19 19:33:55 | [diff] [blame] | 203 | PP_InputEvent_Type type, |
| 204 | PP_TimeTicks time_stamp, |
| 205 | uint32_t modifiers, |
| 206 | uint32_t key_code, |
| 207 | const Var& character_text) { |
| 208 | // Type check the input event before setting it. |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 209 | if (!has_interface<PPB_KeyboardInputEvent_1_0>()) |
[email protected] | aa0c865 | 2011-07-19 19:33:55 | [diff] [blame] | 210 | return; |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 211 | PassRefFromConstructor(get_interface<PPB_KeyboardInputEvent_1_0>()->Create( |
[email protected] | 09af0f7 | 2012-02-27 20:23:19 | [diff] [blame] | 212 | instance.pp_instance(), type, time_stamp, modifiers, key_code, |
[email protected] | aa0c865 | 2011-07-19 19:33:55 | [diff] [blame] | 213 | character_text.pp_var())); |
| 214 | } |
| 215 | |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 216 | uint32_t KeyboardInputEvent::GetKeyCode() const { |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 217 | if (!has_interface<PPB_KeyboardInputEvent_1_0>()) |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 218 | return 0; |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 219 | return get_interface<PPB_KeyboardInputEvent_1_0>()->GetKeyCode(pp_resource()); |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | Var KeyboardInputEvent::GetCharacterText() const { |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 223 | if (!has_interface<PPB_KeyboardInputEvent_1_0>()) |
[email protected] | ca5069f | 2011-07-09 05:39:35 | [diff] [blame] | 224 | return Var(); |
[email protected] | 09af0f7 | 2012-02-27 20:23:19 | [diff] [blame] | 225 | return Var(PASS_REF, |
[email protected] | 1c7e5c9 | 2012-03-22 00:58:28 | [diff] [blame] | 226 | get_interface<PPB_KeyboardInputEvent_1_0>()->GetCharacterText( |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 227 | pp_resource())); |
| 228 | } |
| 229 | |
[email protected] | cdf4e91 | 2012-06-21 23:15:10 | [diff] [blame] | 230 | // TouchInputEvent ------------------------------------------------------------ |
| 231 | TouchInputEvent::TouchInputEvent() : InputEvent() { |
| 232 | } |
| 233 | |
| 234 | TouchInputEvent::TouchInputEvent(const InputEvent& event) : InputEvent() { |
| 235 | if (!has_interface<PPB_TouchInputEvent_1_0>()) |
| 236 | return; |
| 237 | // Type check the input event before setting it. |
| 238 | if (get_interface<PPB_TouchInputEvent_1_0>()->IsTouchInputEvent( |
| 239 | event.pp_resource())) { |
| 240 | Module::Get()->core()->AddRefResource(event.pp_resource()); |
| 241 | PassRefFromConstructor(event.pp_resource()); |
| 242 | } |
| 243 | } |
| 244 | |
[email protected] | a549359 | 2012-08-30 05:49:26 | [diff] [blame] | 245 | TouchInputEvent::TouchInputEvent(const InstanceHandle& instance, |
| 246 | PP_InputEvent_Type type, |
| 247 | PP_TimeTicks time_stamp, |
| 248 | uint32_t modifiers) { |
| 249 | // Type check the input event before setting it. |
| 250 | if (!has_interface<PPB_TouchInputEvent_1_0>()) |
| 251 | return; |
| 252 | PassRefFromConstructor(get_interface<PPB_TouchInputEvent_1_0>()->Create( |
| 253 | instance.pp_instance(), type, time_stamp, modifiers)); |
| 254 | } |
| 255 | |
[email protected] | cdf4e91 | 2012-06-21 23:15:10 | [diff] [blame] | 256 | void TouchInputEvent::AddTouchPoint(PP_TouchListType list, |
| 257 | PP_TouchPoint point) { |
| 258 | if (!has_interface<PPB_TouchInputEvent_1_0>()) |
| 259 | return; |
| 260 | get_interface<PPB_TouchInputEvent_1_0>()->AddTouchPoint(pp_resource(), list, |
| 261 | &point); |
| 262 | } |
| 263 | |
| 264 | uint32_t TouchInputEvent::GetTouchCount(PP_TouchListType list) const { |
| 265 | if (!has_interface<PPB_TouchInputEvent_1_0>()) |
| 266 | return 0; |
| 267 | return get_interface<PPB_TouchInputEvent_1_0>()->GetTouchCount(pp_resource(), |
| 268 | list); |
| 269 | } |
| 270 | |
| 271 | TouchPoint TouchInputEvent::GetTouchById(PP_TouchListType list, |
| 272 | uint32_t id) const { |
| 273 | if (!has_interface<PPB_TouchInputEvent_1_0>()) |
| 274 | return TouchPoint(); |
| 275 | return TouchPoint(get_interface<PPB_TouchInputEvent_1_0>()-> |
| 276 | GetTouchById(pp_resource(), list, id)); |
| 277 | } |
| 278 | |
| 279 | TouchPoint TouchInputEvent::GetTouchByIndex(PP_TouchListType list, |
| 280 | uint32_t index) const { |
| 281 | if (!has_interface<PPB_TouchInputEvent_1_0>()) |
| 282 | return TouchPoint(); |
| 283 | return TouchPoint(get_interface<PPB_TouchInputEvent_1_0>()-> |
| 284 | GetTouchByIndex(pp_resource(), list, index)); |
| 285 | } |
| 286 | |
[email protected] | 79cad34 | 2013-08-01 00:22:48 | [diff] [blame] | 287 | // IMEInputEvent ------------------------------------------------------- |
| 288 | |
| 289 | IMEInputEvent::IMEInputEvent() : InputEvent() { |
| 290 | } |
| 291 | |
| 292 | IMEInputEvent::IMEInputEvent(const InputEvent& event) : InputEvent() { |
| 293 | if (has_interface<PPB_IMEInputEvent_1_0>()) { |
| 294 | if (get_interface<PPB_IMEInputEvent_1_0>()->IsIMEInputEvent( |
| 295 | event.pp_resource())) { |
| 296 | Module::Get()->core()->AddRefResource(event.pp_resource()); |
| 297 | PassRefFromConstructor(event.pp_resource()); |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | IMEInputEvent::IMEInputEvent( |
| 303 | const InstanceHandle& instance, |
| 304 | PP_InputEvent_Type type, |
| 305 | PP_TimeTicks time_stamp, |
| 306 | const Var& text, |
| 307 | const std::vector<uint32_t>& segment_offsets, |
| 308 | int32_t target_segment, |
| 309 | const std::pair<uint32_t, uint32_t>& selection) : InputEvent() { |
| 310 | if (!has_interface<PPB_IMEInputEvent_1_0>()) |
| 311 | return; |
| 312 | uint32_t dummy = 0; |
| 313 | PassRefFromConstructor(get_interface<PPB_IMEInputEvent_1_0>()->Create( |
| 314 | instance.pp_instance(), type, time_stamp, text.pp_var(), |
| 315 | segment_offsets.empty() ? 0 : segment_offsets.size() - 1, |
| 316 | segment_offsets.empty() ? &dummy : &segment_offsets[0], |
| 317 | target_segment, selection.first, selection.second)); |
| 318 | } |
| 319 | |
| 320 | |
| 321 | Var IMEInputEvent::GetText() const { |
| 322 | if (has_interface<PPB_IMEInputEvent_1_0>()) { |
| 323 | return Var(PASS_REF, |
| 324 | get_interface<PPB_IMEInputEvent_1_0>()->GetText( |
| 325 | pp_resource())); |
| 326 | } |
| 327 | return Var(); |
| 328 | } |
| 329 | |
| 330 | uint32_t IMEInputEvent::GetSegmentNumber() const { |
| 331 | if (has_interface<PPB_IMEInputEvent_1_0>()) { |
| 332 | return get_interface<PPB_IMEInputEvent_1_0>()->GetSegmentNumber( |
| 333 | pp_resource()); |
| 334 | } |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | uint32_t IMEInputEvent::GetSegmentOffset(uint32_t index) const { |
| 339 | if (has_interface<PPB_IMEInputEvent_1_0>()) { |
| 340 | return get_interface<PPB_IMEInputEvent_1_0>()->GetSegmentOffset( |
| 341 | pp_resource(), index); |
| 342 | } |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | int32_t IMEInputEvent::GetTargetSegment() const { |
| 347 | if (has_interface<PPB_IMEInputEvent_1_0>()) { |
| 348 | return get_interface<PPB_IMEInputEvent_1_0>()->GetTargetSegment( |
| 349 | pp_resource()); |
| 350 | } |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | void IMEInputEvent::GetSelection(uint32_t* start, uint32_t* end) const { |
| 355 | if (has_interface<PPB_IMEInputEvent_1_0>()) { |
| 356 | get_interface<PPB_IMEInputEvent_1_0>()->GetSelection(pp_resource(), |
| 357 | start, |
| 358 | end); |
| 359 | } |
| 360 | } |
| 361 | |
[email protected] | 493d1421 | 2011-07-07 15:38:48 | [diff] [blame] | 362 | } // namespace pp |