accesskit_unix/atspi/interfaces/
text.rs1use accesskit_atspi_common::{PlatformNode, Rect};
7use atspi::{CoordType, Granularity, ScrollType};
8use std::collections::HashMap;
9use zbus::{fdo, interface};
10
11pub(crate) struct TextInterface {
12 node: PlatformNode,
13}
14
15impl TextInterface {
16 pub fn new(node: PlatformNode) -> Self {
17 Self { node }
18 }
19
20 fn map_error(&self) -> impl '_ + FnOnce(accesskit_atspi_common::Error) -> fdo::Error {
21 |error| crate::util::map_error_from_node(&self.node, error)
22 }
23}
24
25#[interface(name = "org.a11y.atspi.Text")]
26impl TextInterface {
27 #[zbus(property)]
28 fn character_count(&self) -> fdo::Result<i32> {
29 self.node.character_count().map_err(self.map_error())
30 }
31
32 #[zbus(property)]
33 fn caret_offset(&self) -> fdo::Result<i32> {
34 self.node.caret_offset().map_err(self.map_error())
35 }
36
37 fn get_string_at_offset(
38 &self,
39 offset: i32,
40 granularity: Granularity,
41 ) -> fdo::Result<(String, i32, i32)> {
42 self.node
43 .string_at_offset(offset, granularity)
44 .map_err(self.map_error())
45 }
46
47 fn get_text(&self, start_offset: i32, end_offset: i32) -> fdo::Result<String> {
48 self.node
49 .text(start_offset, end_offset)
50 .map_err(self.map_error())
51 }
52
53 fn set_caret_offset(&self, offset: i32) -> fdo::Result<bool> {
54 self.node.set_caret_offset(offset).map_err(self.map_error())
55 }
56
57 fn get_attribute_value(&self, offset: i32, attribute_name: &str) -> fdo::Result<String> {
58 self.node
59 .text_attribute_value(offset, attribute_name)
60 .map_err(self.map_error())
61 }
62
63 fn get_attributes(
64 &self,
65 offset: i32,
66 ) -> fdo::Result<(HashMap<&'static str, String>, i32, i32)> {
67 self.node.text_attributes(offset).map_err(self.map_error())
68 }
69
70 fn get_default_attributes(&self) -> fdo::Result<HashMap<&'static str, String>> {
71 self.node
72 .default_text_attributes()
73 .map_err(self.map_error())
74 }
75
76 fn get_character_extents(&self, offset: i32, coord_type: CoordType) -> fdo::Result<Rect> {
77 self.node
78 .character_extents(offset, coord_type)
79 .map_err(self.map_error())
80 }
81
82 fn get_offset_at_point(&self, x: i32, y: i32, coord_type: CoordType) -> fdo::Result<i32> {
83 self.node
84 .offset_at_point(x, y, coord_type)
85 .map_err(self.map_error())
86 }
87
88 fn get_n_selections(&self) -> fdo::Result<i32> {
89 self.node.n_selections().map_err(self.map_error())
90 }
91
92 fn get_selection(&self, selection_num: i32) -> fdo::Result<(i32, i32)> {
93 self.node.selection(selection_num).map_err(self.map_error())
94 }
95
96 fn add_selection(&self, start_offset: i32, end_offset: i32) -> fdo::Result<bool> {
97 self.node
98 .add_selection(start_offset, end_offset)
99 .map_err(self.map_error())
100 }
101
102 fn remove_selection(&self, selection_num: i32) -> fdo::Result<bool> {
103 self.node
104 .remove_selection(selection_num)
105 .map_err(self.map_error())
106 }
107
108 fn set_selection(
109 &self,
110 selection_num: i32,
111 start_offset: i32,
112 end_offset: i32,
113 ) -> fdo::Result<bool> {
114 self.node
115 .set_selection(selection_num, start_offset, end_offset)
116 .map_err(self.map_error())
117 }
118
119 fn get_range_extents(
120 &self,
121 start_offset: i32,
122 end_offset: i32,
123 coord_type: CoordType,
124 ) -> fdo::Result<Rect> {
125 self.node
126 .range_extents(start_offset, end_offset, coord_type)
127 .map_err(self.map_error())
128 }
129
130 fn get_attribute_run(
131 &self,
132 offset: i32,
133 include_defaults: bool,
134 ) -> fdo::Result<(HashMap<&'static str, String>, i32, i32)> {
135 self.node
136 .text_attribute_run(offset, include_defaults)
137 .map_err(self.map_error())
138 }
139
140 fn scroll_substring_to(
141 &self,
142 start_offset: i32,
143 end_offset: i32,
144 scroll_type: ScrollType,
145 ) -> fdo::Result<bool> {
146 self.node
147 .scroll_substring_to(start_offset, end_offset, scroll_type)
148 .map_err(self.map_error())
149 }
150
151 fn scroll_substring_to_point(
152 &self,
153 start_offset: i32,
154 end_offset: i32,
155 coord_type: CoordType,
156 x: i32,
157 y: i32,
158 ) -> fdo::Result<bool> {
159 self.node
160 .scroll_substring_to_point(start_offset, end_offset, coord_type, x, y)
161 .map_err(self.map_error())
162 }
163}