Skip to content

Commit

Permalink
refactor!: Rename Checked to Toggled; drop ToggleButton role (#388
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mwcampbell authored Apr 25, 2024
1 parent b3484c0 commit 6bc040b
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 44 deletions.
4 changes: 2 additions & 2 deletions bindings/c/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ renaming_overrides_prefixing = true
"Affine" = "accesskit_affine"
"AriaCurrent" = "accesskit_aria_current"
"AutoComplete" = "accesskit_auto_complete"
"Checked" = "accesskit_checked"
"DeactivationHandlerCallback" = "accesskit_deactivation_handler_callback"
"DefaultActionVerb" = "accesskit_default_action_verb"
"HWND" = "HWND"
Expand All @@ -54,12 +53,12 @@ renaming_overrides_prefixing = true
"TextAlign" = "accesskit_text_align"
"TextDecoration" = "accesskit_text_decoration"
"TextDirection" = "accesskit_text_direction"
"Toggled" = "accesskit_toggled"
"Vec2" = "accesskit_vec2"
"VerticalOffset" = "accesskit_vertical_offset"
"WPARAM" = "WPARAM"
"opt_AriaCurrent" = "accesskit_opt_aria_current"
"opt_AutoComplete" = "accesskit_opt_auto_complete"
"opt_Checked" = "accesskit_opt_checked"
"opt_DefaultActionVerb" = "accesskit_opt_default_action_verb"
"opt_HasPopup" = "accesskit_opt_has_popup"
"opt_Invalid" = "accesskit_opt_invalid"
Expand All @@ -70,6 +69,7 @@ renaming_overrides_prefixing = true
"opt_TextAlign" = "accesskit_opt_text_align"
"opt_TextDecoration" = "accesskit_opt_text_decoration"
"opt_TextDirection" = "accesskit_opt_text_direction"
"opt_Toggled" = "accesskit_opt_toggled"
"opt_VerticalOffset" = "accesskit_opt_vertical_offset"

[enum]
Expand Down
2 changes: 1 addition & 1 deletion bindings/c/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ bool_property_methods! {

unique_enum_property_methods! {
(Invalid, invalid, set_invalid, clear_invalid),
(Checked, checked, set_checked, clear_checked),
(Toggled, toggled, set_toggled, clear_toggled),
(Live, live, set_live, clear_live),
(DefaultActionVerb, default_action_verb, set_default_action_verb, clear_default_action_verb),
(TextDirection, text_direction, set_text_direction, clear_text_direction),
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ bool_property_methods! {

unique_enum_property_methods! {
(accesskit::Invalid, invalid, set_invalid, clear_invalid),
(accesskit::Checked, checked, set_checked, clear_checked),
(accesskit::Toggled, toggled, set_toggled, clear_toggled),
(accesskit::Live, live, set_live, clear_live),
(accesskit::DefaultActionVerb, default_action_verb, set_default_action_verb, clear_default_action_verb),
(accesskit::TextDirection, text_direction, set_text_direction, clear_text_direction),
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn accesskit(py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_class::<::accesskit::Orientation>()?;
m.add_class::<::accesskit::TextDirection>()?;
m.add_class::<::accesskit::Invalid>()?;
m.add_class::<::accesskit::Checked>()?;
m.add_class::<::accesskit::Toggled>()?;
m.add_class::<::accesskit::DefaultActionVerb>()?;
m.add_class::<::accesskit::SortDirection>()?;
m.add_class::<::accesskit::AriaCurrent>()?;
Expand Down
15 changes: 7 additions & 8 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ pub enum Role {
LayoutTableRow,
LayoutTable,
Switch,
ToggleButton,
Menu,

MultilineTextInput,
Expand Down Expand Up @@ -501,7 +500,7 @@ pub enum Invalid {
pyclass(module = "accesskit", rename_all = "SCREAMING_SNAKE_CASE")
)]
#[repr(u8)]
pub enum Checked {
pub enum Toggled {
False,
True,
Mixed,
Expand Down Expand Up @@ -817,7 +816,7 @@ enum PropertyValue {
CoordSlice(Box<[f32]>),
Bool(bool),
Invalid(Invalid),
Checked(Checked),
Toggled(Toggled),
Live(Live),
DefaultActionVerb(DefaultActionVerb),
TextDirection(TextDirection),
Expand Down Expand Up @@ -931,7 +930,7 @@ enum PropertyId {

// Unique enums
Invalid,
Checked,
Toggled,
Live,
DefaultActionVerb,
TextDirection,
Expand Down Expand Up @@ -1733,7 +1732,7 @@ bool_property_methods! {

unique_enum_property_methods! {
(Invalid, invalid, set_invalid, clear_invalid),
(Checked, checked, set_checked, clear_checked),
(Toggled, toggled, set_toggled, clear_toggled),
(Live, live, set_live, clear_live),
(DefaultActionVerb, default_action_verb, set_default_action_verb, clear_default_action_verb),
(TextDirection, text_direction, set_text_direction, clear_text_direction),
Expand Down Expand Up @@ -1883,7 +1882,7 @@ impl Serialize for Node {
CoordSlice,
Bool,
Invalid,
Checked,
Toggled,
Live,
DefaultActionVerb,
TextDirection,
Expand Down Expand Up @@ -2028,7 +2027,7 @@ impl<'de> Visitor<'de> for NodeVisitor {
Selected
},
Invalid { Invalid },
Checked { Checked },
Toggled { Toggled },
Live { Live },
DefaultActionVerb { DefaultActionVerb },
TextDirection { TextDirection },
Expand Down Expand Up @@ -2214,7 +2213,7 @@ impl JsonSchema for Node {
Selected
},
Invalid { Invalid },
Checked { Checked },
Toggled { Toggled },
Live { Live },
DefaultActionVerb { DefaultActionVerb },
TextDirection { TextDirection },
Expand Down
11 changes: 5 additions & 6 deletions consumer/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use std::{iter::FusedIterator, ops::Deref};

use accesskit::{
Action, Affine, Checked, DefaultActionVerb, Live, Node as NodeData, NodeId, Point, Rect, Role,
TextSelection,
Action, Affine, DefaultActionVerb, Live, Node as NodeData, NodeId, Point, Rect, Role,
TextSelection, Toggled,
};

use crate::filters::FilterResult;
Expand Down Expand Up @@ -384,8 +384,8 @@ impl NodeState {
self.is_read_only() || self.is_disabled()
}

pub fn checked(&self) -> Option<Checked> {
self.data().checked()
pub fn toggled(&self) -> Option<Toggled> {
self.data().toggled()
}

pub fn numeric_value(&self) -> Option<f64> {
Expand Down Expand Up @@ -461,7 +461,7 @@ impl NodeState {
}

pub fn supports_toggle(&self) -> bool {
self.checked().is_some()
self.toggled().is_some()
}

pub fn supports_expand_collapse(&self) -> bool {
Expand Down Expand Up @@ -580,7 +580,6 @@ impl NodeState {
| Role::RadioGroup
| Role::Slider
| Role::Switch
| Role::ToggleButton
| Role::TreeGrid
)
}
Expand Down
26 changes: 16 additions & 10 deletions platforms/atspi-common/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// found in the LICENSE.chromium file.

use accesskit::{
Action, ActionData, ActionRequest, Affine, Checked, DefaultActionVerb, Live, NodeId, Point,
Rect, Role,
Action, ActionData, ActionRequest, Affine, DefaultActionVerb, Live, NodeId, Point, Rect, Role,
Toggled,
};
use accesskit_consumer::{DetachedNode, FilterResult, Node, NodeState, TreeState};
use atspi_common::{
Expand Down Expand Up @@ -100,7 +100,14 @@ impl<'a> NodeWrapper<'a> {
Role::Banner | Role::Header => AtspiRole::Landmark,
Role::Blockquote => AtspiRole::BlockQuote,
Role::Caret => AtspiRole::Unknown,
Role::Button | Role::DefaultButton => AtspiRole::PushButton,
Role::Button => {
if self.node_state().toggled().is_some() {
AtspiRole::ToggleButton
} else {
AtspiRole::PushButton
}
}
Role::DefaultButton => AtspiRole::PushButton,
Role::Canvas => AtspiRole::Canvas,
Role::Caption => AtspiRole::Caption,
Role::Cell => AtspiRole::TableCell,
Expand Down Expand Up @@ -279,7 +286,6 @@ impl<'a> NodeWrapper<'a> {
AtspiRole::Static
}
Role::Timer => AtspiRole::Timer,
Role::ToggleButton => AtspiRole::ToggleButton,
Role::Toolbar => AtspiRole::ToolBar,
Role::Tooltip => AtspiRole::ToolTip,
Role::Tree => AtspiRole::Tree,
Expand Down Expand Up @@ -324,7 +330,7 @@ impl<'a> NodeWrapper<'a> {
if filter_result == FilterResult::Include {
atspi_state.insert(State::Visible | State::Showing);
}
if atspi_role != AtspiRole::ToggleButton && state.checked().is_some() {
if atspi_role != AtspiRole::ToggleButton && state.toggled().is_some() {
atspi_state.insert(State::Checkable);
}
if let Some(selected) = state.is_selected() {
Expand All @@ -348,13 +354,13 @@ impl<'a> NodeWrapper<'a> {
atspi_state.insert(State::Indeterminate);
}

// Checked state
match state.checked() {
Some(Checked::Mixed) => atspi_state.insert(State::Indeterminate),
Some(Checked::True) if atspi_role == AtspiRole::ToggleButton => {
// Toggled state
match state.toggled() {
Some(Toggled::Mixed) => atspi_state.insert(State::Indeterminate),
Some(Toggled::True) if atspi_role == AtspiRole::ToggleButton => {
atspi_state.insert(State::Pressed)
}
Some(Checked::True) => atspi_state.insert(State::Checked),
Some(Toggled::True) => atspi_state.insert(State::Checked),
_ => {}
}

Expand Down
16 changes: 11 additions & 5 deletions platforms/macos/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#![allow(non_upper_case_globals)]

use accesskit::{Action, ActionData, ActionRequest, Checked, NodeId, Role, TextSelection};
use accesskit::{Action, ActionData, ActionRequest, NodeId, Role, TextSelection, Toggled};
use accesskit_consumer::{DetachedNode, FilterResult, Node, NodeState};
use objc2::{
declare_class, msg_send_id,
Expand Down Expand Up @@ -57,7 +57,14 @@ fn ns_role(node_state: &NodeState) -> &'static NSAccessibilityRole {
| Role::PasswordInput
| Role::PhoneNumberInput
| Role::UrlInput => NSAccessibilityTextFieldRole,
Role::Button | Role::DefaultButton => NSAccessibilityButtonRole,
Role::Button => {
if node_state.toggled().is_some() {
NSAccessibilityCheckBoxRole
} else {
NSAccessibilityButtonRole
}
}
Role::DefaultButton => NSAccessibilityButtonRole,
Role::Pane => NSAccessibilityUnknownRole,
Role::RowHeader => NSAccessibilityCellRole,
Role::ColumnHeader => NSAccessibilityCellRole,
Expand All @@ -70,7 +77,6 @@ fn ns_role(node_state: &NodeState) -> &'static NSAccessibilityRole {
Role::LayoutTableRow => NSAccessibilityGroupRole,
Role::LayoutTable => NSAccessibilityGroupRole,
Role::Switch => NSAccessibilityCheckBoxRole,
Role::ToggleButton => NSAccessibilityCheckBoxRole,
Role::Menu => NSAccessibilityMenuRole,
Role::MultilineTextInput => NSAccessibilityTextAreaRole,
Role::DateInput | Role::DateTimeInput | Role::WeekInput | Role::MonthInput => {
Expand Down Expand Up @@ -298,8 +304,8 @@ impl<'a> NodeWrapper<'a> {

pub(crate) fn value(&self) -> Option<Value> {
let state = self.node_state();
if let Some(checked) = state.checked() {
return Some(Value::Bool(checked != Checked::False));
if let Some(toggled) = state.toggled() {
return Some(Value::Bool(toggled != Toggled::False));
}
if let Some(value) = self.node_value() {
return Some(Value::String(value));
Expand Down
19 changes: 9 additions & 10 deletions platforms/windows/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#![allow(non_upper_case_globals)]

use accesskit::{
Action, ActionData, ActionRequest, Checked, Live, NodeId, NodeIdContent, Point, Role,
Action, ActionData, ActionRequest, Live, NodeId, NodeIdContent, Point, Role, Toggled,
};
use accesskit_consumer::{DetachedNode, FilterResult, Node, NodeState, TreeState};
use paste::paste;
Expand Down Expand Up @@ -100,7 +100,6 @@ impl<'a> NodeWrapper<'a> {
Role::LayoutTableRow => UIA_DataItemControlTypeId,
Role::LayoutTable => UIA_TableControlTypeId,
Role::Switch => UIA_ButtonControlTypeId,
Role::ToggleButton => UIA_ButtonControlTypeId,
Role::Menu => UIA_MenuControlTypeId,
Role::Abbr => UIA_TextControlTypeId,
Role::Alert => UIA_TextControlTypeId,
Expand Down Expand Up @@ -320,14 +319,14 @@ impl<'a> NodeWrapper<'a> {
}

fn is_toggle_pattern_supported(&self) -> bool {
self.node_state().checked().is_some() && !self.is_selection_item_pattern_supported()
self.node_state().toggled().is_some() && !self.is_selection_item_pattern_supported()
}

fn toggle_state(&self) -> ToggleState {
match self.node_state().checked().unwrap() {
Checked::False => ToggleState_Off,
Checked::True => ToggleState_On,
Checked::Mixed => ToggleState_Indeterminate,
match self.node_state().toggled().unwrap() {
Toggled::False => ToggleState_Off,
Toggled::True => ToggleState_On,
Toggled::Mixed => ToggleState_Indeterminate,
}
}

Expand Down Expand Up @@ -386,8 +385,8 @@ impl<'a> NodeWrapper<'a> {
// SelectionItem.IsSelected is exposed when aria-checked is True or
// False, for 'radio' and 'menuitemradio' roles.
Role::RadioButton | Role::MenuItemRadio => matches!(
self.node_state().checked(),
Some(Checked::True | Checked::False)
self.node_state().toggled(),
Some(Toggled::True | Toggled::False)
),
// https://www.w3.org/TR/wai-aria-1.1/#aria-selected
// SelectionItem.IsSelected is exposed when aria-select is True or False.
Expand All @@ -406,7 +405,7 @@ impl<'a> NodeWrapper<'a> {
// SelectionItem.IsSelected is set according to the True or False
// value of aria-checked for 'radio' and 'menuitemradio' roles.
Role::RadioButton | Role::MenuItemRadio => {
self.node_state().checked() == Some(Checked::True)
self.node_state().toggled() == Some(Toggled::True)
}
// https://www.w3.org/TR/wai-aria-1.1/#aria-selected
// SelectionItem.IsSelected is set according to the True or False
Expand Down

0 comments on commit 6bc040b

Please sign in to comment.