Chromium Code Reviews| 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/memory/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.h" | 12 #include "base/time.h" |
| 13 | 13 |
| 14 #import <Foundation/Foundation.h> | |
| 14 #include <IOKit/hid/IOHIDKeys.h> | 15 #include <IOKit/hid/IOHIDKeys.h> |
| 15 #import <Foundation/Foundation.h> | |
| 16 | 16 |
| 17 using WebKit::WebGamepad; | 17 using WebKit::WebGamepad; |
| 18 using WebKit::WebGamepads; | 18 using WebKit::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: |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 53 if (!xbox_fetcher_->RegisterForNotifications()) | 53 if (!xbox_fetcher_->RegisterForNotifications()) |
| 54 xbox_fetcher_.reset(); | 54 xbox_fetcher_.reset(); |
| 55 | 55 |
| 56 hid_manager_ref_.reset(IOHIDManagerCreate(kCFAllocatorDefault, | 56 hid_manager_ref_.reset(IOHIDManagerCreate(kCFAllocatorDefault, |
| 57 kIOHIDOptionsTypeNone)); | 57 kIOHIDOptionsTypeNone)); |
| 58 if (CFGetTypeID(hid_manager_ref_) != IOHIDManagerGetTypeID()) { | 58 if (CFGetTypeID(hid_manager_ref_) != IOHIDManagerGetTypeID()) { |
| 59 enabled_ = false; | 59 enabled_ = false; |
| 60 return; | 60 return; |
| 61 } | 61 } |
| 62 | 62 |
| 63 scoped_nsobject<NSArray> criteria([[NSArray alloc] initWithObjects: | 63 base::scoped_nsobject<NSArray> criteria([[NSArray alloc] initWithObjects: |
| 64 DeviceMatching(kGenericDesktopUsagePage, kJoystickUsageNumber), | 64 DeviceMatching(kGenericDesktopUsagePage, kJoystickUsageNumber), |
| 65 DeviceMatching(kGenericDesktopUsagePage, kGameUsageNumber), | 65 DeviceMatching(kGenericDesktopUsagePage, kGameUsageNumber), |
| 66 DeviceMatching(kGenericDesktopUsagePage, kMultiAxisUsageNumber), | 66 DeviceMatching(kGenericDesktopUsagePage, kMultiAxisUsageNumber), |
| 67 nil]); | 67 nil]); |
|
Nico
2013/06/25 01:09:50
This is maybe partially PR16185.
| |
| 68 IOHIDManagerSetDeviceMatchingMultiple( | 68 IOHIDManagerSetDeviceMatchingMultiple( |
| 69 hid_manager_ref_, | 69 hid_manager_ref_, |
| 70 base::mac::NSToCFCast(criteria)); | 70 base::mac::NSToCFCast(criteria)); |
| 71 | 71 |
| 72 RegisterForNotifications(); | 72 RegisterForNotifications(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void GamepadPlatformDataFetcherMac::RegisterForNotifications() { | 75 void GamepadPlatformDataFetcherMac::RegisterForNotifications() { |
| 76 // Register for plug/unplug notifications. | 76 // Register for plug/unplug notifications. |
| 77 IOHIDManagerRegisterDeviceMatchingCallback( | 77 IOHIDManagerRegisterDeviceMatchingCallback( |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 pads->length = WebGamepads::itemsLengthCap; | 432 pads->length = WebGamepads::itemsLengthCap; |
| 433 for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) { | 433 for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) { |
| 434 if (!associated_[i].is_xbox && associated_[i].hid.mapper) | 434 if (!associated_[i].is_xbox && associated_[i].hid.mapper) |
| 435 associated_[i].hid.mapper(data_.items[i], &pads->items[i]); | 435 associated_[i].hid.mapper(data_.items[i], &pads->items[i]); |
| 436 else | 436 else |
| 437 pads->items[i] = data_.items[i]; | 437 pads->items[i] = data_.items[i]; |
| 438 } | 438 } |
| 439 } | 439 } |
| 440 | 440 |
| 441 } // namespace content | 441 } // namespace content |
| OLD | NEW |