LibWeb: Implement the Gamepad API with SDL3

This commit is contained in:
Luke Wilde 2025-08-18 17:27:00 +01:00 committed by Andreas Kling
parent 50dcd8fc85
commit 74e0483ea5
Notes: github-actions[bot] 2025-09-01 19:11:57 +00:00
36 changed files with 1848 additions and 50 deletions

View file

@ -179,6 +179,8 @@ namespace AttributeNames {
__ENUMERATE_HTML_ATTRIBUTE(onfocusin, "onfocusin") \
__ENUMERATE_HTML_ATTRIBUTE(onfocusout, "onfocusout") \
__ENUMERATE_HTML_ATTRIBUTE(onformdata, "onformdata") \
__ENUMERATE_HTML_ATTRIBUTE(ongamepadconnected, "ongamepadconnected") \
__ENUMERATE_HTML_ATTRIBUTE(ongamepaddisconnected, "ongamepaddisconnected") \
__ENUMERATE_HTML_ATTRIBUTE(ongotpointercapture, "ongotpointercapture") \
__ENUMERATE_HTML_ATTRIBUTE(onhashchange, "onhashchange") \
__ENUMERATE_HTML_ATTRIBUTE(oninput, "oninput") \

View file

@ -296,6 +296,8 @@ void EventLoop::process_input_events() const
page_client.report_finished_handling_input_event(event.page_id, EventResult::Dropped);
page_client.report_finished_handling_input_event(event.page_id, result);
}
page.handle_sdl_input_events();
};
auto documents_of_traversable_navigables = documents_in_this_event_loop_matching([&](auto const& document) {

View file

@ -81,6 +81,9 @@ public:
// https://w3c.github.io/media-capabilities/#media-capabilities-task-source
MediaCapabilities,
// https://w3c.github.io/gamepad/#dfn-gamepad-task-source
Gamepad,
// !!! IMPORTANT: Keep this field last!
// This serves as the base value of all unique task sources.
// Some elements, such as the HTMLMediaElement, must have a unique task source per instance.

View file

@ -10,6 +10,7 @@
#include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Gamepad/EventNames.h>
#include <LibWeb/HTML/HTMLBodyElement.h>
#include <LibWeb/HTML/Numbers.h>
#include <LibWeb/HTML/Parser/HTMLParser.h>

View file

@ -8,6 +8,7 @@
#include <LibWeb/CSS/ComputedProperties.h>
#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Gamepad/EventNames.h>
#include <LibWeb/HTML/HTMLFrameSetElement.h>
#include <LibWeb/HTML/Window.h>

View file

@ -41,6 +41,7 @@ void Navigator::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(Navigator);
Base::initialize(realm);
NavigatorGamepadPartial::check_for_connected_gamepads();
}
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-pdfviewerenabled
@ -65,6 +66,7 @@ bool Navigator::webdriver() const
void Navigator::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
NavigatorGamepadPartial::visit_edges(visitor);
visitor.visit(m_mime_type_array);
visitor.visit(m_plugin_array);
visitor.visit(m_clipboard);

View file

@ -1,10 +1,11 @@
/*
* Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
* Copyright (c) 2022-2025, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/Gamepad/EventNames.h>
#include <LibWeb/HTML/EventNames.h>
#include <LibWeb/HTML/WindowEventHandlers.h>

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
* Copyright (c) 2022-2025, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -9,24 +9,26 @@
#include <AK/Forward.h>
#include <LibWeb/Forward.h>
#define ENUMERATE_WINDOW_EVENT_HANDLERS(E) \
E(onafterprint, HTML::EventNames::afterprint) \
E(onbeforeprint, HTML::EventNames::beforeprint) \
E(onbeforeunload, HTML::EventNames::beforeunload) \
E(onhashchange, HTML::EventNames::hashchange) \
E(onlanguagechange, HTML::EventNames::languagechange) \
E(onmessage, HTML::EventNames::message) \
E(onmessageerror, HTML::EventNames::messageerror) \
E(onoffline, HTML::EventNames::offline) \
E(ononline, HTML::EventNames::online) \
E(onpagehide, HTML::EventNames::pagehide) \
E(onpagereveal, HTML::EventNames::pagereveal) \
E(onpageshow, HTML::EventNames::pageshow) \
E(onpageswap, HTML::EventNames::pageswap) \
E(onpopstate, HTML::EventNames::popstate) \
E(onrejectionhandled, HTML::EventNames::rejectionhandled) \
E(onstorage, HTML::EventNames::storage) \
E(onunhandledrejection, HTML::EventNames::unhandledrejection) \
#define ENUMERATE_WINDOW_EVENT_HANDLERS(E) \
E(onafterprint, HTML::EventNames::afterprint) \
E(onbeforeprint, HTML::EventNames::beforeprint) \
E(onbeforeunload, HTML::EventNames::beforeunload) \
E(ongamepadconnected, Gamepad::EventNames::gamepadconnected) \
E(ongamepaddisconnected, Gamepad::EventNames::gamepaddisconnected) \
E(onhashchange, HTML::EventNames::hashchange) \
E(onlanguagechange, HTML::EventNames::languagechange) \
E(onmessage, HTML::EventNames::message) \
E(onmessageerror, HTML::EventNames::messageerror) \
E(onoffline, HTML::EventNames::offline) \
E(ononline, HTML::EventNames::online) \
E(onpagehide, HTML::EventNames::pagehide) \
E(onpagereveal, HTML::EventNames::pagereveal) \
E(onpageshow, HTML::EventNames::pageshow) \
E(onpageswap, HTML::EventNames::pageswap) \
E(onpopstate, HTML::EventNames::popstate) \
E(onrejectionhandled, HTML::EventNames::rejectionhandled) \
E(onstorage, HTML::EventNames::storage) \
E(onunhandledrejection, HTML::EventNames::unhandledrejection) \
E(onunload, HTML::EventNames::unload)
namespace Web::HTML {