LibWeb: Add support for the 'all' CSS property

The "longhands" array is populated in the code generator to avoid the
overhead of manually maintaining the list in Properties.json

There is one subtest that still fails in
'cssstyledeclaration-csstext-all-shorthand', this is related to
us not maintaining the relative order of CSS declarations for custom vs
non-custom properties.
This commit is contained in:
Callum Law 2025-06-10 01:31:14 +12:00 committed by Sam Atkins
commit d31a58a7d6
Notes: github-actions[bot] 2025-06-12 14:26:43 +00:00
16 changed files with 199 additions and 82 deletions

View file

@ -408,6 +408,11 @@ Parser::ParseErrorOr<NonnullRefPtr<CSSStyleValue const>> Parser::parse_css_value
// Special-case property handling
switch (property_id) {
case PropertyID::All:
// NOTE: The 'all' property, unlike some other shorthands, doesn't support directly listing sub-property
// values, only the CSS-wide keywords - this is handled above, and thus, if we have gotten to here, there
// is an invalid value which is a syntax error.
return ParseError::SyntaxError;
case PropertyID::AspectRatio:
if (auto parsed_value = parse_aspect_ratio_value(tokens); parsed_value && !tokens.has_next_token())
return parsed_value.release_nonnull();

View file

@ -183,6 +183,14 @@
"align-self"
]
},
"all": {
"affects-layout": true,
"affects-stacking-context": true,
"inherited": false,
"initial": "initial",
"longhands": [],
"_comment": "The 'longhands' array is populated in the code generator to avoid having to maintain it manually"
},
"animation": {
"affects-layout": false,
"inherited": false,

View file

@ -996,57 +996,6 @@ void StyleComputer::for_each_property_expanding_shorthands(PropertyID property_i
set_longhand_property(property_id, value);
}
void StyleComputer::set_property_expanding_shorthands(
CascadedProperties& cascaded_properties,
PropertyID property_id,
CSSStyleValue const& value,
GC::Ptr<CSSStyleDeclaration const> declaration,
CascadeOrigin cascade_origin,
Important important,
Optional<FlyString> layer_name)
{
for_each_property_expanding_shorthands(property_id, value, [&](PropertyID longhand_id, CSSStyleValue const& longhand_value) {
if (longhand_value.is_revert()) {
cascaded_properties.revert_property(longhand_id, important, cascade_origin);
} else if (longhand_value.is_revert_layer()) {
cascaded_properties.revert_layer_property(longhand_id, important, layer_name);
} else {
cascaded_properties.set_property(longhand_id, longhand_value, important, cascade_origin, layer_name, declaration);
}
});
}
void StyleComputer::set_all_properties(
CascadedProperties& cascaded_properties,
DOM::Element& element,
Optional<PseudoElement> pseudo_element,
CSSStyleValue const& value,
DOM::Document& document,
GC::Ptr<CSSStyleDeclaration const> declaration,
CascadeOrigin cascade_origin,
Important important,
Optional<FlyString> layer_name) const
{
for (auto i = to_underlying(CSS::first_longhand_property_id); i <= to_underlying(CSS::last_longhand_property_id); ++i) {
auto property_id = (CSS::PropertyID)i;
if (value.is_revert()) {
cascaded_properties.revert_property(property_id, important, cascade_origin);
continue;
}
if (value.is_revert_layer()) {
cascaded_properties.revert_layer_property(property_id, important, layer_name);
continue;
}
NonnullRefPtr<CSSStyleValue const> property_value = value;
if (property_value->is_unresolved())
property_value = Parser::Parser::resolve_unresolved_style_value(Parser::ParsingParams { document }, element, pseudo_element, property_id, property_value->as_unresolved());
set_property_expanding_shorthands(cascaded_properties, property_id, property_value, declaration, cascade_origin, important, layer_name);
}
}
void StyleComputer::cascade_declarations(
CascadedProperties& cascaded_properties,
DOM::Element& element,
@ -1091,12 +1040,6 @@ void StyleComputer::cascade_declarations(
}
}
if (property.property_id == PropertyID::All) {
set_all_properties(cascaded_properties, element, pseudo_element, property_value, m_document, &declaration, cascade_origin, important, layer_name);
continue;
}
// NOTE: This is a duplicate of set_property_expanding_shorthands() with some extra checks.
for_each_property_expanding_shorthands(property.property_id, property_value, [&](PropertyID longhand_id, CSSStyleValue const& longhand_value) {
// If we're a PSV that's already been seen, that should mean that our shorthand already got
// resolved and gave us a value, so we don't want to overwrite it with a PSV.

View file

@ -129,14 +129,6 @@ class FontLoader;
class StyleComputer {
public:
static void for_each_property_expanding_shorthands(PropertyID, CSSStyleValue const&, Function<void(PropertyID, CSSStyleValue const&)> const& set_longhand_property);
static void set_property_expanding_shorthands(
CascadedProperties&,
PropertyID,
CSSStyleValue const&,
GC::Ptr<CSSStyleDeclaration const>,
CascadeOrigin,
Important,
Optional<FlyString> layer_name);
static NonnullRefPtr<CSSStyleValue const> get_inherit_value(CSS::PropertyID, DOM::Element const*, Optional<CSS::PseudoElement> = {});
static Optional<String> user_agent_style_sheet_source(StringView name);
@ -222,17 +214,6 @@ private:
void compute_defaulted_property_value(ComputedProperties&, DOM::Element const*, CSS::PropertyID, Optional<CSS::PseudoElement>) const;
void set_all_properties(
CascadedProperties&,
DOM::Element&,
Optional<PseudoElement>,
CSSStyleValue const&,
DOM::Document&,
GC::Ptr<CSSStyleDeclaration const>,
CascadeOrigin,
Important,
Optional<FlyString> layer_name) const;
template<typename Callback>
void for_each_stylesheet(CascadeOrigin, Callback) const;

View file

@ -95,6 +95,11 @@ String ShorthandStyleValue::to_string(SerializationMode mode) const
// Then special cases
switch (m_properties.shorthand_property) {
case PropertyID::All: {
// NOTE: 'all' can only be serialized in the case all sub-properties share the same CSS-wide keyword, this is
// handled above, thus, if we get to here that mustn't be the case and we should return the empty string.
return ""_string;
}
case PropertyID::Background: {
auto color = longhand(PropertyID::BackgroundColor);
auto image = longhand(PropertyID::BackgroundImage);