LibWeb: Implement the HTMLAreaElement.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 b7fd39c2e6
commit 0a3e1846f0
Notes: sideshowbarker 2024-07-17 02:29:45 +09:00
5 changed files with 24 additions and 1 deletions

View File

@ -4,3 +4,9 @@ a.relList for after setting rel to "whatever": whatever
a.relList for after setting rel to "prefetch": prefetch
a.relList contains "prefetch": true
a.relList contains "whatever": false
area.relList initial length: 0
area.relList always returns the same value: true
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

View File

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

View File

@ -6,6 +6,7 @@
#include <LibWeb/ARIA/Roles.h>
#include <LibWeb/Bindings/HTMLAreaElementPrototype.h>
#include <LibWeb/DOM/DOMTokenList.h>
#include <LibWeb/HTML/HTMLAreaElement.h>
#include <LibWeb/HTML/Window.h>
@ -31,9 +32,21 @@ void HTMLAreaElement::attribute_changed(FlyString const& name, Optional<String>
HTMLElement::attribute_changed(name, value);
if (name == HTML::AttributeNames::href) {
set_the_url();
} else 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/image-maps.html#dom-area-rellist
JS::GCPtr<DOM::DOMTokenList> HTMLAreaElement::rel_list()
{
// The IDL attribute relList must reflect the rel content attribute.
if (!m_rel_list)
m_rel_list = DOM::DOMTokenList::create(*this, HTML::AttributeNames::rel);
return m_rel_list;
}
Optional<String> HTMLAreaElement::hyperlink_element_utils_href() const
{
return attribute(HTML::AttributeNames::href);

View File

@ -20,6 +20,7 @@ class HTMLAreaElement final
public:
virtual ~HTMLAreaElement() override;
JS::GCPtr<DOM::DOMTokenList> rel_list();
private:
HTMLAreaElement(DOM::Document&, DOM::QualifiedName);
@ -50,6 +51,8 @@ private:
}
virtual Optional<ARIA::Role> default_role() const override;
JS::GCPtr<DOM::DOMTokenList> m_rel_list;
};
}

View File

@ -14,7 +14,7 @@ interface HTMLAreaElement : HTMLElement {
[CEReactions, Reflect] attribute DOMString download;
[CEReactions, Reflect] attribute USVString ping;
[CEReactions, Reflect] attribute DOMString rel;
// FIXME: [SameObject, PutForwards=value] readonly attribute DOMTokenList relList;
[SameObject, PutForwards=value] readonly attribute DOMTokenList relList;
// FIXME: [CEReactions] attribute DOMString referrerPolicy;
// Obsolete