HTMLAnchorElement.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 deprecated_attribute(HTML::AttributeNames::rel); }
  17. DeprecatedString target() const { return deprecated_attribute(HTML::AttributeNames::target); }
  18. DeprecatedString download() const { return deprecated_attribute(HTML::AttributeNames::download); }
  19. String text() const;
  20. void set_text(String const&);
  21. StringView referrer_policy() const;
  22. WebIDL::ExceptionOr<void> set_referrer_policy(String 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 void initialize(JS::Realm&) override;
  30. void run_activation_behavior(Web::DOM::Event const&);
  31. // ^DOM::Element
  32. virtual void attribute_changed(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 WebIDL::ExceptionOr<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 void hyperlink_element_utils_queue_an_element_task(HTML::Task::Source source, Function<void()> steps) override
  41. {
  42. queue_an_element_task(source, move(steps));
  43. }
  44. virtual DeprecatedString hyperlink_element_utils_get_an_elements_target() const override
  45. {
  46. return get_an_elements_target();
  47. }
  48. virtual TokenizedFeature::NoOpener hyperlink_element_utils_get_an_elements_noopener(StringView target) const override
  49. {
  50. return get_an_elements_noopener(target);
  51. }
  52. virtual Optional<ARIA::Role> default_role() const override;
  53. };
  54. }
  55. namespace Web::DOM {
  56. template<>
  57. inline bool Node::fast_is<HTML::HTMLAnchorElement>() const { return is_html_anchor_element(); }
  58. }