Add ICU message format support
[chromium-blink-merge.git] / content / browser / gamepad / gamepad_platform_data_fetcher_win.h
blob33dab0ca2e65a4a16fbd61a37139b69462c7e924
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_WIN_H_
6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_
8 #include "build/build_config.h"
10 #ifndef WIN32_LEAN_AND_MEAN
11 #define WIN32_LEAN_AND_MEAN
12 #endif
13 #include <stdlib.h>
14 #include <Unknwn.h>
15 #include <WinDef.h>
16 #include <windows.h>
17 #include <XInput.h>
19 #include "base/basictypes.h"
20 #include "base/compiler_specific.h"
21 #include "base/memory/scoped_ptr.h"
22 #include "base/memory/weak_ptr.h"
23 #include "base/message_loop/message_loop.h"
24 #include "base/scoped_native_library.h"
25 #include "content/browser/gamepad/gamepad_data_fetcher.h"
26 #include "content/browser/gamepad/gamepad_standard_mappings.h"
27 #include "content/browser/gamepad/raw_input_data_fetcher_win.h"
28 #include "third_party/WebKit/public/platform/WebGamepads.h"
30 namespace content {
32 class GamepadPlatformDataFetcherWin : public GamepadDataFetcher {
33 public:
34 GamepadPlatformDataFetcherWin();
35 ~GamepadPlatformDataFetcherWin() override;
36 void GetGamepadData(blink::WebGamepads* pads,
37 bool devices_changed_hint) override;
38 void PauseHint(bool paused) override;
40 private:
41 // XInput-specific implementation for GetGamepadData.
42 bool GetXInputGamepadData(blink::WebGamepads* pads,
43 bool devices_changed_hint);
45 // The three function types we use from xinput1_3.dll.
46 typedef void (WINAPI *XInputEnableFunc)(BOOL enable);
47 typedef DWORD (WINAPI *XInputGetCapabilitiesFunc)(
48 DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities);
49 typedef DWORD (WINAPI *XInputGetStateFunc)(
50 DWORD dwUserIndex, XINPUT_STATE* pState);
52 // Get functions from dynamically loaded xinput1_3.dll. We don't use
53 // DELAYLOAD because the import library for Win8 SDK pulls xinput1_4 which
54 // isn't redistributable. Returns true if loading was successful. We include
55 // xinput1_3.dll with Chrome.
56 bool GetXInputDllFunctions();
58 // Scan for connected XInput and DirectInput gamepads.
59 void EnumerateDevices(blink::WebGamepads* pads);
60 bool GetXInputPadConnectivity(int i, blink::WebGamepad* pad) const;
62 void GetXInputPadData(int i, blink::WebGamepad* pad);
63 void GetRawInputPadData(int i, blink::WebGamepad* pad);
65 int FirstAvailableGamepadId() const;
66 bool HasXInputGamepad(int index) const;
67 bool HasRawInputGamepad(const HANDLE handle) const;
69 base::ScopedNativeLibrary xinput_dll_;
70 bool xinput_available_;
72 // Function pointers to XInput functionality, retrieved in
73 // |GetXinputDllFunctions|.
74 XInputEnableFunc xinput_enable_;
75 XInputGetCapabilitiesFunc xinput_get_capabilities_;
76 XInputGetStateFunc xinput_get_state_;
78 enum PadConnectionStatus {
79 DISCONNECTED,
80 XINPUT_CONNECTED,
81 RAWINPUT_CONNECTED
84 struct PadState {
85 PadConnectionStatus status;
86 GamepadStandardMappingFunction mapper;
88 int xinput_index; // XInput-only
89 HANDLE raw_input_handle; // RawInput-only fields.
91 PadState pad_state_[blink::WebGamepads::itemsLengthCap];
93 scoped_ptr<RawInputDataFetcher> raw_input_fetcher_;
95 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherWin);
98 } // namespace content
100 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_