IDL changes for gamepad support
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 19 Nov 2011 02:03:15 +0000 (02:03 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 19 Nov 2011 02:03:15 +0000 (02:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=71753

Patch by Scott Graham <scottmg@chromium.org> on 2011-11-18
Reviewed by Adam Barth.

Source/WebCore:

IDL changes and associated plumbing to expose list of gamepad objects
on navigator object (per current spec). Full patch is
https://bugs.webkit.org/show_bug.cgi?id=69451. Only basic existence
test until more plumbing in future patches.

Test: gamepad/gamepad-api.html

* WebCore.gypi:
* bindings/generic/RuntimeEnabledFeatures.h:
(WebCore::RuntimeEnabledFeatures::setWebkitGamepadsEnabled):
(WebCore::RuntimeEnabledFeatures::webkitGamepadsEnabled):
* page/Gamepad.cpp: Added.
(WebCore::Gamepad::Gamepad):
(WebCore::Gamepad::axes):
(WebCore::Gamepad::buttons):
(WebCore::Gamepad::~Gamepad):
* page/Gamepad.h: Added.
* page/Gamepad.idl: Added.
* page/GamepadList.cpp: Added.
(WebCore::GamepadList::~GamepadList):
(WebCore::GamepadList::set):
(WebCore::GamepadList::length):
(WebCore::GamepadList::item):
* page/GamepadList.h: Added.
(WebCore::GamepadList::create):
(WebCore::GamepadList::GamepadList):
* page/GamepadList.idl: Added.
* page/Navigator.cpp:
(WebCore::Navigator::webkitGamepads):
* page/Navigator.h:
* page/Navigator.idl:

Source/WebKit/chromium:

Update to use vendor-prefixed enable.

* src/WebRuntimeFeatures.cpp:
(WebKit::WebRuntimeFeatures::enableGamepad):
(WebKit::WebRuntimeFeatures::isGamepadEnabled):

Tools:

Runtime enable gamepad in chromium test shell.

* DumpRenderTree/chromium/TestShell.cpp:
(TestShell::TestShell):

LayoutTests:

Add basic api existence test.

* gamepad/gamepad-api-expected.txt: Added.
* gamepad/gamepad-api.html: Added.
* gamepad/gamepad-test.js: Added.
(logConsole):
(testExpected):
(reportExpected):
(waitForEventAndEnd):
(waitForEvent._eventCallback):
(waitForEvent):
(waitForEventAndTest._eventCallback):
(waitForEventAndTest):
(waitForEventTestAndEnd):
(endTest):
(logResult):
(consoleWrite):
* platform/chromium/fast/dom/navigator-detached-no-crash-expected.txt:
* platform/efl/Skipped:
* platform/gtk/Skipped:
* platform/mac/Skipped:
* platform/qt/Skipped:
* platform/win/Skipped:
* platform/wincairo/Skipped:

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

27 files changed:
LayoutTests/ChangeLog
LayoutTests/gamepad/gamepad-api-expected.txt [new file with mode: 0644]
LayoutTests/gamepad/gamepad-api.html [new file with mode: 0644]
LayoutTests/gamepad/gamepad-test.js [new file with mode: 0644]
LayoutTests/platform/chromium/fast/dom/navigator-detached-no-crash-expected.txt
LayoutTests/platform/efl/Skipped
LayoutTests/platform/gtk/Skipped
LayoutTests/platform/mac/Skipped
LayoutTests/platform/qt/Skipped
LayoutTests/platform/win/Skipped
LayoutTests/platform/wincairo/Skipped
Source/WebCore/ChangeLog
Source/WebCore/WebCore.gypi
Source/WebCore/bindings/generic/RuntimeEnabledFeatures.h
Source/WebCore/page/Gamepad.cpp [new file with mode: 0644]
Source/WebCore/page/Gamepad.h [new file with mode: 0644]
Source/WebCore/page/Gamepad.idl [new file with mode: 0644]
Source/WebCore/page/GamepadList.cpp [new file with mode: 0644]
Source/WebCore/page/GamepadList.h [new file with mode: 0644]
Source/WebCore/page/GamepadList.idl [new file with mode: 0644]
Source/WebCore/page/Navigator.cpp
Source/WebCore/page/Navigator.h
Source/WebCore/page/Navigator.idl
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/WebRuntimeFeatures.cpp
Tools/ChangeLog
Tools/DumpRenderTree/chromium/TestShell.cpp

index 4bcf9ed7192bb5f2fb3ab1e91dd67efcc876c41f..a58bda2b5e5c94900396c8043726262d20ab96b0 100644 (file)
@@ -1,3 +1,35 @@
+2011-11-18  Scott Graham  <scottmg@chromium.org>
+
+        IDL changes for gamepad support
+        https://bugs.webkit.org/show_bug.cgi?id=71753
+
+        Reviewed by Adam Barth.
+
+        Add basic api existence test.
+
+        * gamepad/gamepad-api-expected.txt: Added.
+        * gamepad/gamepad-api.html: Added.
+        * gamepad/gamepad-test.js: Added.
+        (logConsole):
+        (testExpected):
+        (reportExpected):
+        (waitForEventAndEnd):
+        (waitForEvent._eventCallback):
+        (waitForEvent):
+        (waitForEventAndTest._eventCallback):
+        (waitForEventAndTest):
+        (waitForEventTestAndEnd):
+        (endTest):
+        (logResult):
+        (consoleWrite):
+        * platform/chromium/fast/dom/navigator-detached-no-crash-expected.txt:
+        * platform/efl/Skipped:
+        * platform/gtk/Skipped:
+        * platform/mac/Skipped:
+        * platform/qt/Skipped:
+        * platform/win/Skipped:
+        * platform/wincairo/Skipped:
+
 2011-11-18  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r100693.
diff --git a/LayoutTests/gamepad/gamepad-api-expected.txt b/LayoutTests/gamepad/gamepad-api-expected.txt
new file mode 100644 (file)
index 0000000..d900ebf
--- /dev/null
@@ -0,0 +1,3 @@
+EXPECTED (navigator.webkitGamepads !== 'undefined') OK
+END OF TEST
+Make sure the main polling access point exists on navigator.
diff --git a/LayoutTests/gamepad/gamepad-api.html b/LayoutTests/gamepad/gamepad-api.html
new file mode 100644 (file)
index 0000000..b5f0e34
--- /dev/null
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<body>
+<script src="gamepad-test.js"></script>
+<script>
+    testExpected("navigator.webkitGamepads", undefined, "!==");
+    endTest();
+</script>
+<p>Make sure the main polling access point exists on navigator.</p>
+</body>
diff --git a/LayoutTests/gamepad/gamepad-test.js b/LayoutTests/gamepad/gamepad-test.js
new file mode 100644 (file)
index 0000000..261b4f3
--- /dev/null
@@ -0,0 +1,126 @@
+var console = null;
+var printFullTestDetails = true; // This is optionaly switched of by test whose tested values can differ. (see disableFullTestDetailsPrinting())
+
+logConsole();
+
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+}
+
+function logConsole()
+{
+    if (!console && document.body) {
+        console = document.createElement('div');
+        document.body.appendChild(console);
+    }
+    return console;
+}
+
+function testExpected(testFuncString, expected, comparison)
+{
+    try {
+        var observed = eval(testFuncString);
+    } catch (ex) {
+        consoleWrite(ex);
+        return;
+    }
+
+    if (comparison === undefined)
+        comparison = '==';
+
+    var success = false;
+    switch (comparison)
+    {
+        case '<':  success = observed <  expected; break;
+        case '<=': success = observed <= expected; break;
+        case '>':  success = observed >  expected; break;
+        case '>=': success = observed >= expected; break;
+        case '!=': success = observed != expected; break;
+        case '!==': success = observed !== expected; break;
+        case '==': success = observed == expected; break;
+        case '===': success = observed === expected; break;
+    }
+
+    reportExpected(success, testFuncString, comparison, expected, observed)
+}
+
+var testNumber = 0;
+
+function reportExpected(success, testFuncString, comparison, expected, observed)
+{
+    testNumber++;
+
+    var msg = "Test " + testNumber;
+
+    if (printFullTestDetails || !success)
+        msg = "EXPECTED (<em>" + testFuncString + " </em>" + comparison + " '<em>" + expected + "</em>')";
+
+    if (!success)
+        msg +=  ", OBSERVED '<em>" + observed + "</em>'";
+
+    logResult(success, msg);
+}
+
+function waitForEventAndEnd(element, eventName, funcString)
+{
+    waitForEvent(element, eventName, funcString, true)
+}
+
+function waitForEvent(element, eventName, func, endit)
+{
+    function _eventCallback(event)
+    {
+        consoleWrite("EVENT(" + eventName + ")");
+
+        if (func)
+            func(event);
+
+        if (endit)
+            endTest();
+    }
+
+    element.addEventListener(eventName, _eventCallback);
+}
+
+function waitForEventAndTest(element, eventName, testFuncString, endit)
+{
+    function _eventCallback(event)
+    {
+        logResult(eval(testFuncString), "EVENT(" + eventName + ") TEST(" + testFuncString + ")");
+        if (endit)
+            endTest();
+    }
+
+    element.addEventListener(eventName, _eventCallback);
+}
+
+function waitForEventTestAndEnd(element, eventName, testFuncString)
+{
+    waitForEventAndTest(element, eventName, testFuncString, true);
+}
+
+var testEnded = false;
+
+function endTest()
+{
+    consoleWrite("END OF TEST");
+    testEnded = true;
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+}
+
+function logResult(success, text)
+{
+    if (success)
+        consoleWrite(text + " <span style='color:green'>OK</span>");
+    else
+        consoleWrite(text + " <span style='color:red'>FAIL</span>");
+}
+
+function consoleWrite(text)
+{
+    if (testEnded)
+        return;
+    logConsole().innerHTML += text + "<br>";
+}
index 75425a1f78a39818c3d155183c21ca07c5cf7b8f..70973b2baa56fb13852e902188d7da8bb80ffaf6 100644 (file)
@@ -17,6 +17,7 @@ navigator.registerProtocolHandler() threw err TypeError: Not enough arguments
 navigator.userAgent is OK
 navigator.vendor is OK
 navigator.vendorSub is OK
+navigator.webkitGamepads is OK
 navigator.appCodeName is OK
 navigator.appName is OK
 navigator.appVersion is OK
@@ -34,4 +35,5 @@ navigator.registerProtocolHandler() threw err TypeError: Not enough arguments
 navigator.userAgent is OK
 navigator.vendor is OK
 navigator.vendorSub is OK
+navigator.webkitGamepads is OK
 
index 5f81443270eca019e42fd7f899f375f65f6c803a..d56499c93a6e0ee659086e59cbaeccb9680c8b52 100644 (file)
@@ -1909,6 +1909,9 @@ fast/forms/month
 fast/forms/time
 fast/forms/week
 
+# ENABLE_GAMEPAD not enabled.
+gamepad/
+
 # MutationObservers are net yet enabled. http://webkit.org/b/68729
 fast/mutation
 
index 5d8cbbc1b9ffb6946ece164470b425cde3218935..8e3399de9f3b2b2b43524737807de8f0d32785d8 100644 (file)
@@ -258,6 +258,9 @@ fast/forms/month
 fast/forms/time
 fast/forms/week
 
+# ENABLE_GAMEPAD not enabled.
+gamepad/
+
 # Speech input is not yet enabled.
 fast/speech
 
index 0d013818974ec6aee7ccaa48cf2dcb0c7ba34776..4ff78567dce614bcb3bdff25fb7f74f6a6f11920 100644 (file)
@@ -214,6 +214,9 @@ fast/forms/month
 fast/forms/time
 fast/forms/week
 
+# ENABLE_GAMEPAD not enabled.
+gamepad/
+
 # Speech input is not yet enabled.
 fast/speech
 
index 2bc3ef66f3ae5dd1b7b1bbfbf1a1b1032c6025e1..adaebce9c2a6cfba86229fdce39398f8688dadbb 100644 (file)
@@ -89,6 +89,9 @@ fast/forms/month
 fast/forms/time
 fast/forms/week
 
+# ENABLE_GAMEPAD not enabled.
+gamepad/
+
 # ENABLE(INPUT_SPEECH) is disabled.
 fast/speech
 
index 28a530c7cf03f287fe75b2ad427ec9f1415b02b4..4c34b493e5705d5f84f24efcf49cdab3ebf2df40 100644 (file)
@@ -1122,6 +1122,9 @@ fast/forms/month
 fast/forms/time
 fast/forms/week
 
+# ENABLE_GAMEPAD not enabled.
+gamepad/
+
 # Speech input is not yet enabled.
 fast/speech
 
index 86a447c0d9d53511543272b1b168b9ff2ebcad5f..6ba23098134610cf78bd382120908bb16cd1c7a4 100644 (file)
@@ -1639,6 +1639,9 @@ fast/forms/month
 fast/forms/time
 fast/forms/week
 
+# ENABLE_GAMEPAD not enabled.
+gamepad/
+
 # Speech input is not yet enabled.
 fast/speech
 
index 89957a0d6c0708f41c329546262f6f631a1bb44b..65c65cd24ba6bd02f26082df294e3451760eca8d 100644 (file)
@@ -1,3 +1,42 @@
+2011-11-18  Scott Graham  <scottmg@chromium.org>
+
+        IDL changes for gamepad support
+        https://bugs.webkit.org/show_bug.cgi?id=71753
+
+        Reviewed by Adam Barth.
+
+        IDL changes and associated plumbing to expose list of gamepad objects
+        on navigator object (per current spec). Full patch is
+        https://bugs.webkit.org/show_bug.cgi?id=69451. Only basic existence
+        test until more plumbing in future patches.
+
+        Test: gamepad/gamepad-api.html
+
+        * WebCore.gypi:
+        * bindings/generic/RuntimeEnabledFeatures.h:
+        (WebCore::RuntimeEnabledFeatures::setWebkitGamepadsEnabled):
+        (WebCore::RuntimeEnabledFeatures::webkitGamepadsEnabled):
+        * page/Gamepad.cpp: Added.
+        (WebCore::Gamepad::Gamepad):
+        (WebCore::Gamepad::axes):
+        (WebCore::Gamepad::buttons):
+        (WebCore::Gamepad::~Gamepad):
+        * page/Gamepad.h: Added.
+        * page/Gamepad.idl: Added.
+        * page/GamepadList.cpp: Added.
+        (WebCore::GamepadList::~GamepadList):
+        (WebCore::GamepadList::set):
+        (WebCore::GamepadList::length):
+        (WebCore::GamepadList::item):
+        * page/GamepadList.h: Added.
+        (WebCore::GamepadList::create):
+        (WebCore::GamepadList::GamepadList):
+        * page/GamepadList.idl: Added.
+        * page/Navigator.cpp:
+        (WebCore::Navigator::webkitGamepads):
+        * page/Navigator.h:
+        * page/Navigator.idl:
+
 2011-11-18  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r100693.
index 88d456c43306f5ead1920030d14037d57b188832..1f5268e284c68ffec7c92230368e6c43419614c4 100644 (file)
             'page/DOMSelection.idl',
             'page/DOMWindow.idl',
             'page/EventSource.idl',
+            'page/Gamepad.idl',
+            'page/GamepadList.idl',
             'page/Geolocation.idl',
             'page/Geoposition.idl',
             'page/History.idl',
             'page/FrameActionScheduler.h',
             'page/FrameTree.cpp',
             'page/FrameView.cpp',
+            'page/Gamepad.cpp',
+            'page/Gamepad.h',
+            'page/GamepadList.cpp',
+            'page/GamepadList.h',
             'page/Geolocation.cpp',
             'page/GeolocationController.cpp',
             'page/GroupSettings.cpp',
index 9ff2bfc6ad335f80a79071d74e2fb01255255934..ce2ee439c72a8af58444e429420636bea981d98c 100644 (file)
@@ -172,8 +172,8 @@ public:
 #endif
 
 #if ENABLE(GAMEPAD)
-    static void setGamepadsEnabled(bool isEnabled) { isGamepadEnabled = isEnabled; }
-    static bool gamepadsEnabled() { return isGamepadEnabled; }
+    static void setWebkitGamepadsEnabled(bool isEnabled) { isGamepadEnabled = isEnabled; }
+    static bool webkitGamepadsEnabled() { return isGamepadEnabled; }
 #endif
 
 #if ENABLE(QUOTA)
diff --git a/Source/WebCore/page/Gamepad.cpp b/Source/WebCore/page/Gamepad.cpp
new file mode 100644 (file)
index 0000000..05ed18d
--- /dev/null
@@ -0,0 +1,55 @@
+// 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)
+
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+Gamepad::Gamepad()
+{
+}
+
+void Gamepad::axes(unsigned count, float* data)
+{
+    m_axes.resize(count);
+    std::copy(data, data + count, m_axes.begin());
+}
+
+void Gamepad::buttons(unsigned count, float* data)
+{
+    m_buttons.resize(count);
+    std::copy(data, data + count, m_buttons.begin());
+}
+
+Gamepad::~Gamepad()
+{
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD)
diff --git a/Source/WebCore/page/Gamepad.h b/Source/WebCore/page/Gamepad.h
new file mode 100644 (file)
index 0000000..6f3b077
--- /dev/null
@@ -0,0 +1,73 @@
+// 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.
+
+#ifndef Gamepad_h
+#define Gamepad_h
+
+#if ENABLE(GAMEPAD)
+
+#include <wtf/RefCounted.h>
+#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class Gamepad: public RefCounted<Gamepad> {
+public:
+    static PassRefPtr<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)
+
+#endif // Gamepad_h
diff --git a/Source/WebCore/page/Gamepad.idl b/Source/WebCore/page/Gamepad.idl
new file mode 100644 (file)
index 0000000..2149b05
--- /dev/null
@@ -0,0 +1,36 @@
+// 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.
+
+module dom {
+
+    interface [
+        Conditional=GAMEPAD
+    ] Gamepad {
+        readonly attribute DOMString id;
+        readonly attribute unsigned long index;
+        readonly attribute unsigned long long timestamp;
+        readonly attribute float[] axes;
+        readonly attribute float[] buttons;
+    };
+
+}
diff --git a/Source/WebCore/page/GamepadList.cpp b/Source/WebCore/page/GamepadList.cpp
new file mode 100644 (file)
index 0000000..16934ed
--- /dev/null
@@ -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.
+
+#include "config.h"
+#include "GamepadList.h"
+
+#include "Gamepad.h"
+
+#if ENABLE(GAMEPAD)
+
+namespace WebCore {
+
+GamepadList::~GamepadList()
+{
+}
+
+void GamepadList::set(unsigned index, PassRefPtr<Gamepad> gamepad)
+{
+    if (index >= kMaximumGamepads)
+        return;
+    m_items[index] = gamepad;
+}
+
+unsigned GamepadList::length() const
+{
+    return kMaximumGamepads;
+}
+
+Gamepad* GamepadList::item(unsigned index)
+{
+    return index < length() ? m_items[index].get() : 0;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD)
diff --git a/Source/WebCore/page/GamepadList.h b/Source/WebCore/page/GamepadList.h
new file mode 100644 (file)
index 0000000..233f8fe
--- /dev/null
@@ -0,0 +1,57 @@
+// 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.
+
+#ifndef GamepadList_h
+#define GamepadList_h
+
+#if ENABLE(GAMEPAD)
+
+#include "Gamepad.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+typedef Vector<RefPtr<Gamepad> > GamepadVector;
+
+class GamepadList : public RefCounted<GamepadList> {
+public:
+    static PassRefPtr<GamepadList> create() { return adoptRef(new GamepadList); }
+    ~GamepadList();
+
+    void set(unsigned index, PassRefPtr<Gamepad>);
+    Gamepad* item(unsigned index);
+    unsigned length() const;
+
+private:
+    enum { kMaximumGamepads = 4 };
+    GamepadList() { }
+    RefPtr<Gamepad> m_items[kMaximumGamepads];
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD)
+
+#endif // GamepadList_h
diff --git a/Source/WebCore/page/GamepadList.idl b/Source/WebCore/page/GamepadList.idl
new file mode 100644 (file)
index 0000000..242b815
--- /dev/null
@@ -0,0 +1,34 @@
+// 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.
+
+module dom {
+
+    interface [
+        Conditional=GAMEPAD,
+        HasIndexGetter
+    ] GamepadList {
+        readonly attribute unsigned long length;
+        Gamepad item(in [Optional=CallWithDefaultValue] unsigned long index);
+    };
+
+}
index 105209841b8a1f70688454000a4327303ff995b4..f3be0cc48fa4867412367e74dd75173b7a8f8ac5 100644 (file)
@@ -32,6 +32,7 @@
 #include "Frame.h"
 #include "FrameLoader.h"
 #include "FrameLoaderClient.h"
+#include "GamepadList.h"
 #include "Geolocation.h"
 #include "PointerLock.h"
 #include "KURL.h"
@@ -304,4 +305,12 @@ void Navigator::webkitGetUserMedia(const String& options, PassRefPtr<NavigatorUs
 }
 #endif
 
+#if ENABLE(GAMEPAD)
+GamepadList* Navigator::webkitGamepads()
+{
+    // Stubbed until platform/ changes landed.
+    return 0;
+}
+#endif
+
 } // namespace WebCore
