SVGAElement.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
  3. * Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibWeb/Bindings/SVGAElementPrototype.h>
  8. #include <LibWeb/DOM/DOMTokenList.h>
  9. #include <LibWeb/Layout/SVGGraphicsBox.h>
  10. #include <LibWeb/SVG/SVGAElement.h>
  11. namespace Web::SVG {
  12. JS_DEFINE_ALLOCATOR(SVGAElement);
  13. SVGAElement::SVGAElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  14. : SVGGraphicsElement(document, move(qualified_name))
  15. {
  16. }
  17. SVGAElement::~SVGAElement() = default;
  18. void SVGAElement::initialize(JS::Realm& realm)
  19. {
  20. Base::initialize(realm);
  21. WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGAElement);
  22. }
  23. void SVGAElement::visit_edges(Cell::Visitor& visitor)
  24. {
  25. Base::visit_edges(visitor);
  26. SVGURIReferenceMixin::visit_edges(visitor);
  27. visitor.visit(m_rel_list);
  28. }
  29. void SVGAElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
  30. {
  31. Base::attribute_changed(name, old_value, value);
  32. if (name == SVG::AttributeNames::href) {
  33. invalidate_style(DOM::StyleInvalidationReason::HTMLHyperlinkElementHrefChange);
  34. }
  35. if (name == HTML::AttributeNames::rel) {
  36. if (m_rel_list)
  37. m_rel_list->associated_attribute_changed(value.value_or(String {}));
  38. }
  39. }
  40. // https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindex
  41. i32 SVGAElement::default_tab_index_value() const
  42. {
  43. // See the base function for the spec comments.
  44. return 0;
  45. }
  46. // https://svgwg.org/svg2-draft/linking.html#__svg__SVGAElement__relList
  47. JS::NonnullGCPtr<DOM::DOMTokenList> SVGAElement::rel_list()
  48. {
  49. // The relList IDL attribute reflects the ‘rel’ content attribute.
  50. if (!m_rel_list)
  51. m_rel_list = DOM::DOMTokenList::create(*this, HTML::AttributeNames::rel);
  52. return *m_rel_list;
  53. }
  54. JS::GCPtr<Layout::Node> SVGAElement::create_layout_node(CSS::StyleProperties style)
  55. {
  56. return heap().allocate<Layout::SVGGraphicsBox>(document(), *this, move(style));
  57. }
  58. }