compositor/layout: Rely on layout for fine-grained input event hit testing (#38480)

Before, the compositor was responsible for doing the hit testing during
input events within a page. This change moves that hit testing to
layout.  With this change, epoch mismatches are no longer a bit deal and
we can simply ignore them, as the Constellation and Script will take
care of ignoring hit tests against scroll nodes and browsing contexts
that no longer exist. This means that hit testing retry support can be
removed.

Add the concept of a Script `HitTest` that transforms the coarse-grained
renderer hit test into one that hit tests against the actual layout
items.

Testing: Currently we do not have good tests for verifying the behavior
of
input events, but WebDriver tests should cover this.
Fixes: This is part of #37932.
Fixes: #26608.
Fixes: #25282.
Fixes: #38090.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: kongbai1996 <1782765876@qq.com>
This commit is contained in:
Martin Robinson 2025-08-07 10:38:43 +02:00 committed by GitHub
parent c0cc8484f8
commit ad805e3110
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 348 additions and 511 deletions

View file

@ -39,5 +39,6 @@ selectors = { workspace = true }
serde = { workspace = true }
servo_arc = { workspace = true }
servo_url = { path = "../../url" }
stylo_traits = { workspace = true }
stylo = { workspace = true }
webrender_api = { workspace = true }

View file

@ -25,7 +25,8 @@ use bitflags::bitflags;
use compositing_traits::CrossProcessCompositorApi;
use constellation_traits::LoadData;
use embedder_traits::{Theme, UntrustedNodeAddress, ViewportDetails};
use euclid::default::{Point2D, Rect};
use euclid::Point2D;
use euclid::default::{Point2D as UntypedPoint2D, Rect};
use fnv::FnvHashMap;
use fonts::{FontContext, SystemFontServiceProxy};
use fxhash::FxHashMap;
@ -54,6 +55,7 @@ use style::properties::PropertyId;
use style::properties::style_structs::Font;
use style::selector_parser::{PseudoElement, RestyleDamage, Snapshot};
use style::stylesheets::Stylesheet;
use style_traits::CSSPixel;
use webrender_api::units::{DeviceIntSize, LayoutPoint, LayoutVector2D};
use webrender_api::{ExternalScrollId, ImageKey};
@ -288,7 +290,7 @@ pub trait Layout {
animation_timeline_value: f64,
) -> Option<ServoArc<Font>>;
fn query_scrolling_area(&self, node: Option<TrustedNodeAddress>) -> Rect<i32>;
fn query_text_indext(&self, node: OpaqueNode, point: Point2D<f32>) -> Option<usize>;
fn query_text_indext(&self, node: OpaqueNode, point: UntypedPoint2D<f32>) -> Option<usize>;
fn query_elements_from_point(
&self,
point: LayoutPoint,
@ -608,9 +610,9 @@ pub struct ElementsFromPointResult {
/// An [`OpaqueNode`] that contains a pointer to the node hit by
/// this hit test result.
pub node: OpaqueNode,
/// The [`LayoutPoint`] of the original query point relative to the
/// The [`Point2D`] of the original query point relative to the
/// node fragment rectangle.
pub point_in_target: LayoutPoint,
pub point_in_target: Point2D<f32, CSSPixel>,
}
bitflags! {