Title: [211007] trunk
Revision
211007
Author
beid...@apple.com
Date
2017-01-20 18:24:17 -0800 (Fri, 20 Jan 2017)

Log Message

Require a button press on a gamepad for them to be exposed to the DOM.
<rdar://problem/28620919> and https://bugs.webkit.org/show_bug.cgi?id=167272

Reviewed by Alex Christensen.

Source/WebCore:

Test: gamepad/gamepad-visibility-1.html

* Modules/gamepad/GamepadManager.cpp:
(WebCore::GamepadManager::platformGamepadInputActivity):
* Modules/gamepad/GamepadManager.h:

* platform/gamepad/GamepadProvider.cpp:
(WebCore::GamepadProvider::dispatchPlatformGamepadInputActivity):
* platform/gamepad/GamepadProvider.h:
(WebCore::GamepadProvider::~GamepadProvider): Deleted.
(WebCore::GamepadProvider::isMockGamepadProvider): Deleted.

* platform/gamepad/GamepadProviderClient.h:

* platform/gamepad/cocoa/GameControllerGamepad.h:
* platform/gamepad/cocoa/GameControllerGamepad.mm:
(WebCore::GameControllerGamepad::setupAsExtendedGamepad):
(WebCore::GameControllerGamepad::setupAsGamepad):

* platform/gamepad/cocoa/GameControllerGamepadProvider.h:
* platform/gamepad/cocoa/GameControllerGamepadProvider.mm:
(WebCore::GameControllerGamepadProvider::gamepadHadInput):
(WebCore::GameControllerGamepadProvider::inputNotificationTimerFired):

* platform/gamepad/mac/HIDGamepad.cpp:
(WebCore::HIDGamepad::valueChanged):
* platform/gamepad/mac/HIDGamepad.h:

* platform/gamepad/mac/HIDGamepadProvider.cpp:
(WebCore::HIDGamepadProvider::valuesChanged):
(WebCore::HIDGamepadProvider::inputNotificationTimerFired):
* platform/gamepad/mac/HIDGamepadProvider.h:

* testing/MockGamepadProvider.cpp:
(WebCore::MockGamepadProvider::setMockGamepadButtonValue):
(WebCore::MockGamepadProvider::gamepadInputActivity):
* testing/MockGamepadProvider.h:

Source/WebKit2:

* UIProcess/Gamepad/UIGamepadProvider.cpp:
(WebKit::UIGamepadProvider::gamepadSyncTimerFired):
(WebKit::UIGamepadProvider::platformGamepadInputActivity):
* UIProcess/Gamepad/UIGamepadProvider.h:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::gamepadActivity):
* UIProcess/WebPageProxy.h:

* WebProcess/Gamepad/WebGamepadProvider.cpp:
(WebKit::WebGamepadProvider::gamepadActivity):
* WebProcess/Gamepad/WebGamepadProvider.h:

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::gamepadActivity):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

LayoutTests:

* gamepad/gamepad-visibility-1-expected.txt: Added.
* gamepad/gamepad-visibility-1.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (211006 => 211007)


--- trunk/LayoutTests/ChangeLog	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/LayoutTests/ChangeLog	2017-01-21 02:24:17 UTC (rev 211007)
@@ -1,3 +1,13 @@
+2017-01-20  Brady Eidson  <beid...@apple.com>
+
+        Require a button press on a gamepad for them to be exposed to the DOM.
+        <rdar://problem/28620919> and https://bugs.webkit.org/show_bug.cgi?id=167272
+
+        Reviewed by Alex Christensen.
+
+        * gamepad/gamepad-visibility-1-expected.txt: Added.
+        * gamepad/gamepad-visibility-1.html: Added.
+
 2017-01-20  Joseph Pecoraro  <pecor...@apple.com>
 
         Cleanup RuntimeEnabledFeatures

Added: trunk/LayoutTests/gamepad/gamepad-visibility-1-expected.txt (0 => 211007)


--- trunk/LayoutTests/gamepad/gamepad-visibility-1-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/gamepad/gamepad-visibility-1-expected.txt	2017-01-21 02:24:17 UTC (rev 211007)
@@ -0,0 +1,2 @@
+No connect event seen in 20 run loop spins. Yay.
+

Added: trunk/LayoutTests/gamepad/gamepad-visibility-1.html (0 => 211007)


