From 529fd0a65c7b66b43d2aa0d14b3af02c40615784 Mon Sep 17 00:00:00 2001 From: Bastiaan van der Plaat Date: Fri, 24 Nov 2023 17:38:31 +0100 Subject: [PATCH] LibWeb: Add HTML legend element form getter --- .../Libraries/LibWeb/HTML/HTMLLegendElement.cpp | 14 ++++++++++++++ Userland/Libraries/LibWeb/HTML/HTMLLegendElement.h | 2 ++ .../Libraries/LibWeb/HTML/HTMLLegendElement.idl | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLegendElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLLegendElement.cpp index 28cbc7f77e..84362407b9 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLegendElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLLegendElement.cpp @@ -5,6 +5,7 @@ */ #include +#include #include namespace Web::HTML { @@ -24,4 +25,17 @@ void HTMLLegendElement::initialize(JS::Realm& realm) set_prototype(&Bindings::ensure_web_prototype(realm, "HTMLLegendElement"_fly_string)); } +// https://html.spec.whatwg.org/multipage/form-elements.html#dom-legend-form +HTMLFormElement* HTMLLegendElement::form() +{ + // The form IDL attribute's behavior depends on whether the legend element is in a fieldset element or not. + // If the legend has a fieldset element as its parent, then the form IDL attribute must return the same value as the form IDL attribute on that fieldset element. + if (is(parent_element())) { + return verify_cast(parent_element())->form(); + } + + // Otherwise, it must return null. + return nullptr; +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLegendElement.h b/Userland/Libraries/LibWeb/HTML/HTMLLegendElement.h index a54a833920..4bf0350e50 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLegendElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLLegendElement.h @@ -17,6 +17,8 @@ class HTMLLegendElement final : public HTMLElement { public: virtual ~HTMLLegendElement() override; + HTMLFormElement* form(); + private: HTMLLegendElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLegendElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLLegendElement.idl index 392420876a..aeef2c1d59 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLegendElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLLegendElement.idl @@ -5,7 +5,7 @@ interface HTMLLegendElement : HTMLElement { [HTMLConstructor] constructor(); - // FIXME: readonly attribute HTMLFormElement? form; + readonly attribute HTMLFormElement? form; // Obsolete [CEReactions, Reflect] attribute DOMString align;