HTMLAreaElement.cpp 1.6 KB

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