Modified: trunk/Source/WebCore/ChangeLog (170550 => 170551)
--- trunk/Source/WebCore/ChangeLog 2014-06-27 20:47:05 UTC (rev 170550)
+++ trunk/Source/WebCore/ChangeLog 2014-06-27 20:53:14 UTC (rev 170551)
@@ -1,3 +1,22 @@
+2014-06-27 Brady Eidson <beid...@apple.com>
+
+ HIDGamepads should populate themselves with initial input values
+ https://bugs.webkit.org/show_bug.cgi?id=134381
+
+ Reviewed by Darin Adler.
+
+ No new tests (Not yet a tested config)
+
+ * platform/mac/HIDGamepad.cpp:
+ (WebCore::HIDGamepad::getCurrentValueForElement):
+ (WebCore::HIDGamepad::initElements): Loop through all the saved elements to get current values.
+ (WebCore::HIDGamepad::maybeAddButton):
+ (WebCore::HIDGamepad::maybeAddAxis):
+ * platform/mac/HIDGamepad.h:
+ (WebCore::HIDGamepadElement::HIDGamepadElement):
+ (WebCore::HIDGamepadButton::HIDGamepadButton):
+ (WebCore::HIDGamepadAxis::HIDGamepadAxis):
+
2014-06-27 Peyton Randolph <prando...@apple.com>
Add feature flag for link long-press gesture.
Modified: trunk/Source/WebCore/platform/mac/HIDGamepad.cpp (170550 => 170551)
--- trunk/Source/WebCore/platform/mac/HIDGamepad.cpp 2014-06-27 20:47:05 UTC (rev 170550)
+++ trunk/Source/WebCore/platform/mac/HIDGamepad.cpp 2014-06-27 20:53:14 UTC (rev 170551)
@@ -59,6 +59,14 @@
initElements();
}
+void HIDGamepad::getCurrentValueForElement(const HIDGamepadElement& gamepadElement)
+{
+ IOHIDElementRef element = gamepadElement.iohidElement.get();
+ IOHIDValueRef value;
+ if (IOHIDDeviceGetValue(IOHIDElementGetDevice(element), element, &value) == kIOReturnSuccess)
+ valueChanged(value);
+}
+
void HIDGamepad::initElements()
{
RetainPtr<CFArrayRef> elements = adoptCF(IOHIDDeviceCopyMatchingElements(m_hidDevice.get(), NULL, kIOHIDOptionsTypeNone));
@@ -71,6 +79,12 @@
m_axisValues.resize(m_axes.size());
m_buttonValues.resize(m_buttons.size());
+
+ for (auto& button : m_buttons)
+ getCurrentValueForElement(*button);
+
+ for (auto& axis : m_axes)
+ getCurrentValueForElement(*axis);
}
void HIDGamepad::initElementsFromArray(CFArrayRef elements)
@@ -113,7 +127,7 @@
CFIndex min = IOHIDElementGetLogicalMin(element);
CFIndex max = IOHIDElementGetLogicalMax(element);
- m_buttons.append(std::make_unique<HIDGamepadButton>(usage, min, max));
+ m_buttons.append(std::make_unique<HIDGamepadButton>(usage, min, max, element));
IOHIDElementCookie cookie = IOHIDElementGetCookie(element);
m_elementMap.set(cookie, m_buttons.last().get());
@@ -135,7 +149,7 @@
CFIndex min = IOHIDElementGetPhysicalMin(element);
CFIndex max = IOHIDElementGetPhysicalMax(element);
- m_axes.append(std::make_unique<HIDGamepadAxis>(min, max));
+ m_axes.append(std::make_unique<HIDGamepadAxis>(min, max, element));
IOHIDElementCookie cookie = IOHIDElementGetCookie(element);
m_elementMap.set(cookie, m_axes.last().get());
Modified: trunk/Source/WebCore/platform/mac/HIDGamepad.h (170550 => 170551)
--- trunk/Source/WebCore/platform/mac/HIDGamepad.h 2014-06-27 20:47:05 UTC (rev 170550)
+++ trunk/Source/WebCore/platform/mac/HIDGamepad.h 2014-06-27 20:53:14 UTC (rev 170551)
@@ -36,10 +36,11 @@
namespace WebCore {
struct HIDGamepadElement {
- HIDGamepadElement(double theMin, double theMax)
+ HIDGamepadElement(double theMin, double theMax, IOHIDElementRef element)
: min(theMin)
, max(theMax)
, rawValue(theMin)
+ , iohidElement(element)
{
}
@@ -50,6 +51,7 @@
double min;
double max;
double rawValue;
+ RetainPtr<IOHIDElementRef> iohidElement;
virtual bool isButton() const { return false; }
virtual bool isAxis() const { return false; }
@@ -57,9 +59,9 @@
virtual double normalizedValue() = 0;
};
-struct HIDGamepadButton : public HIDGamepadElement {
- HIDGamepadButton(uint32_t thePriority, double min, double max)
- : HIDGamepadElement(min, max)
+struct HIDGamepadButton : HIDGamepadElement {
+ HIDGamepadButton(uint32_t thePriority, double min, double max, IOHIDElementRef element)
+ : HIDGamepadElement(min, max, element)
, priority(thePriority)
{
}
@@ -75,9 +77,9 @@
}
};
-struct HIDGamepadAxis : public HIDGamepadElement {
- HIDGamepadAxis(double min, double max)
- : HIDGamepadElement(min, max)
+struct HIDGamepadAxis : HIDGamepadElement {
+ HIDGamepadAxis(double min, double max, IOHIDElementRef element)
+ : HIDGamepadElement(min, max, element)
{
}
@@ -108,6 +110,8 @@
bool maybeAddButton(IOHIDElementRef);
bool maybeAddAxis(IOHIDElementRef);
+ void getCurrentValueForElement(const HIDGamepadElement&);
+
RetainPtr<IOHIDDeviceRef> m_hidDevice;
HashMap<IOHIDElementCookie, HIDGamepadElement*> m_elementMap;