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

Unified Diff: content/shell/renderer/test_runner/gamepad_controller.cc

Issue 207323002: Gamepad API: add test support for gamepad events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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
Index: content/shell/renderer/test_runner/gamepad_controller.cc
diff --git a/content/shell/renderer/test_runner/gamepad_controller.cc b/content/shell/renderer/test_runner/gamepad_controller.cc
index 576469d5f2157c7311b173ec428092d0cb7c2d91..6affefb2f7434382206ffdc55d16ed393c6a3e52 100644
--- a/content/shell/renderer/test_runner/gamepad_controller.cc
+++ b/content/shell/renderer/test_runner/gamepad_controller.cc
@@ -38,6 +38,7 @@ class GamepadControllerBindings
v8::Isolate* isolate) OVERRIDE;
void Connect(int index);
+ void DispatchConnected(int index);
void Disconnect(int index);
void SetId(int index, const std::string& src);
void SetButtonCount(int index, int buttons);
@@ -82,6 +83,7 @@ gin::ObjectTemplateBuilder GamepadControllerBindings::GetObjectTemplateBuilder(
return gin::Wrappable<GamepadControllerBindings>::GetObjectTemplateBuilder(
isolate)
.SetMethod("connect", &GamepadControllerBindings::Connect)
+ .SetMethod("dispatchConnected", &GamepadControllerBindings::DispatchConnected)
.SetMethod("disconnect", &GamepadControllerBindings::Disconnect)
.SetMethod("setId", &GamepadControllerBindings::SetId)
.SetMethod("setButtonCount", &GamepadControllerBindings::SetButtonCount)
@@ -95,6 +97,11 @@ void GamepadControllerBindings::Connect(int index) {
controller_->Connect(index);
}
+void GamepadControllerBindings::DispatchConnected(int index) {
+ if (controller_)
+ controller_->DispatchConnected(index);
+}
+
void GamepadControllerBindings::Disconnect(int index) {
if (controller_)
controller_->Disconnect(index);
@@ -158,17 +165,28 @@ void GamepadController::Connect(int index) {
delegate_->setGamepadData(gamepads_);
}
+void GamepadController::DispatchConnected(int index) {
+ if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap))
+ return;
+ const WebGamepad& pad = gamepads_.items[index];
+ if (pad.connected && delegate_)
+ delegate_->didConnectGamepad(index, pad);
+}
+
void GamepadController::Disconnect(int index) {
if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap))
return;
- gamepads_.items[index].connected = false;
+ WebGamepad& pad = gamepads_.items[index];
+ pad.connected = false;
gamepads_.length = 0;
for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) {
if (gamepads_.items[i].connected)
gamepads_.length = i + 1;
}
- if (delegate_)
+ if (delegate_) {
delegate_->setGamepadData(gamepads_);
+ delegate_->didDisconnectGamepad(index, pad);
+ }
}
void GamepadController::SetId(int index, const std::string& src) {

Powered by Google App Engine
This is Rietveld 408576698