Truly independent web browser
LibWeb: Settle ink overflow only for the rows a hit test reads
Aliaksandr Kalenikd2b6b75729a6
diff --git a/Libraries/LibWeb/Rust/src/layout/row_reads.rs b/Libraries/LibWeb/Rust/src/layout/row_reads.rsindex 87f6609cd95..4e06acadf9e 100644--- a/Libraries/LibWeb/Rust/src/layout/row_reads.rs+++ b/Libraries/LibWeb/Rust/src/layout/row_reads.rs@@ -24,6 +24,13 @@ use crate::painting::visual_context::VisualContextTree;use std::rc::Rc;use std::sync::Arc;+#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]+pub(crate) enum MeasuredOverflow {+ None,+ Scrollable,+ ScrollableAndInk,+}+/// The rows of a document's layout as its render state published them. It is immutable and owns all of it, through the/// copy-on-write generations the arena's columns publish, so the host reads it while the arena goes on changing.pub(crate) struct RowSnapshot {@@ -39,8 +46,8 @@ pub(crate) struct RowSnapshot {pub(crate) viewport: NodeSlotId,/// How far the arena's rows had been written when they were published.version: RowsVersion,- /// Whether every row's scrollable overflow and ink overflow were measured when the rows were published.- overflow_is_settled: bool,+ /// How much of every row's overflow was measured when the rows were published.+ measured_overflow: MeasuredOverflow,/// The text rows that waited for their text to be rendered again when the rows were published, by slot index:/// every other text row carries the text it renders.text_awaiting_render: Box<[NodeSlotId]>,@@ -85,10 +92,10 @@ impl RowSnapshot {&self.text_awaiting_render}- /// Whether every row's scrollable overflow was measured when the rows were published, which a read of overflow- /// needs.- pub(crate) fn overflow_is_settled(&self) -> bool {- self.overflow_is_settled+ /// How much of every row's overflow was measured when the rows were published: a read of overflow needs the+ /// scrollable overflow, and a hit test the ink overflow as well.+ pub(crate) fn measured_overflow(&self) -> MeasuredOverflow {+ self.measured_overflow}/// The row in slot `id`, if the slot held it when the rows were published.@@ -283,11 +290,13 @@ impl RowIdentities {}impl LayoutNodeArena {- /// The rows as they are now, for the host to read, once every row's scrollable overflow is settled where- /// `settle_overflow` says so.- pub(crate) fn publish_row_snapshot(&mut self, settle_overflow: bool) -> RowSnapshot {- if settle_overflow {+ /// The rows as they are now, for the host to read, once as much of every row's overflow is settled as+ /// `overflow_to_measure` says.+ pub(crate) fn publish_row_snapshot(&mut self, overflow_to_measure: MeasuredOverflow) -> RowSnapshot {+ if overflow_to_measure >= MeasuredOverflow::Scrollable {self.settle_scrollable_overflow();+ }+ if overflow_to_measure >= MeasuredOverflow::ScrollableAndInk {self.settle_ink_overflow();}let paintable = self.publish_rows();@@ -299,7 +308,13 @@ impl LayoutNodeArena {visual_context_tree: self.paint_state().visual_context.tree.clone(),viewport: self.layout_root(),version: self.rows_version(),- overflow_is_settled: self.scrollable_overflow_is_settled() && self.ink_overflow_is_settled(),+ measured_overflow: if !self.scrollable_overflow_is_settled() {+ MeasuredOverflow::None+ } else if !self.ink_overflow_is_settled() {+ MeasuredOverflow::Scrollable+ } else {+ MeasuredOverflow::ScrollableAndInk+ },text_awaiting_render: self.text_rows_awaiting_sync(),}}@@ -314,17 +329,17 @@ mod tests {let mut arena = LayoutNodeArena::new();let row = arena.allocate_for_test().slot;arena.write_shape(row).set_kind(NodeKind::BlockContainer);- let before = arena.publish_row_snapshot(false);+ let before = arena.publish_row_snapshot(MeasuredOverflow::None);assert!(before.reads_as(arena.rows_version()));arena.write_shape(row).set_kind(NodeKind::InlineNode);assert!(!before.reads_as(arena.rows_version()));- let after = arena.publish_row_snapshot(false);+ let after = arena.publish_row_snapshot(MeasuredOverflow::None);assert_eq!(before.node(row).map(|node| node.kind), Some(NodeKind::BlockContainer));assert_eq!(after.node(row).map(|node| node.kind), Some(NodeKind::InlineNode));arena.free_subtree(row).destroy_shells_and_invoke_callbacks(&crate::stage::MainThread::for_test());- assert!(arena.publish_row_snapshot(false).node(row).is_none());+ assert!(arena.publish_row_snapshot(MeasuredOverflow::None).node(row).is_none());assert!(after.node(row).is_some());}@@ -336,7 +351,7 @@ mod tests {let last = arena.allocate_for_test().slot;arena.insert_child(parent, first, NodeSlotId::INVALID);arena.insert_child(parent, last, NodeSlotId::INVALID);- let rows = arena.publish_row_snapshot(false);+ let rows = arena.publish_row_snapshot(MeasuredOverflow::None);assert_eq!(rows.link(parent, FfiNodeLink::FirstChild), first);assert_eq!(rows.link(parent, FfiNodeLink::LastChild), last);assert_eq!(rows.link(last, FfiNodeLink::PreviousSibling), first);@@ -346,7 +361,7 @@ mod tests {assert!(!rows.reads_as(arena.rows_version()));assert_eq!(arena- .publish_row_snapshot(false)+ .publish_row_snapshot(MeasuredOverflow::None).link(last, FfiNodeLink::PreviousSibling),NodeSlotId::INVALID);diff --git a/Libraries/LibWeb/Rust/src/layout/update_layout.rs b/Libraries/LibWeb/Rust/src/layout/update_layout.rsindex 2ed6f253445..db7e920f112 100644--- a/Libraries/LibWeb/Rust/src/layout/update_layout.rs+++ b/Libraries/LibWeb/Rust/src/layout/update_layout.rs@@ -40,7 +40,11 @@ fn run_layout_round_job(host: &DocumentHost, read: &BegunRead, job: LayoutRoundJlet mut answer = job.run(state.arena_handle_mut());answer.prepare_committed_layout_for_rendering(state.arena_mut());// The host reads what each box owed an image is from rows published with the answer.- let rows = (!answer.owed_images.is_empty()).then(|| state.arena_mut().publish_row_snapshot(false));+ let rows = (!answer.owed_images.is_empty()).then(|| {+ state+ .arena_mut()+ .publish_row_snapshot(crate::layout::row_reads::MeasuredOverflow::None)+ });(answer, rows)});if let Some(rows) = rows {diff --git a/Libraries/LibWeb/Rust/src/painting/ffi.rs b/Libraries/LibWeb/Rust/src/painting/ffi.rsindex 64215a0121d..25796a90f92 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi.rs@@ -215,7 +215,7 @@ pub extern "C" fn render_state_paintable_scrollable_overflow() {// The host reads the overflow from the rows it holds, where they were measured and still read as the arena.let known = host.read_known_rows(|rows, source| {- rows.overflow_is_settled()+ (rows.measured_overflow() >= crate::layout::row_reads::MeasuredOverflow::Scrollable).then(|| FfiOptionalOverflowData::of(source, slot))});if let Some(Some(overflow)) = known {diff --git a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rsindex 7089a3f8aa9..f7a2bef45f1 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs@@ -1002,7 +1002,8 @@ pub extern "C" fn layout_paintable_event_dispatch_target(}/// Answers `query` about `point` through `answer`, from the rows as of every write the host made, with every row's-/// overflow measured, in `read`. A hit test paints nothing, so it walks the overlays a frame paints.+/// scrollable overflow and ink overflow measured, in `read`. A hit test paints nothing, so it walks the overlays a+/// frame paints.fn with_point_query<R>(host: &crate::render_state::DocumentHost,read: &crate::render_state::BegunRead,@@ -1014,7 +1015,7 @@ fn with_point_query<R>(let scroll_state = host.scroll_state();let callbacks =crate::painting::host::FfiHitTestQueryCallbacks::for_host_query(query, scroll_state.device_offsets());- let rows = host.fresh_measured_rows(read);+ let rows = host.fresh_rows_measured_for_hit_testing(read);let Some(tree) = rows.visual_context_tree.as_deref() else {return default;};diff --git a/Libraries/LibWeb/Rust/src/render_state.rs b/Libraries/LibWeb/Rust/src/render_state.rsindex f50a26d1b1f..6fa7b2d3074 100644--- a/Libraries/LibWeb/Rust/src/render_state.rs+++ b/Libraries/LibWeb/Rust/src/render_state.rs@@ -288,7 +288,10 @@ impl RenderState {if !shell_style_changes.is_empty() {self.owed.push(shell_style_changes);}- let rows = self.arena.arena_mut().publish_row_snapshot(false);+ let rows = self+ .arena+ .arena_mut()+ .publish_row_snapshot(crate::layout::row_reads::MeasuredOverflow::None);Some((round, rows))}}diff --git a/Libraries/LibWeb/Rust/src/render_state/document_host.rs b/Libraries/LibWeb/Rust/src/render_state/document_host.rsindex fa2f134f9e4..26605312e24 100644--- a/Libraries/LibWeb/Rust/src/render_state/document_host.rs+++ b/Libraries/LibWeb/Rust/src/render_state/document_host.rs@@ -19,7 +19,7 @@ use crate::css::style::style_job::{SealedStyleInputs, StyleJobAnswer};use crate::css::style::tree::StyleNodeID;use crate::css::transition::HoverTransitions;use crate::layout::node_data::NodeSlotId;-use crate::layout::row_reads::{RowIdentities, RowSnapshot, RowStyles};+use crate::layout::row_reads::{MeasuredOverflow, RowIdentities, RowSnapshot, RowStyles};use crate::layout::tree_update_marks::{LayoutTreeUpdateMarkWrite, LayoutTreeUpdateMarks};use crate::layout::{FlownRound, HostTables, RowsVersion};use crate::painting::paint_read::PaintSource;@@ -1294,7 +1294,7 @@ impl DocumentHost {/// The rows as of every change the host queued, which the render state publishes again first where the ones the/// host has may be stale, spending `wait`.pub(crate) fn fresh_rows(&self, wait: impl RenderWait) -> Rc<RowSnapshot> {- self.rows_as_of_writes(wait, false)+ self.rows_as_of_writes(wait, MeasuredOverflow::None)}/// What each row is and the row each node is bound to, as of every change the host queued. The host reads them from@@ -1302,7 +1302,7 @@ impl DocumentHost {/// render state publishes again first, spending `wait`.pub(crate) fn row_identities(&self, wait: impl RenderWait) -> RowIdentities {self.known_row_identities()- .unwrap_or_else(|| RowIdentities::of(self.rows_as_of_writes(wait, false)))+ .unwrap_or_else(|| RowIdentities::of(self.rows_as_of_writes(wait, MeasuredOverflow::None)))}/// The style record each row has, and what each row is, as of every change the host queued, for a read of the row@@ -1314,7 +1314,7 @@ impl DocumentHost {self.known_rows(RowWrite::Styles, |rows, version| {rows.reads_styles_as(version) && !self.changes.may_write_style_of(id, rows)})- .unwrap_or_else(|| self.rows_as_of_writes(wait, false)),+ .unwrap_or_else(|| self.rows_as_of_writes(wait, MeasuredOverflow::None)),)}@@ -1334,20 +1334,26 @@ impl DocumentHost {Some(RowIdentities::of(rows))}- /// Like [`Self::fresh_rows`], with every row's scrollable overflow measured, as a read of overflow needs.- pub(crate) fn fresh_measured_rows(&self, wait: impl RenderWait) -> Rc<RowSnapshot> {- self.rows_as_of_writes(wait, true)+ /// Like [`Self::fresh_rows`], with every row's scrollable overflow and ink overflow measured, as a hit test needs.+ pub(crate) fn fresh_rows_measured_for_hit_testing(&self, wait: impl RenderWait) -> Rc<RowSnapshot> {+ self.rows_as_of_writes(wait, MeasuredOverflow::ScrollableAndInk)}/// Answers `read` from the rows as of every write the host made, through the paint side's reads, spending `wait`- /// where the rows have to be published again, with every row's overflow settled where `settle_overflow`.+ /// where the rows have to be published again, with every row's scrollable overflow settled where+ /// `settle_overflow`.pub(crate) fn read_rows<R>(&self,wait: impl RenderWait,settle_overflow: bool,read: impl FnOnce(&PaintSource<'_>) -> R,) -> R {- let rows = self.rows_as_of_writes(wait, settle_overflow);+ let overflow_to_measure = if settle_overflow {+ MeasuredOverflow::Scrollable+ } else {+ MeasuredOverflow::None+ };+ let rows = self.rows_as_of_writes(wait, overflow_to_measure);read(&PaintSource::over_rows(&rows.paintable, &self.absolute_rects))}@@ -1378,7 +1384,7 @@ impl DocumentHost {wait: impl RenderWait,read: impl FnOnce(&PaintSource<'_>, &[NodeSlotId]) -> R,) -> R {- let rows = self.rows_as_of_writes(wait, false);+ let rows = self.rows_as_of_writes(wait, MeasuredOverflow::None);read(&PaintSource::over_rows(&rows.paintable, &self.absolute_rects),rows.text_awaiting_render(),@@ -1388,19 +1394,19 @@ impl DocumentHost {/// The rows as of every write the host made: the ones the host has where it knows they still read as the arena,/// and otherwise those the render state answers, spending `wait`, which are the ones the host has where they still/// read as the arena once the owner has applied the host's writes.- fn rows_as_of_writes(&self, wait: impl RenderWait, settle_overflow: bool) -> Rc<RowSnapshot> {+ fn rows_as_of_writes(&self, wait: impl RenderWait, overflow_to_measure: MeasuredOverflow) -> Rc<RowSnapshot> {let held = self.rows.borrow().clone()- .filter(|rows| !settle_overflow || rows.overflow_is_settled());+ .filter(|rows| rows.measured_overflow() >= overflow_to_measure);if let Some(rows) = held.as_ref().filter(|rows| self.knows_rows_read_as_arena(rows)) {return Rc::clone(rows);}let held_version = held.as_ref().map(|rows| rows.version());let published = self.ask(wait, |state| {let arena = state.arena_mut();- (held_version != Some(arena.rows_version())).then(|| arena.publish_row_snapshot(settle_overflow))+ (held_version != Some(arena.rows_version())).then(|| arena.publish_row_snapshot(overflow_to_measure))});match published {Some(rows) => {