mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-06-28 12:10:28 +00:00
`@scope (a) to (b) {}` applies its contained style rules to elements
that have `a` as a parent, and do not have `a b` as a parent. Both the
`a` and `b` selector lists are optional.
Because it's situational whether a `@scope` will apply to a given
element, we store the ancestor scope on the `MatchingRule`, similar to
`@container`, and then determine during matching whether all the parent
`@scope`s match or not.
The rules for how selectors inside `@scope` are adjusted and interpreted
are a bit confusing. Unlike for other at-rules, nested style rules
inside `@scope` do not get a leading `&` added during parsing. To
support this, `adapt_nested_relative_selector_list()` now takes a flag
for whether its parent is a `@scope` or not.
`@scope` can also contain nested declarations without itself being
nested inside a style rule.
When determining their selectors, nested declarations rules adopt the
`@scope`'s scoping root if it has one, or otherwise fall back to the
parent element of the `<style>` element (not implemented here,) or the
`:root`. These are required to have zero specificity, so we wrap the
selector in `:where()`.
37 lines
654 B
C++
37 lines
654 B
C++
/*
|
|
* Copyright (c) 2025-2026, Sam Atkins <sam@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/FlyString.h>
|
|
#include <LibWeb/CSS/CSSRule.h>
|
|
|
|
namespace Web::CSS::Parser {
|
|
|
|
enum class RuleContext : u8 {
|
|
Unknown,
|
|
Style,
|
|
AtContainer,
|
|
AtCounterStyle,
|
|
AtMedia,
|
|
AtFontFace,
|
|
AtFontFeatureValues,
|
|
FontFeatureValue,
|
|
AtFunction,
|
|
AtKeyframes,
|
|
Keyframe,
|
|
AtSupports,
|
|
AtScope,
|
|
SupportsCondition,
|
|
AtLayer,
|
|
AtProperty,
|
|
AtPage,
|
|
Margin,
|
|
};
|
|
RuleContext rule_context_type_for_rule(CSSRule::Type);
|
|
RuleContext rule_context_type_for_at_rule(FlyString const&);
|
|
|
|
}
|