aboutsummaryrefslogtreecommitdiffstats
path: root/components/compositing/touch.rs
diff options
context:
space:
mode:
authorBi Fuguo <1782765876@qq.com>2025-03-03 23:30:57 +0800
committerGitHub <noreply@github.com>2025-03-03 15:30:57 +0000
commita22f95a6a75f4d4204c604d314862b7cf7d26175 (patch)
tree531134f930fc25fad2044c248d14c4ed6f229425 /components/compositing/touch.rs
parent5650fa2e79e03b83667c204f4ea0cf5ce6722615 (diff)
downloadservo-a22f95a6a75f4d4204c604d314862b7cf7d26175.tar.gz
servo-a22f95a6a75f4d4204c604d314862b7cf7d26175.zip
Fix the problem that touchmove crashes occasionally. Fix crash when multiple touch cancels occur (#35763)
* Fix the problem that touchmove crashes occasionally. Check whether touchSequenceInfo exists when touch_sequence_map is modified in on_touch_event_processed. Signed-off-by: kongbai1996 <1782765876@qq.com> * Remove outdated todo. We already transition to Finished in `on_touch_cancel` in the Touch handler, so we don't need any logic in the event handler. Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> --------- Signed-off-by: kongbai1996 <1782765876@qq.com> Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> Co-authored-by: Jonathan Schwender <schwenderjonathan@gmail.com>
Diffstat (limited to 'components/compositing/touch.rs')
-rw-r--r--components/compositing/touch.rs58
1 files changed, 28 insertions, 30 deletions
diff --git a/components/compositing/touch.rs b/components/compositing/touch.rs
index be6f1189560..4d49b42189f 100644
--- a/components/compositing/touch.rs
+++ b/components/compositing/touch.rs
@@ -26,7 +26,7 @@ const FLING_MAX_SCREEN_PX: f32 = 4000.0;
pub struct TouchHandler {
pub current_sequence_id: TouchSequenceId,
// todo: VecDeque + modulo arithmetic would be more efficient.
- pub touch_sequence_map: HashMap<TouchSequenceId, TouchSequenceInfo>,
+ touch_sequence_map: HashMap<TouchSequenceId, TouchSequenceInfo>,
}
/// Whether the default move action is allowed or not.
@@ -213,41 +213,39 @@ impl TouchHandler {
}
pub(crate) fn set_handling_touch_move(&mut self, sequence_id: TouchSequenceId, flag: bool) {
- self.touch_sequence_map
- .get_mut(&sequence_id)
- .unwrap()
- .handling_touch_move = flag;
+ if let Some(sequence) = self.touch_sequence_map.get_mut(&sequence_id) {
+ sequence.handling_touch_move = flag;
+ }
}
pub(crate) fn is_handling_touch_move(&self, sequence_id: TouchSequenceId) -> bool {
- self.touch_sequence_map
- .get(&sequence_id)
- .unwrap()
- .handling_touch_move
+ if let Some(sequence) = self.touch_sequence_map.get(&sequence_id) {
+ sequence.handling_touch_move
+ } else {
+ false
+ }
}
pub(crate) fn prevent_click(&mut self, sequence_id: TouchSequenceId) {
- self.touch_sequence_map
- .get_mut(&sequence_id)
- .unwrap()
- .prevent_click = true;
+ if let Some(sequence) = self.touch_sequence_map.get_mut(&sequence_id) {
+ sequence.prevent_click = true;
+ }
}
pub(crate) fn prevent_move(&mut self, sequence_id: TouchSequenceId) {
- self.touch_sequence_map
- .get_mut(&sequence_id)
- .unwrap()
- .prevent_move = TouchMoveAllowed::Prevented;
+ if let Some(sequence) = self.touch_sequence_map.get_mut(&sequence_id) {
+ sequence.prevent_move = TouchMoveAllowed::Prevented;
+ }
}
/// Returns true if default move actions are allowed, false if prevented or the result
/// is still pending.,
pub(crate) fn move_allowed(&mut self, sequence_id: TouchSequenceId) -> bool {
- self.touch_sequence_map
- .get(&sequence_id)
- .unwrap()
- .prevent_move ==
- TouchMoveAllowed::Allowed
+ if let Some(sequence) = self.touch_sequence_map.get_mut(&sequence_id) {
+ sequence.prevent_move == TouchMoveAllowed::Allowed
+ } else {
+ true
+ }
}
pub(crate) fn pending_touch_move_action(
@@ -294,10 +292,8 @@ impl TouchHandler {
pub(crate) fn get_touch_sequence_mut(
&mut self,
sequence_id: TouchSequenceId,
- ) -> &mut TouchSequenceInfo {
- self.touch_sequence_map
- .get_mut(&sequence_id)
- .expect("Touch sequence not found.")
+ ) -> Option<&mut TouchSequenceInfo> {
+ self.touch_sequence_map.get_mut(&sequence_id)
}
pub fn on_touch_down(&mut self, id: TouchId, point: Point2D<f32, DevicePixel>) {
@@ -377,7 +373,7 @@ impl TouchHandler {
id: TouchId,
point: Point2D<f32, DevicePixel>,
) -> TouchMoveAction {
- let touch_sequence = self.get_touch_sequence_mut(self.current_sequence_id);
+ let touch_sequence = self.get_current_touch_sequence_mut();
let idx = match touch_sequence
.active_touch_points
.iter_mut()
@@ -454,7 +450,7 @@ impl TouchHandler {
}
pub fn on_touch_up(&mut self, id: TouchId, point: Point2D<f32, DevicePixel>) {
- let touch_sequence = self.get_touch_sequence_mut(self.current_sequence_id);
+ let touch_sequence = self.get_current_touch_sequence_mut();
let old = match touch_sequence
.active_touch_points
.iter()
@@ -531,7 +527,7 @@ impl TouchHandler {
}
pub fn on_touch_cancel(&mut self, id: TouchId, _point: Point2D<f32, DevicePixel>) {
- let touch_sequence = self.get_touch_sequence_mut(self.current_sequence_id);
+ let touch_sequence = self.get_current_touch_sequence_mut();
match touch_sequence
.active_touch_points
.iter()
@@ -545,6 +541,8 @@ impl TouchHandler {
return;
},
}
- touch_sequence.state = Finished;
+ if touch_sequence.active_touch_points.is_empty() {
+ touch_sequence.state = Finished;
+ }
}
}