SVGAElement.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 == HTML::AttributeNames::rel) {
  33. if (m_rel_list)
  34. m_rel_list->associated_attribute_changed(value.value_or(String {}));
  35. }
  36. }
  37. // https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindex
  38. i32 SVGAElement::default_tab_index_value() const
  39. {
  40. // See the base function for the spec comments.
  41. return 0;
  42. }
  43. // https://svgwg.org/svg2-draft/linking.html#__svg__SVGAElement__relList
  44. JS::NonnullGCPtr<DOM::DOMTokenList> SVGAElement::rel_list()
  45. {
  46. // The relList IDL attribute reflects the ‘rel’ content attribute.
  47. if (!m_rel_list)
  48. m_rel_list = DOM::DOMTokenList::create(*this, HTML::AttributeNames::rel);
  49. return *m_rel_list;
  50. }
  51. JS::GCPtr<Layout::Node> SVGAElement::create_layout_node(CSS::StyleProperties style)
  52. {
  53. return heap().allocate_without_realm<Layout::SVGGraphicsBox>(document(), *this, move(style));
  54. }
  55. }