ferroui_base/input/i_input_root.rs
1use super::text_input::ITextInputMethodImpl;
2use super::{FocusManager, InputElement, WindowDecorationsElementRole};
3use crate::{Point, Ref};
4use std::rc::Rc;
5
6/// Defines the interface for top-level input elements: the part of a
7/// presentation source that input is delivered through.
8pub trait IInputRoot {
9 /// The focus manager of the root.
10 fn focus_manager(&self) -> Option<Rc<FocusManager>>;
11
12 /// The input element that the pointer is currently over.
13 fn pointer_over_element(&self) -> Option<Ref<InputElement>>;
14
15 /// Sets the input element that the pointer is currently over.
16 fn set_pointer_over_element(&self, value: Option<Ref<InputElement>>);
17
18 /// The element whose cursor is shown.
19 fn cursor_element(&self) -> Option<Ref<InputElement>>;
20
21 /// Sets the element whose cursor is shown.
22 fn set_cursor_element(&self, value: Option<Ref<InputElement>>);
23
24 /// The input method of the platform for this root, if it has one.
25 ///
26 /// A root that supports text input methods overrides this; the default
27 /// is a root without one.
28 fn input_method(&self) -> Option<Rc<dyn ITextInputMethodImpl>> {
29 None
30 }
31
32 /// The root input element.
33 fn root_element(&self) -> Ref<InputElement>;
34
35 /// Deviation (DEVIATIONS.md, Input): the optional form of
36 /// [`root_element`](Self::root_element).
37 ///
38 /// The root input element, or `None` once the root has closed: what the
39 /// reference reads as a null `RootElement`, for the code that runs while
40 /// an event that closed its root is still being processed.
41 fn try_root_element(&self) -> Option<Ref<InputElement>> {
42 Some(self.root_element())
43 }
44
45 /// The element keyboard input is sent to when nothing is focused.
46 fn focus_root(&self) -> Ref<InputElement>;
47
48 /// Performs a hit-test for chrome/decoration elements at the given
49 /// position, in root-relative coordinates.
50 ///
51 /// Returns `None` if no chrome element was hit (no chrome involvement
52 /// at this point),
53 /// [`WindowDecorationsElementRole::DecorationsElement`] or
54 /// [`WindowDecorationsElementRole::User`] if an interactive chrome
55 /// element was hit — the platform should redirect non-client input to
56 /// regular client input. Any other value different from
57 /// [`WindowDecorationsElementRole::None`] indicates a specific
58 /// non-client role (titlebar, resize grip, etc.).
59 fn hit_test_chrome_element(&self, _point: Point) -> Option<WindowDecorationsElementRole> {
60 None
61 }
62
63 /// Called when what is under the pointer may have changed without the
64 /// pointer moving, e.g. when the capture of a pointer changes.
65 ///
66 /// The root re-evaluates the pointer-over element. This is a dispatcher
67 /// seam: a host should update the pointer-over state from here, either
68 /// immediately or posted to its dispatcher.
69 fn pointer_over_invalidated(&self);
70}