HTMLAreaElement.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/HTML/HTMLAreaElement.h>
  9. #include <LibWeb/HTML/Window.h>
  10. namespace Web::HTML {
  11. JS_DEFINE_ALLOCATOR(HTMLAreaElement);
  12. HTMLAreaElement::HTMLAreaElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  13. : HTMLElement(document, move(qualified_name))
  14. {
  15. }
  16. HTMLAreaElement::~HTMLAreaElement() = default;
  17. void HTMLAreaElement::initialize(JS::Realm& realm)
  18. {
  19. Base::initialize(realm);
  20. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLAreaElement);
  21. }
  22. void HTMLAreaElement::attribute_changed(FlyString const& name, Optional<String> const& value)
  23. {
  24. HTMLElement::attribute_changed(name, value);
  25. if (name == HTML::AttributeNames::href) {
  26. set_the_url();
  27. }
  28. }
  29. Optional<String> HTMLAreaElement::hyperlink_element_utils_href() const
  30. {
  31. return attribute(HTML::AttributeNames::href);
  32. }
  33. WebIDL::ExceptionOr<void> HTMLAreaElement::set_hyperlink_element_utils_href(String href)
  34. {
  35. return set_attribute(HTML::AttributeNames::href, move(href));
  36. }
  37. // https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindex
  38. i32 HTMLAreaElement::default_tab_index_value() const
  39. {
  40. // See the base function for the spec comments.
  41. return 0;
  42. }
  43. Optional<ARIA::Role> HTMLAreaElement::default_role() const
  44. {
  45. // https://www.w3.org/TR/html-aria/#el-area-no-href
  46. if (!href().is_empty())
  47. return ARIA::Role::link;
  48. // https://www.w3.org/TR/html-aria/#el-area
  49. return ARIA::Role::generic;
  50. }
  51. }