| 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_mac.h" | 5 #include "content/browser/gamepad/gamepad_platform_data_fetcher_mac.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 | 13 |
| 14 #import <Foundation/Foundation.h> | 14 #import <Foundation/Foundation.h> |
| 15 #include <IOKit/hid/IOHIDKeys.h> | 15 #include <IOKit/hid/IOHIDKeys.h> |
| 16 | 16 |
| 17 using WebKit::WebGamepad; | 17 using blink::WebGamepad; |
| 18 using WebKit::WebGamepads; | 18 using blink::WebGamepads; |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 NSDictionary* DeviceMatching(uint32_t usage_page, uint32_t usage) { | 24 NSDictionary* DeviceMatching(uint32_t usage_page, uint32_t usage) { |
| 25 return [NSDictionary dictionaryWithObjectsAndKeys: | 25 return [NSDictionary dictionaryWithObjectsAndKeys: |
| 26 [NSNumber numberWithUnsignedInt:usage_page], | 26 [NSNumber numberWithUnsignedInt:usage_page], |
| 27 base::mac::CFToNSCast(CFSTR(kIOHIDDeviceUsagePageKey)), | 27 base::mac::CFToNSCast(CFSTR(kIOHIDDeviceUsagePageKey)), |
| 28 [NSNumber numberWithUnsignedInt:usage], | 28 [NSNumber numberWithUnsignedInt:usage], |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 @"%@ (%sVendor: %04x Product: %04x)", | 259 @"%@ (%sVendor: %04x Product: %04x)", |
| 260 product, | 260 product, |
| 261 associated_[slot].hid.mapper ? "STANDARD GAMEPAD " : "", | 261 associated_[slot].hid.mapper ? "STANDARD GAMEPAD " : "", |
| 262 vendor_int, | 262 vendor_int, |
| 263 product_int]; | 263 product_int]; |
| 264 NSData* as16 = [ident dataUsingEncoding:NSUTF16LittleEndianStringEncoding]; | 264 NSData* as16 = [ident dataUsingEncoding:NSUTF16LittleEndianStringEncoding]; |
| 265 | 265 |
| 266 const size_t kOutputLengthBytes = sizeof(data_.items[slot].id); | 266 const size_t kOutputLengthBytes = sizeof(data_.items[slot].id); |
| 267 memset(&data_.items[slot].id, 0, kOutputLengthBytes); | 267 memset(&data_.items[slot].id, 0, kOutputLengthBytes); |
| 268 [as16 getBytes:data_.items[slot].id | 268 [as16 getBytes:data_.items[slot].id |
| 269 length:kOutputLengthBytes - sizeof(WebKit::WebUChar)]; | 269 length:kOutputLengthBytes - sizeof(blink::WebUChar)]; |
| 270 | 270 |
| 271 base::ScopedCFTypeRef<CFArrayRef> elements( | 271 base::ScopedCFTypeRef<CFArrayRef> elements( |
| 272 IOHIDDeviceCopyMatchingElements(device, NULL, kIOHIDOptionsTypeNone)); | 272 IOHIDDeviceCopyMatchingElements(device, NULL, kIOHIDOptionsTypeNone)); |
| 273 AddButtonsAndAxes(CFToNSCast(elements), slot); | 273 AddButtonsAndAxes(CFToNSCast(elements), slot); |
| 274 | 274 |
| 275 associated_[slot].hid.device_ref = device; | 275 associated_[slot].hid.device_ref = device; |
| 276 data_.items[slot].connected = true; | 276 data_.items[slot].connected = true; |
| 277 if (slot >= data_.length) | 277 if (slot >= data_.length) |
| 278 data_.length = slot + 1; | 278 data_.length = slot + 1; |
| 279 } | 279 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 (XboxController::LEDPattern)(XboxController::LED_FLASH_TOP_LEFT + slot)); | 352 (XboxController::LEDPattern)(XboxController::LED_FLASH_TOP_LEFT + slot)); |
| 353 | 353 |
| 354 NSString* ident = | 354 NSString* ident = |
| 355 [NSString stringWithFormat: | 355 [NSString stringWithFormat: |
| 356 @"Xbox 360 Controller (STANDARD GAMEPAD Vendor: %04x Product: %04x)", | 356 @"Xbox 360 Controller (STANDARD GAMEPAD Vendor: %04x Product: %04x)", |
| 357 device->GetProductId(), device->GetVendorId()]; | 357 device->GetProductId(), device->GetVendorId()]; |
| 358 NSData* as16 = [ident dataUsingEncoding:NSUTF16StringEncoding]; | 358 NSData* as16 = [ident dataUsingEncoding:NSUTF16StringEncoding]; |
| 359 const size_t kOutputLengthBytes = sizeof(data_.items[slot].id); | 359 const size_t kOutputLengthBytes = sizeof(data_.items[slot].id); |
| 360 memset(&data_.items[slot].id, 0, kOutputLengthBytes); | 360 memset(&data_.items[slot].id, 0, kOutputLengthBytes); |
| 361 [as16 getBytes:data_.items[slot].id | 361 [as16 getBytes:data_.items[slot].id |
| 362 length:kOutputLengthBytes - sizeof(WebKit::WebUChar)]; | 362 length:kOutputLengthBytes - sizeof(blink::WebUChar)]; |
| 363 | 363 |
| 364 associated_[slot].is_xbox = true; | 364 associated_[slot].is_xbox = true; |
| 365 associated_[slot].xbox.device = device; | 365 associated_[slot].xbox.device = device; |
| 366 associated_[slot].xbox.location_id = device->location_id(); | 366 associated_[slot].xbox.location_id = device->location_id(); |
| 367 data_.items[slot].connected = true; | 367 data_.items[slot].connected = true; |
| 368 data_.items[slot].axesLength = 4; | 368 data_.items[slot].axesLength = 4; |
| 369 data_.items[slot].buttonsLength = 17; | 369 data_.items[slot].buttonsLength = 17; |
| 370 data_.items[slot].timestamp = 0; | 370 data_.items[slot].timestamp = 0; |
| 371 if (slot >= data_.length) | 371 if (slot >= data_.length) |
| 372 data_.length = slot + 1; | 372 data_.length = slot + 1; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 pads->length = WebGamepads::itemsLengthCap; | 431 pads->length = WebGamepads::itemsLengthCap; |
| 432 for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) { | 432 for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) { |
| 433 if (!associated_[i].is_xbox && associated_[i].hid.mapper) | 433 if (!associated_[i].is_xbox && associated_[i].hid.mapper) |
| 434 associated_[i].hid.mapper(data_.items[i], &pads->items[i]); | 434 associated_[i].hid.mapper(data_.items[i], &pads->items[i]); |
| 435 else | 435 else |
| 436 pads->items[i] = data_.items[i]; | 436 pads->items[i] = data_.items[i]; |
| 437 } | 437 } |
| 438 } | 438 } |
| 439 | 439 |
| 440 } // namespace content | 440 } // namespace content |
| OLD | NEW |