HTMLAnchorElement.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/HTML/HTMLElement.h>
  8. #include <LibWeb/HTML/HTMLHyperlinkElementUtils.h>
  9. namespace Web::HTML {
  10. class HTMLAnchorElement final
  11. : public HTMLElement
  12. , public HTMLHyperlinkElementUtils {
  13. WEB_PLATFORM_OBJECT(HTMLAnchorElement, HTMLElement);
  14. public:
  15. virtual ~HTMLAnchorElement() override;
  16. DeprecatedString rel() const { return attribute(HTML::AttributeNames::rel); }
  17. DeprecatedString target() const { return attribute(HTML::AttributeNames::target); }
  18. DeprecatedString download() const { return attribute(HTML::AttributeNames::download); }
  19. DeprecatedString text() const;
  20. void set_text(DeprecatedString const&);
  21. DeprecatedString referrer_policy() const;
  22. WebIDL::ExceptionOr<void> set_referrer_policy(DeprecatedString const&);
  23. // ^EventTarget
  24. // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-a-element
  25. virtual bool is_focusable() const override { return has_attribute(HTML::AttributeNames::href); }
  26. virtual bool is_html_anchor_element() const override { return true; }
  27. private:
  28. HTMLAnchorElement(DOM::Document&, DOM::QualifiedName);
  29. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  30. void run_activation_behavior(Web::DOM::Event const&);
  31. // ^DOM::Element
  32. virtual void parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value) override;
  33. virtual i32 default_tab_index_value() const override;
  34. // ^HTML::HTMLHyperlinkElementUtils
  35. virtual DOM::Document& hyperlink_element_utils_document() override { return document(); }
  36. virtual DeprecatedString hyperlink_element_utils_href() const override;
  37. virtual void set_hyperlink_element_utils_href(DeprecatedString) override;
  38. virtual bool hyperlink_element_utils_is_html_anchor_element() const final { return true; }
  39. virtual bool hyperlink_element_utils_is_connected() const final { return is_connected(); }
  40. virtual DeprecatedString hyperlink_element_utils_target() const final { return target(); }
  41. virtual DeprecatedString hyperlink_element_utils_rel() const final { return rel(); }
  42. virtual void hyperlink_element_utils_queue_an_element_task(HTML::Task::Source source, Function<void()> steps) override
  43. {
  44. queue_an_element_task(source, move(steps));
  45. }
  46. virtual Optional<ARIA::Role> default_role() const override;
  47. };
  48. }
  49. namespace Web::DOM {
  50. template<>
  51. inline bool Node::fast_is<HTML::HTMLAnchorElement>() const { return is_html_anchor_element(); }
  52. }