Skip to content
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

feat: Support custom role descriptions #316

Merged
merged 5 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions consumer/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,14 @@ impl NodeState {
self.data().role()
}

pub fn role_description(&self) -> Option<String> {
self.data().role_description().map(String::from)
}

pub fn has_role_description(&self) -> bool {
self.data().role_description().is_some()
}

pub fn is_hidden(&self) -> bool {
self.data().is_hidden()
}
Expand Down
14 changes: 13 additions & 1 deletion platforms/macos/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use objc2::{
foundation::{
NSArray, NSCopying, NSInteger, NSNumber, NSObject, NSPoint, NSRange, NSRect, NSString,
},
msg_send_id, ns_string,
msg_send, msg_send_id, ns_string,
rc::{Id, Owned, Shared},
runtime::Sel,
sel, ClassType,
Expand Down Expand Up @@ -400,6 +400,18 @@ declare_class!(
Id::autorelease_return(role.copy())
}

#[sel(accessibilityRoleDescription)]
fn role_description(&self) -> *mut NSString {
self.resolve(|node| {
if let Some(role_description) = node.role_description() {
Id::autorelease_return(NSString::from_str(&role_description))
} else {
unsafe { msg_send![super(self), accessibilityRoleDescription] }
}
})
.unwrap_or_else(null_mut)
}

#[sel(accessibilityTitle)]
fn title(&self) -> *mut NSString {
let result = self
Expand Down
4 changes: 4 additions & 0 deletions platforms/unix/src/atspi/interfaces/accessible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ impl AccessibleInterface<PlatformNode> {
self.node.role()
}

fn get_localized_role_name(&self) -> fdo::Result<String> {
self.node.localized_role_name()
}

fn get_state(&self) -> fdo::Result<StateSet> {
self.node.state()
}
Expand Down
8 changes: 8 additions & 0 deletions platforms/unix/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ impl<'a> NodeWrapper<'a> {
}

pub fn role(&self) -> AtspiRole {
if self.node_state().has_role_description() {
return AtspiRole::Extended;
}

match self.node_state().role() {
Role::Alert => AtspiRole::Notification,
Role::AlertDialog => AtspiRole::Alert,
Expand Down Expand Up @@ -813,6 +817,10 @@ impl PlatformNode {
})
}

pub(crate) fn localized_role_name(&self) -> fdo::Result<String> {
self.resolve(|node| Ok(node.state().role_description().unwrap_or_default()))
}

pub fn state(&self) -> fdo::Result<StateSet> {
self.resolve_with_context(|node, context| {
let wrapper = self.node_wrapper(&node);
Expand Down
5 changes: 5 additions & 0 deletions platforms/windows/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ impl<'a> NodeWrapper<'a> {
}
}

fn localized_control_type(&self) -> Option<String> {
self.node_state().role_description()
}

fn name(&self) -> Option<String> {
match self {
Self::Node(node) => node.name(),
Expand Down Expand Up @@ -841,6 +845,7 @@ macro_rules! patterns {

properties! {
(ControlType, control_type),
(LocalizedControlType, localized_control_type),
(Name, name),
(IsContentElement, is_content_element),
(IsControlElement, is_content_element),
Expand Down