Skip to content

Commit ef3b003

Browse files
authored
refactor!: Drop DefaultActionVerb (#472)
1 parent 2fa0d3f commit ef3b003

File tree

8 files changed

+44
-117
lines changed

8 files changed

+44
-117
lines changed

common/src/lib.rs

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,6 @@ pub enum Role {
268268
}
269269

270270
/// An action to be taken on an accessibility node.
271-
///
272-
/// In contrast to [`DefaultActionVerb`], these describe what happens to the
273-
/// object, e.g. "focus".
274271
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
275272
#[cfg_attr(feature = "enumn", derive(enumn::N))]
276273
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -282,8 +279,8 @@ pub enum Role {
282279
)]
283280
#[repr(u8)]
284281
pub enum Action {
285-
/// Do the default action for an object, typically this means "click".
286-
Default,
282+
/// Do the equivalent of a single click or tap.
283+
Click,
287284

288285
Focus,
289286
Blur,
@@ -357,7 +354,7 @@ impl Action {
357354
// want to bring this crate by default though and we can't use a
358355
// macro as it would break C bindings header file generation.
359356
match value {
360-
0 => Some(Action::Default),
357+
0 => Some(Action::Click),
361358
1 => Some(Action::Focus),
362359
2 => Some(Action::Blur),
363360
3 => Some(Action::Collapse),
@@ -468,39 +465,6 @@ pub enum Toggled {
468465
Mixed,
469466
}
470467

471-
/// Describes the action that will be performed on a given node when
472-
/// executing the default action, which is a click.
473-
///
474-
/// In contrast to [`Action`], these describe what the user can do on the
475-
/// object, e.g. "press", not what happens to the object as a result.
476-
/// Only one verb can be used at a time to describe the default action.
477-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
478-
#[cfg_attr(feature = "enumn", derive(enumn::N))]
479-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
480-
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
481-
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
482-
#[cfg_attr(
483-
feature = "pyo3",
484-
pyclass(module = "accesskit", rename_all = "SCREAMING_SNAKE_CASE")
485-
)]
486-
#[repr(u8)]
487-
pub enum DefaultActionVerb {
488-
Click,
489-
Focus,
490-
Check,
491-
Uncheck,
492-
/// A click will be performed on one of the node's ancestors.
493-
/// This happens when the node itself is not clickable, but one of its
494-
/// ancestors has click handlers attached which are able to capture the click
495-
/// as it bubbles up.
496-
ClickAncestor,
497-
Jump,
498-
Open,
499-
Press,
500-
Select,
501-
Unselect,
502-
}
503-
504468
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
505469
#[cfg_attr(feature = "enumn", derive(enumn::N))]
506470
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -779,7 +743,6 @@ enum PropertyValue {
779743
Invalid(Invalid),
780744
Toggled(Toggled),
781745
Live(Live),
782-
DefaultActionVerb(DefaultActionVerb),
783746
TextDirection(TextDirection),
784747
Orientation(Orientation),
785748
SortDirection(SortDirection),
@@ -892,7 +855,6 @@ enum PropertyId {
892855
Invalid,
893856
Toggled,
894857
Live,
895-
DefaultActionVerb,
896858
TextDirection,
897859
Orientation,
898860
SortDirection,
@@ -1775,7 +1737,6 @@ unique_enum_property_methods! {
17751737
(Invalid, invalid, set_invalid, clear_invalid),
17761738
(Toggled, toggled, set_toggled, clear_toggled),
17771739
(Live, live, set_live, clear_live),
1778-
(DefaultActionVerb, default_action_verb, set_default_action_verb, clear_default_action_verb),
17791740
(TextDirection, text_direction, set_text_direction, clear_text_direction),
17801741
(Orientation, orientation, set_orientation, clear_orientation),
17811742
(SortDirection, sort_direction, set_sort_direction, clear_sort_direction),
@@ -1957,7 +1918,6 @@ impl Serialize for Properties {
19571918
Invalid,
19581919
Toggled,
19591920
Live,
1960-
DefaultActionVerb,
19611921
TextDirection,
19621922
Orientation,
19631923
SortDirection,
@@ -2086,7 +2046,6 @@ impl<'de> Visitor<'de> for PropertiesVisitor {
20862046
Invalid { Invalid },
20872047
Toggled { Toggled },
20882048
Live { Live },
2089-
DefaultActionVerb { DefaultActionVerb },
20902049
TextDirection { TextDirection },
20912050
Orientation { Orientation },
20922051
SortDirection { SortDirection },
@@ -2234,7 +2193,6 @@ impl JsonSchema for Properties {
22342193
Invalid { Invalid },
22352194
Toggled { Toggled },
22362195
Live { Live },
2237-
DefaultActionVerb { DefaultActionVerb },
22382196
TextDirection { TextDirection },
22392197
Orientation { Orientation },
22402198
SortDirection { SortDirection },
@@ -2437,7 +2395,7 @@ mod tests {
24372395

24382396
#[test]
24392397
fn action_n() {
2440-
assert_eq!(Action::n(0), Some(Action::Default));
2398+
assert_eq!(Action::n(0), Some(Action::Click));
24412399
assert_eq!(Action::n(1), Some(Action::Focus));
24422400
assert_eq!(Action::n(2), Some(Action::Blur));
24432401
assert_eq!(Action::n(3), Some(Action::Collapse));
@@ -2475,9 +2433,9 @@ mod tests {
24752433
);
24762434

24772435
let mut builder = NodeBuilder::new(Role::Unknown);
2478-
builder.add_action(Action::Default);
2436+
builder.add_action(Action::Click);
24792437
assert_eq!(
2480-
&[Action::Default],
2438+
&[Action::Click],
24812439
action_mask_to_action_vec(builder.actions).as_slice()
24822440
);
24832441

@@ -2489,10 +2447,10 @@ mod tests {
24892447
);
24902448

24912449
let mut builder = NodeBuilder::new(Role::Unknown);
2492-
builder.add_action(Action::Default);
2450+
builder.add_action(Action::Click);
24932451
builder.add_action(Action::ShowContextMenu);
24942452
assert_eq!(
2495-
&[Action::Default, Action::ShowContextMenu],
2453+
&[Action::Click, Action::ShowContextMenu],
24962454
action_mask_to_action_vec(builder.actions).as_slice()
24972455
);
24982456

consumer/src/node.rs

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
use std::{iter::FusedIterator, sync::Arc};
1212

1313
use accesskit::{
14-
Action, Affine, DefaultActionVerb, Live, Node as NodeData, NodeId, Orientation, Point, Rect,
15-
Role, TextSelection, Toggled,
14+
Action, Affine, Live, Node as NodeData, NodeId, Orientation, Point, Rect, Role, TextSelection,
15+
Toggled,
1616
};
1717

1818
use crate::filters::FilterResult;
@@ -404,31 +404,17 @@ impl<'a> Node<'a> {
404404
self.data().orientation()
405405
}
406406

407-
pub fn default_action_verb(&self) -> Option<DefaultActionVerb> {
408-
self.data().default_action_verb()
409-
}
410-
411407
// When probing for supported actions as the next several functions do,
412408
// it's tempting to check the role. But it's better to not assume anything
413409
// beyond what the provider has explicitly told us. Rationale:
414-
// if the provider developer forgot to correctly set `default_action_verb`,
410+
// if the provider developer forgot to call `add_action` for an action,
415411
// an AT (or even AccessKit itself) can fall back to simulating
416412
// a mouse click. But if the provider doesn't handle an action request
417413
// and we assume that it will based on the role, the attempted action
418414
// does nothing. This stance is a departure from Chromium.
419415

420416
pub fn is_clickable(&self) -> bool {
421-
// If it has a custom default action verb except for
422-
// `DefaultActionVerb::ClickAncestor`, it's definitely clickable.
423-
// `DefaultActionVerb::ClickAncestor` is used when a node with a
424-
// click listener is present in its ancestry chain.
425-
if let Some(verb) = self.default_action_verb() {
426-
if verb != DefaultActionVerb::ClickAncestor {
427-
return true;
428-
}
429-
}
430-
431-
false
417+
self.supports_action(Action::Click)
432418
}
433419

434420
pub fn supports_toggle(&self) -> bool {
@@ -449,16 +435,11 @@ impl<'a> Node<'a> {
449435
// "invocable", as the "invoke" action would be a redundant synonym
450436
// for the "set focus" action. The same logic applies to selection.
451437
self.is_clickable()
452-
&& !matches!(
453-
self.default_action_verb(),
454-
Some(
455-
DefaultActionVerb::Focus
456-
| DefaultActionVerb::Select
457-
| DefaultActionVerb::Unselect
458-
)
459-
)
438+
&& !self.is_text_input()
439+
&& !matches!(self.role(), Role::Document | Role::Terminal)
460440
&& !self.supports_toggle()
461441
&& !self.supports_expand_collapse()
442+
&& self.is_selected().is_none()
462443
}
463444

464445
// The future of the `Action` enum is undecided, so keep the following

platforms/atspi-common/src/node.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// found in the LICENSE.chromium file.
1010

1111
use accesskit::{
12-
Action, ActionData, ActionRequest, Affine, DefaultActionVerb, Live, NodeId, Orientation, Point,
13-
Rect, Role, Toggled,
12+
Action, ActionData, ActionRequest, Affine, Live, NodeId, Orientation, Point, Rect, Role,
13+
Toggled,
1414
};
1515
use accesskit_consumer::{FilterResult, Node, TreeState};
1616
use atspi_common::{
@@ -361,7 +361,7 @@ impl<'a> NodeWrapper<'a> {
361361
}
362362

363363
fn supports_action(&self) -> bool {
364-
self.0.default_action_verb().is_some()
364+
self.0.is_clickable()
365365
}
366366

367367
fn supports_component(&self) -> bool {
@@ -403,29 +403,18 @@ impl<'a> NodeWrapper<'a> {
403403
}
404404

405405
fn n_actions(&self) -> i32 {
406-
match self.0.default_action_verb() {
407-
Some(_) => 1,
408-
None => 0,
406+
if self.0.is_clickable() {
407+
1
408+
} else {
409+
0
409410
}
410411
}
411412

412413
fn get_action_name(&self, index: i32) -> String {
413414
if index != 0 {
414415
return String::new();
415416
}
416-
String::from(match self.0.default_action_verb() {
417-
Some(DefaultActionVerb::Click) => "click",
418-
Some(DefaultActionVerb::Focus) => "focus",
419-
Some(DefaultActionVerb::Check) => "check",
420-
Some(DefaultActionVerb::Uncheck) => "uncheck",
421-
Some(DefaultActionVerb::ClickAncestor) => "clickAncestor",
422-
Some(DefaultActionVerb::Jump) => "jump",
423-
Some(DefaultActionVerb::Open) => "open",
424-
Some(DefaultActionVerb::Press) => "press",
425-
Some(DefaultActionVerb::Select) => "select",
426-
Some(DefaultActionVerb::Unselect) => "unselect",
427-
None => "",
428-
})
417+
String::from(if self.0.is_clickable() { "click" } else { "" })
429418
}
430419

431420
fn raw_bounds_and_transform(&self) -> (Option<Rect>, Affine) {
@@ -870,7 +859,7 @@ impl PlatformNode {
870859
return Ok(false);
871860
}
872861
self.do_action_internal(|_, _| ActionRequest {
873-
action: Action::Default,
862+
action: Action::Click,
874863
target: self.id,
875864
data: None,
876865
})?;

platforms/macos/src/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ declare_class!(
553553
let clickable = node.is_clickable();
554554
if clickable {
555555
context.do_action(ActionRequest {
556-
action: Action::Default,
556+
action: Action::Click,
557557
target: node.id(),
558558
data: None,
559559
});

platforms/windows/examples/hello_world.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Based on the create_window sample in windows-samples-rs.
22

33
use accesskit::{
4-
Action, ActionHandler, ActionRequest, ActivationHandler, DefaultActionVerb, Live, Node,
5-
NodeBuilder, NodeId, Rect, Role, Tree, TreeUpdate,
4+
Action, ActionHandler, ActionRequest, ActivationHandler, Live, Node, NodeBuilder, NodeId, Rect,
5+
Role, Tree, TreeUpdate,
66
};
77
use accesskit_windows::Adapter;
88
use once_cell::sync::Lazy;
@@ -59,7 +59,7 @@ const BUTTON_2_RECT: Rect = Rect {
5959
};
6060

6161
const SET_FOCUS_MSG: u32 = WM_USER;
62-
const DO_DEFAULT_ACTION_MSG: u32 = WM_USER + 1;
62+
const CLICK_MSG: u32 = WM_USER + 1;
6363

6464
fn build_button(id: NodeId, name: &str) -> Node {
6565
let rect = match id {
@@ -72,7 +72,7 @@ fn build_button(id: NodeId, name: &str) -> Node {
7272
builder.set_bounds(rect);
7373
builder.set_name(name);
7474
builder.add_action(Action::Focus);
75-
builder.set_default_action_verb(DefaultActionVerb::Click);
75+
builder.add_action(Action::Click);
7676
builder.build()
7777
}
7878

@@ -206,11 +206,11 @@ impl ActionHandler for SimpleActionHandler {
206206
}
207207
.unwrap();
208208
}
209-
Action::Default => {
209+
Action::Click => {
210210
unsafe {
211211
PostMessageW(
212212
self.window,
213-
DO_DEFAULT_ACTION_MSG,
213+
CLICK_MSG,
214214
WPARAM(0),
215215
LPARAM(request.target.0 as _),
216216
)
@@ -308,7 +308,7 @@ extern "system" fn wndproc(window: HWND, message: u32, wparam: WPARAM, lparam: L
308308
}
309309
LRESULT(0)
310310
}
311-
DO_DEFAULT_ACTION_MSG => {
311+
CLICK_MSG => {
312312
let id = NodeId(lparam.0 as _);
313313
if id == BUTTON_1_ID || id == BUTTON_2_ID {
314314
let state = unsafe { &*get_window_state(window) };

platforms/windows/src/node.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,8 @@ impl PlatformNode {
597597
Ok(())
598598
}
599599

600-
fn do_default_action(&self) -> Result<()> {
601-
self.do_action(|| (Action::Default, None))
600+
fn click(&self) -> Result<()> {
601+
self.do_action(|| (Action::Click, None))
602602
}
603603

604604
fn relative(&self, node_id: NodeId) -> Self {
@@ -886,12 +886,12 @@ patterns! {
886886
(ToggleState, toggle_state, ToggleState)
887887
), (
888888
fn Toggle(&self) -> Result<()> {
889-
self.do_default_action()
889+
self.click()
890890
}
891891
)),
892892
(Invoke, is_invoke_pattern_supported, (), (
893893
fn Invoke(&self) -> Result<()> {
894-
self.do_default_action()
894+
self.click()
895895
}
896896
)),
897897
(Value, is_value_pattern_supported, (
@@ -923,7 +923,7 @@ patterns! {
923923
(IsSelected, is_selected, BOOL)
924924
), (
925925
fn Select(&self) -> Result<()> {
926-
self.do_default_action()
926+
self.click()
927927
},
928928

929929
fn AddToSelection(&self) -> Result<()> {

0 commit comments

Comments
 (0)