Skip to content
Open
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
114 changes: 112 additions & 2 deletions adapters/atspi-common/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ use std::{
};

use crate::{
Action as AtspiAction, Error, ObjectEvent, Property, Rect as AtspiRect, Result,
adapter::Adapter,
context::{AppContext, Context},
filters::filter,
text_attributes::ATTRIBUTE_GETTERS,
util::*,
Action as AtspiAction, Error, ObjectEvent, Property, Rect as AtspiRect, Result,
};

pub(crate) struct NodeWrapper<'a>(pub(crate) &'a NodeRef<'a>);
Expand Down Expand Up @@ -438,6 +438,10 @@ impl NodeWrapper<'_> {
self.0.raw_bounds().is_some() || self.is_root()
}

fn supports_editable_text(&self) -> bool {
self.0.is_text_input() && self.0.supports_text_ranges()
}

fn supports_hyperlink(&self) -> bool {
self.0.supports_url()
}
Expand All @@ -462,6 +466,9 @@ impl NodeWrapper<'_> {
if self.supports_component() {
interfaces.insert(Interface::Component);
}
if self.supports_editable_text() {
interfaces.insert(Interface::EditableText);
}
if self.supports_hyperlink() {
interfaces.insert(Interface::Hyperlink);
}
Expand All @@ -487,7 +494,11 @@ impl NodeWrapper<'_> {
}

fn n_actions(&self) -> i32 {
if self.0.is_clickable(&filter) { 1 } else { 0 }
if self.0.is_clickable(&filter) {
1
} else {
0
}
}

fn get_action_name(&self, index: i32) -> String {
Expand Down Expand Up @@ -966,6 +977,10 @@ impl PlatformNode {
})
}

pub fn supports_editable_text(&self) -> Result<bool> {
self.resolve(|node| Ok(NodeWrapper(&node).supports_editable_text()))
}

