Skip to content

Commit

Permalink
fix: Add sub roles to MacOS adapter (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
HolgerGottChristensen authored Nov 1, 2024
1 parent 9634fc2 commit 40ad828
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions platforms/macos/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,59 @@ fn ns_role(node: &Node) -> &'static NSAccessibilityRole {
}
}

fn ns_sub_role(node: &Node) -> &'static NSAccessibilitySubrole {
let role = node.role();

unsafe {
match role {
Role::Alert => ns_string!("AXApplicationAlert"),
Role::AlertDialog => ns_string!("AXApplicationAlertDialog"),
Role::Article => ns_string!("AXDocumentArticle"),
Role::Banner => ns_string!("AXLandmarkBanner"),
Role::Button if node.toggled().is_some() => NSAccessibilityToggleSubrole,
Role::Code => ns_string!("AXCodeStyleGroup"),
Role::Complementary => ns_string!("AXLandmarkComplementary"),
Role::ContentDeletion => ns_string!("AXDeleteStyleGroup"),
Role::ContentInsertion => ns_string!("AXInsertStyleGroup"),
Role::ContentInfo => ns_string!("AXLandmarkContentInfo"),
Role::Definition => ns_string!("AXDefinition"),
Role::Dialog => NSAccessibilityDialogSubrole,
Role::Document => ns_string!("AXDocument"),
Role::Emphasis => ns_string!("AXEmphasisStyleGroup"),
Role::Feed => ns_string!("AXApplicationGroup"),
Role::Footer => ns_string!("AXLandmarkContentInfo"),
Role::Form => ns_string!("AXLandmarkForm"),
Role::GraphicsDocument => ns_string!("AXDocument"),
Role::Group => ns_string!("AXApplicationGroup"),
Role::Header => ns_string!("AXLandmarkBanner"),
Role::LayoutTableCell => NSAccessibilityGroupRole,
Role::LayoutTableRow => NSAccessibilityTableRowSubrole,
Role::Log => ns_string!("AXApplicationLog"),
Role::Main => ns_string!("AXLandmarkMain"),
Role::Marquee => ns_string!("AXApplicationMarquee"),
Role::Math => ns_string!("AXDocumentMath"),
Role::Meter => ns_string!("AXMeter"),
Role::Navigation => ns_string!("AXLandmarkNavigation"),
Role::Note => ns_string!("AXDocumentNote"),
Role::PasswordInput => NSAccessibilitySecureTextFieldSubrole,
Role::Region => ns_string!("AXLandmarkRegion"),
Role::Search => ns_string!("AXLandmarkSearch"),
Role::SearchInput => NSAccessibilitySearchFieldSubrole,
Role::Status => ns_string!("AXApplicationStatus"),
Role::Strong => ns_string!("AXStrongStyleGroup"),
Role::Switch => NSAccessibilitySwitchSubrole,
Role::Tab => NSAccessibilityTabButtonSubrole,
Role::TabPanel => ns_string!("AXTabPanel"),
Role::Term => ns_string!("AXTerm"),
Role::Time => ns_string!("AXTimeGroup"),
Role::Timer => ns_string!("AXApplicationTimer"),
Role::TreeItem => NSAccessibilityOutlineRowSubrole,
Role::Tooltip => ns_string!("AXUserInterfaceTooltip"),
_ => NSAccessibilityUnknownSubrole,
}
}
}

pub(crate) fn can_be_focused(node: &Node) -> bool {
filter(node) == FilterResult::Include && node.role() != Role::Window
}
Expand Down Expand Up @@ -388,6 +441,13 @@ declare_class!(
.copy()
}

#[method_id(accessibilitySubrole)]
fn sub_role(&self) -> Id<NSAccessibilitySubrole> {
self.resolve(ns_sub_role)
.unwrap_or(unsafe { NSAccessibilityUnknownSubrole })
.copy()
}

#[method_id(accessibilityRoleDescription)]
fn role_description(&self) -> Option<Id<NSString>> {
self.resolve(|node| {
Expand Down Expand Up @@ -788,6 +848,7 @@ declare_class!(
|| selector == sel!(accessibilityChildrenInNavigationOrder)
|| selector == sel!(accessibilityFrame)
|| selector == sel!(accessibilityRole)
|| selector == sel!(accessibilitySubrole)
|| selector == sel!(isAccessibilityEnabled)
|| selector == sel!(accessibilityWindow)
|| selector == sel!(accessibilityTopLevelUIElement)
Expand Down

0 comments on commit 40ad828

Please sign in to comment.