GameController.framework backend for gamepad API.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Aug 2016 22:23:20 +0000 (22:23 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Aug 2016 22:23:20 +0000 (22:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=161086

Reviewed by Alex Christensen.

Source/WebCore:

No new tests (Native framework backends not directly testable)

* WebCore.xcodeproj/project.pbxproj:

* platform/gamepad/cocoa/GameControllerGamepad.h: Copied from Source/WebKit2/UIProcess/Gamepad/mac/UIGamepadProviderHID.cpp.
* platform/gamepad/cocoa/GameControllerGamepad.mm: Added.
(WebCore::GameControllerGamepad::GameControllerGamepad):
(WebCore::GameControllerGamepad::setupAsExtendedGamepad):
(WebCore::GameControllerGamepad::setupAsGamepad):

* platform/gamepad/cocoa/GameControllerGamepadProvider.h: Added.
* platform/gamepad/cocoa/GameControllerGamepadProvider.mm: Added.
(WebCore::GameControllerGamepadProvider::singleton):
(WebCore::GameControllerGamepadProvider::GameControllerGamepadProvider):
(WebCore::GameControllerGamepadProvider::controllerDidConnect):
(WebCore::GameControllerGamepadProvider::controllerDidDisconnect):
(WebCore::GameControllerGamepadProvider::startMonitoringGamepads):
(WebCore::GameControllerGamepadProvider::stopMonitoringGamepads):
(WebCore::GameControllerGamepadProvider::indexForNewlyConnectedDevice):
(WebCore::GameControllerGamepadProvider::gamepadHadInput):
(WebCore::GameControllerGamepadProvider::makeInvisibileGamepadsVisible):
(WebCore::GameControllerGamepadProvider::inputNotificationTimerFired):

Source/WebKit2:

* UIProcess/API/Cocoa/WKProcessPool.mm:
(+[WKProcessPool _forceGameControllerFramework]):
* UIProcess/API/Cocoa/WKProcessPoolPrivate.h:

* UIProcess/Gamepad/UIGamepadProvider.h:

* UIProcess/Gamepad/cocoa/UIGamepadProviderCocoa.mm: Renamed from Source/WebKit2/UIProcess/Gamepad/mac/UIGamepadProviderHID.cpp.
(WebKit::UIGamepadProvider::setUsesGameControllerFramework):
(WebKit::UIGamepadProvider::platformSetDefaultGamepadProvider):
(WebKit::UIGamepadProvider::platformStopMonitoringInput):
(WebKit::UIGamepadProvider::platformStartMonitoringInput):

* WebKit2.xcodeproj/project.pbxproj:

Source/WTF:

* wtf/RunLoop.h:
(WTF::RunLoop::TimerBase::startOneShot):

Tools:

* MiniBrowser/mac/AppDelegate.m:
(-[BrowserAppDelegate awakeFromNib]):

* MiniBrowser/mac/SettingsController.h:
* MiniBrowser/mac/SettingsController.m:
(-[SettingsController _populateMenu]):
(-[SettingsController validateMenuItem:]):
(-[SettingsController usesGameControllerFramework]):
(-[SettingsController toggleUsesGameControllerFramework:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@205199 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/RunLoop.h
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.h [new file with mode: 0644]
Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.mm [new file with mode: 0644]
Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.h [new file with mode: 0644]
Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.mm [new file with mode: 0644]
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKProcessPool.mm
Source/WebKit2/UIProcess/API/Cocoa/WKProcessPoolPrivate.h
Source/WebKit2/UIProcess/Gamepad/UIGamepadProvider.h
Source/WebKit2/UIProcess/Gamepad/cocoa/UIGamepadProviderCocoa.mm [moved from Source/WebKit2/UIProcess/Gamepad/mac/UIGamepadProviderHID.cpp with 70% similarity]
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Tools/ChangeLog
Tools/MiniBrowser/mac/AppDelegate.m
Tools/MiniBrowser/mac/SettingsController.h
Tools/MiniBrowser/mac/SettingsController.m

index 810b3c3..fe9001c 100644 (file)
@@ -1,3 +1,13 @@
+2016-08-30  Brady Eidson  <beidson@apple.com>
+
+        GameController.framework backend for gamepad API.
+        https://bugs.webkit.org/show_bug.cgi?id=161086
+
+        Reviewed by Alex Christensen.
+
+        * wtf/RunLoop.h:
+        (WTF::RunLoop::TimerBase::startOneShot):
+
 2016-08-30  Mark Lam  <mark.lam@apple.com>
 
         Introduce the ThrowScope and force every throw site to instantiate a ThrowScope.
index 3611d7a..555d447 100644 (file)
@@ -91,6 +91,7 @@ public:
         void startRepeating(double repeatInterval) { start(repeatInterval, true); }
         void startRepeating(std::chrono::milliseconds repeatInterval) { startRepeating(repeatInterval.count() * 0.001); }
         void startOneShot(double interval) { start(interval, false); }
+        void startOneShot(std::chrono::milliseconds interval) { start(interval.count() * 0.001, false); }
 
         WTF_EXPORT_PRIVATE void stop();
         WTF_EXPORT_PRIVATE bool isActive() const;
index 1e6087d..1314447 100644 (file)
@@ -1,3 +1,33 @@
+2016-08-30  Brady Eidson  <beidson@apple.com>
+
+        GameController.framework backend for gamepad API.
+        https://bugs.webkit.org/show_bug.cgi?id=161086
+
+        Reviewed by Alex Christensen.
+
+        No new tests (Native framework backends not directly testable)
+
+        * WebCore.xcodeproj/project.pbxproj:
+        
+        * platform/gamepad/cocoa/GameControllerGamepad.h: Copied from Source/WebKit2/UIProcess/Gamepad/mac/UIGamepadProviderHID.cpp.
+        * platform/gamepad/cocoa/GameControllerGamepad.mm: Added.
+        (WebCore::GameControllerGamepad::GameControllerGamepad):
+        (WebCore::GameControllerGamepad::setupAsExtendedGamepad):
+        (WebCore::GameControllerGamepad::setupAsGamepad):
+        
+        * platform/gamepad/cocoa/GameControllerGamepadProvider.h: Added.
+        * platform/gamepad/cocoa/GameControllerGamepadProvider.mm: Added.
+        (WebCore::GameControllerGamepadProvider::singleton):
+        (WebCore::GameControllerGamepadProvider::GameControllerGamepadProvider):
+        (WebCore::GameControllerGamepadProvider::controllerDidConnect):
+        (WebCore::GameControllerGamepadProvider::controllerDidDisconnect):
+        (WebCore::GameControllerGamepadProvider::startMonitoringGamepads):
+        (WebCore::GameControllerGamepadProvider::stopMonitoringGamepads):
+        (WebCore::GameControllerGamepadProvider::indexForNewlyConnectedDevice):
+        (WebCore::GameControllerGamepadProvider::gamepadHadInput):
+        (WebCore::GameControllerGamepadProvider::makeInvisibileGamepadsVisible):
+        (WebCore::GameControllerGamepadProvider::inputNotificationTimerFired):
+
 2016-08-30  Mark Lam  <mark.lam@apple.com>
 
         Introduce the ThrowScope and force every throw site to instantiate a ThrowScope.
index 8f53fbe..f2d7d45 100644 (file)
                51ABAE1E103C1913008C5260 /* SocketStreamHandleImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 51ABAE1C103C1913008C5260 /* SocketStreamHandleImpl.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51ABAE1F103C1913008C5260 /* SocketStreamHandleImplCFNet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51ABAE1D103C1913008C5260 /* SocketStreamHandleImplCFNet.cpp */; };
                51ABF64D16392E2800132A7A /* LoaderStrategy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51ABF64C16392E2800132A7A /* LoaderStrategy.cpp */; };
+               51AEA4C91D6E3CC900E0269D /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 51AEA4C81D6E3CC100E0269D /* GameController.framework */; };
                51AF503616F100F60095B2E8 /* ResourceLoaderTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 51AF503516F100F60095B2E8 /* ResourceLoaderTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51B2417B0D931F3F00E83F5C /* LegacyWebArchiveMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51B2417A0D931F3F00E83F5C /* LegacyWebArchiveMac.mm */; };
                51B454EA1B4DAE7D0085EAA6 /* PingHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = 51B454E91B4DAE7D0085EAA6 /* PingHandle.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51E1ECC10C91C90400DC255B /* IconRecord.h in Headers */ = {isa = PBXBuildFile; fileRef = 51E1ECBB0C91C90400DC255B /* IconRecord.h */; };
                51E1ECC20C91C90400DC255B /* PageURLRecord.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51E1ECBC0C91C90400DC255B /* PageURLRecord.cpp */; };
                51E1ECC30C91C90400DC255B /* PageURLRecord.h in Headers */ = {isa = PBXBuildFile; fileRef = 51E1ECBD0C91C90400DC255B /* PageURLRecord.h */; };
+               51E399001D6E4750009C8831 /* GameControllerGamepad.h in Headers */ = {isa = PBXBuildFile; fileRef = 51E398FC1D6E474B009C8831 /* GameControllerGamepad.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               51E399011D6E4750009C8831 /* GameControllerGamepad.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E398FD1D6E474B009C8831 /* GameControllerGamepad.mm */; };
+               51E399021D6E4750009C8831 /* GameControllerGamepadProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 51E398FE1D6E474B009C8831 /* GameControllerGamepadProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               51E399031D6E4750009C8831 /* GameControllerGamepadProvider.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E398FF1D6E474B009C8831 /* GameControllerGamepadProvider.mm */; };
                51E3AA0A1B98BCAB0036AD81 /* SecurityOriginData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51E3AA081B98BC9A0036AD81 /* SecurityOriginData.cpp */; };
                51E3AA0B1B98BCAB0036AD81 /* SecurityOriginData.h in Headers */ = {isa = PBXBuildFile; fileRef = 51E3AA091B98BC9A0036AD81 /* SecurityOriginData.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51E3F9C70DA059DC00250911 /* Storage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51E3F9C50DA059DC00250911 /* Storage.cpp */; };
                51ABAE1C103C1913008C5260 /* SocketStreamHandleImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SocketStreamHandleImpl.h; sourceTree = "<group>"; };
                51ABAE1D103C1913008C5260 /* SocketStreamHandleImplCFNet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SocketStreamHandleImplCFNet.cpp; sourceTree = "<group>"; };
                51ABF64C16392E2800132A7A /* LoaderStrategy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoaderStrategy.cpp; sourceTree = "<group>"; };
+               51AEA4C81D6E3CC100E0269D /* GameController.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GameController.framework; path = ../../../../../../System/Library/Frameworks/GameController.framework; sourceTree = "<group>"; };
                51AF503516F100F60095B2E8 /* ResourceLoaderTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceLoaderTypes.h; sourceTree = "<group>"; };
                51B2417A0D931F3F00E83F5C /* LegacyWebArchiveMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LegacyWebArchiveMac.mm; sourceTree = "<group>"; };
                51B454E91B4DAE7D0085EAA6 /* PingHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PingHandle.h; sourceTree = "<group>"; };
                51E1ECBB0C91C90400DC255B /* IconRecord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IconRecord.h; sourceTree = "<group>"; };
                51E1ECBC0C91C90400DC255B /* PageURLRecord.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PageURLRecord.cpp; sourceTree = "<group>"; };
                51E1ECBD0C91C90400DC255B /* PageURLRecord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PageURLRecord.h; sourceTree = "<group>"; };
+               51E398FC1D6E474B009C8831 /* GameControllerGamepad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameControllerGamepad.h; sourceTree = "<group>"; };
+               51E398FD1D6E474B009C8831 /* GameControllerGamepad.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GameControllerGamepad.mm; sourceTree = "<group>"; };
+               51E398FE1D6E474B009C8831 /* GameControllerGamepadProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameControllerGamepadProvider.h; sourceTree = "<group>"; };
+               51E398FF1D6E474B009C8831 /* GameControllerGamepadProvider.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GameControllerGamepadProvider.mm; sourceTree = "<group>"; };
                51E3AA081B98BC9A0036AD81 /* SecurityOriginData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SecurityOriginData.cpp; sourceTree = "<group>"; };
                51E3AA091B98BC9A0036AD81 /* SecurityOriginData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecurityOriginData.h; sourceTree = "<group>"; };
                51E3F9C40DA059DC00250911 /* Storage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Storage.h; sourceTree = "<group>"; };
                                93F19B1608245E59001E9ABC /* JavaScriptCore.framework in Frameworks */,
                                93F19B1708245E59001E9ABC /* libicucore.dylib in Frameworks */,
                                1CFAE3230A6D6A3F0032593D /* libobjc.dylib in Frameworks */,
+                               51AEA4C91D6E3CC900E0269D /* GameController.framework in Frameworks */,
                                DD763BB20992C2C900740B8E /* libxml2.dylib in Frameworks */,
                                379919B21200DE5000EA041C /* libz.dylib in Frameworks */,
                                A88AD52F09524B92001DD196 /* QuartzCore.framework in Frameworks */,
                                FD2DBF0E12B048A300ED98C6 /* Accelerate.framework */,
                                FD2DBF0F12B048A300ED98C6 /* AudioToolbox.framework */,
                                AA5F3B9016CC5BEB00455EB0 /* CoreFoundation.framework */,
+                               51AEA4C81D6E3CC100E0269D /* GameController.framework */,
                                1AB33DA412551E320024457A /* IOKit.framework */,
                                F8216299029F4FB501000131 /* JavaScriptCore.framework */,
                                93F1D31A0558CC5C00821BC0 /* libicucore.dylib */,
                515BE1871D54F5DB00DD7C68 /* gamepad */ = {
                        isa = PBXGroup;
                        children = (
+                               51AEA4BF1D6E3C2300E0269D /* cocoa */,
                                515BE1961D54F64500DD7C68 /* mac */,
                                515BE1881D54F5F600DD7C68 /* EmptyGamepadProvider.cpp */,
                                515BE1891D54F5F600DD7C68 /* EmptyGamepadProvider.h */,
                        name = Gamepad;
                        sourceTree = "<group>";
                };
+               51AEA4BF1D6E3C2300E0269D /* cocoa */ = {
+                       isa = PBXGroup;
+                       children = (
+                               51E398FC1D6E474B009C8831 /* GameControllerGamepad.h */,
+                               51E398FD1D6E474B009C8831 /* GameControllerGamepad.mm */,
+                               51E398FE1D6E474B009C8831 /* GameControllerGamepadProvider.h */,
+                               51E398FF1D6E474B009C8831 /* GameControllerGamepadProvider.mm */,
+                       );
+                       path = cocoa;
+                       sourceTree = "<group>";
+               };
                51C4AA5118B28357007BFE9B /* mac */ = {
                        isa = PBXGroup;
                        children = (
                                B2FA3D670AB75A6F000E5AC4 /* JSSVGDocument.h in Headers */,
                                B222F69D0AB771B80022EFAD /* JSSVGElement.h in Headers */,
                                8542A7990AE5C94400DF58DF /* JSSVGElementWrapperFactory.h in Headers */,
+                               51E399001D6E4750009C8831 /* GameControllerGamepad.h in Headers */,
                                B2FA3D690AB75A6F000E5AC4 /* JSSVGEllipseElement.h in Headers */,
                                B266CD4E0C3AEC6500EB08D2 /* JSSVGException.h in Headers */,
                                B2FA3D6B0AB75A6F000E5AC4 /* JSSVGFEBlendElement.h in Headers */,
                                CDA07FBE18E0A16A004699FA /* SystemSleepListener.h in Headers */,
                                CDA07FC218E0A22B004699FA /* SystemSleepListenerMac.h in Headers */,
                                5D5975B319635F1100D00878 /* SystemVersion.h in Headers */,
+                               51E399021D6E4750009C8831 /* GameControllerGamepadProvider.h in Headers */,
                                A8CFF0510A154F09000A4234 /* TableLayout.h in Headers */,
                                463EB6231B8789E00096ED51 /* TagCollection.h in Headers */,
                                F55B3DD61251F12D003EF269 /* TelephoneInputType.h in Headers */,
                                B2FA3D680AB75A6F000E5AC4 /* JSSVGEllipseElement.cpp in Sources */,
                                B266CD4D0C3AEC6500EB08D2 /* JSSVGException.cpp in Sources */,
                                B2FA3D6A0AB75A6F000E5AC4 /* JSSVGFEBlendElement.cpp in Sources */,
+                               51E399031D6E4750009C8831 /* GameControllerGamepadProvider.mm in Sources */,
                                B2FA3D6C0AB75A6F000E5AC4 /* JSSVGFEColorMatrixElement.cpp in Sources */,
                                B2FA3D6E0AB75A6F000E5AC4 /* JSSVGFEComponentTransferElement.cpp in Sources */,
                                B2FA3D700AB75A6F000E5AC4 /* JSSVGFECompositeElement.cpp in Sources */,
                                E43105B816750F0C00DB2FB8 /* NodeTraversal.cpp in Sources */,
                                33503CC71017A1B1003B47E1 /* Notification.cpp in Sources */,
                                3390CA550FFC157B00921962 /* NotificationCenter.cpp in Sources */,
+                               51E399011D6E4750009C8831 /* GameControllerGamepad.mm in Sources */,
                                3128CA68147331520074C72A /* NotificationController.cpp in Sources */,
                                E1513D511677F08800149FCB /* NotImplemented.cpp in Sources */,
                                1A569D0A0D7E2B82007C3983 /* NP_jsobject.cpp in Sources */,
diff --git a/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.h b/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.h
new file mode 100644 (file)
index 0000000..38cc07d
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(GAMEPAD) && defined(__LP64__)
+
+#include "PlatformGamepad.h"
+#include <wtf/RetainPtr.h>
+
+OBJC_CLASS GCController;
+OBJC_CLASS GCControllerAxisInput;
+OBJC_CLASS GCControllerButtonInput;
+OBJC_CLASS GCControllerElement;
+OBJC_CLASS GCExtendedGamepad;
+OBJC_CLASS GCGamepad;
+
+namespace WebCore {
+
+class GameControllerGamepad : public PlatformGamepad {
+    WTF_MAKE_NONCOPYABLE(GameControllerGamepad);
+public:
+    GameControllerGamepad(GCController *, unsigned index);
+
+    const Vector<double>& axisValues() const final { return m_axisValues; }
+    const Vector<double>& buttonValues() const final { return m_buttonValues; }
+
+private:
+    void setupAsExtendedGamepad();
+    void setupAsGamepad();
+
+    RetainPtr<GCController> m_gcController;
+
+    Vector<double> m_axisValues;
+    Vector<double> m_buttonValues;
+
+    RetainPtr<GCGamepad> m_gamepad;
+    RetainPtr<GCExtendedGamepad> m_extendedGamepad;
+};
+
+
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD) && defined(__LP64__)
+
diff --git a/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.mm b/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.mm
new file mode 100644 (file)
index 0000000..80b0943
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "config.h"
+#include "GameControllerGamepad.h"
+
+#if ENABLE(GAMEPAD) && defined(__LP64__)
+#include "GameControllerGamepadProvider.h"
+#include <GameController/GameController.h>
+#include <wtf/CurrentTime.h>
+
+namespace WebCore {
+
+GameControllerGamepad::GameControllerGamepad(GCController *controller, unsigned index)
+    : PlatformGamepad(index)
+    , m_gcController(controller)
+{
+    ASSERT(index < 4);
+    controller.playerIndex = (GCControllerPlayerIndex)(GCControllerPlayerIndex1 + index);
+
+    m_extendedGamepad = controller.extendedGamepad;
+    if (!m_extendedGamepad)
+        m_gamepad = controller.gamepad;
+
+    ASSERT(m_extendedGamepad || m_gamepad);
+
+    if (m_extendedGamepad)
+        setupAsExtendedGamepad();
+    else
+        setupAsGamepad();
+}
+
+void GameControllerGamepad::setupAsExtendedGamepad()
+{
+    ASSERT(m_extendedGamepad);
+
+    m_id = makeString(String(m_gcController.get().vendorName), ASCIILiteral(" Extended Gamepad"));
+
+    m_extendedGamepad.get().valueChangedHandler = ^(GCExtendedGamepad *, GCControllerElement *) {
+        m_lastUpdateTime = monotonicallyIncreasingTime();
+        GameControllerGamepadProvider::singleton().gamepadHadInput(*this);
+    };
+
+    m_buttonValues.resize(8);
+    m_buttonValues[0] = m_extendedGamepad.get().buttonA.value;
+    m_buttonValues[1] = m_extendedGamepad.get().buttonB.value;
+    m_buttonValues[2] = m_extendedGamepad.get().buttonX.value;
+    m_buttonValues[3] = m_extendedGamepad.get().buttonY.value;
+    m_buttonValues[4] = m_extendedGamepad.get().leftShoulder.value;
+    m_buttonValues[5] = m_extendedGamepad.get().rightShoulder.value;
+    m_buttonValues[6] = m_extendedGamepad.get().leftTrigger.value;
+    m_buttonValues[7] = m_extendedGamepad.get().rightTrigger.value;
+
+    m_axisValues.resize(6);
+    m_axisValues[0] = m_extendedGamepad.get().leftThumbstick.xAxis.value;
+    m_axisValues[1] = m_extendedGamepad.get().leftThumbstick.yAxis.value;
+    m_axisValues[2] = m_extendedGamepad.get().rightThumbstick.xAxis.value;
+    m_axisValues[3] = m_extendedGamepad.get().rightThumbstick.yAxis.value;
+    m_axisValues[4] = m_extendedGamepad.get().dpad.xAxis.value;
+    m_axisValues[5] = m_extendedGamepad.get().dpad.yAxis.value;
+
+    m_extendedGamepad.get().buttonA.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+        m_buttonValues[0] = value;
+    };
+    m_extendedGamepad.get().buttonB.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+        m_buttonValues[1] = value;
+    };
+    m_extendedGamepad.get().buttonX.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+        m_buttonValues[2] = value;
+    };
+    m_extendedGamepad.get().buttonY.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+        m_buttonValues[3] = value;
+    };
+    m_extendedGamepad.get().leftShoulder.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+        m_buttonValues[4] = value;
+    };
+    m_extendedGamepad.get().rightShoulder.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+        m_buttonValues[5] = value;
+    };
+    m_extendedGamepad.get().leftTrigger.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+        m_buttonValues[6] = value;
+    };
+    m_extendedGamepad.get().rightTrigger.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+        m_buttonValues[7] = value;
+    };
+
+    m_extendedGamepad.get().leftThumbstick.xAxis.valueChangedHandler = ^(GCControllerAxisInput *, float value) {
+        m_axisValues[0] = value;
+    };
+    m_extendedGamepad.get().leftThumbstick.yAxis.valueChangedHandler = ^(GCControllerAxisInput *, float value) {
+        m_axisValues[1] = value;
+    };
+    m_extendedGamepad.get().rightThumbstick.xAxis.valueChangedHandler = ^(GCControllerAxisInput *, float value) {
+        m_axisValues[2] = value;
+    };
+    m_extendedGamepad.get().rightThumbstick.yAxis.valueChangedHandler = ^(GCControllerAxisInput *, float value) {
+        m_axisValues[3] = value;
+    };
+    m_extendedGamepad.get().dpad.xAxis.valueChangedHandler = ^(GCControllerAxisInput *, float value) {
+        m_axisValues[4] = value;
+    };
+    m_extendedGamepad.get().dpad.yAxis.valueChangedHandler = ^(GCControllerAxisInput *, float value) {
+        m_axisValues[5] = value;
+    };
+}
+
+void GameControllerGamepad::setupAsGamepad()
+{
+    ASSERT(m_gamepad);
+
+    m_id = makeString(String(m_gcController.get().vendorName), ASCIILiteral(" Gamepad"));
+
+    m_gamepad.get().valueChangedHandler = ^(GCGamepad *, GCControllerElement *) {
+        m_lastUpdateTime = monotonicallyIncreasingTime();
+        GameControllerGamepadProvider::singleton().gamepadHadInput(*this);
+    };
+
+    m_buttonValues.resize(6);
+    m_buttonValues[0] = m_extendedGamepad.get().buttonA.value;
+    m_buttonValues[1] = m_extendedGamepad.get().buttonB.value;
+    m_buttonValues[2] = m_extendedGamepad.get().buttonX.value;
+    m_buttonValues[3] = m_extendedGamepad.get().buttonY.value;
+    m_buttonValues[4] = m_extendedGamepad.get().leftShoulder.value;
+    m_buttonValues[5] = m_extendedGamepad.get().rightShoulder.value;
+
+    m_axisValues.resize(2);
+    m_axisValues[0] = m_extendedGamepad.get().dpad.xAxis.value;
+    m_axisValues[1] = m_extendedGamepad.get().dpad.yAxis.value;
+
+    m_extendedGamepad.get().buttonA.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+        m_buttonValues[0] = value;
+    };
+    m_extendedGamepad.get().buttonB.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+        m_buttonValues[1] = value;
+    };
+    m_extendedGamepad.get().buttonX.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+        m_buttonValues[2] = value;
+    };
+    m_extendedGamepad.get().buttonY.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+        m_buttonValues[3] = value;
+    };
+    m_extendedGamepad.get().leftShoulder.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+        m_buttonValues[4] = value;
+    };
+    m_extendedGamepad.get().rightShoulder.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+        m_buttonValues[5] = value;
+    };
+
+    m_extendedGamepad.get().leftThumbstick.xAxis.valueChangedHandler = ^(GCControllerAxisInput *, float value) {
+        m_axisValues[0] = value;
+    };
+    m_extendedGamepad.get().leftThumbstick.yAxis.valueChangedHandler = ^(GCControllerAxisInput *, float value) {
+        m_axisValues[1] = value;
+    };
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD) && defined(__LP64__)
diff --git a/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.h b/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.h
new file mode 100644 (file)
index 0000000..f700fcc
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(GAMEPAD) && defined(__LP64__)
+
+#include "GamepadProvider.h"
+#include <wtf/HashMap.h>
+#include <wtf/HashSet.h>
+#include <wtf/NeverDestroyed.h>
+#include <wtf/RetainPtr.h>
+#include <wtf/RunLoop.h>
+
+OBJC_CLASS GCController;
+OBJC_CLASS NSObject;
+
+namespace WebCore {
+
+class GameControllerGamepad;
+class GamepadProviderClient;
+
+class GameControllerGamepadProvider : public GamepadProvider {
+    WTF_MAKE_NONCOPYABLE(GameControllerGamepadProvider);
+    friend class NeverDestroyed<GameControllerGamepadProvider>;
+public:
+    WEBCORE_EXPORT static GameControllerGamepadProvider& singleton();
+
+    WEBCORE_EXPORT void startMonitoringGamepads(GamepadProviderClient&) final;
+    WEBCORE_EXPORT void stopMonitoringGamepads(GamepadProviderClient&) final;
+    const Vector<PlatformGamepad*>& platformGamepads() final { return m_gamepadVector; }
+
+    WEBCORE_EXPORT void stopMonitoringInput();
+    WEBCORE_EXPORT void startMonitoringInput();
+
+    void gamepadHadInput(GameControllerGamepad&);
+
+private:
+    GameControllerGamepadProvider();
+
+    enum class ConnectionVisibility {
+        Visible,
+        Invisible,
+    };
+
+    void controllerDidConnect(GCController *, ConnectionVisibility);
+    void controllerDidDisconnect(GCController *);
+
+    unsigned indexForNewlyConnectedDevice();
+
+    void inputNotificationTimerFired();
+
+    void makeInvisibileGamepadsVisible();
+
+    HashSet<GamepadProviderClient*> m_clients;
+
+    HashMap<GCController *, std::unique_ptr<GameControllerGamepad>> m_gamepadMap;
+    Vector<PlatformGamepad*> m_gamepadVector;
+    HashSet<PlatformGamepad*> m_invisibleGamepads;
+
+    RetainPtr<NSObject> m_connectObserver;
+    RetainPtr<NSObject> m_disconnectObserver;
+
+    RunLoop::Timer<GameControllerGamepadProvider> m_inputNotificationTimer;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD)
diff --git a/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.mm b/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.mm
new file mode 100644 (file)
index 0000000..e08a5c5
--- /dev/null
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#import "config.h"
+#import "GameControllerGamepadProvider.h"
+
+#if ENABLE(GAMEPAD) && defined(__LP64__)
+
+#import "GameControllerGamepad.h"
+#import "GamepadProviderClient.h"
+#import "Logging.h"
+#import <GameController/GameController.h>
+
+namespace WebCore {
+
+static const std::chrono::milliseconds InputNotificationDelay = 16ms;
+
+GameControllerGamepadProvider& GameControllerGamepadProvider::singleton()
+{
+    static NeverDestroyed<GameControllerGamepadProvider> sharedProvider;
+    return sharedProvider;
+}
+
+GameControllerGamepadProvider::GameControllerGamepadProvider()
+    : m_inputNotificationTimer(RunLoop::current(), this, &GameControllerGamepadProvider::inputNotificationTimerFired)
+
+{
+}
+
+void GameControllerGamepadProvider::controllerDidConnect(GCController *controller, ConnectionVisibility visibility)
+{
+    LOG(Gamepad, "GameControllerGamepadProvider controller %p added", controller);
+
+    unsigned index = indexForNewlyConnectedDevice();
+    auto gamepad = std::make_unique<GameControllerGamepad>(controller, index);
+
+    if (m_gamepadVector.size() <= index)
+        m_gamepadVector.resize(index + 1);
+
+    m_gamepadVector[index] = gamepad.get();
+    m_gamepadMap.set(controller, WTFMove(gamepad));
+
+
+    if (visibility == ConnectionVisibility::Invisible) {
+        m_invisibleGamepads.add(m_gamepadVector[index]);
+        return;
+    }
+
+    makeInvisibileGamepadsVisible();
+
+    for (auto& client : m_clients)
+        client->platformGamepadConnected(*m_gamepadVector[index]);
+}
+
+void GameControllerGamepadProvider::controllerDidDisconnect(GCController *controller)
+{
+    LOG(Gamepad, "GameControllerGamepadProvider controller %p removed", controller);
+
+    auto removedGamepad = m_gamepadMap.take(controller);
+    ASSERT(removedGamepad);
+
+    auto i = m_gamepadVector.find(removedGamepad.get());
+    if (i != notFound)
+        m_gamepadVector[i] = nullptr;
+
+    m_invisibleGamepads.remove(removedGamepad.get());
+
+    for (auto& client : m_clients)
+        client->platformGamepadDisconnected(*removedGamepad);
+}
+
+void GameControllerGamepadProvider::startMonitoringGamepads(GamepadProviderClient& client)
+{
+    ASSERT(!m_clients.contains(&client));
+    m_clients.add(&client);
+
+    if (m_connectObserver)
+        return;
+
+    m_connectObserver = [[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidConnectNotification object:nil queue:nil usingBlock:^(NSNotification *notification) {
+        GameControllerGamepadProvider::singleton().controllerDidConnect(notification.object, ConnectionVisibility::Visible);
+    }];
+
+    m_disconnectObserver = [[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidDisconnectNotification object:nil queue:nil usingBlock:^(NSNotification *notification) {
+        GameControllerGamepadProvider::singleton().controllerDidDisconnect(notification.object);
+    }];
+
+    for (GCController *controller in [GCController controllers])
+        controllerDidConnect(controller, ConnectionVisibility::Invisible);
+}
+
+void GameControllerGamepadProvider::stopMonitoringGamepads(GamepadProviderClient& client)
+{
+    ASSERT(m_clients.contains(&client));
+    m_clients.remove(&client);
+
+    if (!m_connectObserver || !m_clients.isEmpty())
+        return;
+
+    [[NSNotificationCenter defaultCenter] removeObserver:m_connectObserver.get()];
+    [[NSNotificationCenter defaultCenter] removeObserver:m_disconnectObserver.get()];
+}
+
+unsigned GameControllerGamepadProvider::indexForNewlyConnectedDevice()
+{
+    unsigned index = 0;
+    while (index < m_gamepadVector.size() && m_gamepadVector[index])
+        ++index;
+
+    return index;
+}
+
+void GameControllerGamepadProvider::gamepadHadInput(GameControllerGamepad&)
+{
+    if (!m_inputNotificationTimer.isActive())
+        m_inputNotificationTimer.startOneShot(InputNotificationDelay);
+}
+
+void GameControllerGamepadProvider::makeInvisibileGamepadsVisible()
+{
+    for (auto* gamepad : m_invisibleGamepads) {
+        for (auto& client : m_clients)
+            client->platformGamepadConnected(*gamepad);
+    }
+
+    m_invisibleGamepads.clear();
+}
+
+void GameControllerGamepadProvider::inputNotificationTimerFired()
+{
+    makeInvisibileGamepadsVisible();
+
+    for (auto& client : m_clients)
+        client->platformGamepadInputActivity();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD)
index 29f8def..0e87680 100644 (file)
@@ -1,3 +1,24 @@
+2016-08-30  Brady Eidson  <beidson@apple.com>
+
+        GameController.framework backend for gamepad API.
+        https://bugs.webkit.org/show_bug.cgi?id=161086
+
+        Reviewed by Alex Christensen.
+
+        * UIProcess/API/Cocoa/WKProcessPool.mm:
+        (+[WKProcessPool _forceGameControllerFramework]):
+        * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
+
+        * UIProcess/Gamepad/UIGamepadProvider.h:
+
+        * UIProcess/Gamepad/cocoa/UIGamepadProviderCocoa.mm: Renamed from Source/WebKit2/UIProcess/Gamepad/mac/UIGamepadProviderHID.cpp.
+        (WebKit::UIGamepadProvider::setUsesGameControllerFramework):
+        (WebKit::UIGamepadProvider::platformSetDefaultGamepadProvider):
+        (WebKit::UIGamepadProvider::platformStopMonitoringInput):
+        (WebKit::UIGamepadProvider::platformStartMonitoringInput):
+
+        * WebKit2.xcodeproj/project.pbxproj:
+
 2016-08-30  Mark Lam  <mark.lam@apple.com>
 
         Introduce the ThrowScope and force every throw site to instantiate a ThrowScope.
index 7e9212a..3f43bfc 100644 (file)
@@ -32,6 +32,7 @@
 #import "CacheModel.h"
 #import "DownloadClient.h"
 #import "SandboxUtilities.h"
+#import "UIGamepadProvider.h"
 #import "WKObject.h"
 #import "WeakObjCPtr.h"
 #import "WebCertificateInfo.h"
@@ -290,6 +291,13 @@ static WebKit::HTTPCookieAcceptPolicy toHTTPCookieAcceptPolicy(NSHTTPCookieAccep
     _processPool->terminateDatabaseProcess();
 }
 
++ (void)_forceGameControllerFramework
+{
+#if ENABLE(GAMEPAD)
+    WebKit::UIGamepadProvider::setUsesGameControllerFramework();
+#endif
+}
+
 - (BOOL)_isCookieStoragePartitioningEnabled
 {
     return _processPool->cookieStoragePartitioningEnabled();
index 72f036d..329a6d4 100644 (file)
@@ -64,6 +64,9 @@
 // Test only. Should be called only while no web content processes are running.
 - (void)_terminateDatabaseProcess;
 
+// Test only. Should be called before any web content processes are launched.
++ (void)_forceGameControllerFramework;
+
 @property (nonatomic, getter=_isCookieStoragePartitioningEnabled, setter=_setCookieStoragePartitioningEnabled:) BOOL _cookieStoragePartitioningEnabled WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 @end
index f86f8d5..0af9d53 100644 (file)
@@ -52,6 +52,10 @@ public:
 
     Vector<GamepadData> gamepadStates() const;
 
+#if PLATFORM(COCOA)
+    static void setUsesGameControllerFramework();
+#endif
+
 private:
     friend NeverDestroyed<UIGamepadProvider>;
     UIGamepadProvider();
@@ -28,6 +28,7 @@
 
 #if ENABLE(GAMEPAD)
 
+#include <WebCore/GameControllerGamepadProvider.h>
 #include <WebCore/HIDGamepadProvider.h>
 #include <WebCore/MockGamepadProvider.h>
 
@@ -35,24 +36,44 @@ using namespace WebCore;
 
 namespace WebKit {
 
+static bool useGameControllerFramework = false;
+
+void UIGamepadProvider::setUsesGameControllerFramework()
+{
+    useGameControllerFramework = true;
+}
+
 void UIGamepadProvider::platformSetDefaultGamepadProvider()
 {
     if (GamepadProvider::singleton().isMockGamepadProvider())
         return;
 
+#if PLATFORM(IOS)
+    GamepadProvider::setSharedProvider(GameControllerGamepadProvider::singleton());
+#elif defined(__LP64__)
+    if (useGameControllerFramework)
+        GamepadProvider::setSharedProvider(GameControllerGamepadProvider::singleton());
+    else
+        GamepadProvider::setSharedProvider(HIDGamepadProvider::singleton());
+#else
     GamepadProvider::setSharedProvider(HIDGamepadProvider::singleton());
+#endif
 }
 
 void UIGamepadProvider::platformStopMonitoringInput()
 {
-    // No effect when the MockGamepadProvider is being used.
-    return HIDGamepadProvider::singleton().stopMonitoringInput();
+#if PLATFORM(MAC)
+    if (!useGameControllerFramework)
+        HIDGamepadProvider::singleton().stopMonitoringInput();
+#endif
 }
 
 void UIGamepadProvider::platformStartMonitoringInput()
 {
-    // No effect when the MockGamepadProvider is being used.
-    return HIDGamepadProvider::singleton().startMonitoringInput();
+#if PLATFORM(MAC)
+    if (!useGameControllerFramework)
+        HIDGamepadProvider::singleton().startMonitoringInput();
+#endif
 }
 
 }
index e2680cf..cff8460 100644 (file)
                51578B831209ECEF00A37C4A /* APIData.h in Headers */ = {isa = PBXBuildFile; fileRef = 51578B821209ECEF00A37C4A /* APIData.h */; };
                515BE1771D53FE8700DD7C68 /* WebGamepadProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 515BE1731D53FDDC00DD7C68 /* WebGamepadProvider.cpp */; };
                515BE1791D53FE8F00DD7C68 /* WebGamepadProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 515BE1741D53FDDC00DD7C68 /* WebGamepadProvider.h */; };
-               515BE1A71D55293400DD7C68 /* UIGamepadProviderHID.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 515BE1A61D55293000DD7C68 /* UIGamepadProviderHID.cpp */; };
                515BE1A81D55293400DD7C68 /* UIGamepadProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 515BE1A41D55292800DD7C68 /* UIGamepadProvider.cpp */; };
                515BE1A91D55293400DD7C68 /* UIGamepadProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 515BE1A51D55292800DD7C68 /* UIGamepadProvider.h */; };
                515BE1AA1D555A9B00DD7C68 /* WebGamepad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 515BE19F1D550AB000DD7C68 /* WebGamepad.cpp */; };
                51E35200180F5D0F00E53BE9 /* DatabaseToWebProcessConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51E351FD180F5D0B00E53BE9 /* DatabaseToWebProcessConnection.cpp */; };
                51E35202180F5D1E00E53BE9 /* DatabaseProcessMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E35201180F5D1E00E53BE9 /* DatabaseProcessMac.mm */; };
                51E35209180F5D6B00E53BE9 /* DatabaseServiceEntryPoint.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E35208180F5D6B00E53BE9 /* DatabaseServiceEntryPoint.mm */; };
