Skip to content

Truly independent web browser

LibWeb: Restyle below an element that waited on fonts in every round

Andreas Klingf892d98c5f98
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs
index 9a4d8c739f5..e4154353799 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs
@@ -662,7 +662,8 @@ impl Live {
///
/// The pass styled nothing of an element in `waiting`, nor anything below it: the next one
/// restyles the element, and its descendants where this one restyled every element or the
- /// descendants of the element or of an ancestor. Elsewhere the hints of the elements below it
+ /// descendants of the element or of an ancestor, as `waiting_restyling_descendants` holds where the pass's
+ /// walk asked that of the element, such as below an element displayed again. Elsewhere the hints of the elements below it
/// stay for the next pass, and its children are restyled where its style moves.
///
/// The next pass computes an element in `waiting_with_kept_matches`, which the pass matched to
@@ -677,11 +678,13 @@ impl Live {
waiting: &[StyleNodeID],
waiting_with_kept_matches: &[StyleNodeID],
waiting_pseudo_elements: &[StyleNodeID],
+ waiting_restyling_descendants: &HashSet<StyleNodeID>,
) -> Vec<(StyleNodeID, HintBits)> {
let kept_matches: HashSet<StyleNodeID> = waiting_with_kept_matches.iter().copied().collect();
let element = waiting.iter().map(|&node| {
let tree = &state.projection;
let restyles_descendants = !hinted
+ || waiting_restyling_descendants.contains(&node)
|| std::iter::successors(Some(node), |&ancestor| tree.inheritance_parent(ancestor))
.any(|ancestor| self.hints.get(ancestor) & RESTYLE_DESCENDANTS != 0);
let bits = match restyles_descendants {
@@ -2156,6 +2159,7 @@ impl Live {
let (mut root_font, mut root_font_moved) = (None, None);
let mut statistics = traversal::Statistics::default();
let mut suspended = None;
+ let mut waiting_restyling_descendants = HashSet::default();
for round in 1..=MAX_SUSPENDING_ROUNDS {
let state: &RetainedState = retained;
let reasons = self.hints.reasons();
@@ -2188,7 +2192,8 @@ impl Live {
break;
}
if round == MAX_SUSPENDING_ROUNDS {
- traversal::settle_suspended(&context, std::mem::take(&mut statistics.suspended));
+ waiting_restyling_descendants =
+ traversal::settle_suspended(&context, std::mem::take(&mut statistics.suspended));
break;
}
let (next, fonts, random_bases) = statistics.take_suspended();
@@ -2306,6 +2311,7 @@ impl Live {
&statistics.waiting,
&statistics.waiting_with_kept_matches,
&statistics.waiting_pseudo_elements,
+ &waiting_restyling_descendants,
);
self.keep_deferred_hints(&state.projection, &statistics.deferred, &waiting);
let styled = Instant::now();
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs
index afd9c3a8f98..34eacb3e058 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs
@@ -2830,14 +2830,24 @@ pub(super) fn resume(
/// Keep the records of the pseudo-elements `suspended` holds back that did not wait, as no round
/// resumes them: the next pass styles the others.
-pub(super) fn settle_suspended(context: &PassContext<'_>, suspended: Vec<Suspended>) {
+///
+/// Answers the elements whose ancestors asked this pass to restyle what is below them, which only the elements themselves
+/// knew: the next pass restyles those too.
+pub(super) fn settle_suspended(context: &PassContext<'_>, suspended: Vec<Suspended>) -> HashSet<StyleNodeID> {
+ let mut restyling_descendants = HashSet::default();
for suspended in suspended {
- if let Suspended::PseudoElements(suspended) = suspended {
- context
+ match suspended {
+ Suspended::Element(queued) => {
+ if queued.hint & RESTYLE_DESCENDANTS != 0 {
+ restyling_descendants.insert(queued.node);
+ }
+ }
+ Suspended::PseudoElements(suspended) => context
.records
- .insert_pseudo_element_records(suspended.node, suspended.records);
+ .insert_pseudo_element_records(suspended.node, suspended.records),
}
}
+ restyling_descendants
}
/// Style the pseudo-elements of `pseudo_elements`, and the elements `queued` makes of `elements`
diff --git a/Tests/LibWeb/Text/expected/css/selector-match-below-shown-root-past-font-waits.txt b/Tests/LibWeb/Text/expected/css/selector-match-below-shown-root-past-font-waits.txt
index eb03044a9b2..41531a0cf3a 100644
--- a/Tests/LibWeb/Text/expected/css/selector-match-below-shown-root-past-font-waits.txt
+++ b/Tests/LibWeb/Text/expected/css/selector-match-below-shown-root-past-font-waits.txt
@@ -1,2 +1,2 @@
before: rgb(255, 0, 0)
-after: rgb(255, 0, 0)
+after: rgb(0, 0, 0)