CSSImportRule.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 <LibURL/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. JS_DECLARE_ALLOCATOR(CSSImportRule);
  20. public:
  21. [[nodiscard]] static JS::NonnullGCPtr<CSSImportRule> create(URL::URL, DOM::Document&);
  22. virtual ~CSSImportRule() = default;
  23. URL::URL const& url() const { return m_url; }
  24. // FIXME: This should return only the specified part of the url. eg, "stuff/foo.css", not "https://example.com/stuff/foo.css".
  25. String href() const { return MUST(m_url.to_string()); }
  26. CSSStyleSheet* loaded_style_sheet() { return m_style_sheet; }
  27. CSSStyleSheet const* loaded_style_sheet() const { return m_style_sheet; }
  28. CSSStyleSheet* style_sheet_for_bindings() { return m_style_sheet; }
  29. void set_style_sheet(CSSStyleSheet* style_sheet) { m_style_sheet = style_sheet; }
  30. virtual Type type() const override { return Type::Import; }
  31. private:
  32. CSSImportRule(URL::URL, DOM::Document&);
  33. virtual void initialize(JS::Realm&) override;
  34. virtual void visit_edges(Cell::Visitor&) override;
  35. virtual String serialized() const override;
  36. // ^ResourceClient
  37. virtual void resource_did_fail() override;
  38. virtual void resource_did_load() override;
  39. URL::URL m_url;
  40. JS::GCPtr<DOM::Document> m_document;
  41. JS::GCPtr<CSSStyleSheet> m_style_sheet;
  42. Optional<DOM::DocumentLoadEventDelayer> m_document_load_event_delayer;
  43. };
  44. template<>
  45. inline bool CSSRule::fast_is<CSSImportRule>() const { return type() == CSSRule::Type::Import; }
  46. }