From daefe744ba7ab10515c8b56303dc16b4569730ca Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 20 Aug 2023 14:39:57 +1200 Subject: [PATCH] LibWeb: Implement RadioNodeList This interface is used in the interface for HTMLFormControlsCollection as a live view over its matching elements. Currently the "value" attribute for this interface is left unimplemented. --- .../BindingsGenerator/IDLGenerators.cpp | 1 + Userland/Libraries/LibWeb/CMakeLists.txt | 1 + .../Libraries/LibWeb/DOM/RadioNodeList.cpp | 32 +++++++++++++++++++ Userland/Libraries/LibWeb/DOM/RadioNodeList.h | 29 +++++++++++++++++ .../Libraries/LibWeb/DOM/RadioNodeList.idl | 7 ++++ Userland/Libraries/LibWeb/Forward.h | 3 +- Userland/Libraries/LibWeb/idl_files.cmake | 1 + 7 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 Userland/Libraries/LibWeb/DOM/RadioNodeList.cpp create mode 100644 Userland/Libraries/LibWeb/DOM/RadioNodeList.h create mode 100644 Userland/Libraries/LibWeb/DOM/RadioNodeList.idl diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index ca175163ee3..7f4316f285b 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -50,6 +50,7 @@ static bool is_platform_object(Type const& type) "PerformanceMark"sv, "ReadableStreamBYOBReader"sv, "ReadableStreamDefaultReader"sv, + "RadioNodeList"sv, "Range"sv, "ReadableStream"sv, "Request"sv, diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 5f55da32ad3..423da95deff 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -168,6 +168,7 @@ set(SOURCES DOM/Position.cpp DOM/ProcessingInstruction.cpp DOM/QualifiedName.cpp + DOM/RadioNodeList.cpp DOM/Range.cpp DOM/ShadowRoot.cpp DOM/StaticNodeList.cpp diff --git a/Userland/Libraries/LibWeb/DOM/RadioNodeList.cpp b/Userland/Libraries/LibWeb/DOM/RadioNodeList.cpp new file mode 100644 index 00000000000..28280644107 --- /dev/null +++ b/Userland/Libraries/LibWeb/DOM/RadioNodeList.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +namespace Web::DOM { + +JS::NonnullGCPtr RadioNodeList::create(JS::Realm& realm, Node& root, Scope scope, Function filter) +{ + return realm.heap().allocate(realm, realm, root, scope, move(filter)); +} + +RadioNodeList::RadioNodeList(JS::Realm& realm, Node& root, Scope scope, Function filter) + : LiveNodeList(realm, root, scope, move(filter)) +{ +} + +RadioNodeList::~RadioNodeList() = default; + +void RadioNodeList::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "RadioNodeList")); +} + +} diff --git a/Userland/Libraries/LibWeb/DOM/RadioNodeList.h b/Userland/Libraries/LibWeb/DOM/RadioNodeList.h new file mode 100644 index 00000000000..cd2cb0d2027 --- /dev/null +++ b/Userland/Libraries/LibWeb/DOM/RadioNodeList.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::DOM { + +// https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#radionodelist +class RadioNodeList : public LiveNodeList { + WEB_PLATFORM_OBJECT(RadioNodeList, LiveNodeList); + +public: + [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm& realm, Node& root, Scope scope, Function filter); + + virtual ~RadioNodeList() override; + +protected: + virtual void initialize(JS::Realm&) override; + +private: + explicit RadioNodeList(JS::Realm& realm, Node& root, Scope scope, Function filter); +}; + +} diff --git a/Userland/Libraries/LibWeb/DOM/RadioNodeList.idl b/Userland/Libraries/LibWeb/DOM/RadioNodeList.idl new file mode 100644 index 00000000000..66a6ffc47a7 --- /dev/null +++ b/Userland/Libraries/LibWeb/DOM/RadioNodeList.idl @@ -0,0 +1,7 @@ +#import + +// https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#radionodelist +[Exposed=Window, UseNewAKString] +interface RadioNodeList : NodeList { + // FIXME: attribute DOMString value; +}; diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 791a3fa8d88..de79e66af15 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2020-2023, Andreas Kling - * Copyright (c) 2021, the SerenityOS developers. + * Copyright (c) 2021-2023, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -238,6 +238,7 @@ class ParentNode; class Position; class ProcessingInstruction; class Range; +class RadioNodeList; class RegisteredObserver; class ShadowRoot; class StaticNodeList; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 473fe9308ca..8f6693fa3cc 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -50,6 +50,7 @@ libweb_js_bindings(DOM/NodeFilter) libweb_js_bindings(DOM/NodeIterator) libweb_js_bindings(DOM/NodeList) libweb_js_bindings(DOM/ProcessingInstruction) +libweb_js_bindings(DOM/RadioNodeList) libweb_js_bindings(DOM/Range) libweb_js_bindings(DOM/ShadowRoot) libweb_js_bindings(DOM/StaticRange)