Skip to content

Truly independent web browser

LibWeb: Ask for the topmost hit before everything under a point

Aliaksandr Kalenik108695c74534
diff --git a/Libraries/LibWeb/Painting/HitTestQuery.cpp b/Libraries/LibWeb/Painting/HitTestQuery.cpp
index 28ec9169056..f4e915bcc8b 100644
--- a/Libraries/LibWeb/Painting/HitTestQuery.cpp
+++ b/Libraries/LibWeb/Painting/HitTestQuery.cpp
@@ -171,12 +171,18 @@ Optional<HitTestResult> HitTestQuery::hit_test(Layout::BegunRead const& read, CS
TraversalDecision HitTestQuery::hit_test_all(Layout::BegunRead const& read, CSSPixelPoint point, Function<TraversalDecision(HitTestResult)> const& callback) const
{
+ Layout::RustFFI::FfiPointHit topmost_hit;
+ if (!Layout::RustFFI::layout_hit_test_topmost_hit(m_arena->host(), &read, ffi_query(), point, &topmost_hit))
+ return TraversalDecision::Continue;
+ if (callback(hit_test_result_for(read, topmost_hit)) == TraversalDecision::Break)
+ return TraversalDecision::Break;
+
Vector<Layout::RustFFI::FfiPointHit> hits;
Layout::RustFFI::layout_hit_test_all_hits(m_arena->host(), &read, ffi_query(), point, &hits, [](void* sink, Layout::RustFFI::FfiPointHit const* hit) {
static_cast<Vector<Layout::RustFFI::FfiPointHit>*>(sink)->append(*hit);
});
- for (auto const& hit : hits) {
- if (callback(hit_test_result_for(read, hit)) == TraversalDecision::Break)
+ for (size_t index_below_topmost_hit = 1; index_below_topmost_hit < hits.size(); ++index_below_topmost_hit) {
+ if (callback(hit_test_result_for(read, hits[index_below_topmost_hit])) == TraversalDecision::Break)
return TraversalDecision::Break;
}
diff --git a/Libraries/LibWeb/Rust/src/painting/hit_test/walk.rs b/Libraries/LibWeb/Rust/src/painting/hit_test/walk.rs
index 6e8339d125b..16a920c3590 100644
--- a/Libraries/LibWeb/Rust/src/painting/hit_test/walk.rs
+++ b/Libraries/LibWeb/Rust/src/painting/hit_test/walk.rs
@@ -419,6 +419,13 @@ pub(crate) fn all_hits(rows: &impl PaintRead, query: PointQuery<'_>) -> Vec<Poin
"Skipping paint scopes by their ink bounds changed the hits at {:?}: {hits:?} instead of {hits_without_skipping:?}",
query.point
);
+ let topmost_without_skipping = walk_for(rows, query, Wanted::Topmost, false).topmost();
+ assert!(
+ topmost_without_skipping.as_ref() == hits_without_skipping.first(),
+ "The walk that stops at the topmost hit at {:?} found {topmost_without_skipping:?} instead of {:?}",
+ query.point,
+ hits_without_skipping.first()
+ );
}
hits
}