| Index: content/browser/gamepad/gamepad_platform_data_fetcher_mac.mm
|
| diff --git a/content/browser/gamepad/gamepad_platform_data_fetcher_mac.mm b/content/browser/gamepad/gamepad_platform_data_fetcher_mac.mm
|
| index 69d0c63e31d4c974c131eafd0f7ef62f0a2e03ce..a5e9120b5f3f87ef61bbd3ead8e5500eb1be12b8 100644
|
| --- a/content/browser/gamepad/gamepad_platform_data_fetcher_mac.mm
|
| +++ b/content/browser/gamepad/gamepad_platform_data_fetcher_mac.mm
|
| @@ -21,6 +21,13 @@ namespace content {
|
|
|
| namespace {
|
|
|
| +void copyNSStringAsUTF16LittleEndian(
|
| + NSString* src, blink::WebUChar* dest, size_t dest_len) {
|
| + NSData* as16 = [src dataUsingEncoding:NSUTF16LittleEndianStringEncoding];
|
| + memset(dest, 0, dest_len);
|
| + [as16 getBytes:dest length:dest_len - sizeof(blink::WebUChar)];
|
| +}
|
| +
|
| NSDictionary* DeviceMatching(uint32_t usage_page, uint32_t usage) {
|
| return [NSDictionary dictionaryWithObjectsAndKeys:
|
| [NSNumber numberWithUnsignedInt:usage_page],
|
| @@ -255,18 +262,37 @@ void GamepadPlatformDataFetcherMac::DeviceAdd(IOHIDDeviceRef device) {
|
| associated_[slot].hid.mapper =
|
| GetGamepadStandardMappingFunction(vendor_as_str, product_as_str);
|
|
|
| +#ifdef ENABLE_NEW_GAMEPAD_API
|
| + NSString* ident = [NSString stringWithFormat:
|
| + @"%@ (Vendor: %04x Product: %04x)",
|
| + product,
|
| + vendor_int,
|
| + product_int];
|
| + copyNSStringAsUTF16LittleEndian(
|
| + ident,
|
| + data_.items[slot].id,
|
| + sizeof(data_.items[slot].id));
|
| +
|
| + if (associated_[slot].hid.mapper) {
|
| + copyNSStringAsUTF16LittleEndian(
|
| + @"standard",
|
| + data_.items[slot].mapping,
|
| + sizeof(data_.items[slot].mapping));
|
| + } else {
|
| + data_.items[slot].mapping[0] = 0;
|
| + }
|
| +#else
|
| NSString* ident = [NSString stringWithFormat:
|
| @"%@ (%sVendor: %04x Product: %04x)",
|
| product,
|
| associated_[slot].hid.mapper ? "STANDARD GAMEPAD " : "",
|
| vendor_int,
|
| product_int];
|
| - NSData* as16 = [ident dataUsingEncoding:NSUTF16LittleEndianStringEncoding];
|
| -
|
| - const size_t kOutputLengthBytes = sizeof(data_.items[slot].id);
|
| - memset(&data_.items[slot].id, 0, kOutputLengthBytes);
|
| - [as16 getBytes:data_.items[slot].id
|
| - length:kOutputLengthBytes - sizeof(blink::WebUChar)];
|
| + copyNSStringAsUTF16LittleEndian(
|
| + ident,
|
| + data_.items[slot].id,
|
| + sizeof(data_.items[slot].id));
|
| +#endif
|
|
|
| base::ScopedCFTypeRef<CFArrayRef> elements(
|
| IOHIDDeviceCopyMatchingElements(device, NULL, kIOHIDOptionsTypeNone));
|
| @@ -351,15 +377,30 @@ void GamepadPlatformDataFetcherMac::XboxDeviceAdd(XboxController* device) {
|
| device->SetLEDPattern(
|
| (XboxController::LEDPattern)(XboxController::LED_FLASH_TOP_LEFT + slot));
|
|
|
| +#ifdef ENABLE_NEW_GAMEPAD_API
|
| + NSString* ident =
|
| + [NSString stringWithFormat:
|
| + @"Xbox 360 Controller (Vendor: %04x Product: %04x)",
|
| + device->GetProductId(), device->GetVendorId()];
|
| + copyNSStringAsUTF16LittleEndian(
|
| + ident,
|
| + data_.items[slot].id,
|
| + sizeof(data_.items[slot].id));
|
| +
|
| + copyNSStringAsUTF16LittleEndian(
|
| + @"standard",
|
| + data_.items[slot].mapping,
|
| + sizeof(data_.items[slot].mapping));
|
| +#else
|
| NSString* ident =
|
| [NSString stringWithFormat:
|
| @"Xbox 360 Controller (STANDARD GAMEPAD Vendor: %04x Product: %04x)",
|
| device->GetProductId(), device->GetVendorId()];
|
| - NSData* as16 = [ident dataUsingEncoding:NSUTF16StringEncoding];
|
| - const size_t kOutputLengthBytes = sizeof(data_.items[slot].id);
|
| - memset(&data_.items[slot].id, 0, kOutputLengthBytes);
|
| - [as16 getBytes:data_.items[slot].id
|
| - length:kOutputLengthBytes - sizeof(blink::WebUChar)];
|
| + copyNSStringAsUTF16LittleEndian(
|
| + ident,
|
| + data_.items[slot].id,
|
| + sizeof(data_.items[slot].id));
|
| +#endif
|
|
|
| associated_[slot].is_xbox = true;
|
| associated_[slot].xbox.device = device;
|
|
|