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