CSSImportRule.h 2.0 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. namespace Web::CSS {
  14. class CSSImportRule final
  15. : public CSSRule
  16. , public ResourceClient {
  17. WEB_PLATFORM_OBJECT(CSSImportRule, CSSRule);
  18. public:
  19. static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSImportRule>> create(AK::URL, DOM::Document&);
  20. virtual ~CSSImportRule() = default;
  21. AK::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. DeprecatedString href() const { return m_url.to_deprecated_string(); }
  24. bool has_import_result() const { return !m_style_sheet; }
  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 JS::ThrowCompletionOr<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. }