CSSImportRule.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2021, the SerenityOS developers.
  3. * Copyright (c) 2021-2022, 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 final
  14. : public CSSRule
  15. , public ResourceClient {
  16. AK_MAKE_NONCOPYABLE(CSSImportRule);
  17. AK_MAKE_NONMOVABLE(CSSImportRule);
  18. public:
  19. using WrapperType = Bindings::CSSImportRuleWrapper;
  20. static NonnullRefPtr<CSSImportRule> create(AK::URL url, DOM::Document& document)
  21. {
  22. return adopt_ref(*new CSSImportRule(move(url), document));
  23. }
  24. virtual ~CSSImportRule() = default;
  25. AK::URL const& url() const { return m_url; }
  26. // FIXME: This should return only the specified part of the url. eg, "stuff/foo.css", not "https://example.com/stuff/foo.css".
  27. String href() const { return m_url.to_string(); }
  28. bool has_import_result() const { return !m_style_sheet.is_null(); }
  29. RefPtr<CSSStyleSheet> loaded_style_sheet() { return m_style_sheet; }
  30. RefPtr<CSSStyleSheet> const loaded_style_sheet() const { return m_style_sheet; }
  31. NonnullRefPtr<CSSStyleSheet> style_sheet_for_bindings() { return *m_style_sheet; }
  32. void set_style_sheet(RefPtr<CSSStyleSheet> const& style_sheet) { m_style_sheet = style_sheet; }
  33. virtual StringView class_name() const override { return "CSSImportRule"sv; };
  34. virtual Type type() const override { return Type::Import; };
  35. private:
  36. explicit CSSImportRule(AK::URL, DOM::Document&);
  37. virtual String serialized() const override;
  38. // ^ResourceClient
  39. virtual void resource_did_fail() override;
  40. virtual void resource_did_load() override;
  41. AK::URL m_url;
  42. WeakPtr<DOM::Document> m_document;
  43. Optional<DOM::DocumentLoadEventDelayer> m_document_load_event_delayer;
  44. RefPtr<CSSStyleSheet> m_style_sheet;
  45. };
  46. template<>
  47. inline bool CSSRule::fast_is<CSSImportRule>() const { return type() == CSSRule::Type::Import; }
  48. }