--- trunk/LayoutTests/gamepad/gamepad-visibility-1.html	                        (rev 0)
+++ trunk/LayoutTests/gamepad/gamepad-visibility-1.html	2017-01-21 02:24:17 UTC (rev 211007)
@@ -0,0 +1,56 @@
+<head>
+<script>
+
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+}
+
+function log(msg)
+{
+    document.getElementById("logger").innerHTML += msg + "<br>";
+}
+
+function finishTest()
+{
+    if (testRunner)
+        testRunner.notifyDone();
+}
+
+var timeoutCount = 0;
+
+function spinABit()
+{
+    if (timeoutCount == 20) {
+        log("No connect event seen in 20 run loop spins. Yay.");
+        finishTest();
+    }
+
+    ++timeoutCount;
+    setTimeout(spinABit, 0);
+}
+
+function handleGamepadConnect()
+{
+    log("Connect event seen! Should NOT have been seen");
+    finishTest();
+}
+
+function runTest() {
+    addEventListener("gamepadconnected", handleGamepadConnect);
+
+    // Connecting the gamepad and changing axis values should *not* make it visible.
+    // Only button presses should expose it.
+    testRunner.setMockGamepadDetails(0, "Test Joystick", 2, 2);
+    testRunner.connectMockGamepad(0);
+    testRunner.setMockGamepadAxisValue(0, 0, 0.7);
+    testRunner.setMockGamepadAxisValue(0, 1, -1.0);
+
+    setTimeout(spinABit, 0);
+}
+
+</script>
+</head>
+<body _onload_="runTest();">
+<div id="logger"></div>
+</body>

Modified: trunk/Source/WebCore/ChangeLog (211006 => 211007)


--- trunk/Source/WebCore/ChangeLog	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebCore/ChangeLog	2017-01-21 02:24:17 UTC (rev 211007)
@@ -1,3 +1,48 @@
+2017-01-20  Brady Eidson  <beid...@apple.com>
+
+        Require a button press on a gamepad for them to be exposed to the DOM.
+        <rdar://problem/28620919> and https://bugs.webkit.org/show_bug.cgi?id=167272
+
+        Reviewed by Alex Christensen.
+
+        Test: gamepad/gamepad-visibility-1.html
+
+        * Modules/gamepad/GamepadManager.cpp:
+        (WebCore::GamepadManager::platformGamepadInputActivity):
+        * Modules/gamepad/GamepadManager.h:
+
+        * platform/gamepad/GamepadProvider.cpp:
+        (WebCore::GamepadProvider::dispatchPlatformGamepadInputActivity):
+        * platform/gamepad/GamepadProvider.h:
+        (WebCore::GamepadProvider::~GamepadProvider): Deleted.
+        (WebCore::GamepadProvider::isMockGamepadProvider): Deleted.
+
+        * platform/gamepad/GamepadProviderClient.h:
+
+        * platform/gamepad/cocoa/GameControllerGamepad.h:
+        * platform/gamepad/cocoa/GameControllerGamepad.mm:
+        (WebCore::GameControllerGamepad::setupAsExtendedGamepad):
+        (WebCore::GameControllerGamepad::setupAsGamepad):
+
+        * platform/gamepad/cocoa/GameControllerGamepadProvider.h:
+        * platform/gamepad/cocoa/GameControllerGamepadProvider.mm:
+        (WebCore::GameControllerGamepadProvider::gamepadHadInput):
+        (WebCore::GameControllerGamepadProvider::inputNotificationTimerFired):
+
+        * platform/gamepad/mac/HIDGamepad.cpp:
+        (WebCore::HIDGamepad::valueChanged):
+        * platform/gamepad/mac/HIDGamepad.h:
+
+        * platform/gamepad/mac/HIDGamepadProvider.cpp:
+        (WebCore::HIDGamepadProvider::valuesChanged):
+        (WebCore::HIDGamepadProvider::inputNotificationTimerFired):
+        * platform/gamepad/mac/HIDGamepadProvider.h:
+
+        * testing/MockGamepadProvider.cpp:
+        (WebCore::MockGamepadProvider::setMockGamepadButtonValue):
+        (WebCore::MockGamepadProvider::gamepadInputActivity):
+        * testing/MockGamepadProvider.h:
+
 2017-01-20  Joseph Pecoraro  <pecor...@apple.com>
 
         Cleanup RuntimeEnabledFeatures

