/* * Copyright (c) 2021, the SerenityOS developers. * Copyright (c) 2021-2026, Sam Atkins * Copyright (c) 2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include namespace Web::CSS { class WEB_API CSSImportRule final : public CSSRule , public CSSStyleSheet::Subresource { WEB_PLATFORM_OBJECT(CSSImportRule, CSSRule); GC_DECLARE_ALLOCATOR(CSSImportRule); public: struct ImportScope { Optional start_selectors; Optional end_selectors; }; [[nodiscard]] static GC::Ref create(JS::Realm&, URL, GC::Ptr, Optional layer, Optional&& scope, RefPtr, GC::Ref); virtual ~CSSImportRule() override; URL const& url() const { return m_url; } String href() const { return m_url.url(); } CSSStyleSheet* loaded_style_sheet() { return m_style_sheet; } CSSStyleSheet const* loaded_style_sheet() const { return m_style_sheet; } GC::Ref media() const; CSSStyleSheet* style_sheet_for_bindings() { return m_style_sheet; } Optional layer_name() const; Optional supports_text() const; bool matches() const; bool has_scope() const { return m_scope.has_value(); } Optional const& scope_start_selectors() const; Optional const& scope_end_selectors() const; Optional const& scope_start_selectors_for_matching() const; Optional const& scope_end_selectors_for_matching() const; Optional internal_layer_name() const { return m_layer_internal; } Optional internal_qualified_layer_name(Badge) const; private: CSSImportRule(JS::Realm&, URL, GC::Ptr, Optional, Optional&&, RefPtr, GC::Ref); virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; virtual void clear_caches() override; virtual void dump(StringBuilder&, int indent_levels) const override; virtual void set_parent_style_sheet(CSSStyleSheet*) override; virtual GC::Ptr parent_style_sheet_for_subresource() override { return m_parent_style_sheet; } virtual String serialized() const override; void fetch(); void set_style_sheet(GC::Ref); URL m_url; GC::Ptr m_document; Optional m_layer; Optional m_layer_internal; Optional m_scope; mutable Optional m_cached_scope_start_selectors_for_matching; mutable Optional m_cached_scope_end_selectors_for_matching; RefPtr m_supports; GC::Ref m_media; GC::Ptr m_style_sheet; }; template<> inline bool CSSRule::fast_is() const { return type() == CSSRule::Type::Import; } }