LibWeb/SVG: Implement SVGAElement.relList

This commit is contained in:
Jamie Mansfield 2024-07-16 12:08:34 +01:00 committed by Andreas Kling
parent 7562f89d4e
commit 6ca4c2beb0
Notes: sideshowbarker 2024-07-17 07:14:14 +09:00
5 changed files with 54 additions and 4 deletions

View file

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

View file

@ -1,8 +1,7 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
function relListTest(tagName) {
const element = document.createElement(tagName);
function relListTest(tagName, element) {
const relList = element.relList;
println(`${tagName}.relList initial length: ${relList.length}`);
println(`${tagName}.relList always returns the same value: ${relList === element.relList}`);
@ -21,9 +20,17 @@
"form",
"link",
];
const svgTagNamesToTest = [
"a",
];
for (const tagName of tagNamesToTest) {
relListTest(tagName);
const element = document.createElement(tagName);
relListTest(tagName, element);
}
for (const tagName of svgTagNamesToTest) {
const element = document.createElementNS("http://www.w3.org/2000/svg", tagName);
relListTest(`svg.${tagName}`, element);
}
});
</script>

View file

@ -1,10 +1,12 @@
/*
* Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/SVGAElementPrototype.h>
#include <LibWeb/DOM/DOMTokenList.h>
#include <LibWeb/Layout/SVGGraphicsBox.h>
#include <LibWeb/SVG/SVGAElement.h>
@ -25,6 +27,30 @@ void SVGAElement::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGAElement);
}
void SVGAElement::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_rel_list);
}
void SVGAElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
{
Base::attribute_changed(name, old_value, value);
if (name == HTML::AttributeNames::rel) {
if (m_rel_list)
m_rel_list->associated_attribute_changed(value.value_or(String {}));
}
}
// https://svgwg.org/svg2-draft/linking.html#__svg__SVGAElement__relList
JS::NonnullGCPtr<DOM::DOMTokenList> SVGAElement::rel_list()
{
// The relList IDL attribute reflects the rel content attribute.
if (!m_rel_list)
m_rel_list = DOM::DOMTokenList::create(*this, HTML::AttributeNames::rel);
return *m_rel_list;
}
JS::GCPtr<Layout::Node> SVGAElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
{
return heap().allocate_without_realm<Layout::SVGGraphicsBox>(document(), *this, move(style));

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -17,11 +18,20 @@ class SVGAElement final : public SVGGraphicsElement {
public:
virtual ~SVGAElement() override;
JS::NonnullGCPtr<DOM::DOMTokenList> rel_list();
virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
private:
SVGAElement(DOM::Document&, DOM::QualifiedName);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
// ^DOM::Element
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
JS::GCPtr<DOM::DOMTokenList> m_rel_list;
};
}

View file

@ -1,3 +1,4 @@
#import <DOM/DOMTokenList.idl>
#import <HTML/HTMLHyperlinkElementUtils.idl>
#import <SVG/SVGURIReference.idl>
@ -9,7 +10,7 @@ interface SVGAElement : SVGGraphicsElement {
[Reflect] attribute DOMString download;
[Reflect] attribute USVString ping;
[Reflect] attribute DOMString rel;
[FIXME, SameObject, PutForwards=value] readonly attribute DOMTokenList relList;
[SameObject, PutForwards=value] readonly attribute DOMTokenList relList;
[Reflect] attribute DOMString hreflang;
[Reflect] attribute DOMString type;