pub fn supports_hyperlink(&self) -> Result<bool> {
self.resolve(|node| {
let wrapper = NodeWrapper(&node);
Expand Down Expand Up @@ -1136,6 +1151,19 @@ impl PlatformNode {
Ok(true)
}

pub fn set_text_contents(&self, value: &str) -> Result<bool> {
if self.resolve(|node| Ok(node.is_read_only()))? {
return Ok(false);
}
self.do_action_internal(self.id, |_, _, target_node, target_tree| ActionRequest {
action: Action::SetValue,
target_tree,
target_node,
data: Some(ActionData::Value(value.into())),
})?;
Ok(true)
}

pub fn n_anchors(&self) -> Result<i32> {
self.resolve(|node| if node.url().is_some() { Ok(1) } else { Ok(0) })
}
Expand Down Expand Up @@ -1942,3 +1970,85 @@ pub struct CacheNode {
pub role: AtspiRole,
pub states: StateSet,
}

#[cfg(test)]
mod tests {
use super::*;
use crate::{AdapterCallback, Event};
use accesskit::{ActionHandler, Node, TreeInfo, TreeUpdate};
use std::sync::mpsc::{self, Sender};

struct NoOpCallback;

impl AdapterCallback for NoOpCallback {
fn register_interfaces(&self, _: &Adapter, _: FullNodeId, _: InterfaceSet) {}
fn unregister_interfaces(&self, _: &Adapter, _: FullNodeId, _: InterfaceSet) {}
fn emit_event(&self, _: &Adapter, _: Event) {}
}

struct Recorder(Sender<ActionRequest>);

impl ActionHandler for Recorder {
fn do_action(&mut self, request: ActionRequest) {
self.0.send(request).unwrap();
}
}

#[test]
fn editable_text_support_and_dispatch() {
let mut input = Node::new(Role::TextInput);
input.push_child(NodeId(1));
let mut text_run = Node::new(Role::TextRun);
text_run.set_value("");
text_run.set_character_lengths([]);
let (sender, actions) = mpsc::channel();
let app_context = AppContext::new(None);
let mut adapter = Adapter::new(
&app_context,
NoOpCallback,
TreeUpdate {
nodes: vec![(NodeId(0), input.clone()), (NodeId(1), text_run)],
tree: Some(TreeInfo::new(NodeId(0))),
tree_id: TreeId::ROOT,
focus: NodeId(0),
},
false,
WindowBounds::default(),
Recorder(sender),
);
let node = adapter.platform_node(adapter.root_id());

assert!(node.supports_editable_text().unwrap());
assert!(node.interfaces().unwrap().contains(Interface::EditableText));
assert!(node.set_text_contents("hello").unwrap());

input.set_read_only();
adapter.update(TreeUpdate {
nodes: vec![(NodeId(0), input.clone())],
tree: None,
tree_id: TreeId::ROOT,
focus: NodeId(0),
});
assert!(node.supports_editable_text().unwrap());
assert!(!node.set_text_contents("ignored").unwrap());

input.clear_children();
adapter.update(TreeUpdate {
nodes: vec![(NodeId(0), input)],
tree: None,
tree_id: TreeId::ROOT,
focus: NodeId(0),
});
assert!(!node.supports_editable_text().unwrap());

assert_eq!(
actions.try_iter().collect::<Vec<_>>(),
[ActionRequest {
action: Action::SetValue,
target_tree: TreeId::ROOT,
target_node: NodeId(0),
data: Some(ActionData::Value("hello".into())),
}]
);
}
}
14 changes: 14 additions & 0 deletions adapters/atspi-common/src/simplified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,20 @@ impl Accessible {
}
}

pub fn supports_editable_text(&self) -> Result<bool> {
match self {
Self::Node(node) => node.supports_editable_text(),
Self::Root(_) => Ok(false),
}
}

pub fn set_text_contents(&self, value: &str) -> Result<bool> {
match self {
Self::Node(node) => node.set_text_contents(value),
Self::Root(_) => Err(Error::UnsupportedInterface),
}
}

pub fn supports_hyperlink(&self) -> Result<bool> {
match self {
Self::Node(node) => node.supports_hyperlink(),
Expand Down
8 changes: 8 additions & 0 deletions adapters/unix/src/atspi/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ impl Bus {
)
.await?;
}
if new_interfaces.contains(Interface::EditableText) {
self.register_interface(&path, EditableTextInterface::new(node.clone()))
.await?;
}
if new_interfaces.contains(Interface::Hyperlink) {
self.register_interface(
&path,
Expand Down Expand Up @@ -200,6 +204,10 @@ impl Bus {
self.unregister_interface::<ComponentInterface>(&path)
.await?;
}
if old_interfaces.contains(Interface::EditableText) {
self.unregister_interface::<EditableTextInterface>(&path)
.await?;
}
if old_interfaces.contains(Interface::Hyperlink) {
self.unregister_interface::<HyperlinkInterface>(&path)
.await?;
Expand Down
52 changes: 52 additions & 0 deletions adapters/unix/src/atspi/interfaces/editable_text.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2026 The AccessKit Authors. All rights reserved.
// Licensed under the Apache License, Version 2.0 (found in
// the LICENSE-APACHE file) or the MIT license (found in
// the LICENSE-MIT file), at your option.

use accesskit_atspi_common::PlatformNode;
use zbus::{fdo, interface};

fn unsupported() -> fdo::Error {
fdo::Error::NotSupported("editing operation is not supported".into())
}

pub(crate) struct EditableTextInterface(PlatformNode);

impl EditableTextInterface {
pub fn new(node: PlatformNode) -> Self {
Self(node)
}

fn map_error(&self) -> impl '_ + FnOnce(accesskit_atspi_common::Error) -> fdo::Error {
|error| crate::util::map_error_from_node(&self.0, error)
}
}

#[interface(name = "org.a11y.atspi.EditableText")]
impl EditableTextInterface {
fn copy_text(&self, _start_pos: i32, _end_pos: i32) -> fdo::Result<()> {
Err(unsupported())
}

fn cut_text(&self, _start_pos: i32, _end_pos: i32) -> fdo::Result<bool> {
Err(unsupported())
}

fn delete_text(&self, _start_pos: i32, _end_pos: i32) -> fdo::Result<bool> {
Err(unsupported())
}

fn insert_text(&self, _position: i32, _text: &str, _length: i32) -> fdo::Result<bool> {
Err(unsupported())
}

fn paste_text(&self, _position: i32) -> fdo::Result<bool> {
Err(unsupported())
}

fn set_text_contents(&self, new_contents: &str) -> fdo::Result<bool> {
self.0
.set_text_contents(new_contents)
.map_err(self.map_error())
}
}
2 changes: 2 additions & 0 deletions adapters/unix/src/atspi/interfaces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod action;
mod application;
mod cache;
mod component;
mod editable_text;
mod hyperlink;
mod selection;
mod text;
Expand Down Expand Up @@ -35,6 +36,7 @@ pub(crate) use action::*;
pub(crate) use application::*;
pub(crate) use cache::*;
pub(crate) use component::*;
pub(crate) use editable_text::*;
pub(crate) use hyperlink::*;
pub(crate) use selection::*;
pub(crate) use text::*;
Expand Down