OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_ |
| 6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" |
| 10 #include "base/mac/scoped_cftyperef.h" |
| 11 #include "build/build_config.h" |
| 12 #include "content/browser/gamepad/gamepad_data_fetcher.h" |
| 13 #include "content/browser/gamepad/gamepad_standard_mappings.h" |
| 14 #include "content/common/gamepad_hardware_buffer.h" |
| 15 |
| 16 #include <CoreFoundation/CoreFoundation.h> |
| 17 #include <IOKit/hid/IOHIDManager.h> |
| 18 |
| 19 #if defined(__OBJC__) |
| 20 @class NSArray; |
| 21 #else |
| 22 class NSArray; |
| 23 #endif |
| 24 |
| 25 namespace content { |
| 26 |
| 27 class GamepadPlatformDataFetcherMac : public GamepadDataFetcher { |
| 28 public: |
| 29 GamepadPlatformDataFetcherMac(); |
| 30 virtual ~GamepadPlatformDataFetcherMac(); |
| 31 virtual void GetGamepadData(WebKit::WebGamepads* pads, |
| 32 bool devices_changed_hint) OVERRIDE; |
| 33 virtual void PauseHint(bool paused) OVERRIDE; |
| 34 |
| 35 private: |
| 36 bool enabled_; |
| 37 base::mac::ScopedCFTypeRef<IOHIDManagerRef> hid_manager_ref_; |
| 38 |
| 39 static GamepadPlatformDataFetcherMac* InstanceFromContext(void* context); |
| 40 static void DeviceAddCallback(void* context, |
| 41 IOReturn result, |
| 42 void* sender, |
| 43 IOHIDDeviceRef ref); |
| 44 static void DeviceRemoveCallback(void* context, |
| 45 IOReturn result, |
| 46 void* sender, |
| 47 IOHIDDeviceRef ref); |
| 48 static void ValueChangedCallback(void* context, |
| 49 IOReturn result, |
| 50 void* sender, |
| 51 IOHIDValueRef ref); |
| 52 |
| 53 void DeviceAdd(IOHIDDeviceRef device); |
| 54 void AddButtonsAndAxes(NSArray* elements, size_t slot); |
| 55 void DeviceRemove(IOHIDDeviceRef device); |
| 56 void ValueChanged(IOHIDValueRef value); |
| 57 |
| 58 void RegisterForNotifications(); |
| 59 void UnregisterFromNotifications(); |
| 60 |
| 61 WebKit::WebGamepads data_; |
| 62 |
| 63 // Side-band data that's not passed to the consumer, but we need to maintain |
| 64 // to update data_. |
| 65 struct AssociatedData { |
| 66 IOHIDDeviceRef device_ref; |
| 67 IOHIDElementRef button_elements[WebKit::WebGamepad::buttonsLengthCap]; |
| 68 IOHIDElementRef axis_elements[WebKit::WebGamepad::buttonsLengthCap]; |
| 69 CFIndex axis_minimums[WebKit::WebGamepad::axesLengthCap]; |
| 70 CFIndex axis_maximums[WebKit::WebGamepad::axesLengthCap]; |
| 71 // Function to map from device data to standard layout, if available. May |
| 72 // be null if no mapping is available. |
| 73 GamepadStandardMappingFunction mapper; |
| 74 }; |
| 75 AssociatedData associated_[WebKit::WebGamepads::itemsLengthCap]; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherMac); |
| 78 }; |
| 79 |
| 80 } // namespace content |
| 81 |
| 82 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_ |
OLD | NEW |