Skip to content

Commit

Permalink
LibWeb: Implement the HTMLFormElement.relList attribute
Browse files Browse the repository at this point in the history
This returns a DOMTokenList that reflects the `rel` attribute.
  • Loading branch information
tcl3 authored and awesomekling committed May 16, 2024
1 parent 0a3e184 commit fc4e0cf
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Tests/LibWeb/Text/expected/HTML/relList-attribute.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions Tests/LibWeb/Text/input/HTML/relList-attribute.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
const tagNamesToTest = [
"a",
"area",
"form",
];

for (const tagName of tagNamesToTest) {
Expand Down
19 changes: 19 additions & 0 deletions Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
{
Expand Down
6 changes: 6 additions & 0 deletions Userland/Libraries/LibWeb/HTML/HTMLFormElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class HTMLFormElement final : public HTMLElement {
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&);

Expand All @@ -109,6 +111,8 @@ class HTMLFormElement final : public HTMLElement {
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);
Expand Down Expand Up @@ -143,6 +147,8 @@ class HTMLFormElement final : public HTMLElement {
// 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;
};

}
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fc4e0cf

Please sign in to comment.