Let legacy layout serialize shorthands in getComputedStyle (#32149)

* Let legacy layout serialize shorthands in getComputedStyle

This ports #31277 (with the changes from #32066) into legacy layout.

Otherwise, turning white-space into a shorthand (#32146) would fail
some tests that expect the property to be serializable.

* Update text expecatations
This commit is contained in:
Oriol Brufau 2024-04-26 17:37:46 +02:00 committed by GitHub
parent 1a0565bbec
commit fdb6fb7920
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
59 changed files with 270 additions and 1920 deletions

View file

@ -766,13 +766,9 @@ pub fn process_resolved_style_request<'dom>(
);
let style = styles.primary();
let longhand_id = match *property {
PropertyId::NonCustom(id) => {
match id.unaliased().as_longhand() {
Some(id) => id,
// Firefox returns blank strings for the computed value of shorthands,
// so this should be web-compatible.
None => return String::new(),
}
PropertyId::NonCustom(id) => match id.longhand_or_shorthand() {
Ok(longhand_id) => longhand_id,
Err(shorthand_id) => return shorthand_to_css_string(shorthand_id, style),
},
PropertyId::Custom(ref name) => {
return style.computed_value_to_string(PropertyDeclarationId::Custom(name));
@ -815,13 +811,9 @@ fn process_resolved_style_request_internal<'dom>(
let style = &*layout_el.resolved_style();
let longhand_id = match *property {
PropertyId::NonCustom(id) => {
match id.unaliased().as_longhand() {
Some(id) => id,
// Firefox returns blank strings for the computed value of shorthands,
// so this should be web-compatible.
None => return String::new(),
}
PropertyId::NonCustom(id) => match id.longhand_or_shorthand() {
Ok(longhand_id) => longhand_id,
Err(shorthand_id) => return shorthand_to_css_string(shorthand_id, style),
},
PropertyId::Custom(ref name) => {
return style.computed_value_to_string(PropertyDeclarationId::Custom(name));
@ -934,6 +926,25 @@ fn process_resolved_style_request_internal<'dom>(
}
}
fn shorthand_to_css_string(
id: style::properties::ShorthandId,
style: &style::properties::ComputedValues,
) -> String {
use style::values::resolved::Context;
let mut block = PropertyDeclarationBlock::new();
let mut dest = String::new();
for longhand in id.longhands() {
block.push(
style.computed_or_resolved_declaration(longhand, Some(&Context { style })),
Importance::Normal,
);
}
match block.shorthand_to_css(id, &mut dest) {
Ok(_) => dest.to_owned(),
Err(_) => String::new(),
}
}
pub fn process_offset_parent_query(
requested_node: OpaqueNode,
layout_root: &mut dyn Flow,