ladybird/Libraries/LibWeb/CSS/Parser/RuleContext.cpp
Sam Atkins c2f0d61eb6 LibWeb/CSS: Implement initial parsing for @container rules
The main limitation here are that none of the container-query features
are parsed in a meaningful way; they all become `<general-enclosed>`.
Parsing for them will be added as they are implemented.
2026-03-30 14:49:24 +01:00

87 lines
3.1 KiB
C++

/*
* Copyright (c) 2025-2026, 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:
return RuleContext::AtContainer;
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("container"sv))
return RuleContext::AtContainer;
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;
}
}