diff --git a/crates/behavior/src/press.rs b/crates/behavior/src/press.rs index ccd3b1694..ba4a4d7f3 100644 --- a/crates/behavior/src/press.rs +++ b/crates/behavior/src/press.rs @@ -471,6 +471,11 @@ struct Open { dragging: bool, /// Moved past slop on a target that senses no drag: the click is gone and nothing starts. abandoned: bool, + /// The pointer left the window ([`PointerEvent::Gone`]): the click is gone, but a target that senses a drag still + /// starts it from the moves that follow. The button is still down and the window keeps getting the pointer's moves + /// and release while it is outside, so a press near a window edge (a window's resize grip) that leaves the window + /// before it passes slop still drags. + left: bool, /// A pass reported the press: later passes within slop report `Held`, not `Down`. reported: bool, /// A pass reported the drag's start: later passes report `Drag`. @@ -489,7 +494,7 @@ impl Open { /// A release now is a click. fn clicks(&self) -> bool { - !self.dragging && !self.abandoned && self.sense.contains(Sense::CLICK) + !self.dragging && !self.abandoned && !self.left && self.sense.contains(Sense::CLICK) } } @@ -568,7 +573,7 @@ impl PressMachine { } PointerEvent::Gone => { if let Some(open) = &mut self.open { - open.abandoned = true; + open.left = true; } } PointerEvent::Pressed { button, pos: at, time, clicks } => { @@ -607,6 +612,7 @@ impl PressMachine { start: PressStart::new(at, button, time, clicks), dragging: false, abandoned: false, + left: false, reported: false, drag_reported: false, released_at: None, @@ -739,6 +745,25 @@ mod tests { assert!(machine.target().is_none(), "the release ends the press"); } + /// The pointer leaving the window (a press on a window's edge grip pulled outward) ends the press's click but not + /// its drag: the window keeps getting the held button's moves from outside, and they start the drag once past slop. + /// The resize from a window edge used to fail whenever the pointer left the window before it passed slop. + #[test] + fn a_press_whose_pointer_left_the_window_still_drags_but_no_longer_clicks() { + let moved = |x: f32| PointerEvent::Moved { at: pos2(x, 0.0), sample: None }; + let up = |x: f32| PointerEvent::released(pos2(x, 0.0)); + let gone = PointerEvent::Gone; + let out = [moved(SLOP / 2.0), gone]; + assert_eq!(phases(&[&[press(0.0, 1.0)], &out, &[moved(SLOP * 2.0)], &[moved(SLOP * 3.0)], &[up(SLOP * 3.0)]], Sense::DRAG), "D H S G R"); + assert_eq!(phases(&[&[press(0.0, 1.0)], &out, &[up(SLOP / 2.0)]], Sense::CLICK), "D H R", "a click target loses its click"); + assert_eq!( + phases(&[&[press(0.0, 1.0)], &out, &[moved(0.0)], &[up(0.0)]], Sense::CLICK | Sense::DRAG), + "D H H R", + "coming back does not bring the click back" + ); + assert_eq!(phases(&[&[press(0.0, 1.0)], &[moved(0.0)], &[up(0.0)]], Sense::CLICK), "D H R!", "a press that stays in still clicks"); + } + #[test] fn held_reports_the_pointer_of_its_pass_within_slop() { let mut machine = PressMachine::new(); diff --git a/crates/ui-contract/tests/it/runtime/window_move.rs b/crates/ui-contract/tests/it/runtime/window_move.rs index 8913ebddb..7fb2b94d9 100644 --- a/crates/ui-contract/tests/it/runtime/window_move.rs +++ b/crates/ui-contract/tests/it/runtime/window_move.rs @@ -122,6 +122,29 @@ fn root_drag(chrome: WindowChrome, at: Pos2, by: Vec2) -> (Vec, (drag(at, by, |events| rig.frame(&windows, events, vec![])), rig) } +/// A grip pulled out of the window resizes it: winit reports the pointer leaving the window (`PointerGone`) while the +/// button is held, before the press has passed slop, and the moves from outside still start the drag. The resize used +/// to start only when the pointer passed slop inside the window, so a quick outward pull on an edge did nothing. +#[trial] +fn a_grip_pulled_out_of_the_window_still_resizes_it() { + let windows = root(WindowChrome::Integrated); + let rig = Rig::new(Mount::window(Resize::GRIPS)); + for _ in 0..4 { + rig.frame(&windows, vec![], vec![]); + } + let edge = pos2(2.0, ROOT.y / 2.0); + let mut sent = rig.frame(&windows, vec![moved(edge)], vec![]); + sent.extend(rig.frame(&windows, vec![press(edge)], vec![])); + // The first move lands outside the window, within slop of the press; winit reports the leave with it. + sent.extend(rig.frame(&windows, vec![moved(edge - vec2(3.0, 0.0)), Event::PointerGone], vec![])); + for step in 2..=4 { + sent.extend(rig.frame(&windows, vec![moved(edge - vec2(5.0 * step as f32, 0.0))], vec![])); + } + sent.extend(rig.frame(&windows, vec![release(edge - vec2(20.0, 0.0))], vec![])); + sent.extend(rig.frame(&windows, vec![], vec![])); + assert_eq!(resizes(&sent), [ResizeDirection::West], "a pull out of the left edge resizes from the west: {sent:?}"); +} + #[trial] fn a_window_mounts_edges_resize_the_window_and_the_childs_press_keeps_its_click() { let (sent, _) = root_drag(WindowChrome::Integrated, pos2(1.0, ROOT.y / 2.0), vec2(20.0, 0.0));