2024-06-23 12:05:47 -03:00
|
|
|
|
/*
|
|
|
|
|
|
* Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
|
2024-07-16 08:08:34 -03:00
|
|
|
|
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
2024-06-23 12:05:47 -03:00
|
|
|
|
*
|
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2026-04-18 05:54:06 -03:00
|
|
|
|
#include <LibWeb/Bindings/SVGAElement.h>
|
2026-04-29 06:19:45 -03:00
|
|
|
|
#include <LibWeb/CSS/Invalidation/LinkInvalidator.h>
|
2024-07-16 08:08:34 -03:00
|
|
|
|
#include <LibWeb/DOM/DOMTokenList.h>
|
2026-01-10 18:04:37 -03:00
|
|
|
|
#include <LibWeb/HTML/UserNavigationInvolvement.h>
|
2024-06-23 12:05:47 -03:00
|
|
|
|
#include <LibWeb/Layout/SVGGraphicsBox.h>
|
2026-01-10 18:04:37 -03:00
|
|
|
|
#include <LibWeb/SVG/AttributeNames.h>
|
2024-06-23 12:05:47 -03:00
|
|
|
|
#include <LibWeb/SVG/SVGAElement.h>
|
2026-01-10 18:04:37 -03:00
|
|
|
|
#include <LibWeb/UIEvents/MouseEvent.h>
|
2024-06-23 12:05:47 -03:00
|
|
|
|
|
|
|
|
|
|
namespace Web::SVG {
|
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
|
GC_DEFINE_ALLOCATOR(SVGAElement);
|
2024-06-23 12:05:47 -03:00
|
|
|
|
|
|
|
|
|
|
SVGAElement::SVGAElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
|
|
|
|
|
: SVGGraphicsElement(document, move(qualified_name))
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SVGAElement::~SVGAElement() = default;
|
|
|
|
|
|
|
2024-06-28 09:51:57 -03:00
|
|
|
|
void SVGAElement::initialize(JS::Realm& realm)
|
|
|
|
|
|
{
|
|
|
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGAElement);
|
2025-04-20 11:22:57 -03:00
|
|
|
|
Base::initialize(realm);
|
2024-06-28 09:51:57 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-16 08:08:34 -03:00
|
|
|
|
void SVGAElement::visit_edges(Cell::Visitor& visitor)
|
|
|
|
|
|
{
|
|
|
|
|
|
Base::visit_edges(visitor);
|
2024-07-16 09:43:42 -03:00
|
|
|
|
SVGURIReferenceMixin::visit_edges(visitor);
|
2024-07-16 08:08:34 -03:00
|
|
|
|
visitor.visit(m_rel_list);
|
2025-07-11 22:06:51 -03:00
|
|
|
|
visitor.visit(m_target);
|
2024-07-16 08:08:34 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-14 10:14:16 -03:00
|
|
|
|
void SVGAElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_)
|
2024-07-16 08:08:34 -03:00
|
|
|
|
{
|
2024-11-14 10:14:16 -03:00
|
|
|
|
Base::attribute_changed(name, old_value, value, namespace_);
|
|
|
|
|
|
|
2026-04-29 06:19:45 -03:00
|
|
|
|
if (name == SVG::AttributeNames::href)
|
|
|
|
|
|
CSS::Invalidation::invalidate_style_after_hyperlink_state_change(*this);
|
2024-07-16 08:08:34 -03:00
|
|
|
|
if (name == HTML::AttributeNames::rel) {
|
|
|
|
|
|
if (m_rel_list)
|
|
|
|
|
|
m_rel_list->associated_attribute_changed(value.value_or(String {}));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-14 14:45:18 -03: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-11 22:06:51 -03:00
|
|
|
|
// https://svgwg.org/svg2-draft/linking.html#__svg__SVGAElement__target
|
|
|
|
|
|
GC::Ref<SVGAnimatedString> SVGAElement::target()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!m_target)
|
2025-10-31 09:27:49 -03:00
|
|
|
|
m_target = SVGAnimatedString::create(realm(), *this, DOM::QualifiedName { HTML::AttributeNames::target, OptionalNone {}, OptionalNone {} });
|
2025-07-11 22:06:51 -03:00
|
|
|
|
return *m_target;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-16 08:08:34 -03:00
|
|
|
|
// https://svgwg.org/svg2-draft/linking.html#__svg__SVGAElement__relList
|
2024-11-14 12:01:23 -03:00
|
|
|
|
GC::Ref<DOM::DOMTokenList> SVGAElement::rel_list()
|
2024-07-16 08:08:34 -03: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 12:35:12 -03:00
|
|
|
|
GC::Ptr<Layout::Node> SVGAElement::create_layout_node(GC::Ref<CSS::ComputedProperties> style)
|
2024-06-23 12:05:47 -03:00
|
|
|
|
{
|
2024-11-13 14:13:46 -03:00
|
|
|
|
return heap().allocate<Layout::SVGGraphicsBox>(document(), *this, move(style));
|
2024-06-23 12:05:47 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-10 18:04:37 -03:00
|
|
|
|
// https://html.spec.whatwg.org/multipage/links.html#links-created-by-a-and-area-elements
|
|
|
|
|
|
void SVGAElement::activation_behavior(DOM::Event const& event)
|
|
|
|
|
|
{
|
|
|
|
|
|
// The activation behavior of an a or area element element given an event event is:
|
|
|
|
|
|
|
|
|
|
|
|
// 1. If element has no href attribute, then return.
|
|
|
|
|
|
if (href()->base_val().is_empty())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// AD-HOC: Do not activate the element for clicks with the ctrl/cmd modifier present. This lets
|
|
|
|
|
|
// the browser process open the link in a new tab.
|
|
|
|
|
|
if (is<UIEvents::MouseEvent>(event)) {
|
|
|
|
|
|
auto const& mouse_event = static_cast<UIEvents::MouseEvent const&>(event);
|
|
|
|
|
|
if (mouse_event.platform_ctrl_key())
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Let hyperlinkSuffix be null.
|
|
|
|
|
|
Optional<String> hyperlink_suffix {};
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME: 3. If element is an a element, and event's target is an img with an ismap attribute specified, then:
|
|
|
|
|
|
|
|
|
|
|
|
// 4. Let userInvolvement be event's user navigation involvement.
|
|
|
|
|
|
auto user_involvement = HTML::user_navigation_involvement(event);
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME: 5. If the user has expressed a preference to download the hyperlink, then set userInvolvement to "browser UI".
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME: 6. If element has a download attribute, or if the user has expressed a preference to download the
|
|
|
|
|
|
// hyperlink, then download the hyperlink created by element with hyperlinkSuffix set to hyperlinkSuffix and
|
|
|
|
|
|
// userInvolvement set to userInvolvement.
|
|
|
|
|
|
|
|
|
|
|
|
// 7. Otherwise, follow the hyperlink created by element with hyperlinkSuffix set to hyperlinkSuffix and userInvolvement set to userInvolvement.
|
|
|
|
|
|
follow_the_hyperlink(hyperlink_suffix, user_involvement);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-23 12:05:47 -03:00
|
|
|
|
}
|