ladybird/Libraries/LibWeb/CSS/Parser/RuleContext.cpp
Sam Atkins 214d2b5e1f LibWeb/CSS: Implement CSSContainerRule
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.
2026-03-30 14:49:24 +01:00

85 lines
3 KiB
C++

/*
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/CSS/CSSFontFeatureValuesRule.h>
#include <LibWeb/CSS/CSSMarginRule.h>
#include <LibWeb/CSS/Parser/RuleContext.h>
namespace Web::CSS::Parser {
RuleContext rule_context_type_for_rule(CSSRule::Type rule_type)
{
switch (rule_type) {
case CSSRule::Type::Container:
TODO();
case CSSRule::Type::CounterStyle:
return RuleContext::AtCounterStyle;
case CSSRule::Type::Style:
return RuleContext::Style;
case CSSRule::Type::Media:
return RuleContext::AtMedia;
case CSSRule::Type::FontFace:
return RuleContext::AtFontFace;
case CSSRule::Type::FontFeatureValues:
return RuleContext::AtFontFeatureValues;
case CSSRule::Type::Function:
return RuleContext::AtFunction;
case CSSRule::Type::Keyframes:
return RuleContext::AtKeyframes;
case CSSRule::Type::Keyframe:
return RuleContext::Keyframe;
case CSSRule::Type::Supports:
return RuleContext::AtSupports;
case CSSRule::Type::LayerBlock:
return RuleContext::AtLayer;
case CSSRule::Type::Margin:
return RuleContext::Margin;
case CSSRule::Type::NestedDeclarations:
return RuleContext::Style;
case CSSRule::Type::Page:
return RuleContext::AtPage;
case CSSRule::Type::Property:
return RuleContext::AtProperty;
// Other types shouldn't be trying to create a context.
case CSSRule::Type::Import:
case CSSRule::Type::LayerStatement:
case CSSRule::Type::Namespace:
case CSSRule::Type::FunctionDeclarations:
break;
}
VERIFY_NOT_REACHED();
}
RuleContext rule_context_type_for_at_rule(FlyString const& name)
{
if (name.equals_ignoring_ascii_case("media"sv))
return RuleContext::AtMedia;
if (name.equals_ignoring_ascii_case("counter-style"sv))
return RuleContext::AtCounterStyle;
if (name.equals_ignoring_ascii_case("font-face"sv))
return RuleContext::AtFontFace;
if (name.equals_ignoring_ascii_case("keyframes"sv) || name.equals_ignoring_ascii_case("-webkit-keyframes"sv))
return RuleContext::AtKeyframes;
if (name.equals_ignoring_ascii_case("font-feature-values"sv))
return RuleContext::AtFontFeatureValues;
if (name.equals_ignoring_ascii_case("function"sv))
return RuleContext::AtFunction;
if (CSSFontFeatureValuesRule::is_font_feature_value_type_at_keyword(name))
return RuleContext::FontFeatureValue;
if (name.equals_ignoring_ascii_case("supports"sv))
return RuleContext::AtSupports;
if (name.equals_ignoring_ascii_case("layer"sv))
return RuleContext::AtLayer;
if (name.equals_ignoring_ascii_case("property"sv))
return RuleContext::AtProperty;
if (name.equals_ignoring_ascii_case("page"sv))
return RuleContext::AtPage;
if (is_margin_rule_name(name))
return RuleContext::Margin;
return RuleContext::Unknown;
}
}