Update hit test result return type

Signed-off-by: batu_hoang <longvatrong111@gmail.com>
This commit is contained in:
batu_hoang 2025-05-28 14:22:30 +08:00
parent b5a3c975a9
commit ddad26f6c8
2 changed files with 13 additions and 11 deletions

View file

@ -283,8 +283,7 @@ impl PipelineDetails {
pub enum HitTestError { pub enum HitTestError {
EpochMismatch, EpochMismatch,
#[allow(dead_code)] Others,
Other,
} }
impl ServoRenderer { impl ServoRenderer {
@ -296,14 +295,17 @@ impl ServoRenderer {
&self, &self,
point: DevicePoint, point: DevicePoint,
details_for_pipeline: impl Fn(PipelineId) -> Option<&'a PipelineDetails>, details_for_pipeline: impl Fn(PipelineId) -> Option<&'a PipelineDetails>,
) -> Result<Option<CompositorHitTestResult>, HitTestError> { ) -> Result<CompositorHitTestResult, HitTestError> {
match self.hit_test_at_point_with_flags_and_pipeline( match self.hit_test_at_point_with_flags_and_pipeline(
point, point,
HitTestFlags::empty(), HitTestFlags::empty(),
None, None,
details_for_pipeline, details_for_pipeline,
) { ) {
Ok(hit_test_results) => Ok(hit_test_results.first().cloned()), Ok(hit_test_results) => hit_test_results
.first()
.cloned()
.ok_or(HitTestError::Others),
Err(error) => Err(error), Err(error) => Err(error),
} }
} }
@ -639,7 +641,7 @@ impl IOCompositor {
.global .global
.borrow() .borrow()
.hit_test_at_point(point, details_for_pipeline); .hit_test_at_point(point, details_for_pipeline);
if let Ok(Some(result)) = result { if let Ok(result) = result {
self.global.borrow_mut().update_cursor(point, &result); self.global.borrow_mut().update_cursor(point, &result);
} }
} }

View file

@ -331,9 +331,8 @@ impl WebViewRenderer {
.borrow() .borrow()
.hit_test_at_point(point, get_pipeline_details) .hit_test_at_point(point, get_pipeline_details)
{ {
Ok(Some(hit_test_results)) => hit_test_results, Ok(hit_test_results) => hit_test_results,
Err(HitTestError::EpochMismatch) => { Err(HitTestError::EpochMismatch) => {
dbg!("A hit test failed with epoch mismatch. Retrying");
self.pending_input_events.borrow_mut().push_back(event); self.pending_input_events.borrow_mut().push_back(event);
return; return;
}, },
@ -361,15 +360,16 @@ impl WebViewRenderer {
// If we can't find a pipeline to send this event to, we cannot continue. // If we can't find a pipeline to send this event to, we cannot continue.
let get_pipeline_details = |pipeline_id| self.pipelines.get(&pipeline_id); let get_pipeline_details = |pipeline_id| self.pipelines.get(&pipeline_id);
let Ok(Some(result)) = self let Ok(result) = self
.global .global
.borrow() .borrow()
.hit_test_at_point(point, get_pipeline_details) .hit_test_at_point(point, get_pipeline_details)
else { else {
continue; // Don't need to process pending input events in this frame any more.
// TODO: Add multiple retry later if needed.
return;
}; };
dbg!("Hit test for pending event succeeded");
self.global.borrow_mut().update_cursor(point, &result); self.global.borrow_mut().update_cursor(point, &result);
if let Err(error) = self.global.borrow().constellation_sender.send( if let Err(error) = self.global.borrow().constellation_sender.send(
@ -451,7 +451,7 @@ impl WebViewRenderer {
fn send_touch_event(&self, mut event: TouchEvent) -> bool { fn send_touch_event(&self, mut event: TouchEvent) -> bool {
let get_pipeline_details = |pipeline_id| self.pipelines.get(&pipeline_id); let get_pipeline_details = |pipeline_id| self.pipelines.get(&pipeline_id);
let Ok(Some(result)) = self let Ok(result) = self
.global .global
.borrow() .borrow()
.hit_test_at_point(event.point, get_pipeline_details) .hit_test_at_point(event.point, get_pipeline_details)