Truly independent web browser
LibWeb: Stop animating `::first-letter`, `::first-line` and highlights
Tim Ledbetter77634d7c6304
diff --git a/Documentation/CSSGeneratedFiles.md b/Documentation/CSSGeneratedFiles.mdindex e6a3996c638..81a40e50de7 100644--- a/Documentation/CSSGeneratedFiles.md+++ b/Documentation/CSSGeneratedFiles.md@@ -260,6 +260,7 @@ Each entry has the following properties:| Field | Required | Default | Description ||----------------------|----------------------------|----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|+| `accepts-animations` | No | `true` | Whether the transition and animation properties apply to this pseudo-element, whatever its `property-whitelist` says. || `alias-for` | No | Nothing | Use to specify that this should be treated as an alias for the named pseudo-element. || `function-syntax` | No | Nothing | Syntax for the function arguments if this is a function-type pseudo-element. Copied directly from the spec. || `implementation` | Unless `type` is "function | Nothing | How this pseudo-element is implemented, either `"synthetic"` or `"element-reference"` - see below. |@@ -284,7 +285,7 @@ The generated code provides:This is an array of strings. Properties can be named directly ("color"), or categories of properties with a leading `#`("#font-properties"), as the specs often says a group is allowed instead of listing the properties exactly.Any properties we don't support yet can be prefixed with "FIXME:" and will be ignored.-The property groups and the properties that always apply are defined in+The property groups and the transition and animation properties are defined in`PseudoElementPropertyGroups.txt` and generated into the Rust cascade tables.The following categories are supported:diff --git a/Libraries/LibWeb/CSS/PseudoElementPropertyGroups.txt b/Libraries/LibWeb/CSS/PseudoElementPropertyGroups.txtindex b8d520122c6..a9dedd4e13a 100644--- a/Libraries/LibWeb/CSS/PseudoElementPropertyGroups.txt+++ b/Libraries/LibWeb/CSS/PseudoElementPropertyGroups.txt@@ -1,7 +1,7 @@# Copyright (c) 2026-present, the Ladybird developers.# SPDX-License-Identifier: BSD-2-Clause-[always-allowed-properties]+[transition-and-animation-properties]transitiontransition-behaviortransition-delaydiff --git a/Libraries/LibWeb/CSS/PseudoElements.json b/Libraries/LibWeb/CSS/PseudoElements.jsonindex 3bae168d940..7fb35fc2c28 100644--- a/Libraries/LibWeb/CSS/PseudoElements.json+++ b/Libraries/LibWeb/CSS/PseudoElements.json@@ -76,6 +76,7 @@"float","#custom-properties"],+ "accepts-animations": false,"implementation": "synthetic"},"first-line": {@@ -91,12 +92,14 @@"FIXME: ruby-position","#inline-layout-properties"],+ "accepts-animations": false,"implementation": "synthetic"},"highlight": {"spec": "https://drafts.csswg.org/css-pseudo-4/#selectordef-highlight","type": "function",- "function-syntax": "<highlight-name-selector>"+ "function-syntax": "<highlight-name-selector>",+ "accepts-animations": false},"marker": {"spec": "https://drafts.csswg.org/css-pseudo-4/#selectordef-marker",@@ -136,6 +139,7 @@"stroke-width","#custom-properties"],+ "accepts-animations": false,"implementation": "synthetic"},"search-text-current": {@@ -151,6 +155,7 @@"stroke-width","#custom-properties"],+ "accepts-animations": false,"implementation": "synthetic"},"selection": {@@ -165,6 +170,7 @@"stroke-width","#custom-properties"],+ "accepts-animations": false,"implementation": "synthetic"},"slider-fill": {@@ -198,6 +204,7 @@"stroke-width","#custom-properties"],+ "accepts-animations": false,"implementation": "synthetic"},"view-transition": {diff --git a/Libraries/LibWeb/Rust/build.rs b/Libraries/LibWeb/Rust/build.rsindex cf20f4294bc..07a95830b76 100644--- a/Libraries/LibWeb/Rust/build.rs+++ b/Libraries/LibWeb/Rust/build.rs@@ -844,14 +844,21 @@ fn generate_property_metadata(manifest_dir: &Path, out_dir: &Path) -> Result<(),}Ok(result.into_iter().collect())};- let always_allowed_pseudo_properties = property_ids(+ let transition_and_animation_pseudo_properties = property_ids(property_groups- .get("#always-allowed-properties")- .ok_or("missing always-allowed pseudo-element property group")?,+ .get("#transition-and-animation-properties")+ .ok_or("missing transition and animation pseudo-element property group")?,)?;let mut pseudo_property_whitelist_rows = Vec::new();+ let mut pseudo_accepts_animations_rows = Vec::new();for name in ordered_pseudo_element_names(&pseudo_elements)? {let object = pseudo_elements[&name].as_object().unwrap();+ pseudo_accepts_animations_rows.push(+ object+ .get("accepts-animations")+ .and_then(serde_json::Value::as_bool)+ .unwrap_or(true),+ );let Some(whitelist) = object.get("property-whitelist") else {pseudo_property_whitelist_rows.push(" None,".to_string());continue;@@ -867,6 +874,7 @@ fn generate_property_metadata(manifest_dir: &Path, out_dir: &Path) -> Result<(),}// UnknownWebKit follows the known pseudo-elements and accepts all properties.pseudo_property_whitelist_rows.push(" None,".to_string());+ pseudo_accepts_animations_rows.push(true);// The longhands other longhands' computation reads, which are computed first.let manual_order = [@@ -1792,7 +1800,7 @@ fn generate_property_metadata(manifest_dir: &Path, out_dir: &Path) -> Result<(),.join("\n")));output.push_str(&format!(- "\npub(crate) static PSEUDO_ELEMENT_ALWAYS_ALLOWED_PROPERTIES: &[u16] = &{always_allowed_pseudo_properties:?};\n"+ "\npub(crate) static PSEUDO_ELEMENT_TRANSITION_AND_ANIMATION_PROPERTIES: &[u16] = &{transition_and_animation_pseudo_properties:?};\n"));let positional_shorthands: Vec<u16> = properties.iter()@@ -1814,6 +1822,10 @@ fn generate_property_metadata(manifest_dir: &Path, out_dir: &Path) -> Result<(),pseudo_property_whitelist_rows.len(),pseudo_property_whitelist_rows.join("\n")));+ output.push_str(&format!(+ "pub(crate) static PSEUDO_ELEMENT_ACCEPTS_ANIMATIONS: [bool; {}] = {pseudo_accepts_animations_rows:?};\n",+ pseudo_accepts_animations_rows.len(),+ ));std::fs::write(out_dir.join("property_metadata_generated.rs"), output)?;Ok(())}diff --git a/Libraries/LibWeb/Rust/src/css/property_metadata.rs b/Libraries/LibWeb/Rust/src/css/property_metadata.rsindex 89ef9f39e66..5f7b4348c58 100644--- a/Libraries/LibWeb/Rust/src/css/property_metadata.rs+++ b/Libraries/LibWeb/Rust/src/css/property_metadata.rs@@ -190,11 +190,11 @@ pub(crate) fn property_initial_value(property_id: u16) -> &'static str {}pub(crate) fn pseudo_element_supports_property(pseudo_element: u8, property_id: u16) -> bool {- if PSEUDO_ELEMENT_ALWAYS_ALLOWED_PROPERTIES+ if PSEUDO_ELEMENT_TRANSITION_AND_ANIMATION_PROPERTIES.binary_search(&property_id).is_ok(){- return true;+ return PSEUDO_ELEMENT_ACCEPTS_ANIMATIONS[pseudo_element as usize];}match PSEUDO_ELEMENT_PROPERTY_WHITELISTS[pseudo_element as usize] {Some(whitelist) => whitelist.binary_search(&property_id).is_ok(),@@ -202,8 +202,8 @@ pub(crate) fn pseudo_element_supports_property(pseudo_element: u8, property_id:}}-/// Whether a pseudo-element's own whitelist names the property, leaving out the properties every-/// pseudo-element accepts.+/// Whether a pseudo-element's own whitelist names the property, leaving out the transition and animation+/// properties.pub(crate) fn pseudo_element_whitelist_names_property(pseudo_element: u8, property_id: u16) -> bool {PSEUDO_ELEMENT_PROPERTY_WHITELISTS[pseudo_element as usize].is_some_and(|whitelist| whitelist.binary_search(&property_id).is_ok())diff --git a/Tests/LibWeb/Text/expected/css/highlight-pseudo-element-ignores-animations.txt b/Tests/LibWeb/Text/expected/css/highlight-pseudo-element-ignores-animations.txtnew file mode 100644index 00000000000..889264460b3--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/highlight-pseudo-element-ignores-animations.txt@@ -0,0 +1,3 @@+::selection: rgb(0, 128, 0)+::search-text: rgb(0, 128, 0)+::spelling-error: rgb(0, 128, 0)diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/first-letter-allowed-properties.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/first-letter-allowed-properties.txtindex f9d0837b7cf..d2525aaaf18 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/first-letter-allowed-properties.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/first-letter-allowed-properties.txt@@ -2,8 +2,7 @@ Harness status: OKFound 36 tests-35 Pass-1 Fail+36 PassPass pre test setupPass backgroundAttachment should be applied to first-letter pseudo elements.Pass backgroundBlendMode should be applied to first-letter pseudo elements.@@ -37,6 +36,6 @@ Pass textUnderlinePosition should be applied to first-letter pseudo elements.Pass verticalAlign should be applied to first-letter pseudo elements.Pass wordSpacing should be applied to first-letter pseudo elements.Pass position should not be applied to first-letter pseudo elements.-Fail transition should not be applied to first-letter pseudo elements.+Pass transition should not be applied to first-letter pseudo elements.Pass transform should not be applied to first-letter pseudo elements.Pass wordBreak should not be applied to first-letter pseudo elements.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/first-line-allowed-properties.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/first-line-allowed-properties.txtnew file mode 100644index 00000000000..0b3621f5ad2--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/first-line-allowed-properties.txt@@ -0,0 +1,118 @@+Harness status: OK++Found 112 tests++109 Pass+3 Fail+Pass retrieve style rule+Pass backgroundAttachment should be applied to first-line pseudo elements (display:block)+Pass backgroundBlendMode should be applied to first-line pseudo elements (display:block)+Pass backgroundClip should be applied to first-line pseudo elements (display:block)+Pass backgroundColor should be applied to first-line pseudo elements (display:block)+Pass backgroundImage should be applied to first-line pseudo elements (display:block)+Pass backgroundOrigin should be applied to first-line pseudo elements (display:block)+Pass backgroundPosition should be applied to first-line pseudo elements (display:block)+Pass backgroundRepeat should be applied to first-line pseudo elements (display:block)+Pass backgroundSize should be applied to first-line pseudo elements (display:block)+Pass color should be applied to first-line pseudo elements (display:block)+Pass fontFamily should be applied to first-line pseudo elements (display:block)+Pass fontFeatureSettings should be applied to first-line pseudo elements (display:block)+Pass fontKerning should be applied to first-line pseudo elements (display:block)+Pass fontSize should be applied to first-line pseudo elements (display:block)+Pass fontSizeAdjust should be applied to first-line pseudo elements (display:block)+Pass fontStyle should be applied to first-line pseudo elements (display:block)+Pass fontVariant should be applied to first-line pseudo elements (display:block)+Pass fontWeight should be applied to first-line pseudo elements (display:block)+Pass fontVariationSettings should be applied to first-line pseudo elements (display:block)+Pass letterSpacing should be applied to first-line pseudo elements (display:block)+Pass opacity should be applied to first-line pseudo elements (display:block)+Pass textDecoration should be applied to first-line pseudo elements (display:block)+Pass textJustify should be applied to first-line pseudo elements (display:block)+Pass textShadow should be applied to first-line pseudo elements (display:block)+Pass textTransform should be applied to first-line pseudo elements (display:block)+Pass textUnderlinePosition should be applied to first-line pseudo elements (display:block)+Pass verticalAlign should be applied to first-line pseudo elements (display:block)+Pass wordSpacing should be applied to first-line pseudo elements (display:block)+Fail border should not be applied to first-line pseudo elements (display:block)+Pass borderImage should not be applied to first-line pseudo elements (display:block)+Pass borderRadius should not be applied to first-line pseudo elements (display:block)+Pass margin should not be applied to first-line pseudo elements (display:block)+Pass padding should not be applied to first-line pseudo elements (display:block)+Pass position should not be applied to first-line pseudo elements (display:block)+Pass transition should not be applied to first-line pseudo elements (display:block)+Pass transform should not be applied to first-line pseudo elements (display:block)+Pass wordBreak should not be applied to first-line pseudo elements (display:block)+Pass backgroundAttachment should be applied to first-line pseudo elements (display:inline)+Pass backgroundBlendMode should be applied to first-line pseudo elements (display:inline)+Pass backgroundClip should be applied to first-line pseudo elements (display:inline)+Pass backgroundColor should be applied to first-line pseudo elements (display:inline)+Pass backgroundImage should be applied to first-line pseudo elements (display:inline)+Pass backgroundOrigin should be applied to first-line pseudo elements (display:inline)+Pass backgroundPosition should be applied to first-line pseudo elements (display:inline)+Pass backgroundRepeat should be applied to first-line pseudo elements (display:inline)+Pass backgroundSize should be applied to first-line pseudo elements (display:inline)+Pass color should be applied to first-line pseudo elements (display:inline)+Pass fontFamily should be applied to first-line pseudo elements (display:inline)+Pass fontFeatureSettings should be applied to first-line pseudo elements (display:inline)+Pass fontKerning should be applied to first-line pseudo elements (display:inline)+Pass fontSize should be applied to first-line pseudo elements (display:inline)+Pass fontSizeAdjust should be applied to first-line pseudo elements (display:inline)+Pass fontStyle should be applied to first-line pseudo elements (display:inline)+Pass fontVariant should be applied to first-line pseudo elements (display:inline)+Pass fontWeight should be applied to first-line pseudo elements (display:inline)+Pass fontVariationSettings should be applied to first-line pseudo elements (display:inline)+Pass letterSpacing should be applied to first-line pseudo elements (display:inline)+Pass opacity should be applied to first-line pseudo elements (display:inline)+Pass textDecoration should be applied to first-line pseudo elements (display:inline)+Pass textJustify should be applied to first-line pseudo elements (display:inline)+Pass textShadow should be applied to first-line pseudo elements (display:inline)+Pass textTransform should be applied to first-line pseudo elements (display:inline)+Pass textUnderlinePosition should be applied to first-line pseudo elements (display:inline)+Pass verticalAlign should be applied to first-line pseudo elements (display:inline)+Pass wordSpacing should be applied to first-line pseudo elements (display:inline)+Fail border should not be applied to first-line pseudo elements (display:inline)+Pass borderImage should not be applied to first-line pseudo elements (display:inline)+Pass borderRadius should not be applied to first-line pseudo elements (display:inline)+Pass margin should not be applied to first-line pseudo elements (display:inline)+Pass padding should not be applied to first-line pseudo elements (display:inline)+Pass position should not be applied to first-line pseudo elements (display:inline)+Pass transition should not be applied to first-line pseudo elements (display:inline)+Pass transform should not be applied to first-line pseudo elements (display:inline)+Pass wordBreak should not be applied to first-line pseudo elements (display:inline)+Pass backgroundAttachment should be applied to first-line pseudo elements (display:flex)+Pass backgroundBlendMode should be applied to first-line pseudo elements (display:flex)+Pass backgroundClip should be applied to first-line pseudo elements (display:flex)+Pass backgroundColor should be applied to first-line pseudo elements (display:flex)+Pass backgroundImage should be applied to first-line pseudo elements (display:flex)+Pass backgroundOrigin should be applied to first-line pseudo elements (display:flex)+Pass backgroundPosition should be applied to first-line pseudo elements (display:flex)+Pass backgroundRepeat should be applied to first-line pseudo elements (display:flex)+Pass backgroundSize should be applied to first-line pseudo elements (display:flex)+Pass color should be applied to first-line pseudo elements (display:flex)+Pass fontFamily should be applied to first-line pseudo elements (display:flex)+Pass fontFeatureSettings should be applied to first-line pseudo elements (display:flex)+Pass fontKerning should be applied to first-line pseudo elements (display:flex)+Pass fontSize should be applied to first-line pseudo elements (display:flex)+Pass fontSizeAdjust should be applied to first-line pseudo elements (display:flex)+Pass fontStyle should be applied to first-line pseudo elements (display:flex)+Pass fontVariant should be applied to first-line pseudo elements (display:flex)+Pass fontWeight should be applied to first-line pseudo elements (display:flex)+Pass fontVariationSettings should be applied to first-line pseudo elements (display:flex)+Pass letterSpacing should be applied to first-line pseudo elements (display:flex)+Pass opacity should be applied to first-line pseudo elements (display:flex)+Pass textDecoration should be applied to first-line pseudo elements (display:flex)+Pass textJustify should be applied to first-line pseudo elements (display:flex)+Pass textShadow should be applied to first-line pseudo elements (display:flex)+Pass textTransform should be applied to first-line pseudo elements (display:flex)+Pass textUnderlinePosition should be applied to first-line pseudo elements (display:flex)+Pass verticalAlign should be applied to first-line pseudo elements (display:flex)+Pass wordSpacing should be applied to first-line pseudo elements (display:flex)+Fail border should not be applied to first-line pseudo elements (display:flex)+Pass borderImage should not be applied to first-line pseudo elements (display:flex)+Pass borderRadius should not be applied to first-line pseudo elements (display:flex)+Pass margin should not be applied to first-line pseudo elements (display:flex)+Pass padding should not be applied to first-line pseudo elements (display:flex)+Pass position should not be applied to first-line pseudo elements (display:flex)+Pass transition should not be applied to first-line pseudo elements (display:flex)+Pass transform should not be applied to first-line pseudo elements (display:flex)+Pass wordBreak should not be applied to first-line pseudo elements (display:flex)\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/css/highlight-pseudo-element-ignores-animations.html b/Tests/LibWeb/Text/input/css/highlight-pseudo-element-ignores-animations.htmlnew file mode 100644index 00000000000..dd810b3e8ad--- /dev/null+++ b/Tests/LibWeb/Text/input/css/highlight-pseudo-element-ignores-animations.html@@ -0,0 +1,27 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+@keyframes recolor {+ from { color: rgb(255, 0, 0); }+ to { color: rgb(0, 0, 255); }+}+p::selection {+ color: rgb(0, 128, 0);+ animation: recolor 100s linear -50s paused;+}+p::search-text {+ color: rgb(0, 128, 0);+ animation: recolor 100s linear -50s paused;+}+p::spelling-error {+ color: rgb(0, 128, 0);+ animation: recolor 100s linear -50s paused;+}+</style>+<p id="target">Text</p>+<script>+ test(() => {+ for (const pseudoElement of ["::selection", "::search-text", "::spelling-error"])+ println(`${pseudoElement}: ${getComputedStyle(target, pseudoElement).color}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/first-line-allowed-properties.html b/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/first-line-allowed-properties.htmlnew file mode 100644index 00000000000..b1464c0c93e--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/first-line-allowed-properties.html@@ -0,0 +1,116 @@+<!DOCTYPE html>+<title>CSS Test: Properties allowed on ::first-line pseudo elements</title>+<link rel="help" href="https://drafts.csswg.org/css-pseudo-4/#first-line-styling">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<style>+ #target::first-line {}+ #target { visibility: hidden; }+</style>+<div id="target">text</div>+<script>+ let style;+ const target = document.querySelector("#target");+ const defaultComputedStyle = getComputedStyle(target);++ test(() => {+ var styleRule = document.styleSheets[0].cssRules[0];+ assert_equals(styleRule.selectorText, "#target::first-line", "make sure we have the correct style rule");+ style = styleRule.style;+ }, "retrieve style rule");++ const validProperties = {+ backgroundAttachment: "fixed",+ backgroundBlendMode: "hue",+ backgroundClip: "padding-box",+ backgroundColor: "rgb(10, 20, 30)",+ backgroundImage: "linear-gradient(rgb(0, 0, 0), rgb(255, 255, 255))",+ backgroundOrigin: "border-box",+ backgroundPosition: "50% 50%",+ backgroundRepeat: "no-repeat",+ backgroundSize: "10px 20px",+ color: "rgba(10, 20, 30, 0.4)",+ fontFamily: "sans-serif",+ fontFeatureSettings: '"vert" 2',+ fontKerning: "none",+ fontSize: "30px",+ fontSizeAdjust: "0.5",+ fontStyle: "italic",+ fontVariant: "small-caps",+ fontWeight: "900",+ fontVariationSettings: '"XHGT" 0.7',+ letterSpacing: "12px",+ opacity: "0.5",+ textDecoration: "overline wavy rgb(10, 20, 30)",+ textJustify: "none",+ textShadow: "rgb(10, 20, 30) 10px 20px 30px",+ textTransform: "capitalize",+ textUnderlinePosition: "under",+ verticalAlign: "12%",+ wordSpacing: "12px"+ };++ // The css-pseudo-4 specification says only certain properties _apply_,+ // which is different from computed values, but browsers implement this+ // interoperably. Also, the inheritance section saying properties not in+ // the list that apply to ::first-line are inherited from the non-pseudo+ // parent instead, is also an indication this is the intent of the spec.+ //+ // Similarly, there was a resolution for highlight pseudos along the same+ // lines:+ // https://github.com/w3c/csswg-drafts/issues/7591+ const invalidProperties = {+ border: "40px dotted rgb(10, 20, 30)",+ borderImage: "linear-gradient(rgb(0, 0, 0), rgb(255, 255, 255)) 10% / 20 / 30px repeat",+ borderRadius: "10px 20px",+ margin: "10px 20px 30px 40px",+ padding: "10px 20px 30px 40px",+ position: "absolute",+ transition: "transform 1s",+ transform: "rotate(45deg)",+ wordBreak: "break-all"+ };++ function testFirstLineProperty(property, rule, expected, reason) {+ test(function() {+ style[property] = "";+ style[property] = rule;+ assert_equals(getComputedStyle(target, "::first-line")[property], expected);+ style[property] = "";+ }, reason);+ }++ for (let property in validProperties) {+ testFirstLineProperty(property, validProperties[property], validProperties[property],+ property + " should be applied to first-line pseudo elements (display:block)");+ }++ for (let property in invalidProperties) {+ testFirstLineProperty(property, invalidProperties[property], defaultComputedStyle[property],+ property + " should not be applied to first-line pseudo elements (display:block)");+ }++ target.style.display = "inline";++ for (let property in validProperties) {+ testFirstLineProperty(property, validProperties[property], validProperties[property],+ property + " should be applied to first-line pseudo elements (display:inline)");+ }++ for (let property in invalidProperties) {+ testFirstLineProperty(property, invalidProperties[property], defaultComputedStyle[property],+ property + " should not be applied to first-line pseudo elements (display:inline)");+ }++ target.style.display = "flex";++ for (let property in validProperties) {+ testFirstLineProperty(property, validProperties[property], validProperties[property],+ property + " should be applied to first-line pseudo elements (display:flex)");+ }++ for (let property in invalidProperties) {+ testFirstLineProperty(property, invalidProperties[property], defaultComputedStyle[property],+ property + " should not be applied to first-line pseudo elements (display:flex)");+ }+</script>