Path: blob/master/drivers/accesskit/accessibility_driver_accesskit.cpp
21072 views
/**************************************************************************/1/* accessibility_driver_accesskit.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#ifdef ACCESSKIT_ENABLED3132#include "accessibility_driver_accesskit.h"3334#include "core/config/project_settings.h"35#include "core/io/file_access.h"36#include "core/version.h"3738#include "servers/text/text_server.h"3940AccessibilityDriverAccessKit *AccessibilityDriverAccessKit::singleton = nullptr;4142_FORCE_INLINE_ accesskit_role AccessibilityDriverAccessKit::_accessibility_role(DisplayServer::AccessibilityRole p_role) const {43if (role_map.has(p_role)) {44return role_map[p_role];45}46return ACCESSKIT_ROLE_UNKNOWN;47}4849_FORCE_INLINE_ accesskit_action AccessibilityDriverAccessKit::_accessibility_action(DisplayServer::AccessibilityAction p_action) const {50if (action_map.has(p_action)) {51return action_map[p_action];52}53return ACCESSKIT_ACTION_CLICK;54}5556bool AccessibilityDriverAccessKit::window_create(DisplayServer::WindowID p_window_id, void *p_handle) {57ERR_FAIL_COND_V(windows.has(p_window_id), false);5859WindowData &wd = windows[p_window_id];6061AccessibilityElement *ae = memnew(AccessibilityElement);62ae->role = ACCESSKIT_ROLE_WINDOW;63ae->window_id = p_window_id;64wd.root_id = rid_owner.make_rid(ae);6566#ifdef WINDOWS_ENABLED67wd.adapter = accesskit_windows_subclassing_adapter_new(static_cast<HWND>(p_handle), &_accessibility_initial_tree_update_callback, (void *)(size_t)p_window_id, &_accessibility_action_callback, (void *)(size_t)p_window_id);68#endif69#ifdef MACOS_ENABLED70wd.adapter = accesskit_macos_subclassing_adapter_for_window(p_handle, &_accessibility_initial_tree_update_callback, (void *)(size_t)p_window_id, &_accessibility_action_callback, (void *)(size_t)p_window_id);71#endif72#ifdef LINUXBSD_ENABLED73wd.adapter = accesskit_unix_adapter_new(&_accessibility_initial_tree_update_callback, (void *)(size_t)p_window_id, &_accessibility_action_callback, (void *)(size_t)p_window_id, &_accessibility_deactivation_callback, (void *)(size_t)p_window_id);74#endif7576if (wd.adapter == nullptr) {77memdelete(ae);78rid_owner.free(wd.root_id);79windows.erase(p_window_id);8081return false;82} else {83return true;84}85}8687void AccessibilityDriverAccessKit::window_destroy(DisplayServer::WindowID p_window_id) {88WindowData *wd = windows.getptr(p_window_id);89ERR_FAIL_NULL(wd);9091#ifdef WINDOWS_ENABLED92accesskit_windows_subclassing_adapter_free(wd->adapter);93#endif94#ifdef MACOS_ENABLED95accesskit_macos_subclassing_adapter_free(wd->adapter);96#endif97#ifdef LINUXBSD_ENABLED98accesskit_unix_adapter_free(wd->adapter);99#endif100accessibility_free_element(wd->root_id);101102windows.erase(p_window_id);103}104105void AccessibilityDriverAccessKit::_accessibility_deactivation_callback(void *p_user_data) {106// NOP107}108109void AccessibilityDriverAccessKit::_accessibility_action_callback(struct accesskit_action_request *p_request, void *p_user_data) {110DisplayServer::WindowID window_id = (DisplayServer::WindowID)(size_t)p_user_data;111ERR_FAIL_COND(!singleton->windows.has(window_id));112113RID rid = RID::from_uint64(p_request->target);114AccessibilityElement *ae = singleton->rid_owner.get_or_null(rid);115ERR_FAIL_NULL(ae);116117Variant rq_data;118if (!ae->actions.has(p_request->action) && ae->role == ACCESSKIT_ROLE_TEXT_RUN && p_request->action == ACCESSKIT_ACTION_SCROLL_INTO_VIEW) {119AccessibilityElement *root_ae = singleton->rid_owner.get_or_null(ae->parent);120ERR_FAIL_NULL(root_ae);121ae = root_ae;122rq_data = ae->run;123}124125if (ae->actions.has(p_request->action)) {126Callable &cb = ae->actions[p_request->action];127if (cb.is_valid()) {128if (p_request->data.has_value) {129switch (p_request->data.value.tag) {130case ACCESSKIT_ACTION_DATA_CUSTOM_ACTION: {131rq_data = p_request->data.value.custom_action;132} break;133case ACCESSKIT_ACTION_DATA_VALUE: {134rq_data = String::utf8(p_request->data.value.value);135} break;136case ACCESSKIT_ACTION_DATA_NUMERIC_VALUE: {137rq_data = p_request->data.value.numeric_value;138} break;139case ACCESSKIT_ACTION_DATA_SCROLL_HINT: {140switch (p_request->data.value.scroll_hint) {141case ACCESSKIT_SCROLL_HINT_TOP_LEFT: {142rq_data = DisplayServer::SCROLL_HINT_TOP_LEFT;143} break;144case ACCESSKIT_SCROLL_HINT_BOTTOM_RIGHT: {145rq_data = DisplayServer::SCROLL_HINT_BOTTOM_RIGHT;146} break;147case ACCESSKIT_SCROLL_HINT_TOP_EDGE: {148rq_data = DisplayServer::SCROLL_HINT_TOP_EDGE;149} break;150case ACCESSKIT_SCROLL_HINT_BOTTOM_EDGE: {151rq_data = DisplayServer::SCROLL_HINT_BOTTOM_EDGE;152} break;153case ACCESSKIT_SCROLL_HINT_LEFT_EDGE: {154rq_data = DisplayServer::SCROLL_HINT_LEFT_EDGE;155} break;156case ACCESSKIT_SCROLL_HINT_RIGHT_EDGE: {157rq_data = DisplayServer::SCROLL_HINT_RIGHT_EDGE;158} break;159default:160break;161}162} break;163case ACCESSKIT_ACTION_DATA_SCROLL_UNIT: {164if (p_request->data.value.scroll_unit == ACCESSKIT_SCROLL_UNIT_ITEM) {165rq_data = DisplayServer::SCROLL_UNIT_ITEM;166} else if (p_request->data.value.scroll_unit == ACCESSKIT_SCROLL_UNIT_PAGE) {167rq_data = DisplayServer::SCROLL_UNIT_PAGE;168}169} break;170case ACCESSKIT_ACTION_DATA_SCROLL_TO_POINT: {171rq_data = Point2(p_request->data.value.scroll_to_point.x, p_request->data.value.scroll_to_point.y);172} break;173case ACCESSKIT_ACTION_DATA_SET_SCROLL_OFFSET: {174rq_data = Point2(p_request->data.value.set_scroll_offset.x, p_request->data.value.set_scroll_offset.y);175} break;176case ACCESSKIT_ACTION_DATA_SET_TEXT_SELECTION: {177Dictionary sel;178179RID start_rid = RID::from_uint64(p_request->data.value.set_text_selection.anchor.node);180AccessibilityElement *start_ae = singleton->rid_owner.get_or_null(start_rid);181ERR_FAIL_NULL(start_ae);182183RID end_rid = RID::from_uint64(p_request->data.value.set_text_selection.focus.node);184AccessibilityElement *end_ae = singleton->rid_owner.get_or_null(end_rid);185ERR_FAIL_NULL(end_ae);186187sel["start_element"] = start_ae->parent;188sel["start_char"] = (int64_t)p_request->data.value.set_text_selection.anchor.character_index + start_ae->run.x;189sel["end_element"] = end_ae->parent;190sel["end_char"] = (int64_t)p_request->data.value.set_text_selection.focus.character_index + end_ae->run.x;191rq_data = sel;192} break;193}194}195196cb.call_deferred(rq_data);197}198}199}200201accesskit_tree_update *AccessibilityDriverAccessKit::_accessibility_initial_tree_update_callback(void *p_user_data) {202DisplayServer::WindowID window_id = (DisplayServer::WindowID)(size_t)p_user_data;203WindowData *wd = singleton->windows.getptr(window_id);204ERR_FAIL_NULL_V(wd, nullptr);205206accesskit_node *win_node = accesskit_node_new(ACCESSKIT_ROLE_WINDOW);207accesskit_node_set_label(win_node, "Godot Engine");208accesskit_node_set_busy(win_node);209210accesskit_node_id win_id = (accesskit_node_id)wd->root_id.get_id();211212accesskit_tree_update *tree_update = accesskit_tree_update_with_capacity_and_focus(1, win_id);213214accesskit_tree_update_set_tree(tree_update, accesskit_tree_new(win_id));215accesskit_tree_update_push_node(tree_update, win_id, win_node);216217return tree_update;218}219220RID AccessibilityDriverAccessKit::accessibility_create_element(DisplayServer::WindowID p_window_id, DisplayServer::AccessibilityRole p_role) {221AccessibilityElement *ae = memnew(AccessibilityElement);222ae->role = _accessibility_role(p_role);223ae->window_id = p_window_id;224RID rid = rid_owner.make_rid(ae);225226return rid;227}228229RID AccessibilityDriverAccessKit::accessibility_create_sub_element(const RID &p_parent_rid, DisplayServer::AccessibilityRole p_role, int p_insert_pos) {230AccessibilityElement *parent_ae = rid_owner.get_or_null(p_parent_rid);231ERR_FAIL_NULL_V(parent_ae, RID());232233WindowData *wd = windows.getptr(parent_ae->window_id);234ERR_FAIL_NULL_V(wd, RID());235236AccessibilityElement *ae = memnew(AccessibilityElement);237ae->role = _accessibility_role(p_role);238ae->window_id = parent_ae->window_id;239ae->parent = p_parent_rid;240ae->node = accesskit_node_new(ae->role);241RID rid = rid_owner.make_rid(ae);242if (p_insert_pos == -1) {243parent_ae->children.push_back(rid);244} else {245parent_ae->children.insert(p_insert_pos, rid);246}247wd->update.insert(rid);248249return rid;250}251252RID AccessibilityDriverAccessKit::accessibility_create_sub_text_edit_elements(const RID &p_parent_rid, const RID &p_shaped_text, float p_min_height, int p_insert_pos, bool p_is_last_line) {253AccessibilityElement *parent_ae = rid_owner.get_or_null(p_parent_rid);254ERR_FAIL_NULL_V(parent_ae, RID());255256WindowData *wd = windows.getptr(parent_ae->window_id);257ERR_FAIL_NULL_V(wd, RID());258259AccessibilityElement *root_ae = memnew(AccessibilityElement);260root_ae->role = ACCESSKIT_ROLE_GENERIC_CONTAINER;261root_ae->window_id = parent_ae->window_id;262root_ae->parent = p_parent_rid;263root_ae->node = accesskit_node_new(root_ae->role);264RID root_rid = rid_owner.make_rid(root_ae);265if (p_insert_pos == -1) {266parent_ae->children.push_back(root_rid);267} else {268parent_ae->children.insert(p_insert_pos, root_rid);269}270wd->update.insert(root_rid);271272float text_width = 0;273float text_height = p_min_height;274Vector<int32_t> words;275int64_t run_count = 0; // Note: runs in visual order.276const Glyph *gl = nullptr;277int64_t gl_count = 0;278int64_t gl_index = 0;279float run_off_x = 0.0;280Vector2i full_range;281282if (p_shaped_text.is_valid()) {283text_width = TS->shaped_text_get_size(p_shaped_text).x;284text_height = MAX(text_height, TS->shaped_text_get_size(p_shaped_text).y);285words = TS->shaped_text_get_word_breaks(p_shaped_text);286run_count = TS->shaped_get_run_count(p_shaped_text);287gl = TS->shaped_text_get_glyphs(p_shaped_text);288gl_count = TS->shaped_text_get_glyph_count(p_shaped_text);289full_range = TS->shaped_text_get_range(p_shaped_text);290}291292accesskit_rect root_rect;293root_rect.x0 = 0;294root_rect.y0 = 0;295root_rect.x1 = text_width;296root_rect.y1 = MAX(p_min_height, text_height);297accesskit_node_set_bounds(root_ae->node, root_rect);298299// Create text element for each run.300Vector<AccessibilityElement *> text_elements;301for (int64_t i = 0; i < run_count; i++) {302const Vector2i range = TS->shaped_get_run_range(p_shaped_text, i);303String t = TS->shaped_get_run_text(p_shaped_text, i);304305if (t.is_empty()) {306continue;307}308309AccessibilityElement *ae = memnew(AccessibilityElement);310ae->role = ACCESSKIT_ROLE_TEXT_RUN;311ae->window_id = parent_ae->window_id;312ae->parent = root_rid;313ae->run = Vector3i(range.x, range.y, i);314ae->node = accesskit_node_new(ae->role);315316text_elements.push_back(ae);317318// UTF-8 text and char lengths.319Vector<uint8_t> char_lengths;320CharString text = t.utf8(&char_lengths);321322accesskit_node_set_value(ae->node, text.ptr());323accesskit_node_set_character_lengths(ae->node, char_lengths.size(), char_lengths.ptr());324325// Word sizes.326Vector<uint8_t> word_lengths;327328int32_t prev = ae->run.x;329int32_t total = 0;330for (int j = 0; j < words.size(); j += 2) {331if (words[j] < ae->run.x) {332continue;333}334if (words[j] >= ae->run.y) {335break;336}337int32_t wlen = words[j] - prev;338while (wlen > 255) {339word_lengths.push_back(255);340wlen -= 255;341total += 255;342}343if (wlen > 0) {344word_lengths.push_back(wlen);345total += wlen;346}347prev = words[j];348}349if (total < t.length()) {350word_lengths.push_back(t.length() - total);351}352accesskit_node_set_word_lengths(ae->node, word_lengths.size(), word_lengths.ptr());353354// Char widths and positions.355Vector<float> char_positions;356Vector<float> char_widths;357358char_positions.resize_initialized(t.length());359float *positions_ptr = char_positions.ptrw();360361char_widths.resize_initialized(t.length());362float *widths_ptr = char_widths.ptrw();363364float size_x = 0.0;365for (int j = gl_index; j < gl_count; j += gl[j].count) {366if (gl[j].start >= ae->run.y) {367gl_index = j;368break;369}370371float advance = 0.0; // Graphame advance.372for (int k = 0; k < gl[j].count; k++) {373advance += gl[j + k].advance;374}375int chars = gl[j].end - gl[j].start;376float adv_per_char = advance / (float)chars;377378for (int k = 0; k < chars; k++) {379int index = gl[j].start + k - ae->run.x;380ERR_CONTINUE(index < 0 || index >= t.length());381positions_ptr[index] = size_x + adv_per_char * k;382widths_ptr[index] = adv_per_char;383}384size_x += advance * gl[j].repeat;385}386positions_ptr[t.length() - 1] = size_x;387widths_ptr[t.length() - 1] = 1.0;388389accesskit_node_set_character_positions(ae->node, char_positions.size(), char_positions.ptr());390accesskit_node_set_character_widths(ae->node, char_widths.size(), char_widths.ptr());391392RID font_rid = TS->shaped_get_run_font_rid(p_shaped_text, i);393if (font_rid != RID()) {394CharString font_name = TS->font_get_name(font_rid).utf8();395if (font_name.length() > 0) {396accesskit_node_set_font_family(ae->node, font_name.ptr());397}398if (TS->font_get_style(font_rid).has_flag(TextServer::FONT_BOLD)) {399accesskit_node_set_bold(ae->node);400}401if (TS->font_get_style(font_rid).has_flag(TextServer::FONT_ITALIC)) {402accesskit_node_set_italic(ae->node);403}404accesskit_node_set_font_weight(ae->node, TS->font_get_weight(font_rid));405}406accesskit_node_set_font_size(ae->node, TS->shaped_get_run_font_size(p_shaped_text, i));407CharString language = TS->shaped_get_run_language(p_shaped_text, i).utf8();408if (language.length() > 0) {409accesskit_node_set_language(ae->node, language.ptr());410}411accesskit_node_set_text_direction(ae->node, ACCESSKIT_TEXT_DIRECTION_LEFT_TO_RIGHT);412413accesskit_rect rect;414rect.x0 = run_off_x;415rect.y0 = 0;416rect.x1 = run_off_x + size_x;417rect.y1 = text_height;418accesskit_node_set_bounds(ae->node, rect);419accesskit_node_add_action(ae->node, ACCESSKIT_ACTION_SCROLL_INTO_VIEW);420421run_off_x += size_x;422}423if (!p_is_last_line || text_elements.is_empty()) {424// Add "\n" at the end.425AccessibilityElement *ae = memnew(AccessibilityElement);426ae->role = ACCESSKIT_ROLE_TEXT_RUN;427ae->window_id = parent_ae->window_id;428ae->parent = root_rid;429ae->run = Vector3i(full_range.y, full_range.y, run_count);430ae->node = accesskit_node_new(ae->role);431432text_elements.push_back(ae);433434if (!p_is_last_line) {435accesskit_node_set_value(ae->node, "\n");436437Vector<uint8_t> char_lengths;438Vector<float> char_positions;439Vector<float> char_widths;440char_lengths.push_back(1);441char_positions.push_back(0.0);442char_widths.push_back(1.0);443444accesskit_node_set_character_lengths(ae->node, char_lengths.size(), char_lengths.ptr());445accesskit_node_set_character_positions(ae->node, char_positions.size(), char_positions.ptr());446accesskit_node_set_character_widths(ae->node, char_widths.size(), char_widths.ptr());447} else {448accesskit_node_set_value(ae->node, "");449}450accesskit_node_set_text_direction(ae->node, ACCESSKIT_TEXT_DIRECTION_LEFT_TO_RIGHT);451452accesskit_rect rect;453rect.x0 = run_off_x;454rect.y0 = 0;455rect.x1 = run_off_x + 1;456rect.y1 = text_height;457accesskit_node_set_bounds(ae->node, rect);458}459460// Sort runs in logical order.461struct RunCompare {462_FORCE_INLINE_ bool operator()(const AccessibilityElement *l, const AccessibilityElement *r) const {463return l->run.x < r->run.x;464}465};466text_elements.sort_custom<RunCompare>();467for (int i = 0; i < text_elements.size(); i++) {468RID rid = rid_owner.make_rid(text_elements[i]);469root_ae->children.push_back(rid);470wd->update.insert(rid);471472// Link adjacent TextRuns on the same line.473if (i > 0) {474RID prev_rid = root_ae->children[i - 1];475AccessibilityElement *prev_ae = rid_owner.get_or_null(prev_rid);476accesskit_node_set_previous_on_line(text_elements[i]->node, (accesskit_node_id)prev_rid.get_id());477accesskit_node_set_next_on_line(prev_ae->node, (accesskit_node_id)rid.get_id());478}479}480481return root_rid;482}483484bool AccessibilityDriverAccessKit::accessibility_has_element(const RID &p_id) const {485return rid_owner.owns(p_id);486}487488void AccessibilityDriverAccessKit::_free_recursive(WindowData *p_wd, const RID &p_id) {489if (p_wd && p_wd->update.has(p_id)) {490p_wd->update.erase(p_id);491}492AccessibilityElement *ae = rid_owner.get_or_null(p_id);493for (const RID &rid : ae->children) {494_free_recursive(p_wd, rid);495}496if (ae->node) {497accesskit_node_free(ae->node);498}499memdelete(ae);500rid_owner.free(p_id);501}502503void AccessibilityDriverAccessKit::accessibility_free_element(const RID &p_id) {504ERR_FAIL_COND_MSG(in_accessibility_update, "Element can't be removed inside NOTIFICATION_ACCESSIBILITY_UPDATE notification.");505506AccessibilityElement *ae = rid_owner.get_or_null(p_id);507if (ae) {508WindowData *wd = windows.getptr(ae->window_id);509AccessibilityElement *parent_ae = rid_owner.get_or_null(ae->parent);510if (parent_ae) {511parent_ae->children.erase(p_id);512}513_free_recursive(wd, p_id);514}515}516517void AccessibilityDriverAccessKit::accessibility_element_set_meta(const RID &p_id, const Variant &p_meta) {518ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");519520AccessibilityElement *ae = rid_owner.get_or_null(p_id);521ERR_FAIL_NULL(ae);522ae->meta = p_meta;523}524525Variant AccessibilityDriverAccessKit::accessibility_element_get_meta(const RID &p_id) const {526const AccessibilityElement *ae = rid_owner.get_or_null(p_id);527ERR_FAIL_NULL_V(ae, Variant());528return ae->meta;529}530531void AccessibilityDriverAccessKit::accessibility_update_set_focus(const RID &p_id) {532ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");533534if (p_id.is_valid() && rid_owner.owns(p_id)) {535focus = p_id;536} else {537focus = RID();538}539}540541RID AccessibilityDriverAccessKit::accessibility_get_window_root(DisplayServer::WindowID p_window_id) const {542const WindowData *wd = windows.getptr(p_window_id);543ERR_FAIL_NULL_V(wd, RID());544545return wd->root_id;546}547548accesskit_tree_update *AccessibilityDriverAccessKit::_accessibility_build_tree_update(void *p_user_data) {549DisplayServer::WindowID window_id = (DisplayServer::WindowID)(size_t)p_user_data;550551ERR_FAIL_COND_V(!singleton->windows.has(window_id), nullptr);552WindowData &wd = singleton->windows[window_id];553554singleton->in_accessibility_update = true;555if (singleton->update_cb.is_valid()) {556singleton->update_cb.call(window_id);557}558singleton->in_accessibility_update = false;559560AccessibilityElement *focus_ae = singleton->rid_owner.get_or_null(singleton->focus);561uint32_t update_size = wd.update.size();562563accesskit_node_id ac_focus = (accesskit_node_id)wd.root_id.get_id();564if (focus_ae && focus_ae->window_id == window_id) {565ac_focus = (accesskit_node_id)singleton->focus.get_id();566}567568accesskit_tree_update *tree_update = (update_size > 0) ? accesskit_tree_update_with_capacity_and_focus(update_size, ac_focus) : accesskit_tree_update_with_focus(ac_focus);569for (const RID &rid : wd.update) {570AccessibilityElement *ae = singleton->rid_owner.get_or_null(rid);571if (ae && ae->node) {572for (const RID &child_rid : ae->children) {573accesskit_node_push_child(ae->node, (accesskit_node_id)child_rid.get_id());574}575accesskit_tree_update_push_node(tree_update, (accesskit_node_id)rid.get_id(), ae->node);576ae->node = nullptr;577}578}579wd.update.clear();580581return tree_update;582}583584void AccessibilityDriverAccessKit::accessibility_update_if_active(const Callable &p_callable) {585ERR_FAIL_COND(!p_callable.is_valid());586update_cb = p_callable;587for (KeyValue<DisplayServer::WindowID, WindowData> &window : windows) {588#ifdef WINDOWS_ENABLED589accesskit_windows_queued_events *events = accesskit_windows_subclassing_adapter_update_if_active(window.value.adapter, _accessibility_build_tree_update, (void *)(size_t)window.key);590if (events) {591accesskit_windows_queued_events_raise(events);592}593#endif594#ifdef MACOS_ENABLED595accesskit_macos_queued_events *events = accesskit_macos_subclassing_adapter_update_if_active(window.value.adapter, _accessibility_build_tree_update, (void *)(size_t)window.key);596if (events) {597accesskit_macos_queued_events_raise(events);598}599#endif600#ifdef LINUXBSD_ENABLED601accesskit_unix_adapter_update_if_active(window.value.adapter, _accessibility_build_tree_update, (void *)(size_t)window.key);602#endif603}604update_cb = Callable();605}606607_FORCE_INLINE_ void AccessibilityDriverAccessKit::_ensure_node(const RID &p_id, AccessibilityElement *p_ae) {608if (unlikely(!p_ae->node)) {609WindowData *wd = windows.getptr(p_ae->window_id);610ERR_FAIL_NULL(wd);611612wd->update.insert(p_id);613p_ae->node = accesskit_node_new(p_ae->role);614615// Re-apply stored name if any, so nodes recreated by _ensure_node616// retain their label even if the caller doesn't re-set all properties.617if (!p_ae->name.is_empty() || !p_ae->name_extra_info.is_empty()) {618String full_name = p_ae->name + " " + p_ae->name_extra_info;619accesskit_node_set_label(p_ae->node, full_name.utf8().ptr());620}621}622}623624void AccessibilityDriverAccessKit::accessibility_set_window_rect(DisplayServer::WindowID p_window_id, const Rect2 &p_rect_out, const Rect2 &p_rect_in) {625#ifdef LINUXBSD_ENABLED626const WindowData *wd = windows.getptr(p_window_id);627ERR_FAIL_NULL(wd);628629accesskit_rect outer_bounds = { p_rect_out.position.x, p_rect_out.position.y, p_rect_out.position.x + p_rect_out.size.width, p_rect_out.position.y + p_rect_out.size.height };630accesskit_rect inner_bounds = { p_rect_in.position.x, p_rect_in.position.y, p_rect_in.position.x + p_rect_in.size.width, p_rect_in.position.y + p_rect_in.size.height };631accesskit_unix_adapter_set_root_window_bounds(wd->adapter, outer_bounds, inner_bounds);632#endif633}634635void AccessibilityDriverAccessKit::accessibility_set_window_focused(DisplayServer::WindowID p_window_id, bool p_focused) {636const WindowData *wd = windows.getptr(p_window_id);637ERR_FAIL_NULL(wd);638639#ifdef LINUXBSD_ENABLED640accesskit_unix_adapter_update_window_focus_state(wd->adapter, p_focused);641#endif642#ifdef MACOS_ENABLED643accesskit_macos_queued_events *events = accesskit_macos_subclassing_adapter_update_view_focus_state(wd->adapter, p_focused);644if (events != nullptr) {645accesskit_macos_queued_events_raise(events);646}647#endif648// Note: On Windows, the subclassing adapter takes care of this.649}650651void AccessibilityDriverAccessKit::accessibility_update_set_role(const RID &p_id, DisplayServer::AccessibilityRole p_role) {652ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");653654AccessibilityElement *ae = rid_owner.get_or_null(p_id);655ERR_FAIL_NULL(ae);656if (ae->role == _accessibility_role(p_role)) {657return;658}659ae->role = _accessibility_role(p_role);660_ensure_node(p_id, ae);661662accesskit_node_set_role(ae->node, ae->role);663}664665void AccessibilityDriverAccessKit::accessibility_update_set_name(const RID &p_id, const String &p_name) {666ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");667668AccessibilityElement *ae = rid_owner.get_or_null(p_id);669ERR_FAIL_NULL(ae);670_ensure_node(p_id, ae);671672ae->name = p_name;673String full_name = ae->name + " " + ae->name_extra_info;674if (!full_name.is_empty()) {675accesskit_node_set_label(ae->node, full_name.utf8().ptr());676} else {677accesskit_node_clear_label(ae->node);678}679}680681void AccessibilityDriverAccessKit::accessibility_update_set_extra_info(const RID &p_id, const String &p_name_extra_info) {682ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");683684AccessibilityElement *ae = rid_owner.get_or_null(p_id);685ERR_FAIL_NULL(ae);686_ensure_node(p_id, ae);687688ae->name_extra_info = p_name_extra_info;689String full_name = ae->name + " " + ae->name_extra_info;690if (!full_name.is_empty()) {691accesskit_node_set_label(ae->node, full_name.utf8().ptr());692} else {693accesskit_node_clear_label(ae->node);694}695}696697void AccessibilityDriverAccessKit::accessibility_update_set_description(const RID &p_id, const String &p_description) {698ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");699700AccessibilityElement *ae = rid_owner.get_or_null(p_id);701ERR_FAIL_NULL(ae);702_ensure_node(p_id, ae);703704if (!p_description.is_empty()) {705accesskit_node_set_description(ae->node, p_description.utf8().ptr());706} else {707accesskit_node_clear_description(ae->node);708}709}710711void AccessibilityDriverAccessKit::accessibility_update_set_value(const RID &p_id, const String &p_value) {712ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");713714AccessibilityElement *ae = rid_owner.get_or_null(p_id);715ERR_FAIL_NULL(ae);716_ensure_node(p_id, ae);717718if (!p_value.is_empty()) {719Vector<uint8_t> ch_length;720accesskit_node_set_value(ae->node, p_value.utf8(&ch_length).ptr());721accesskit_node_set_character_lengths(ae->node, ch_length.size(), ch_length.ptr());722} else {723accesskit_node_clear_value(ae->node);724accesskit_node_clear_character_lengths(ae->node);725}726}727728void AccessibilityDriverAccessKit::accessibility_update_set_tooltip(const RID &p_id, const String &p_tooltip) {729ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");730731AccessibilityElement *ae = rid_owner.get_or_null(p_id);732ERR_FAIL_NULL(ae);733_ensure_node(p_id, ae);734735if (!p_tooltip.is_empty()) {736accesskit_node_set_tooltip(ae->node, p_tooltip.utf8().ptr());737} else {738accesskit_node_clear_tooltip(ae->node);739}740}741742void AccessibilityDriverAccessKit::accessibility_update_set_bounds(const RID &p_id, const Rect2 &p_rect) {743ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");744745AccessibilityElement *ae = rid_owner.get_or_null(p_id);746ERR_FAIL_NULL(ae);747_ensure_node(p_id, ae);748749accesskit_rect rect;750rect.x0 = p_rect.position.x;751rect.y0 = p_rect.position.y;752rect.x1 = p_rect.position.x + p_rect.size.x;753rect.y1 = p_rect.position.y + p_rect.size.y;754accesskit_node_set_bounds(ae->node, rect);755}756757void AccessibilityDriverAccessKit::accessibility_update_set_transform(const RID &p_id, const Transform2D &p_transform) {758ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");759760AccessibilityElement *ae = rid_owner.get_or_null(p_id);761ERR_FAIL_NULL(ae);762_ensure_node(p_id, ae);763764accesskit_affine transform = { p_transform.columns[0][0], p_transform.columns[0][1], p_transform.columns[1][0], p_transform.columns[1][1], p_transform.columns[2][0], p_transform.columns[2][1] };765accesskit_node_set_transform(ae->node, transform);766}767768void AccessibilityDriverAccessKit::accessibility_update_add_child(const RID &p_id, const RID &p_child_id) {769ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");770771AccessibilityElement *ae = rid_owner.get_or_null(p_id);772ERR_FAIL_NULL(ae);773AccessibilityElement *other_ae = rid_owner.get_or_null(p_child_id);774ERR_FAIL_NULL(other_ae);775ERR_FAIL_COND(other_ae->window_id != ae->window_id);776_ensure_node(p_id, ae);777778accesskit_node_push_child(ae->node, (accesskit_node_id)p_child_id.get_id());779}780781void AccessibilityDriverAccessKit::accessibility_update_add_related_controls(const RID &p_id, const RID &p_related_id) {782ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");783784AccessibilityElement *ae = rid_owner.get_or_null(p_id);785ERR_FAIL_NULL(ae);786AccessibilityElement *other_ae = rid_owner.get_or_null(p_related_id);787ERR_FAIL_NULL(other_ae);788ERR_FAIL_COND(other_ae->window_id != ae->window_id);789_ensure_node(p_id, ae);790791accesskit_node_push_controlled(ae->node, (accesskit_node_id)p_related_id.get_id());792}793794void AccessibilityDriverAccessKit::accessibility_update_add_related_details(const RID &p_id, const RID &p_related_id) {795ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");796797AccessibilityElement *ae = rid_owner.get_or_null(p_id);798ERR_FAIL_NULL(ae);799AccessibilityElement *other_ae = rid_owner.get_or_null(p_related_id);800ERR_FAIL_NULL(other_ae);801ERR_FAIL_COND(other_ae->window_id != ae->window_id);802_ensure_node(p_id, ae);803804accesskit_node_push_detail(ae->node, (accesskit_node_id)p_related_id.get_id());805}806807void AccessibilityDriverAccessKit::accessibility_update_add_related_described_by(const RID &p_id, const RID &p_related_id) {808ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");809810AccessibilityElement *ae = rid_owner.get_or_null(p_id);811ERR_FAIL_NULL(ae);812AccessibilityElement *other_ae = rid_owner.get_or_null(p_related_id);813ERR_FAIL_NULL(other_ae);814ERR_FAIL_COND(other_ae->window_id != ae->window_id);815_ensure_node(p_id, ae);816817accesskit_node_push_described_by(ae->node, (accesskit_node_id)p_related_id.get_id());818}819820void AccessibilityDriverAccessKit::accessibility_update_add_related_flow_to(const RID &p_id, const RID &p_related_id) {821ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");822823AccessibilityElement *ae = rid_owner.get_or_null(p_id);824ERR_FAIL_NULL(ae);825AccessibilityElement *other_ae = rid_owner.get_or_null(p_related_id);826ERR_FAIL_NULL(other_ae);827ERR_FAIL_COND(other_ae->window_id != ae->window_id);828_ensure_node(p_id, ae);829830accesskit_node_push_flow_to(ae->node, (accesskit_node_id)p_related_id.get_id());831}832833void AccessibilityDriverAccessKit::accessibility_update_add_related_labeled_by(const RID &p_id, const RID &p_related_id) {834ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");835836AccessibilityElement *ae = rid_owner.get_or_null(p_id);837ERR_FAIL_NULL(ae);838AccessibilityElement *other_ae = rid_owner.get_or_null(p_related_id);839ERR_FAIL_NULL(other_ae);840ERR_FAIL_COND(other_ae->window_id != ae->window_id);841_ensure_node(p_id, ae);842843accesskit_node_push_labelled_by(ae->node, (accesskit_node_id)p_related_id.get_id());844}845846void AccessibilityDriverAccessKit::accessibility_update_add_related_radio_group(const RID &p_id, const RID &p_related_id) {847ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");848849AccessibilityElement *ae = rid_owner.get_or_null(p_id);850ERR_FAIL_NULL(ae);851AccessibilityElement *other_ae = rid_owner.get_or_null(p_related_id);852ERR_FAIL_NULL(other_ae);853ERR_FAIL_COND(other_ae->window_id != ae->window_id);854_ensure_node(p_id, ae);855856accesskit_node_push_to_radio_group(ae->node, (accesskit_node_id)p_related_id.get_id());857}858859void AccessibilityDriverAccessKit::accessibility_update_set_active_descendant(const RID &p_id, const RID &p_other_id) {860ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");861862AccessibilityElement *ae = rid_owner.get_or_null(p_id);863ERR_FAIL_NULL(ae);864AccessibilityElement *other_ae = rid_owner.get_or_null(p_other_id);865ERR_FAIL_NULL(other_ae);866ERR_FAIL_COND(other_ae->window_id != ae->window_id);867_ensure_node(p_id, ae);868869accesskit_node_set_active_descendant(ae->node, (accesskit_node_id)p_other_id.get_id());870}871872void AccessibilityDriverAccessKit::accessibility_update_set_next_on_line(const RID &p_id, const RID &p_other_id) {873ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");874875AccessibilityElement *ae = rid_owner.get_or_null(p_id);876ERR_FAIL_NULL(ae);877AccessibilityElement *other_ae = rid_owner.get_or_null(p_other_id);878ERR_FAIL_NULL(other_ae);879ERR_FAIL_COND(other_ae->window_id != ae->window_id);880_ensure_node(p_id, ae);881882accesskit_node_set_next_on_line(ae->node, (accesskit_node_id)p_other_id.get_id());883}884885void AccessibilityDriverAccessKit::accessibility_update_set_previous_on_line(const RID &p_id, const RID &p_other_id) {886ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");887888AccessibilityElement *ae = rid_owner.get_or_null(p_id);889ERR_FAIL_NULL(ae);890AccessibilityElement *other_ae = rid_owner.get_or_null(p_other_id);891ERR_FAIL_NULL(other_ae);892ERR_FAIL_COND(other_ae->window_id != ae->window_id);893_ensure_node(p_id, ae);894895accesskit_node_set_previous_on_line(ae->node, (accesskit_node_id)p_other_id.get_id());896}897898void AccessibilityDriverAccessKit::accessibility_update_set_member_of(const RID &p_id, const RID &p_group_id) {899ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");900901AccessibilityElement *ae = rid_owner.get_or_null(p_id);902ERR_FAIL_NULL(ae);903AccessibilityElement *other_ae = rid_owner.get_or_null(p_group_id);904ERR_FAIL_NULL(other_ae);905ERR_FAIL_COND(other_ae->window_id != ae->window_id);906_ensure_node(p_id, ae);907908accesskit_node_set_member_of(ae->node, (accesskit_node_id)p_group_id.get_id());909}910911void AccessibilityDriverAccessKit::accessibility_update_set_in_page_link_target(const RID &p_id, const RID &p_other_id) {912ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");913914AccessibilityElement *ae = rid_owner.get_or_null(p_id);915ERR_FAIL_NULL(ae);916AccessibilityElement *other_ae = rid_owner.get_or_null(p_other_id);917ERR_FAIL_NULL(other_ae);918ERR_FAIL_COND(other_ae->window_id != ae->window_id);919_ensure_node(p_id, ae);920921accesskit_node_set_in_page_link_target(ae->node, (accesskit_node_id)p_other_id.get_id());922}923924void AccessibilityDriverAccessKit::accessibility_update_set_error_message(const RID &p_id, const RID &p_other_id) {925ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");926927AccessibilityElement *ae = rid_owner.get_or_null(p_id);928ERR_FAIL_NULL(ae);929AccessibilityElement *other_ae = rid_owner.get_or_null(p_other_id);930ERR_FAIL_NULL(other_ae);931ERR_FAIL_COND(other_ae->window_id != ae->window_id);932_ensure_node(p_id, ae);933934accesskit_node_set_error_message(ae->node, (accesskit_node_id)p_other_id.get_id());935}936937void AccessibilityDriverAccessKit::accessibility_update_set_live(const RID &p_id, DisplayServer::AccessibilityLiveMode p_live) {938ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");939940AccessibilityElement *ae = rid_owner.get_or_null(p_id);941ERR_FAIL_NULL(ae);942_ensure_node(p_id, ae);943944switch (p_live) {945case DisplayServer::AccessibilityLiveMode::LIVE_OFF: {946accesskit_node_set_live(ae->node, ACCESSKIT_LIVE_OFF);947} break;948case DisplayServer::AccessibilityLiveMode::LIVE_POLITE: {949accesskit_node_set_live(ae->node, ACCESSKIT_LIVE_POLITE);950} break;951case DisplayServer::AccessibilityLiveMode::LIVE_ASSERTIVE: {952accesskit_node_set_live(ae->node, ACCESSKIT_LIVE_ASSERTIVE);953} break;954}955}956957void AccessibilityDriverAccessKit::accessibility_update_add_action(const RID &p_id, DisplayServer::AccessibilityAction p_action, const Callable &p_callable) {958ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");959960AccessibilityElement *ae = rid_owner.get_or_null(p_id);961ERR_FAIL_NULL(ae);962_ensure_node(p_id, ae);963964ae->actions[_accessibility_action(p_action)] = p_callable;965966accesskit_node_add_action(ae->node, _accessibility_action(p_action));967}968969void AccessibilityDriverAccessKit::accessibility_update_add_custom_action(const RID &p_id, int p_action_id, const String &p_action_description) {970ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");971972AccessibilityElement *ae = rid_owner.get_or_null(p_id);973ERR_FAIL_NULL(ae);974_ensure_node(p_id, ae);975976if (!p_action_description.is_empty()) {977accesskit_custom_action *ca = accesskit_custom_action_new(p_action_id);978accesskit_custom_action_set_description(ca, p_action_description.utf8().ptr());979accesskit_node_push_custom_action(ae->node, ca);980} else {981String cs_name = vformat("Custom Action %d", p_action_id);982accesskit_custom_action *ca = accesskit_custom_action_new(p_action_id);983accesskit_custom_action_set_description(ca, cs_name.utf8().ptr());984accesskit_node_push_custom_action(ae->node, ca);985}986}987988void AccessibilityDriverAccessKit::accessibility_update_set_table_row_count(const RID &p_id, int p_count) {989ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");990991AccessibilityElement *ae = rid_owner.get_or_null(p_id);992ERR_FAIL_NULL(ae);993_ensure_node(p_id, ae);994995accesskit_node_set_row_count(ae->node, p_count);996}997998void AccessibilityDriverAccessKit::accessibility_update_set_table_column_count(const RID &p_id, int p_count) {999ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");10001001AccessibilityElement *ae = rid_owner.get_or_null(p_id);1002ERR_FAIL_NULL(ae);1003_ensure_node(p_id, ae);10041005accesskit_node_set_column_count(ae->node, p_count);1006}10071008void AccessibilityDriverAccessKit::accessibility_update_set_table_row_index(const RID &p_id, int p_index) {1009ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");10101011AccessibilityElement *ae = rid_owner.get_or_null(p_id);1012ERR_FAIL_NULL(ae);1013_ensure_node(p_id, ae);10141015accesskit_node_set_row_index(ae->node, p_index);1016}10171018void AccessibilityDriverAccessKit::accessibility_update_set_table_column_index(const RID &p_id, int p_index) {1019ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");10201021AccessibilityElement *ae = rid_owner.get_or_null(p_id);1022ERR_FAIL_NULL(ae);1023_ensure_node(p_id, ae);10241025accesskit_node_set_column_index(ae->node, p_index);1026}10271028void AccessibilityDriverAccessKit::accessibility_update_set_table_cell_position(const RID &p_id, int p_row_index, int p_column_index) {1029ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");10301031AccessibilityElement *ae = rid_owner.get_or_null(p_id);1032ERR_FAIL_NULL(ae);1033_ensure_node(p_id, ae);10341035accesskit_node_set_row_index(ae->node, p_row_index);1036accesskit_node_set_column_index(ae->node, p_column_index);1037}10381039void AccessibilityDriverAccessKit::accessibility_update_set_table_cell_span(const RID &p_id, int p_row_span, int p_column_span) {1040ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");10411042AccessibilityElement *ae = rid_owner.get_or_null(p_id);1043ERR_FAIL_NULL(ae);1044_ensure_node(p_id, ae);10451046accesskit_node_set_row_span(ae->node, p_row_span);1047accesskit_node_set_column_span(ae->node, p_column_span);1048}10491050void AccessibilityDriverAccessKit::accessibility_update_set_list_item_count(const RID &p_id, int p_size) {1051ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");10521053AccessibilityElement *ae = rid_owner.get_or_null(p_id);1054ERR_FAIL_NULL(ae);1055_ensure_node(p_id, ae);10561057accesskit_node_set_size_of_set(ae->node, p_size);1058}10591060void AccessibilityDriverAccessKit::accessibility_update_set_list_item_index(const RID &p_id, int p_index) {1061ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");10621063AccessibilityElement *ae = rid_owner.get_or_null(p_id);1064ERR_FAIL_NULL(ae);1065_ensure_node(p_id, ae);10661067accesskit_node_set_position_in_set(ae->node, p_index);1068}10691070void AccessibilityDriverAccessKit::accessibility_update_set_list_item_level(const RID &p_id, int p_level) {1071ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");10721073AccessibilityElement *ae = rid_owner.get_or_null(p_id);1074ERR_FAIL_NULL(ae);1075_ensure_node(p_id, ae);10761077accesskit_node_set_level(ae->node, p_level);1078}10791080void AccessibilityDriverAccessKit::accessibility_update_set_list_item_selected(const RID &p_id, bool p_selected) {1081ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");10821083AccessibilityElement *ae = rid_owner.get_or_null(p_id);1084ERR_FAIL_NULL(ae);1085_ensure_node(p_id, ae);10861087accesskit_node_set_selected(ae->node, p_selected);1088}10891090void AccessibilityDriverAccessKit::accessibility_update_set_list_item_expanded(const RID &p_id, bool p_expanded) {1091ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");10921093AccessibilityElement *ae = rid_owner.get_or_null(p_id);1094ERR_FAIL_NULL(ae);1095_ensure_node(p_id, ae);10961097accesskit_node_set_expanded(ae->node, p_expanded);1098}10991100void AccessibilityDriverAccessKit::accessibility_update_set_popup_type(const RID &p_id, DisplayServer::AccessibilityPopupType p_popup) {1101ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");11021103AccessibilityElement *ae = rid_owner.get_or_null(p_id);1104ERR_FAIL_NULL(ae);1105_ensure_node(p_id, ae);11061107switch (p_popup) {1108case DisplayServer::AccessibilityPopupType::POPUP_MENU: {1109accesskit_node_set_has_popup(ae->node, ACCESSKIT_HAS_POPUP_MENU);1110} break;1111case DisplayServer::AccessibilityPopupType::POPUP_LIST: {1112accesskit_node_set_has_popup(ae->node, ACCESSKIT_HAS_POPUP_LISTBOX);1113} break;1114case DisplayServer::AccessibilityPopupType::POPUP_TREE: {1115accesskit_node_set_has_popup(ae->node, ACCESSKIT_HAS_POPUP_TREE);1116} break;1117case DisplayServer::AccessibilityPopupType::POPUP_DIALOG: {1118accesskit_node_set_has_popup(ae->node, ACCESSKIT_HAS_POPUP_DIALOG);1119} break;1120}1121}11221123void AccessibilityDriverAccessKit::accessibility_update_set_checked(const RID &p_id, bool p_checekd) {1124ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");11251126AccessibilityElement *ae = rid_owner.get_or_null(p_id);1127ERR_FAIL_NULL(ae);1128_ensure_node(p_id, ae);11291130if (p_checekd) {1131accesskit_node_set_toggled(ae->node, ACCESSKIT_TOGGLED_TRUE);1132} else {1133accesskit_node_set_toggled(ae->node, ACCESSKIT_TOGGLED_FALSE);1134}1135}11361137void AccessibilityDriverAccessKit::accessibility_update_set_num_value(const RID &p_id, double p_position) {1138ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");11391140AccessibilityElement *ae = rid_owner.get_or_null(p_id);1141ERR_FAIL_NULL(ae);1142_ensure_node(p_id, ae);11431144accesskit_node_set_numeric_value(ae->node, p_position);1145}11461147void AccessibilityDriverAccessKit::accessibility_update_set_num_range(const RID &p_id, double p_min, double p_max) {1148ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");11491150AccessibilityElement *ae = rid_owner.get_or_null(p_id);1151ERR_FAIL_NULL(ae);1152_ensure_node(p_id, ae);11531154accesskit_node_set_min_numeric_value(ae->node, p_min);1155accesskit_node_set_max_numeric_value(ae->node, p_max);1156}11571158void AccessibilityDriverAccessKit::accessibility_update_set_num_step(const RID &p_id, double p_step) {1159ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");11601161AccessibilityElement *ae = rid_owner.get_or_null(p_id);1162ERR_FAIL_NULL(ae);1163_ensure_node(p_id, ae);11641165accesskit_node_set_numeric_value_step(ae->node, p_step);1166}11671168void AccessibilityDriverAccessKit::accessibility_update_set_num_jump(const RID &p_id, double p_jump) {1169ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");11701171AccessibilityElement *ae = rid_owner.get_or_null(p_id);1172ERR_FAIL_NULL(ae);1173_ensure_node(p_id, ae);11741175accesskit_node_set_numeric_value_jump(ae->node, p_jump);1176}11771178void AccessibilityDriverAccessKit::accessibility_update_set_scroll_x(const RID &p_id, double p_position) {1179ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");11801181AccessibilityElement *ae = rid_owner.get_or_null(p_id);1182ERR_FAIL_NULL(ae);1183_ensure_node(p_id, ae);11841185accesskit_node_set_scroll_x(ae->node, p_position);1186}11871188void AccessibilityDriverAccessKit::accessibility_update_set_scroll_x_range(const RID &p_id, double p_min, double p_max) {1189ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");11901191AccessibilityElement *ae = rid_owner.get_or_null(p_id);1192ERR_FAIL_NULL(ae);1193_ensure_node(p_id, ae);11941195accesskit_node_set_scroll_x_min(ae->node, p_min);1196accesskit_node_set_scroll_x_max(ae->node, p_max);1197}11981199void AccessibilityDriverAccessKit::accessibility_update_set_scroll_y(const RID &p_id, double p_position) {1200ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");12011202AccessibilityElement *ae = rid_owner.get_or_null(p_id);1203ERR_FAIL_NULL(ae);1204_ensure_node(p_id, ae);12051206accesskit_node_set_scroll_y(ae->node, p_position);1207}12081209void AccessibilityDriverAccessKit::accessibility_update_set_scroll_y_range(const RID &p_id, double p_min, double p_max) {1210ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");12111212AccessibilityElement *ae = rid_owner.get_or_null(p_id);1213ERR_FAIL_NULL(ae);1214_ensure_node(p_id, ae);12151216accesskit_node_set_scroll_y_min(ae->node, p_min);1217accesskit_node_set_scroll_y_max(ae->node, p_max);1218}12191220void AccessibilityDriverAccessKit::accessibility_update_set_text_decorations(const RID &p_id, bool p_underline, bool p_strikethrough, bool p_overline) {1221ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");12221223AccessibilityElement *ae = rid_owner.get_or_null(p_id);1224ERR_FAIL_NULL(ae);1225_ensure_node(p_id, ae);12261227if (p_underline) {1228accesskit_node_set_underline(ae->node, ACCESSKIT_TEXT_DECORATION_SOLID);1229} else {1230accesskit_node_clear_underline(ae->node);1231}1232if (p_overline) {1233accesskit_node_set_overline(ae->node, ACCESSKIT_TEXT_DECORATION_SOLID);1234} else {1235accesskit_node_clear_overline(ae->node);1236}1237if (p_strikethrough) {1238accesskit_node_set_strikethrough(ae->node, ACCESSKIT_TEXT_DECORATION_SOLID);1239} else {1240accesskit_node_clear_strikethrough(ae->node);1241}1242}12431244void AccessibilityDriverAccessKit::accessibility_update_set_text_align(const RID &p_id, HorizontalAlignment p_align) {1245ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");12461247AccessibilityElement *ae = rid_owner.get_or_null(p_id);1248ERR_FAIL_NULL(ae);1249_ensure_node(p_id, ae);12501251switch (p_align) {1252case HORIZONTAL_ALIGNMENT_LEFT: {1253accesskit_node_set_text_align(ae->node, ACCESSKIT_TEXT_ALIGN_LEFT);1254} break;1255case HORIZONTAL_ALIGNMENT_CENTER: {1256accesskit_node_set_text_align(ae->node, ACCESSKIT_TEXT_ALIGN_RIGHT);1257} break;1258case HORIZONTAL_ALIGNMENT_RIGHT: {1259accesskit_node_set_text_align(ae->node, ACCESSKIT_TEXT_ALIGN_CENTER);1260} break;1261case HORIZONTAL_ALIGNMENT_FILL: {1262accesskit_node_set_text_align(ae->node, ACCESSKIT_TEXT_ALIGN_JUSTIFY);1263} break;1264}1265}12661267void AccessibilityDriverAccessKit::accessibility_update_set_text_selection(const RID &p_id, const RID &p_text_start_id, int p_start_char, const RID &p_text_end_id, int p_end_char) {1268ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");12691270AccessibilityElement *ae = rid_owner.get_or_null(p_id);1271ERR_FAIL_NULL(ae);1272AccessibilityElement *start_ae = rid_owner.get_or_null(p_text_start_id);1273ERR_FAIL_NULL(start_ae);1274ERR_FAIL_COND(start_ae->window_id != ae->window_id);1275AccessibilityElement *end_ae = rid_owner.get_or_null(p_text_end_id);1276ERR_FAIL_NULL(end_ae);1277ERR_FAIL_COND(end_ae->window_id != ae->window_id);12781279int start_pos = p_start_char;1280int end_pos = p_end_char;1281RID start_rid;1282RID end_rid;1283for (const RID &rid : start_ae->children) {1284const AccessibilityElement *child_ae = rid_owner.get_or_null(rid);1285if (child_ae && child_ae->role == ACCESSKIT_ROLE_TEXT_RUN) {1286if (p_start_char >= child_ae->run.x && p_start_char <= child_ae->run.y) {1287start_rid = rid;1288start_pos = p_start_char - child_ae->run.x;1289break;1290}1291}1292}1293for (const RID &rid : end_ae->children) {1294const AccessibilityElement *child_ae = rid_owner.get_or_null(rid);1295if (child_ae && child_ae->role == ACCESSKIT_ROLE_TEXT_RUN) {1296if (p_end_char >= child_ae->run.x && p_end_char <= child_ae->run.y) {1297end_rid = rid;1298end_pos = p_end_char - child_ae->run.x;1299break;1300}1301}1302}1303ERR_FAIL_COND(start_rid.is_null() && end_rid.is_null());1304_ensure_node(p_id, ae);13051306accesskit_text_selection sel;1307sel.anchor.node = (accesskit_node_id)start_rid.get_id();1308sel.anchor.character_index = start_pos;1309sel.focus.node = (accesskit_node_id)end_rid.get_id();1310sel.focus.character_index = end_pos;1311accesskit_node_set_text_selection(ae->node, sel);1312}13131314void AccessibilityDriverAccessKit::accessibility_update_set_flag(const RID &p_id, DisplayServer::AccessibilityFlags p_flag, bool p_value) {1315ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");13161317AccessibilityElement *ae = rid_owner.get_or_null(p_id);1318ERR_FAIL_NULL(ae);1319_ensure_node(p_id, ae);13201321switch (p_flag) {1322case DisplayServer::AccessibilityFlags::FLAG_HIDDEN: {1323if (p_value) {1324accesskit_node_set_hidden(ae->node);1325} else {1326accesskit_node_clear_hidden(ae->node);1327}1328} break;1329case DisplayServer::AccessibilityFlags::FLAG_MULTISELECTABLE: {1330if (p_value) {1331accesskit_node_set_multiselectable(ae->node);1332} else {1333accesskit_node_clear_multiselectable(ae->node);1334}1335} break;1336case DisplayServer::AccessibilityFlags::FLAG_REQUIRED: {1337if (p_value) {1338accesskit_node_set_required(ae->node);1339} else {1340accesskit_node_clear_required(ae->node);1341}1342} break;1343case DisplayServer::AccessibilityFlags::FLAG_VISITED: {1344if (p_value) {1345accesskit_node_set_visited(ae->node);1346} else {1347accesskit_node_clear_visited(ae->node);1348}1349} break;1350case DisplayServer::AccessibilityFlags::FLAG_BUSY: {1351if (p_value) {1352accesskit_node_set_busy(ae->node);1353} else {1354accesskit_node_clear_busy(ae->node);1355}1356} break;1357case DisplayServer::AccessibilityFlags::FLAG_MODAL: {1358if (p_value) {1359accesskit_node_set_modal(ae->node);1360} else {1361accesskit_node_clear_modal(ae->node);1362}1363} break;1364case DisplayServer::AccessibilityFlags::FLAG_TOUCH_PASSTHROUGH: {1365if (p_value) {1366accesskit_node_set_touch_transparent(ae->node);1367} else {1368accesskit_node_clear_touch_transparent(ae->node);1369}1370} break;1371case DisplayServer::AccessibilityFlags::FLAG_READONLY: {1372if (p_value) {1373accesskit_node_set_read_only(ae->node);1374} else {1375accesskit_node_clear_read_only(ae->node);1376}1377} break;1378case DisplayServer::AccessibilityFlags::FLAG_DISABLED: {1379if (p_value) {1380accesskit_node_set_disabled(ae->node);1381} else {1382accesskit_node_clear_disabled(ae->node);1383}1384} break;1385case DisplayServer::AccessibilityFlags::FLAG_CLIPS_CHILDREN: {1386if (p_value) {1387accesskit_node_set_clips_children(ae->node);1388} else {1389accesskit_node_clear_clips_children(ae->node);1390}1391} break;1392}1393}13941395void AccessibilityDriverAccessKit::accessibility_update_set_classname(const RID &p_id, const String &p_classname) {1396ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");13971398AccessibilityElement *ae = rid_owner.get_or_null(p_id);1399ERR_FAIL_NULL(ae);1400_ensure_node(p_id, ae);14011402if (!p_classname.is_empty()) {1403accesskit_node_set_class_name(ae->node, p_classname.utf8().ptr());1404} else {1405accesskit_node_clear_class_name(ae->node);1406}1407}14081409void AccessibilityDriverAccessKit::accessibility_update_set_placeholder(const RID &p_id, const String &p_placeholder) {1410ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");14111412AccessibilityElement *ae = rid_owner.get_or_null(p_id);1413ERR_FAIL_NULL(ae);1414_ensure_node(p_id, ae);14151416if (!p_placeholder.is_empty()) {1417accesskit_node_set_placeholder(ae->node, p_placeholder.utf8().ptr());1418} else {1419accesskit_node_clear_placeholder(ae->node);1420}1421}14221423void AccessibilityDriverAccessKit::accessibility_update_set_language(const RID &p_id, const String &p_language) {1424ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");14251426AccessibilityElement *ae = rid_owner.get_or_null(p_id);1427ERR_FAIL_NULL(ae);1428_ensure_node(p_id, ae);14291430accesskit_node_set_language(ae->node, p_language.utf8().ptr());1431}14321433void AccessibilityDriverAccessKit::accessibility_update_set_text_orientation(const RID &p_id, bool p_vertical) {1434ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");14351436AccessibilityElement *ae = rid_owner.get_or_null(p_id);1437ERR_FAIL_NULL(ae);1438_ensure_node(p_id, ae);14391440if (p_vertical) {1441accesskit_node_set_text_direction(ae->node, ACCESSKIT_TEXT_DIRECTION_TOP_TO_BOTTOM);1442} else {1443accesskit_node_set_text_direction(ae->node, ACCESSKIT_TEXT_DIRECTION_LEFT_TO_RIGHT);1444}1445}14461447void AccessibilityDriverAccessKit::accessibility_update_set_list_orientation(const RID &p_id, bool p_vertical) {1448ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");14491450AccessibilityElement *ae = rid_owner.get_or_null(p_id);1451ERR_FAIL_NULL(ae);1452_ensure_node(p_id, ae);14531454if (p_vertical) {1455accesskit_node_set_orientation(ae->node, ACCESSKIT_ORIENTATION_VERTICAL);1456} else {1457accesskit_node_set_orientation(ae->node, ACCESSKIT_ORIENTATION_HORIZONTAL);1458}1459}14601461void AccessibilityDriverAccessKit::accessibility_update_set_shortcut(const RID &p_id, const String &p_shortcut) {1462ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");14631464AccessibilityElement *ae = rid_owner.get_or_null(p_id);1465ERR_FAIL_NULL(ae);1466_ensure_node(p_id, ae);14671468if (!p_shortcut.is_empty()) {1469accesskit_node_set_keyboard_shortcut(ae->node, p_shortcut.utf8().ptr());1470} else {1471accesskit_node_clear_keyboard_shortcut(ae->node);1472}1473}14741475void AccessibilityDriverAccessKit::accessibility_update_set_url(const RID &p_id, const String &p_url) {1476ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");14771478AccessibilityElement *ae = rid_owner.get_or_null(p_id);1479ERR_FAIL_NULL(ae);1480_ensure_node(p_id, ae);14811482if (!p_url.is_empty()) {1483accesskit_node_set_url(ae->node, p_url.utf8().ptr());1484} else {1485accesskit_node_clear_url(ae->node);1486}1487}14881489void AccessibilityDriverAccessKit::accessibility_update_set_role_description(const RID &p_id, const String &p_description) {1490ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");14911492AccessibilityElement *ae = rid_owner.get_or_null(p_id);1493ERR_FAIL_NULL(ae);1494_ensure_node(p_id, ae);14951496if (!p_description.is_empty()) {1497accesskit_node_set_role_description(ae->node, p_description.utf8().ptr());1498} else {1499accesskit_node_clear_role_description(ae->node);1500}1501}15021503void AccessibilityDriverAccessKit::accessibility_update_set_state_description(const RID &p_id, const String &p_description) {1504ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");15051506AccessibilityElement *ae = rid_owner.get_or_null(p_id);1507ERR_FAIL_NULL(ae);1508_ensure_node(p_id, ae);15091510if (!p_description.is_empty()) {1511accesskit_node_set_state_description(ae->node, p_description.utf8().ptr());1512} else {1513accesskit_node_clear_state_description(ae->node);1514}1515}15161517void AccessibilityDriverAccessKit::accessibility_update_set_color_value(const RID &p_id, const Color &p_color) {1518ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");15191520AccessibilityElement *ae = rid_owner.get_or_null(p_id);1521ERR_FAIL_NULL(ae);1522_ensure_node(p_id, ae);15231524accesskit_node_set_color_value(ae->node, p_color.to_rgba32());1525}15261527void AccessibilityDriverAccessKit::accessibility_update_set_background_color(const RID &p_id, const Color &p_color) {1528ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");15291530AccessibilityElement *ae = rid_owner.get_or_null(p_id);1531ERR_FAIL_NULL(ae);1532_ensure_node(p_id, ae);15331534accesskit_node_set_background_color(ae->node, p_color.to_rgba32());1535}15361537void AccessibilityDriverAccessKit::accessibility_update_set_foreground_color(const RID &p_id, const Color &p_color) {1538ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification.");15391540AccessibilityElement *ae = rid_owner.get_or_null(p_id);1541ERR_FAIL_NULL(ae);1542_ensure_node(p_id, ae);15431544accesskit_node_set_foreground_color(ae->node, p_color.to_rgba32());1545}15461547Error AccessibilityDriverAccessKit::init() {1548#ifdef ACCESSKIT_DYNAMIC1549#ifdef DEBUG_ENABLED1550int dylibloader_verbose = 1;1551#else1552int dylibloader_verbose = 0;1553#endif1554void *library_handle = nullptr;1555String path;1556String arch = Engine::get_singleton()->get_architecture_name();1557#ifdef LINUXBSD_ENABLED1558path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("libaccesskit." + arch + ".so");1559if (!FileAccess::exists(path)) {1560path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("../lib").path_join("libaccesskit." + arch + ".so");1561}1562if (!FileAccess::exists(path)) {1563path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("libaccesskit.so");1564}1565if (!FileAccess::exists(path)) {1566path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("../lib").path_join("libaccesskit.so");1567}1568if (!FileAccess::exists(path)) {1569return ERR_CANT_CREATE;1570}1571#endif1572#ifdef MACOS_ENABLED1573path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("libaccesskit." + arch + ".dylib");1574if (!FileAccess::exists(path)) {1575path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("../Frameworks").path_join("libaccesskit." + arch + ".dylib");1576}1577if (!FileAccess::exists(path)) {1578path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("libaccesskit.dylib");1579}1580if (!FileAccess::exists(path)) {1581path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("../Frameworks").path_join("libaccesskit.dylib");1582}1583if (!FileAccess::exists(path)) {1584return ERR_CANT_CREATE;1585}1586#endif1587#ifdef WINDOWS_ENABLED1588path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("accesskit." + arch + ".dll");1589if (!FileAccess::exists(path)) {1590path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("accesskit.dll");1591}1592if (!FileAccess::exists(path)) {1593return ERR_CANT_CREATE;1594}1595#endif15961597Error err = OS::get_singleton()->open_dynamic_library(path, library_handle);1598if (err == OK && initialize_libaccesskit(dylibloader_verbose, library_handle) == 0) {1599print_verbose("AccessKit loaded.");1600} else {1601return ERR_CANT_CREATE;1602}1603#endif1604#ifdef MACOS_ENABLED1605//accesskit_macos_add_focus_forwarder_to_window_class("GodotWindow");1606#endif1607return OK;1608}16091610AccessibilityDriverAccessKit::AccessibilityDriverAccessKit() {1611singleton = this;16121613role_map[DisplayServer::AccessibilityRole::ROLE_UNKNOWN] = ACCESSKIT_ROLE_UNKNOWN;1614role_map[DisplayServer::AccessibilityRole::ROLE_DEFAULT_BUTTON] = ACCESSKIT_ROLE_DEFAULT_BUTTON;1615role_map[DisplayServer::AccessibilityRole::ROLE_AUDIO] = ACCESSKIT_ROLE_AUDIO;1616role_map[DisplayServer::AccessibilityRole::ROLE_VIDEO] = ACCESSKIT_ROLE_VIDEO;1617role_map[DisplayServer::AccessibilityRole::ROLE_STATIC_TEXT] = ACCESSKIT_ROLE_LABEL;1618role_map[DisplayServer::AccessibilityRole::ROLE_CONTAINER] = ACCESSKIT_ROLE_GENERIC_CONTAINER;1619role_map[DisplayServer::AccessibilityRole::ROLE_PANEL] = ACCESSKIT_ROLE_PANE;1620role_map[DisplayServer::AccessibilityRole::ROLE_BUTTON] = ACCESSKIT_ROLE_BUTTON;1621role_map[DisplayServer::AccessibilityRole::ROLE_LINK] = ACCESSKIT_ROLE_LINK;1622role_map[DisplayServer::AccessibilityRole::ROLE_CHECK_BOX] = ACCESSKIT_ROLE_CHECK_BOX;1623role_map[DisplayServer::AccessibilityRole::ROLE_RADIO_BUTTON] = ACCESSKIT_ROLE_RADIO_BUTTON;1624role_map[DisplayServer::AccessibilityRole::ROLE_CHECK_BUTTON] = ACCESSKIT_ROLE_SWITCH;1625role_map[DisplayServer::AccessibilityRole::ROLE_SCROLL_BAR] = ACCESSKIT_ROLE_SCROLL_BAR;1626role_map[DisplayServer::AccessibilityRole::ROLE_SCROLL_VIEW] = ACCESSKIT_ROLE_SCROLL_VIEW;1627role_map[DisplayServer::AccessibilityRole::ROLE_SPLITTER] = ACCESSKIT_ROLE_SPLITTER;1628role_map[DisplayServer::AccessibilityRole::ROLE_SLIDER] = ACCESSKIT_ROLE_SLIDER;1629role_map[DisplayServer::AccessibilityRole::ROLE_SPIN_BUTTON] = ACCESSKIT_ROLE_SPIN_BUTTON;1630role_map[DisplayServer::AccessibilityRole::ROLE_PROGRESS_INDICATOR] = ACCESSKIT_ROLE_PROGRESS_INDICATOR;1631role_map[DisplayServer::AccessibilityRole::ROLE_TEXT_FIELD] = ACCESSKIT_ROLE_TEXT_INPUT;1632role_map[DisplayServer::AccessibilityRole::ROLE_MULTILINE_TEXT_FIELD] = ACCESSKIT_ROLE_MULTILINE_TEXT_INPUT;1633role_map[DisplayServer::AccessibilityRole::ROLE_COLOR_PICKER] = ACCESSKIT_ROLE_COLOR_WELL;1634role_map[DisplayServer::AccessibilityRole::ROLE_TABLE] = ACCESSKIT_ROLE_TABLE;1635role_map[DisplayServer::AccessibilityRole::ROLE_CELL] = ACCESSKIT_ROLE_CELL;1636role_map[DisplayServer::AccessibilityRole::ROLE_ROW] = ACCESSKIT_ROLE_ROW;1637role_map[DisplayServer::AccessibilityRole::ROLE_ROW_GROUP] = ACCESSKIT_ROLE_ROW_GROUP;1638role_map[DisplayServer::AccessibilityRole::ROLE_ROW_HEADER] = ACCESSKIT_ROLE_ROW_HEADER;1639role_map[DisplayServer::AccessibilityRole::ROLE_COLUMN_HEADER] = ACCESSKIT_ROLE_COLUMN_HEADER;1640role_map[DisplayServer::AccessibilityRole::ROLE_TREE] = ACCESSKIT_ROLE_TREE;1641role_map[DisplayServer::AccessibilityRole::ROLE_TREE_ITEM] = ACCESSKIT_ROLE_TREE_ITEM;1642role_map[DisplayServer::AccessibilityRole::ROLE_LIST] = ACCESSKIT_ROLE_LIST;1643role_map[DisplayServer::AccessibilityRole::ROLE_LIST_ITEM] = ACCESSKIT_ROLE_LIST_ITEM;1644role_map[DisplayServer::AccessibilityRole::ROLE_LIST_BOX] = ACCESSKIT_ROLE_LIST_BOX;1645role_map[DisplayServer::AccessibilityRole::ROLE_LIST_BOX_OPTION] = ACCESSKIT_ROLE_LIST_BOX_OPTION;1646role_map[DisplayServer::AccessibilityRole::ROLE_TAB_BAR] = ACCESSKIT_ROLE_TAB_LIST;1647role_map[DisplayServer::AccessibilityRole::ROLE_TAB] = ACCESSKIT_ROLE_TAB;1648role_map[DisplayServer::AccessibilityRole::ROLE_TAB_PANEL] = ACCESSKIT_ROLE_TAB_PANEL;1649role_map[DisplayServer::AccessibilityRole::ROLE_MENU_BAR] = ACCESSKIT_ROLE_MENU_BAR;1650role_map[DisplayServer::AccessibilityRole::ROLE_MENU] = ACCESSKIT_ROLE_MENU;1651role_map[DisplayServer::AccessibilityRole::ROLE_MENU_ITEM] = ACCESSKIT_ROLE_MENU_ITEM;1652role_map[DisplayServer::AccessibilityRole::ROLE_MENU_ITEM_CHECK_BOX] = ACCESSKIT_ROLE_MENU_ITEM_CHECK_BOX;1653role_map[DisplayServer::AccessibilityRole::ROLE_MENU_ITEM_RADIO] = ACCESSKIT_ROLE_MENU_ITEM_RADIO;1654role_map[DisplayServer::AccessibilityRole::ROLE_IMAGE] = ACCESSKIT_ROLE_IMAGE;1655role_map[DisplayServer::AccessibilityRole::ROLE_WINDOW] = ACCESSKIT_ROLE_WINDOW;1656role_map[DisplayServer::AccessibilityRole::ROLE_TITLE_BAR] = ACCESSKIT_ROLE_TITLE_BAR;1657role_map[DisplayServer::AccessibilityRole::ROLE_DIALOG] = ACCESSKIT_ROLE_DIALOG;1658role_map[DisplayServer::AccessibilityRole::ROLE_TOOLTIP] = ACCESSKIT_ROLE_TOOLTIP;1659role_map[DisplayServer::AccessibilityRole::ROLE_REGION] = ACCESSKIT_ROLE_REGION;16601661action_map[DisplayServer::AccessibilityAction::ACTION_CLICK] = ACCESSKIT_ACTION_CLICK;1662action_map[DisplayServer::AccessibilityAction::ACTION_FOCUS] = ACCESSKIT_ACTION_FOCUS;1663action_map[DisplayServer::AccessibilityAction::ACTION_BLUR] = ACCESSKIT_ACTION_BLUR;1664action_map[DisplayServer::AccessibilityAction::ACTION_COLLAPSE] = ACCESSKIT_ACTION_COLLAPSE;1665action_map[DisplayServer::AccessibilityAction::ACTION_EXPAND] = ACCESSKIT_ACTION_EXPAND;1666action_map[DisplayServer::AccessibilityAction::ACTION_DECREMENT] = ACCESSKIT_ACTION_DECREMENT;1667action_map[DisplayServer::AccessibilityAction::ACTION_INCREMENT] = ACCESSKIT_ACTION_INCREMENT;1668action_map[DisplayServer::AccessibilityAction::ACTION_HIDE_TOOLTIP] = ACCESSKIT_ACTION_HIDE_TOOLTIP;1669action_map[DisplayServer::AccessibilityAction::ACTION_SHOW_TOOLTIP] = ACCESSKIT_ACTION_SHOW_TOOLTIP;1670//action_map[DisplayServer::AccessibilityAction::ACTION_INVALIDATE_TREE] = ACCESSKIT_ACTION_INVALIDATE_TREE;1671//action_map[DisplayServer::AccessibilityAction::ACTION_LOAD_INLINE_TEXT_BOXES] = ACCESSKIT_ACTION_LOAD_INLINE_TEXT_BOXES;1672action_map[DisplayServer::AccessibilityAction::ACTION_SET_TEXT_SELECTION] = ACCESSKIT_ACTION_SET_TEXT_SELECTION;1673action_map[DisplayServer::AccessibilityAction::ACTION_REPLACE_SELECTED_TEXT] = ACCESSKIT_ACTION_REPLACE_SELECTED_TEXT;1674action_map[DisplayServer::AccessibilityAction::ACTION_SCROLL_BACKWARD] = ACCESSKIT_ACTION_SCROLL_UP;1675action_map[DisplayServer::AccessibilityAction::ACTION_SCROLL_DOWN] = ACCESSKIT_ACTION_SCROLL_DOWN;1676action_map[DisplayServer::AccessibilityAction::ACTION_SCROLL_FORWARD] = ACCESSKIT_ACTION_SCROLL_DOWN;1677action_map[DisplayServer::AccessibilityAction::ACTION_SCROLL_LEFT] = ACCESSKIT_ACTION_SCROLL_LEFT;1678action_map[DisplayServer::AccessibilityAction::ACTION_SCROLL_RIGHT] = ACCESSKIT_ACTION_SCROLL_RIGHT;1679action_map[DisplayServer::AccessibilityAction::ACTION_SCROLL_UP] = ACCESSKIT_ACTION_SCROLL_UP;1680action_map[DisplayServer::AccessibilityAction::ACTION_SCROLL_INTO_VIEW] = ACCESSKIT_ACTION_SCROLL_INTO_VIEW;1681action_map[DisplayServer::AccessibilityAction::ACTION_SCROLL_TO_POINT] = ACCESSKIT_ACTION_SCROLL_TO_POINT;1682action_map[DisplayServer::AccessibilityAction::ACTION_SET_SCROLL_OFFSET] = ACCESSKIT_ACTION_SET_SCROLL_OFFSET;1683//action_map[DisplayServer::AccessibilityAction::ACTION_SET_SEQUENTIAL_FOCUS_NAVIGATION_STARTING_POINT] = ACCESSKIT_ACTION_SET_SEQUENTIAL_FOCUS_NAVIGATION_STARTING_POINT;1684action_map[DisplayServer::AccessibilityAction::ACTION_SET_VALUE] = ACCESSKIT_ACTION_SET_VALUE;1685action_map[DisplayServer::AccessibilityAction::ACTION_SHOW_CONTEXT_MENU] = ACCESSKIT_ACTION_SHOW_CONTEXT_MENU;1686action_map[DisplayServer::AccessibilityAction::ACTION_CUSTOM] = ACCESSKIT_ACTION_CUSTOM_ACTION;1687}16881689AccessibilityDriverAccessKit::~AccessibilityDriverAccessKit() {1690singleton = nullptr;1691}16921693#endif // ACCESSKIT_ENABLED169416951696