Skip to content

Truly independent web browser

LibWeb: Do not share style records across a substituted inherit

Andreas Klingd820885a764f
diff --git a/Libraries/LibWeb/Rust/src/css/style/publication.rs b/Libraries/LibWeb/Rust/src/css/style/publication.rs
index 561d39fb7c7..3822b6fed42 100644
--- a/Libraries/LibWeb/Rust/src/css/style/publication.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/publication.rs
@@ -1562,10 +1562,23 @@ impl RetainedState {
self.note_node_substitution(node, scratch, state, environment);
// A record whose winners read beyond its environment is the element's alone, as is one
// declaring registered custom properties, which its own font decides. The key is the one
- // above, with the environment the element's declarations resolved.
+ // above, with the environment the element's declarations resolved. A substitution that
+ // made a non-inherited longhand `inherit` pins the parent's record, as a written `inherit`
+ // does.
let cache_key = cache_key
.filter(|_| !has_registered_declarations)
- .map(|key| ColdRecordKey { environment, ..key });
+ .map(|key| ColdRecordKey {
+ environment,
+ parent: ColdRecordParent {
+ record: if store.substitutes_inherit_for_non_inherited_property(self) {
+ parent_record.map_or(0, |record| record.raw())
+ } else {
+ key.parent.record
+ },
+ ..key.parent
+ },
+ ..key
+ });
if let Some(delta) = self.assign_cached_cold_record(
node,
target,
@@ -2973,8 +2986,13 @@ impl RetainedState {
return;
};
// A record whose winners read beyond its environment is the element's alone, as is one
- // `records_are_the_elements_alone` says is.
- if self.state_reads_beyond_environment(node, cascade_state.1) || self.records_are_the_elements_alone(node) {
+ // `records_are_the_elements_alone` says is. Nor is one whose winners substitute kept: what
+ // they substituted to is C++'s, and a substitution can make a non-inherited property
+ // `inherit`, which neither the key nor the record's explicitly inherited groups would show.
+ if self.state_reads_beyond_environment(node, cascade_state.1)
+ || self.records_are_the_elements_alone(node)
+ || self.state_has_substitutions(node, cascade_state.1)
+ {
return;
}
let Some(parent) = self.cold_record_parent(node, parent, parent_record, cascade_state.1) else {
diff --git a/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rs b/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rs
index 75d2139f484..13512b946a2 100644
--- a/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rs
@@ -434,10 +434,10 @@ impl RetainedState {
}
// What the record is derived from: the element's inherited style, display and
// environment, and the element's record itself only when the state inherits a
- // non-inherited property from it, or when the element's animations sampled values
- // into its inherited style. A record whose winners read beyond its environment is
- // the originating element's alone, as is one declaring registered custom properties,
- // which its own font decides.
+ // non-inherited property from it, written or substituted, or when the element's
+ // animations sampled values into its inherited style. A record whose winners read
+ // beyond its environment is the originating element's alone, as is one declaring
+ // registered custom properties, which its own font decides.
let key = self
.computed_group_sets
.node_inherited_groups_identity(node)
@@ -450,6 +450,7 @@ impl RetainedState {
parent_record: if pseudo_kind::is_highlight(kind)
|| kind == BACKDROP
|| state.is_some_and(|state| self.state_explicitly_inherits_non_inherited_property(node, state))
+ || store.substitutes_inherit_for_non_inherited_property(self)
|| !self.computed_group_sets.record_inherits_as_its_base(new_element_record)
{
new_element_record.raw()
diff --git a/Libraries/LibWeb/Rust/src/css/style/publication/winner_store.rs b/Libraries/LibWeb/Rust/src/css/style/publication/winner_store.rs
index e68d8a833e3..6249b4d2c91 100644
--- a/Libraries/LibWeb/Rust/src/css/style/publication/winner_store.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/publication/winner_store.rs
@@ -156,6 +156,19 @@ impl WinnerStore {
.any(|declaration| view.dependencies(declaration).uses_tree_counting_function)
}
+ /// Whether a substitution made a non-inherited longhand `inherit`, which its written value
+ /// does not show: the value is then read from the parent's record, not its inherited style.
+ pub(super) fn substitutes_inherit_for_non_inherited_property(&self, engine: &RetainedState) -> bool {
+ let view = self.view(engine);
+ self.declarations.iter().any(|declaration| {
+ matches!(declaration.value, WinnerValue::Substituted { .. })
+ && declaration.property >= crate::css::property_metadata::FIRST_LONGHAND_PROPERTY_ID
+ && !crate::css::property_metadata::property_is_inherited(declaration.property)
+ && matches!(view.value(declaration).data(), StyleValueData::Keyword { keyword }
+ if *keyword == crate::css::style_compute::keyword::INHERIT)
+ })
+ }
+
/// The proof that no value the store holds resolves a `url()`, or `None` when one may.
pub(super) fn reads_no_resource_contexts(&self, engine: &RetainedState) -> Option<ReadsNoResourceContexts> {
let view = self.view(engine);
diff --git a/Tests/LibWeb/Text/expected/css/style-engine/substituted-inherit-is-not-shared-across-parents.txt b/Tests/LibWeb/Text/expected/css/style-engine/substituted-inherit-is-not-shared-across-parents.txt
index 76d0ca7c404..15f38f004f1 100644
--- a/Tests/LibWeb/Text/expected/css/style-engine/substituted-inherit-is-not-shared-across-parents.txt
+++ b/Tests/LibWeb/Text/expected/css/style-engine/substituted-inherit-is-not-shared-across-parents.txt
@@ -1,6 +1,6 @@
narrow child: 20px
-wide child: 20px
-later wide child: 20px
+wide child: 40px
+later wide child: 40px
shallow ::before width with margin: 30
deep ::before width with margin: 50
later deep ::before width with margin: 50