Fix regressions in focus and active support (#3622)
Release Notes: - N/A
This commit is contained in:
commit
13c064186a
3 changed files with 26 additions and 12 deletions
|
@ -656,7 +656,6 @@ pub struct Interactivity {
|
||||||
pub focusable: bool,
|
pub focusable: bool,
|
||||||
pub tracked_focus_handle: Option<FocusHandle>,
|
pub tracked_focus_handle: Option<FocusHandle>,
|
||||||
pub scroll_handle: Option<ScrollHandle>,
|
pub scroll_handle: Option<ScrollHandle>,
|
||||||
pub focus_listeners: FocusListeners,
|
|
||||||
pub group: Option<SharedString>,
|
pub group: Option<SharedString>,
|
||||||
pub base_style: Box<StyleRefinement>,
|
pub base_style: Box<StyleRefinement>,
|
||||||
pub focus_style: Option<Box<StyleRefinement>>,
|
pub focus_style: Option<Box<StyleRefinement>>,
|
||||||
|
@ -759,6 +758,26 @@ impl Interactivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If this element can be focused, register a mouse down listener
|
||||||
|
// that will automatically transfer focus when hitting the element.
|
||||||
|
// This behavior can be suppressed by using `cx.prevent_default()`.
|
||||||
|
if let Some(focus_handle) = element_state.focus_handle.clone() {
|
||||||
|
cx.on_mouse_event({
|
||||||
|
let interactive_bounds = interactive_bounds.clone();
|
||||||
|
move |event: &MouseDownEvent, phase, cx| {
|
||||||
|
if phase == DispatchPhase::Bubble
|
||||||
|
&& !cx.default_prevented()
|
||||||
|
&& interactive_bounds.visibly_contains(&event.position, cx)
|
||||||
|
{
|
||||||
|
cx.focus(&focus_handle);
|
||||||
|
// If there is a parent that is also focusable, prevent it
|
||||||
|
// from trasferring focus because we already did so.
|
||||||
|
cx.prevent_default();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
for listener in self.mouse_down_listeners.drain(..) {
|
for listener in self.mouse_down_listeners.drain(..) {
|
||||||
let interactive_bounds = interactive_bounds.clone();
|
let interactive_bounds = interactive_bounds.clone();
|
||||||
cx.on_mouse_event(move |event: &MouseDownEvent, phase, cx| {
|
cx.on_mouse_event(move |event: &MouseDownEvent, phase, cx| {
|
||||||
|
@ -988,7 +1007,7 @@ impl Interactivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
let active_state = element_state.clicked_state.clone();
|
let active_state = element_state.clicked_state.clone();
|
||||||
if !active_state.borrow().is_clicked() {
|
if active_state.borrow().is_clicked() {
|
||||||
cx.on_mouse_event(move |_: &MouseUpEvent, phase, cx| {
|
cx.on_mouse_event(move |_: &MouseUpEvent, phase, cx| {
|
||||||
if phase == DispatchPhase::Capture {
|
if phase == DispatchPhase::Capture {
|
||||||
*active_state.borrow_mut() = ElementClickedState::default();
|
*active_state.borrow_mut() = ElementClickedState::default();
|
||||||
|
@ -1002,7 +1021,7 @@ impl Interactivity {
|
||||||
.and_then(|group_active| GroupBounds::get(&group_active.group, cx));
|
.and_then(|group_active| GroupBounds::get(&group_active.group, cx));
|
||||||
let interactive_bounds = interactive_bounds.clone();
|
let interactive_bounds = interactive_bounds.clone();
|
||||||
cx.on_mouse_event(move |down: &MouseDownEvent, phase, cx| {
|
cx.on_mouse_event(move |down: &MouseDownEvent, phase, cx| {
|
||||||
if phase == DispatchPhase::Bubble {
|
if phase == DispatchPhase::Bubble && !cx.default_prevented() {
|
||||||
let group =
|
let group =
|
||||||
active_group_bounds.map_or(false, |bounds| bounds.contains(&down.position));
|
active_group_bounds.map_or(false, |bounds| bounds.contains(&down.position));
|
||||||
let element = interactive_bounds.visibly_contains(&down.position, cx);
|
let element = interactive_bounds.visibly_contains(&down.position, cx);
|
||||||
|
@ -1083,13 +1102,6 @@ impl Interactivity {
|
||||||
cx.on_action(action_type, listener)
|
cx.on_action(action_type, listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(focus_handle) = element_state.focus_handle.as_ref() {
|
|
||||||
for listener in self.focus_listeners {
|
|
||||||
let focus_handle = focus_handle.clone();
|
|
||||||
cx.on_focus_changed(move |event, cx| listener(&focus_handle, event, cx));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
f(style, scroll_offset.unwrap_or_default(), cx)
|
f(style, scroll_offset.unwrap_or_default(), cx)
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -1193,7 +1205,6 @@ impl Default for Interactivity {
|
||||||
focusable: false,
|
focusable: false,
|
||||||
tracked_focus_handle: None,
|
tracked_focus_handle: None,
|
||||||
scroll_handle: None,
|
scroll_handle: None,
|
||||||
focus_listeners: Vec::default(),
|
|
||||||
// scroll_offset: Point::default(),
|
// scroll_offset: Point::default(),
|
||||||
group: None,
|
group: None,
|
||||||
base_style: Box::new(StyleRefinement::default()),
|
base_style: Box::new(StyleRefinement::default()),
|
||||||
|
|
|
@ -1332,8 +1332,9 @@ impl<'a> WindowContext<'a> {
|
||||||
|
|
||||||
/// Dispatch a mouse or keyboard event on the window.
|
/// Dispatch a mouse or keyboard event on the window.
|
||||||
pub fn dispatch_event(&mut self, event: InputEvent) -> bool {
|
pub fn dispatch_event(&mut self, event: InputEvent) -> bool {
|
||||||
// Handlers may set this to false by calling `stop_propagation`
|
// Handlers may set this to false by calling `stop_propagation`.
|
||||||
self.app.propagate_event = true;
|
self.app.propagate_event = true;
|
||||||
|
// Handlers may set this to true by calling `prevent_default`.
|
||||||
self.window.default_prevented = false;
|
self.window.default_prevented = false;
|
||||||
|
|
||||||
let event = match event {
|
let event = match event {
|
||||||
|
|
|
@ -66,9 +66,11 @@ impl Render for FocusStory {
|
||||||
let color_4 = theme.status().conflict;
|
let color_4 = theme.status().conflict;
|
||||||
let color_5 = theme.status().ignored;
|
let color_5 = theme.status().ignored;
|
||||||
let color_6 = theme.status().renamed;
|
let color_6 = theme.status().renamed;
|
||||||
|
let color_7 = theme.status().hint;
|
||||||
|
|
||||||
div()
|
div()
|
||||||
.id("parent")
|
.id("parent")
|
||||||
|
.active(|style| style.bg(color_7))
|
||||||
.track_focus(&self.parent_focus)
|
.track_focus(&self.parent_focus)
|
||||||
.key_context("parent")
|
.key_context("parent")
|
||||||
.on_action(cx.listener(|_, _action: &ActionA, _cx| {
|
.on_action(cx.listener(|_, _action: &ActionA, _cx| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue