mirror of
https://github.com/servo/servo.git
synced 2025-07-20 05:43:41 +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
|
// Events that do not need to do hit testing are sent directly to the
|
||||||
// constellation to filter down.
|
// constellation to filter down.
|
||||||
let Some(point) = event.point() else {
|
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),
|
// 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.
|
// 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
|
self.pending_point_input_events
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
|
@ -369,16 +386,14 @@ impl WebViewRenderer {
|
||||||
.borrow()
|
.borrow()
|
||||||
.hit_test_at_point(point, get_pipeline_details)
|
.hit_test_at_point(point, get_pipeline_details)
|
||||||
{
|
{
|
||||||
Ok(hit_test_results) => hit_test_results,
|
Ok(hit_test_results) => Some(hit_test_results),
|
||||||
Err(HitTestError::EpochMismatch) => {
|
Err(HitTestError::EpochMismatch) if retry_on_error => {
|
||||||
self.pending_point_input_events
|
self.pending_point_input_events
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.push_back(event);
|
.push_back(event.clone());
|
||||||
return false;
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
|
@ -389,15 +404,19 @@ impl WebViewRenderer {
|
||||||
InputEvent::MouseLeave(_) |
|
InputEvent::MouseLeave(_) |
|
||||||
InputEvent::MouseMove(_) |
|
InputEvent::MouseMove(_) |
|
||||||
InputEvent::Wheel(_) => {
|
InputEvent::Wheel(_) => {
|
||||||
|
if let Some(ref result) = result {
|
||||||
self.global
|
self.global
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.update_cursor_from_hittest(point, &result);
|
.update_cursor_from_hittest(point, result);
|
||||||
|
} else {
|
||||||
|
warn!("Not hit test result.");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_ => unreachable!("Unexpected input event type: {event:?}"),
|
_ => unreachable!("Unexpected input event type: {event:?}"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(error) = self.global.borrow().constellation_sender.send(
|
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:?}).");
|
warn!("Sending event to constellation failed ({error:?}).");
|
||||||
false
|
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) {
|
pub(crate) fn notify_input_event(&mut self, event: InputEvent) {
|
||||||
if self.global.borrow().shutdown_state() != ShutdownState::NotShuttingDown {
|
if self.global.borrow().shutdown_state() != ShutdownState::NotShuttingDown {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -2246,6 +2246,7 @@ impl Document {
|
||||||
) -> TouchEventResult {
|
) -> TouchEventResult {
|
||||||
// Ignore all incoming events without a hit test.
|
// Ignore all incoming events without a hit test.
|
||||||
let Some(hit_test_result) = hit_test_result else {
|
let Some(hit_test_result) = hit_test_result else {
|
||||||
|
self.update_active_touch_points_when_early_return(event);
|
||||||
return TouchEventResult::Forwarded;
|
return TouchEventResult::Forwarded;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2263,6 +2264,7 @@ impl Document {
|
||||||
.filter_map(DomRoot::downcast::<Element>)
|
.filter_map(DomRoot::downcast::<Element>)
|
||||||
.next()
|
.next()
|
||||||
else {
|
else {
|
||||||
|
self.update_active_touch_points_when_early_return(event);
|
||||||
return TouchEventResult::Forwarded;
|
return TouchEventResult::Forwarded;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2348,6 +2350,34 @@ impl Document {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If hittest fails, we still need to update the active point information.
|
||||||
|
fn update_active_touch_points_when_early_return(&self, event: TouchEvent) {
|
||||||
|
match event.event_type {
|
||||||
|
TouchEventType::Down => {
|
||||||
|
// If the touchdown fails, we don't need to do anything.
|
||||||
|
// When a touchmove or touchdown occurs at that touch point,
|
||||||
|
// a warning is triggered: Got a touchmove/touchend event for a non-active touch point
|
||||||
|
},
|
||||||
|
TouchEventType::Move => {
|
||||||
|
// The failure of touchmove does not affect the number of active points.
|
||||||
|
// Since there is no position information when it fails, we do not need to update.
|
||||||
|
},
|
||||||
|
TouchEventType::Up | TouchEventType::Cancel => {
|
||||||
|
// Remove an existing touch point
|
||||||
|
let mut active_touch_points = self.active_touch_points.borrow_mut();
|
||||||
|
match active_touch_points
|
||||||
|
.iter()
|
||||||
|
.position(|t| t.Identifier() == event.id.0)
|
||||||
|
{
|
||||||
|
Some(i) => {
|
||||||
|
active_touch_points.swap_remove(i);
|
||||||
|
},
|
||||||
|
None => warn!("Got a touchend event for a non-active touch point"),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub(crate) fn handle_scroll_event(&self, event: ScrollEvent, can_gc: CanGc) {
|
pub(crate) fn handle_scroll_event(&self, event: ScrollEvent, can_gc: CanGc) {
|
||||||
// <https://drafts.csswg.org/cssom-view/#scrolling-events>
|
// <https://drafts.csswg.org/cssom-view/#scrolling-events>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue