| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/gamepad/gamepad_platform_data_fetcher_linux.h" | 5 #include "content/browser/gamepad/gamepad_platform_data_fetcher_linux.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <linux/joystick.h> | 8 #include <linux/joystick.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 bool IsGamepad(udev_device* dev, int* index, std::string* path) { | 36 bool IsGamepad(udev_device* dev, int* index, std::string* path) { |
| 37 if (!device::udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK")) | 37 if (!device::udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK")) |
| 38 return false; | 38 return false; |
| 39 | 39 |
| 40 const char* node_path = device::udev_device_get_devnode(dev); | 40 const char* node_path = device::udev_device_get_devnode(dev); |
| 41 if (!node_path) | 41 if (!node_path) |
| 42 return false; | 42 return false; |
| 43 | 43 |
| 44 static const char kJoystickRoot[] = "/dev/input/js"; | 44 static const char kJoystickRoot[] = "/dev/input/js"; |
| 45 bool is_gamepad = base::StartsWithASCII(node_path, kJoystickRoot, true); | 45 bool is_gamepad = base::StartsWith(node_path, kJoystickRoot, |
| 46 base::CompareCase::SENSITIVE); |
| 46 if (!is_gamepad) | 47 if (!is_gamepad) |
| 47 return false; | 48 return false; |
| 48 | 49 |
| 49 int tmp_idx = -1; | 50 int tmp_idx = -1; |
| 50 const int base_len = sizeof(kJoystickRoot) - 1; | 51 const int base_len = sizeof(kJoystickRoot) - 1; |
| 51 base::StringPiece str(&node_path[base_len], strlen(node_path) - base_len); | 52 base::StringPiece str(&node_path[base_len], strlen(node_path) - base_len); |
| 52 if (!base::StringToInt(str, &tmp_idx)) | 53 if (!base::StringToInt(str, &tmp_idx)) |
| 53 return false; | 54 return false; |
| 54 if (tmp_idx < 0 || | 55 if (tmp_idx < 0 || |
| 55 tmp_idx >= static_cast<int>(blink::WebGamepads::itemsLengthCap)) { | 56 tmp_idx >= static_cast<int>(blink::WebGamepads::itemsLengthCap)) { |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 pad.buttons[item].pressed = event.value; | 261 pad.buttons[item].pressed = event.value; |
| 261 pad.buttons[item].value = event.value ? 1.0 : 0.0; | 262 pad.buttons[item].value = event.value ? 1.0 : 0.0; |
| 262 if (item >= pad.buttonsLength) | 263 if (item >= pad.buttonsLength) |
| 263 pad.buttonsLength = item + 1; | 264 pad.buttonsLength = item + 1; |
| 264 } | 265 } |
| 265 pad.timestamp = event.time; | 266 pad.timestamp = event.time; |
| 266 } | 267 } |
| 267 } | 268 } |
| 268 | 269 |
| 269 } // namespace content | 270 } // namespace content |
| OLD | NEW |