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.
5 #ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_
6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/mac/scoped_cftyperef.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "build/build_config.h"
13 #include "content/browser/gamepad/gamepad_data_fetcher.h"
14 #include "content/browser/gamepad/gamepad_standard_mappings.h"
15 #include "content/browser/gamepad/xbox_data_fetcher_mac.h"
16 #include "content/common/gamepad_hardware_buffer.h"
17 #include "third_party/WebKit/public/platform/WebGamepads.h"
19 #include <CoreFoundation/CoreFoundation.h>
20 #include <IOKit/hid/IOHIDManager.h>
30 class GamepadPlatformDataFetcherMac
: public GamepadDataFetcher
,
31 public XboxDataFetcher::Delegate
{
33 GamepadPlatformDataFetcherMac();
34 ~GamepadPlatformDataFetcherMac() override
;
35 void GetGamepadData(blink::WebGamepads
* pads
,
36 bool devices_changed_hint
) override
;
37 void PauseHint(bool paused
) override
;
42 base::ScopedCFTypeRef
<IOHIDManagerRef
> hid_manager_ref_
;
44 static GamepadPlatformDataFetcherMac
* InstanceFromContext(void* context
);
45 static void DeviceAddCallback(void* context
,
49 static void DeviceRemoveCallback(void* context
,
53 static void ValueChangedCallback(void* context
,
58 size_t GetEmptySlot();
59 size_t GetSlotForDevice(IOHIDDeviceRef device
);
60 size_t GetSlotForXboxDevice(XboxController
* device
);
62 void DeviceAdd(IOHIDDeviceRef device
);
63 bool AddButtonsAndAxes(NSArray
* elements
, size_t slot
);
64 void DeviceRemove(IOHIDDeviceRef device
);
65 void ValueChanged(IOHIDValueRef value
);
67 void XboxDeviceAdd(XboxController
* device
) override
;
68 void XboxDeviceRemove(XboxController
* device
) override
;
69 void XboxValueChanged(XboxController
* device
,
70 const XboxController::Data
& data
) override
;
72 void RegisterForNotifications();
73 void UnregisterFromNotifications();
75 scoped_ptr
<XboxDataFetcher
> xbox_fetcher_
;
77 blink::WebGamepads data_
;
79 // Side-band data that's not passed to the consumer, but we need to maintain
81 struct AssociatedData
{
85 IOHIDDeviceRef device_ref
;
86 IOHIDElementRef button_elements
[blink::WebGamepad::buttonsLengthCap
];
87 IOHIDElementRef axis_elements
[blink::WebGamepad::axesLengthCap
];
88 CFIndex axis_minimums
[blink::WebGamepad::axesLengthCap
];
89 CFIndex axis_maximums
[blink::WebGamepad::axesLengthCap
];
90 // Function to map from device data to standard layout, if available.
91 // May be null if no mapping is available.
92 GamepadStandardMappingFunction mapper
;
95 XboxController
* device
;
100 AssociatedData associated_
[blink::WebGamepads::itemsLengthCap
];
102 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherMac
);
105 } // namespace content
107 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_