mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
compositor|script: Update script's active_touch_points when hit tests on compositor fail (#37779)
[RootCause]:Tochdown executes normally, but touchup fails during hittest and does not send a touchup event to the script, causing the script to save an incorrect number of active_touch_points. The application receives an incorrect event.touches.length, causing a logic error and preventing the carousel from sliding. [Solution]: When hit test on compositor fails, we also need to send the EmbedderToConstellationMessage::ForwardInputEvent message to constellation. In the script's handle_touch_event, if it exits early, we also need to update active_touch_points. Testing: Fixes: #37763 --------- Signed-off-by: kongbai1996 <1782765876@qq.com>
This commit is contained in:
parent
068406ee6e
commit
fe7aa91235
2 changed files with 61 additions and 57 deletions
|
@ -345,7 +345,22 @@ impl WebViewRenderer {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn dispatch_point_input_event(&mut self, mut event: InputEvent) -> bool {
|
||||
pub(crate) fn dispatch_point_input_event(&self, event: InputEvent) -> bool {
|
||||
self.dispatch_point_input_event_internal(event, true)
|
||||
}
|
||||
|
||||
pub(crate) fn dispatch_pending_point_input_events(&self) {
|
||||
while let Some(event) = self.pending_point_input_events.borrow_mut().pop_front() {
|
||||
// TODO: Add multiple retry later if needed.
|
||||
self.dispatch_point_input_event_internal(event, false);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn dispatch_point_input_event_internal(
|
||||
&self,
|
||||
mut event: InputEvent,
|
||||
retry_on_error: bool,
|
||||
) -> bool {
|
||||
// Events that do not need to do hit testing are sent directly to the
|
||||
// constellation to filter down.
|
||||
let Some(point) = event.point() else {
|
||||
|
@ -354,7 +369,9 @@ impl WebViewRenderer {
|
|||
|
||||
// Delay the event if the epoch is not synchronized yet (new frame is not ready),
|
||||
// or hit test result would fail and the event is rejected anyway.
|
||||
if !self.webrender_frame_ready.get() || !self.pending_point_input_events.borrow().is_empty()
|
||||
if retry_on_error &&
|
||||
(!self.webrender_frame_ready.get() ||
|
||||
!self.pending_point_input_events.borrow().is_empty())
|
||||
{
|
||||
self.pending_point_input_events
|
||||
.borrow_mut()
|
||||
|
@ -369,16 +386,14 @@ impl WebViewRenderer {
|
|||
.borrow()
|
||||
.hit_test_at_point(point, get_pipeline_details)
|
||||
{
|
||||
Ok(hit_test_results) => hit_test_results,
|
||||
Err(HitTestError::EpochMismatch) => {
|
||||
Ok(hit_test_results) => Some(hit_test_results),
|
||||
Err(HitTestError::EpochMismatch) if retry_on_error => {
|
||||
self.pending_point_input_events
|
||||
.borrow_mut()
|
||||
.push_back(event);
|
||||
return false;
|
||||
},
|
||||
_ => {
|
||||
.push_back(event.clone());
|
||||
return false;
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
|
||||
match event {
|
||||
|
@ -389,15 +404,19 @@ impl WebViewRenderer {
|
|||
InputEvent::MouseLeave(_) |
|
||||
InputEvent::MouseMove(_) |
|
||||
InputEvent::Wheel(_) => {
|
||||
self.global
|
||||
.borrow_mut()
|
||||
.update_cursor_from_hittest(point, &result);
|
||||
if let Some(ref result) = result {
|
||||
self.global
|
||||
.borrow_mut()
|
||||
.update_cursor_from_hittest(point, result);
|
||||
} else {
|
||||
warn!("Not hit test result.");
|
||||
}
|
||||
},
|
||||
_ => unreachable!("Unexpected input event type: {event:?}"),
|
||||
}
|
||||
|
||||
if let Err(error) = self.global.borrow().constellation_sender.send(
|
||||
EmbedderToConstellationMessage::ForwardInputEvent(self.id, event, Some(result)),
|
||||
EmbedderToConstellationMessage::ForwardInputEvent(self.id, event, result),
|
||||
) {
|
||||
warn!("Sending event to constellation failed ({error:?}).");
|
||||
false
|
||||
|
@ -406,51 +425,6 @@ impl WebViewRenderer {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: This function duplicates a lot of `dispatch_point_input_event.
|
||||
// Perhaps it should just be called here instead.
|
||||
pub(crate) fn dispatch_pending_point_input_events(&self) {
|
||||
while let Some(mut event) = self.pending_point_input_events.borrow_mut().pop_front() {
|
||||
// Events that do not need to do hit testing are sent directly to the
|
||||
// constellation to filter down.
|
||||
let Some(point) = event.point() else {
|
||||
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 Ok(result) = self
|
||||
.global
|
||||
.borrow()
|
||||
.hit_test_at_point(point, get_pipeline_details)
|
||||
else {
|
||||
// Don't need to process pending input events in this frame any more.
|
||||
// TODO: Add multiple retry later if needed.
|
||||
return;
|
||||
};
|
||||
|
||||
match event {
|
||||
InputEvent::Touch(ref mut touch_event) => {
|
||||
touch_event.init_sequence_id(self.touch_handler.current_sequence_id);
|
||||
},
|
||||
InputEvent::MouseButton(_) |
|
||||
InputEvent::MouseLeave(_) |
|
||||
InputEvent::MouseMove(_) |
|
||||
InputEvent::Wheel(_) => {
|
||||
self.global
|
||||
.borrow_mut()
|
||||
.update_cursor_from_hittest(point, &result);
|
||||
},
|
||||
_ => unreachable!("Unexpected input event type: {event:?}"),
|
||||
}
|
||||
|
||||
if let Err(error) = self.global.borrow().constellation_sender.send(
|
||||
EmbedderToConstellationMessage::ForwardInputEvent(self.id, event, Some(result)),
|
||||
) {
|
||||
warn!("Sending event to constellation failed ({error:?}).");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn notify_input_event(&mut self, event: InputEvent) {
|
||||
if self.global.borrow().shutdown_state() != ShutdownState::NotShuttingDown {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue