From c0bcde93e7e5bf1f4d0362d1d793e9f3cf0431a8 Mon Sep 17 00:00:00 2001 From: holgerchristensen Date: Thu, 31 Oct 2024 22:58:37 +0100 Subject: [PATCH 1/5] Add sub roles to MacOS adapter --- platforms/macos/src/node.rs | 94 ++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/platforms/macos/src/node.rs b/platforms/macos/src/node.rs index 98cc6fbf..3dfc7ff4 100644 --- a/platforms/macos/src/node.rs +++ b/platforms/macos/src/node.rs @@ -27,7 +27,6 @@ use objc2_foundation::{ NSString, }; use std::rc::{Rc, Weak}; - use crate::{context::Context, filters::filter, util::*}; fn ns_role(node: &Node) -> &'static NSAccessibilityRole { @@ -232,6 +231,91 @@ 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 + } else { + NSAccessibilityUnknownSubrole + } + } + 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::MathMLFraction => ns_string!("AXMathFraction"), + //Role::MathMLIdentifier => ns_string!("AXMathIdentifier"), + //Role::MathMLMath => ns_string!("AXDocumentMath"), + //Role::MathMLMultiscripts => ns_string!("AXMathMultiscript"), + //Role::MathMLNoneScript => ns_string!("AXMathRow"), + //Role::MathMLNumber => ns_string!("AXMathNumber"), + //Role::MathMLOperator => ns_string!("AXMathOperator"), + //Role::MathMLOver => ns_string!("AXMathUnderOver"), + //Role::MathMLPrescriptDelimiter => ns_string!("AXMathRow"), + //Role::MathMLRoot => ns_string!("AXMathRoot"), + //Role::MathMLRow => ns_string!("AXMathRow"), + //Role::MathMLSquareRoot => ns_string!("AXMathSquareRoot"), + //Role::MathMLSub => ns_string!("AXMathSubscriptSuperscript"), + //Role::MathMLSubSup => ns_string!("AXMathSubscriptSuperscript"), + //Role::MathMLSup => ns_string!("AXMathSubscriptSuperscript"), + //Role::MathMLTable => ns_string!("AXMathTable"), + //Role::MathMLTableCell => ns_string!("AXMathTableCell"), + //Role::MathMLTableRow => ns_string!("AXMathTableRow"), + //Role::MathMLText => ns_string!("AXMathText"), + //Role::MathMLUnder => ns_string!("AXMathUnderOver"), + //Role::MathMLUnderOver => ns_string!("AXMathUnderOver"), + Role::Meter => ns_string!("AXMeter"), + Role::Navigation => ns_string!("AXLandmarkNavigation"), + Role::Note => ns_string!("AXDocumentNote"), + Role::Region => ns_string!("AXLandmarkRegion"), + Role::Search => ns_string!("AXLandmarkSearch"), + //Role::SearchBox => NSAccessibilitySearchFieldSubrole, + //Role::SectionFooter => ns_string!("AXSectionFooter"), + //Role::SectionHeader => ns_string!("AXSectionHeader"), + Role::Status => ns_string!("AXApplicationStatus"), + Role::Strong => ns_string!("AXStrongStyleGroup"), + //Role::Subscript => ns_string!("AXSubscriptStyleGroup"), + //Role::Superscript => ns_string!("AXSuperscriptStyleGroup"), + 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 } @@ -411,6 +495,13 @@ declare_class!( .copy() } + #[method_id(accessibilitySubrole)] + fn sub_role(&self) -> Id { + self.resolve(ns_sub_role) + .unwrap_or(unsafe { NSAccessibilityUnknownSubrole }) + .copy() + } + #[method_id(accessibilityRoleDescription)] fn role_description(&self) -> Option> { self.resolve(|node| { @@ -811,6 +902,7 @@ declare_class!( || selector == sel!(accessibilityChildrenInNavigationOrder) || selector == sel!(accessibilityFrame) || selector == sel!(accessibilityRole) + || selector == sel!(accessibilitySubrole) || selector == sel!(isAccessibilityEnabled) || selector == sel!(accessibilityWindow) || selector == sel!(accessibilityTopLevelUIElement) From f01a6d719229fe76e7b22d695c73f56e5c613611 Mon Sep 17 00:00:00 2001 From: holgerchristensen Date: Thu, 31 Oct 2024 23:08:18 +0100 Subject: [PATCH 2/5] Fmt --- platforms/macos/src/node.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/platforms/macos/src/node.rs b/platforms/macos/src/node.rs index 3dfc7ff4..53ffe3e0 100644 --- a/platforms/macos/src/node.rs +++ b/platforms/macos/src/node.rs @@ -27,6 +27,7 @@ use objc2_foundation::{ NSString, }; use std::rc::{Rc, Weak}; + use crate::{context::Context, filters::filter, util::*}; fn ns_role(node: &Node) -> &'static NSAccessibilityRole { From aac0f5d64be43cbd02f6a1e1d4a2ab2464cbb282 Mon Sep 17 00:00:00 2001 From: holgerchristensen Date: Thu, 31 Oct 2024 23:11:25 +0100 Subject: [PATCH 3/5] Fmt --- platforms/macos/src/node.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/platforms/macos/src/node.rs b/platforms/macos/src/node.rs index 53ffe3e0..6aa1eac2 100644 --- a/platforms/macos/src/node.rs +++ b/platforms/macos/src/node.rs @@ -316,7 +316,6 @@ fn ns_sub_role(node: &Node) -> &'static NSAccessibilitySubrole { } } - pub(crate) fn can_be_focused(node: &Node) -> bool { filter(node) == FilterResult::Include && node.role() != Role::Window } From 5a0aa0caa6125b12787c9e355ad434326120fe05 Mon Sep 17 00:00:00 2001 From: holgerchristensen Date: Fri, 1 Nov 2024 17:13:19 +0100 Subject: [PATCH 4/5] Removed math roles. Added password input and search input --- platforms/macos/src/node.rs | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/platforms/macos/src/node.rs b/platforms/macos/src/node.rs index 6aa1eac2..6769f6a9 100644 --- a/platforms/macos/src/node.rs +++ b/platforms/macos/src/node.rs @@ -269,43 +269,18 @@ fn ns_sub_role(node: &Node) -> &'static NSAccessibilitySubrole { Role::Main => ns_string!("AXLandmarkMain"), Role::Marquee => ns_string!("AXApplicationMarquee"), Role::Math => ns_string!("AXDocumentMath"), - //Role::MathMLFraction => ns_string!("AXMathFraction"), - //Role::MathMLIdentifier => ns_string!("AXMathIdentifier"), - //Role::MathMLMath => ns_string!("AXDocumentMath"), - //Role::MathMLMultiscripts => ns_string!("AXMathMultiscript"), - //Role::MathMLNoneScript => ns_string!("AXMathRow"), - //Role::MathMLNumber => ns_string!("AXMathNumber"), - //Role::MathMLOperator => ns_string!("AXMathOperator"), - //Role::MathMLOver => ns_string!("AXMathUnderOver"), - //Role::MathMLPrescriptDelimiter => ns_string!("AXMathRow"), - //Role::MathMLRoot => ns_string!("AXMathRoot"), - //Role::MathMLRow => ns_string!("AXMathRow"), - //Role::MathMLSquareRoot => ns_string!("AXMathSquareRoot"), - //Role::MathMLSub => ns_string!("AXMathSubscriptSuperscript"), - //Role::MathMLSubSup => ns_string!("AXMathSubscriptSuperscript"), - //Role::MathMLSup => ns_string!("AXMathSubscriptSuperscript"), - //Role::MathMLTable => ns_string!("AXMathTable"), - //Role::MathMLTableCell => ns_string!("AXMathTableCell"), - //Role::MathMLTableRow => ns_string!("AXMathTableRow"), - //Role::MathMLText => ns_string!("AXMathText"), - //Role::MathMLUnder => ns_string!("AXMathUnderOver"), - //Role::MathMLUnderOver => ns_string!("AXMathUnderOver"), 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::SearchBox => NSAccessibilitySearchFieldSubrole, - //Role::SectionFooter => ns_string!("AXSectionFooter"), - //Role::SectionHeader => ns_string!("AXSectionHeader"), + Role::SearchInput => NSAccessibilitySearchFieldSubrole, Role::Status => ns_string!("AXApplicationStatus"), Role::Strong => ns_string!("AXStrongStyleGroup"), - //Role::Subscript => ns_string!("AXSubscriptStyleGroup"), - //Role::Superscript => ns_string!("AXSuperscriptStyleGroup"), 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"), From 1575ce30514fabca90126a0ed2b782dc01c35729 Mon Sep 17 00:00:00 2001 From: HolgerGottChristensen Date: Fri, 1 Nov 2024 17:28:48 +0100 Subject: [PATCH 5/5] Update platforms/macos/src/node.rs Co-authored-by: Arnold Loubriat --- platforms/macos/src/node.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/platforms/macos/src/node.rs b/platforms/macos/src/node.rs index 6769f6a9..5b2b43f4 100644 --- a/platforms/macos/src/node.rs +++ b/platforms/macos/src/node.rs @@ -241,13 +241,7 @@ fn ns_sub_role(node: &Node) -> &'static NSAccessibilitySubrole { Role::AlertDialog => ns_string!("AXApplicationAlertDialog"), Role::Article => ns_string!("AXDocumentArticle"), Role::Banner => ns_string!("AXLandmarkBanner"), - Role::Button => { - if node.toggled().is_some() { - NSAccessibilityToggleSubrole - } else { - NSAccessibilityUnknownSubrole - } - } + Role::Button if node.toggled().is_some() => NSAccessibilityToggleSubrole, Role::Code => ns_string!("AXCodeStyleGroup"), Role::Complementary => ns_string!("AXLandmarkComplementary"), Role::ContentDeletion => ns_string!("AXDeleteStyleGroup"),