Skip to content

Truly independent web browser

LibWeb: Wait for as many fonts as a demand's inherited chain asks for

Andreas Kling475ae1cd902b
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/mod.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/mod.rs
index d7f65053049..cb9403fa36b 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/mod.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/mod.rs
@@ -128,6 +128,10 @@ pub(super) struct Waits {
/// what its descendants wait on, so each round can find more.
const MAX_RESOLVE_ROUNDS: usize = 32;
+/// How many more rounds a computation may wait for each element it inherits through, each of which it may compute with
+/// a few fonts of its own and the random base values it draws in one round.
+const MAX_RESOLVE_ROUNDS_PER_ANCESTOR: usize = 4;
+
impl StyleEngine {
/// Runs `body` with the fonts of the document found by the content of their requests: a round
/// computes the values its font requests name anew, so the fonts the round before asked for are
@@ -155,7 +159,9 @@ impl StyleEngine {
mut attempt: impl FnMut(&mut Self) -> Result<T, Waits>,
) -> Option<T> {
self.matching_fonts_by_content(|engine| {
- for _ in 0..MAX_RESOLVE_ROUNDS {
+ let mut rounds = 0;
+ let mut max_rounds = MAX_RESOLVE_ROUNDS;
+ while rounds < max_rounds {
match attempt(engine) {
Ok(answer) => return Some(answer),
Err(waits) => {
@@ -167,6 +173,14 @@ impl StyleEngine {
}
}
}
+ rounds += 1;
+ if rounds == MAX_RESOLVE_ROUNDS {
+ let projection = &engine.retained.projection;
+ let ancestors = std::iter::successors(projection.inheritance_parent(node), |&parent| {
+ projection.inheritance_parent(parent)
+ });
+ max_rounds += MAX_RESOLVE_ROUNDS_PER_ANCESTOR * ancestors.count();
+ }
}
None
})
diff --git a/Tests/LibWeb/Text/expected/css/svg-resource-below-display-none-through-many-fonts.txt b/Tests/LibWeb/Text/expected/css/svg-resource-below-display-none-through-many-fonts.txt
new file mode 100644
index 00000000000..32a325949e5
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/svg-resource-below-display-none-through-many-fonts.txt
@@ -0,0 +1,2 @@
+shape: 10
+font of the gradient: font-of-level-59
diff --git a/Tests/LibWeb/Text/input/css/svg-resource-below-display-none-through-many-fonts.html b/Tests/LibWeb/Text/input/css/svg-resource-below-display-none-through-many-fonts.html
new file mode 100644
index 00000000000..32d4d37e527
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/svg-resource-below-display-none-through-many-fonts.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<body>
+<script src="../include.js"></script>
+<svg id="sprite" style="display: none"></svg>
+<svg width="10" height="10"><rect id="shape" width="10" height="10" fill="url(#gradient)" /></svg>
+<script>
+ asyncTest(done => {
+ // The style engine keeps the style of the gradient, below an element that is not displayed, by computing the
+ // elements it inherits through, each of which waits on a font of its own.
+ let parent = sprite;
+ for (let level = 0; level < 60; ++level) {
+ const group = document.createElementNS("http://www.w3.org/2000/svg", "g");
+ group.style.fontFamily = `font-of-level-${level}`;
+ group.style.fontSize = `${10 + level}px`;
+ parent.append(group);
+ parent = group;
+ }
+ const gradient = document.createElementNS("http://www.w3.org/2000/svg", "linearGradient");
+ gradient.id = "gradient";
+ parent.append(gradient);
+ requestAnimationFrame(() => {
+ requestAnimationFrame(() => {
+ println(`shape: ${shape.getBoundingClientRect().width}`);
+ println(`font of the gradient: ${getComputedStyle(gradient).fontFamily}`);
+ done();
+ });
+ });
+ });
+</script>