summaryrefslogtreecommitdiff
path: root/Source/WebCore/Modules/gamepad
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/Modules/gamepad')
-rw-r--r--Source/WebCore/Modules/gamepad/Gamepad.cpp67
-rw-r--r--Source/WebCore/Modules/gamepad/Gamepad.h69
-rw-r--r--Source/WebCore/Modules/gamepad/Gamepad.idl38
-rw-r--r--Source/WebCore/Modules/gamepad/GamepadButton.cpp48
-rw-r--r--Source/WebCore/Modules/gamepad/GamepadButton.h54
-rw-r--r--Source/WebCore/Modules/gamepad/GamepadButton.idl34
-rw-r--r--Source/WebCore/Modules/gamepad/GamepadEvent.cpp46
-rw-r--r--Source/WebCore/Modules/gamepad/GamepadEvent.h67
-rw-r--r--Source/WebCore/Modules/gamepad/GamepadEvent.idl38
-rw-r--r--Source/WebCore/Modules/gamepad/GamepadManager.cpp245
-rw-r--r--Source/WebCore/Modules/gamepad/GamepadManager.h76
-rw-r--r--Source/WebCore/Modules/gamepad/NavigatorGamepad.cpp122
-rw-r--r--Source/WebCore/Modules/gamepad/NavigatorGamepad.h55
-rw-r--r--Source/WebCore/Modules/gamepad/NavigatorGamepad.idl36
-rw-r--r--Source/WebCore/Modules/gamepad/deprecated/Gamepad.cpp61
-rw-r--r--Source/WebCore/Modules/gamepad/deprecated/Gamepad.h72
-rw-r--r--Source/WebCore/Modules/gamepad/deprecated/Gamepad.idl37
-rw-r--r--Source/WebCore/Modules/gamepad/deprecated/GamepadList.cpp (renamed from Source/WebCore/Modules/gamepad/GamepadList.cpp)8
-rw-r--r--Source/WebCore/Modules/gamepad/deprecated/GamepadList.h (renamed from Source/WebCore/Modules/gamepad/GamepadList.h)14
-rw-r--r--Source/WebCore/Modules/gamepad/deprecated/GamepadList.idl (renamed from Source/WebCore/Modules/gamepad/GamepadList.idl)4
-rw-r--r--Source/WebCore/Modules/gamepad/deprecated/NavigatorGamepad.cpp76
-rw-r--r--Source/WebCore/Modules/gamepad/deprecated/NavigatorGamepad.h56
-rw-r--r--Source/WebCore/Modules/gamepad/deprecated/NavigatorGamepad.idl25
23 files changed, 1189 insertions, 159 deletions
diff --git a/Source/WebCore/Modules/gamepad/Gamepad.cpp b/Source/WebCore/Modules/gamepad/Gamepad.cpp
index 89105ceb8..d11c5508d 100644
--- a/Source/WebCore/Modules/gamepad/Gamepad.cpp
+++ b/Source/WebCore/Modules/gamepad/Gamepad.cpp
@@ -1,26 +1,26 @@
/*
- * Copyright (C) 2011, Google Inc. All rights reserved.
+ * Copyright (C) 2014 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:
- *
+ * 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.
+ * 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"
@@ -28,32 +28,47 @@
#if ENABLE(GAMEPAD)
+#include "GamepadButton.h"
+#include "PlatformGamepad.h"
#include <wtf/text/WTFString.h>
namespace WebCore {
-Gamepad::Gamepad()
- : m_index(0)
- , m_timestamp(0)
+Gamepad::Gamepad(const PlatformGamepad& platformGamepad)
+ : m_id(platformGamepad.id())
+ , m_index(platformGamepad.index())
+ , m_connected(true)
+ , m_timestamp(platformGamepad.lastUpdateTime())
{
+ m_axes.resize(platformGamepad.axisValues().size());
+ m_axes.fill(0.0);
+ unsigned buttonCount = platformGamepad.buttonValues().size();
+ for (unsigned i = 0; i < buttonCount; ++i)
+ m_buttons.append(GamepadButton::create());
}
-void Gamepad::axes(unsigned count, float* data)
+Gamepad::~Gamepad()
{
- m_axes.resize(count);
- if (count)
- std::copy(data, data + count, m_axes.begin());
}
-void Gamepad::buttons(unsigned count, float* data)
+const Vector<double>& Gamepad::axes() const
{
- m_buttons.resize(count);
- if (count)
- std::copy(data, data + count, m_buttons.begin());
+ return m_axes;
}
-Gamepad::~Gamepad()
+const Vector<Ref<GamepadButton>>& Gamepad::buttons() const
{
+ return m_buttons;
+}
+
+void Gamepad::updateFromPlatformGamepad(const PlatformGamepad& platformGamepad)
+{
+ for (unsigned i = 0; i < m_axes.size(); ++i)
+ m_axes[i] = platformGamepad.axisValues()[i];
+ for (unsigned i = 0; i < m_buttons.size(); ++i)
+ m_buttons[i]->setValue(platformGamepad.buttonValues()[i]);
+
+ m_timestamp = platformGamepad.lastUpdateTime();
}
} // namespace WebCore
diff --git a/Source/WebCore/Modules/gamepad/Gamepad.h b/Source/WebCore/Modules/gamepad/Gamepad.h
index 5b9b1d2dc..f32992f28 100644
--- a/Source/WebCore/Modules/gamepad/Gamepad.h
+++ b/Source/WebCore/Modules/gamepad/Gamepad.h
@@ -1,30 +1,29 @@
/*
- * Copyright (C) 2011, Google Inc. All rights reserved.
+ * Copyright (C) 2014 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:
- *
+ * 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.
+ * 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.
*/
-#ifndef Gamepad_h
-#define Gamepad_h
+#pragma once
#if ENABLE(GAMEPAD)
@@ -34,42 +33,40 @@
namespace WebCore {
+class GamepadButton;
+class PlatformGamepad;
+
class Gamepad: public RefCounted<Gamepad> {
public:
- static PassRefPtr<Gamepad> create()
+ static Ref<Gamepad> create(const PlatformGamepad& platformGamepad)
{
- return adoptRef(new Gamepad);
+ return adoptRef(*new Gamepad(platformGamepad));
}
~Gamepad();
- typedef Vector<float> FloatVector;
-
const String& id() const { return m_id; }
- void id(const String& id) { m_id = id; }
-
unsigned index() const { return m_index; }
- void index(unsigned val) { m_index = val; }
+ const String& mapping() const { return m_mapping; }
- unsigned long long timestamp() const { return m_timestamp; }
- void timestamp(unsigned long long val) { m_timestamp = val; }
+ bool connected() const { return m_connected; }
+ double timestamp() const { return m_timestamp; }
+ const Vector<double>& axes() const;
+ const Vector<Ref<GamepadButton>>& buttons() const;
- const FloatVector& axes() const { return m_axes; }
- void axes(unsigned count, float* data);
-
- const FloatVector& buttons() const { return m_buttons; }
- void buttons(unsigned count, float* data);
+ void updateFromPlatformGamepad(const PlatformGamepad&);
private:
- Gamepad();
+ explicit Gamepad(const PlatformGamepad&);
String m_id;
unsigned m_index;
- unsigned long long m_timestamp;
- FloatVector m_axes;
- FloatVector m_buttons;
+ bool m_connected;
+ double m_timestamp;
+ String m_mapping;
+
+ Vector<double> m_axes;
+ Vector<Ref<GamepadButton>> m_buttons;
};
} // namespace WebCore
#endif // ENABLE(GAMEPAD)
-
-#endif // Gamepad_h
diff --git a/Source/WebCore/Modules/gamepad/Gamepad.idl b/Source/WebCore/Modules/gamepad/Gamepad.idl
index 0c9c1e745..8f3b80343 100644
--- a/Source/WebCore/Modules/gamepad/Gamepad.idl
+++ b/Source/WebCore/Modules/gamepad/Gamepad.idl
@@ -1,37 +1,39 @@
/*
- * Copyright (C) 2011, Google Inc. All rights reserved.
+ * Copyright (C) 2014 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:
- *
+ * 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.
+ * 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.
*/
[
- NoInterfaceObject,
+ EnabledAtRuntime=Gamepads,
Conditional=GAMEPAD,
ImplementationLacksVTable
] interface Gamepad {
readonly attribute DOMString id;
readonly attribute unsigned long index;
- readonly attribute unsigned long long timestamp;
- readonly attribute float[] axes;
- readonly attribute float[] buttons;
+ readonly attribute boolean connected;
+ readonly attribute double timestamp;
+ readonly attribute DOMString mapping;
+ readonly attribute sequence<double> axes;
+ readonly attribute sequence<GamepadButton> buttons;
};
diff --git a/Source/WebCore/Modules/gamepad/GamepadButton.cpp b/Source/WebCore/Modules/gamepad/GamepadButton.cpp
new file mode 100644
index 000000000..99fe7c4c1
--- /dev/null
+++ b/Source/WebCore/Modules/gamepad/GamepadButton.cpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2014 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 "GamepadButton.h"
+
+#if ENABLE(GAMEPAD)
+
+namespace WebCore {
+
+GamepadButton::GamepadButton()
+ : m_value(0)
+{
+}
+
+bool GamepadButton::pressed() const
+{
+ // FIXME: The spec states that for analog buttons there needs to be a
+ // threshold for determining the state of "pressed".
+ // What should that threshold be?
+ return m_value > 0.1;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD)
diff --git a/Source/WebCore/Modules/gamepad/GamepadButton.h b/Source/WebCore/Modules/gamepad/GamepadButton.h
new file mode 100644
index 000000000..db4f9f587
--- /dev/null
+++ b/Source/WebCore/Modules/gamepad/GamepadButton.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2014 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)
+
+#include <wtf/Ref.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class GamepadButton : public RefCounted<GamepadButton> {
+public:
+ static Ref<GamepadButton> create()
+ {
+ return adoptRef(*new GamepadButton);
+ }
+
+ bool pressed() const;
+ double value() const { return m_value; }
+ void setValue(double value) { m_value = value; }
+
+private:
+ GamepadButton();
+
+ double m_value;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD)
diff --git a/Source/WebCore/Modules/gamepad/GamepadButton.idl b/Source/WebCore/Modules/gamepad/GamepadButton.idl
new file mode 100644
index 000000000..0a2e67b60
--- /dev/null
+++ b/Source/WebCore/Modules/gamepad/GamepadButton.idl
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+[
+ EnabledAtRuntime=Gamepads,
+ Conditional=GAMEPAD,
+ ImplementationLacksVTable
+] interface GamepadButton {
+ readonly attribute boolean pressed;
+ readonly attribute double value;
+};
+
diff --git a/Source/WebCore/Modules/gamepad/GamepadEvent.cpp b/Source/WebCore/Modules/gamepad/GamepadEvent.cpp
new file mode 100644
index 000000000..a6800af6d
--- /dev/null
+++ b/Source/WebCore/Modules/gamepad/GamepadEvent.cpp
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2014 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 "GamepadEvent.h"
+
+#if ENABLE(GAMEPAD)
+
+namespace WebCore {
+
+GamepadEvent::GamepadEvent(const AtomicString& eventType, Gamepad& gamepad)
+ : Event(eventType, false, false)
+ , m_gamepad(&gamepad)
+{
+}
+
+GamepadEvent::GamepadEvent(const AtomicString& eventType, const Init& initializer, IsTrusted isTrusted)
+ : Event(eventType, initializer, isTrusted)
+ , m_gamepad(initializer.gamepad)
+{
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD)
diff --git a/Source/WebCore/Modules/gamepad/GamepadEvent.h b/Source/WebCore/Modules/gamepad/GamepadEvent.h
new file mode 100644
index 000000000..d43da58a9
--- /dev/null
+++ b/Source/WebCore/Modules/gamepad/GamepadEvent.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2014 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)
+
+#include "Event.h"
+#include "Gamepad.h"
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class GamepadEvent : public Event {
+public:
+ ~GamepadEvent() { }
+
+ static Ref<GamepadEvent> create(const AtomicString& eventType, Gamepad& gamepad)
+ {
+ return adoptRef(*new GamepadEvent(eventType, gamepad));
+ }
+
+ struct Init : EventInit {
+ RefPtr<Gamepad> gamepad;
+ };
+
+ static Ref<GamepadEvent> create(const AtomicString& eventType, const Init& initializer, IsTrusted isTrusted = IsTrusted::No)
+ {
+ return adoptRef(*new GamepadEvent(eventType, initializer, isTrusted));
+ }
+
+ Gamepad* gamepad() const { return m_gamepad.get(); }
+
+ EventInterface eventInterface() const override { return GamepadEventInterfaceType; }
+
+private:
+ explicit GamepadEvent(const AtomicString& eventType, Gamepad&);
+ GamepadEvent(const AtomicString& eventType, const Init&, IsTrusted);
+
+ RefPtr<Gamepad> m_gamepad;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD)
diff --git a/Source/WebCore/Modules/gamepad/GamepadEvent.idl b/Source/WebCore/Modules/gamepad/GamepadEvent.idl
new file mode 100644
index 000000000..d99b379f9
--- /dev/null
+++ b/Source/WebCore/Modules/gamepad/GamepadEvent.idl
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+[
+ Conditional=GAMEPAD,
+ Constructor(DOMString type, GamepadEventInit eventInitDict),
+ EnabledAtRuntime=Gamepads,
+] interface GamepadEvent : Event {
+ readonly attribute Gamepad? gamepad;
+};
+
+dictionary GamepadEventInit : EventInit {
+ // The specification says this member should be required and non-nullable.
+ // However, this does not match the behavior of Chrome or Firefox.
+ Gamepad? gamepad = null;
+};
diff --git a/Source/WebCore/Modules/gamepad/GamepadManager.cpp b/Source/WebCore/Modules/gamepad/GamepadManager.cpp
new file mode 100644
index 000000000..b2ecba196
--- /dev/null
+++ b/Source/WebCore/Modules/gamepad/GamepadManager.cpp
@@ -0,0 +1,245 @@
+/*
+ * Copyright (C) 2014 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 "GamepadManager.h"
+
+#if ENABLE(GAMEPAD)
+
+#include "DOMWindow.h"
+#include "Document.h"
+#include "EventNames.h"
+#include "Gamepad.h"
+#include "GamepadEvent.h"
+#include "GamepadProvider.h"
+#include "Logging.h"
+#include "NavigatorGamepad.h"
+#include "PlatformGamepad.h"
+
+namespace WebCore {
+
+static NavigatorGamepad* navigatorGamepadFromDOMWindow(DOMWindow* window)
+{
+ Navigator* navigator = window->navigator();
+ if (!navigator)
+ return nullptr;
+
+ return NavigatorGamepad::from(navigator);
+}
+
+GamepadManager& GamepadManager::singleton()
+{
+ static NeverDestroyed<GamepadManager> sharedManager;
+ return sharedManager;
+}
+
+GamepadManager::GamepadManager()
+ : m_isMonitoringGamepads(false)
+{
+}
+
+void GamepadManager::platformGamepadConnected(PlatformGamepad& platformGamepad)
+{
+ // Notify blind Navigators and Windows about all gamepads except for this one.
+ for (auto* gamepad : GamepadProvider::singleton().platformGamepads()) {
+ if (!gamepad || gamepad == &platformGamepad)
+ continue;
+
+ makeGamepadVisible(*gamepad, m_gamepadBlindNavigators, m_gamepadBlindDOMWindows);
+ }
+
+ m_gamepadBlindNavigators.clear();
+ m_gamepadBlindDOMWindows.clear();
+
+ // Notify everyone of this new gamepad.
+ makeGamepadVisible(platformGamepad, m_navigators, m_domWindows);
+}
+
+void GamepadManager::platformGamepadDisconnected(PlatformGamepad& platformGamepad)
+{
+ Vector<WeakPtr<DOMWindow>> weakWindows;
+ for (auto* domWindow : m_domWindows)
+ weakWindows.append(domWindow->createWeakPtr());
+
+ HashSet<NavigatorGamepad*> notifiedNavigators;
+
+ // Handle the disconnect for all DOMWindows with event listeners and their Navigators.
+ for (auto& window : weakWindows) {
+ // Event dispatch might have made this window go away.
+ if (!window)
+ continue;
+
+ // This DOMWindow's Navigator might not be accessible. e.g. The DOMWindow might be in the back/forward cache.
+ // If this happens the DOMWindow will not get this gamepaddisconnected event.
+ NavigatorGamepad* navigator = navigatorGamepadFromDOMWindow(window.get());
+ if (!navigator)
+ continue;
+
+ // If this Navigator hasn't seen gamepads yet then its Window should not get the disconnect event.
+ if (m_gamepadBlindNavigators.contains(navigator))
+ continue;
+
+ Ref<Gamepad> gamepad(navigator->gamepadFromPlatformGamepad(platformGamepad));
+
+ navigator->gamepadDisconnected(platformGamepad);
+ notifiedNavigators.add(navigator);
+
+ window->dispatchEvent(GamepadEvent::create(eventNames().gamepaddisconnectedEvent, gamepad.get()), window->document());
+ }
+
+ // Notify all the Navigators that haven't already been notified.
+ for (auto* navigator : m_navigators) {
+ if (!notifiedNavigators.contains(navigator))
+ navigator->gamepadDisconnected(platformGamepad);
+ }
+}
+
+void GamepadManager::platformGamepadInputActivity(bool shouldMakeGamepadVisible)
+{
+ if (!shouldMakeGamepadVisible)
+ return;
+
+ if (m_gamepadBlindNavigators.isEmpty() && m_gamepadBlindDOMWindows.isEmpty())
+ return;
+
+ for (auto* gamepad : GamepadProvider::singleton().platformGamepads()) {
+ if (gamepad)
+ makeGamepadVisible(*gamepad, m_gamepadBlindNavigators, m_gamepadBlindDOMWindows);
+ }
+
+ m_gamepadBlindNavigators.clear();
+ m_gamepadBlindDOMWindows.clear();
+}
+
+void GamepadManager::makeGamepadVisible(PlatformGamepad& platformGamepad, HashSet<NavigatorGamepad*>& navigatorSet, HashSet<DOMWindow*>& domWindowSet)
+{
+ if (navigatorSet.isEmpty() && domWindowSet.isEmpty())
+ return;
+
+ for (auto* navigator : navigatorSet)
+ navigator->gamepadConnected(platformGamepad);
+
+ Vector<WeakPtr<DOMWindow>> weakWindows;
+ for (auto* domWindow : m_domWindows)
+ weakWindows.append(domWindow->createWeakPtr());
+
+ for (auto& window : weakWindows) {
+ // Event dispatch might have made this window go away.
+ if (!window)
+ continue;
+
+ // This DOMWindow's Navigator might not be accessible. e.g. The DOMWindow might be in the back/forward cache.
+ // If this happens the DOMWindow will not get this gamepadconnected event.
+ // The new gamepad will still be visibile to it once it is restored from the back/forward cache.
+ NavigatorGamepad* navigator = navigatorGamepadFromDOMWindow(window.get());
+ if (!navigator)
+ continue;
+
+ Ref<Gamepad> gamepad(navigator->gamepadFromPlatformGamepad(platformGamepad));
+ window->dispatchEvent(GamepadEvent::create(eventNames().gamepadconnectedEvent, gamepad.get()), window->document());
+ }
+}
+
+void GamepadManager::registerNavigator(NavigatorGamepad* navigator)
+{
+ LOG(Gamepad, "GamepadManager registering NavigatorGamepad %p", navigator);
+
+ ASSERT(!m_navigators.contains(navigator));
+ m_navigators.add(navigator);
+ m_gamepadBlindNavigators.add(navigator);
+
+ maybeStartMonitoringGamepads();
+}
+
+void GamepadManager::unregisterNavigator(NavigatorGamepad* navigator)
+{
+ LOG(Gamepad, "GamepadManager unregistering NavigatorGamepad %p", navigator);
+
+ ASSERT(m_navigators.contains(navigator));
+ m_navigators.remove(navigator);
+ m_gamepadBlindNavigators.remove(navigator);
+
+ maybeStopMonitoringGamepads();
+}
+
+void GamepadManager::registerDOMWindow(DOMWindow* window)
+{
+ LOG(Gamepad, "GamepadManager registering DOMWindow %p", window);
+
+ ASSERT(!m_domWindows.contains(window));
+ m_domWindows.add(window);
+
+ // Anytime we register a DOMWindow, we should also double check that its NavigatorGamepad is registered.
+ NavigatorGamepad* navigator = navigatorGamepadFromDOMWindow(window);
+ ASSERT(navigator);
+
+ if (m_navigators.add(navigator).isNewEntry)
+ m_gamepadBlindNavigators.add(navigator);
+
+ // If this DOMWindow's NavigatorGamepad was already registered but was still blind,
+ // then this DOMWindow should be blind.
+ if (m_gamepadBlindNavigators.contains(navigator))
+ m_gamepadBlindDOMWindows.add(window);
+
+ maybeStartMonitoringGamepads();
+}
+
+void GamepadManager::unregisterDOMWindow(DOMWindow* window)
+{
+ LOG(Gamepad, "GamepadManager unregistering DOMWindow %p", window);
+
+ ASSERT(m_domWindows.contains(window));
+ m_domWindows.remove(window);
+ m_gamepadBlindDOMWindows.remove(window);
+
+ maybeStopMonitoringGamepads();
+}
+
+void GamepadManager::maybeStartMonitoringGamepads()
+{
+ if (m_isMonitoringGamepads)
+ return;
+
+ if (!m_navigators.isEmpty() || !m_domWindows.isEmpty()) {
+ LOG(Gamepad, "GamepadManager has %i NavigatorGamepads and %i DOMWindows registered, is starting gamepad monitoring", m_navigators.size(), m_domWindows.size());
+ m_isMonitoringGamepads = true;
+ GamepadProvider::singleton().startMonitoringGamepads(*this);
+ }
+}
+
+void GamepadManager::maybeStopMonitoringGamepads()
+{
+ if (!m_isMonitoringGamepads)
+ return;
+
+ if (m_navigators.isEmpty() && m_domWindows.isEmpty()) {
+ LOG(Gamepad, "GamepadManager has no NavigatorGamepads or DOMWindows registered, is stopping gamepad monitoring");
+ m_isMonitoringGamepads = false;
+ GamepadProvider::singleton().stopMonitoringGamepads(*this);
+ }
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD)
diff --git a/Source/WebCore/Modules/gamepad/GamepadManager.h b/Source/WebCore/Modules/gamepad/GamepadManager.h
new file mode 100644
index 000000000..63b66fa6d
--- /dev/null
+++ b/Source/WebCore/Modules/gamepad/GamepadManager.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2014 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)
+
+#include "GamepadProviderClient.h"
+#include <wtf/HashSet.h>
+#include <wtf/NeverDestroyed.h>
+#include <wtf/RefPtr.h>
+#include <wtf/text/AtomicString.h>
+
+namespace WebCore {
+
+class DOMWindow;
+class Gamepad;
+class NavigatorGamepad;
+
+class GamepadManager : public GamepadProviderClient {
+ WTF_MAKE_NONCOPYABLE(GamepadManager);
+ friend class NeverDestroyed<GamepadManager>;
+public:
+ static GamepadManager& singleton();
+
+ void platformGamepadConnected(PlatformGamepad&) final;
+ void platformGamepadDisconnected(PlatformGamepad&) final;
+ void platformGamepadInputActivity(bool shouldMakeGamepadVisible) final;
+
+ void registerNavigator(NavigatorGamepad*);
+ void unregisterNavigator(NavigatorGamepad*);
+ void registerDOMWindow(DOMWindow*);
+ void unregisterDOMWindow(DOMWindow*);
+
+private:
+ GamepadManager();
+
+ void makeGamepadVisible(PlatformGamepad&, HashSet<NavigatorGamepad*>&, HashSet<DOMWindow*>&);
+ void dispatchGamepadEvent(const WTF::AtomicString& eventName, PlatformGamepad&);
+
+ void maybeStartMonitoringGamepads();
+ void maybeStopMonitoringGamepads();
+
+ bool m_isMonitoringGamepads;
+
+ HashSet<NavigatorGamepad*> m_navigators;
+ HashSet<NavigatorGamepad*> m_gamepadBlindNavigators;
+ HashSet<DOMWindow*> m_domWindows;
+ HashSet<DOMWindow*> m_gamepadBlindDOMWindows;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD)
diff --git a/Source/WebCore/Modules/gamepad/NavigatorGamepad.cpp b/Source/WebCore/Modules/gamepad/NavigatorGamepad.cpp
index 2079e7876..61020899c 100644
--- a/Source/WebCore/Modules/gamepad/NavigatorGamepad.cpp
+++ b/Source/WebCore/Modules/gamepad/NavigatorGamepad.cpp
@@ -1,26 +1,26 @@
/*
- * Copyright (C) 2011, Google Inc. All rights reserved.
+ * Copyright (C) 2014 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:
- *
+ * 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.
+ * 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"
@@ -28,19 +28,22 @@
#if ENABLE(GAMEPAD)
-#include "GamepadList.h"
-#include "Gamepads.h"
+#include "Gamepad.h"
+#include "GamepadManager.h"
+#include "GamepadProvider.h"
#include "Navigator.h"
-#include <wtf/PassOwnPtr.h>
+#include "PlatformGamepad.h"
namespace WebCore {
NavigatorGamepad::NavigatorGamepad()
{
+ GamepadManager::singleton().registerNavigator(this);
}
NavigatorGamepad::~NavigatorGamepad()
{
+ GamepadManager::singleton().unregisterNavigator(this);
}
const char* NavigatorGamepad::supplementName()
@@ -52,23 +55,90 @@ NavigatorGamepad* NavigatorGamepad::from(Navigator* navigator)
{
NavigatorGamepad* supplement = static_cast<NavigatorGamepad*>(Supplement<Navigator>::from(navigator, supplementName()));
if (!supplement) {
- supplement = new NavigatorGamepad();
- provideTo(navigator, supplementName(), adoptPtr(supplement));
+ auto newSupplement = std::make_unique<NavigatorGamepad>();
+ supplement = newSupplement.get();
+ provideTo(navigator, supplementName(), WTFMove(newSupplement));
}
return supplement;
}
-GamepadList* NavigatorGamepad::webkitGetGamepads(Navigator* navigator)
+Ref<Gamepad> NavigatorGamepad::gamepadFromPlatformGamepad(PlatformGamepad& platformGamepad)
+{
+ unsigned index = platformGamepad.index();
+ if (index >= m_gamepads.size() || !m_gamepads[index])
+ return Gamepad::create(platformGamepad);
+
+ return *m_gamepads[index];
+}
+
+const Vector<RefPtr<Gamepad>>& NavigatorGamepad::getGamepads(Navigator& navigator)
+{
+ return NavigatorGamepad::from(&navigator)->gamepads();
+}
+
+const Vector<RefPtr<Gamepad>>& NavigatorGamepad::gamepads()
+{
+ if (m_gamepads.isEmpty())
+ return m_gamepads;
+
+ const Vector<PlatformGamepad*>& platformGamepads = GamepadProvider::singleton().platformGamepads();
+
+ for (unsigned i = 0; i < platformGamepads.size(); ++i) {
+ if (!platformGamepads[i]) {
+ ASSERT(!m_gamepads[i]);
+ continue;
+ }
+
+ ASSERT(m_gamepads[i]);
+ m_gamepads[i]->updateFromPlatformGamepad(*platformGamepads[i]);
+ }
+
+ return m_gamepads;
+}
+
+void NavigatorGamepad::gamepadsBecameVisible()
+{
+ const Vector<PlatformGamepad*>& platformGamepads = GamepadProvider::singleton().platformGamepads();
+ m_gamepads.resize(platformGamepads.size());
+
+ for (unsigned i = 0; i < platformGamepads.size(); ++i) {
+ if (!platformGamepads[i])
+ continue;
+
+ m_gamepads[i] = Gamepad::create(*platformGamepads[i]);
+ }
+}
+
+void NavigatorGamepad::gamepadConnected(PlatformGamepad& platformGamepad)
{
- return NavigatorGamepad::from(navigator)->gamepads();
+ // If this is the first gamepad this Navigator object has seen, then all gamepads just became visible.
+ if (m_gamepads.isEmpty()) {
+ gamepadsBecameVisible();
+ return;
+ }
+
+ unsigned index = platformGamepad.index();
+ ASSERT(GamepadProvider::singleton().platformGamepads()[index] == &platformGamepad);
+
+ // The new index should already fit in the existing array, or should be exactly one past-the-end of the existing array.
+ ASSERT(index <= m_gamepads.size());
+
+ if (index < m_gamepads.size())
+ m_gamepads[index] = Gamepad::create(platformGamepad);
+ else if (index == m_gamepads.size())
+ m_gamepads.append(Gamepad::create(platformGamepad));
}
-GamepadList* NavigatorGamepad::gamepads()
+void NavigatorGamepad::gamepadDisconnected(PlatformGamepad& platformGamepad)
{
- if (!m_gamepads)
- m_gamepads = GamepadList::create();
- sampleGamepads(m_gamepads.get());
- return m_gamepads.get();
+ // If this Navigator hasn't seen any gamepads yet its Vector will still be empty.
+ if (!m_gamepads.size())
+ return;
+
+ ASSERT(platformGamepad.index() < m_gamepads.size());
+ ASSERT(m_gamepads[platformGamepad.index()]);
+
+ m_gamepads[platformGamepad.index()] = nullptr;
}
} // namespace WebCore
diff --git a/Source/WebCore/Modules/gamepad/NavigatorGamepad.h b/Source/WebCore/Modules/gamepad/NavigatorGamepad.h
index 3ee8ba91c..dee01e69c 100644
--- a/Source/WebCore/Modules/gamepad/NavigatorGamepad.h
+++ b/Source/WebCore/Modules/gamepad/NavigatorGamepad.h
@@ -1,58 +1,67 @@
/*
- * Copyright (C) 2011, Google Inc. All rights reserved.
+ * Copyright (C) 2014 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:
- *
+ * 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.
+ * 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.
*/
-#ifndef NavigatorGamepad_h
-#define NavigatorGamepad_h
+#pragma once
#if ENABLE(GAMEPAD)
#include "Supplementable.h"
+#include <wtf/Vector.h>
namespace WebCore {
-class GamepadList;
+class Gamepad;
class Navigator;
+class PlatformGamepad;
class NavigatorGamepad : public Supplement<Navigator> {
public:
+ NavigatorGamepad();
virtual ~NavigatorGamepad();
+
static NavigatorGamepad* from(Navigator*);
- static GamepadList* webkitGetGamepads(Navigator*);
+ // The array of Gamepads might be sparse.
+ // Null checking each entry is necessary.
+ static const Vector<RefPtr<Gamepad>>& getGamepads(Navigator&);
+
+ void gamepadConnected(PlatformGamepad&);
+ void gamepadDisconnected(PlatformGamepad&);
- GamepadList* gamepads();
+ Ref<Gamepad> gamepadFromPlatformGamepad(PlatformGamepad&);
private:
- NavigatorGamepad();
static const char* supplementName();
- RefPtr<GamepadList> m_gamepads;
+ void gamepadsBecameVisible();
+
+ const Vector<RefPtr<Gamepad>>& gamepads();
+
+ Vector<RefPtr<Gamepad>> m_gamepads;
};
} // namespace WebCore
#endif // ENABLE(GAMEPAD)
-
-#endif // NavigatorGamepad_h
diff --git a/Source/WebCore/Modules/gamepad/NavigatorGamepad.idl b/Source/WebCore/Modules/gamepad/NavigatorGamepad.idl
index a26c5eae5..c1960938f 100644
--- a/Source/WebCore/Modules/gamepad/NavigatorGamepad.idl
+++ b/Source/WebCore/Modules/gamepad/NavigatorGamepad.idl
@@ -1,25 +1,31 @@
/*
- * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * 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 library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * 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.
*/
[
Conditional=GAMEPAD,
] partial interface Navigator {
- GamepadList webkitGetGamepads();
+ [EnabledAtRuntime=Gamepads] sequence<Gamepad> getGamepads();
};
diff --git a/Source/WebCore/Modules/gamepad/deprecated/Gamepad.cpp b/Source/WebCore/Modules/gamepad/deprecated/Gamepad.cpp
new file mode 100644
index 000000000..52e274906
--- /dev/null
+++ b/Source/WebCore/Modules/gamepad/deprecated/Gamepad.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2011, Google 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 "Gamepad.h"
+
+#if ENABLE(GAMEPAD_DEPRECATED)
+
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+Gamepad::Gamepad()
+ : m_index(0)
+ , m_timestamp(0)
+{
+}
+
+void Gamepad::axes(unsigned count, float* data)
+{
+ m_axes.resize(count);
+ if (count)
+ std::copy(data, data + count, m_axes.begin());
+}
+
+void Gamepad::buttons(unsigned count, float* data)
+{
+ m_buttons.resize(count);
+ if (count)
+ std::copy(data, data + count, m_buttons.begin());
+}
+
+Gamepad::~Gamepad()
+{
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD_DEPRECATED)
diff --git a/Source/WebCore/Modules/gamepad/deprecated/Gamepad.h b/Source/WebCore/Modules/gamepad/deprecated/Gamepad.h
new file mode 100644
index 000000000..54c949b8c
--- /dev/null
+++ b/Source/WebCore/Modules/gamepad/deprecated/Gamepad.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2011, Google 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_DEPRECATED)
+
+#include <wtf/RefCounted.h>
+#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class Gamepad: public RefCounted<Gamepad> {
+public:
+ static Ref<Gamepad> create()
+ {
+ return adoptRef(*new Gamepad);
+ }
+ ~Gamepad();
+
+ typedef Vector<float> FloatVector;
+
+ const String& id() const { return m_id; }
+ void id(const String& id) { m_id = id; }
+
+ unsigned index() const { return m_index; }
+ void index(unsigned val) { m_index = val; }
+
+ unsigned long long timestamp() const { return m_timestamp; }
+ void timestamp(unsigned long long val) { m_timestamp = val; }
+
+ const FloatVector& axes() const { return m_axes; }
+ void axes(unsigned count, float* data);
+
+ const FloatVector& buttons() const { return m_buttons; }
+ void buttons(unsigned count, float* data);
+
+private:
+ Gamepad();
+ String m_id;
+ unsigned m_index;
+ unsigned long long m_timestamp;
+ FloatVector m_axes;
+ FloatVector m_buttons;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD_DEPRECATED)
diff --git a/Source/WebCore/Modules/gamepad/deprecated/Gamepad.idl b/Source/WebCore/Modules/gamepad/deprecated/Gamepad.idl
new file mode 100644
index 000000000..824e97e96
--- /dev/null
+++ b/Source/WebCore/Modules/gamepad/deprecated/Gamepad.idl
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2011, Google 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.
+ */
+
+[
+ NoInterfaceObject,
+ Conditional=GAMEPAD_DEPRECATED,
+ ImplementationLacksVTable
+] interface Gamepad {
+ readonly attribute DOMString id;
+ readonly attribute unsigned long index;
+ readonly attribute unsigned long long timestamp;
+ readonly attribute sequence<unrestricted float> axes;
+ readonly attribute sequence<unrestricted float> buttons;
+};
+
diff --git a/Source/WebCore/Modules/gamepad/GamepadList.cpp b/Source/WebCore/Modules/gamepad/deprecated/GamepadList.cpp
index 265022225..22e028867 100644
--- a/Source/WebCore/Modules/gamepad/GamepadList.cpp
+++ b/Source/WebCore/Modules/gamepad/deprecated/GamepadList.cpp
@@ -28,7 +28,7 @@
#include "Gamepad.h"
-#if ENABLE(GAMEPAD)
+#if ENABLE(GAMEPAD_DEPRECATED)
namespace WebCore {
@@ -36,11 +36,11 @@ GamepadList::~GamepadList()
{
}
-void GamepadList::set(unsigned index, PassRefPtr<Gamepad> gamepad)
+void GamepadList::set(unsigned index, RefPtr<Gamepad>&& gamepad)
{
if (index >= kMaximumGamepads)
return;
- m_items[index] = gamepad;
+ m_items[index] = WTFMove(gamepad);
}
unsigned GamepadList::length() const
@@ -55,4 +55,4 @@ Gamepad* GamepadList::item(unsigned index)
} // namespace WebCore
-#endif // ENABLE(GAMEPAD)
+#endif // ENABLE(GAMEPAD_DEPRECATED)
diff --git a/Source/WebCore/Modules/gamepad/GamepadList.h b/Source/WebCore/Modules/gamepad/deprecated/GamepadList.h
index fa6af61da..ab3626b4a 100644
--- a/Source/WebCore/Modules/gamepad/GamepadList.h
+++ b/Source/WebCore/Modules/gamepad/deprecated/GamepadList.h
@@ -23,13 +23,11 @@
* DAMAGE.
*/
-#ifndef GamepadList_h
-#define GamepadList_h
+#pragma once
-#if ENABLE(GAMEPAD)
+#if ENABLE(GAMEPAD_DEPRECATED)
#include "Gamepad.h"
-#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/Vector.h>
@@ -39,10 +37,10 @@ typedef Vector<RefPtr<Gamepad> > GamepadVector;
class GamepadList : public RefCounted<GamepadList> {
public:
- static PassRefPtr<GamepadList> create() { return adoptRef(new GamepadList); }
+ static Ref<GamepadList> create() { return adoptRef(*new GamepadList); }
~GamepadList();
- void set(unsigned index, PassRefPtr<Gamepad>);
+ void set(unsigned index, RefPtr<Gamepad>&&);
Gamepad* item(unsigned index);
unsigned length() const;
@@ -54,6 +52,4 @@ private:
} // namespace WebCore
-#endif // ENABLE(GAMEPAD)
-
-#endif // GamepadList_h
+#endif // ENABLE(GAMEPAD_DEPRECATED)
diff --git a/Source/WebCore/Modules/gamepad/GamepadList.idl b/Source/WebCore/Modules/gamepad/deprecated/GamepadList.idl
index 4b256afef..9ab4c57fe 100644
--- a/Source/WebCore/Modules/gamepad/GamepadList.idl
+++ b/Source/WebCore/Modules/gamepad/deprecated/GamepadList.idl
@@ -25,10 +25,10 @@
[
NoInterfaceObject,
- Conditional=GAMEPAD,
+ Conditional=GAMEPAD_DEPRECATED,
ImplementationLacksVTable,
] interface GamepadList {
readonly attribute unsigned long length;
- getter Gamepad item([Default=Undefined] optional unsigned long index);
+ getter Gamepad item(unsigned long index);
};
diff --git a/Source/WebCore/Modules/gamepad/deprecated/NavigatorGamepad.cpp b/Source/WebCore/Modules/gamepad/deprecated/NavigatorGamepad.cpp
new file mode 100644
index 000000000..2321d5ada
--- /dev/null
+++ b/Source/WebCore/Modules/gamepad/deprecated/NavigatorGamepad.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2011, Google 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 "NavigatorGamepad.h"
+
+#if ENABLE(GAMEPAD_DEPRECATED)
+
+#include "GamepadList.h"
+#include "Gamepads.h"
+#include "Navigator.h"
+
+namespace WebCore {
+
+NavigatorGamepad::NavigatorGamepad()
+{
+}
+
+NavigatorGamepad::~NavigatorGamepad()
+{
+}
+
+const char* NavigatorGamepad::supplementName()
+{
+ return "NavigatorGamepad";
+}
+
+NavigatorGamepad* NavigatorGamepad::from(Navigator* navigator)
+{
+ NavigatorGamepad* supplement = static_cast<NavigatorGamepad*>(Supplement<Navigator>::from(navigator, supplementName()));
+ if (!supplement) {
+ auto newSupplement = std::make_unique<NavigatorGamepad>();
+ supplement = newSupplement.get();
+ provideTo(navigator, supplementName(), WTFMove(newSupplement));
+ }
+ return supplement;
+}
+
+GamepadList* NavigatorGamepad::webkitGetGamepads(Navigator& navigator)
+{
+ return NavigatorGamepad::from(&navigator)->gamepads();
+}
+
+GamepadList* NavigatorGamepad::gamepads()
+{
+ if (!m_gamepads)
+ m_gamepads = GamepadList::create();
+ sampleGamepads(m_gamepads.get());
+ return m_gamepads.get();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD_DEPRECATED)
diff --git a/Source/WebCore/Modules/gamepad/deprecated/NavigatorGamepad.h b/Source/WebCore/Modules/gamepad/deprecated/NavigatorGamepad.h
new file mode 100644
index 000000000..6f57882d8
--- /dev/null
+++ b/Source/WebCore/Modules/gamepad/deprecated/NavigatorGamepad.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2011, Google 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_DEPRECATED)
+
+#include "Supplementable.h"
+
+namespace WebCore {
+
+class GamepadList;
+class Navigator;
+
+class NavigatorGamepad : public Supplement<Navigator> {
+public:
+ NavigatorGamepad();
+ virtual ~NavigatorGamepad();
+
+ static NavigatorGamepad* from(Navigator*);
+
+ static GamepadList* webkitGetGamepads(Navigator&);
+
+ GamepadList* gamepads();
+
+private:
+ static const char* supplementName();
+
+ RefPtr<GamepadList> m_gamepads;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD_DEPRECATED)
diff --git a/Source/WebCore/Modules/gamepad/deprecated/NavigatorGamepad.idl b/Source/WebCore/Modules/gamepad/deprecated/NavigatorGamepad.idl
new file mode 100644
index 000000000..d19d843ef
--- /dev/null
+++ b/Source/WebCore/Modules/gamepad/deprecated/NavigatorGamepad.idl
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+[
+ Conditional=GAMEPAD_DEPRECATED,
+] partial interface Navigator {
+ GamepadList webkitGetGamepads();
+};
+