index 49c5488c5b238d06afb7e541da5e9219e36a37d7..5babdc5dd8f2f9dc25a9100cd2bf5fff7ebbfeae 100644 (file)
@@ -31,6 +31,7 @@ namespace WebCore {
 class DOMMimeTypeArray;
 class DOMPluginArray;
 class Frame;
+class GamepadList;
 class Geolocation;
 class PointerLock;
 class NavigatorUserMediaErrorCallback;
@@ -74,6 +75,10 @@ public:
     virtual void webkitGetUserMedia(const String& options, PassRefPtr<NavigatorUserMediaSuccessCallback>, PassRefPtr<NavigatorUserMediaErrorCallback>, ExceptionCode&);
 #endif
 
+#if ENABLE(GAMEPAD)
+    GamepadList* webkitGamepads();
+#endif
+
 private:
     Navigator(Frame*);
     Frame* m_frame;
index 6fe43e660a85073314853f58161317a6dbfa2385..0847c8c44ac5230d82c5e4a21656d4199968268e 100644 (file)
@@ -61,6 +61,8 @@ module window {
                                                            in [Callback=FunctionOnly, Optional] NavigatorUserMediaErrorCallback errorCallback)
             raises(DOMException);
 #endif
+
+        readonly attribute [Conditional=GAMEPAD, EnabledAtRuntime] GamepadList webkitGamepads;
     };
 
 }
