HTMLAreaElement.cpp 1.6 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. HTMLAreaElement::HTMLAreaElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  11. : HTMLElement(document, move(qualified_name))
  12. {
  13. }
  14. HTMLAreaElement::~HTMLAreaElement() = default;
  15. JS::ThrowCompletionOr<void> HTMLAreaElement::initialize(JS::Realm& realm)
  16. {
  17. MUST_OR_THROW_OOM(Base::initialize(realm));
  18. set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLAreaElementPrototype>(realm, "HTMLAreaElement"));
  19. return {};
  20. }
  21. void HTMLAreaElement::parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value)
  22. {
  23. HTMLElement::parse_attribute(name, value);
  24. if (name == HTML::AttributeNames::href) {
  25. set_the_url();
  26. }
  27. }
  28. DeprecatedString HTMLAreaElement::hyperlink_element_utils_href() const
  29. {
  30. return attribute(HTML::AttributeNames::href);
  31. }
  32. void HTMLAreaElement::set_hyperlink_element_utils_href(DeprecatedString href)
  33. {
  34. MUST(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_null())
  46. return ARIA::Role::link;
  47. // https://www.w3.org/TR/html-aria/#el-area
  48. return ARIA::Role::generic;
  49. }
  50. }