HTMLLinkElement.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, the SerenityOS developers.
  4. * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <LibWeb/DOM/DocumentLoadEventDelayer.h>
  10. #include <LibWeb/HTML/HTMLElement.h>
  11. namespace Web::HTML {
  12. class HTMLLinkElement final
  13. : public HTMLElement
  14. , public ResourceClient {
  15. WEB_PLATFORM_OBJECT(HTMLLinkElement, HTMLElement);
  16. public:
  17. virtual ~HTMLLinkElement() override;
  18. virtual void inserted() override;
  19. String rel() const { return attribute(HTML::AttributeNames::rel); }
  20. String type() const { return attribute(HTML::AttributeNames::type); }
  21. String href() const { return attribute(HTML::AttributeNames::href); }
  22. bool has_loaded_icon() const;
  23. bool load_favicon_and_use_if_window_is_active();
  24. private:
  25. HTMLLinkElement(DOM::Document&, DOM::QualifiedName);
  26. void parse_attribute(FlyString const&, String const&) override;
  27. // ^ResourceClient
  28. virtual void resource_did_fail() override;
  29. virtual void resource_did_load() override;
  30. void resource_did_load_stylesheet();
  31. void resource_did_load_favicon();
  32. struct Relationship {
  33. enum {
  34. Alternate = 1 << 0,
  35. Stylesheet = 1 << 1,
  36. Preload = 1 << 2,
  37. DNSPrefetch = 1 << 3,
  38. Preconnect = 1 << 4,
  39. Icon = 1 << 5,
  40. };
  41. };
  42. RefPtr<Resource> m_preload_resource;
  43. Optional<DOM::DocumentLoadEventDelayer> m_document_load_event_delayer;
  44. unsigned m_relationship { 0 };
  45. };
  46. }
  47. WRAPPER_HACK(HTMLLinkElement, Web::HTML)