Truly independent web browser
Tests/LibWeb: Count overflow index refills across tree edits
Andreas Kling6837c36b99bd
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex c46ff9ba3ad..efe62e296df 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -748,8 +748,10 @@ void Document::reset_style_invalidation_counters(Layout::BegunRead const& read){m_style_invalidation_counters = {};(void)CSS::StyleEngineFFI::style_engine_size_query_container_scan_visits(style_computer().style_engine().host(), &read, true);- if (m_layout_node_arena)+ if (m_layout_node_arena) {Layout::RustFFI::render_state_scrollable_overflow_recalculation_count(m_layout_node_arena->host(), true);+ Layout::RustFFI::render_state_overflow_contained_box_index_refill_count(m_layout_node_arena->host(), true);+ }CSS::reset_longhand_wrappers_minted();}diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cppindex 3268fe8d08b..41784b5c2f3 100644--- a/Libraries/LibWeb/Internals/Internals.cpp+++ b/Libraries/LibWeb/Internals/Internals.cpp@@ -2810,6 +2810,7 @@ GC::Ref<JS::Object> Internals::style_invalidation_counters_object() constobject->define_direct_property("styleCascadeMicroseconds"_utf16_fly_string, JS::Value(counters.style_cascade_microseconds), JS::default_attributes);object->define_direct_property("styleValuesMicroseconds"_utf16_fly_string, JS::Value(counters.style_values_microseconds), JS::default_attributes);object->define_direct_property("scrollableOverflowRecalculations"_utf16_fly_string, JS::Value(Layout::RustFFI::render_state_scrollable_overflow_recalculation_count(document.layout_node_arena().host(), false)), JS::default_attributes);+ object->define_direct_property("overflowContainedBoxIndexRefills"_utf16_fly_string, JS::Value(Layout::RustFFI::render_state_overflow_contained_box_index_refill_count(document.layout_node_arena().host(), false)), JS::default_attributes);return object;}diff --git a/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs b/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rsindex 5bc58bfbae5..d8f94ceab27 100644--- a/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs+++ b/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs@@ -634,6 +634,7 @@ pub(crate) struct ScrollableOverflowState {pub(crate) geometry_changed: Cell<bool>,pub(crate) scrollability_changed: Cell<bool>,pub(crate) recalculations: Cell<u64>,+ pub(crate) contained_box_index_refills: Cell<u64>,/// Rows whose overflow a read could find unmeasured: new rows, and rows whose measurement was/// invalidated. Reading overflow never measures it, so the pass measures these first.pub(crate) rows_to_measure: RefCell<Vec<NodeSlotId>>,@@ -669,6 +670,8 @@ impl LayoutNodeArena {}let mut index = self.scrollable_overflow.non_child_boxes.borrow_mut();if let Some(viewport) = self.scrollable_overflow.viewport.get() {+ let refills = &self.scrollable_overflow.contained_box_index_refills;+ refills.set(refills.get() + 1);refill_contained_boxes_index(&self.paintable_rows(), viewport, &mut index);} else {index.clear();diff --git a/Libraries/LibWeb/Rust/src/render_state/devtools.rs b/Libraries/LibWeb/Rust/src/render_state/devtools.rsindex f93dafc3676..d4aa4a69293 100644--- a/Libraries/LibWeb/Rust/src/render_state/devtools.rs+++ b/Libraries/LibWeb/Rust/src/render_state/devtools.rs@@ -102,6 +102,16 @@ pub extern "C" fn render_state_scrollable_overflow_recalculation_count(host: &Do})}+/// How many times paint preparation rebuilt the index of boxes whose containing block is not their parent, counting+/// from zero again where `reset`.+#[unsafe(no_mangle)]+pub extern "C" fn render_state_overflow_contained_box_index_refill_count(host: &DocumentHost, reset: bool) -> u64 {+ read_arena(host, |arena| {+ let refills = &arena.scrollable_overflow.contained_box_index_refills;+ if reset { refills.replace(0) } else { refills.get() }+ })+}+/// How many boxes wait for their visual context to be updated.#[unsafe(no_mangle)]pub extern "C" fn render_state_visual_context_pending_dirty_box_count(host: &DocumentHost) -> usize {diff --git a/Tests/LibWeb/Text/expected/scrollable-overflow-contained-box-index-edits.txt b/Tests/LibWeb/Text/expected/scrollable-overflow-contained-box-index-edits.txtnew file mode 100644index 00000000000..ed8555a0129--- /dev/null+++ b/Tests/LibWeb/Text/expected/scrollable-overflow-contained-box-index-edits.txt@@ -0,0 +1,7 @@+text edit: refills=1 scrollHeight=300+plain block inserted: refills=1 scrollHeight=300+plain block removed: refills=1 scrollHeight=300+nested absolutely positioned box inserted: refills=1 scrollHeight=500+nested absolutely positioned box removed: refills=1 scrollHeight=300+inline-block moved out of its inline parent: refills=1 scrollHeight=300+inline-block moved back into an inline parent: refills=1 scrollHeight=300diff --git a/Tests/LibWeb/Text/input/scrollable-overflow-contained-box-index-edits.html b/Tests/LibWeb/Text/input/scrollable-overflow-contained-box-index-edits.htmlnew file mode 100644index 00000000000..73caf3c6d1f--- /dev/null+++ b/Tests/LibWeb/Text/input/scrollable-overflow-contained-box-index-edits.html@@ -0,0 +1,49 @@+<!DOCTYPE html>+<script src="include.js"></script>+<style>+ body { margin: 0; font: 10px/10px SerenitySans; }+ #scroller { position: relative; width: 100px; height: 100px; overflow: auto; }+ .tall { position: absolute; top: 0; left: 0; width: 10px; height: 300px; }+ .deep { position: absolute; top: 0; left: 0; width: 10px; height: 500px; }+ .inline-block { display: inline-block; width: 10px; height: 10px; }+</style>+<div id="scroller">+ <div><div class="tall"></div></div>+ <p>text <span id="label">0</span> <span id="holder"><span class="inline-block"></span></span></p>+ <div id="target"></div>+</div>+<script>+ test(() => {+ function step(name, mutate) {+ scroller.scrollHeight;+ internals.resetStyleInvalidationCounters();+ mutate();+ const scrollHeight = scroller.scrollHeight;+ const refills = internals.getStyleInvalidationCounters().overflowContainedBoxIndexRefills;+ println(`${name}: refills=${refills} scrollHeight=${scrollHeight}`);+ }++ step("text edit", () => {+ label.textContent = "1";+ });+ step("plain block inserted", () => {+ target.appendChild(document.createElement("div")).textContent = "plain";+ });+ step("plain block removed", () => {+ target.firstChild.remove();+ });+ step("nested absolutely positioned box inserted", () => {+ const wrapper = target.appendChild(document.createElement("div"));+ wrapper.appendChild(document.createElement("div")).className = "deep";+ });+ step("nested absolutely positioned box removed", () => {+ target.firstChild.remove();+ });+ step("inline-block moved out of its inline parent", () => {+ target.appendChild(holder.firstChild);+ });+ step("inline-block moved back into an inline parent", () => {+ holder.appendChild(target.firstChild);+ });+ });+</script>