Modified: trunk/Source/WebCore/Modules/gamepad/GamepadManager.cpp (211006 => 211007)


--- trunk/Source/WebCore/Modules/gamepad/GamepadManager.cpp	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebCore/Modules/gamepad/GamepadManager.cpp	2017-01-21 02:24:17 UTC (rev 211007)
@@ -115,8 +115,11 @@
     }
 }
 
-void GamepadManager::platformGamepadInputActivity()
+void GamepadManager::platformGamepadInputActivity(bool shouldMakeGamepadVisible)
 {
+    if (!shouldMakeGamepadVisible)
+        return;
+
     if (m_gamepadBlindNavigators.isEmpty() && m_gamepadBlindDOMWindows.isEmpty())
         return;
 

Modified: trunk/Source/WebCore/Modules/gamepad/GamepadManager.h (211006 => 211007)


--- trunk/Source/WebCore/Modules/gamepad/GamepadManager.h	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebCore/Modules/gamepad/GamepadManager.h	2017-01-21 02:24:17 UTC (rev 211007)
@@ -47,7 +47,7 @@
 
     void platformGamepadConnected(PlatformGamepad&) final;
     void platformGamepadDisconnected(PlatformGamepad&) final;
-    void platformGamepadInputActivity() final;
+    void platformGamepadInputActivity(bool shouldMakeGamepadVisible) final;
 
     void registerNavigator(NavigatorGamepad*);
     void unregisterNavigator(NavigatorGamepad*);

Modified: trunk/Source/WebCore/platform/gamepad/GamepadProvider.cpp (211006 => 211007)


--- trunk/Source/WebCore/platform/gamepad/GamepadProvider.cpp	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebCore/platform/gamepad/GamepadProvider.cpp	2017-01-21 02:24:17 UTC (rev 211007)
@@ -28,6 +28,7 @@
 #if ENABLE(GAMEPAD)
 
 #include "EmptyGamepadProvider.h"
+#include "GamepadProviderClient.h"
 #include <wtf/NeverDestroyed.h>
 
 namespace WebCore {
@@ -49,6 +50,14 @@
     sharedProvider = &newProvider;
 }
 
+void GamepadProvider::dispatchPlatformGamepadInputActivity()
+{
+    for (auto& client : m_clients)
+        client->platformGamepadInputActivity(m_shouldMakeGamepadsVisible);
+
+    m_shouldMakeGamepadsVisible = false;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(GAMEPAD)

Modified: trunk/Source/WebCore/platform/gamepad/GamepadProvider.h (211006 => 211007)


--- trunk/Source/WebCore/platform/gamepad/GamepadProvider.h	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebCore/platform/gamepad/GamepadProvider.h	2017-01-21 02:24:17 UTC (rev 211007)
@@ -27,6 +27,7 @@
 
 #if ENABLE(GAMEPAD)
 
+#include <wtf/HashSet.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
@@ -34,7 +35,7 @@
 class GamepadProviderClient;
 class PlatformGamepad;
 
-class GamepadProvider {
+class WEBCORE_EXPORT GamepadProvider {
 public:
     virtual ~GamepadProvider() { }
 
@@ -46,6 +47,13 @@
     virtual const Vector<PlatformGamepad*>& platformGamepads() = 0;
     virtual bool isMockGamepadProvider() const { return false; }
 
+protected:
+    void dispatchPlatformGamepadInputActivity();
+    void setShouldMakeGamepadsVisibile() { m_shouldMakeGamepadsVisible = true; }
+    HashSet<GamepadProviderClient*> m_clients;
+
+private:
+    bool m_shouldMakeGamepadsVisible { false };
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/gamepad/GamepadProviderClient.h (211006 => 211007)


--- trunk/Source/WebCore/platform/gamepad/GamepadProviderClient.h	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebCore/platform/gamepad/GamepadProviderClient.h	2017-01-21 02:24:17 UTC (rev 211007)
@@ -40,7 +40,7 @@
     virtual void setInitialConnectedGamepads(const Vector<PlatformGamepad*>&) { }
     virtual void platformGamepadConnected(PlatformGamepad&) = 0;
     virtual void platformGamepadDisconnected(PlatformGamepad&) = 0;
-    virtual void platformGamepadInputActivity() = 0;
+    virtual void platformGamepadInputActivity(bool shouldMakeGamepadVisible) = 0;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.h (211006 => 211007)


--- trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.h	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.h	2017-01-21 02:24:17 UTC (rev 211007)
@@ -58,6 +58,8 @@
 
     RetainPtr<GCGamepad> m_gamepad;
     RetainPtr<GCExtendedGamepad> m_extendedGamepad;
+
+    bool m_hadButtonPresses { false };
 };
 
 

Modified: trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.mm (211006 => 211007)


--- trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.mm	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.mm	2017-01-21 02:24:17 UTC (rev 211007)
@@ -59,7 +59,8 @@
 
     m_extendedGamepad.get().valueChangedHandler = ^(GCExtendedGamepad *, GCControllerElement *) {
         m_lastUpdateTime = monotonicallyIncreasingTime();
-        GameControllerGamepadProvider::singleton().gamepadHadInput(*this);
+        GameControllerGamepadProvider::singleton().gamepadHadInput(*this, m_hadButtonPresses);
+        m_hadButtonPresses = false;
     };
 
     m_buttonValues.resize(8);
@@ -80,29 +81,45 @@
     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_extendedGamepad.get().buttonA.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
         m_buttonValues[0] = value;
+        if (pressed)
+            m_hadButtonPresses = true;
     };
-    m_extendedGamepad.get().buttonB.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+    m_extendedGamepad.get().buttonB.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
         m_buttonValues[1] = value;
+        if (pressed)
+            m_hadButtonPresses = true;
     };
-    m_extendedGamepad.get().buttonX.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+    m_extendedGamepad.get().buttonX.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
         m_buttonValues[2] = value;
+        if (pressed)
+            m_hadButtonPresses = true;
     };
