CSSImportRule.h 1.7 KB

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