-
Notifications
You must be signed in to change notification settings - Fork 190
Make non-primary click events focus buttons and checkboxes. #1329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,15 +112,24 @@ impl Widget for Button { | |
| event: &PointerEvent, | ||
| ) { | ||
| match event { | ||
| PointerEvent::Down { .. } => { | ||
| ctx.capture_pointer(); | ||
| // Changes in pointer capture impact appearance, but not accessibility node | ||
| ctx.request_paint_only(); | ||
| trace!("Button {:?} pressed", ctx.widget_id()); | ||
| PointerEvent::Down { button, .. } => { | ||
| if *button == Some(PointerButton::Primary) { | ||
| ctx.capture_pointer(); | ||
| // Changes in pointer capture impact appearance, but not accessibility node | ||
| ctx.request_paint_only(); | ||
| trace!("Button {:?} pressed", ctx.widget_id()); | ||
| } | ||
| // Any click event should lead to this widget getting focused. | ||
| ctx.request_focus(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this set the focus anchor, rather than actually setting the focus directly? I think either way would be viable. On the web, it seems to do the former, from some brief testing. This doesn't block this PR. |
||
| } | ||
| PointerEvent::Up { button, .. } => { | ||
| PointerEvent::Up { | ||
| button: Some(PointerButton::Primary), | ||
| .. | ||
| } => { | ||
| if ctx.is_active() && ctx.is_hovered() { | ||
| ctx.submit_action::<Self::Action>(ButtonPress { button: *button }); | ||
| ctx.submit_action::<Self::Action>(ButtonPress { | ||
| button: Some(PointerButton::Primary), | ||
| }); | ||
| trace!("Button {:?} released", ctx.widget_id()); | ||
| } | ||
| // Changes in pointer capture impact appearance, but not accessibility node | ||
|
|
@@ -316,6 +325,7 @@ impl Widget for Button { | |
| // --- MARK: TESTS | ||
| #[cfg(test)] | ||
| mod tests { | ||
| use assert_matches::assert_matches; | ||
| use masonry_testing::{TestHarnessParams, assert_failing_render_snapshot}; | ||
|
|
||
| use super::*; | ||
|
|
@@ -363,6 +373,19 @@ mod tests { | |
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn button_right_click() { | ||
| let button = NewWidget::new(Button::with_text("Hello")); | ||
|
|
||
| let mut harness = TestHarness::create(default_property_set(), button); | ||
| let button_id = harness.root_id(); | ||
|
|
||
| harness.mouse_move_to(button_id); | ||
| harness.mouse_button_press(PointerButton::Secondary); | ||
| assert_eq!(harness.focused_widget_id(), Some(button_id)); | ||
| assert_matches!(harness.pop_action_erased(), None); | ||
| } | ||
|
Comment on lines
+376
to
+387
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need a test for an emulated touch event here. That's a |
||
|
|
||
| #[test] | ||
| fn edit_button() { | ||
| let image_1 = { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change means that buttons are no longer usable on touch screens (e.g. on Android).
We cannot land this change with that regression in place.
It also breaks
button_any_pointeron the Xilem side, which is fine, but we should just remove it if we're doing that. But no longer supporting touch screens is not a good plan.button_any_pointerwas added as a quick hack to unblock a user, but I'm not going to dig into who that was at the moment.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what kind of filter could we use that accepts touchscreen presses but rejects right-clicks?
Is it
Some(PointerButton::Primary) | None?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I should have said that explicitly