Require a button press on a gamepad for them to be exposed to the DOM.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 21 Jan 2017 02:24:17 +0000 (02:24 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 21 Jan 2017 02:24:17 +0000 (02:24 +0000)
<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.

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

29 files changed:
LayoutTests/ChangeLog
LayoutTests/gamepad/gamepad-visibility-1-expected.txt [new file with mode: 0644]
LayoutTests/gamepad/gamepad-visibility-1.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/gamepad/GamepadManager.cpp
Source/WebCore/Modules/gamepad/GamepadManager.h
Source/WebCore/platform/gamepad/GamepadProvider.cpp
Source/WebCore/platform/gamepad/GamepadProvider.h
Source/WebCore/platform/gamepad/GamepadProviderClient.h
Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.h
Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.mm
Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.h
Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.mm
Source/WebCore/platform/gamepad/mac/HIDGamepad.cpp
Source/WebCore/platform/gamepad/mac/HIDGamepad.h
Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.cpp
Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.h
Source/WebCore/testing/MockGamepadProvider.cpp
Source/WebCore/testing/MockGamepadProvider.h
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/Gamepad/UIGamepadProvider.cpp
Source/WebKit2/UIProcess/Gamepad/UIGamepadProvider.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/WebProcess/Gamepad/WebGamepadProvider.cpp
Source/WebKit2/WebProcess/Gamepad/WebGamepadProvider.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

index 83f657c..a4d672c 100644 (file)
@@ -1,3 +1,13 @@
+2017-01-20  Brady Eidson  <beidson@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  <pecoraro@apple.com>
 
         Cleanup RuntimeEnabledFeatures
diff --git a/LayoutTests/gamepad/gamepad-visibility-1-expected.txt b/LayoutTests/gamepad/gamepad-visibility-1-expected.txt
new file mode 100644 (file)
index 0000000..dd453a2
--- /dev/null
@@ -0,0 +1,2 @@
+No connect event seen in 20 run loop spins. Yay.
+
diff --git a/LayoutTests/gamepad/gamepad-visibility-1.html b/LayoutTests/gamepad/gamepad-visibility-1.html
new file mode 100644 (file)
index 0000000..8d54389
--- /dev/null
@@ -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>
index 53193b0..b35ff04 100644 (file)
@@ -1,3 +1,48 @@
+2017-01-20  Brady Eidson  <beidson@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  <pecoraro@apple.com>
 
         Cleanup RuntimeEnabledFeatures
index 1c34d3d..b2ecba1 100644 (file)
@@ -115,8 +115,11 @@ void GamepadManager::platformGamepadDisconnected(PlatformGamepad& platformGamepa
     }
 }
 
