CSSImportRule.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2021, the SerenityOS developers.
  3. * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
  4. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <AK/URL.h>
  10. #include <LibWeb/CSS/CSSRule.h>
  11. #include <LibWeb/CSS/CSSStyleSheet.h>
  12. #include <LibWeb/DOM/DocumentLoadEventDelayer.h>
  13. #include <LibWeb/Loader/Resource.h>
  14. namespace Web::CSS {
  15. class CSSImportRule final
  16. : public CSSRule
  17. , public ResourceClient {
  18. WEB_PLATFORM_OBJECT(CSSImportRule, CSSRule);
  19. public:
  20. [[nodiscard]] static JS::NonnullGCPtr<CSSImportRule> create(AK::URL, DOM::Document&);
  21. virtual ~CSSImportRule() = default;
  22. AK::URL const& url() const { return m_url; }
  23. // FIXME: This should return only the specified part of the url. eg, "stuff/foo.css", not "https://example.com/stuff/foo.css".
  24. DeprecatedString href() const { return m_url.to_deprecated_string(); }
  25. CSSStyleSheet* loaded_style_sheet() { return m_style_sheet; }
  26. CSSStyleSheet const* loaded_style_sheet() const { return m_style_sheet; }
  27. CSSStyleSheet* style_sheet_for_bindings() { return m_style_sheet; }
  28. void set_style_sheet(CSSStyleSheet* style_sheet) { m_style_sheet = style_sheet; }
  29. virtual Type type() const override { return Type::Import; }
  30. private:
  31. CSSImportRule(AK::URL, DOM::Document&);
  32. virtual void initialize(JS::Realm&) override;
  33. virtual void visit_edges(Cell::Visitor&) override;
  34. virtual DeprecatedString serialized() const override;
  35. // ^ResourceClient
  36. virtual void resource_did_fail() override;
  37. virtual void resource_did_load() override;
  38. AK::URL m_url;
  39. JS::GCPtr<DOM::Document> m_document;
  40. JS::GCPtr<CSSStyleSheet> m_style_sheet;
  41. Optional<DOM::DocumentLoadEventDelayer> m_document_load_event_delayer;
  42. };
  43. template<>
  44. inline bool CSSRule::fast_is<CSSImportRule>() const { return type() == CSSRule::Type::Import; }
  45. }