| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/test_runner/gamepad_controller.h" | 5 #include "components/test_runner/gamepad_controller.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "components/test_runner/web_test_delegate.h" | 10 #include "components/test_runner/web_test_delegate.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 } | 171 } |
| 172 | 172 |
| 173 void GamepadController::SetListener(blink::WebGamepadListener* listener) { | 173 void GamepadController::SetListener(blink::WebGamepadListener* listener) { |
| 174 listener_ = listener; | 174 listener_ = listener; |
| 175 } | 175 } |
| 176 | 176 |
| 177 void GamepadController::Connect(int index) { | 177 void GamepadController::Connect(int index) { |
| 178 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) | 178 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) |
| 179 return; | 179 return; |
| 180 gamepads_.items[index].connected = true; | 180 gamepads_.items[index].connected = true; |
| 181 gamepads_.length = 0; | |
| 182 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { | |
| 183 if (gamepads_.items[i].connected) | |
| 184 gamepads_.length = i + 1; | |
| 185 } | |
| 186 } | 181 } |
| 187 | 182 |
| 188 void GamepadController::DispatchConnected(int index) { | 183 void GamepadController::DispatchConnected(int index) { |
| 189 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap) | 184 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap) |
| 190 || !gamepads_.items[index].connected) | 185 || !gamepads_.items[index].connected) |
| 191 return; | 186 return; |
| 192 const WebGamepad& pad = gamepads_.items[index]; | 187 const WebGamepad& pad = gamepads_.items[index]; |
| 193 if (listener_) | 188 if (listener_) |
| 194 listener_->didConnectGamepad(index, pad); | 189 listener_->didConnectGamepad(index, pad); |
| 195 } | 190 } |
| 196 | 191 |
| 197 void GamepadController::Disconnect(int index) { | 192 void GamepadController::Disconnect(int index) { |
| 198 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) | 193 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) |
| 199 return; | 194 return; |
| 200 WebGamepad& pad = gamepads_.items[index]; | 195 WebGamepad& pad = gamepads_.items[index]; |
| 201 pad.connected = false; | 196 pad.connected = false; |
| 202 gamepads_.length = 0; | |
| 203 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { | |
| 204 if (gamepads_.items[i].connected) | |
| 205 gamepads_.length = i + 1; | |
| 206 } | |
| 207 if (listener_) | 197 if (listener_) |
| 208 listener_->didDisconnectGamepad(index, pad); | 198 listener_->didDisconnectGamepad(index, pad); |
| 209 } | 199 } |
| 210 | 200 |
| 211 void GamepadController::SetId(int index, const std::string& src) { | 201 void GamepadController::SetId(int index, const std::string& src) { |
| 212 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) | 202 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) |
| 213 return; | 203 return; |
| 214 const char* p = src.c_str(); | 204 const char* p = src.c_str(); |
| 215 memset(gamepads_.items[index].id, 0, sizeof(gamepads_.items[index].id)); | 205 memset(gamepads_.items[index].id, 0, sizeof(gamepads_.items[index].id)); |
| 216 for (unsigned i = 0; *p && i < WebGamepad::idLengthCap - 1; ++i) | 206 for (unsigned i = 0; *p && i < WebGamepad::idLengthCap - 1; ++i) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 244 | 234 |
| 245 void GamepadController::SetAxisData(int index, int axis, double data) { | 235 void GamepadController::SetAxisData(int index, int axis, double data) { |
| 246 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) | 236 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) |
| 247 return; | 237 return; |
| 248 if (axis < 0 || axis >= static_cast<int>(WebGamepad::axesLengthCap)) | 238 if (axis < 0 || axis >= static_cast<int>(WebGamepad::axesLengthCap)) |
| 249 return; | 239 return; |
| 250 gamepads_.items[index].axes[axis] = data; | 240 gamepads_.items[index].axes[axis] = data; |
| 251 } | 241 } |
| 252 | 242 |
| 253 } // namespace test_runner | 243 } // namespace test_runner |
| OLD | NEW |