Skip to content

Commit

Permalink
feat: Basic Unix platform adapter (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
DataTriny committed Jan 5, 2023
1 parent c0e8c37 commit 1cea32e
Show file tree
Hide file tree
Showing 28 changed files with 3,204 additions and 31 deletions.
770 changes: 750 additions & 20 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -3,6 +3,7 @@ members = [
"common",
"consumer",
"platforms/macos",
"platforms/unix",
"platforms/windows",
"platforms/winit",
]
Expand Down
35 changes: 26 additions & 9 deletions consumer/src/node.rs
Expand Up @@ -103,25 +103,30 @@ impl<'a> Node<'a> {
(self.tree_state.node_by_id(*parent).unwrap(), *index)
})
}
}

impl NodeState {
pub fn child_ids(
&self,
) -> impl DoubleEndedIterator<Item = NodeId>
+ ExactSizeIterator<Item = NodeId>
+ FusedIterator<Item = NodeId>
+ 'a {
let data = &self.state.data;
+ '_ {
let data = &self.data;
data.children.iter().copied()
}
}

impl<'a> Node<'a> {
pub fn children(
&self,
) -> impl DoubleEndedIterator<Item = Node<'a>>
+ ExactSizeIterator<Item = Node<'a>>
+ FusedIterator<Item = Node<'a>>
+ 'a {
let state = self.tree_state;
self.child_ids()
self.state
.child_ids()
.map(move |id| state.node_by_id(id).unwrap())
}

Expand Down Expand Up @@ -267,23 +272,31 @@ impl<'a> Node<'a> {
};
parent_transform * self.direct_transform()
}
}

impl NodeState {
pub fn raw_bounds(&self) -> Option<Rect> {
self.data().bounds
}
}

impl<'a> Node<'a> {
pub fn has_bounds(&self) -> bool {
self.data().bounds.is_some()
self.state.raw_bounds().is_some()
}

/// Returns the node's transformed bounding box relative to the tree's
/// container (e.g. window).
pub fn bounding_box(&self) -> Option<Rect> {
self.data()
.bounds
self.state
.raw_bounds()
.as_ref()
.map(|rect| self.transform().transform_rect_bbox(*rect))
}

pub(crate) fn bounding_box_in_coordinate_space(&self, other: &Node) -> Option<Rect> {
self.data()
.bounds
self.state
.raw_bounds()
.as_ref()
.map(|rect| self.relative_transform(other).transform_rect_bbox(*rect))
}
Expand All @@ -307,7 +320,7 @@ impl<'a> Node<'a> {
}

if filter_result == FilterResult::Include {
if let Some(rect) = &self.data().bounds {
if let Some(rect) = &self.state.raw_bounds() {
if rect.contains(point) {
return Some((*self, point));
}
Expand Down Expand Up @@ -413,6 +426,10 @@ impl NodeState {
self.data().multiline
}

pub fn is_protected(&self) -> bool {
self.data().protected
}

pub fn default_action_verb(&self) -> Option<DefaultActionVerb> {
self.data().default_action_verb
}
Expand Down
9 changes: 9 additions & 0 deletions consumer/src/tree.rs
Expand Up @@ -3,6 +3,7 @@
// the LICENSE-APACHE file) or the MIT license (found in
// the LICENSE-MIT file), at your option.

use accesskit::kurbo::Point;
use accesskit::{
Action, ActionData, ActionHandler, ActionRequest, Live, Node as NodeData, NodeId,
TextSelection, Tree as TreeData, TreeUpdate,
Expand Down Expand Up @@ -386,6 +387,14 @@ impl Tree {
})
}

pub fn scroll_to_point(&self, target: NodeId, point: Point) {
self.action_handler.do_action(ActionRequest {
action: Action::ScrollToPoint,
target,
data: Some(ActionData::ScrollToPoint(point)),
})
}

pub fn select_text_range(&self, range: &TextRange) {
let selection = TextSelection {
anchor: range.start.downgrade(),
Expand Down
21 changes: 21 additions & 0 deletions platforms/unix/Cargo.toml
@@ -0,0 +1,21 @@
[package]
name = "accesskit_unix"
version = "0.1.0"
authors = ["Arnold Loubriat <datatriny@gmail.com>"]
license = "MIT/Apache-2.0"
description = "AccessKit UI accessibility infrastructure: Linux adapter"
categories = ["gui"]
keywords = ["gui", "ui", "accessibility"]
repository = "https://github.com/AccessKit/accesskit"
readme = "README.md"
edition = "2021"

[dependencies]
accesskit = { version = "0.8.1", path = "../../common" }
accesskit_consumer = { version = "0.11.0", path = "../../consumer" }
async-channel = "1.8.0"
atspi = "0.8.7"
futures-lite = "1.12.0"
parking_lot = "0.12.1"
serde = "1.0"
zbus = "3.6"
3 changes: 3 additions & 0 deletions platforms/unix/README.md
@@ -0,0 +1,3 @@
# AccessKit Unix adapter

This is the Unix adapter for [AccessKit](https://accesskit.dev/). It exposes an AccessKit accessibility tree through the AT-SPI protocol.

0 comments on commit 1cea32e

Please sign in to comment.