-void GamepadManager::platformGamepadInputActivity()
+void GamepadManager::platformGamepadInputActivity(bool shouldMakeGamepadVisible)
 {
+    if (!shouldMakeGamepadVisible)
+        return;
+
     if (m_gamepadBlindNavigators.isEmpty() && m_gamepadBlindDOMWindows.isEmpty())
         return;
 
index 9ee7d9a..63b66fa 100644 (file)
@@ -47,7 +47,7 @@ public:
 
     void platformGamepadConnected(PlatformGamepad&) final;
     void platformGamepadDisconnected(PlatformGamepad&) final;
-    void platformGamepadInputActivity() final;
+    void platformGamepadInputActivity(bool shouldMakeGamepadVisible) final;
 
     void registerNavigator(NavigatorGamepad*);
     void unregisterNavigator(NavigatorGamepad*);
index 8861a0e..79c47af 100644 (file)
@@ -28,6 +28,7 @@
 #if ENABLE(GAMEPAD)
 
 #include "EmptyGamepadProvider.h"
+#include "GamepadProviderClient.h"
 #include <wtf/NeverDestroyed.h>
 
 namespace WebCore {
@@ -49,6 +50,14 @@ void GamepadProvider::setSharedProvider(GamepadProvider& newProvider)
     sharedProvider = &newProvider;
 }
 
+void GamepadProvider::dispatchPlatformGamepadInputActivity()
+{
+    for (auto& client : m_clients)
+        client->platformGamepadInputActivity(m_shouldMakeGamepadsVisible);
+
+    m_shouldMakeGamepadsVisible = false;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(GAMEPAD)
index 09156a7..1d50f2c 100644 (file)
@@ -27,6 +27,7 @@
 
 #if ENABLE(GAMEPAD)
 
+#include <wtf/HashSet.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
@@ -34,7 +35,7 @@ namespace WebCore {
 class GamepadProviderClient;
 class PlatformGamepad;
 
-class GamepadProvider {
+class WEBCORE_EXPORT GamepadProvider {
 public:
     virtual ~GamepadProvider() { }
 
@@ -46,6 +47,13 @@ public:
     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
index 01a2cec..63ea46c 100644 (file)
@@ -40,7 +40,7 @@ public:
     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
index 994d972..4611ce1 100644 (file)
@@ -58,6 +58,8 @@ private:
 
     RetainPtr<GCGamepad> m_gamepad;
     RetainPtr<GCExtendedGamepad> m_extendedGamepad;
+
+    bool m_hadButtonPresses { false };
 };
 
 
index 1f252f4..29950ba 100644 (file)
@@ -59,7 +59,8 @@ void GameControllerGamepad::setupAsExtendedGamepad()
 
     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 @@ void GameControllerGamepad::setupAsExtendedGamepad()
     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 @@ void GameControllerGamepad::setupAsGamepad()
 
     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 @@ void GameControllerGamepad::setupAsGamepad()
     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) {
index af01b8d..520d5c1 100644 (file)
@@ -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 @@ public:
     WEBCORE_EXPORT void stopMonitoringInput();
     WEBCORE_EXPORT void startMonitoringInput();
 
-    void gamepadHadInput(GameControllerGamepad&);
+    void gamepadHadInput(GameControllerGamepad&, bool hadButtonPresses);
 
 private:
     GameControllerGamepadProvider();
@@ -74,8 +73,6 @@ private:
 
     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 @@ private:
     RetainPtr<NSObject> m_disconnectObserver;
 
     RunLoop::Timer<GameControllerGamepadProvider> m_inputNotificationTimer;
+    bool m_shouldMakeInvisibileGamepadsVisible { false };
 };
 
 } // namespace WebCore
index 6a53f12..515f3e4 100644 (file)
@@ -141,10 +141,13 @@ unsigned GameControllerGamepadProvider::indexForNewlyConnectedDevice()
     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::makeInvisibileGamepadsVisible()
 
 void GameControllerGamepadProvider::inputNotificationTimerFired()
 {
-    makeInvisibileGamepadsVisible();
+    if (m_shouldMakeInvisibileGamepadsVisible) {
+        setShouldMakeGamepadsVisibile();
+        makeInvisibileGamepadsVisible();
+    }
 
-    for (auto& client : m_clients)
-        client->platformGamepadInputActivity();
+    m_shouldMakeInvisibileGamepadsVisible = false;
+
+    dispatchPlatformGamepadInputActivity();
 }
 
 } // namespace WebCore
index d0aaec2..837a398 100644 (file)
@@ -158,14 +158,14 @@ bool HIDGamepad::maybeAddAxis(IOHIDElementRef element)
     return true;
 }
 
-void HIDGamepad::valueChanged(IOHIDValueRef value)
+HIDInputType HIDGamepad::valueChanged(IOHIDValueRef value)
 {
     IOHIDElementCookie cookie = IOHIDElementGetCookie(IOHIDValueGetElement(value));
     HIDGamepadElement* element = m_elementMap.get(cookie);
 
     // 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 @@ void HIDGamepad::valueChanged(IOHIDValueRef value)
         ASSERT_NOT_REACHED();
 
     m_lastUpdateTime = monotonicallyIncreasingTime();
+
+    return element->isButton() ? HIDInputType::ButtonPress : HIDInputType::NotAButtonPress;
 }
 
 } // namespace WebCore
index 28402c5..43ae749 100644 (file)
@@ -91,13 +91,18 @@ struct HIDGamepadAxis : HIDGamepadElement {
     }
 };
 
+enum class HIDInputType {
+    ButtonPress,
+    NotAButtonPress,
+};
+
 class HIDGamepad : public PlatformGamepad {
 public:
     HIDGamepad(IOHIDDeviceRef, unsigned index);
 
     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; }
index 0d8a79a..f659605 100644 (file)
@@ -237,7 +237,8 @@ void HIDGamepadProvider::valuesChanged(IOHIDValueRef value)
     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 @@ void HIDGamepadProvider::inputNotificationTimerFired()
     if (!m_shouldDispatchCallbacks)
         return;
 
-    for (auto& client : m_clients)
-        client->platformGamepadInputActivity();
+    dispatchPlatformGamepadInputActivity();
 }
 
 std::unique_ptr<HIDGamepad> HIDGamepadProvider::removeGamepadForDevice(IOHIDDeviceRef device)
index 504cb4c..27859be 100644 (file)
@@ -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 @@ private:
 
     RetainPtr<IOHIDManagerRef> m_manager;
 
