Skip to content

Commit b1fb5b3

Browse files
committed
feat: Expose tabs in consumer and atspi-common
1 parent 4b74090 commit b1fb5b3

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

consumer/src/node.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ impl<'a> Node<'a> {
407407
self.data().orientation().or_else(|| {
408408
if self.role() == Role::ListBox {
409409
Some(Orientation::Vertical)
410+
} else if self.role() == Role::TabList {
411+
Some(Orientation::Horizontal)
410412
} else {
411413
None
412414
}
@@ -691,6 +693,16 @@ impl<'a> Node<'a> {
691693
)
692694
}
693695

696+
pub fn controls(
697+
&self,
698+
) -> impl DoubleEndedIterator<Item = Node<'a>> + FusedIterator<Item = Node<'a>> + 'a {
699+
let state = self.tree_state;
700+
let data = &self.state.data;
701+
data.controls()
702+
.iter()
703+
.map(move |id| state.node_by_id(*id).unwrap())
704+
}
705+
694706
pub fn raw_text_selection(&self) -> Option<&TextSelection> {
695707
self.data().text_selection()
696708
}

platforms/atspi-common/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub mod simplified;
1717
mod util;
1818

1919
pub use atspi_common::{
20-
CoordType, Granularity, InterfaceSet, Layer, Role, ScrollType, State, StateSet,
20+
CoordType, Granularity, InterfaceSet, Layer, RelationType, Role, ScrollType, State, StateSet,
2121
};
2222

2323
pub use action::*;

platforms/atspi-common/src/node.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use accesskit::{
1414
};
1515
use accesskit_consumer::{FilterResult, Node, TreeState};
1616
use atspi_common::{
17-
CoordType, Granularity, Interface, InterfaceSet, Layer, Politeness, Role as AtspiRole,
18-
ScrollType, State, StateSet,
17+
CoordType, Granularity, Interface, InterfaceSet, Layer, Politeness, RelationType,
18+
Role as AtspiRole, ScrollType, State, StateSet,
1919
};
2020
use std::{
2121
collections::HashMap,
@@ -829,6 +829,25 @@ impl PlatformNode {
829829
})
830830
}
831831

832+
pub fn relation_set<T>(
833+
&self,
834+
f: impl Fn(NodeId) -> T,
835+
) -> Result<HashMap<RelationType, Vec<T>>> {
836+
self.resolve(|node| {
837+
let mut relations = HashMap::new();
838+
let controls: Vec<_> = node
839+
.controls()
840+
.filter(|controlled| filter(controlled) == FilterResult::Include)
841+
.map(|controlled| controlled.id())
842+
.map(f)
843+
.collect();
844+
if !controls.is_empty() {
845+
relations.insert(RelationType::ControllerFor, controls);
846+
}
847+
Ok(relations)
848+
})
849+
}
850+
832851
pub fn role(&self) -> Result<AtspiRole> {
833852
self.resolve(|node| {
834853
let wrapper = NodeWrapper(&node);

platforms/atspi-common/src/simplified.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ use crate::{
1414
WindowEvent,
1515
};
1616

17-
pub use crate::{CoordType, Error, Granularity, Layer, Rect, Result, Role, ScrollType, StateSet};
17+
pub use crate::{
18+
CoordType, Error, Granularity, Layer, Rect, RelationType, Result, Role, ScrollType, StateSet,
19+
};
1820

1921
#[derive(Clone, Hash, PartialEq)]
2022
pub enum Accessible {
@@ -117,6 +119,13 @@ impl Accessible {
117119
}
118120
}
119121

122+
pub fn relation_set(&self) -> Result<HashMap<RelationType, Vec<Self>>> {
123+
match self {
124+
Self::Node(node) => node.relation_set(|id| Self::Node(node.relative(id))),
125+
Self::Root(_) => Ok(HashMap::new()),
126+
}
127+
}
128+
120129
pub fn application(&self) -> Result<Self> {
121130
match self {
122131
Self::Node(node) => node.root().map(Self::Root),

platforms/macos/src/node.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ impl NodeWrapper<'_> {
324324
if let Some(toggled) = self.0.toggled() {
325325
return Some(Value::Bool(toggled != Toggled::False));
326326
}
327+
if self.0.role() == Role::Tab {
328+
return Some(Value::Bool(self.0.is_selected().unwrap_or(false)));
329+
}
327330
if let Some(value) = self.0.value() {
328331
return Some(Value::String(value));
329332
}

0 commit comments

Comments
 (0)