1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Base accessibility API.

This commit is contained in:
Pāvels Nadtočajevs
2025-03-21 16:42:23 +02:00
parent af2c713971
commit b106dfd4f9
124 changed files with 7631 additions and 181 deletions

View File

@@ -142,6 +142,45 @@ void TabContainer::gui_input(const Ref<InputEvent> &p_event) {
void TabContainer::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ACCESSIBILITY_INVALIDATE: {
tab_panels.clear();
} break;
case NOTIFICATION_ACCESSIBILITY_UPDATE: {
RID ae = get_accessibility_element();
ERR_FAIL_COND(ae.is_null());
int tab_index = 0;
int tab_cur = tab_bar->get_current_tab();
for (int i = 0; i < get_child_count(); i++) {
Node *child_node = get_child(i);
Window *child_wnd = Object::cast_to<Window>(child_node);
if (child_wnd && !child_wnd->is_embedded()) {
continue;
}
if (child_node->is_part_of_edited_scene()) {
continue;
}
Control *control = as_sortable_control(child_node, SortableVisibilityMode::IGNORE);
if (!control || control == tab_bar || children_removing.has(control)) {
DisplayServer::get_singleton()->accessibility_update_add_child(ae, child_node->get_accessibility_element());
} else {
if (!tab_panels.has(child_node)) {
tab_panels[child_node] = DisplayServer::get_singleton()->accessibility_create_sub_element(ae, DisplayServer::AccessibilityRole::ROLE_TAB_PANEL);
}
RID panel = tab_panels[child_node];
RID tab = tab_bar->get_tab_accessibility_element(tab_index);
DisplayServer::get_singleton()->accessibility_update_add_related_controls(tab, panel);
DisplayServer::get_singleton()->accessibility_update_add_related_labeled_by(panel, tab);
DisplayServer::get_singleton()->accessibility_update_set_flag(panel, DisplayServer::AccessibilityFlags::FLAG_HIDDEN, tab_index != tab_cur);
DisplayServer::get_singleton()->accessibility_update_add_child(panel, child_node->get_accessibility_element());
tab_index++;
}
}
} break;
case NOTIFICATION_ENTER_TREE: {
// If some nodes happen to be renamed outside the tree, the tab names need to be updated manually.
if (get_tab_count() > 0) {
@@ -556,6 +595,7 @@ void TabContainer::add_child_notify(Node *p_child) {
if (get_tab_count() == 1) {
queue_redraw();
}
queue_accessibility_update();
p_child->connect("renamed", callable_mp(this, &TabContainer::_refresh_tab_names));
p_child->connect(SceneStringName(visibility_changed), callable_mp(this, &TabContainer::_on_tab_visibility_changed).bind(c));
@@ -579,11 +619,17 @@ void TabContainer::move_child_notify(Node *p_child) {
}
_refresh_tab_indices();
queue_accessibility_update();
}
void TabContainer::remove_child_notify(Node *p_child) {
Container::remove_child_notify(p_child);
if (tab_panels.has(p_child)) {
DisplayServer::get_singleton()->accessibility_free_element(tab_panels[p_child]);
tab_panels.erase(p_child);
}
if (p_child == tab_bar) {
return;
}
@@ -607,6 +653,7 @@ void TabContainer::remove_child_notify(Node *p_child) {
if (get_tab_count() == 0) {
queue_redraw();
}
queue_accessibility_update();
p_child->remove_meta("_tab_index");
p_child->remove_meta("_tab_name");