1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Modified by Longbridge for gpui-fast.
//! Whether the pointer is in the window, for hit testing.
//!
//! `MouseExited` carries the exit position, which lies on the window edge and
//! so is still inside hitboxes flush with that edge (such as maximized title
//! bar buttons on X11). Hit testing ignores the last position from the exit
//! until the next pointer event, so those hitboxes stop showing as hovered.
use crate::{FileDropEvent, Frame, HitTest, PlatformInput, Window};
/// Records whether `event` moves the pointer out of the window or back in.
pub(crate) fn note_input(window: &mut Window, event: &PlatformInput) {
match event {
PlatformInput::MouseExited(_) => window.fast_pointer_outside = true,
PlatformInput::KeyDown(_)
| PlatformInput::KeyUp(_)
| PlatformInput::ModifiersChanged(_)
| PlatformInput::MousePressure(_)
| PlatformInput::FileDrop(FileDropEvent::Exited | FileDropEvent::Ended) => {}
_ => window.fast_pointer_outside = false,
}
}
/// Hit tests `frame` at the pointer, or nothing while the pointer is outside.
pub(crate) fn hit_test(window: &Window, frame: &Frame) -> HitTest {
if window.fast_pointer_outside {
HitTest::default()
} else {
frame.hit_test(window.mouse_position)
}
}
/// Records the hover state an element paints with, so the next mouse move compares against
/// what is on screen. An element can become hovered without a mouse move (an occluding overlay
/// closes under a still pointer); if the move that leaves it compared against a stale `false`,
/// nothing would be redrawn and the hover style would stay (gpui-kit#4072).
pub(crate) fn note_painted_hover(
state: &Option<std::rc::Rc<std::cell::RefCell<crate::ElementHoverState>>>,
group: bool,
hitbox: &crate::HitboxId,
window: &Window,
) {
if let Some(state) = state {
let hovered = !window.last_input_was_touch() && hitbox.is_hovered(window);
let mut state = state.borrow_mut();
if group {
state.group = hovered;
} else {
state.element = hovered;
}
}
}