diff options
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/plugins/ppapi/event_conversion.cc | 27 | ||||
-rw-r--r-- | webkit/plugins/ppapi/event_conversion.h | 7 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.cc | 46 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.h | 2 |
4 files changed, 39 insertions, 43 deletions
diff --git a/webkit/plugins/ppapi/event_conversion.cc b/webkit/plugins/ppapi/event_conversion.cc index 9936ce3..cfc74a9 100644 --- a/webkit/plugins/ppapi/event_conversion.cc +++ b/webkit/plugins/ppapi/event_conversion.cc @@ -16,6 +16,7 @@ #include "ppapi/shared_impl/ppb_input_event_shared.h" #include "ppapi/shared_impl/time_conversion.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/usb_key_code_conversion.h" @@ -522,5 +523,31 @@ PP_InputEvent_Class ClassifyInputEvent(WebInputEvent::Type type) { } } +void ConvertWebKitGamepadData(WebKit::WebGamepads& webkit_data, + PP_GamepadsSampleData_Dev* output_data) { + output_data->length = webkit_data.length; + for (unsigned i = 0; i < webkit_data.length; ++i) { + PP_GamepadSampleData_Dev& output_pad = output_data->items[i]; + const WebKit::WebGamepad& webkit_pad = webkit_data.items[i]; + output_pad.connected = webkit_pad.connected ? PP_TRUE : PP_FALSE; + if (webkit_pad.connected) { + COMPILE_ASSERT(sizeof(output_pad.id) == sizeof(webkit_pad.id), + id_size_does_not_match); + COMPILE_ASSERT(sizeof(output_pad.axes) == sizeof(webkit_pad.axes), + axes_size_does_not_match); + COMPILE_ASSERT(sizeof(output_pad.buttons) == sizeof(webkit_pad.buttons), + buttons_size_does_not_match); + memcpy(output_pad.id, webkit_pad.id, sizeof(output_pad.id)); + output_pad.timestamp = webkit_pad.timestamp; + output_pad.axes_length = webkit_pad.axesLength; + memcpy(output_pad.axes, webkit_pad.axes, sizeof(output_pad.axes)); + output_pad.buttons_length = webkit_pad.buttonsLength; + memcpy(output_pad.buttons, + webkit_pad.buttons, + sizeof(output_pad.buttons)); + } + } +} + } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/event_conversion.h b/webkit/plugins/ppapi/event_conversion.h index b9b4004..573e5b6 100644 --- a/webkit/plugins/ppapi/event_conversion.h +++ b/webkit/plugins/ppapi/event_conversion.h @@ -8,6 +8,7 @@ #include <vector> #include "base/memory/linked_ptr.h" +#include "ppapi/c/dev/ppb_gamepad_dev.h" #include "ppapi/c/ppb_input_event.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" @@ -18,6 +19,7 @@ struct InputEventData; } namespace WebKit { +class WebGamepads; class WebInputEvent; } @@ -47,6 +49,11 @@ std::vector<linked_ptr<WebKit::WebInputEvent> > CreateSimulatedWebInputEvents( // type should not be "Undefined" since there's no corresponding PPAPI class. PP_InputEvent_Class ClassifyInputEvent(WebKit::WebInputEvent::Type type); +// Translate from WebGamepads to the Gamepad API format +// PP_GamepadsSampleData_Dev. +void ConvertWebKitGamepadData(WebKit::WebGamepads& webkit_data, + PP_GamepadsSampleData_Dev* output_data); + } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index 7dde8d7..a5d6515 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -220,15 +220,6 @@ COMPILE_ASSERT_MATCHING_ENUM(TypeGrabbing, PP_CURSORTYPE_GRABBING); // Do not assert WebCursorInfo::TypeCustom == PP_CURSORTYPE_CUSTOM; // PP_CURSORTYPE_CUSTOM is pinned to allow new cursor types. -// Ensure conversion from WebKit::WebGamepads to PP_GamepadsData_Dev is safe. -// See also DCHECKs in SampleGamepads below. -// -// Temporarily disabled for 2-sided WebKit roll. -//COMPILE_ASSERT(sizeof(WebKit::WebGamepads) == sizeof(PP_GamepadsData_Dev), -// size_difference); -//COMPILE_ASSERT(sizeof(WebKit::WebGamepad) == sizeof(PP_GamepadData_Dev), -// size_difference); - // Sets |*security_origin| to be the WebKit security origin associated with the // document containing the given plugin instance. On success, returns true. If // the instance is invalid, returns false and |*security_origin| will be @@ -1354,39 +1345,10 @@ bool PluginInstance::IsRectTopmost(const gfx::Rect& rect) { } void PluginInstance::SampleGamepads(PP_Instance instance, - PP_GamepadsData_Dev* data) { - - // Because the WebKit objects have trivial ctors, using offsetof doesn't - // work. Instead use this version based on src/v8/src/globals.h. This - // workaround doesn't work in constant expressions as required for - // COMPILE_ASSERT, so DCHECK instead. - -#define OFFSET_OF(type, field) \ - (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4) - -#define DCHECK_GAMEPADS_OFFSET(webkit_name, pp_name) \ - DCHECK(OFFSET_OF(WebKit::WebGamepads, webkit_name) \ - == OFFSET_OF(PP_GamepadsData_Dev, pp_name)) - -#define DCHECK_GAMEPAD_OFFSET(webkit_name, pp_name) \ - DCHECK(OFFSET_OF(WebKit::WebGamepad, webkit_name) \ - == OFFSET_OF(PP_GamepadData_Dev, pp_name)) - - DCHECK_GAMEPADS_OFFSET(length, length); - DCHECK_GAMEPADS_OFFSET(items, items); - DCHECK_GAMEPAD_OFFSET(connected, connected); - DCHECK_GAMEPAD_OFFSET(id, id); - DCHECK_GAMEPAD_OFFSET(timestamp, timestamp); - DCHECK_GAMEPAD_OFFSET(axesLength, axes_length); - DCHECK_GAMEPAD_OFFSET(axes, axes); - DCHECK_GAMEPAD_OFFSET(buttonsLength, buttons_length); - DCHECK_GAMEPAD_OFFSET(buttons, buttons); - -#undef OFFSET_OF -#undef DCHECK_GAMEPADS_OFFSET -#undef DCHECK_GAMEPAD_OFFSET - - delegate()->SampleGamepads(reinterpret_cast<WebKit::WebGamepads*>(data)); + PP_GamepadsSampleData_Dev* data) { + WebKit::WebGamepads webkit_data; + delegate()->SampleGamepads(&webkit_data); + ConvertWebKitGamepadData(webkit_data, data); } bool PluginInstance::IsViewAccelerated() { diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h index 65f8475..b81a3e8 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -295,7 +295,7 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : bool IsRectTopmost(const gfx::Rect& rect); // Implementation of PPB_Gamepad. - void SampleGamepads(PP_Instance instance, PP_GamepadsData_Dev* data) + void SampleGamepads(PP_Instance instance, PP_GamepadsSampleData_Dev* data) OVERRIDE; // Implementation of PPP_Messaging. |