Skip to content

Truly independent web browser

LibWeb: Remove caret lines and caret fields from the hit-test list

Aliaksandr Kalenik1dee169ef8b9
diff --git a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs
index d2c9b0757c1..90e53fe3a8d 100644
--- a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs
+++ b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs
@@ -927,11 +927,9 @@ pub extern "C" fn layout_hit_test_item_facts(
"exporting a hit-test item that names a non-live paintable"
);
Some(crate::painting::host::FfiHitTestItemExport {
- can_produce_caret_position: item.can_produce_caret_position,
paintable: item.paintable,
hit_node: item.hit_node,
chrome_widget_kind: item.chrome_widget_kind,
- caret_rect: item.caret_rect.into(),
context: item.context,
})
})
diff --git a/Libraries/LibWeb/Rust/src/painting/hit_test/caret.rs b/Libraries/LibWeb/Rust/src/painting/hit_test/caret.rs
index bd416daec5c..421c0499b50 100644
--- a/Libraries/LibWeb/Rust/src/painting/hit_test/caret.rs
+++ b/Libraries/LibWeb/Rust/src/painting/hit_test/caret.rs
@@ -51,7 +51,7 @@ impl HitTestList {
HitTestItemKind::Box | HitTestItemKind::EmptyEditable | HitTestItemKind::ChromeWidget => {
resolver.in_box(item.paintable)
}
- HitTestItemKind::SvgPath | HitTestItemKind::EmptyLine => Some(resolver.at_start_of(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);
diff --git a/Libraries/LibWeb/Rust/src/painting/hit_test/mod.rs b/Libraries/LibWeb/Rust/src/painting/hit_test/mod.rs
index b4a2728fdff..3525f6c8bc8 100644
--- a/Libraries/LibWeb/Rust/src/painting/hit_test/mod.rs
+++ b/Libraries/LibWeb/Rust/src/painting/hit_test/mod.rs
@@ -22,9 +22,8 @@ pub enum HitTestItemKind {
Box = 0,
SvgPath = 1,
TextFragment = 2,
- EmptyLine = 3,
- EmptyEditable = 4,
- ChromeWidget = 5,
+ EmptyEditable = 3,
+ ChromeWidget = 4,
}
pub const CHROME_WIDGET_NONE: u8 = 0;
@@ -42,12 +41,7 @@ pub struct HitTestItem {
pub hit_node: NodeSlotId,
pub chrome_widget_kind: u8,
pub text_fragment_index: Option<u32>,
- pub caret_node: NodeSlotId,
- pub caret_offset: usize,
pub rect: CssPixelRect,
- pub caret_rect: CssPixelRect,
- pub caret_line_index: Option<usize>,
- pub block_container: NodeSlotId,
pub context: ContextRef,
pub border_radii: BorderRadii,
pub path: Option<Arc<libgfx_rust::path::Path>>,
@@ -56,11 +50,6 @@ pub struct HitTestItem {
pub svg_hit_areas: u8,
/// For an SVG path whose stroke pointer events can target, the shape of that stroke.
pub svg_stroke: Option<Arc<SvgStrokeHitRegion>>,
- pub writing_mode: u8,
- pub inline_axis_is_reverse: bool,
- pub block_axis_is_reverse: bool,
- pub containing_block: NodeSlotId,
- pub can_produce_caret_position: bool,
}
/// The areas of an SVG graphics element that pointer events can target.
@@ -175,10 +164,7 @@ impl HitTestList {
}
self.spatial_indexes_built = true;
for item_index in 0..self.items.len() {
- let item_is_caret_target_only = self.items[item_index].kind == HitTestItemKind::EmptyLine;
- if !item_is_caret_target_only {
- self.add_item_to_spatial_index(item_index);
- }
+ self.add_item_to_spatial_index(item_index);
}
}
diff --git a/Libraries/LibWeb/Rust/src/painting/hit_test/query.rs b/Libraries/LibWeb/Rust/src/painting/hit_test/query.rs
index fc5c04c5df3..d73f30e4f70 100644
--- a/Libraries/LibWeb/Rust/src/painting/hit_test/query.rs
+++ b/Libraries/LibWeb/Rust/src/painting/hit_test/query.rs
@@ -123,8 +123,6 @@ impl HitTestList {
.is_some_and(|stroke| stroke.contains(path, x, y)))
}
HitTestItemKind::TextFragment => item.rect.contains_point(local_point),
- // Empty lines are caret targets only; they never contain a point for regular hit testing.
- HitTestItemKind::EmptyLine => false,
HitTestItemKind::EmptyEditable => item.rect.contains_point(local_point),
HitTestItemKind::ChromeWidget => {
if !layout_arena.paintable_row_is_populated(item.paintable) {
diff --git a/Libraries/LibWeb/Rust/src/painting/hit_test/resolve.rs b/Libraries/LibWeb/Rust/src/painting/hit_test/resolve.rs
index 272508cd893..9d8de388d7d 100644
--- a/Libraries/LibWeb/Rust/src/painting/hit_test/resolve.rs
+++ b/Libraries/LibWeb/Rust/src/painting/hit_test/resolve.rs
@@ -30,7 +30,6 @@ impl HitTestList {
match item.kind {
HitTestItemKind::TextFragment => fragment_layout_node_slot(arena, item)
.map_or_else(FfiNodeIdentity::default, |slot| row_node_identity(arena, slot, true)),
- HitTestItemKind::EmptyLine => row_node_identity(arena, item.caret_node, false),
_ => event_dispatch_target_of_paintable(arena, item.paintable),
}
}
diff --git a/Libraries/LibWeb/Rust/src/painting/host/hit_test.rs b/Libraries/LibWeb/Rust/src/painting/host/hit_test.rs
index 46e20c466a0..51e4a47bf4c 100644
--- a/Libraries/LibWeb/Rust/src/painting/host/hit_test.rs
+++ b/Libraries/LibWeb/Rust/src/painting/host/hit_test.rs
@@ -159,10 +159,8 @@ impl FfiCaretAt {
#[derive(Clone, Copy, Debug)]
#[repr(C)]
pub struct FfiHitTestItemExport {
- pub can_produce_caret_position: bool,
pub paintable: NodeSlotId,
pub hit_node: NodeSlotId,
pub chrome_widget_kind: u8,
- pub caret_rect: used_values::FfiCssPixelRect,
pub context: ContextRef,
}
diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs b/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs
index 9a5d541226f..93cb7ddb65e 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs
@@ -170,13 +170,6 @@ pub(crate) fn committed_svg_text_character_cells(
})
}
-pub(crate) fn committed_containing_line_box_index(arena: &impl GeometryRead, slot: NodeSlotId) -> Option<usize> {
- arena.with_committed_fragment_link(slot, |link| {
- link.and_then(|link| link.placement.containing_line_box_index)
- .map(|index| index as usize)
- })
-}
-
pub(crate) fn committed_svg_viewport_transform(
arena: &impl GeometryRead,
slot: NodeSlotId,
diff --git a/Libraries/LibWeb/Rust/src/painting/record/assemble.rs b/Libraries/LibWeb/Rust/src/painting/record/assemble.rs
index 03e30dc9e6a..1d762e2ed09 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/assemble.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/assemble.rs
@@ -690,24 +690,14 @@ mod tests {
paintable: owner,
hit_node: owner,
chrome_widget_kind: 0,
- text_fragment_index: None,
- caret_node: NodeSlotId::INVALID,
- caret_offset: 0,
+ text_fragment_index: Some(index + u32::from(content.version) * 100),
rect: CssPixelRect::default(),
- caret_rect: CssPixelRect::default(),
- caret_line_index: Some(index as usize + content.version as usize * 100),
- block_container: NodeSlotId::INVALID,
context: ContextRef::default(),
border_radii: BorderRadii::default(),
path: None,
winding_rule: libgfx_rust::WindingRule::Nonzero,
svg_hit_areas: 0,
svg_stroke: None,
- writing_mode: 0,
- inline_axis_is_reverse: false,
- block_axis_is_reverse: false,
- containing_block: NodeSlotId::INVALID,
- can_produce_caret_position: false,
});
}
output.blocking_wheel_event_region_count += content.blocking;
@@ -826,10 +816,10 @@ mod tests {
);
assert_eq!(assembled.display_list.command_runs, fresh.display_list.command_runs);
// Comparing whole items would compare their paths through the host's path equality.
- let item_identities = |items: &[HitTestItem]| -> Vec<(NodeSlotId, Option<usize>)> {
+ let item_identities = |items: &[HitTestItem]| -> Vec<(NodeSlotId, Option<u32>)> {
items
.iter()
- .map(|item| (item.paintable, item.caret_line_index))
+ .map(|item| (item.paintable, item.text_fragment_index))
.collect()
};
assert_eq!(
diff --git a/Libraries/LibWeb/Rust/src/painting/record/hit_test_items.rs b/Libraries/LibWeb/Rust/src/painting/record/hit_test_items.rs
index 4a663986b0c..7bd93297996 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/hit_test_items.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/hit_test_items.rs
@@ -11,7 +11,6 @@ use super::{PaintPhase, PaintRecorder};
use crate::css::computed_value_types::SVG_PAINT_NONE;
use crate::css::css_enums;
use crate::css::css_pixels::{CssPixelRect, CssPixels};
-use crate::layout::inline_content::ForcedBreakPosition;
use crate::layout::node_data::{DomPaintFact, NodeKind, NodeSlotId};
use crate::layout::node_facts::{self, NodeShape};
use crate::painting::display_list::commands::ContextRef;
@@ -166,10 +165,6 @@ impl<'a, O: Observer> PaintRecorder<'a, O> {
self.source.node_is_generated_for_pseudo_element(paintable)
}
- fn is_atomic_inline(&self, paintable: NodeSlotId) -> bool {
- crate::painting::style_queries::is_atomic_inline(self.source, paintable)
- }
-
pub(crate) fn record_foreign_object_descendant_hit_test_items(&mut self, paintable: NodeSlotId) {
let mut next_child = crate::painting::paint_order::first_paint_child(self.source, paintable);
while let Some(child) = next_child {
@@ -263,50 +258,6 @@ impl<'a, O: Observer> PaintRecorder<'a, O> {
}
self.append_text_fragment(paintable, index as u32, context);
});
- self.record_empty_line_caret_items(paintable, context);
- }
-
- fn record_empty_line_caret_items(&mut self, paintable: NodeSlotId, context: ContextRef) {
- let empty_lines: Vec<(usize, ForcedBreakPosition, CssPixelRect, u32)> = {
- let side = self.source.committed_side_data(paintable);
- if side.fragments().is_empty() {
- return;
- }
- side.lines()
- .iter()
- .enumerate()
- .filter_map(|(line_index, line)| {
- let position = line.forced_break.filter(|position| {
- line.fragment_count == 0 && self.forced_break_is_caret_target(position.node)
- })?;
- Some((line_index, position, CssPixelRect::from(line.rect), line.box_fragment))
- })
- .collect()
- };
- if empty_lines.is_empty() {
- return;
- }
- let positions = paintable_geometry::LineRootPositions::new(self.source, paintable);
- for (line_index, forced_break, line_rect, box_fragment) in empty_lines {
- let caret_offset = if self.source.node_kind_if_live(forced_break.node) == Some(NodeKind::BreakNode) {
- 0
- } else {
- self.source.dom_offset_for_rendered_text_offset(
- forced_break.node,
- forced_break.rendered_offset as usize,
- crate::layout::RenderedTextBoundary::Start,
- )
- };
- let line_rect = line_rect.translated_by(positions.of_fragment(box_fragment));
- self.append_empty_line(
- paintable,
- forced_break.node,
- caret_offset,
- line_index,
- line_rect,
- context,
- );
- }
}
fn record_inline_hit_test_items(&mut self, paintable: NodeSlotId, phase: PaintPhase) {
@@ -565,27 +516,6 @@ impl<'a, O: Observer> PaintRecorder<'a, O> {
// A text node has no style of its own, so its parent both decides whether the fragment can be hit and is what an
// event dispatched from it resolves against. Returns that node, or None when the fragment is not hit-testable.
- /// Whether the line that the <br> or the preserved newline in the text `node` ends is a caret target.
- fn forced_break_is_caret_target(&self, node: NodeSlotId) -> bool {
- let Some(row) = self.source.node(node) else {
- return false;
- };
- if row.dom_paint_facts() & DomPaintFact::Inert as u8 != 0 {
- return false;
- }
- let Some(style) = row.style().or_else(|| self.source.node_style_if_live(row.parent())) else {
- return false;
- };
- if style.visibility() != css_enums::visibility::VISIBLE
- || style.pointer_events() == css_enums::pointer_events::NONE
- {
- return false;
- }
- self.source
- .node_style_if_live(row.parent())
- .is_none_or(|parent_style| parent_style.effects().opacity != 0.0)
- }
-
fn hit_node_for_text_fragment(&mut self, fragment: &FragmentRecord) -> Option<NodeSlotId> {
let node = fragment.layout_node;
let row = self.source.node(node)?;
@@ -608,42 +538,6 @@ impl<'a, O: Observer> PaintRecorder<'a, O> {
Some(parent)
}
- fn block_container_of_paintable(&self, paintable: NodeSlotId) -> NodeSlotId {
- self.data(paintable).containing_block
- }
-
- fn block_container_of_fragment(&self, fragment: &FragmentRecord) -> NodeSlotId {
- text_fragment::containing_block_paintable(self.source, fragment).unwrap_or(NodeSlotId::INVALID)
- }
-
- fn writing_mode_of(&self, paintable: NodeSlotId) -> u8 {
- self.source
- .node_style_if_live(paintable)
- .map_or(css_enums::writing_mode::HORIZONTAL_TB, |style| style.writing_mode())
- }
-
- fn inline_axis_is_reverse_of(&self, paintable: NodeSlotId) -> bool {
- self.source
- .node_style_if_live(paintable)
- .is_some_and(|style| style.inline_axis_is_reverse())
- }
-
- fn block_axis_is_reverse_of(&self, paintable: NodeSlotId) -> bool {
- self.source
- .node_style_if_live(paintable)
- .is_some_and(|style| style.block_axis_is_reverse())
- }
-
- fn layout_containing_block_of(&self, paintable: NodeSlotId) -> NodeSlotId {
- self.source
- .node_containing_block_if_live(paintable)
- .unwrap_or(NodeSlotId::INVALID)
- }
-
- fn node_has_dom_node(&self, node: NodeSlotId) -> bool {
- self.source.node_is_dom_backed(node)
- }
-
fn append_box(
&mut self,
paintable_box: NodeSlotId,
@@ -651,21 +545,9 @@ impl<'a, O: Observer> PaintRecorder<'a, O> {
context: ContextRef,
border_radii: BorderRadii,
) {
- let caret_line_index = paintable_geometry::committed_containing_line_box_index(self.source, paintable_box);
- let can_produce_caret_position = (self.is_atomic_inline(paintable_box) || self.is_replaced_box(paintable_box))
- && {
- let negative_z =
- crate::painting::style_queries::effective_z_index(self.source, paintable_box).unwrap_or(0) < 0;
- !negative_z && self.node_has_dom_node(paintable_box)
- };
- let block_container = self.block_container_of_paintable(paintable_box);
let item = HitTestItem {
rect,
- caret_rect: rect,
- caret_line_index,
- block_container,
border_radii,
- can_produce_caret_position,
..self.base_hit_test_item(HitTestItemKind::Box, paintable_box, context)
};
self.list.append(item);
@@ -678,23 +560,13 @@ impl<'a, O: Observer> PaintRecorder<'a, O> {
hit_node: target,
chrome_widget_kind: CHROME_WIDGET_NONE,
text_fragment_index: None,
- caret_node: NodeSlotId::INVALID,
- caret_offset: 0,
rect: CssPixelRect::default(),
- caret_rect: CssPixelRect::default(),
- caret_line_index: None,
- block_container: NodeSlotId::INVALID,
context,
border_radii: BorderRadii::default(),
path: None,
winding_rule: WindingRule::Nonzero,
svg_hit_areas: 0,
svg_stroke: None,
- writing_mode: self.writing_mode_of(target),
- inline_axis_is_reverse: self.inline_axis_is_reverse_of(target),
- block_axis_is_reverse: self.block_axis_is_reverse_of(target),
- containing_block: self.layout_containing_block_of(target),
- can_produce_caret_position: false,
}
}
@@ -703,52 +575,18 @@ impl<'a, O: Observer> PaintRecorder<'a, O> {
let Some(hit_node) = self.hit_node_for_text_fragment(&fragment) else {
return;
};
- let layout_arena = self.source;
- let block_container = self.block_container_of_fragment(&fragment);
let item = HitTestItem {
text_fragment_index: Some(fragment_index),
- rect: text_fragment::absolute_rect(layout_arena, &fragment),
- caret_rect: text_fragment::whole_range_rect(layout_arena, &fragment),
- caret_line_index: Some(fragment.line_index as usize),
- block_container,
- containing_block: layout_arena
- .node_containing_block_if_live(fragment.layout_node)
- .unwrap_or(NodeSlotId::INVALID),
- can_produce_caret_position: self.node_has_dom_node(fragment.layout_node),
+ rect: text_fragment::absolute_rect(self.source, &fragment),
hit_node,
..self.base_hit_test_item(HitTestItemKind::TextFragment, owner, context)
};
self.list.append(item);
}
- fn append_empty_line(
- &mut self,
- block_container: NodeSlotId,
- caret_node: NodeSlotId,
- caret_offset: usize,
- caret_line_index: usize,
- line_rect: CssPixelRect,
- context: ContextRef,
- ) {
- let item = HitTestItem {
- caret_node,
- caret_offset,
- caret_rect: line_rect,
- caret_line_index: Some(caret_line_index),
- block_container,
- can_produce_caret_position: self.node_has_dom_node(caret_node),
- ..self.base_hit_test_item(HitTestItemKind::EmptyLine, block_container, context)
- };
- self.list.append(item);
- }
-
fn append_empty_editable(&mut self, paintable: NodeSlotId, rect: CssPixelRect, context: ContextRef) {
- let block_container = self.block_container_of_paintable(paintable);
let item = HitTestItem {
rect,
- caret_rect: rect,
- block_container,
- can_produce_caret_position: self.node_has_dom_node(paintable),
..self.base_hit_test_item(HitTestItemKind::EmptyEditable, paintable, context)
};
self.list.append(item);
diff --git a/Libraries/LibWeb/Rust/src/painting/record/mod.rs b/Libraries/LibWeb/Rust/src/painting/record/mod.rs
index e30dd9f3453..92395ae25ab 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/mod.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/mod.rs
@@ -745,10 +745,6 @@ impl<O: Observer> PaintRecorder<'_, O> {
self.paintable_facts(paintable).visible_for_hit_testing
}
- fn is_replaced_box(&self, paintable: NodeSlotId) -> bool {
- crate::painting::style_queries::is_replaced_box(self.source, paintable)
- }
-
pub(crate) fn with_context<R>(&mut self, context: ContextRef, paint: impl FnOnce(&mut Self) -> R) -> R {
let previous_context = self.recorder.accumulated_visual_context();
self.recorder.set_accumulated_visual_context(context);
diff --git a/Libraries/LibWeb/Rust/src/painting/style_queries.rs b/Libraries/LibWeb/Rust/src/painting/style_queries.rs
index b2aa8d403df..1a847976f70 100644
--- a/Libraries/LibWeb/Rust/src/painting/style_queries.rs
+++ b/Libraries/LibWeb/Rust/src/painting/style_queries.rs
@@ -376,10 +376,6 @@ pub(crate) fn has_css_transform(arena: &impl PaintRead, node: NodeSlotId, style:
has_transform && is_transformable(arena, node)
}
-pub(crate) fn is_atomic_inline(arena: &impl PaintRead, node: NodeSlotId) -> bool {
- arena.node(node).is_some_and(PaintRow::is_atomic_inline)
-}
-
pub(crate) fn is_transformable(arena: &impl PaintRead, node: NodeSlotId) -> bool {
let Some(row) = arena.node(node) else {
return false;
diff --git a/Libraries/LibWeb/Rust/src/painting/text_fragment.rs b/Libraries/LibWeb/Rust/src/painting/text_fragment.rs
index 6677a3ef0fe..c79b5860ccf 100644
--- a/Libraries/LibWeb/Rust/src/painting/text_fragment.rs
+++ b/Libraries/LibWeb/Rust/src/painting/text_fragment.rs
@@ -377,14 +377,6 @@ pub(crate) fn rects_for_selection_offsets(
.collect()
}
-pub(crate) fn whole_range_rect(layout_arena: &impl PaintRead, fragment: &FragmentRecord) -> CssPixelRect {
- let offsets = SelectionOffsets {
- start: 0,
- end: fragment.length_in_code_units,
- };
- rect_for_selection_offsets(layout_arena, fragment, offsets)
-}
-
pub(crate) fn is_block_level_box(layout_arena: &impl PaintRead, fragment: &FragmentRecord) -> bool {
layout_arena
.node_style_if_live(fragment.layout_node)