Skip to content

Truly independent web browser

LibWeb: Ask only the element about registered custom properties

Andreas Kling8c64b07f5a9d
diff --git a/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs b/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs
index 30b4d78616f..33317bd87e9 100644
--- a/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs
@@ -423,11 +423,15 @@ pub(super) fn append_named_custom_property_reads(value: &StyleValueData, names:
}
/// The custom properties a written value reads by name, or `None` when it may read others: an
-/// `if()` condition, a custom function or an attribute's value can read any.
+/// `if()` condition, a custom function or an attribute's value can read any, and `inherit()` reads
+/// what the parent holds, which holds more than it hands down.
fn named_custom_property_reads(value: &StyleValueData) -> Option<Vec<&[u16]>> {
let value = substituted_tokens(value);
if let StyleValueData::Unresolved(unresolved) = value
- && (unresolved.presence().attr || unresolved.presence().dashed_function || unresolved.presence().if_)
+ && (unresolved.presence().attr
+ || unresolved.presence().dashed_function
+ || unresolved.presence().if_
+ || unresolved.presence().inherit)
{
return None;
}
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs
index 31153c7b2e9..21b4890e307 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs
@@ -1609,7 +1609,8 @@ impl<'a> Scratch<'a> {
};
// What the element's pseudo-elements and animations compute reads the element's custom
// properties beyond its own record, as do transitions, which start from the values that
- // moved. A registered custom property computes against the element's own context.
+ // moved. A custom property the element declares that is registered computes against the
+ // element's own context, where one it only inherits arrives computed.
if !records.pseudo_element_records(node).is_empty()
|| records.composition(node).is_some()
|| records.sampled_custom_properties(node).is_some()
@@ -1622,10 +1623,11 @@ impl<'a> Scratch<'a> {
crate::css::property_metadata::property_id::TRANSITION_DURATION,
)),
)
- || state
- .document_style_computation_inputs
- .custom_property_registry()
- .has_registrations()
+ || old.custom_declarations().is_some_and(|declarations| {
+ declarations
+ .iter()
+ .any(|(declared, _)| state.custom_property_name_is_registered(declared.name))
+ })
{
return false;
}
diff --git a/Tests/LibWeb/Text/expected/css/style-engine/custom-property-move-with-registered-properties.txt b/Tests/LibWeb/Text/expected/css/style-engine/custom-property-move-with-registered-properties.txt
new file mode 100644
index 00000000000..9441d4de9b6
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/style-engine/custom-property-move-with-registered-properties.txt
@@ -0,0 +1,20 @@
+initially
+own: width=20px inherited=10px own=20px theme=1
+inherited: width=10px inherited=10px own=0px theme=1
+theme: width=1px inherited=10px own=0px theme=1
+unrelated: width=3px inherited=10px own=0px theme=1
+after moving an unregistered custom property
+own: width=40px inherited=10px own=40px theme=2
+inherited: width=10px inherited=10px own=0px theme=2
+theme: width=2px inherited=10px own=0px theme=2
+unrelated: width=3px inherited=10px own=0px theme=2
+after moving an inherited registered custom property
+own: width=40px inherited=30px own=40px theme=2
+inherited: width=30px inherited=30px own=0px theme=2
+theme: width=2px inherited=30px own=0px theme=2
+unrelated: width=3px inherited=30px own=0px theme=2
+after setting a registered custom property that does not inherit
+own: width=40px inherited=30px own=40px theme=2
+inherited: width=30px inherited=30px own=0px theme=2
+theme: width=2px inherited=30px own=0px theme=2
+unrelated: width=3px inherited=30px own=0px theme=2
diff --git a/Tests/LibWeb/Text/expected/css/style-invalidation/animated-custom-property-stops-where-descendants-reset-it.txt b/Tests/LibWeb/Text/expected/css/style-invalidation/animated-custom-property-stops-where-descendants-reset-it.txt
index e5bb0b62b1d..c3dfe9941e1 100644
--- a/Tests/LibWeb/Text/expected/css/style-invalidation/animated-custom-property-stops-where-descendants-reset-it.txt
+++ b/Tests/LibWeb/Text/expected/css/style-invalidation/animated-custom-property-stops-where-descendants-reset-it.txt
@@ -1,7 +1,7 @@
reader in an element a slot takes: 90deg
deep reader below non-readers: 90deg
deep reader after a step: 180deg
-elements below the reset restyled: 100
+elements below the reset restyled: 0
reader below the reset: 0deg
reader declaring its own below a registered declaration: 90deg
that reader after a step: 180deg
diff --git a/Tests/LibWeb/Text/input/css/style-engine/custom-property-move-with-registered-properties.html b/Tests/LibWeb/Text/input/css/style-engine/custom-property-move-with-registered-properties.html
new file mode 100644
index 00000000000..5109d617acc
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/style-engine/custom-property-move-with-registered-properties.html
@@ -0,0 +1,70 @@
+<!doctype html>
+<script src="../../include.js"></script>
+<style>
+ @property --unrelated {
+ syntax: "<number>";
+ inherits: false;
+ initial-value: 0;
+ }
+ @property --inherited-length {
+ syntax: "<length>";
+ inherits: true;
+ initial-value: 0px;
+ }
+ @property --own-length {
+ syntax: "<length>";
+ inherits: true;
+ initial-value: 0px;
+ }
+ #root {
+ --theme: 1;
+ --inherited-length: 1em;
+ font-size: 10px;
+ }
+ .declares-registered {
+ font-size: 20px;
+ --own-length: calc(var(--theme) * 1em);
+ }
+ .reads-own {
+ width: var(--own-length);
+ }
+ .reads-inherited {
+ width: var(--inherited-length);
+ }
+ .reads-theme {
+ width: calc(var(--theme) * 1px);
+ }
+ .reads-unrelated {
+ width: calc((var(--unrelated) + 3) * 1px);
+ }
+</style>
+<div id="root">
+ <div>
+ <div class="declares-registered"><div id="own" class="reads-own"></div></div>
+ <div id="inherited" class="reads-inherited"></div>
+ <div id="theme" class="reads-theme"></div>
+ <div id="unrelated" class="reads-unrelated"></div>
+ </div>
+</div>
+<script>
+ test(() => {
+ const report = title => {
+ println(title);
+ for (const id of ["own", "inherited", "theme", "unrelated"]) {
+ const style = getComputedStyle(document.getElementById(id));
+ const inherited = style.getPropertyValue("--inherited-length");
+ const own = style.getPropertyValue("--own-length");
+ const theme = style.getPropertyValue("--theme");
+ println(`${id}: width=${style.width} inherited=${inherited} own=${own} theme=${theme}`);
+ }
+ };
+ const root = document.getElementById("root");
+ report("initially");
+ root.style.setProperty("--theme", "2");
+ report("after moving an unregistered custom property");
+ root.style.setProperty("--inherited-length", "3em");
+ report("after moving an inherited registered custom property");
+ root.style.setProperty("--unrelated", "4");
+ report("after setting a registered custom property that does not inherit");
+ });
+</script>