Truly independent web browser
LibWeb: Restyle below a style query's container as its siblings move
Andreas Kling765301635f5a
diff --git a/Libraries/LibWeb/Rust/src/css/custom_properties.rs b/Libraries/LibWeb/Rust/src/css/custom_properties.rsindex c6003b78a09..c8ba427bdb7 100644--- a/Libraries/LibWeb/Rust/src/css/custom_properties.rs+++ b/Libraries/LibWeb/Rust/src/css/custom_properties.rs@@ -2753,12 +2753,15 @@ pub(crate) fn evaluate_retained_container_style_feature(length_resolution_context: &crate::css::style_compute::FfiLengthResolutionContext,color_resolution_input: crate::css::color_resolution::ColorResolutionInput<'_>,tree_counting: Option<(u64, u64)>,+ read_sibling_position: &mut bool,) -> MatchResult {+ let mut dependencies = None;let mut context = ASFResolutionContext {inheritance_store: store.and_then(|store| store.inheritance_parent.as_deref()),style_query_length_resolution_context: Some(length_resolution_context),style_query_color_resolution_input: Some(color_resolution_input),style_query_tree_counting: tree_counting,+ style_query_dependencies: Some(&mut dependencies),..Default::default()};let registry = Some(registry);@@ -2769,6 +2772,8 @@ pub(crate) fn evaluate_retained_container_style_feature(}StyleFeature::Range { .. } => evaluate_style_range(store, registry, feature, &mut context, 0),};+ *read_sibling_position |=+ dependencies.is_some_and(|dependencies: Box<StyleQueryDependencies>| dependencies.sibling_position);match result {ConditionEvaluation::Match(true) => MatchResult::True,ConditionEvaluation::Match(false) => MatchResult::False,diff --git a/Libraries/LibWeb/Rust/src/css/style/container_queries.rs b/Libraries/LibWeb/Rust/src/css/style/container_queries.rsindex 2724d972604..8961a5b17e0 100644--- a/Libraries/LibWeb/Rust/src/css/style/container_queries.rs+++ b/Libraries/LibWeb/Rust/src/css/style/container_queries.rs@@ -8,6 +8,8 @@//! container query inputs, the previous layout's boxes and the containers' style records.use super::bridge::FfiContainerEffectKind;+use super::selector_evaluation::StructuralRead;+use super::transaction_view::TransactionFactSide;use super::tree::StyleNodeID;use super::*;use crate::css::computed_longhand_table::FONT_METRICS_DEPEND_ON_VIEWPORT_METRICS;@@ -627,6 +629,7 @@ impl RetainedState {.effects.push((candidate, FfiContainerEffectKind::NeedsEvaluationAfterLayout));}+ let mut read_sibling_position = false;// SAFETY: The facts' length context is live for the call.let result = unsafe {crate::css::parser::query_parser::evaluate_container_query(query, &facts, &mut |feature| {@@ -640,9 +643,22 @@ impl RetainedState {&length,context.color,context.tree_counting,+ &mut read_sibling_position,)})};+ // NB: Its siblings moving is what moves the answer, as for a record reading its own place.+ if read_sibling_position {+ self.containers_counted_by_style_queries+ .lock()+ .expect("the counted containers are never held across a panic")+ .insert(candidate);+ self.projection.note_structural_read(+ TransactionFactSide::After,+ candidate,+ StructuralRead::SiblingPositionValue,+ );+ }if resolved_viewport_relative_length {verdict.effectsdiff --git a/Libraries/LibWeb/Rust/src/css/style/inputs.rs b/Libraries/LibWeb/Rust/src/css/style/inputs.rsindex 4346c96e119..87ecce34165 100644--- a/Libraries/LibWeb/Rust/src/css/style/inputs.rs+++ b/Libraries/LibWeb/Rust/src/css/style/inputs.rs@@ -1595,6 +1595,7 @@ impl StyleEngine {html_element_namespace: StyleAtomID::NONE,sibling_positions: crate::fork::ForkReset::default(),+ containers_counted_by_style_queries: Default::default(),cold_pass_report: [0; pipeline::ReportField::COUNT],live_style: None,live_style_may_start: crate::fork::ForkReset::original(),@@ -2492,6 +2493,8 @@ impl RetainedState {// Scratch of one traversal.// Keyed by the tree's DOM order version.sibling_positions: _,+ // Too many only walk more, and an element's identity is used again.+ containers_counted_by_style_queries: _,// Dropped in `forget_departed_elements` when a relation holds a departed element.// Scratch of one transaction.// Not keyed by style node.diff --git a/Libraries/LibWeb/Rust/src/css/style/mod.rs b/Libraries/LibWeb/Rust/src/css/style/mod.rsindex 2081d18a2b1..3b3057a1e71 100644--- a/Libraries/LibWeb/Rust/src/css/style/mod.rs+++ b/Libraries/LibWeb/Rust/src/css/style/mod.rs@@ -332,6 +332,9 @@ pub struct RetainedState {/// The places of the children of parents with many of them, which sibling-counting functions/// read, kept while the tree's DOM order stands.sibling_positions: crate::fork::ForkReset<Mutex<publication::SiblingPositionCache>>,+ /// The elements a style() container query asked as containers with a value counting their place among their+ /// siblings. A fork shares them, as too many only walk more. An element's identity used again stays here too.+ containers_counted_by_style_queries: Arc<Mutex<HashSet<StyleNodeID>>>,/// What the last the engine cold pass measured.cold_pass_report: pipeline::Report,/// The engine kept live beside this engine, when asked for, which a fork goes on keeping.diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rsindex fcf0fed69e7..22a535fdef5 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs@@ -28,8 +28,9 @@ use super::rule_changes::Restyled;use super::rule_store::RuleChanges;use super::rules::{IndexChanges, RuleIndex};use super::traversal::{- self, DIRTY_DESCENDANTS, HintBits, InitialStyle, MATCH_DESCENDANTS, MATCH_SELF, PARENT_CHANGED, PassContext,- RECOMPUTE_SELF, RESTYLE_DESCENDANTS, RESTYLE_PSEUDO_ELEMENTS, RESTYLE_SELF, RESTYLES_SELF, STYLES_SOMETHING,+ self, CONTAINERS_MOVED, DIRTY_DESCENDANTS, HintBits, InitialStyle, MATCH_DESCENDANTS, MATCH_SELF, PARENT_CHANGED,+ PassContext, RECOMPUTE_SELF, RESTYLE_DESCENDANTS, RESTYLE_PSEUDO_ELEMENTS, RESTYLE_SELF, RESTYLES_SELF,+ STYLES_SOMETHING,};use crate::cow_column::CowColumn;use crate::css::style::custom_property_cascade::{@@ -1206,7 +1207,8 @@ impl Live {// An element arriving, leaving or moving among its siblings changes what `sibling-index()`// and `sibling-count()` compute to for its siblings.for &parent in sibling_parents.iter() {- // NB: Every record reading it noted so on its element's parent as it was held.+ // NB: Every record reading it noted so on its element's parent as it was held, and every style query+ // reading it on its container's parent as it answered.if !tree.is_live(parent)|| !projection.structural_flags(parent)@@ -1214,6 +1216,10 @@ impl Live {{continue;}+ let counted_containers = state+ .containers_counted_by_style_queries+ .lock()+ .expect("the counted containers are never held across a panic");for child in projection.children(parent) {if self.records@@ -1227,6 +1233,11 @@ impl Live {{self.hints.add(child, RESTYLE_SELF);}+ // A style() query counted where this child stands as a container, which no record of it may read: the+ // elements below it that read their containers read them anew.+ if counted_containers.contains(&child) {+ self.hints.add(child, CONTAINERS_MOVED);+ }}}diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rsindex 8d59cc16610..12ed9122325 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs@@ -699,7 +699,8 @@ impl StructuralFlags {pub(in crate::css::style) const CHILDREN_READ_POSITIONS: Self = Self(1 << 2);/// A selector read whether the element is `:empty`.pub(in crate::css::style) const READ_EMPTINESS: Self = Self(1 << 3);- /// The record of a child, or of a pseudo-element of it, computes from its place among its siblings.+ /// The record of a child, or of a pseudo-element of it, or a style query asking the child as a container, computes+ /// from its place among its siblings.pub(in crate::css::style) const CHILD_READS_SIBLING_POSITION: Self = Self(1 << 4);/// A selector read where a child stands counted from the end.pub(in crate::css::style) const CHILDREN_READ_POSITIONS_FROM_END: Self = Self(1 << 5);diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rsindex 528a55c8203..7e1f9c4b9de 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs@@ -203,7 +203,7 @@ pub(super) const PARENT_CHANGED: HintBits = 1 << 5;const PARENT_RESTYLED: HintBits = 1 << 6;/// An ancestor of the element describes another container than it did, which the elements below/// it that read their containers are restyled for.-const CONTAINERS_MOVED: HintBits = 1 << 7;+pub(super) const CONTAINERS_MOVED: HintBits = 1 << 7;/// The element is restyled for its pseudo-elements, which inherit the composition of its/// animations that moved, as under a parent that changed. Where nothing else restyles it, the/// host owes it no other composition.diff --git a/Tests/LibWeb/Text/expected/css/style-engine/container-style-query-tree-counting-invalidation.txt b/Tests/LibWeb/Text/expected/css/style-engine/container-style-query-tree-counting-invalidation.txtindex 54a84084f9a..a6bdef8e027 100644--- a/Tests/LibWeb/Text/expected/css/style-engine/container-style-query-tree-counting-invalidation.txt+++ b/Tests/LibWeb/Text/expected/css/style-engine/container-style-query-tree-counting-invalidation.txt@@ -4,10 +4,10 @@ as written:sibling-count(): nosibling-index() in a custom function: nosiblings removed:- sibling-index(): no- sibling-index() on a pseudo-element: no- sibling-count(): no- sibling-index() in a custom function: no+ sibling-index(): yes+ sibling-index() on a pseudo-element: yes+ sibling-count(): yes+ sibling-index() in a custom function: yessiblings added:sibling-index(): nosibling-index() on a pseudo-element: nodiff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-values/tree-counting/sibling-function-container-query-invalidation.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-values/tree-counting/sibling-function-container-query-invalidation.txtindex 87841866d85..1d971d4bc1c 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-values/tree-counting/sibling-function-container-query-invalidation.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-values/tree-counting/sibling-function-container-query-invalidation.txt@@ -2,13 +2,13 @@ Harness status: OKFound 8 tests-4 Pass-4 Fail+6 Pass+2 FailPass sibling-index() in @container width query initially not matchingPass sibling-count() in @container width query initially not matchingPass sibling-index() in @container style() query initially not matchingPass sibling-count() in @container style() query initially not matchingFail sibling-index() in @container width query matching after removalFail sibling-count() in @container width query matching after removal-Fail sibling-index() in @container style() query matching after removal-Fail sibling-count() in @container style() query matching after removal\ No newline at end of file+Pass sibling-index() in @container style() query matching after removal+Pass sibling-count() in @container style() query matching after removal\ No newline at end of file