Truly independent web browser
LibWeb: Answer caret queries by walking paint order over rows
Aliaksandr Kalenik090f542a9663
diff --git a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rsindex 5bdc9a89764..752c9bcc19a 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs@@ -982,57 +982,6 @@ fn landed_recording_stands(host: &crate::render_state::DocumentHost, version: cr})}-/// Answers `query` from every hit-test item of `host`'s document, built up by `build`, and the rows as of every write-/// the host made, with every row's overflow measured, in `read`. The items are walked from those rows where the ones-/// the host kept no longer say what the rows do. Answers `default` where the document has no visual context tree.-/// Every entry that hits tests is called with a live document host, on its document's thread.-fn with_hit_test_list<R>(- host: &crate::render_state::DocumentHost,- read: &crate::render_state::BegunRead,- default: R,- build: impl FnOnce(&mut crate::painting::hit_test::HitTestList, &crate::painting::paint_read::PaintSource<'_>),- query: impl FnOnce(- &crate::painting::hit_test::HitTestList,- &crate::layout::row_reads::RowSnapshot,- &crate::painting::paint_read::PaintSource<'_>,- ) -> R,-) -> R {- let rows = host.fresh_measured_rows(read);- let Some(tree) = rows.visual_context_tree.as_deref() else {- return default;- };- let absolute_rects = std::cell::RefCell::default();- let source = crate::painting::paint_read::PaintSource::over_rows(&rows.paintable, &absolute_rects);- let mut kept = host.whole_document_hit_test_list();- let list =- crate::painting::hit_test::walk::WholeDocumentHitTestList::current(&mut kept, &source, tree, rows.viewport);- build(list, &source);- query(list, &rows, &source)-}--fn with_hit_test_list_spatial_indexes_and_visual_context_tree<R>(- host: &crate::render_state::DocumentHost,- read: &crate::render_state::BegunRead,- default: R,- query: impl FnOnce(- &crate::painting::hit_test::HitTestList,- &crate::painting::visual_context::VisualContextTree,- &crate::painting::paint_read::PaintSource<'_>,- ) -> R,-) -> R {- with_hit_test_list(- host,- read,- None,- |list, _| list.build_spatial_indexes_if_needed(),- |list, rows, source| {- let tree = rows.visual_context_tree.as_deref()?;- Some(query(list, tree, source))- },- )- .unwrap_or(default)-}-/// `tree` with the compositor's animations sampled at the time the query reads them at, where it reads them so, kept in/// `sampled`; otherwise `tree` itself.fn tree_as_the_query_reads_it<'tree>(@@ -1184,18 +1133,8 @@ pub unsafe extern "C" fn layout_hit_test_caret_position_from_point(constraint_scope: NodeSlotId,out: &mut FfiCaretAt,) {- let scroll_state = host.scroll_state();- let callbacks =- crate::painting::host::FfiHitTestQueryCallbacks::for_host_query(&query, scroll_state.device_offsets());- *out = with_hit_test_list_spatial_indexes_and_visual_context_tree(host, read, None, |list, tree, arena| {- let world = callbacks.build_world_transforms(tree);- list.caret_position_from_point(- arena,- tree,- &callbacks.with_world_transforms(&world),- point.into(),- constraint_scope,- )+ *out = with_point_query(host, read, &query, point, None, |source, point_query| {+ crate::painting::hit_test::caret::caret_position_from_point(source, point_query, constraint_scope)}).unwrap_or_else(FfiCaretAt::none);}diff --git a/Libraries/LibWeb/Rust/src/painting/hit_test/caret.rs b/Libraries/LibWeb/Rust/src/painting/hit_test/caret.rsindex 421c0499b50..b474907810a 100644--- a/Libraries/LibWeb/Rust/src/painting/hit_test/caret.rs+++ b/Libraries/LibWeb/Rust/src/painting/hit_test/caret.rs@@ -4,66 +4,61 @@* SPDX-License-Identifier: BSD-2-Clause*/+use super::walk::{PointQuery, topmost_hit};use super::*;use crate::layout::node_data::{DomPaintFact, NodeFlag, NodeKind};use crate::layout::query::inline_cursor::{CaretPosition, InlineCursor};-use crate::painting::host::{FfiCaretAt, FfiCaretBoundaryKind, FfiHitTestQueryCallbacks, FfiResolvedCaret};+use crate::painting::host::{FfiCaretAt, FfiCaretBoundaryKind, FfiResolvedCaret};use crate::painting::paint_read::{PaintRead, PaintRow};use crate::painting::paintable_data::FragmentRecord;use crate::painting::viewport_mapping::{ViewportMapping, ViewportSpace};use crate::painting::visual_context::ClipBehavior;use crate::painting::{node_painting, paintable_geometry, style_queries};-impl HitTestList {- /// The caret position at `point`: the one the box the point hits gives it, as editing resolves a point, or with a- /// `constraint_scope` box, the one that box gives it wherever the point is.- pub(crate) fn caret_position_from_point(- &self,- arena: &impl PaintRead,- tree: &VisualContextTree,- callbacks: &FfiHitTestQueryCallbacks,- point: CssPixelPoint,- constraint_scope: NodeSlotId,- ) -> Option<FfiCaretAt> {- let resolver = PointResolver {- arena,- mapping: callbacks.viewport_mapping(tree),- point,- };- if !constraint_scope.is_invalid() {- let mut scope = constraint_scope;- while !arena.paintable_row_is_populated(scope) {- scope = arena.node_parent_if_live(scope)?;- }- return resolver.in_box(scope);+/// The caret position at the point of `query`: the one the box the point hits gives it, as editing resolves a point,+/// or with a `constraint_scope` box, the one that box gives it wherever the point is.+pub(crate) fn caret_position_from_point(+ arena: &impl PaintRead,+ query: PointQuery<'_>,+ constraint_scope: NodeSlotId,+) -> Option<FfiCaretAt> {+ let resolver = PointResolver {+ arena,+ mapping: query.callbacks.viewport_mapping(query.tree),+ point: query.point,+ };+ if !constraint_scope.is_invalid() {+ let mut scope = constraint_scope;+ while !arena.paintable_row_is_populated(scope) {+ scope = arena.node_parent_if_live(scope)?;}- // A point that hits nothing, such as one past the edge of the viewport during a drag, goes to the viewport.- let Some(hit) = self.find_topmost_item(arena, tree, callbacks, point) else {- let mut viewport = self.items.first()?.paintable;- while let Some(parent) = arena.node_parent_if_live(viewport) {- viewport = parent;- }- return resolver.in_box(viewport);- };- let item = &self.items[hit.index];- let caret = match item.kind {- HitTestItemKind::TextFragment => resolver.in_lines_of(item.paintable),- HitTestItemKind::Box | HitTestItemKind::EmptyEditable | HitTestItemKind::ChromeWidget => {- resolver.in_box(item.paintable)- }- HitTestItemKind::SvgPath => Some(resolver.at_start_of(item.paintable)),- };- if let Some(caret) = caret.filter(|caret| caret.caret.has_position) {- return Some(caret);+ return resolver.in_box(scope);+ }+ // A point that hits nothing, such as one past the edge of the viewport during a drag, goes to the viewport.+ let Some(hit) = topmost_hit(arena, query) else {+ if !arena.paintable_row_is_populated(query.viewport) {+ return None;}- // Generated content, such as a list marker, gives no position, and the nearest box around it that stands for a- // node takes the point.- let mut node = arena.node_parent_if_live(item.paintable)?;- while !arena.node_is_dom_backed(node) {- node = arena.node_parent_if_live(node)?;+ return resolver.in_box(query.viewport);+ };+ let item = &hit.item;+ let caret = match item.kind {+ HitTestItemKind::TextFragment => resolver.in_lines_of(item.paintable),+ HitTestItemKind::Box | HitTestItemKind::EmptyEditable | HitTestItemKind::ChromeWidget => {+ resolver.in_box(item.paintable)}- resolver.in_box(node)+ HitTestItemKind::SvgPath => Some(resolver.at_start_of(item.paintable)),+ };+ if let Some(caret) = caret.filter(|caret| caret.caret.has_position) {+ return Some(caret);+ }+ // Generated content, such as a list marker, gives no position, and the nearest box around it that stands for a+ // node takes the point.+ let mut node = arena.node_parent_if_live(item.paintable)?;+ while !arena.node_is_dom_backed(node) {+ node = arena.node_parent_if_live(node)?;}+ resolver.in_box(node)}/// Resolves a point, in the viewport, to a caret position the way a box gives one for a point over it.diff --git a/Libraries/LibWeb/Rust/src/painting/hit_test/mod.rs b/Libraries/LibWeb/Rust/src/painting/hit_test/mod.rsindex 9a304e31750..46e0bd9f9d6 100644--- a/Libraries/LibWeb/Rust/src/painting/hit_test/mod.rs+++ b/Libraries/LibWeb/Rust/src/painting/hit_test/mod.rs@@ -15,7 +15,6 @@ use crate::css::css_pixels::{CssPixelPoint, CssPixelRect};use crate::css::style::fast_hash::FastMap;use crate::layout::node_data::NodeSlotId;use crate::painting::display_list::commands::ContextRef;-use crate::painting::visual_context::VisualContextTree;use std::sync::Arc;#[derive(Clone, Copy, Debug, PartialEq, Eq)]@@ -102,100 +101,6 @@ impl PartialEq for SvgStrokeHitRegion {}}-#[derive(Default)]-pub struct SpatialIndex {- pub cells: FastMap<u64, Vec<usize>>,- pub unbucketed_items: Vec<usize>,-}--const SPATIAL_INDEX_CELL_SIZE: f64 = 128.0;-const MAX_BUCKETED_CELLS_PER_ITEM: u64 = 64;--pub fn spatial_index_cell_for(offset: CssPixels) -> i32 {- (offset.to_double() / SPATIAL_INDEX_CELL_SIZE).floor() as i32-}--pub fn spatial_index_cell_key(x: i32, y: i32) -> u64 {- ((x as u32 as u64) << 32) | (y as u32 as u64)-}--/// Every hit-test item of a document in paint order, walked from its rows, with spatial indexes for point queries.-#[derive(Default)]-pub struct HitTestList {- pub items: Arc<Vec<HitTestItem>>,- /// Point queries read only the spatial indexes, which are built on first use.- pub spatial_indexes_built: bool,- pub spatial_indexes_by_context: Vec<(ContextRef, SpatialIndex)>,- pub spatial_index_position_by_context: FastMap<ContextRef, usize>,-}--impl HitTestList {- pub(crate) fn build_spatial_indexes_if_needed(&mut self) {- if self.spatial_indexes_built {- return;- }- self.spatial_indexes_built = true;- for item_index in 0..self.items.len() {- self.add_item_to_spatial_index(item_index);- }- }-- fn spatial_index_for(&mut self, context: ContextRef) -> &mut SpatialIndex {- let items_arrive_in_runs_sharing_a_context = self- .spatial_indexes_by_context- .last()- .is_some_and(|(last_context, _)| *last_context == context);- let position = if items_arrive_in_runs_sharing_a_context {- self.spatial_indexes_by_context.len() - 1- } else {- *self- .spatial_index_position_by_context- .entry(context)- .or_insert_with(|| {- self.spatial_indexes_by_context.push((context, SpatialIndex::default()));- self.spatial_indexes_by_context.len() - 1- })- };- &mut self.spatial_indexes_by_context[position].1- }-- fn add_item_to_spatial_index(&mut self, item_index: usize) {- let (kind, rect, context) = {- let item = &self.items[item_index];- (item.kind, item.rect, item.context)- };- let spatial_index = self.spatial_index_for(context);- if kind == HitTestItemKind::ChromeWidget || rect.is_empty() {- spatial_index.unbucketed_items.push(item_index);- return;- }- let min_x = spatial_index_cell_for(rect.left());- let max_x = spatial_index_cell_for(rect.right());- let min_y = spatial_index_cell_for(rect.top());- let max_y = spatial_index_cell_for(rect.bottom());- let column_count = i64::from(max_x) - i64::from(min_x) + 1;- let row_count = i64::from(max_y) - i64::from(min_y) + 1;- if column_count <= 0 || row_count <= 0 {- spatial_index.unbucketed_items.push(item_index);- return;- }- let cell_count = column_count as u64 * row_count as u64;- if cell_count > MAX_BUCKETED_CELLS_PER_ITEM {- spatial_index.unbucketed_items.push(item_index);- return;- }- for y in min_y..=max_y {- for x in min_x..=max_x {- spatial_index- .cells- .entry(spatial_index_cell_key(x, y))- .or_default()- .push(item_index);- }- }- }-}-pub(crate) fn to_css_point(local: libgfx_rust::FloatPoint) -> CssPixelPoint {CssPixelPoint::new(CssPixels::nearest_value_for_f32(local.x),diff --git a/Libraries/LibWeb/Rust/src/painting/hit_test/query.rs b/Libraries/LibWeb/Rust/src/painting/hit_test/query.rsindex 98768389662..c11eb2e6233 100644--- a/Libraries/LibWeb/Rust/src/painting/hit_test/query.rs+++ b/Libraries/LibWeb/Rust/src/painting/hit_test/query.rs@@ -9,9 +9,8 @@ use crate::painting::chrome_geometry::{ChromeGeometry, scrollbar_is_hidden};use crate::painting::ffi::ScrollDirection;use crate::painting::host::FfiHitTestQueryCallbacks;use crate::painting::paint_read::PaintRead;-use crate::painting::viewport_mapping::ViewportSpace;use crate::painting::visual_context::{- ClipBehavior, NO_SORTING_CONTEXT, SortingContexts, SpatialNodeIndex, VisualContextTree, WorldTransforms,+ NO_SORTING_CONTEXT, SortingContexts, SpatialNodeIndex, VisualContextTree, WorldTransforms,};use libgfx_rust::FloatPoint;use std::collections::HashMap;@@ -86,12 +85,6 @@ impl<'a> DepthSortingState<'a> {}}-#[derive(Clone, Copy, Debug, PartialEq, Eq)]-pub struct TopmostItem {- pub index: usize,- pub local_point: CssPixelPoint,-}-pub(super) fn item_contains_point(layout_arena: &impl PaintRead,callbacks: &FfiHitTestQueryCallbacks,@@ -157,137 +150,3 @@ pub(super) fn item_contains_point(}}}--impl HitTestList {- fn find_topmost_item_in_list(- &self,- layout_arena: &impl PaintRead,- callbacks: &FfiHitTestQueryCallbacks,- item_indices: &[usize],- local: FloatPoint,- topmost: &mut Option<usize>,- ) {- for item_index in item_indices.iter().rev() {- if topmost.is_some_and(|topmost| *item_index <= topmost) {- return;- }- if item_contains_point(layout_arena, callbacks, &self.items[*item_index], local) {- *topmost = Some(*item_index);- return;- }- }- }-- fn candidate_item_lists(spatial_index: &SpatialIndex, local_point: CssPixelPoint) -> [Option<&[usize]>; 2] {- let x = spatial_index_cell_for(local_point.x);- let y = spatial_index_cell_for(local_point.y);- let bucket = spatial_index.cells.get(&spatial_index_cell_key(x, y));- [- Some(spatial_index.unbucketed_items.as_slice()),- bucket.map(|bucket| bucket.as_slice()),- ]- }-- fn find_topmost(- &self,- layout_arena: &impl PaintRead,- visual_context_tree: &VisualContextTree,- callbacks: &FfiHitTestQueryCallbacks,- point: CssPixelPoint,- ) -> Option<TopmostItem> {- debug_assert!(self.spatial_indexes_built);- let mut topmost: Option<TopmostItem> = None;- let mut topmost_index: Option<usize> = None;- let viewport_mapping = callbacks.viewport_mapping(visual_context_tree);- for (context, spatial_index) in &self.spatial_indexes_by_context {- let Some(local) =- viewport_mapping.point_to_local(*context, point, ViewportSpace::VisualViewport, ClipBehavior::Respect)- else {- continue;- };- let local_point = to_css_point(local);- let previous = topmost_index;- for candidate_list in Self::candidate_item_lists(spatial_index, local_point)- .into_iter()- .flatten()- {- self.find_topmost_item_in_list(layout_arena, callbacks, candidate_list, local, &mut topmost_index);- }- if topmost_index != previous {- topmost = topmost_index.map(|index| TopmostItem { index, local_point });- }- }- topmost- }-- // Planes of a 3D rendering context paint depth sorted, so the front-most plane at the point wins over a- // plane recorded later. Coplanar planes compare equal and fall back to record order.- fn depth_sort_key(&self, depth_sorting: &mut DepthSortingState<'_>, item_index: usize) -> (Option<i64>, usize) {- (- depth_sorting.depth_key_for(self.items[item_index].context.spatial),- item_index,- )- }-- fn topmost_item_by_plane_depth(- &self,- layout_arena: &impl PaintRead,- visual_context_tree: &VisualContextTree,- callbacks: &FfiHitTestQueryCallbacks,- point: CssPixelPoint,- topmost: TopmostItem,- ) -> TopmostItem {- let mut depth_sorting = DepthSortingState::new(callbacks, visual_context_tree, point);- let Some(group) = depth_sorting.group_for(self.items[topmost.index].context.spatial) else {- return topmost;- };- let mut winner = topmost;- let viewport_mapping = callbacks.viewport_mapping(visual_context_tree);- for (context, spatial_index) in &self.spatial_indexes_by_context {- if depth_sorting.group_for(context.spatial) != Some(group) {- continue;- }- let Some(local) =- viewport_mapping.point_to_local(*context, point, ViewportSpace::VisualViewport, ClipBehavior::Respect)- else {- continue;- };- let local_point = to_css_point(local);- for candidate_list in Self::candidate_item_lists(spatial_index, local_point)- .into_iter()- .flatten()- {- for item_index in candidate_list {- if *item_index == winner.index- || !item_contains_point(layout_arena, callbacks, &self.items[*item_index], local)- {- continue;- }- let candidate_key = self.depth_sort_key(&mut depth_sorting, *item_index);- let winner_key = self.depth_sort_key(&mut depth_sorting, winner.index);- if candidate_key > winner_key {- winner = TopmostItem {- index: *item_index,- local_point,- };- }- }- }- }- winner- }-- pub(crate) fn find_topmost_item(- &self,- layout_arena: &impl PaintRead,- visual_context_tree: &VisualContextTree,- callbacks: &FfiHitTestQueryCallbacks,- point: CssPixelPoint,- ) -> Option<TopmostItem> {- let topmost = self.find_topmost(layout_arena, visual_context_tree, callbacks, point)?;- // Record order misranks content inside a 3D rendering context, whose planes paint depth sorted. A winner- // on such a plane is re-resolved against every hit plane of its outermost context. Content outside the- // context keeps record order, which stays correct because a context's items are recorded contiguously.- Some(self.topmost_item_by_plane_depth(layout_arena, visual_context_tree, callbacks, point, topmost))- }-}diff --git a/Libraries/LibWeb/Rust/src/painting/hit_test/walk.rs b/Libraries/LibWeb/Rust/src/painting/hit_test/walk.rsindex 5e93e82524f..262b8b046a0 100644--- a/Libraries/LibWeb/Rust/src/painting/hit_test/walk.rs+++ b/Libraries/LibWeb/Rust/src/painting/hit_test/walk.rs@@ -97,119 +97,6 @@ fn own_accumulated_2d_scale()}-struct WholeDocumentWalk<'a, R: PaintRead> {- rows: &'a R,- spaces: WorldTransforms,- paint_overlay: bool,- items: Vec<HitTestItem>,-}--impl<R: PaintRead> HitTestItemSink for WholeDocumentWalk<'_, R> {- fn hit_test_facts(&mut self, paintable: NodeSlotId) -> HitTestFacts {- hit_test_facts(self.rows, paintable)- }-- fn own_accumulated_2d_scale(&self, paintable: NodeSlotId) -> libgfx_rust::FloatSize {- own_accumulated_2d_scale(self.rows, &self.spaces, paintable)- }-- fn append(&mut self, item: HitTestItem) {- self.items.push(item);- }-}--impl<R: PaintRead> WholeDocumentWalk<'_, R> {- fn scope(&mut self, scope: PaintScope) {- let plan = PaintScopePlan::build(self.rows, scope, self.paint_overlay);- if plan.establishes_stacking_context && !stacking_context_paints(self.rows, scope.owner) {- return;- }- for item in plan.items {- match item {- PaintOrderItem::Producer(producer) => {- for part in hit_tested_parts(producer) {- self.part(scope.owner, part);- }- }- PaintOrderItem::Scope(child) => self.scope(child),- }- }- }-- fn part(&mut self, owner: NodeSlotId, part: HitTestedPart) {- let rows = self.rows;- match part {- HitTestedPart::Phase(phase) => hit_test_items_of_phase(rows, self, owner, phase),- HitTestedPart::SvgBox => self.svg_box(owner),- }- }-- fn svg_box(&mut self, svg_box: NodeSlotId) {- let rows = self.rows;- if svg_box_is_hidden_by_an_empty_mask_or_clip(rows, svg_box) {- return;- }- hit_test_items_of_phase(rows, self, svg_box, PaintPhase::Foreground);- for child in svg_children_painted_with_their_parent(rows, svg_box) {- self.svg_box(child);- }- }-}--/// Every hit-test item of a document as of one state of its rows.-pub(crate) struct WholeDocumentHitTestList {- hit_test_items_stamp: u64,- visual_context_tree_structural_epoch: u64,- pub list: HitTestList,-}--impl WholeDocumentHitTestList {- /// The list in `kept` where it still says what the rows do, and otherwise a list walked from the rows, which- /// `kept` holds from then on. The items name nodes of `tree`, so a tree built anew makes a new list too.- pub(crate) fn current<'kept>(- kept: &'kept mut Option<Self>,- rows: &impl PaintRead,- tree: &VisualContextTree,- viewport: NodeSlotId,- ) -> &'kept mut HitTestList {- let hit_test_items_stamp = rows.hit_test_items_stamp();- let is_current = kept.as_ref().is_some_and(|kept| {- kept.hit_test_items_stamp == hit_test_items_stamp- && kept.visual_context_tree_structural_epoch == tree.structural_epoch- });- if !is_current {- *kept = Some(Self {- hit_test_items_stamp,- visual_context_tree_structural_epoch: tree.structural_epoch,- list: HitTestList {- items: Arc::new(hit_test_items_in_paint_order(rows, tree, viewport, true)),- ..HitTestList::default()- },- });- }- &mut kept.as_mut().expect("a list was kept above").list- }-}--/// Every hit-test item of the document in paint order, with the overlays of stacking contexts where `paint_overlay`.-fn hit_test_items_in_paint_order(- rows: &impl PaintRead,- tree: &VisualContextTree,- viewport: NodeSlotId,- paint_overlay: bool,-) -> Vec<HitTestItem> {- let mut walk = WholeDocumentWalk {- rows,- spaces: WorldTransforms::new(tree, &[], None),- paint_overlay,- items: Vec::new(),- };- if rows.paintable_row_is_populated(viewport) {- walk.scope(PaintScope::stacking_context(viewport));- }- walk.items-}-/// An item under a point, with the point in the space of the item.#[derive(Clone, Debug, PartialEq)]pub(crate) struct PointHit {diff --git a/Libraries/LibWeb/Rust/src/render_state/clock.rs b/Libraries/LibWeb/Rust/src/render_state/clock.rsindex 3af8509e679..d0bba857014 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock.rs@@ -356,8 +356,6 @@ pub(crate) struct Lane {/// Whether a move of the hover had boxes show the styles the host installed in them again in place of samples, which/// the tick shows again.samples_restored: bool,- /// The list a drag selection finds its caret positions in, for the frame whose items it holds.- selection_hit_test_list: Option<crate::painting::hit_test::walk::WholeDocumentHitTestList>,/// What a drag selection owes the rows of the fork of `::selection` styles, once a tick asked.selection_styles: Option<crate::css::style::drag_selection::SelectionStyles>,/// Where the highlight the fork holds ends, if a tick moved it.@@ -1303,7 +1301,6 @@ impl Lane {hovered: hover::LaneHover::default(),unshown_move: None,samples_restored: false,- selection_hit_test_list: None,selection_styles: None,selection_focus_shown: None,}@@ -1362,9 +1359,6 @@ impl Lane {self.shown_at = f64::NEG_INFINITY;self.selection_focus_shown = None;self.selection_styles = None;- if plan.hover.as_ref().is_none_or(|hover| hover.selection_drag().is_none()) {- self.selection_hit_test_list = None;- }self.replan_host_effects(&plan.elements);self.plan = plan;}diff --git a/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs b/Libraries/LibWeb/Rust/src/render_state/clock/hover.rsindex 1e7dd00e318..7736b823a05 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs@@ -209,7 +209,7 @@ impl Drop for HoverLinkReporter {/// A frame paints the overlays of its stacking contexts, the scrollbars among them, which a hit test of what the/// frame shows finds.-const FRAMES_PAINT_OVERLAYS: bool = true;+pub(super) const FRAMES_PAINT_OVERLAYS: bool = true;/// The immutable inputs needed to hit test the presented frame and resolve its predefined cursors.struct ReadOnlyHoverFrame {diff --git a/Libraries/LibWeb/Rust/src/render_state/clock/selection.rs b/Libraries/LibWeb/Rust/src/render_state/clock/selection.rsindex 505c7a9a20a..8c4eb62bdc2 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock/selection.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock/selection.rs@@ -26,8 +26,9 @@ use crate::css::style::tree::StyleNodeID;use crate::layout::LayoutNodeArena;use crate::layout::node_data::{NodeFlag, NodeKind, NodeSlotId};use crate::layout::svg_formatting_context::FfiFloatRect;+use crate::painting::hit_test::caret::caret_position_from_point;use crate::painting::hit_test::resolve::row_dom_style_node;-use crate::painting::hit_test::walk::WholeDocumentHitTestList;+use crate::painting::hit_test::walk::{PointQuery, topmost_hit};use crate::painting::host::{FfiCaretBoundaryKind, FfiHitTestQueryCallbacks, FfiResolvedCaret};use crate::painting::paint_read::GeometryRead;use crate::painting::paintable_data::{@@ -428,7 +429,6 @@ impl Lane {if let Some(plan) = &mut self.plan.hover {plan.end_selection_drag();}- self.selection_hit_test_list = None;self.selection_styles = None;}@@ -489,15 +489,11 @@ impl Lane {return Err(LeftToHost("scrolled since the frame"));}let tree = self.tree_on_screen(state, frame_time_nanoseconds).map_err(LeftToHost)?;+ // The walk skips the boxes whose ink overflow the pointer misses.+ state.arena.arena_mut().settle_ink_overflow();let arena = state.arena.arena();let engine = state.engine_ref();let scroll_offsets = self.scroll_offsets_on_screen(arena, &arena.paint_state().visual_context, plan);- // NB: The list walks the rows and its spatial indexes walk every item, which a drag need not repeat over the- // same frame.- let list =- WholeDocumentHitTestList::current(&mut self.selection_hit_test_list, arena, &tree, arena.layout_root());- list.build_spatial_indexes_if_needed();- let list = &*list;let callbacks = FfiHitTestQueryCallbacks::sealed(plan.device_pixels_per_css_pixel(),&scroll_offsets,@@ -506,20 +502,23 @@ impl Lane {let world = callbacks.build_world_transforms(&tree);let callbacks = callbacks.with_world_transforms(&world);let pixel_ratio = plan.device_pixels_per_css_pixel() as f32;- let css_point =- |x, y| CssPixelPoint::new(CssPixels::nearest_value_for_f32(x), CssPixels::nearest_value_for_f32(y));+ let query_at = |x, y| PointQuery {+ tree: &tree,+ callbacks: &callbacks,+ viewport: arena.layout_root(),+ paint_overlay: hover::FRAMES_PAINT_OVERLAYS,+ point: CssPixelPoint::new(CssPixels::nearest_value_for_f32(x), CssPixels::nearest_value_for_f32(y)),+ };let (x, y) = (position.x / pixel_ratio, position.y / pixel_ratio);// The host hands a move over the content of another navigable to it, and the selection here stays as it is.- let over_a_frame = list- .find_topmost_item(arena, &tree, &callbacks, css_point(x, y))- .and_then(|topmost| arena.node_kind_if_live(list.items[topmost.index].paintable))+ let over_a_frame = topmost_hit(arena, query_at(x, y))+ .and_then(|topmost| arena.node_kind_if_live(topmost.item.paintable))== Some(NodeKind::NavigableContainerViewport);if over_a_frame {return Err(LeftToHost("the content of another navigable"));}let (x, y) = drag.constrained(x, y);- let caret = list- .caret_position_from_point(arena, &tree, &callbacks, css_point(x, y), NodeSlotId::INVALID)+ let caret = caret_position_from_point(arena, query_at(x, y), NodeSlotId::INVALID).filter(|caret| caret.caret.has_position).ok_or(LeftToHost("no caret position"))?;let (focus, focus_node) = focus_at(engine, &caret.caret, drag.anchor)?;diff --git a/Libraries/LibWeb/Rust/src/render_state/document_host.rs b/Libraries/LibWeb/Rust/src/render_state/document_host.rsindex d9d97b6fc5e..fa2f134f9e4 100644--- a/Libraries/LibWeb/Rust/src/render_state/document_host.rs+++ b/Libraries/LibWeb/Rust/src/render_state/document_host.rs@@ -68,9 +68,6 @@ pub struct DocumentHost {recording: RefCell<RecordingSlot>,/// The rows the render state published last, which the host reads between its jobs.rows: RefCell<Option<Rc<RowSnapshot>>>,- /// Every hit-test item of the document, which caret queries walk the rows for when they first need them and- /// read until the rows say something else can be hit.- whole_document_hit_test_list: RefCell<Option<crate::painting::hit_test::walk::WholeDocumentHitTestList>>,/// The reactions of the style update the host took last, which it reads until it ends the transaction.style_update: RefCell<Option<StyleJobAnswer>>,/// The first sample of the transitions a step the host read from the style update starts, by element, which@@ -210,7 +207,6 @@ impl DocumentHost {host_tables: HostTables::default(),recording: RefCell::default(),rows: RefCell::default(),- whole_document_hit_test_list: RefCell::default(),style_update: RefCell::default(),fresh_transition_sample: Cell::default(),absolute_rects: RefCell::default(),@@ -1543,12 +1539,6 @@ impl DocumentHost {self.compositor_animations.take()}- pub(crate) fn whole_document_hit_test_list(- &self,- ) -> RefMut<'_, Option<crate::painting::hit_test::walk::WholeDocumentHitTestList>> {- self.whole_document_hit_test_list.borrow_mut()- }-/// What the document keeps of its recordings.pub(crate) fn recording(&self) -> RefMut<'_, RecordingSlot> {self.recording.borrow_mut()