HTMLLinkElement.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. DeprecatedString rel() const { return attribute(HTML::AttributeNames::rel); }
  20. DeprecatedString type() const { return attribute(HTML::AttributeNames::type); }
  21. DeprecatedString 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. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  27. void parse_attribute(DeprecatedFlyString const&, DeprecatedString const&) override;
  28. // ^ResourceClient
  29. virtual void resource_did_fail() override;
  30. virtual void resource_did_load() override;
  31. // ^ HTMLElement
  32. virtual void did_remove_attribute(DeprecatedFlyString const&) override;
  33. virtual void visit_edges(Cell::Visitor&) override;
  34. void resource_did_load_stylesheet();
  35. void resource_did_load_favicon();
  36. struct Relationship {
  37. enum {
  38. Alternate = 1 << 0,
  39. Stylesheet = 1 << 1,
  40. Preload = 1 << 2,
  41. DNSPrefetch = 1 << 3,
  42. Preconnect = 1 << 4,
  43. Icon = 1 << 5,
  44. };
  45. };
  46. RefPtr<Resource> m_preload_resource;
  47. JS::GCPtr<CSS::CSSStyleSheet> m_loaded_style_sheet;
  48. Optional<DOM::DocumentLoadEventDelayer> m_document_load_event_delayer;
  49. unsigned m_relationship { 0 };
  50. };
  51. }