Repository: servo/servo
File: components/script/dom/document_event_handler.rs (Rust)

Code before:
                    .filter(|t| t.Target() == touch_dispatch_target)
                    .cloned(),
            );
            TouchList::new(window, filtered.r(), can_gc)
        };

        let changed_touches = TouchList::new(window, from_ref(&&*changed_touch), can_gc);

        let event_name = match event.event_type {
            TouchEventType::Down => "touchstart",
            TouchEventType::Move => "touchmove",
            TouchEventType::Up => "touchend",
            TouchEventType::Cancel => "touchcancel",
        };

        let touch_event = TouchEvent::new(
            window,
            DOMString::from(event_name),
            EventBubbles::Bubbles,
            EventCancelable::from(event.is_cancelable()),
            EventComposed::Composed,
            Some(window),
            0i32,
            &touches,
            &changed_touches,
            &target_touches,
            // FIXME: modifier keys
            false,
            false,
            false,
            false,
            can_gc,
        );
        let event = touch_event.upcast::<Event>();
        event.fire(&touch_dispatch_target, can_gc);
        event.flags().into()
    }

    // If hittest fails, we still need to update the active point information.
    fn update_active_touch_points_when_early_return(&self, event: EmbedderTouchEvent) {
        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 => {

Review comment (suggestion):
I think it was a little nicer when these were inlined here and not put into temporary variables. I would move them back if you can.


```suggestion
            &TouchList::new(window, from_ref(&&*touch), can_gc),
            &TouchList::new(window, target_touches.r(), can_gc),
```

Code after:
            TouchEventType::Cancel => "touchcancel",
        };

        let touch_event = TouchEvent::new(
            window,
            DOMString::from(event_name),
            EventBubbles::Bubbles,
            EventCancelable::from(event.is_cancelable()),
            EventComposed::Composed,
            Some(window),
            0i32,
            &TouchList::new(window, self.active_touch_points.borrow().r(), can_gc),
            &TouchList::new(window, from_ref(&&*changed_touch), can_gc),
            &TouchList::new(window, target_touches.r(), can_gc),
            // FIXME: modifier keys
            false,
            false,
            false,
            false,
            can_gc,
        );
        let event = touch_event.upcast::<Event>();
        event.fire(&touch_dispatch_target, can_gc);
        event.flags().into()
    }

    // If hittest fails, we still need to update the active point information.
    fn update_active_touch_points_when_early_return(&self, event: EmbedderTouchEvent) {
        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.touch_id.0)
                {
                    Some(i) => {
                        active_touch_points.swap_remove(i);
                        // Also remove pointer ID mapping when touch ends/cancels on early return
                        self.remove_pointer_id_for_touch(event.touch_id.0);
                    },
                    None => warn!("Got a touchend event for a non-active touch point"),