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 <libudev.h> | 8 #include <libudev.h> |
9 #include <linux/joystick.h> | 9 #include <linux/joystick.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 bool is_gamepad = StartsWithASCII(node_path, kJoystickRoot, true); | 45 bool is_gamepad = StartsWithASCII(node_path, kJoystickRoot, true); |
46 if (!is_gamepad) | 46 if (!is_gamepad) |
47 return false; | 47 return false; |
48 | 48 |
49 int tmp_idx = -1; | 49 int tmp_idx = -1; |
50 const int base_len = sizeof(kJoystickRoot) - 1; | 50 const int base_len = sizeof(kJoystickRoot) - 1; |
51 base::StringPiece str(&node_path[base_len], strlen(node_path) - base_len); | 51 base::StringPiece str(&node_path[base_len], strlen(node_path) - base_len); |
52 if (!base::StringToInt(str, &tmp_idx)) | 52 if (!base::StringToInt(str, &tmp_idx)) |
53 return false; | 53 return false; |
54 if (tmp_idx < 0 || | 54 if (tmp_idx < 0 || |
55 tmp_idx >= static_cast<int>(WebKit::WebGamepads::itemsLengthCap)) { | 55 tmp_idx >= static_cast<int>(blink::WebGamepads::itemsLengthCap)) { |
56 return false; | 56 return false; |
57 } | 57 } |
58 *index = tmp_idx; | 58 *index = tmp_idx; |
59 *path = node_path; | 59 *path = node_path; |
60 return true; | 60 return true; |
61 } | 61 } |
62 | 62 |
63 } // namespace | 63 } // namespace |
64 | 64 |
65 namespace content { | 65 namespace content { |
66 | 66 |
67 using WebKit::WebGamepad; | 67 using blink::WebGamepad; |
68 using WebKit::WebGamepads; | 68 using blink::WebGamepads; |
69 | 69 |
70 GamepadPlatformDataFetcherLinux::GamepadPlatformDataFetcherLinux() { | 70 GamepadPlatformDataFetcherLinux::GamepadPlatformDataFetcherLinux() { |
71 for (size_t i = 0; i < arraysize(device_fds_); ++i) | 71 for (size_t i = 0; i < arraysize(device_fds_); ++i) |
72 device_fds_[i] = -1; | 72 device_fds_[i] = -1; |
73 memset(mappers_, 0, sizeof(mappers_)); | 73 memset(mappers_, 0, sizeof(mappers_)); |
74 | 74 |
75 std::vector<UdevLinux::UdevMonitorFilter> filters; | 75 std::vector<UdevLinux::UdevMonitorFilter> filters; |
76 filters.push_back(UdevLinux::UdevMonitorFilter(kInputSubsystem, NULL)); | 76 filters.push_back(UdevLinux::UdevMonitorFilter(kInputSubsystem, NULL)); |
77 udev_.reset( | 77 udev_.reset( |
78 new UdevLinux(filters, | 78 new UdevLinux(filters, |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 continue; | 248 continue; |
249 pad.buttons[item] = event.value ? 1.0 : 0.0; | 249 pad.buttons[item] = event.value ? 1.0 : 0.0; |
250 if (item >= pad.buttonsLength) | 250 if (item >= pad.buttonsLength) |
251 pad.buttonsLength = item + 1; | 251 pad.buttonsLength = item + 1; |
252 } | 252 } |
253 pad.timestamp = event.time; | 253 pad.timestamp = event.time; |
254 } | 254 } |
255 } | 255 } |
256 | 256 |
257 } // namespace content | 257 } // namespace content |
OLD | NEW |