Truly independent web browser
LibWeb: Name the longhands of a shorthand descriptor
Andreas Kling5e3b937a3f9f
diff --git a/Libraries/LibWeb/Rust/build.rs b/Libraries/LibWeb/Rust/build.rsindex bf47eb2059f..49bf9e13ca8 100644--- a/Libraries/LibWeb/Rust/build.rs+++ b/Libraries/LibWeb/Rust/build.rs@@ -235,7 +235,7 @@ fn generate_descriptor_metadata(manifest_dir: &Path, out_dir: &Path) -> Result<(pub(crate) enum DescriptorValueType { CounterStyleSystem, CounterStyleAdditiveSymbols, CounterStyleName, CounterStyleNegative, CounterStylePad, CounterStyleRange, CropOrCross, FamilyName, FontSrcList, FontWeightAbsolutePair, Length, OptionalDeclarationValue, PageSize, PositivePercentage, String, Symbol, Symbols, UnicodeRangeTokens }\n\n\pub(crate) struct DescriptorMetadata { pub id: u8, pub syntax: &'static [DescriptorSyntax], pub allow_arbitrary_substitution_functions: bool, pub allow_css_wide_keywords: bool }\n\n\#[derive(Clone, Copy, Debug, PartialEq, Eq)]\n\- pub(crate) struct DescriptorLonghand { pub descriptor_id: u8, pub property_id: u16 }\n\n\+ pub(crate) struct DescriptorLonghand { pub descriptor_id: u8, pub property_id: u16, pub name: &'static str }\n\n\fn equals(value: &[u16], expected: &[u8]) -> bool { value.len() == expected.len() && value.iter().zip(expected).all(|(&left, &right)| u8::try_from(left).is_ok_and(|left| left.eq_ignore_ascii_case(&right))) }\n\n\pub(crate) fn descriptor_metadata(at_rule: u8, name: &[u16]) -> Option<DescriptorMetadata> {\n match at_rule {\n",);@@ -366,16 +366,17 @@ fn generate_descriptor_metadata(manifest_dir: &Path, out_dir: &Path) -> Result<(generated_longhands.push((descriptor_id(longhand)?,longhand.replace('-', "_").to_ascii_uppercase(),+ longhand,));}if generated_longhands.is_empty() {continue;}write!(output, " ({at_rule_index}, {}) => &[", descriptor_id(name)?)?;- for (longhand_id, property_constant) in generated_longhands {+ for (longhand_id, property_constant, longhand_name) in generated_longhands {write!(output,- "DescriptorLonghand {{ descriptor_id: {longhand_id}, property_id: property_id::{property_constant} }},"+ "DescriptorLonghand {{ descriptor_id: {longhand_id}, property_id: property_id::{property_constant}, name: \"{longhand_name}\" }},")?;}output.push_str("],\n");diff --git a/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rsindex 7b9c77235b4..8059acb2498 100644--- a/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rs+++ b/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rs@@ -2865,7 +2865,7 @@ fn collect_descriptors<'a>(&mut descriptors,DescriptorData {id: longhand.descriptor_id,- name: CssString::from_utf16(declaration.name.as_ref()),+ name: CssString::from_utf16(&longhand.name.encode_utf16().collect::<Vec<_>>()),value: values.as_slice()[index].clone().into_arc(),},);diff --git a/Tests/LibWeb/Text/expected/css/page-margin-shorthand-descriptor.txt b/Tests/LibWeb/Text/expected/css/page-margin-shorthand-descriptor.txtnew file mode 100644index 00000000000..1f5ee0eeeef--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/page-margin-shorthand-descriptor.txt@@ -0,0 +1,7 @@+@page { margin-top: 1px; margin-right: 2px; margin-bottom: 3px; margin-left: 4px; }+length: 4+margin-top: 1px+margin-right: 2px+margin-bottom: 3px+margin-left: 4px+@page { margin-top: 1px; margin-right: 2px; margin-bottom: 3px; margin-left: 4px; }diff --git a/Tests/LibWeb/Text/input/css/page-margin-shorthand-descriptor.html b/Tests/LibWeb/Text/input/css/page-margin-shorthand-descriptor.htmlnew file mode 100644index 00000000000..6d032daf8db--- /dev/null+++ b/Tests/LibWeb/Text/input/css/page-margin-shorthand-descriptor.html@@ -0,0 +1,19 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style id="sheet">+ @page { margin: 1px 2px 3px 4px; }+</style>+<script>+ test(() => {+ const rule = document.getElementById("sheet").sheet.cssRules[0];+ println(rule.cssText);+ println(`length: ${rule.style.length}`);+ for (let i = 0; i < rule.style.length; ++i)+ println(`${rule.style[i]}: ${rule.style.getPropertyValue(rule.style[i])}`);++ // What the rule serializes to must parse back to the same margins.+ const reparsed = new CSSStyleSheet();+ reparsed.replaceSync(rule.cssText);+ println(reparsed.cssRules[0].cssText);+ });+</script>