-    m_extendedGamepad.get().buttonY.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+    m_extendedGamepad.get().buttonY.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
         m_buttonValues[3] = value;
+        if (pressed)
+            m_hadButtonPresses = true;
     };
-    m_extendedGamepad.get().leftShoulder.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+    m_extendedGamepad.get().leftShoulder.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
         m_buttonValues[4] = value;
+        if (pressed)
+            m_hadButtonPresses = true;
     };
-    m_extendedGamepad.get().rightShoulder.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+    m_extendedGamepad.get().rightShoulder.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
         m_buttonValues[5] = value;
+        if (pressed)
+            m_hadButtonPresses = true;
     };
-    m_extendedGamepad.get().leftTrigger.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+    m_extendedGamepad.get().leftTrigger.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
         m_buttonValues[6] = value;
+        if (pressed)
+            m_hadButtonPresses = true;
     };
-    m_extendedGamepad.get().rightTrigger.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+    m_extendedGamepad.get().rightTrigger.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
         m_buttonValues[7] = value;
+        if (pressed)
+            m_hadButtonPresses = true;
     };
 
     m_extendedGamepad.get().leftThumbstick.xAxis.valueChangedHandler = ^(GCControllerAxisInput *, float value) {
@@ -133,7 +150,8 @@
 
     m_gamepad.get().valueChangedHandler = ^(GCGamepad *, GCControllerElement *) {
         m_lastUpdateTime = monotonicallyIncreasingTime();
-        GameControllerGamepadProvider::singleton().gamepadHadInput(*this);
+        GameControllerGamepadProvider::singleton().gamepadHadInput(*this, m_hadButtonPresses);
+        m_hadButtonPresses = false;
     };
 
     m_buttonValues.resize(6);
@@ -148,23 +166,35 @@
     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_extendedGamepad.get().buttonA.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
         m_buttonValues[0] = value;
+        if (pressed)
+            m_hadButtonPresses = true;
     };
-    m_extendedGamepad.get().buttonB.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+    m_extendedGamepad.get().buttonB.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
         m_buttonValues[1] = value;
+        if (pressed)
+            m_hadButtonPresses = true;
     };
-    m_extendedGamepad.get().buttonX.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+    m_extendedGamepad.get().buttonX.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
         m_buttonValues[2] = value;
+        if (pressed)
+            m_hadButtonPresses = true;
     };
-    m_extendedGamepad.get().buttonY.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+    m_extendedGamepad.get().buttonY.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
         m_buttonValues[3] = value;
+        if (pressed)
+            m_hadButtonPresses = true;
     };
