mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-19 10:20:22 +00:00
No parsing yet, just CSSContainerRule and the supporting ContainerQuery class. CSSContainerRule is unusual in how it matches, because instead of it either matching or not matching globally, it instead is matched against a specific element. But also, some at-rules inside it always apply, as if they were written outside it. This doesn't fit well with how CSSConditionRule is implemented, and will likely require some rework later. For now, `condition_matches()` always returns false, and `for_each_effective_rule()` is overridden to always process those global at-rules and nothing else.
58 lines
1.6 KiB
C++
58 lines
1.6 KiB
C++
/*
|
|
* 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>
|
|
|
|
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;
|
|
|
|
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;
|
|
virtual String serialized() const override;
|
|
|
|
Vector<Condition> m_conditions;
|
|
};
|
|
|
|
template<>
|
|
inline bool CSSRule::fast_is<CSSContainerRule>() const { return type() == CSSRule::Type::Container; }
|
|
|
|
}
|