HTMLAreaElement.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/ARIA/Roles.h>
  7. #include <LibWeb/Bindings/HTMLAreaElementPrototype.h>
  8. #include <LibWeb/DOM/DOMTokenList.h>
  9. #include <LibWeb/HTML/HTMLAreaElement.h>
  10. #include <LibWeb/HTML/Window.h>
  11. namespace Web::HTML {
  12. GC_DEFINE_ALLOCATOR(HTMLAreaElement);
  13. HTMLAreaElement::HTMLAreaElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  14. : HTMLElement(document, move(qualified_name))
  15. {
  16. }
  17. HTMLAreaElement::~HTMLAreaElement() = default;
  18. void HTMLAreaElement::initialize(JS::Realm& realm)
  19. {
  20. Base::initialize(realm);
  21. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLAreaElement);
  22. }
  23. void HTMLAreaElement::visit_edges(Cell::Visitor& visitor)
  24. {
  25. Base::visit_edges(visitor);
  26. visitor.visit(m_rel_list);
  27. }
  28. void HTMLAreaElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_)
  29. {
  30. Base::attribute_changed(name, old_value, value, namespace_);
  31. if (name == HTML::AttributeNames::href) {
  32. set_the_url();
  33. } else if (name == HTML::AttributeNames::rel) {
  34. if (m_rel_list)
  35. m_rel_list->associated_attribute_changed(value.value_or(String {}));
  36. }
  37. }
  38. // https://html.spec.whatwg.org/multipage/image-maps.html#dom-area-rellist
  39. GC::Ref<DOM::DOMTokenList> HTMLAreaElement::rel_list()
  40. {
  41. // The IDL attribute relList must reflect the rel content attribute.
  42. if (!m_rel_list)
  43. m_rel_list = DOM::DOMTokenList::create(*this, HTML::AttributeNames::rel);
  44. return *m_rel_list;
  45. }
  46. Optional<String> HTMLAreaElement::hyperlink_element_utils_href() const
  47. {
  48. return attribute(HTML::AttributeNames::href);
  49. }
  50. WebIDL::ExceptionOr<void> HTMLAreaElement::set_hyperlink_element_utils_href(String href)
  51. {
  52. return set_attribute(HTML::AttributeNames::href, move(href));
  53. }
  54. Optional<String> HTMLAreaElement::hyperlink_element_utils_referrerpolicy() const
  55. {
  56. return attribute(HTML::AttributeNames::referrerpolicy);
  57. }
  58. // https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindex
  59. i32 HTMLAreaElement::default_tab_index_value() const
  60. {
  61. // See the base function for the spec comments.
  62. return 0;
  63. }
  64. Optional<ARIA::Role> HTMLAreaElement::default_role() const
  65. {
  66. // https://www.w3.org/TR/html-aria/#el-area-no-href
  67. if (!href().is_empty())
  68. return ARIA::Role::link;
  69. // https://www.w3.org/TR/html-aria/#el-area
  70. return ARIA::Role::generic;
  71. }
  72. }