CSSImportRule.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. 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. void set_style_sheet(CSSStyleSheet* style_sheet) { m_style_sheet = style_sheet; }
  28. virtual Type type() const override { return Type::Import; };
  29. private:
  30. CSSImportRule(AK::URL, DOM::Document&);
  31. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  32. virtual void visit_edges(Cell::Visitor&) override;
  33. virtual DeprecatedString 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. JS::GCPtr<DOM::Document> m_document;
  39. JS::GCPtr<CSSStyleSheet> m_style_sheet;
  40. Optional<DOM::DocumentLoadEventDelayer> m_document_load_event_delayer;
  41. };
  42. template<>
  43. inline bool CSSRule::fast_is<CSSImportRule>() const { return type() == CSSRule::Type::Import; }
  44. }