diff options
author | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-10 19:24:28 +0000 |
---|---|---|
committer | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-10 19:24:28 +0000 |
commit | 0a424afc9c94380ecd80967be73cfb684b6ae3f4 (patch) | |
tree | 8741005d16fd3313f9d9430d30bec6497cd63225 /webkit/plugins/ppapi | |
parent | 336648ae73fa2d95d5042b00503c406fee1a6d0e (diff) | |
download | chromium_src-0a424afc9c94380ecd80967be73cfb684b6ae3f4.zip chromium_src-0a424afc9c94380ecd80967be73cfb684b6ae3f4.tar.gz chromium_src-0a424afc9c94380ecd80967be73cfb684b6ae3f4.tar.bz2 |
Pepper gamepad support
BUG=79098
Review URL: http://codereview.chromium.org/9085027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117077 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins/ppapi')
-rw-r--r-- | webkit/plugins/ppapi/mock_plugin_delegate.cc | 7 | ||||
-rw-r--r-- | webkit/plugins/ppapi/mock_plugin_delegate.h | 3 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_delegate.h | 6 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.cc | 45 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.h | 5 |
5 files changed, 63 insertions, 3 deletions
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc index a991c50..da371c54 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.cc +++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,6 +8,7 @@ #include "base/message_loop_proxy.h" #include "ppapi/c/pp_errors.h" #include "ppapi/shared_impl/ppapi_preferences.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" namespace webkit { @@ -361,6 +362,10 @@ void MockPluginDelegate::DidChangeCursor(PluginInstance* instance, void MockPluginDelegate::DidReceiveMouseEvent(PluginInstance* instance) { } +void MockPluginDelegate::SampleGamepads(WebKit::WebGamepads* data) { + data->length = 0; +} + bool MockPluginDelegate::IsInFullscreenMode() { return false; } diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h index 7fe0155..fbd961a 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.h +++ b/webkit/plugins/ppapi/mock_plugin_delegate.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -153,6 +153,7 @@ class MockPluginDelegate : public PluginDelegate { virtual void DidChangeCursor(PluginInstance* instance, const WebKit::WebCursorInfo& cursor); virtual void DidReceiveMouseEvent(PluginInstance* instance); + virtual void SampleGamepads(WebKit::WebGamepads* data) OVERRIDE; virtual bool IsInFullscreenMode(); virtual bool IsPageVisible() const; }; diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index af93ec8..6f9a17e 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -59,6 +59,7 @@ class PlatformCanvas; namespace WebKit { class WebFileChooserCompletion; +class WebGamepads; struct WebCursorInfo; struct WebFileChooserParams; } @@ -515,6 +516,9 @@ class PluginDelegate { // Determines if the browser entered fullscreen mode. virtual bool IsInFullscreenMode() = 0; + // Retrieve current gamepad data. + virtual void SampleGamepads(WebKit::WebGamepads* data) = 0; + // Returns true if the containing page is visible. virtual bool IsPageVisible() const = 0; }; diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index 63536bc..b3782d3 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -14,6 +14,7 @@ #include "base/utf_string_conversions.h" #include "ppapi/c/dev/ppb_console_dev.h" #include "ppapi/c/dev/ppb_find_dev.h" +#include "ppapi/c/dev/ppb_gamepad_dev.h" #include "ppapi/c/dev/ppb_zoom_dev.h" #include "ppapi/c/dev/ppp_find_dev.h" #include "ppapi/c/dev/ppp_selection_dev.h" @@ -45,6 +46,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" @@ -226,6 +228,13 @@ 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. +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 @@ -1310,6 +1319,42 @@ int32_t PluginInstance::Navigate(PPB_URLRequestInfo_Impl* request, return PP_OK; } +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)); +} + bool PluginInstance::IsViewAccelerated() { if (!container_) return false; diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h index cbafec1..3caef5c 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -16,6 +16,7 @@ #include "base/string16.h" #include "googleurl/src/gurl.h" #include "ppapi/c/dev/pp_cursor_type_dev.h" +#include "ppapi/c/dev/ppb_gamepad_dev.h" #include "ppapi/c/dev/ppp_printing_dev.h" #include "ppapi/c/dev/ppp_find_dev.h" #include "ppapi/c/dev/ppp_selection_dev.h" @@ -287,6 +288,10 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : const char* target, bool from_user_action); + // Implementation of PPB_Gamepad. + void SampleGamepads(PP_Instance instance, PP_GamepadsData_Dev* data) + OVERRIDE; + // Implementation of PPP_Messaging. void HandleMessage(PP_Var message); |