LibWeb: Implement the HTMLFormElement.relList attribute

This returns a DOMTokenList that reflects the `rel` attribute.
This commit is contained in:
Tim Ledbetter
2024-05-16 06:02:56 +01:00
committed by Andreas Kling
parent 0a3e1846f0
commit fc4e0cf10e
5 changed files with 33 additions and 1 deletions

View File

@@ -10,3 +10,9 @@ area.relList for after setting rel to "whatever": whatever
area.relList for after setting rel to "prefetch": prefetch
area.relList contains "prefetch": true
area.relList contains "whatever": false
form.relList initial length: 0
form.relList always returns the same value: true
form.relList for after setting rel to "whatever": whatever
form.relList for after setting rel to "prefetch": prefetch
form.relList contains "prefetch": true
form.relList contains "whatever": false

View File

@@ -18,6 +18,7 @@
const tagNamesToTest = [
"a",
"area",
"form",
];
for (const tagName of tagNamesToTest) {

View File

@@ -11,6 +11,7 @@
#include <LibTextCodec/Decoder.h>
#include <LibWeb/Bindings/ExceptionOrUtils.h>
#include <LibWeb/Bindings/HTMLFormElementPrototype.h>
#include <LibWeb/DOM/DOMTokenList.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/HTMLFormControlsCollection.h>
@@ -584,6 +585,15 @@ StringView HTMLFormElement::method() const
VERIFY_NOT_REACHED();
}
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-rellist
JS::GCPtr<DOM::DOMTokenList> HTMLFormElement::rel_list()
{
// The relList IDL attribute must reflect the rel content attribute.
if (!m_rel_list)
m_rel_list = DOM::DOMTokenList::create(*this, HTML::AttributeNames::rel);
return m_rel_list;
}
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-method
WebIDL::ExceptionOr<void> HTMLFormElement::set_method(String const& method)
{
@@ -611,6 +621,15 @@ WebIDL::ExceptionOr<void> HTMLFormElement::set_action(String const& value)
return set_attribute(AttributeNames::action, value);
}
void HTMLFormElement::attribute_changed(FlyString const& name, Optional<String> const& value)
{
HTMLElement::attribute_changed(name, value);
if (name == HTML::AttributeNames::rel) {
if (m_rel_list)
m_rel_list->associated_attribute_changed(value.value_or(String {}));
}
}
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#picking-an-encoding-for-the-form
ErrorOr<String> HTMLFormElement::pick_an_encoding() const
{

View File

@@ -92,6 +92,8 @@ public:
StringView method() const;
WebIDL::ExceptionOr<void> set_method(String const&);
JS::GCPtr<DOM::DOMTokenList> rel_list();
String action() const;
WebIDL::ExceptionOr<void> set_action(String const&);
@@ -109,6 +111,8 @@ private:
virtual Vector<FlyString> supported_property_names() const override;
virtual bool is_supported_property_index(u32) const override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
ErrorOr<String> pick_an_encoding() const;
ErrorOr<void> mutate_action_url(URL::URL parsed_action, Vector<XHR::FormDataEntry> entry_list, String encoding, JS::NonnullGCPtr<Navigable> target_navigable, Bindings::NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement);
@@ -143,6 +147,8 @@ private:
// Each form element has a planned navigation, which is either null or a task; when the form is first created,
// its planned navigation must be set to null.
JS::GCPtr<Task const> m_planned_navigation;
JS::GCPtr<DOM::DOMTokenList> m_rel_list;
};
}

View File

@@ -17,7 +17,7 @@ interface HTMLFormElement : HTMLElement {
[CEReactions, Reflect=novalidate] attribute boolean noValidate;
[CEReactions, Reflect] attribute DOMString target;
[CEReactions, Reflect] attribute DOMString rel;
// FIXME: [SameObject, PutForwards=value] readonly attribute DOMTokenList relList;
[SameObject, PutForwards=value] readonly attribute DOMTokenList relList;
[SameObject] readonly attribute HTMLFormControlsCollection elements;
readonly attribute unsigned long length;