HTMLAreaElement.cpp 1.5 KB

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