-    m_extendedGamepad.get().leftShoulder.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+    m_extendedGamepad.get().leftShoulder.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
         m_buttonValues[4] = value;
+        if (pressed)
+            m_hadButtonPresses = true;
     };
-    m_extendedGamepad.get().rightShoulder.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL) {
+    m_extendedGamepad.get().rightShoulder.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
         m_buttonValues[5] = value;
+        if (pressed)
+            m_hadButtonPresses = true;
     };
 
     m_extendedGamepad.get().leftThumbstick.xAxis.valueChangedHandler = ^(GCControllerAxisInput *, float value) {

Modified: trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.h (211006 => 211007)


--- trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.h	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.h	2017-01-21 02:24:17 UTC (rev 211007)
@@ -29,7 +29,6 @@
 
 #include "GamepadProvider.h"
 #include <wtf/HashMap.h>
-#include <wtf/HashSet.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/RetainPtr.h>
 #include <wtf/RunLoop.h>
@@ -55,7 +54,7 @@
     WEBCORE_EXPORT void stopMonitoringInput();
     WEBCORE_EXPORT void startMonitoringInput();
 
-    void gamepadHadInput(GameControllerGamepad&);
+    void gamepadHadInput(GameControllerGamepad&, bool hadButtonPresses);
 
 private:
     GameControllerGamepadProvider();
@@ -74,8 +73,6 @@
 
     void makeInvisibileGamepadsVisible();
 
-    HashSet<GamepadProviderClient*> m_clients;
-
     HashMap<GCController *, std::unique_ptr<GameControllerGamepad>> m_gamepadMap;
     Vector<PlatformGamepad*> m_gamepadVector;
     HashSet<PlatformGamepad*> m_invisibleGamepads;
@@ -84,6 +81,7 @@
     RetainPtr<NSObject> m_disconnectObserver;
 
     RunLoop::Timer<GameControllerGamepadProvider> m_inputNotificationTimer;
+    bool m_shouldMakeInvisibileGamepadsVisible { false };
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.mm (211006 => 211007)


--- trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.mm	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.mm	2017-01-21 02:24:17 UTC (rev 211007)
@@ -141,10 +141,13 @@
     return index;
 }
 
-void GameControllerGamepadProvider::gamepadHadInput(GameControllerGamepad&)
+void GameControllerGamepadProvider::gamepadHadInput(GameControllerGamepad&, bool hadButtonPresses)
 {
     if (!m_inputNotificationTimer.isActive())
         m_inputNotificationTimer.startOneShot(InputNotificationDelay);
+
+    if (hadButtonPresses)
+        m_shouldMakeInvisibileGamepadsVisible = true;
 }
 
 void GameControllerGamepadProvider::makeInvisibileGamepadsVisible()
@@ -159,10 +162,14 @@
 
 void GameControllerGamepadProvider::inputNotificationTimerFired()
 {
-    makeInvisibileGamepadsVisible();
+    if (m_shouldMakeInvisibileGamepadsVisible) {
+        setShouldMakeGamepadsVisibile();
+        makeInvisibileGamepadsVisible();
+    }
 
-    for (auto& client : m_clients)
-        client->platformGamepadInputActivity();
+    m_shouldMakeInvisibileGamepadsVisible = false;
+
+    dispatchPlatformGamepadInputActivity();
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.cpp (211006 => 211007)


--- trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.cpp	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.cpp	2017-01-21 02:24:17 UTC (rev 211007)
@@ -158,7 +158,7 @@
     return true;
 }
 
-void HIDGamepad::valueChanged(IOHIDValueRef value)
+HIDInputType HIDGamepad::valueChanged(IOHIDValueRef value)
 {
     IOHIDElementCookie cookie = IOHIDElementGetCookie(IOHIDValueGetElement(value));
     HIDGamepadElement* element = m_elementMap.get(cookie);
@@ -165,7 +165,7 @@
 
     // This might be an element we don't currently handle as input so we can skip it.
     if (!element)
-        return;
+        return HIDInputType::NotAButtonPress;
 
     element->rawValue = IOHIDValueGetScaledValue(value, kIOHIDValueScaleTypePhysical);
 
@@ -183,6 +183,8 @@
         ASSERT_NOT_REACHED();
 
     m_lastUpdateTime = monotonicallyIncreasingTime();
+
+    return element->isButton() ? HIDInputType::ButtonPress : HIDInputType::NotAButtonPress;
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.h (211006 => 211007)


--- trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.h	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.h	2017-01-21 02:24:17 UTC (rev 211007)
@@ -91,6 +91,11 @@
     }
 };
 
