Repository: servo/servo
File: components/paint/touch.rs (Rust)

Code before:
            active_touch_points: vec![],
            touch_ids_in_move: FxHashSet::default(),
            prevent_click: false,
            prevent_move: TouchMoveAllowed::Pending,
            pending_touch_move_actions: vec![],
            hit_test_result_cache: None,
        };
        // We insert a simulated initial touch sequence, which is already finished,
        // so that we always have one element in the map, which simplifies creating
        // a new touch sequence on touch_down.
        let mut touch_sequence_map = FxHashMap::default();
        touch_sequence_map.insert(TouchSequenceId::new(), finished_info);
        TouchHandler {
            webview_id,
            current_sequence_id: TouchSequenceId::new(),
            touch_sequence_map,
            pending_touch_input_events: Default::default(),
            observing_frames_for_fling: Default::default(),
        }
    }

    pub(crate) fn set_handling_touch_move_for_touch_id(
        &mut self,
        sequence_id: TouchSequenceId,
        touch_id: TouchId,
        flag: bool,
    ) {
        if let Some(sequence) = self.touch_sequence_map.get_mut(&sequence_id) {
            if flag {
                sequence.touch_ids_in_move.insert(touch_id);
            } else {
                sequence.touch_ids_in_move.remove(&touch_id);
            }
        }
    }

    pub(crate) fn is_handling_touch_move_for_touch_id(
        &self,
        sequence_id: TouchSequenceId,
        touch_id: TouchId,
    ) -> bool {
        self.touch_sequence_map
            .get(&sequence_id)
            .is_some_and(|seq| seq.touch_ids_in_move.contains(&touch_id))
    }

    pub(crate) fn prevent_click(&mut self, sequence_id: TouchSequenceId) {
        if let Some(sequence) = self.touch_sequence_map.get_mut(&sequence_id) {
            sequence.prevent_click = true;
        } else {
            warn!("TouchSequenceInfo corresponding to the sequence number has been deleted.");

Review comment (suggestion):
The name flag is non-descriptive. Instead, introduce an enum with name `TouchIdTacking::{Track,Remove}`

Code after:

impl TouchHandler {
    pub(crate) fn new(webview_id: WebViewId) -> Self {
        let finished_info = TouchSequenceInfo {
            state: TouchSequenceState::Finished,
            active_touch_points: vec![],
            touch_ids_in_move: FxHashSet::default(),
            prevent_click: false,
            prevent_move: TouchMoveAllowed::Pending,
            pending_touch_move_actions: vec![],
            hit_test_result_cache: None,
        };
        // We insert a simulated initial touch sequence, which is already finished,
        // so that we always have one element in the map, which simplifies creating
        // a new touch sequence on touch_down.
        let mut touch_sequence_map = FxHashMap::default();
        touch_sequence_map.insert(TouchSequenceId::new(), finished_info);
        TouchHandler {
            webview_id,
            current_sequence_id: TouchSequenceId::new(),
            touch_sequence_map,
            pending_touch_input_events: Default::default(),
            observing_frames_for_fling: Default::default(),
        }
    }

    pub(crate) fn set_handling_touch_move_for_touch_id(
        &mut self,
        sequence_id: TouchSequenceId,
        touch_id: TouchId,
        flag: TouchIdMoveTracking,
    ) {
        if let Some(sequence) = self.touch_sequence_map.get_mut(&sequence_id) {
            match flag {
                TouchIdMoveTracking::Track => {
                    sequence.touch_ids_in_move.insert(touch_id);
                },
                TouchIdMoveTracking::Remove => {
                    sequence.touch_ids_in_move.remove(&touch_id);
                },
            }
        }
    }

    pub(crate) fn is_handling_touch_move_for_touch_id(
        &self,
        sequence_id: TouchSequenceId,
        touch_id: TouchId,
    ) -> bool {
        self.touch_sequence_map
            .get(&sequence_id)