2026-03-27 11:14:00 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2026, Sam Atkins <sam@ladybird.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/FlyString.h>
|
|
|
|
|
#include <AK/Optional.h>
|
|
|
|
|
#include <LibWeb/CSS/CSSConditionRule.h>
|
2026-05-08 11:57:57 -03:00
|
|
|
#include <LibWeb/Forward.h>
|
2026-03-27 11:14:00 -03:00
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
|
|
|
|
|
// https://drafts.csswg.org/css-conditional-5/#dictdef-csscontainercondition
|
|
|
|
|
struct CSSContainerCondition {
|
|
|
|
|
String name;
|
|
|
|
|
String query;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// https://drafts.csswg.org/css-conditional-5/#the-csscontainerrule-interface
|
|
|
|
|
class CSSContainerRule final : public CSSConditionRule {
|
|
|
|
|
WEB_PLATFORM_OBJECT(CSSContainerRule, CSSConditionRule);
|
|
|
|
|
GC_DECLARE_ALLOCATOR(CSSContainerRule);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
struct Condition {
|
|
|
|
|
Optional<FlyString> container_name;
|
|
|
|
|
RefPtr<ContainerQuery> container_query;
|
|
|
|
|
};
|
|
|
|
|
[[nodiscard]] static GC::Ref<CSSContainerRule> create(JS::Realm&, Vector<Condition>&&, CSSRuleList&);
|
|
|
|
|
|
|
|
|
|
virtual ~CSSContainerRule() override;
|
|
|
|
|
|
|
|
|
|
virtual String condition_text() const override;
|
|
|
|
|
virtual bool condition_matches() const override;
|
2026-05-08 11:57:57 -03:00
|
|
|
bool matches(DOM::AbstractElement const&) const;
|
2026-05-14 08:46:17 -03:00
|
|
|
bool contains_size_feature() const;
|
2026-03-27 11:14:00 -03:00
|
|
|
|
|
|
|
|
String container_name() const;
|
|
|
|
|
String container_query() const;
|
|
|
|
|
|
|
|
|
|
// FIXME: Should be FrozenArray
|
|
|
|
|
Vector<CSSContainerCondition> conditions() const;
|
|
|
|
|
|
|
|
|
|
virtual void for_each_effective_rule(TraversalOrder, Function<void(CSSRule const&)> const& callback) const override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
CSSContainerRule(JS::Realm&, Vector<Condition>&&, CSSRuleList&);
|
|
|
|
|
|
|
|
|
|
virtual void initialize(JS::Realm&) override;
|
2026-05-08 13:42:15 -03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
virtual void clear_caches() override;
|
2026-03-27 11:14:00 -03:00
|
|
|
virtual String serialized() const override;
|
2026-05-08 13:42:15 -03:00
|
|
|
CSSContainerRule const* find_parent_container_rule() const;
|
2026-03-27 11:14:00 -03:00
|
|
|
|
2026-05-08 11:57:57 -03:00
|
|
|
bool conditions_match(DOM::AbstractElement const&) const;
|
|
|
|
|
|
2026-03-27 11:14:00 -03:00
|
|
|
Vector<Condition> m_conditions;
|
2026-05-08 13:42:15 -03:00
|
|
|
mutable GC::Ptr<CSSContainerRule const> m_cached_parent_container_rule;
|
|
|
|
|
mutable bool m_parent_container_rule_cache_valid { false };
|
2026-03-27 11:14:00 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
inline bool CSSRule::fast_is<CSSContainerRule>() const { return type() == CSSRule::Type::Container; }
|
|
|
|
|
|
|
|
|
|
}
|