+enum class HIDInputType {
+    ButtonPress,
+    NotAButtonPress,
+};
+
 class HIDGamepad : public PlatformGamepad {
 public:
     HIDGamepad(IOHIDDeviceRef, unsigned index);
@@ -97,7 +102,7 @@
 
     IOHIDDeviceRef hidDevice() const { return m_hidDevice.get(); }
 
-    void valueChanged(IOHIDValueRef);
+    HIDInputType valueChanged(IOHIDValueRef);
 
     const Vector<double>& axisValues() const final { return m_axisValues; }
     const Vector<double>& buttonValues() const final { return m_buttonValues; }

Modified: trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.cpp (211006 => 211007)


--- trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.cpp	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.cpp	2017-01-21 02:24:17 UTC (rev 211007)
@@ -237,7 +237,8 @@
     if (!gamepad)
         return;
 
-    gamepad->valueChanged(value);
+    if (gamepad->valueChanged(value) == HIDInputType::ButtonPress)
+        setShouldMakeGamepadsVisibile();
 
     // This isActive check is necessary as we want to delay input notifications from the time of the first input,
     // and not push the notification out on every subsequent input.
@@ -250,8 +251,7 @@
     if (!m_shouldDispatchCallbacks)
         return;
 
-    for (auto& client : m_clients)
-        client->platformGamepadInputActivity();
+    dispatchPlatformGamepadInputActivity();
 }
 
 std::unique_ptr<HIDGamepad> HIDGamepadProvider::removeGamepadForDevice(IOHIDDeviceRef device)

Modified: trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.h (211006 => 211007)


--- trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.h	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.h	2017-01-21 02:24:17 UTC (rev 211007)
@@ -33,7 +33,6 @@
 #include <IOKit/hid/IOHIDManager.h>
 #include <wtf/Deque.h>
 #include <wtf/HashMap.h>
-#include <wtf/HashSet.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/RetainPtr.h>
 
@@ -76,7 +75,6 @@
 
     RetainPtr<IOHIDManagerRef> m_manager;
 
-    HashSet<GamepadProviderClient*> m_clients;
     bool m_shouldDispatchCallbacks;
 
     Timer m_connectionDelayTimer;

Modified: trunk/Source/WebCore/testing/MockGamepadProvider.cpp (211006 => 211007)


--- trunk/Source/WebCore/testing/MockGamepadProvider.cpp	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebCore/testing/MockGamepadProvider.cpp	2017-01-21 02:24:17 UTC (rev 211007)
@@ -132,6 +132,7 @@
     }
 
     m_mockGamepadVector[index]->setButtonValue(buttonIndex, value);
+    setShouldMakeGamepadsVisibile();
     gamepadInputActivity();
     return true;
 }
@@ -143,8 +144,7 @@
 
     m_shouldScheduleActivityCallback = false;
     callOnMainThread([this]() {
-        for (auto& client : m_clients)
-            client->platformGamepadInputActivity();
+        dispatchPlatformGamepadInputActivity();
 
         m_shouldScheduleActivityCallback = true;
     });

Modified: trunk/Source/WebCore/testing/MockGamepadProvider.h (211006 => 211007)


--- trunk/Source/WebCore/testing/MockGamepadProvider.h	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebCore/testing/MockGamepadProvider.h	2017-01-21 02:24:17 UTC (rev 211007)
@@ -29,7 +29,6 @@
 
 #include "GamepadProvider.h"
 #include "MockGamepad.h"
-#include <wtf/HashSet.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/text/WTFString.h>
 
@@ -62,8 +61,6 @@
     Vector<PlatformGamepad*> m_connectedGamepadVector;
     Vector<std::unique_ptr<MockGamepad>> m_mockGamepadVector;
 
-    HashSet<GamepadProviderClient*> m_clients;
-
     bool m_shouldScheduleActivityCallback { true };
 };
 

Modified: trunk/Source/WebKit2/ChangeLog (211006 => 211007)


