Attempt to remove the dangeous element focus API

This commit is contained in:
Kirill Bulatov
2023-12-12 15:07:27 +02:00
parent 43b8d65fee
commit 717b2885f8
5 changed files with 39 additions and 80 deletions
+1 -45
View File
@@ -441,6 +441,7 @@ pub trait StatefulInteractiveElement: InteractiveElement {
}
}
// TODO kb do we leave those on an element?
pub trait FocusableElement: InteractiveElement {
fn focus(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self
where
@@ -485,51 +486,6 @@ pub trait FocusableElement: InteractiveElement {
}));
self
}
fn on_focus_in(mut self, listener: impl Fn(&FocusEvent, &mut WindowContext) + 'static) -> Self
where
Self: Sized,
{
self.interactivity()
.focus_listeners
.push(Box::new(move |focus_handle, event, cx| {
let descendant_blurred = event
.blurred
.as_ref()
.map_or(false, |blurred| focus_handle.contains(blurred, cx));
let descendant_focused = event
.focused
.as_ref()
.map_or(false, |focused| focus_handle.contains(focused, cx));
if !descendant_blurred && descendant_focused {
listener(event, cx)
}
}));
self
}
fn on_focus_out(mut self, listener: impl Fn(&FocusEvent, &mut WindowContext) + 'static) -> Self
where
Self: Sized,
{
self.interactivity()
.focus_listeners
.push(Box::new(move |focus_handle, event, cx| {
let descendant_blurred = event
.blurred
.as_ref()
.map_or(false, |blurred| focus_handle.contains(blurred, cx));
let descendant_focused = event
.focused
.as_ref()
.map_or(false, |focused| focus_handle.contains(focused, cx));
if descendant_blurred && !descendant_focused {
listener(event, cx)
}
}));
self
}
}
pub type FocusListeners = SmallVec<[FocusListener; 2]>;
+1
View File
@@ -168,6 +168,7 @@ impl FocusHandle {
self.id.within_focused(cx)
}
// TODO kb now never used?
/// Obtains whether this handle contains the given handle in the most recently rendered frame.
pub(crate) fn contains(&self, other: &Self, cx: &WindowContext) -> bool {
self.id.contains(other.id, cx)