CSSImportRule.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2021, the SerenityOS developers.
  3. * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/URL.h>
  9. #include <LibWeb/CSS/CSSRule.h>
  10. #include <LibWeb/CSS/CSSStyleSheet.h>
  11. #include <LibWeb/DOM/DocumentLoadEventDelayer.h>
  12. namespace Web::CSS {
  13. class CSSImportRule
  14. : public CSSRule
  15. , public ResourceClient {
  16. AK_MAKE_NONCOPYABLE(CSSImportRule);
  17. AK_MAKE_NONMOVABLE(CSSImportRule);
  18. public:
  19. static NonnullRefPtr<CSSImportRule> create(AK::URL url, DOM::Document& document)
  20. {
  21. return adopt_ref(*new CSSImportRule(move(url), document));
  22. }
  23. ~CSSImportRule() = default;
  24. const AK::URL& url() const { return m_url; }
  25. bool has_import_result() const { return !m_style_sheet.is_null(); }
  26. RefPtr<CSSStyleSheet> loaded_style_sheet() { return m_style_sheet; }
  27. const RefPtr<CSSStyleSheet> loaded_style_sheet() const { return m_style_sheet; }
  28. void set_style_sheet(const RefPtr<CSSStyleSheet>& style_sheet) { m_style_sheet = style_sheet; }
  29. virtual StringView class_name() const override { return "CSSImportRule"; };
  30. virtual Type type() const override { return Type::Import; };
  31. private:
  32. explicit CSSImportRule(AK::URL, DOM::Document&);
  33. virtual String serialized() const override;
  34. // ^ResourceClient
  35. virtual void resource_did_fail() override;
  36. virtual void resource_did_load() override;
  37. AK::URL m_url;
  38. WeakPtr<DOM::Document> m_document;
  39. Optional<DOM::DocumentLoadEventDelayer> m_document_load_event_delayer;
  40. RefPtr<CSSStyleSheet> m_style_sheet;
  41. };
  42. template<>
  43. inline bool CSSRule::fast_is<CSSImportRule>() const { return type() == CSSRule::Type::Import; }
  44. }