2021-02-21 13:36:34 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
2026-02-05 14:40:15 -03:00
|
|
|
* Copyright (c) 2021-2026, Sam Atkins <sam@ladybird.org>
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2021-02-21 13:36:34 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-02-21 13:36:34 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <LibWeb/CSS/CSSRule.h>
|
2021-09-30 17:57:35 -03:00
|
|
|
#include <LibWeb/CSS/CSSStyleSheet.h>
|
2026-05-29 13:16:12 -03:00
|
|
|
#include <LibWeb/CSS/Selector.h>
|
2025-04-08 14:16:38 -03:00
|
|
|
#include <LibWeb/CSS/URL.h>
|
2025-07-19 23:35:33 -03:00
|
|
|
#include <LibWeb/Export.h>
|
2025-11-29 06:16:38 -03:00
|
|
|
#include <LibWeb/Forward.h>
|
2021-02-21 13:36:34 -03:00
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
|
2025-07-19 23:35:33 -03:00
|
|
|
class WEB_API CSSImportRule final
|
2026-02-05 14:40:15 -03:00
|
|
|
: public CSSRule
|
|
|
|
|
, public CSSStyleSheet::Subresource {
|
2022-08-28 08:42:07 -03:00
|
|
|
WEB_PLATFORM_OBJECT(CSSImportRule, CSSRule);
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DECLARE_ALLOCATOR(CSSImportRule);
|
2021-02-21 13:36:34 -03:00
|
|
|
|
|
|
|
|
public:
|
2026-05-29 13:16:12 -03:00
|
|
|
struct ImportScope {
|
|
|
|
|
Optional<SelectorList> start_selectors;
|
|
|
|
|
Optional<SelectorList> end_selectors;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] static GC::Ref<CSSImportRule> create(JS::Realm&, URL, GC::Ptr<DOM::Document>, Optional<FlyString> layer, Optional<ImportScope>&& scope, RefPtr<Supports>, GC::Ref<MediaList>);
|
2021-02-21 13:36:34 -03:00
|
|
|
|
2026-02-05 14:40:15 -03:00
|
|
|
virtual ~CSSImportRule() override;
|
2021-02-21 13:36:34 -03:00
|
|
|
|
2025-04-08 14:16:38 -03:00
|
|
|
URL const& url() const { return m_url; }
|
|
|
|
|
String href() const { return m_url.url(); }
|
2021-02-21 13:36:34 -03:00
|
|
|
|
2022-08-07 10:46:44 -03:00
|
|
|
CSSStyleSheet* loaded_style_sheet() { return m_style_sheet; }
|
|
|
|
|
CSSStyleSheet const* loaded_style_sheet() const { return m_style_sheet; }
|
2025-12-04 13:48:19 -03:00
|
|
|
GC::Ref<MediaList> media() const;
|
2022-08-07 10:46:44 -03:00
|
|
|
CSSStyleSheet* style_sheet_for_bindings() { return m_style_sheet; }
|
2021-02-21 13:44:17 -03:00
|
|
|
|
2025-12-02 09:38:16 -03:00
|
|
|
Optional<FlyString> layer_name() const;
|
2025-03-19 08:32:34 -03:00
|
|
|
Optional<String> supports_text() const;
|
|
|
|
|
|
2025-12-04 11:34:28 -03:00
|
|
|
bool matches() const;
|
2026-05-29 13:16:12 -03:00
|
|
|
bool has_scope() const { return m_scope.has_value(); }
|
|
|
|
|
Optional<SelectorList> const& scope_start_selectors() const;
|
|
|
|
|
Optional<SelectorList> const& scope_end_selectors() const;
|
2026-06-04 13:22:45 -03:00
|
|
|
Optional<SelectorList> const& scope_start_selectors_for_matching() const;
|
|
|
|
|
Optional<SelectorList> const& scope_end_selectors_for_matching() const;
|
2025-12-04 11:34:28 -03:00
|
|
|
|
|
|
|
|
Optional<FlyString> internal_layer_name() const { return m_layer_internal; }
|
|
|
|
|
Optional<FlyString> internal_qualified_layer_name(Badge<StyleScope>) const;
|
|
|
|
|
|
2021-02-21 13:36:34 -03:00
|
|
|
private:
|
2026-05-29 13:16:12 -03:00
|
|
|
CSSImportRule(JS::Realm&, URL, GC::Ptr<DOM::Document>, Optional<FlyString>, Optional<ImportScope>&&, RefPtr<Supports>, GC::Ref<MediaList>);
|
2022-08-28 08:42:07 -03:00
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2022-08-07 10:46:44 -03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2026-06-04 13:22:45 -03:00
|
|
|
virtual void clear_caches() override;
|
2025-12-04 09:03:01 -03:00
|
|
|
virtual void dump(StringBuilder&, int indent_levels) const override;
|
2021-02-21 13:36:34 -03:00
|
|
|
|
2024-12-20 17:25:40 -03:00
|
|
|
virtual void set_parent_style_sheet(CSSStyleSheet*) override;
|
|
|
|
|
|
2026-02-05 14:40:15 -03:00
|
|
|
virtual GC::Ptr<CSSStyleSheet> parent_style_sheet_for_subresource() override { return m_parent_style_sheet; }
|
|
|
|
|
|
2023-11-20 07:16:39 -03:00
|
|
|
virtual String serialized() const override;
|
2021-10-01 14:57:45 -03:00
|
|
|
|
2024-12-20 17:25:40 -03:00
|
|
|
void fetch();
|
|
|
|
|
void set_style_sheet(GC::Ref<CSSStyleSheet>);
|
2021-11-18 14:34:53 -03:00
|
|
|
|
2025-04-08 14:16:38 -03:00
|
|
|
URL m_url;
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<DOM::Document> m_document;
|
2025-12-04 11:15:07 -03:00
|
|
|
Optional<FlyString> m_layer;
|
2025-12-04 11:34:28 -03:00
|
|
|
Optional<FlyString> m_layer_internal;
|
2026-05-29 13:16:12 -03:00
|
|
|
Optional<ImportScope> m_scope;
|
2026-06-04 13:22:45 -03:00
|
|
|
mutable Optional<SelectorList> m_cached_scope_start_selectors_for_matching;
|
|
|
|
|
mutable Optional<SelectorList> m_cached_scope_end_selectors_for_matching;
|
2025-03-19 08:23:33 -03:00
|
|
|
RefPtr<Supports> m_supports;
|
2025-12-04 13:48:19 -03:00
|
|
|
GC::Ref<MediaList> m_media;
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<CSSStyleSheet> m_style_sheet;
|
2021-02-21 13:36:34 -03:00
|
|
|
};
|
|
|
|
|
|
2021-03-18 17:50:52 -03:00
|
|
|
template<>
|
|
|
|
|
inline bool CSSRule::fast_is<CSSImportRule>() const { return type() == CSSRule::Type::Import; }
|
|
|
|
|
|
2021-02-21 13:36:34 -03:00
|
|
|
}
|