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:
Fuguo 2025-07-04 17:57:24 +08:00 committed by GitHub
parent 068406ee6e
commit fe7aa91235
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 61 additions and 57 deletions

View file

@ -2246,6 +2246,7 @@ impl Document {
) -> TouchEventResult {
// Ignore all incoming events without a hit test.
let Some(hit_test_result) = hit_test_result else {
self.update_active_touch_points_when_early_return(event);
return TouchEventResult::Forwarded;
};
@ -2263,6 +2264,7 @@ impl Document {
.filter_map(DomRoot::downcast::<Element>)
.next()
else {
self.update_active_touch_points_when_early_return(event);
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)]
pub(crate) fn handle_scroll_event(&self, event: ScrollEvent, can_gc: CanGc) {
// <https://drafts.csswg.org/cssom-view/#scrolling-events>