+               51E399061D6F54C7009C8831 /* UIGamepadProviderCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E399051D6F54C5009C8831 /* UIGamepadProviderCocoa.mm */; };
                51EFC1CF1524E62500C9A938 /* WKBundleDOMWindowExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 51FA2D541521118600C1BA0B /* WKBundleDOMWindowExtension.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51F060E01654317F00F3281B /* WebResourceLoaderMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F060DE1654317500F3281B /* WebResourceLoaderMessages.h */; };
                51F060E11654318500F3281B /* WebResourceLoaderMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51F060DD1654317500F3281B /* WebResourceLoaderMessageReceiver.cpp */; };
                515BE1A01D550AB000DD7C68 /* WebGamepad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebGamepad.h; sourceTree = "<group>"; };
                515BE1A41D55292800DD7C68 /* UIGamepadProvider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIGamepadProvider.cpp; sourceTree = "<group>"; };
                515BE1A51D55292800DD7C68 /* UIGamepadProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIGamepadProvider.h; sourceTree = "<group>"; };
-               515BE1A61D55293000DD7C68 /* UIGamepadProviderHID.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UIGamepadProviderHID.cpp; path = UIProcess/Gamepad/mac/UIGamepadProviderHID.cpp; sourceTree = SOURCE_ROOT; };
                515BE1AC1D555C5100DD7C68 /* UIGamepad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIGamepad.cpp; sourceTree = "<group>"; };
                515BE1AD1D555C5100DD7C68 /* UIGamepad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIGamepad.h; sourceTree = "<group>"; };
                515BE1B01D59006900DD7C68 /* GamepadData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GamepadData.h; sourceTree = "<group>"; };
                51E35201180F5D1E00E53BE9 /* DatabaseProcessMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DatabaseProcessMac.mm; sourceTree = "<group>"; };
                51E35207180F5D6100E53BE9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
                51E35208180F5D6B00E53BE9 /* DatabaseServiceEntryPoint.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DatabaseServiceEntryPoint.mm; sourceTree = "<group>"; };
+               51E399051D6F54C5009C8831 /* UIGamepadProviderCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIGamepadProviderCocoa.mm; sourceTree = "<group>"; };
                51F060DD1654317500F3281B /* WebResourceLoaderMessageReceiver.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebResourceLoaderMessageReceiver.cpp; sourceTree = "<group>"; };
                51F060DE1654317500F3281B /* WebResourceLoaderMessages.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebResourceLoaderMessages.h; sourceTree = "<group>"; };
                51F7DC4A180CC93600212CA3 /* com.apple.WebKit.Databases.Development.xpc */ = {isa = PBXFileReference; explicitFileType = "wrapper.xpc-service"; includeInIndex = 0; path = com.apple.WebKit.Databases.Development.xpc; sourceTree = BUILT_PRODUCTS_DIR; };
                515BE17B1D54EF5A00DD7C68 /* Gamepad */ = {
                        isa = PBXGroup;
                        children = (
+                               51E399041D6F54AD009C8831 /* cocoa */,
                                515BE1A11D5523B300DD7C68 /* mac */,
                                515BE1AC1D555C5100DD7C68 /* UIGamepad.cpp */,
                                515BE1AD1D555C5100DD7C68 /* UIGamepad.h */,
                515BE1A11D5523B300DD7C68 /* mac */ = {
                        isa = PBXGroup;
                        children = (
-                               515BE1A61D55293000DD7C68 /* UIGamepadProviderHID.cpp */,
                                515BE1B61D5A94F900DD7C68 /* UIGamepadProviderMac.mm */,
                        );
                        name = mac;
                        path = IndexedDB;
                        sourceTree = "<group>";
                };
+               51E399041D6F54AD009C8831 /* cocoa */ = {
+                       isa = PBXGroup;
+                       children = (
+                               51E399051D6F54C5009C8831 /* UIGamepadProviderCocoa.mm */,
+                       );
+                       path = cocoa;
+                       sourceTree = "<group>";
+               };
                51F7DC0A180CC41100212CA3 /* DatabaseProcess */ = {
                        isa = PBXGroup;
                        children = (
                                1A0EC910124C0AF5007EF4A5 /* PluginProcessConnectionManager.cpp in Sources */,
                                1A7865B916CAC71500ACE83A /* PluginProcessConnectionManagerMessageReceiver.cpp in Sources */,
                                1A2BB6D014117B4D000F35D4 /* PluginProcessConnectionMessageReceiver.cpp in Sources */,
+                               51E399061D6F54C7009C8831 /* UIGamepadProviderCocoa.mm in Sources */,
                                1A2D90D31281C966001EB962 /* PluginProcessCreationParameters.cpp in Sources */,
                                1AA4792312A59FD9008236C3 /* PluginProcessMac.mm in Sources */,
                                1A0EC604124A9F2C007EF4A5 /* PluginProcessManager.cpp in Sources */,
                                1AFE436518B6C081009C7A48 /* UIDelegate.mm in Sources */,
                                515BE1B41D5917FF00DD7C68 /* UIGamepad.cpp in Sources */,
                                515BE1A81D55293400DD7C68 /* UIGamepadProvider.cpp in Sources */,
-                               515BE1A71D55293400DD7C68 /* UIGamepadProviderHID.cpp in Sources */,
                                515BE1B71D5A94FD00DD7C68 /* UIGamepadProviderMac.mm in Sources */,
                                1A64245F12DE29A100CAAE2C /* UpdateInfo.cpp in Sources */,
                                1AC1336718565B5700F3EC05 /* UserData.cpp in Sources */,
index 4eb4f4a..c4a1072 100644 (file)
@@ -1,3 +1,20 @@
+2016-08-30  Brady Eidson  <beidson@apple.com>
+
+        GameController.framework backend for gamepad API.
+        https://bugs.webkit.org/show_bug.cgi?id=161086
+
+        Reviewed by Alex Christensen.
+
+        * MiniBrowser/mac/AppDelegate.m:
+        (-[BrowserAppDelegate awakeFromNib]):
+
+        * MiniBrowser/mac/SettingsController.h:
+        * MiniBrowser/mac/SettingsController.m:
+        (-[SettingsController _populateMenu]):
+        (-[SettingsController validateMenuItem:]):
+        (-[SettingsController usesGameControllerFramework]):
+        (-[SettingsController toggleUsesGameControllerFramework:]):
+
 2016-08-30  Brent Fulgham  <bfulgham@apple.com>
 
         Use of uninitialised memory in TransformationMatrx::blend4()
index 95a576a..c4fb8fa 100644 (file)
@@ -66,6 +66,12 @@ enum {
 {
     NSMenuItem *item = [[NSMenuItem alloc] init];
     [item setSubmenu:[[SettingsController shared] menu]];
+
+#if WK_API_ENABLED
+    if ([[SettingsController shared] usesGameControllerFramework])
+        [WKProcessPool _forceGameControllerFramework];
+#endif
+
     [[NSApp mainMenu] insertItem:[item autorelease] atIndex:[[NSApp mainMenu] indexOfItemWithTitle:@"Debug"]];
 }
 
index bccef9a..dd83ab1 100644 (file)
@@ -50,6 +50,7 @@
 @property (nonatomic, readonly) BOOL displayListDrawingEnabled;
 @property (nonatomic, readonly) BOOL resourceLoadStatisticsEnabled;
 @property (nonatomic, readonly) BOOL visualViewportEnabled;
+@property (nonatomic, readonly) BOOL usesGameControllerFramework;
 
 @property (nonatomic, readonly) NSString *defaultURL;
 
index 4148f48..74f7e9a 100644 (file)
@@ -41,6 +41,7 @@ static NSString * const LayerBordersVisiblePreferenceKey = @"LayerBordersVisible
 static NSString * const SimpleLineLayoutDebugBordersEnabledPreferenceKey = @"SimpleLineLayoutDebugBordersEnabled";
 static NSString * const TiledScrollingIndicatorVisiblePreferenceKey = @"TiledScrollingIndicatorVisible";
 static NSString * const ResourceUsageOverlayVisiblePreferenceKey = @"ResourceUsageOverlayVisible";
+static NSString * const UsesGameControllerFrameworkKey = @"UsesGameControllerFramework";
 static NSString * const IncrementalRenderingSuppressedPreferenceKey = @"IncrementalRenderingSuppressed";
 static NSString * const AcceleratedDrawingEnabledPreferenceKey = @"AcceleratedDrawingEnabled";
 static NSString * const DisplayListDrawingEnabledPreferenceKey = @"DisplayListDrawingEnabled";
@@ -132,6 +133,7 @@ typedef NS_ENUM(NSInteger, DebugOverylayMenuItemTag) {
     [self _addItemWithTitle:@"Use UI-Side Compositing" action:@selector(toggleUseUISideCompositing:) indented:YES];
     [self _addItemWithTitle:@"Disable Per-Window Web Processes" action:@selector(togglePerWindowWebProcessesDisabled:) indented:YES];
     [self _addItemWithTitle:@"Show Resource Usage Overlay" action:@selector(toggleShowResourceUsageOverlay:) indented:YES];
+    [self _addItemWithTitle:@"Use GameController.framework on macOS (Restart required)" action:@selector(toggleUsesGameControllerFramework:) indented:YES];
 
     NSMenuItem *debugOverlaysSubmenuItem = [[NSMenuItem alloc] initWithTitle:@"Debug Overlays" action:nil keyEquivalent:@""];
     NSMenu *debugOverlaysMenu = [[NSMenu alloc] initWithTitle:@"Debug Overlays"];
@@ -203,6 +205,8 @@ typedef NS_ENUM(NSInteger, DebugOverylayMenuItemTag) {
         [menuItem setState:[self tiledScrollingIndicatorVisible] ? NSOnState : NSOffState];
     else if (action == @selector(toggleShowResourceUsageOverlay:))
         [menuItem setState:[self resourceUsageOverlayVisible] ? NSOnState : NSOffState];
+    else if (action == @selector(toggleUsesGameControllerFramework:))
+        [menuItem setState:[self usesGameControllerFramework] ? NSOnState : NSOffState];
     else if (action == @selector(toggleUseUISideCompositing:))
         [menuItem setState:[self useUISideCompositing] ? NSOnState : NSOffState];
     else if (action == @selector(togglePerWindowWebProcessesDisabled:))
@@ -350,6 +354,16 @@ typedef NS_ENUM(NSInteger, DebugOverylayMenuItemTag) {
     [self _toggleBooleanDefault:ResourceUsageOverlayVisiblePreferenceKey];
 }
 
+- (BOOL)usesGameControllerFramework
+{
+    return [[NSUserDefaults standardUserDefaults] boolForKey:UsesGameControllerFrameworkKey];
+}
+
+- (void)toggleUsesGameControllerFramework:(id)sender
+{
+    [self _toggleBooleanDefault:UsesGameControllerFrameworkKey];
+}
+
 - (BOOL)tiledScrollingIndicatorVisible
 {
     return [[NSUserDefaults standardUserDefaults] boolForKey:TiledScrollingIndicatorVisiblePreferenceKey];