Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2136)

Unified Diff: Source/modules/gamepad/Gamepad.cpp

Issue 170993002: Updating Blink-side WebGamepad interface (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Minor cleanups Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/gamepad/Gamepad.h ('k') | Source/modules/gamepad/Gamepad.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/gamepad/Gamepad.cpp
diff --git a/Source/modules/gamepad/Gamepad.cpp b/Source/modules/gamepad/Gamepad.cpp
index c83ccaf90a457ce81bcf3bc81f7680410dfefc00..0c82a833a4f7e75b92c8eec369b9a85acc29c43c 100644
--- a/Source/modules/gamepad/Gamepad.cpp
+++ b/Source/modules/gamepad/Gamepad.cpp
@@ -28,6 +28,8 @@
namespace WebCore {
+const float ButtonPressedThreshold = 0.1f;
scottmg 2014/02/18 23:46:31 As noted in the chromium-side review, I think this
+
DEFINE_GC_INFO(Gamepad);
Gamepad::Gamepad()
@@ -46,9 +48,16 @@ void Gamepad::axes(unsigned count, float* data)
void Gamepad::buttons(unsigned count, float* data)
{
- m_buttons.resize(count);
- if (count)
- std::copy(data, data + count, m_buttons.begin());
+ if (m_buttons.size() != count) {
+ m_buttons.resize(count);
+ for (unsigned i = 0; i < count; ++i)
+ m_buttons[i] = GamepadButton::create();
+ }
+
+ for (unsigned i = 0; i < count; ++i) {
+ m_buttons[i]->value(data[i]);
+ m_buttons[i]->pressed(data[i] >= ButtonPressedThreshold);
+ }
}
Gamepad::~Gamepad()
« no previous file with comments | « Source/modules/gamepad/Gamepad.h ('k') | Source/modules/gamepad/Gamepad.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698