Skip to content

Truly independent web browser

LibWeb: Don’t describe layer owners while style work is pending

sideshowbarker5cc3cf8b26f3
diff --git a/Libraries/LibWeb/CSS/UpdateStyle.cpp b/Libraries/LibWeb/CSS/UpdateStyle.cpp
index 6ebaa50813e..f5c4378d985 100644
--- a/Libraries/LibWeb/CSS/UpdateStyle.cpp
+++ b/Libraries/LibWeb/CSS/UpdateStyle.cpp
@@ -949,6 +949,11 @@ void Document::update_style()
}
}
+bool Document::has_style_work(Layout::BegunRead const& read) const
+{
+ return CSS::document_has_style_work(read, *this);
+}
+
bool Document::let_style_update_fly(Layout::RustFFI::FfiFlightBlocker blocker)
{
if (blocker != Layout::RustFFI::FfiFlightBlocker::None || m_flown_style_update_inputs.has_value())
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h
index f7bdac780cb..df140647fde 100644
--- a/Libraries/LibWeb/DOM/Document.h
+++ b/Libraries/LibWeb/DOM/Document.h
@@ -669,6 +669,8 @@ public:
void update_style_and_layout_once(Layout::BegunRead const&, UpdateLayoutReason, ThrottledAnimationSamplingScope);
void update_layout_if_needed_for_node(Node const&, UpdateLayoutReason);
[[nodiscard]] bool layout_is_up_to_date() const;
+ // Whether anything the document's style depends on may have moved since its last style update.
+ [[nodiscard]] bool has_style_work(Layout::BegunRead const&) const;
[[nodiscard]] bool layout_is_known_stale() const;
void clear_devtools_layout_inspection_data();
void sample_animation_effects_needing_style_update();
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index e413f957133..13e1adcbea5 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -1673,6 +1673,11 @@ void Internals::update_visual_contexts_for_testing()
Layout::RustFFI::render_state_prepare_paint_properties_for_testing(document.layout_node_arena().host(), read);
}
+u64 Internals::describe_owners_of_visual_context_nodes()
+{
+ return Painting::describe_owners_of_visual_context_nodes(window().associated_document(), {}, {}).structural_epoch;
+}
+
void Internals::begin_input_trace()
{
page().input_trace().begin();
diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.h
index 754e3d418d8..ababdb1c966 100644
--- a/Libraries/LibWeb/Internals/Internals.h
+++ b/Libraries/LibWeb/Internals/Internals.h
@@ -194,6 +194,7 @@ public:
void begin_visual_context_trace();
Utf16String take_visual_context_trace();
void update_visual_contexts_for_testing();
+ u64 describe_owners_of_visual_context_nodes();
Utf16String take_display_list_trace();
void begin_input_trace();
GC::Ref<JS::Object> take_input_trace();
diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idl
index 8670827ac15..4cec5cffb99 100644
--- a/Libraries/LibWeb/Internals/Internals.idl
+++ b/Libraries/LibWeb/Internals/Internals.idl
@@ -215,6 +215,9 @@ interface Internals {
DOMString takeVisualContextTrace();
// Lays out and brings the visual context tree up to date, as a read of paint properties does.
undefined updateVisualContextsForTesting();
+ // Asks for the owners of no nodes of the visual context tree, as the layers window does without updating style or
+ // layout first, and answers the structural epoch of the tree the answer is for: 0 for none yet.
+ unsigned long long describeOwnersOfVisualContextNodes();
// Records where the compositor and this process route each input event, and why, until takeInputTrace().
undefined beginInputTrace();
object takeInputTrace();
diff --git a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
index 987b614a0e2..55c6e32a52d 100644
--- a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
+++ b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
@@ -285,7 +285,11 @@ OwnersOfVisualContextNodes describe_owners_of_visual_context_nodes(DOM::Document
Layout::ForcedReadScope read_scope { document };
Layout::BegunRead const& read = read_scope;
- if (!document.has_committed_viewport_box())
+ // NB: Bringing the tree up to date describes the paint servers it paints with, which the elements its boxes refer to
+ // have to have styles for. With style work pending, those can be elements no style update has styled yet, so
+ // this answers for no tree, which the view asks of again with the next frame, rather than updating style for a
+ // debugging aid.
+ if (!document.has_committed_viewport_box() || document.has_style_work(read))
return { .structural_epoch = 0, .owners = move(context.owners) };
Layout::RustFFI::FfiVisualContextNodeOwnerCallbacks callbacks {
diff --git a/Tests/LibWeb/Text/expected/describe-owners-of-visual-context-nodes-with-unstyled-paint-server.txt b/Tests/LibWeb/Text/expected/describe-owners-of-visual-context-nodes-with-unstyled-paint-server.txt
new file mode 100644
index 00000000000..e5a1d23c306
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/describe-owners-of-visual-context-nodes-with-unstyled-paint-server.txt
@@ -0,0 +1,3 @@
+after a frame, describes a tree: true
+with style pending, describes a tree: false
+after the next frame, describes a tree: true
diff --git a/Tests/LibWeb/Text/input/describe-owners-of-visual-context-nodes-with-unstyled-paint-server.html b/Tests/LibWeb/Text/input/describe-owners-of-visual-context-nodes-with-unstyled-paint-server.html
new file mode 100644
index 00000000000..11141373b06
--- /dev/null
+++ b/Tests/LibWeb/Text/input/describe-owners-of-visual-context-nodes-with-unstyled-paint-server.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<svg width="100" height="100">
+ <defs id="defs"><radialGradient id="gradient"><stop offset="0" stop-color="green" /></radialGradient></defs>
+ <rect width="100" height="100" fill="url(#gradient)" />
+</svg>
+<script>
+ asyncTest(async done => {
+ await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
+ println(`after a frame, describes a tree: ${internals.describeOwnersOfVisualContextNodes() !== 0}`);
+
+ // A gradient with the id the rect paints with, which no style update has styled yet.
+ const gradient = document.createElementNS("http://www.w3.org/2000/svg", "radialGradient");
+ gradient.id = "gradient";
+ gradient.innerHTML = '<stop offset="0" stop-color="blue" />';
+ document.getElementById("defs").replaceChildren(gradient);
+ println(`with style pending, describes a tree: ${internals.describeOwnersOfVisualContextNodes() !== 0}`);
+
+ await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
+ println(`after the next frame, describes a tree: ${internals.describeOwnersOfVisualContextNodes() !== 0}`);
+ done();
+ });
+</script>