| 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..7e05999d6881840a770352d56735ac10d3ae5d24 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],
|
| @@ -261,12 +268,19 @@ void GamepadPlatformDataFetcherMac::DeviceAdd(IOHIDDeviceRef device) {
|
| 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));
|
| +
|
| + if (associated_[slot].hid.mapper) {
|
| + CopyNSStringAsUTF16LittleEndian(
|
| + @"standard",
|
| + data_.items[slot].mapping,
|
| + sizeof(data_.items[slot].mapping));
|
| + } else {
|
| + data_.items[slot].mapping[0] = 0;
|
| + }
|
|
|
| base::ScopedCFTypeRef<CFArrayRef> elements(
|
| IOHIDDeviceCopyMatchingElements(device, NULL, kIOHIDOptionsTypeNone));
|
| @@ -320,7 +334,8 @@ void GamepadPlatformDataFetcherMac::ValueChanged(IOHIDValueRef value) {
|
| // Find and fill in the associated button event, if any.
|
| for (size_t i = 0; i < pad.buttonsLength; ++i) {
|
| if (associated.hid.button_elements[i] == element) {
|
| - pad.buttons[i] = IOHIDValueGetIntegerValue(value) ? 1.f : 0.f;
|
| + pad.buttons[i].pressed = IOHIDValueGetIntegerValue(value);
|
| + pad.buttons[i].value = pad.buttons[i].pressed ? 1.f : 0.f;
|
| pad.timestamp = std::max(pad.timestamp, IOHIDValueGetTimeStamp(value));
|
| return;
|
| }
|
| @@ -355,11 +370,15 @@ void GamepadPlatformDataFetcherMac::XboxDeviceAdd(XboxController* device) {
|
| [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));
|
| +
|
| + CopyNSStringAsUTF16LittleEndian(
|
| + @"standard",
|
| + data_.items[slot].mapping,
|
| + sizeof(data_.items[slot].mapping));
|
|
|
| associated_[slot].is_xbox = true;
|
| associated_[slot].xbox.device = device;
|
| @@ -406,12 +425,16 @@ void GamepadPlatformDataFetcherMac::XboxValueChanged(
|
| WebGamepad& pad = data_.items[slot];
|
|
|
| for (size_t i = 0; i < 6; i++) {
|
| - pad.buttons[i] = data.buttons[i] ? 1.0f : 0.0f;
|
| + pad.buttons[i].pressed = data.buttons[i];
|
| + pad.buttons[i].value = data.buttons[i] ? 1.0f : 0.0f;
|
| }
|
| - pad.buttons[6] = data.triggers[0];
|
| - pad.buttons[7] = data.triggers[1];
|
| + pad.buttons[6].pressed = data.triggers[0] > kDefaultButtonPressedThreshold;
|
| + pad.buttons[6].value = data.triggers[0];
|
| + pad.buttons[7].pressed = data.triggers[1] > kDefaultButtonPressedThreshold;
|
| + pad.buttons[7].value = data.triggers[1];
|
| for (size_t i = 8; i < 17; i++) {
|
| - pad.buttons[i] = data.buttons[i - 2] ? 1.0f : 0.0f;
|
| + pad.buttons[i].pressed = data.buttons[i - 2];
|
| + pad.buttons[i].value = data.buttons[i - 2] ? 1.0f : 0.0f;
|
| }
|
| for (size_t i = 0; i < arraysize(data.axes); i++) {
|
| pad.axes[i] = data.axes[i];
|
|
|