Skip to content

Truly independent web browser

LibWeb: Split registered computed lists into Typed OM values

Andreas Kling6e1d0dce8565
diff --git a/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.cpp b/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.cpp
index 4e13e2bf0b2..b430741ee84 100644
--- a/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.cpp
+++ b/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.cpp
@@ -16,6 +16,7 @@
#include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/CSS/PropertyNameAndID.h>
#include <LibWeb/CSS/StyleSheetState.h>
+#include <LibWeb/CSS/StyleValues/StyleValueList.h>
#include <LibWeb/CSS/Zoom.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
@@ -54,6 +55,19 @@ static bool has_computed_style(DOM::AbstractElement const& abstract_element)
return abstract_element.element().is_connected();
}
+static StyleValueVector subdivide_property_value(StyleValue const& value, PropertyNameAndID const& property, DOM::AbstractElement const* computed_element)
+{
+ // https://drafts.css-houdini.org/css-typed-om-1/#reify-stylevalue
+ // If an internal representation is from a list-valued property, this list defines how to reify a single iteration
+ // of the property; multiple iterations are reflected by returning multiple values from StylePropertyMap.getAll().
+ if (computed_element && property.is_custom_property() && value.is_value_list()) {
+ auto registration = computed_element->document().get_registered_custom_property(property.name());
+ if (registration.has_value() && Parser::ValueParserFFI::rust_syntax_value_is_list(registration->syntax.data(), value.rust_style_value_data()))
+ return value.as_value_list().values();
+ }
+ return value.subdivide_into_iterations(property);
+}
+
// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymapreadonly-get
WebIDL::ExceptionOr<Variant<GC::Ref<CSSStyleValue>, Empty>> StylePropertyMapReadOnly::get(Utf16String property_name)
{
@@ -71,7 +85,7 @@ WebIDL::ExceptionOr<Variant<GC::Ref<CSSStyleValue>, Empty>> StylePropertyMapRead
// 4. If props[property] exists, subdivide into iterations props[property], then reify the first item of the result and return it.
if (auto property_value = get_style_value(props, property.value())) {
- auto iterations = property_value->subdivide_into_iterations(property.value());
+ auto iterations = subdivide_property_value(*property_value, property.value(), props.get_pointer<DOM::AbstractElement>());
return iterations.first()->reify(property->name());
}
@@ -98,7 +112,7 @@ WebIDL::ExceptionOr<GC::RootVector<GC::Ref<CSSStyleValue>>> StylePropertyMapRead
// 4. If props[property] exists, subdivide into iterations props[property], then reify each item of the result, and return the list.
if (auto property_value = get_style_value(props, property.value())) {
- auto iterations = property_value->subdivide_into_iterations(property.value());
+ auto iterations = subdivide_property_value(*property_value, property.value(), props.get_pointer<DOM::AbstractElement>());
for (auto const& style_value : iterations)
results.append(style_value->reify(property->name()));
return results;
diff --git a/Libraries/LibWeb/Rust/src/css/parser/syntax.rs b/Libraries/LibWeb/Rust/src/css/parser/syntax.rs
index 6189965ee65..7e9ebcb6db4 100644
--- a/Libraries/LibWeb/Rust/src/css/parser/syntax.rs
+++ b/Libraries/LibWeb/Rust/src/css/parser/syntax.rs
@@ -458,6 +458,24 @@ pub extern "C" fn rust_syntax_is_single_component(syntax: &SyntaxNode) -> bool {
is_single_syntax_component(syntax)
}
+#[unsafe(no_mangle)]
+pub extern "C" fn rust_syntax_value_is_list(syntax: &SyntaxNode, value: &StyleValueData) -> bool {
+ match syntax {
+ SyntaxNode::Multiplier { .. } => true,
+ SyntaxNode::Alternatives(alternatives) => {
+ // NB: Select the same first matching alternative as parsing. A transform-list is one Typed OM value,
+ // whereas a multiplier on transform-function produces multiple values.
+ let source = crate::css::serialize::serialize_style_value_to_utf16(value);
+ let context = ParseContext::default();
+ alternatives
+ .iter()
+ .find(|alternative| parse_with_syntax(&context, &source, alternative).is_some())
+ .is_some_and(|alternative| matches!(alternative, SyntaxNode::Multiplier { .. }))
+ }
+ _ => false,
+ }
+}
+
#[unsafe(no_mangle)]
pub extern "C" fn rust_syntax_equals(left: &SyntaxNode, right: &SyntaxNode) -> bool {
left == right
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/typedom.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/typedom.txt
index 76371f57141..9ab53fd48ad 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/typedom.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/typedom.txt
@@ -2,8 +2,8 @@ Harness status: OK
Found 325 tests
-320 Pass
-5 Fail
+324 Pass
+1 Fail
Pass Computed * is reified as CSSUnparsedValue
Pass Computed <angle> is reified as CSSUnitValue
Pass Computed <color> is reified as CSSStyleValue
@@ -20,10 +20,10 @@ Pass Computed <resolution> is reified as CSSUnitValue
Pass Computed <time> is reified as CSSUnitValue
Pass Computed <url> is reified as CSSStyleValue
Pass Computed ident is reified as CSSKeywordValue
-Fail First computed value correctly reified in space-separated list
-Fail First computed value correctly reified in comma-separated list
-Fail All computed values correctly reified in space-separated list
-Fail All computed values correctly reified in comma-separated list
+Pass First computed value correctly reified in space-separated list
+Pass First computed value correctly reified in comma-separated list
+Pass All computed values correctly reified in space-separated list
+Pass All computed values correctly reified in comma-separated list
Pass Specified * is reified as CSSUnparsedValue from get/getAll [attributeStyleMap]
Pass Specified * is reified as CSSUnparsedValue from get/getAll [styleMap]
Pass Specified foo is reified as CSSUnparsedValue from get/getAll [attributeStyleMap]