--- trunk/Source/WebKit2/ChangeLog	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebKit2/ChangeLog	2017-01-21 02:24:17 UTC (rev 211007)
@@ -1,3 +1,28 @@
+2017-01-20  Brady Eidson  <beid...@apple.com>
+
+        Require a button press on a gamepad for them to be exposed to the DOM.
+        <rdar://problem/28620919> and https://bugs.webkit.org/show_bug.cgi?id=167272
+
+        Reviewed by Alex Christensen.
+
+        * UIProcess/Gamepad/UIGamepadProvider.cpp:
+        (WebKit::UIGamepadProvider::gamepadSyncTimerFired):
+        (WebKit::UIGamepadProvider::platformGamepadInputActivity):
+        * UIProcess/Gamepad/UIGamepadProvider.h:
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::gamepadActivity):
+        * UIProcess/WebPageProxy.h:
+
+        * WebProcess/Gamepad/WebGamepadProvider.cpp:
+        (WebKit::WebGamepadProvider::gamepadActivity):
+        * WebProcess/Gamepad/WebGamepadProvider.h:
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::gamepadActivity):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2017-01-20  Joseph Pecoraro  <pecor...@apple.com>
 
         Cleanup RuntimeEnabledFeatures

Modified: trunk/Source/WebKit2/UIProcess/Gamepad/UIGamepadProvider.cpp (211006 => 211007)


--- trunk/Source/WebKit2/UIProcess/Gamepad/UIGamepadProvider.cpp	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebKit2/UIProcess/Gamepad/UIGamepadProvider.cpp	2017-01-21 02:24:17 UTC (rev 211007)
@@ -65,7 +65,8 @@
     if (!webPageProxy || !m_processPoolsUsingGamepads.contains(&webPageProxy->process().processPool()))
         return;
 
-    webPageProxy->gamepadActivity(snapshotGamepads());
+    webPageProxy->gamepadActivity(snapshotGamepads(), m_shouldMakeGamepadsVisibleOnSync);
+    m_shouldMakeGamepadsVisibleOnSync = false;
 }
 
 void UIGamepadProvider::scheduleGamepadStateSync()
@@ -126,7 +127,7 @@
         pool->gamepadDisconnected(*disconnectedGamepad);
 }
 
-void UIGamepadProvider::platformGamepadInputActivity()
+void UIGamepadProvider::platformGamepadInputActivity(bool shouldMakeGamepadsVisible)
 {
     auto platformGamepads = GamepadProvider::singleton().platformGamepads();
     ASSERT(platformGamepads.size() == m_gamepads.size());
@@ -141,6 +142,9 @@
         m_gamepads[i]->updateFromPlatformGamepad(*platformGamepads[i]);
     }
 
+    if (shouldMakeGamepadsVisible)
+        m_shouldMakeGamepadsVisibleOnSync = true;
+
     scheduleGamepadStateSync();
 }
 

Modified: trunk/Source/WebKit2/UIProcess/Gamepad/UIGamepadProvider.h (211006 => 211007)


--- trunk/Source/WebKit2/UIProcess/Gamepad/UIGamepadProvider.h	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebKit2/UIProcess/Gamepad/UIGamepadProvider.h	2017-01-21 02:24:17 UTC (rev 211007)
@@ -74,7 +74,7 @@
     void setInitialConnectedGamepads(const Vector<WebCore::PlatformGamepad*>&) final;
     void platformGamepadConnected(WebCore::PlatformGamepad&) final;
     void platformGamepadDisconnected(WebCore::PlatformGamepad&) final;
-    void platformGamepadInputActivity() final;
+    void platformGamepadInputActivity(bool shouldMakeGamepadsVisible) final;
 
     void scheduleGamepadStateSync();
     void gamepadSyncTimerFired();
@@ -87,6 +87,7 @@
 
     bool m_isMonitoringGamepads { false };
     bool m_hasInitialGamepads { false };
+    bool m_shouldMakeGamepadsVisibleOnSync { false };
 };
 
 }

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (211006 => 211007)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2017-01-21 02:24:17 UTC (rev 211007)
@@ -5603,9 +5603,9 @@
 
 #if ENABLE(GAMEPAD)
 
