Skip to content

Commit 142b1eb

Browse files
committed
System Testing: Expose the accessibility role of elements
1 parent d0cdebf commit 142b1eb

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

internal/backends/testing/slint_systest.proto

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,27 @@ message ElementTypeNameAndId {
104104
string id = 2;
105105
}
106106

107+
// Copied from enums.rs - can't be auto-generated :(
108+
// with one difference: None became Unknown, because None doesn't compile.
109+
// Upside: AccessKit also uses Unknown :)
110+
enum AccessibleRole {
111+
Unknown = 0;
112+
Button = 1;
113+
Checkbox = 2;
114+
Combobox = 3;
115+
List = 4;
116+
Slider = 5;
117+
Spinbox = 6;
118+
Tab = 7;
119+
TabList = 8;
120+
Text = 9;
121+
Table = 10;
122+
Tree = 11;
123+
ProgressIndicator = 12;
124+
TextInput = 13;
125+
Switch = 14;
126+
}
127+
107128
message ElementPropertiesResponse {
108129
repeated ElementTypeNameAndId type_names_and_ids = 1;
109130
string accessible_label = 2;
@@ -116,6 +137,7 @@ message ElementPropertiesResponse {
116137
bool accessible_checkable = 9;
117138
LogicalSize size = 10;
118139
LogicalPosition absolute_position = 11;
140+
AccessibleRole accessible_role = 12;
119141
}
120142

121143
message InvokeElementAccessibilityActionResponse {

internal/backends/testing/systest.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ impl TestingClient {
213213
accessible_checkable: element.accessible_checkable().unwrap_or_default(),
214214
size: send_logical_size(element.size()).into(),
215215
absolute_position: send_logical_position(element.absolute_position()).into(),
216+
accessible_role: convert_accessible_role(element.accessible_role().unwrap()),
216217
})
217218
}
218219

@@ -338,3 +339,26 @@ fn send_logical_size(sz: i_slint_core::api::LogicalSize) -> proto::LogicalSize {
338339
fn send_logical_position(pos: i_slint_core::api::LogicalPosition) -> proto::LogicalPosition {
339340
proto::LogicalPosition { x: pos.x, y: pos.y }
340341
}
342+
343+
fn convert_accessible_role(role: i_slint_core::items::AccessibleRole) -> proto::AccessibleRole {
344+
match role {
345+
i_slint_core::items::AccessibleRole::None => proto::AccessibleRole::Unknown,
346+
i_slint_core::items::AccessibleRole::Button => proto::AccessibleRole::Button,
347+
i_slint_core::items::AccessibleRole::Checkbox => proto::AccessibleRole::Checkbox,
348+
i_slint_core::items::AccessibleRole::Combobox => proto::AccessibleRole::Combobox,
349+
i_slint_core::items::AccessibleRole::List => proto::AccessibleRole::List,
350+
i_slint_core::items::AccessibleRole::Slider => proto::AccessibleRole::Slider,
351+
i_slint_core::items::AccessibleRole::Spinbox => proto::AccessibleRole::Spinbox,
352+
i_slint_core::items::AccessibleRole::Tab => proto::AccessibleRole::Tab,
353+
i_slint_core::items::AccessibleRole::TabList => proto::AccessibleRole::TabList,
354+
i_slint_core::items::AccessibleRole::Text => proto::AccessibleRole::Text,
355+
i_slint_core::items::AccessibleRole::Table => proto::AccessibleRole::Table,
356+
i_slint_core::items::AccessibleRole::Tree => proto::AccessibleRole::Tree,
357+
i_slint_core::items::AccessibleRole::ProgressIndicator => {
358+
proto::AccessibleRole::ProgressIndicator
359+
}
360+
i_slint_core::items::AccessibleRole::TextInput => proto::AccessibleRole::TextInput,
361+
i_slint_core::items::AccessibleRole::Switch => proto::AccessibleRole::Switch,
362+
_ => proto::AccessibleRole::Unknown,
363+
}
364+
}

0 commit comments

Comments
 (0)