-    HashSet<GamepadProviderClient*> m_clients;
     bool m_shouldDispatchCallbacks;
 
     Timer m_connectionDelayTimer;
index 10757e2..ef21e50 100644 (file)
@@ -132,6 +132,7 @@ bool MockGamepadProvider::setMockGamepadButtonValue(unsigned index, unsigned but
     }
 
     m_mockGamepadVector[index]->setButtonValue(buttonIndex, value);
+    setShouldMakeGamepadsVisibile();
     gamepadInputActivity();
     return true;
 }
@@ -143,8 +144,7 @@ void MockGamepadProvider::gamepadInputActivity()
 
     m_shouldScheduleActivityCallback = false;
     callOnMainThread([this]() {
-        for (auto& client : m_clients)
-            client->platformGamepadInputActivity();
+        dispatchPlatformGamepadInputActivity();
 
         m_shouldScheduleActivityCallback = true;
     });
index af44925..9dd31e5 100644 (file)
@@ -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 @@ private:
     Vector<PlatformGamepad*> m_connectedGamepadVector;
     Vector<std::unique_ptr<MockGamepad>> m_mockGamepadVector;
 
-    HashSet<GamepadProviderClient*> m_clients;
-
     bool m_shouldScheduleActivityCallback { true };
 };
 
index 75c0b0f..c71c3f1 100644 (file)
@@ -1,3 +1,28 @@
+2017-01-20  Brady Eidson  <beidson@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  <pecoraro@apple.com>
 
         Cleanup RuntimeEnabledFeatures
index c3c5ba9..657c416 100644 (file)
@@ -65,7 +65,8 @@ void UIGamepadProvider::gamepadSyncTimerFired()
     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 @@ void UIGamepadProvider::platformGamepadDisconnected(PlatformGamepad& gamepad)
         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 @@ void UIGamepadProvider::platformGamepadInputActivity()
         m_gamepads[i]->updateFromPlatformGamepad(*platformGamepads[i]);
     }
 
+    if (shouldMakeGamepadsVisible)
+        m_shouldMakeGamepadsVisibleOnSync = true;
+
     scheduleGamepadStateSync();
 }
 
index 5414623..e076c2f 100644 (file)
@@ -74,7 +74,7 @@ private:
     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 @@ private:
 
     bool m_isMonitoringGamepads { false };
     bool m_hasInitialGamepads { false };
+    bool m_shouldMakeGamepadsVisibleOnSync { false };
 };
 
 }
index 9f875aa..72585c8 100644 (file)
@@ -5603,9 +5603,9 @@ void WebPageProxy::backForwardClear()
 
 #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
index f2fc7d1..e59596b 100644 (file)
@@ -1175,7 +1175,7 @@ public:
     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(); }
index 62bace4..7326286 100644 (file)
@@ -95,7 +95,7 @@ void WebGamepadProvider::gamepadDisconnected(unsigned index)
         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 @@ void WebGamepadProvider::gamepadActivity(const Vector<GamepadData>& gamepadDatas
     }
 
     for (auto* client : m_clients)
-        client->platformGamepadInputActivity();
+        client->platformGamepadInputActivity(shouldMakeGamepadsVisible);
 }
 
 void WebGamepadProvider::startMonitoringGamepads(GamepadProviderClient& client)
index 6e253c2..dc9750a 100644 (file)
@@ -44,7 +44,7 @@ public:
 
     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>&);
 
index cf529d6..bfe0d27 100644 (file)
@@ -5689,9 +5689,9 @@ void WebPage::setUserInterfaceLayoutDirection(uint32_t direction)
 
 #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
index b65d93b..b71b99b 100644 (file)
@@ -963,7 +963,7 @@ public:
 #endif
 
 #if ENABLE(GAMEPAD)
-    void gamepadActivity(const Vector<GamepadData>&);
+    void gamepadActivity(const Vector<GamepadData>&, bool shouldMakeGamepadsVisible);
 #endif
     
 #if ENABLE(POINTER_LOCK)
index 756b622..0f2d7bb 100644 (file)
@@ -459,6 +459,6 @@ messages -> WebPage LegacyReceiver {
     SetUseIconLoadingClient(bool useIconLoadingClient)
 
 #if ENABLE(GAMEPAD)
-    GamepadActivity(Vector<WebKit::GamepadData> gamepadDatas)
+    GamepadActivity(Vector<WebKit::GamepadData> gamepadDatas, bool shouldMakeGamepadsVisible)
 #endif
 }