-void WebPageProxy::gamepadActivity(const Vector<GamepadData>& gamepadDatas)
+void WebPageProxy::gamepadActivity(const Vector<GamepadData>& gamepadDatas, bool shouldMakeGamepadsVisible)
 {
-    m_process->send(Messages::WebPage::GamepadActivity(gamepadDatas), m_pageID);
+    m_process->send(Messages::WebPage::GamepadActivity(gamepadDatas, shouldMakeGamepadsVisible), m_pageID);
 }
 
 #endif

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (211006 => 211007)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2017-01-21 02:24:17 UTC (rev 211007)
@@ -1175,7 +1175,7 @@
     void canAuthenticateAgainstProtectionSpace(uint64_t loaderID, uint64_t frameID, const WebCore::ProtectionSpace&);
 
 #if ENABLE(GAMEPAD)
-    void gamepadActivity(const Vector<GamepadData>&);
+    void gamepadActivity(const Vector<GamepadData>&, bool shouldMakeGamepadsVisible);
 #endif
         
     WeakPtr<WebPageProxy> createWeakPtr() const { return m_weakPtrFactory.createWeakPtr(); }

Modified: trunk/Source/WebKit2/WebProcess/Gamepad/WebGamepadProvider.cpp (211006 => 211007)


--- trunk/Source/WebKit2/WebProcess/Gamepad/WebGamepadProvider.cpp	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebKit2/WebProcess/Gamepad/WebGamepadProvider.cpp	2017-01-21 02:24:17 UTC (rev 211007)
@@ -95,7 +95,7 @@
         client->platformGamepadDisconnected(*disconnectedGamepad);
 }
 
-void WebGamepadProvider::gamepadActivity(const Vector<GamepadData>& gamepadDatas)
+void WebGamepadProvider::gamepadActivity(const Vector<GamepadData>& gamepadDatas, bool shouldMakeGamepadsVisible)
 {
     ASSERT(m_gamepads.size() == gamepadDatas.size());
 
@@ -105,7 +105,7 @@
     }
 
     for (auto* client : m_clients)
-        client->platformGamepadInputActivity();
+        client->platformGamepadInputActivity(shouldMakeGamepadsVisible);
 }
 
 void WebGamepadProvider::startMonitoringGamepads(GamepadProviderClient& client)

Modified: trunk/Source/WebKit2/WebProcess/Gamepad/WebGamepadProvider.h (211006 => 211007)


--- trunk/Source/WebKit2/WebProcess/Gamepad/WebGamepadProvider.h	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebKit2/WebProcess/Gamepad/WebGamepadProvider.h	2017-01-21 02:24:17 UTC (rev 211007)
@@ -44,7 +44,7 @@
 
     void gamepadConnected(const GamepadData&);
     void gamepadDisconnected(unsigned index);
-    void gamepadActivity(const Vector<GamepadData>&);
+    void gamepadActivity(const Vector<GamepadData>&, bool shouldMakeGamepadsVisible);
 
     void setInitialGamepads(const Vector<GamepadData>&);
 

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (211006 => 211007)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2017-01-21 02:24:17 UTC (rev 211007)
@@ -5689,9 +5689,9 @@
 
 #if ENABLE(GAMEPAD)
 
-void WebPage::gamepadActivity(const Vector<GamepadData>& gamepadDatas)
+void WebPage::gamepadActivity(const Vector<GamepadData>& gamepadDatas, bool shouldMakeGamepadsVisible)
 {
-    WebGamepadProvider::singleton().gamepadActivity(gamepadDatas);
+    WebGamepadProvider::singleton().gamepadActivity(gamepadDatas, shouldMakeGamepadsVisible);
 }
 
 #endif

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (211006 => 211007)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2017-01-21 02:24:17 UTC (rev 211007)
@@ -963,7 +963,7 @@
 #endif
 
 #if ENABLE(GAMEPAD)
-    void gamepadActivity(const Vector<GamepadData>&);
+    void gamepadActivity(const Vector<GamepadData>&, bool shouldMakeGamepadsVisible);
 #endif
     
 #if ENABLE(POINTER_LOCK)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (211006 => 211007)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2017-01-21 02:23:47 UTC (rev 211006)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2017-01-21 02:24:17 UTC (rev 211007)
@@ -459,6 +459,6 @@
     SetUseIconLoadingClient(bool useIconLoadingClient)
 
 #if ENABLE(GAMEPAD)
-    GamepadActivity(Vector<WebKit::GamepadData> gamepadDatas)
+    GamepadActivity(Vector<WebKit::GamepadData> gamepadDatas, bool shouldMakeGamepadsVisible)
 #endif
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to