| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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.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" |
| 11 #include "ppapi/cpp/var.h" | 11 #include "ppapi/cpp/var.h" |
| 12 | 12 |
| 13 namespace pp { | 13 namespace pp { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 template <> const char* interface_name<PPB_InputEvent>() { | 17 template <> const char* interface_name<PPB_InputEvent>() { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 // Type check the input event before setting it. | 77 // Type check the input event before setting it. |
| 78 if (!has_interface<PPB_MouseInputEvent>()) | 78 if (!has_interface<PPB_MouseInputEvent>()) |
| 79 return; | 79 return; |
| 80 if (get_interface<PPB_MouseInputEvent>()->IsMouseInputEvent( | 80 if (get_interface<PPB_MouseInputEvent>()->IsMouseInputEvent( |
| 81 event.pp_resource())) { | 81 event.pp_resource())) { |
| 82 Module::Get()->core()->AddRefResource(event.pp_resource()); | 82 Module::Get()->core()->AddRefResource(event.pp_resource()); |
| 83 PassRefFromConstructor(event.pp_resource()); | 83 PassRefFromConstructor(event.pp_resource()); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 MouseInputEvent::MouseInputEvent(Instance* instance, | 87 MouseInputEvent::MouseInputEvent(const InstanceHandle& instance, |
| 88 PP_InputEvent_Type type, | 88 PP_InputEvent_Type type, |
| 89 PP_TimeTicks time_stamp, | 89 PP_TimeTicks time_stamp, |
| 90 uint32_t modifiers, | 90 uint32_t modifiers, |
| 91 PP_InputEvent_MouseButton mouse_button, | 91 PP_InputEvent_MouseButton mouse_button, |
| 92 const Point& mouse_position, | 92 const Point& mouse_position, |
| 93 int32_t click_count, | 93 int32_t click_count, |
| 94 const Point& mouse_movement) { | 94 const Point& mouse_movement) { |
| 95 // Type check the input event before setting it. | 95 // Type check the input event before setting it. |
| 96 if (!has_interface<PPB_MouseInputEvent>()) | 96 if (!has_interface<PPB_MouseInputEvent>()) |
| 97 return; | 97 return; |
| 98 PassRefFromConstructor(get_interface<PPB_MouseInputEvent>()->Create( | 98 PassRefFromConstructor(get_interface<PPB_MouseInputEvent>()->Create( |
| 99 instance->pp_instance(), type, time_stamp, modifiers, mouse_button, | 99 instance.pp_instance(), type, time_stamp, modifiers, mouse_button, |
| 100 &mouse_position.pp_point(), click_count, &mouse_movement.pp_point())); | 100 &mouse_position.pp_point(), click_count, &mouse_movement.pp_point())); |
| 101 } | 101 } |
| 102 | 102 |
| 103 PP_InputEvent_MouseButton MouseInputEvent::GetButton() const { | 103 PP_InputEvent_MouseButton MouseInputEvent::GetButton() const { |
| 104 if (!has_interface<PPB_MouseInputEvent>()) | 104 if (!has_interface<PPB_MouseInputEvent>()) |
| 105 return PP_INPUTEVENT_MOUSEBUTTON_NONE; | 105 return PP_INPUTEVENT_MOUSEBUTTON_NONE; |
| 106 return get_interface<PPB_MouseInputEvent>()->GetButton(pp_resource()); | 106 return get_interface<PPB_MouseInputEvent>()->GetButton(pp_resource()); |
| 107 } | 107 } |
| 108 | 108 |
| 109 Point MouseInputEvent::GetPosition() const { | 109 Point MouseInputEvent::GetPosition() const { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 133 // Type check the input event before setting it. | 133 // Type check the input event before setting it. |
| 134 if (!has_interface<PPB_WheelInputEvent>()) | 134 if (!has_interface<PPB_WheelInputEvent>()) |
| 135 return; | 135 return; |
| 136 if (get_interface<PPB_WheelInputEvent>()->IsWheelInputEvent( | 136 if (get_interface<PPB_WheelInputEvent>()->IsWheelInputEvent( |
| 137 event.pp_resource())) { | 137 event.pp_resource())) { |
| 138 Module::Get()->core()->AddRefResource(event.pp_resource()); | 138 Module::Get()->core()->AddRefResource(event.pp_resource()); |
| 139 PassRefFromConstructor(event.pp_resource()); | 139 PassRefFromConstructor(event.pp_resource()); |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 | 142 |
| 143 WheelInputEvent::WheelInputEvent(Instance* instance, | 143 WheelInputEvent::WheelInputEvent(const InstanceHandle& instance, |
| 144 PP_TimeTicks time_stamp, | 144 PP_TimeTicks time_stamp, |
| 145 uint32_t modifiers, | 145 uint32_t modifiers, |
| 146 const FloatPoint& wheel_delta, | 146 const FloatPoint& wheel_delta, |
| 147 const FloatPoint& wheel_ticks, | 147 const FloatPoint& wheel_ticks, |
| 148 bool scroll_by_page) { | 148 bool scroll_by_page) { |
| 149 // Type check the input event before setting it. | 149 // Type check the input event before setting it. |
| 150 if (!has_interface<PPB_WheelInputEvent>()) | 150 if (!has_interface<PPB_WheelInputEvent>()) |
| 151 return; | 151 return; |
| 152 PassRefFromConstructor(get_interface<PPB_WheelInputEvent>()->Create( | 152 PassRefFromConstructor(get_interface<PPB_WheelInputEvent>()->Create( |
| 153 instance->pp_instance(), time_stamp, modifiers, | 153 instance.pp_instance(), time_stamp, modifiers, |
| 154 &wheel_delta.pp_float_point(), &wheel_ticks.pp_float_point(), | 154 &wheel_delta.pp_float_point(), &wheel_ticks.pp_float_point(), |
| 155 PP_FromBool(scroll_by_page))); | 155 PP_FromBool(scroll_by_page))); |
| 156 } | 156 } |
| 157 | 157 |
| 158 FloatPoint WheelInputEvent::GetDelta() const { | 158 FloatPoint WheelInputEvent::GetDelta() const { |
| 159 if (!has_interface<PPB_WheelInputEvent>()) | 159 if (!has_interface<PPB_WheelInputEvent>()) |
| 160 return FloatPoint(); | 160 return FloatPoint(); |
| 161 return get_interface<PPB_WheelInputEvent>()->GetDelta(pp_resource()); | 161 return get_interface<PPB_WheelInputEvent>()->GetDelta(pp_resource()); |
| 162 } | 162 } |
| 163 | 163 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 183 // Type check the input event before setting it. | 183 // Type check the input event before setting it. |
| 184 if (!has_interface<PPB_KeyboardInputEvent>()) | 184 if (!has_interface<PPB_KeyboardInputEvent>()) |
| 185 return; | 185 return; |
| 186 if (get_interface<PPB_KeyboardInputEvent>()->IsKeyboardInputEvent( | 186 if (get_interface<PPB_KeyboardInputEvent>()->IsKeyboardInputEvent( |
| 187 event.pp_resource())) { | 187 event.pp_resource())) { |
| 188 Module::Get()->core()->AddRefResource(event.pp_resource()); | 188 Module::Get()->core()->AddRefResource(event.pp_resource()); |
| 189 PassRefFromConstructor(event.pp_resource()); | 189 PassRefFromConstructor(event.pp_resource()); |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 | 192 |
| 193 KeyboardInputEvent::KeyboardInputEvent(Instance* instance, | 193 KeyboardInputEvent::KeyboardInputEvent(const InstanceHandle& instance, |
| 194 PP_InputEvent_Type type, | 194 PP_InputEvent_Type type, |
| 195 PP_TimeTicks time_stamp, | 195 PP_TimeTicks time_stamp, |
| 196 uint32_t modifiers, | 196 uint32_t modifiers, |
| 197 uint32_t key_code, | 197 uint32_t key_code, |
| 198 const Var& character_text) { | 198 const Var& character_text) { |
| 199 // Type check the input event before setting it. | 199 // Type check the input event before setting it. |
| 200 if (!has_interface<PPB_KeyboardInputEvent>()) | 200 if (!has_interface<PPB_KeyboardInputEvent>()) |
| 201 return; | 201 return; |
| 202 PassRefFromConstructor(get_interface<PPB_KeyboardInputEvent>()->Create( | 202 PassRefFromConstructor(get_interface<PPB_KeyboardInputEvent>()->Create( |
| 203 instance->pp_instance(), type, time_stamp, modifiers, key_code, | 203 instance.pp_instance(), type, time_stamp, modifiers, key_code, |
| 204 character_text.pp_var())); | 204 character_text.pp_var())); |
| 205 } | 205 } |
| 206 | 206 |
| 207 uint32_t KeyboardInputEvent::GetKeyCode() const { | 207 uint32_t KeyboardInputEvent::GetKeyCode() const { |
| 208 if (!has_interface<PPB_KeyboardInputEvent>()) | 208 if (!has_interface<PPB_KeyboardInputEvent>()) |
| 209 return 0; | 209 return 0; |
| 210 return get_interface<PPB_KeyboardInputEvent>()->GetKeyCode(pp_resource()); | 210 return get_interface<PPB_KeyboardInputEvent>()->GetKeyCode(pp_resource()); |
| 211 } | 211 } |
| 212 | 212 |
| 213 Var KeyboardInputEvent::GetCharacterText() const { | 213 Var KeyboardInputEvent::GetCharacterText() const { |
| 214 if (!has_interface<PPB_KeyboardInputEvent>()) | 214 if (!has_interface<PPB_KeyboardInputEvent>()) |
| 215 return Var(); | 215 return Var(); |
| 216 return Var(Var::PassRef(), | 216 return Var(PASS_REF, |
| 217 get_interface<PPB_KeyboardInputEvent>()->GetCharacterText( | 217 get_interface<PPB_KeyboardInputEvent>()->GetCharacterText( |
| 218 pp_resource())); | 218 pp_resource())); |
| 219 } | 219 } |
| 220 | 220 |
| 221 } // namespace pp | 221 } // namespace pp |
| OLD | NEW |