index 779ddbd75822dacc2bfe0b971073bb1a8c6b8d33..5e4688ba642e25f7326ccef54b8d5577776cdf74 100644 (file)
@@ -1,3 +1,16 @@
+2011-11-18  Scott Graham  <scottmg@chromium.org>
+
+        IDL changes for gamepad support
+        https://bugs.webkit.org/show_bug.cgi?id=71753
+
+        Reviewed by Adam Barth.
+
+        Update to use vendor-prefixed enable.
+
+        * src/WebRuntimeFeatures.cpp:
+        (WebKit::WebRuntimeFeatures::enableGamepad):
+        (WebKit::WebRuntimeFeatures::isGamepadEnabled):
+
 2011-11-18  Daniel Cheng  <dcheng@chromium.org>
 
         [chromium] Use correct backing store for ChromiumDataObject in pasteboard writes.
index 128a6fae18efc3123a8f83a027661e31bc4188f8..675e2a2d15c50a3930f461114bfcf26221971f6a 100644 (file)
@@ -417,7 +417,7 @@ bool WebRuntimeFeatures::isVideoTrackEnabled()
 void WebRuntimeFeatures::enableGamepad(bool enable)
 {
 #if ENABLE(GAMEPAD)
-    RuntimeEnabledFeatures::setGamepadsEnabled(enable);
+    RuntimeEnabledFeatures::setWebkitGamepadsEnabled(enable);
 #else
     UNUSED_PARAM(enable);
 #endif
@@ -426,7 +426,7 @@ void WebRuntimeFeatures::enableGamepad(bool enable)
 bool WebRuntimeFeatures::isGamepadEnabled()
 {
 #if ENABLE(GAMEPAD)
-    return RuntimeEnabledFeatures::gamepadsEnabled();
+    return RuntimeEnabledFeatures::webkitGamepadsEnabled();
 #else
     return false;
 #endif
index 7d1f760f59037ac868c713820faba9d65cc58c56..58c57a36808f72c4de13c3203b149b15380b21dc 100644 (file)
@@ -1,3 +1,15 @@
+2011-11-18  Scott Graham  <scottmg@chromium.org>
+
+        IDL changes for gamepad support
+        https://bugs.webkit.org/show_bug.cgi?id=71753
+
+        Reviewed by Adam Barth.
+
+        Runtime enable gamepad in chromium test shell.
+
+        * DumpRenderTree/chromium/TestShell.cpp:
+        (TestShell::TestShell):
+
 2011-10-27  Darin Fisher  <darin@chromium.org>
 
         [chromium] Improve fullscreen API
index cb1e219b0766b8b909e63c0d8db012c328fbd498..8507f24c02233bcd108811f0bc717b563de7cf08 100644 (file)
@@ -122,6 +122,7 @@ TestShell::TestShell(bool testShellMode)
     WebRuntimeFeatures::enableMediaStream(true);
     WebRuntimeFeatures::enableWebAudio(true); 
     WebRuntimeFeatures::enableVideoTrack(true);
+    WebRuntimeFeatures::enableGamepad(true);
 
     m_webPermissions = adoptPtr(new WebPermissions(this));
     m_accessibilityController = adoptPtr(new AccessibilityController(this));