2024-06-23 17:05:47 +02:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
|
2024-07-16 12:08:34 +01:00
|
|
|
|
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
2024-06-23 17:05:47 +02:00
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2024-06-28 14:51:57 +02:00
|
|
|
|
#include <LibWeb/Bindings/SVGAElementPrototype.h>
|
2024-07-16 12:08:34 +01:00
|
|
|
|
#include <LibWeb/DOM/DOMTokenList.h>
|
2024-06-23 17:05:47 +02:00
|
|
|
|
#include <LibWeb/Layout/SVGGraphicsBox.h>
|
|
|
|
|
#include <LibWeb/SVG/SVGAElement.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::SVG {
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
|
GC_DEFINE_ALLOCATOR(SVGAElement);
|
2024-06-23 17:05:47 +02:00
|
|
|
|
|
|
|
|
|
SVGAElement::SVGAElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
|
|
|
|
: SVGGraphicsElement(document, move(qualified_name))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SVGAElement::~SVGAElement() = default;
|
|
|
|
|
|
2024-06-28 14:51:57 +02:00
|
|
|
|
void SVGAElement::initialize(JS::Realm& realm)
|
|
|
|
|
{
|
|
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGAElement);
|
2025-04-20 16:22:57 +02:00
|
|
|
|
Base::initialize(realm);
|
2024-06-28 14:51:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 12:08:34 +01:00
|
|
|
|
void SVGAElement::visit_edges(Cell::Visitor& visitor)
|
|
|
|
|
{
|
|
|
|
|
Base::visit_edges(visitor);
|
2024-07-16 13:43:42 +01:00
|
|
|
|
SVGURIReferenceMixin::visit_edges(visitor);
|
2024-07-16 12:08:34 +01:00
|
|
|
|
visitor.visit(m_rel_list);
|
2025-07-12 02:06:51 +01:00
|
|
|
|
visitor.visit(m_target);
|
2024-07-16 12:08:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-14 08:14:16 -05:00
|
|
|
|
void SVGAElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_)
|
2024-07-16 12:08:34 +01:00
|
|
|
|
{
|
2024-11-14 08:14:16 -05:00
|
|
|
|
Base::attribute_changed(name, old_value, value, namespace_);
|
|
|
|
|
|
2024-11-06 18:00:18 +01:00
|
|
|
|
if (name == SVG::AttributeNames::href) {
|
2025-02-08 14:23:17 +01:00
|
|
|
|
invalidate_style(
|
|
|
|
|
DOM::StyleInvalidationReason::HTMLHyperlinkElementHrefChange,
|
|
|
|
|
{
|
|
|
|
|
{ .type = CSS::InvalidationSet::Property::Type::PseudoClass, .value = CSS::PseudoClass::AnyLink },
|
|
|
|
|
{ .type = CSS::InvalidationSet::Property::Type::PseudoClass, .value = CSS::PseudoClass::Link },
|
|
|
|
|
{ .type = CSS::InvalidationSet::Property::Type::PseudoClass, .value = CSS::PseudoClass::LocalLink },
|
|
|
|
|
},
|
|
|
|
|
{});
|
2024-11-06 18:00:18 +01:00
|
|
|
|
}
|
2024-07-16 12:08:34 +01:00
|
|
|
|
if (name == HTML::AttributeNames::rel) {
|
|
|
|
|
if (m_rel_list)
|
|
|
|
|
m_rel_list->associated_attribute_changed(value.value_or(String {}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-14 18:45:18 +01:00
|
|
|
|
// https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindex
|
|
|
|
|
i32 SVGAElement::default_tab_index_value() const
|
|
|
|
|
{
|
|
|
|
|
// See the base function for the spec comments.
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-12 02:06:51 +01:00
|
|
|
|
// https://svgwg.org/svg2-draft/linking.html#__svg__SVGAElement__target
|
|
|
|
|
GC::Ref<SVGAnimatedString> SVGAElement::target()
|
|
|
|
|
{
|
|
|
|
|
if (!m_target)
|
|
|
|
|
m_target = SVGAnimatedString::create(realm(), *this, HTML::AttributeNames::target);
|
|
|
|
|
return *m_target;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 12:08:34 +01:00
|
|
|
|
// https://svgwg.org/svg2-draft/linking.html#__svg__SVGAElement__relList
|
2024-11-15 04:01:23 +13:00
|
|
|
|
GC::Ref<DOM::DOMTokenList> SVGAElement::rel_list()
|
2024-07-16 12:08:34 +01:00
|
|
|
|
{
|
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-20 16:35:12 +01:00
|
|
|
|
GC::Ptr<Layout::Node> SVGAElement::create_layout_node(GC::Ref<CSS::ComputedProperties> style)
|
2024-06-23 17:05:47 +02:00
|
|
|
|
{
|
2024-11-14 06:13:46 +13:00
|
|
|
|
return heap().allocate<Layout::SVGGraphicsBox>(document(), *this, move(style));
|
2024-06-23 17:05:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|