| 1 | /**************************************************************************/ |
| 2 | /* accessibility_driver_accesskit.cpp */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #ifdef ACCESSKIT_ENABLED |
| 32 | |
| 33 | #include "accessibility_driver_accesskit.h" |
| 34 | |
| 35 | #include "core/config/project_settings.h" |
| 36 | #include "core/io/file_access.h" |
| 37 | #include "core/version.h" |
| 38 | |
| 39 | #include "servers/text/text_server.h" |
| 40 | |
| 41 | AccessibilityDriverAccessKit *AccessibilityDriverAccessKit::singleton = nullptr; |
| 42 | |
| 43 | _FORCE_INLINE_ accesskit_role AccessibilityDriverAccessKit::_accessibility_role(DisplayServer::AccessibilityRole p_role) const { |
| 44 | if (role_map.has(p_role)) { |
| 45 | return role_map[p_role]; |
| 46 | } |
| 47 | return ACCESSKIT_ROLE_UNKNOWN; |
| 48 | } |
| 49 | |
| 50 | _FORCE_INLINE_ accesskit_action AccessibilityDriverAccessKit::_accessibility_action(DisplayServer::AccessibilityAction p_action) const { |
| 51 | if (action_map.has(p_action)) { |
| 52 | return action_map[p_action]; |
| 53 | } |
| 54 | return ACCESSKIT_ACTION_CLICK; |
| 55 | } |
| 56 | |
| 57 | bool AccessibilityDriverAccessKit::window_create(DisplayServer::WindowID p_window_id, void *p_handle) { |
| 58 | ERR_FAIL_COND_V(windows.has(p_window_id), false); |
| 59 | |
| 60 | WindowData &wd = windows[p_window_id]; |
| 61 | |
| 62 | AccessibilityElement *ae = memnew(AccessibilityElement); |
| 63 | ae->role = ACCESSKIT_ROLE_WINDOW; |
| 64 | ae->window_id = p_window_id; |
| 65 | wd.root_id = rid_owner.make_rid(ae); |
| 66 | |
| 67 | #ifdef WINDOWS_ENABLED |
| 68 | wd.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); |
| 69 | #endif |
| 70 | #ifdef MACOS_ENABLED |
| 71 | wd.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); |
| 72 | #endif |
| 73 | #ifdef LINUXBSD_ENABLED |
| 74 | wd.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); |
| 75 | #endif |
| 76 | print_verbose(vformat("Accessibility: window %d adapter created.", p_window_id)); |
| 77 | |
| 78 | if (wd.adapter == nullptr) { |
| 79 | memdelete(ae); |
| 80 | rid_owner.free(wd.root_id); |
| 81 | windows.erase(p_window_id); |
| 82 | |
| 83 | return false; |
| 84 | } else { |
| 85 | return true; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | void AccessibilityDriverAccessKit::window_destroy(DisplayServer::WindowID p_window_id) { |
| 90 | WindowData *wd = windows.getptr(p_window_id); |
| 91 | ERR_FAIL_NULL(wd); |
| 92 | |
| 93 | print_verbose(vformat("Accessibility: window %d adapter destroyed.", p_window_id)); |
| 94 | |
| 95 | #ifdef WINDOWS_ENABLED |
| 96 | accesskit_windows_subclassing_adapter_free(wd->adapter); |
| 97 | #endif |
| 98 | #ifdef MACOS_ENABLED |
| 99 | accesskit_macos_subclassing_adapter_free(wd->adapter); |
| 100 | #endif |
| 101 | #ifdef LINUXBSD_ENABLED |
| 102 | accesskit_unix_adapter_free(wd->adapter); |
| 103 | #endif |
| 104 | accessibility_free_element(wd->root_id); |
| 105 | |
| 106 | windows.erase(p_window_id); |
| 107 | } |
| 108 | |
| 109 | void AccessibilityDriverAccessKit::_accessibility_deactivation_callback(void *p_user_data) { |
| 110 | DisplayServer::WindowID window_id = (DisplayServer::WindowID)(size_t)p_user_data; |
| 111 | WindowData *wd = singleton->windows.getptr(window_id); |
| 112 | ERR_FAIL_NULL(wd); |
| 113 | |
| 114 | print_verbose(vformat("Accessibility: window %d adapter deactivated.", window_id)); |
| 115 | |
| 116 | if (singleton->focus.is_valid()) { |
| 117 | AccessibilityElement *ae = singleton->rid_owner.get_or_null(singleton->focus); |
| 118 | if (ae && ae->window_id == window_id) { |
| 119 | singleton->focus = RID(); |
| 120 | } |
| 121 | } |
| 122 | if (wd->deactivate.is_valid()) { |
| 123 | wd->deactivate.call_deferred(); // Should be called on main thread only. |
| 124 | } |
| 125 | wd->update.clear(); |
| 126 | } |
| 127 | |
| 128 | void AccessibilityDriverAccessKit::_accessibility_action_callback(struct accesskit_action_request *p_request, void *p_user_data) { |
| 129 | DisplayServer::WindowID window_id = (DisplayServer::WindowID)(size_t)p_user_data; |
| 130 | ERR_FAIL_COND(!singleton->windows.has(window_id)); |
| 131 | |
| 132 | RID rid = RID::from_uint64(p_request->target_node); |
| 133 | AccessibilityElement *ae = singleton->rid_owner.get_or_null(rid); |
| 134 | ERR_FAIL_NULL(ae); |
| 135 | |
| 136 | Variant rq_data; |
| 137 | if (!ae->actions.has(p_request->action) && ae->role == ACCESSKIT_ROLE_TEXT_RUN && p_request->action == ACCESSKIT_ACTION_SCROLL_INTO_VIEW) { |
| 138 | AccessibilityElement *root_ae = singleton->rid_owner.get_or_null(ae->parent); |
| 139 | ERR_FAIL_NULL(root_ae); |
| 140 | ae = root_ae; |
| 141 | rq_data = ae->run; |
| 142 | } |
| 143 | |
| 144 | if (ae->actions.has(p_request->action)) { |
| 145 | Callable &cb = ae->actions[p_request->action]; |
| 146 | if (cb.is_valid()) { |
| 147 | if (p_request->data.has_value) { |
| 148 | switch (p_request->data.value.tag) { |
| 149 | case ACCESSKIT_ACTION_DATA_CUSTOM_ACTION: { |
| 150 | rq_data = p_request->data.value.custom_action; |
| 151 | } break; |
| 152 | case ACCESSKIT_ACTION_DATA_VALUE: { |
| 153 | rq_data = String::utf8(p_request->data.value.value); |
| 154 | } break; |
| 155 | case ACCESSKIT_ACTION_DATA_NUMERIC_VALUE: { |
| 156 | rq_data = p_request->data.value.numeric_value; |
| 157 | } break; |
| 158 | case ACCESSKIT_ACTION_DATA_SCROLL_HINT: { |
| 159 | switch (p_request->data.value.scroll_hint) { |
| 160 | case ACCESSKIT_SCROLL_HINT_TOP_LEFT: { |
| 161 | rq_data = DisplayServer::SCROLL_HINT_TOP_LEFT; |
| 162 | } break; |
| 163 | case ACCESSKIT_SCROLL_HINT_BOTTOM_RIGHT: { |
| 164 | rq_data = DisplayServer::SCROLL_HINT_BOTTOM_RIGHT; |
| 165 | } break; |
| 166 | case ACCESSKIT_SCROLL_HINT_TOP_EDGE: { |
| 167 | rq_data = DisplayServer::SCROLL_HINT_TOP_EDGE; |
| 168 | } break; |
| 169 | case ACCESSKIT_SCROLL_HINT_BOTTOM_EDGE: { |
| 170 | rq_data = DisplayServer::SCROLL_HINT_BOTTOM_EDGE; |
| 171 | } break; |
| 172 | case ACCESSKIT_SCROLL_HINT_LEFT_EDGE: { |
| 173 | rq_data = DisplayServer::SCROLL_HINT_LEFT_EDGE; |
| 174 | } break; |
| 175 | case ACCESSKIT_SCROLL_HINT_RIGHT_EDGE: { |
| 176 | rq_data = DisplayServer::SCROLL_HINT_RIGHT_EDGE; |
| 177 | } break; |
| 178 | default: |
| 179 | break; |
| 180 | } |
| 181 | } break; |
| 182 | case ACCESSKIT_ACTION_DATA_SCROLL_UNIT: { |
| 183 | if (p_request->data.value.scroll_unit == ACCESSKIT_SCROLL_UNIT_ITEM) { |
| 184 | rq_data = DisplayServer::SCROLL_UNIT_ITEM; |
| 185 | } else if (p_request->data.value.scroll_unit == ACCESSKIT_SCROLL_UNIT_PAGE) { |
| 186 | rq_data = DisplayServer::SCROLL_UNIT_PAGE; |
| 187 | } |
| 188 | } break; |
| 189 | case ACCESSKIT_ACTION_DATA_SCROLL_TO_POINT: { |
| 190 | rq_data = Point2(p_request->data.value.scroll_to_point.x, p_request->data.value.scroll_to_point.y); |
| 191 | } break; |
| 192 | case ACCESSKIT_ACTION_DATA_SET_SCROLL_OFFSET: { |
| 193 | rq_data = Point2(p_request->data.value.set_scroll_offset.x, p_request->data.value.set_scroll_offset.y); |
| 194 | } break; |
| 195 | case ACCESSKIT_ACTION_DATA_SET_TEXT_SELECTION: { |
| 196 | Dictionary sel; |
| 197 | |
| 198 | RID start_rid = RID::from_uint64(p_request->data.value.set_text_selection.anchor.node); |
| 199 | AccessibilityElement *start_ae = singleton->rid_owner.get_or_null(start_rid); |
| 200 | ERR_FAIL_NULL(start_ae); |
| 201 | |
| 202 | RID end_rid = RID::from_uint64(p_request->data.value.set_text_selection.focus.node); |
| 203 | AccessibilityElement *end_ae = singleton->rid_owner.get_or_null(end_rid); |
| 204 | ERR_FAIL_NULL(end_ae); |
| 205 | |
| 206 | sel["start_element"] = start_ae->parent; |
| 207 | sel["start_char"] = (int64_t)p_request->data.value.set_text_selection.anchor.character_index + start_ae->run.x; |
| 208 | sel["end_element"] = end_ae->parent; |
| 209 | sel["end_char"] = (int64_t)p_request->data.value.set_text_selection.focus.character_index + end_ae->run.x; |
| 210 | rq_data = sel; |
| 211 | } break; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | cb.call_deferred(rq_data); |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | accesskit_tree_update *AccessibilityDriverAccessKit::_accessibility_initial_tree_update_callback(void *p_user_data) { |
| 221 | DisplayServer::WindowID window_id = (DisplayServer::WindowID)(size_t)p_user_data; |
| 222 | WindowData *wd = singleton->windows.getptr(window_id); |
| 223 | ERR_FAIL_NULL_V(wd, nullptr); |
| 224 | |
| 225 | accesskit_node *win_node = accesskit_node_new(ACCESSKIT_ROLE_WINDOW); |
| 226 | accesskit_node_set_label(win_node, "Godot Engine"); |
| 227 | accesskit_node_set_busy(win_node); |
| 228 | |
| 229 | accesskit_node_id win_id = (accesskit_node_id)wd->root_id.get_id(); |
| 230 | |
| 231 | accesskit_tree_update *tree_update = accesskit_tree_update_with_capacity_and_focus(1, win_id); |
| 232 | |
| 233 | accesskit_tree_update_set_tree(tree_update, accesskit_tree_new(win_id)); |
| 234 | accesskit_tree_update_push_node(tree_update, win_id, win_node); |
| 235 | |
| 236 | print_verbose(vformat("Accessibility: window %d adapter activated.", window_id)); |
| 237 | |
| 238 | if (wd->activate.is_valid()) { |
| 239 | wd->activate.call_deferred(); // Should be called on main thread only. |
| 240 | } |
| 241 | |
| 242 | return tree_update; |
| 243 | } |
| 244 | |
| 245 | void AccessibilityDriverAccessKit::accessibility_set_window_callbacks(DisplayServer::WindowID p_window_id, const Callable &p_activate_callable, const Callable &p_deativate_callable) { |
| 246 | WindowData *wd = singleton->windows.getptr(p_window_id); |
| 247 | ERR_FAIL_NULL(wd); |
| 248 | |
| 249 | wd->activate = p_activate_callable; |
| 250 | wd->deactivate = p_deativate_callable; |
| 251 | } |
| 252 | |
| 253 | void AccessibilityDriverAccessKit::accessibility_window_activation_completed(DisplayServer::WindowID p_window_id) { |
| 254 | WindowData *wd = singleton->windows.getptr(p_window_id); |
| 255 | if (!wd) { |
| 256 | return; |
| 257 | } |
| 258 | |
| 259 | print_verbose(vformat("Accessibility: window %d adapter initial update completed.", p_window_id)); |
| 260 | |
| 261 | wd->initial_update_completed = true; |
| 262 | } |
| 263 | |
| 264 | void AccessibilityDriverAccessKit::accessibility_window_deactivation_completed(DisplayServer::WindowID p_window_id) { |
| 265 | WindowData *wd = singleton->windows.getptr(p_window_id); |
| 266 | if (!wd) { |
| 267 | return; |
| 268 | } |
| 269 | |
| 270 | print_verbose(vformat("Accessibility: window %d adapter deactivation completed.", p_window_id)); |
| 271 | |
| 272 | #ifdef DEV_ENABLED |
| 273 | LocalVector<RID> to_delete; |
| 274 | for (const RID &rid : rid_owner.get_owned_list()) { |
| 275 | AccessibilityElement *ae = rid_owner.get_or_null(rid); |
| 276 | if (rid != wd->root_id && ae && ae->window_id == p_window_id) { |
| 277 | ERR_PRINT(vformat("Accessibility/BUG: Accessibility element %d was not deleted on window %d adapter deactivation.", rid.get_id(), p_window_id)); |
| 278 | to_delete.push_back(rid); |
| 279 | } |
| 280 | } |
| 281 | for (const RID &rid : to_delete) { |
| 282 | _free_recursive(wd, rid); |
| 283 | } |
| 284 | #endif |
| 285 | wd->initial_update_completed = false; |
| 286 | } |
| 287 | |
| 288 | RID AccessibilityDriverAccessKit::accessibility_create_element(DisplayServer::WindowID p_window_id, DisplayServer::AccessibilityRole p_role) { |
| 289 | AccessibilityElement *ae = memnew(AccessibilityElement); |
| 290 | ae->role = _accessibility_role(p_role); |
| 291 | ae->window_id = p_window_id; |
| 292 | RID rid = rid_owner.make_rid(ae); |
| 293 | |
| 294 | return rid; |
| 295 | } |
| 296 | |
| 297 | RID AccessibilityDriverAccessKit::accessibility_create_sub_element(const RID &p_parent_rid, DisplayServer::AccessibilityRole p_role, int p_insert_pos) { |
| 298 | AccessibilityElement *parent_ae = rid_owner.get_or_null(p_parent_rid); |
| 299 | ERR_FAIL_NULL_V(parent_ae, RID()); |
| 300 | |
| 301 | WindowData *wd = windows.getptr(parent_ae->window_id); |
| 302 | ERR_FAIL_NULL_V(wd, RID()); |
| 303 | |
| 304 | AccessibilityElement *ae = memnew(AccessibilityElement); |
| 305 | ae->role = _accessibility_role(p_role); |
| 306 | ae->window_id = parent_ae->window_id; |
| 307 | ae->parent = p_parent_rid; |
| 308 | ae->node = accesskit_node_new(ae->role); |
| 309 | RID rid = rid_owner.make_rid(ae); |
| 310 | if (p_insert_pos == -1) { |
| 311 | parent_ae->children.push_back(rid); |
| 312 | } else { |
| 313 | parent_ae->children.insert(p_insert_pos, rid); |
| 314 | } |
| 315 | wd->update.insert(rid); |
| 316 | |
| 317 | return rid; |
| 318 | } |
| 319 | |
| 320 | RID 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) { |
| 321 | AccessibilityElement *parent_ae = rid_owner.get_or_null(p_parent_rid); |
| 322 | ERR_FAIL_NULL_V(parent_ae, RID()); |
| 323 | |
| 324 | WindowData *wd = windows.getptr(parent_ae->window_id); |
| 325 | ERR_FAIL_NULL_V(wd, RID()); |
| 326 | |
| 327 | AccessibilityElement *root_ae = memnew(AccessibilityElement); |
| 328 | root_ae->role = ACCESSKIT_ROLE_GENERIC_CONTAINER; |
| 329 | root_ae->window_id = parent_ae->window_id; |
| 330 | root_ae->parent = p_parent_rid; |
| 331 | root_ae->node = accesskit_node_new(root_ae->role); |
| 332 | RID root_rid = rid_owner.make_rid(root_ae); |
| 333 | if (p_insert_pos == -1) { |
| 334 | parent_ae->children.push_back(root_rid); |
| 335 | } else { |
| 336 | parent_ae->children.insert(p_insert_pos, root_rid); |
| 337 | } |
| 338 | wd->update.insert(root_rid); |
| 339 | |
| 340 | float text_width = 0; |
| 341 | float text_height = p_min_height; |
| 342 | Vector<int32_t> words; |
| 343 | int64_t run_count = 0; // Note: runs in visual order. |
| 344 | const Glyph *gl = nullptr; |
| 345 | float run_off_x = 0.0; |
| 346 | Vector2i full_range; |
| 347 | |
| 348 | if (p_shaped_text.is_valid()) { |
| 349 | text_width = TS->shaped_text_get_size(p_shaped_text).x; |
| 350 | text_height = MAX(text_height, TS->shaped_text_get_size(p_shaped_text).y); |
| 351 | words = TS->shaped_text_get_word_breaks(p_shaped_text); |
| 352 | run_count = TS->shaped_get_run_count(p_shaped_text); |
| 353 | gl = TS->shaped_text_get_glyphs(p_shaped_text); |
| 354 | full_range = TS->shaped_text_get_range(p_shaped_text); |
| 355 | } |
| 356 | |
| 357 | accesskit_rect root_rect; |
| 358 | root_rect.x0 = 0; |
| 359 | root_rect.y0 = 0; |
| 360 | root_rect.x1 = text_width; |
| 361 | root_rect.y1 = MAX(p_min_height, text_height); |
| 362 | accesskit_node_set_bounds(root_ae->node, root_rect); |
| 363 | |
| 364 | // Create text element for each run. |
| 365 | Vector<AccessibilityElement *> text_elements; |
| 366 | for (int64_t i = 0; i < run_count; i++) { |
| 367 | const Vector2i range = TS->shaped_get_run_range(p_shaped_text, i); |
| 368 | const Vector2i gl_range = TS->shaped_get_run_glyph_range(p_shaped_text, i); |
| 369 | String run_t = TS->shaped_get_run_text(p_shaped_text, i); |
| 370 | TextServer::Direction dir = TS->shaped_get_run_direction(p_shaped_text, i); |
| 371 | |
| 372 | if (run_t.is_empty()) { |
| 373 | continue; |
| 374 | } |
| 375 | |
| 376 | // Split long runs in to < 254 char subruns due to AccessKit limitation. |
| 377 | Vector<Vector2i> subrun_ranges; |
| 378 | Vector<Vector<uint8_t>> subrun_word_starts; |
| 379 | { |
| 380 | Vector2i cur_range = range; |
| 381 | bool slice = false; |
| 382 | do { |
| 383 | // Word starts. |
| 384 | Vector<uint8_t> word_starts; |
| 385 | word_starts.push_back(0); |
| 386 | |
| 387 | slice = false; |
| 388 | for (int j = 0; j < words.size(); j += 2) { |
| 389 | if (words[j] <= cur_range.x) { |
| 390 | continue; |
| 391 | } |
| 392 | if (words[j] >= cur_range.y) { |
| 393 | break; |
| 394 | } |
| 395 | int32_t wstart = words[j] - cur_range.x; |
| 396 | int32_t wend = words[j + 1] - cur_range.x; |
| 397 | if (wend >= 254) { |
| 398 | cur_range.y = words[j]; |
| 399 | slice = true; |
| 400 | break; |
| 401 | } |
| 402 | word_starts.push_back(wstart); |
| 403 | } |
| 404 | subrun_ranges.push_back(cur_range); |
| 405 | subrun_word_starts.push_back(word_starts); |
| 406 | if (slice) { |
| 407 | cur_range.x = cur_range.y; |
| 408 | cur_range.y = range.y; |
| 409 | } |
| 410 | } while (slice); |
| 411 | } |
| 412 | |
| 413 | // Process subruns. |
| 414 | int start, end, delta; |
| 415 | if (dir == TextServer::DIRECTION_LTR) { |
| 416 | start = 0; |
| 417 | end = subrun_ranges.size(); |
| 418 | delta = +1; |
| 419 | } else { |
| 420 | start = subrun_ranges.size() - 1; |
| 421 | end = -1; |
| 422 | delta = -1; |
| 423 | } |
| 424 | for (int rr = start; rr != end; rr += delta) { |
| 425 | // Word starts. |
| 426 | const Vector<uint8_t> &word_starts = subrun_word_starts[rr]; |
| 427 | const Vector2i &cur_range = subrun_ranges[rr]; |
| 428 | |
| 429 | AccessibilityElement *ae = memnew(AccessibilityElement); |
| 430 | ae->role = ACCESSKIT_ROLE_TEXT_RUN; |
| 431 | ae->window_id = parent_ae->window_id; |
| 432 | ae->parent = root_rid; |
| 433 | ae->run = Vector3i(cur_range.x, cur_range.y, i); |
| 434 | ae->node = accesskit_node_new(ae->role); |
| 435 | |
| 436 | text_elements.push_back(ae); |
| 437 | |
| 438 | String sub_t = run_t.substr(cur_range.x - range.x, cur_range.y - cur_range.x); |
| 439 | if (sub_t.is_empty()) { |
| 440 | continue; |
| 441 | } |
| 442 | |
| 443 | // UTF-8 text and char lengths. |
| 444 | Vector<uint8_t> char_lengths; |
| 445 | CharString text = sub_t.utf8(&char_lengths); |
| 446 | |
| 447 | accesskit_node_set_value(ae->node, text.ptr()); |
| 448 | accesskit_node_set_character_lengths(ae->node, char_lengths.size(), char_lengths.ptr()); |
| 449 | |
| 450 | accesskit_node_set_word_starts(ae->node, word_starts.size(), word_starts.ptr()); |
| 451 | |
| 452 | // Char widths and positions. |
| 453 | Vector<float> char_positions; |
| 454 | Vector<float> char_widths; |
| 455 | |
| 456 | char_positions.resize_initialized(sub_t.length()); |
| 457 | float *positions_ptr = char_positions.ptrw(); |
| 458 | |
| 459 | char_widths.resize_initialized(sub_t.length()); |
| 460 | float *widths_ptr = char_widths.ptrw(); |
| 461 | |
| 462 | float size_x = 0.0; |
| 463 | for (int j = gl_range.x; j <= gl_range.y; j += gl[j].count) { |
| 464 | if (gl[j].start >= ae->run.y || gl[j].start < ae->run.x) { |
| 465 | continue; |
| 466 | } |
| 467 | float advance = 0.0; // Graphame advance. |
| 468 | for (int k = 0; k < gl[j].count; k++) { |
| 469 | advance += gl[j + k].advance; |
| 470 | } |
| 471 | int chars = gl[j].end - gl[j].start; |
| 472 | float adv_per_char = advance / (float)chars; |
| 473 | |
| 474 | for (int k = 0; k < chars; k++) { |
| 475 | int index = gl[j].start + k - ae->run.x; |
| 476 | ERR_CONTINUE(index < 0 || index >= sub_t.length()); |
| 477 | positions_ptr[index] = size_x + adv_per_char * k; |
| 478 | widths_ptr[index] = adv_per_char; |
| 479 | } |
| 480 | size_x += advance * gl[j].repeat; |
| 481 | } |
| 482 | positions_ptr[sub_t.length() - 1] = size_x; |
| 483 | widths_ptr[sub_t.length() - 1] = 1.0; |
| 484 | |
| 485 | accesskit_node_set_character_positions(ae->node, char_positions.size(), char_positions.ptr()); |
| 486 | accesskit_node_set_character_widths(ae->node, char_widths.size(), char_widths.ptr()); |
| 487 | |
| 488 | RID font_rid = TS->shaped_get_run_font_rid(p_shaped_text, i); |
| 489 | if (font_rid != RID()) { |
| 490 | CharString font_name = TS->font_get_name(font_rid).utf8(); |
| 491 | if (font_name.length() > 0) { |
| 492 | accesskit_node_set_font_family(ae->node, font_name.ptr()); |
| 493 | } |
| 494 | if (TS->font_get_style(font_rid).has_flag(TextServer::FONT_ITALIC)) { |
| 495 | accesskit_node_set_italic(ae->node); |
| 496 | } |
| 497 | accesskit_node_set_font_weight(ae->node, TS->font_get_weight(font_rid)); |
| 498 | } |
| 499 | accesskit_node_set_font_size(ae->node, TS->shaped_get_run_font_size(p_shaped_text, i)); |
| 500 | CharString language = TS->shaped_get_run_language(p_shaped_text, i).utf8(); |
| 501 | if (language.length() > 0) { |
| 502 | accesskit_node_set_language(ae->node, language.ptr()); |
| 503 | } |
| 504 | |
| 505 | accesskit_node_set_text_direction(ae->node, ACCESSKIT_TEXT_DIRECTION_LEFT_TO_RIGHT); |
| 506 | |
| 507 | accesskit_rect rect; |
| 508 | rect.x0 = run_off_x; |
| 509 | rect.y0 = 0; |
| 510 | rect.x1 = run_off_x + size_x; |
| 511 | rect.y1 = text_height; |
| 512 | accesskit_node_set_bounds(ae->node, rect); |
| 513 | accesskit_node_add_action(ae->node, ACCESSKIT_ACTION_SCROLL_INTO_VIEW); |
| 514 | |
| 515 | run_off_x += size_x; |
| 516 | } |
| 517 | } |
| 518 | if (!p_is_last_line || text_elements.is_empty()) { |
| 519 | // Add "\n" at the end. |
| 520 | AccessibilityElement *ae = memnew(AccessibilityElement); |
| 521 | ae->role = ACCESSKIT_ROLE_TEXT_RUN; |
| 522 | ae->window_id = parent_ae->window_id; |
| 523 | ae->parent = root_rid; |
| 524 | ae->run = Vector3i(full_range.y, full_range.y, run_count); |
| 525 | ae->node = accesskit_node_new(ae->role); |
| 526 | |
| 527 | text_elements.push_back(ae); |
| 528 | |
| 529 | if (!p_is_last_line) { |
| 530 | accesskit_node_set_value(ae->node, "\n"); |
| 531 | |
| 532 | Vector<uint8_t> char_lengths; |
| 533 | Vector<float> char_positions; |
| 534 | Vector<float> char_widths; |
| 535 | char_lengths.push_back(1); |
| 536 | char_positions.push_back(0.0); |
| 537 | char_widths.push_back(1.0); |
| 538 | |
| 539 | accesskit_node_set_character_lengths(ae->node, char_lengths.size(), char_lengths.ptr()); |
| 540 | accesskit_node_set_character_positions(ae->node, char_positions.size(), char_positions.ptr()); |
| 541 | accesskit_node_set_character_widths(ae->node, char_widths.size(), char_widths.ptr()); |
| 542 | } else { |
| 543 | accesskit_node_set_value(ae->node, ""); |
| 544 | } |
| 545 | accesskit_node_set_text_direction(ae->node, ACCESSKIT_TEXT_DIRECTION_LEFT_TO_RIGHT); |
| 546 | |
| 547 | accesskit_rect rect; |
| 548 | rect.x0 = run_off_x; |
| 549 | rect.y0 = 0; |
| 550 | rect.x1 = run_off_x + 1; |
| 551 | rect.y1 = text_height; |
| 552 | accesskit_node_set_bounds(ae->node, rect); |
| 553 | } |
| 554 | |
| 555 | // Sort runs in logical order. |
| 556 | struct RunCompare { |
| 557 | _FORCE_INLINE_ bool operator()(const AccessibilityElement *l, const AccessibilityElement *r) const { |
| 558 | return l->run.x < r->run.x; |
| 559 | } |
| 560 | }; |
| 561 | text_elements.sort_custom<RunCompare>(); |
| 562 | for (int i = 0; i < text_elements.size(); i++) { |
| 563 | RID rid = rid_owner.make_rid(text_elements[i]); |
| 564 | root_ae->children.push_back(rid); |
| 565 | wd->update.insert(rid); |
| 566 | |
| 567 | // Link adjacent TextRuns on the same line. |
| 568 | if (i > 0) { |
| 569 | RID prev_rid = root_ae->children[i - 1]; |
| 570 | AccessibilityElement *prev_ae = rid_owner.get_or_null(prev_rid); |
| 571 | accesskit_node_set_previous_on_line(text_elements[i]->node, (accesskit_node_id)prev_rid.get_id()); |
| 572 | accesskit_node_set_next_on_line(prev_ae->node, (accesskit_node_id)rid.get_id()); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | return root_rid; |
| 577 | } |
| 578 | |
| 579 | bool AccessibilityDriverAccessKit::accessibility_has_element(const RID &p_id) const { |
| 580 | return rid_owner.owns(p_id); |
| 581 | } |
| 582 | |
| 583 | void AccessibilityDriverAccessKit::_free_recursive(WindowData *p_wd, const RID &p_id) { |
| 584 | if (p_wd && p_wd->update.has(p_id)) { |
| 585 | p_wd->update.erase(p_id); |
| 586 | } |
| 587 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 588 | for (const RID &rid : ae->children) { |
| 589 | _free_recursive(p_wd, rid); |
| 590 | } |
| 591 | if (ae->node) { |
| 592 | accesskit_node_free(ae->node); |
| 593 | } |
| 594 | memdelete(ae); |
| 595 | rid_owner.free(p_id); |
| 596 | } |
| 597 | |
| 598 | void AccessibilityDriverAccessKit::accessibility_free_element(const RID &p_id) { |
| 599 | ERR_FAIL_COND_MSG(in_accessibility_update, "Element can't be removed inside NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 600 | |
| 601 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 602 | if (ae) { |
| 603 | WindowData *wd = windows.getptr(ae->window_id); |
| 604 | AccessibilityElement *parent_ae = rid_owner.get_or_null(ae->parent); |
| 605 | if (parent_ae) { |
| 606 | parent_ae->children.erase(p_id); |
| 607 | } |
| 608 | _free_recursive(wd, p_id); |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | void AccessibilityDriverAccessKit::accessibility_element_set_meta(const RID &p_id, const Variant &p_meta) { |
| 613 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 614 | |
| 615 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 616 | ERR_FAIL_NULL(ae); |
| 617 | ae->meta = p_meta; |
| 618 | } |
| 619 | |
| 620 | Variant AccessibilityDriverAccessKit::accessibility_element_get_meta(const RID &p_id) const { |
| 621 | const AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 622 | ERR_FAIL_NULL_V(ae, Variant()); |
| 623 | return ae->meta; |
| 624 | } |
| 625 | |
| 626 | void AccessibilityDriverAccessKit::accessibility_update_set_focus(const RID &p_id) { |
| 627 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 628 | |
| 629 | if (p_id.is_valid() && rid_owner.owns(p_id)) { |
| 630 | focus = p_id; |
| 631 | } else { |
| 632 | focus = RID(); |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | RID AccessibilityDriverAccessKit::accessibility_get_window_root(DisplayServer::WindowID p_window_id) const { |
| 637 | const WindowData *wd = windows.getptr(p_window_id); |
| 638 | ERR_FAIL_NULL_V(wd, RID()); |
| 639 | |
| 640 | return wd->root_id; |
| 641 | } |
| 642 | |
| 643 | accesskit_tree_update *AccessibilityDriverAccessKit::_accessibility_build_tree_update(void *p_user_data) { |
| 644 | DisplayServer::WindowID window_id = (DisplayServer::WindowID)(size_t)p_user_data; |
| 645 | |
| 646 | ERR_FAIL_COND_V(!singleton->windows.has(window_id), nullptr); |
| 647 | WindowData &wd = singleton->windows[window_id]; |
| 648 | |
| 649 | singleton->in_accessibility_update = true; |
| 650 | if (singleton->update_cb.is_valid()) { |
| 651 | singleton->update_cb.call(window_id); |
| 652 | } |
| 653 | singleton->in_accessibility_update = false; |
| 654 | |
| 655 | AccessibilityElement *focus_ae = singleton->rid_owner.get_or_null(singleton->focus); |
| 656 | uint32_t update_size = wd.update.size(); |
| 657 | |
| 658 | accesskit_node_id ac_focus = (accesskit_node_id)wd.root_id.get_id(); |
| 659 | if (focus_ae && focus_ae->window_id == window_id) { |
| 660 | ac_focus = (accesskit_node_id)singleton->focus.get_id(); |
| 661 | } |
| 662 | |
| 663 | accesskit_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); |
| 664 | for (const RID &rid : wd.update) { |
| 665 | AccessibilityElement *ae = singleton->rid_owner.get_or_null(rid); |
| 666 | if (ae && ae->node) { |
| 667 | for (const RID &child_rid : ae->children) { |
| 668 | accesskit_node_push_child(ae->node, (accesskit_node_id)child_rid.get_id()); |
| 669 | } |
| 670 | accesskit_tree_update_push_node(tree_update, (accesskit_node_id)rid.get_id(), ae->node); |
| 671 | ae->node = nullptr; |
| 672 | } |
| 673 | } |
| 674 | wd.update.clear(); |
| 675 | |
| 676 | return tree_update; |
| 677 | } |
| 678 | |
| 679 | void AccessibilityDriverAccessKit::accessibility_update_if_active(const Callable &p_callable) { |
| 680 | ERR_FAIL_COND(!p_callable.is_valid()); |
| 681 | update_cb = p_callable; |
| 682 | for (KeyValue<DisplayServer::WindowID, WindowData> &window : windows) { |
| 683 | #ifdef WINDOWS_ENABLED |
| 684 | accesskit_windows_queued_events *events = accesskit_windows_subclassing_adapter_update_if_active(window.value.adapter, _accessibility_build_tree_update, (void *)(size_t)window.key); |
| 685 | if (events) { |
| 686 | accesskit_windows_queued_events_raise(events); |
| 687 | } |
| 688 | #endif |
| 689 | #ifdef MACOS_ENABLED |
| 690 | accesskit_macos_queued_events *events = accesskit_macos_subclassing_adapter_update_if_active(window.value.adapter, _accessibility_build_tree_update, (void *)(size_t)window.key); |
| 691 | if (events) { |
| 692 | accesskit_macos_queued_events_raise(events); |
| 693 | } |
| 694 | #endif |
| 695 | #ifdef LINUXBSD_ENABLED |
| 696 | accesskit_unix_adapter_update_if_active(window.value.adapter, _accessibility_build_tree_update, (void *)(size_t)window.key); |
| 697 | #endif |
| 698 | } |
| 699 | update_cb = Callable(); |
| 700 | } |
| 701 | |
| 702 | _FORCE_INLINE_ void AccessibilityDriverAccessKit::_ensure_node(const RID &p_id, AccessibilityElement *p_ae) { |
| 703 | if (unlikely(!p_ae->node)) { |
| 704 | WindowData *wd = windows.getptr(p_ae->window_id); |
| 705 | ERR_FAIL_NULL(wd); |
| 706 | |
| 707 | wd->update.insert(p_id); |
| 708 | p_ae->node = accesskit_node_new(p_ae->role); |
| 709 | |
| 710 | // Re-apply stored name if any, so nodes recreated by _ensure_node |
| 711 | // retain their label even if the caller doesn't re-set all properties. |
| 712 | if (!p_ae->name.is_empty() || !p_ae->name_extra_info.is_empty()) { |
| 713 | String full_name = p_ae->name + " " + p_ae->name_extra_info; |
| 714 | accesskit_node_set_label(p_ae->node, full_name.utf8().ptr()); |
| 715 | } |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | void AccessibilityDriverAccessKit::accessibility_set_window_rect(DisplayServer::WindowID p_window_id, const Rect2 &p_rect_out, const Rect2 &p_rect_in) { |
| 720 | #ifdef LINUXBSD_ENABLED |
| 721 | const WindowData *wd = windows.getptr(p_window_id); |
| 722 | ERR_FAIL_NULL(wd); |
| 723 | |
| 724 | accesskit_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 }; |
| 725 | accesskit_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 }; |
| 726 | accesskit_unix_adapter_set_root_window_bounds(wd->adapter, outer_bounds, inner_bounds); |
| 727 | #endif |
| 728 | } |
| 729 | |
| 730 | void AccessibilityDriverAccessKit::accessibility_set_window_focused(DisplayServer::WindowID p_window_id, bool p_focused) { |
| 731 | const WindowData *wd = windows.getptr(p_window_id); |
| 732 | ERR_FAIL_NULL(wd); |
| 733 | |
| 734 | #ifdef LINUXBSD_ENABLED |
| 735 | accesskit_unix_adapter_update_window_focus_state(wd->adapter, p_focused); |
| 736 | #endif |
| 737 | #ifdef MACOS_ENABLED |
| 738 | accesskit_macos_queued_events *events = accesskit_macos_subclassing_adapter_update_view_focus_state(wd->adapter, p_focused); |
| 739 | if (events != nullptr) { |
| 740 | accesskit_macos_queued_events_raise(events); |
| 741 | } |
| 742 | #endif |
| 743 | // Note: On Windows, the subclassing adapter takes care of this. |
| 744 | } |
| 745 | |
| 746 | void AccessibilityDriverAccessKit::accessibility_update_set_role(const RID &p_id, DisplayServer::AccessibilityRole p_role) { |
| 747 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 748 | |
| 749 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 750 | ERR_FAIL_NULL(ae); |
| 751 | if (ae->role == _accessibility_role(p_role)) { |
| 752 | return; |
| 753 | } |
| 754 | ae->role = _accessibility_role(p_role); |
| 755 | _ensure_node(p_id, ae); |
| 756 | |
| 757 | accesskit_node_set_role(ae->node, ae->role); |
| 758 | } |
| 759 | |
| 760 | void AccessibilityDriverAccessKit::accessibility_update_set_name(const RID &p_id, const String &p_name) { |
| 761 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 762 | |
| 763 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 764 | ERR_FAIL_NULL(ae); |
| 765 | _ensure_node(p_id, ae); |
| 766 | |
| 767 | ae->name = p_name; |
| 768 | String full_name = ae->name + " " + ae->name_extra_info; |
| 769 | if (!full_name.is_empty()) { |
| 770 | accesskit_node_set_label(ae->node, full_name.utf8().ptr()); |
| 771 | } else { |
| 772 | accesskit_node_clear_label(ae->node); |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | void AccessibilityDriverAccessKit::accessibility_update_set_extra_info(const RID &p_id, const String &p_name_extra_info) { |
| 777 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 778 | |
| 779 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 780 | ERR_FAIL_NULL(ae); |
| 781 | _ensure_node(p_id, ae); |
| 782 | |
| 783 | ae->name_extra_info = p_name_extra_info; |
| 784 | String full_name = ae->name + " " + ae->name_extra_info; |
| 785 | if (!full_name.is_empty()) { |
| 786 | accesskit_node_set_label(ae->node, full_name.utf8().ptr()); |
| 787 | } else { |
| 788 | accesskit_node_clear_label(ae->node); |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | void AccessibilityDriverAccessKit::accessibility_update_set_description(const RID &p_id, const String &p_description) { |
| 793 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 794 | |
| 795 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 796 | ERR_FAIL_NULL(ae); |
| 797 | _ensure_node(p_id, ae); |
| 798 | |
| 799 | if (!p_description.is_empty()) { |
| 800 | accesskit_node_set_description(ae->node, p_description.utf8().ptr()); |
| 801 | } else { |
| 802 | accesskit_node_clear_description(ae->node); |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | void AccessibilityDriverAccessKit::accessibility_update_set_value(const RID &p_id, const String &p_value) { |
| 807 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 808 | |
| 809 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 810 | ERR_FAIL_NULL(ae); |
| 811 | _ensure_node(p_id, ae); |
| 812 | |
| 813 | if (!p_value.is_empty()) { |
| 814 | Vector<uint8_t> ch_length; |
| 815 | accesskit_node_set_value(ae->node, p_value.utf8(&ch_length).ptr()); |
| 816 | accesskit_node_set_character_lengths(ae->node, ch_length.size(), ch_length.ptr()); |
| 817 | } else { |
| 818 | accesskit_node_clear_value(ae->node); |
| 819 | accesskit_node_clear_character_lengths(ae->node); |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | void AccessibilityDriverAccessKit::accessibility_update_set_tooltip(const RID &p_id, const String &p_tooltip) { |
| 824 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 825 | |
| 826 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 827 | ERR_FAIL_NULL(ae); |
| 828 | _ensure_node(p_id, ae); |
| 829 | |
| 830 | if (!p_tooltip.is_empty()) { |
| 831 | accesskit_node_set_tooltip(ae->node, p_tooltip.utf8().ptr()); |
| 832 | } else { |
| 833 | accesskit_node_clear_tooltip(ae->node); |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | void AccessibilityDriverAccessKit::accessibility_update_set_bounds(const RID &p_id, const Rect2 &p_rect) { |
| 838 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 839 | |
| 840 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 841 | ERR_FAIL_NULL(ae); |
| 842 | _ensure_node(p_id, ae); |
| 843 | |
| 844 | accesskit_rect rect; |
| 845 | rect.x0 = p_rect.position.x; |
| 846 | rect.y0 = p_rect.position.y; |
| 847 | rect.x1 = p_rect.position.x + p_rect.size.x; |
| 848 | rect.y1 = p_rect.position.y + p_rect.size.y; |
| 849 | accesskit_node_set_bounds(ae->node, rect); |
| 850 | } |
| 851 | |
| 852 | void AccessibilityDriverAccessKit::accessibility_update_set_transform(const RID &p_id, const Transform2D &p_transform) { |
| 853 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 854 | |
| 855 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 856 | ERR_FAIL_NULL(ae); |
| 857 | _ensure_node(p_id, ae); |
| 858 | |
| 859 | accesskit_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] }; |
| 860 | accesskit_node_set_transform(ae->node, transform); |
| 861 | } |
| 862 | |
| 863 | void AccessibilityDriverAccessKit::accessibility_update_add_child(const RID &p_id, const RID &p_child_id) { |
| 864 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 865 | |
| 866 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 867 | ERR_FAIL_NULL(ae); |
| 868 | AccessibilityElement *other_ae = rid_owner.get_or_null(p_child_id); |
| 869 | ERR_FAIL_NULL(other_ae); |
| 870 | ERR_FAIL_COND(other_ae->window_id != ae->window_id); |
| 871 | _ensure_node(p_id, ae); |
| 872 | |
| 873 | accesskit_node_push_child(ae->node, (accesskit_node_id)p_child_id.get_id()); |
| 874 | } |
| 875 | |
| 876 | void AccessibilityDriverAccessKit::accessibility_update_add_related_controls(const RID &p_id, const RID &p_related_id) { |
| 877 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 878 | |
| 879 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 880 | ERR_FAIL_NULL(ae); |
| 881 | AccessibilityElement *other_ae = rid_owner.get_or_null(p_related_id); |
| 882 | ERR_FAIL_NULL(other_ae); |
| 883 | ERR_FAIL_COND(other_ae->window_id != ae->window_id); |
| 884 | _ensure_node(p_id, ae); |
| 885 | |
| 886 | accesskit_node_push_controlled(ae->node, (accesskit_node_id)p_related_id.get_id()); |
| 887 | } |
| 888 | |
| 889 | void AccessibilityDriverAccessKit::accessibility_update_add_related_details(const RID &p_id, const RID &p_related_id) { |
| 890 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 891 | |
| 892 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 893 | ERR_FAIL_NULL(ae); |
| 894 | AccessibilityElement *other_ae = rid_owner.get_or_null(p_related_id); |
| 895 | ERR_FAIL_NULL(other_ae); |
| 896 | ERR_FAIL_COND(other_ae->window_id != ae->window_id); |
| 897 | _ensure_node(p_id, ae); |
| 898 | |
| 899 | accesskit_node_push_detail(ae->node, (accesskit_node_id)p_related_id.get_id()); |
| 900 | } |
| 901 | |
| 902 | void AccessibilityDriverAccessKit::accessibility_update_add_related_described_by(const RID &p_id, const RID &p_related_id) { |
| 903 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 904 | |
| 905 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 906 | ERR_FAIL_NULL(ae); |
| 907 | AccessibilityElement *other_ae = rid_owner.get_or_null(p_related_id); |
| 908 | ERR_FAIL_NULL(other_ae); |
| 909 | ERR_FAIL_COND(other_ae->window_id != ae->window_id); |
| 910 | _ensure_node(p_id, ae); |
| 911 | |
| 912 | accesskit_node_push_described_by(ae->node, (accesskit_node_id)p_related_id.get_id()); |
| 913 | } |
| 914 | |
| 915 | void AccessibilityDriverAccessKit::accessibility_update_add_related_flow_to(const RID &p_id, const RID &p_related_id) { |
| 916 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 917 | |
| 918 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 919 | ERR_FAIL_NULL(ae); |
| 920 | AccessibilityElement *other_ae = rid_owner.get_or_null(p_related_id); |
| 921 | ERR_FAIL_NULL(other_ae); |
| 922 | ERR_FAIL_COND(other_ae->window_id != ae->window_id); |
| 923 | _ensure_node(p_id, ae); |
| 924 | |
| 925 | accesskit_node_push_flow_to(ae->node, (accesskit_node_id)p_related_id.get_id()); |
| 926 | } |
| 927 | |
| 928 | void AccessibilityDriverAccessKit::accessibility_update_add_related_labeled_by(const RID &p_id, const RID &p_related_id) { |
| 929 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 930 | |
| 931 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 932 | ERR_FAIL_NULL(ae); |
| 933 | AccessibilityElement *other_ae = rid_owner.get_or_null(p_related_id); |
| 934 | ERR_FAIL_NULL(other_ae); |
| 935 | ERR_FAIL_COND(other_ae->window_id != ae->window_id); |
| 936 | _ensure_node(p_id, ae); |
| 937 | |
| 938 | accesskit_node_push_labelled_by(ae->node, (accesskit_node_id)p_related_id.get_id()); |
| 939 | } |
| 940 | |
| 941 | void AccessibilityDriverAccessKit::accessibility_update_add_related_radio_group(const RID &p_id, const RID &p_related_id) { |
| 942 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 943 | |
| 944 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 945 | ERR_FAIL_NULL(ae); |
| 946 | AccessibilityElement *other_ae = rid_owner.get_or_null(p_related_id); |
| 947 | ERR_FAIL_NULL(other_ae); |
| 948 | ERR_FAIL_COND(other_ae->window_id != ae->window_id); |
| 949 | _ensure_node(p_id, ae); |
| 950 | |
| 951 | accesskit_node_push_to_radio_group(ae->node, (accesskit_node_id)p_related_id.get_id()); |
| 952 | } |
| 953 | |
| 954 | void AccessibilityDriverAccessKit::accessibility_update_set_active_descendant(const RID &p_id, const RID &p_other_id) { |
| 955 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 956 | |
| 957 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 958 | ERR_FAIL_NULL(ae); |
| 959 | AccessibilityElement *other_ae = rid_owner.get_or_null(p_other_id); |
| 960 | ERR_FAIL_NULL(other_ae); |
| 961 | ERR_FAIL_COND(other_ae->window_id != ae->window_id); |
| 962 | _ensure_node(p_id, ae); |
| 963 | |
| 964 | accesskit_node_set_active_descendant(ae->node, (accesskit_node_id)p_other_id.get_id()); |
| 965 | } |
| 966 | |
| 967 | void AccessibilityDriverAccessKit::accessibility_update_set_next_on_line(const RID &p_id, const RID &p_other_id) { |
| 968 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 969 | |
| 970 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 971 | ERR_FAIL_NULL(ae); |
| 972 | AccessibilityElement *other_ae = rid_owner.get_or_null(p_other_id); |
| 973 | ERR_FAIL_NULL(other_ae); |
| 974 | ERR_FAIL_COND(other_ae->window_id != ae->window_id); |
| 975 | _ensure_node(p_id, ae); |
| 976 | |
| 977 | accesskit_node_set_next_on_line(ae->node, (accesskit_node_id)p_other_id.get_id()); |
| 978 | } |
| 979 | |
| 980 | void AccessibilityDriverAccessKit::accessibility_update_set_previous_on_line(const RID &p_id, const RID &p_other_id) { |
| 981 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 982 | |
| 983 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 984 | ERR_FAIL_NULL(ae); |
| 985 | AccessibilityElement *other_ae = rid_owner.get_or_null(p_other_id); |
| 986 | ERR_FAIL_NULL(other_ae); |
| 987 | ERR_FAIL_COND(other_ae->window_id != ae->window_id); |
| 988 | _ensure_node(p_id, ae); |
| 989 | |
| 990 | accesskit_node_set_previous_on_line(ae->node, (accesskit_node_id)p_other_id.get_id()); |
| 991 | } |
| 992 | |
| 993 | void AccessibilityDriverAccessKit::accessibility_update_set_member_of(const RID &p_id, const RID &p_group_id) { |
| 994 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 995 | |
| 996 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 997 | ERR_FAIL_NULL(ae); |
| 998 | AccessibilityElement *other_ae = rid_owner.get_or_null(p_group_id); |
| 999 | ERR_FAIL_NULL(other_ae); |
| 1000 | ERR_FAIL_COND(other_ae->window_id != ae->window_id); |
| 1001 | _ensure_node(p_id, ae); |
| 1002 | |
| 1003 | accesskit_node_set_member_of(ae->node, (accesskit_node_id)p_group_id.get_id()); |
| 1004 | } |
| 1005 | |
| 1006 | void AccessibilityDriverAccessKit::accessibility_update_set_in_page_link_target(const RID &p_id, const RID &p_other_id) { |
| 1007 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1008 | |
| 1009 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1010 | ERR_FAIL_NULL(ae); |
| 1011 | AccessibilityElement *other_ae = rid_owner.get_or_null(p_other_id); |
| 1012 | ERR_FAIL_NULL(other_ae); |
| 1013 | ERR_FAIL_COND(other_ae->window_id != ae->window_id); |
| 1014 | _ensure_node(p_id, ae); |
| 1015 | |
| 1016 | accesskit_node_set_in_page_link_target(ae->node, (accesskit_node_id)p_other_id.get_id()); |
| 1017 | } |
| 1018 | |
| 1019 | void AccessibilityDriverAccessKit::accessibility_update_set_error_message(const RID &p_id, const RID &p_other_id) { |
| 1020 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1021 | |
| 1022 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1023 | ERR_FAIL_NULL(ae); |
| 1024 | AccessibilityElement *other_ae = rid_owner.get_or_null(p_other_id); |
| 1025 | ERR_FAIL_NULL(other_ae); |
| 1026 | ERR_FAIL_COND(other_ae->window_id != ae->window_id); |
| 1027 | _ensure_node(p_id, ae); |
| 1028 | |
| 1029 | accesskit_node_set_error_message(ae->node, (accesskit_node_id)p_other_id.get_id()); |
| 1030 | } |
| 1031 | |
| 1032 | void AccessibilityDriverAccessKit::accessibility_update_set_live(const RID &p_id, DisplayServer::AccessibilityLiveMode p_live) { |
| 1033 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1034 | |
| 1035 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1036 | ERR_FAIL_NULL(ae); |
| 1037 | _ensure_node(p_id, ae); |
| 1038 | |
| 1039 | switch (p_live) { |
| 1040 | case DisplayServer::AccessibilityLiveMode::LIVE_OFF: { |
| 1041 | accesskit_node_set_live(ae->node, ACCESSKIT_LIVE_OFF); |
| 1042 | } break; |
| 1043 | case DisplayServer::AccessibilityLiveMode::LIVE_POLITE: { |
| 1044 | accesskit_node_set_live(ae->node, ACCESSKIT_LIVE_POLITE); |
| 1045 | } break; |
| 1046 | case DisplayServer::AccessibilityLiveMode::LIVE_ASSERTIVE: { |
| 1047 | accesskit_node_set_live(ae->node, ACCESSKIT_LIVE_ASSERTIVE); |
| 1048 | } break; |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | void AccessibilityDriverAccessKit::accessibility_update_add_action(const RID &p_id, DisplayServer::AccessibilityAction p_action, const Callable &p_callable) { |
| 1053 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1054 | |
| 1055 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1056 | ERR_FAIL_NULL(ae); |
| 1057 | _ensure_node(p_id, ae); |
| 1058 | |
| 1059 | ae->actions[_accessibility_action(p_action)] = p_callable; |
| 1060 | |
| 1061 | accesskit_node_add_action(ae->node, _accessibility_action(p_action)); |
| 1062 | } |
| 1063 | |
| 1064 | void AccessibilityDriverAccessKit::accessibility_update_add_custom_action(const RID &p_id, int p_action_id, const String &p_action_description) { |
| 1065 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1066 | |
| 1067 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1068 | ERR_FAIL_NULL(ae); |
| 1069 | _ensure_node(p_id, ae); |
| 1070 | |
| 1071 | if (!p_action_description.is_empty()) { |
| 1072 | accesskit_custom_action *ca = accesskit_custom_action_new(p_action_id); |
| 1073 | accesskit_custom_action_set_description(ca, p_action_description.utf8().ptr()); |
| 1074 | accesskit_node_push_custom_action(ae->node, ca); |
| 1075 | } else { |
| 1076 | String cs_name = vformat("Custom Action %d", p_action_id); |
| 1077 | accesskit_custom_action *ca = accesskit_custom_action_new(p_action_id); |
| 1078 | accesskit_custom_action_set_description(ca, cs_name.utf8().ptr()); |
| 1079 | accesskit_node_push_custom_action(ae->node, ca); |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | void AccessibilityDriverAccessKit::accessibility_update_set_table_row_count(const RID &p_id, int p_count) { |
| 1084 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1085 | |
| 1086 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1087 | ERR_FAIL_NULL(ae); |
| 1088 | _ensure_node(p_id, ae); |
| 1089 | |
| 1090 | accesskit_node_set_row_count(ae->node, p_count); |
| 1091 | } |
| 1092 | |
| 1093 | void AccessibilityDriverAccessKit::accessibility_update_set_table_column_count(const RID &p_id, int p_count) { |
| 1094 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1095 | |
| 1096 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1097 | ERR_FAIL_NULL(ae); |
| 1098 | _ensure_node(p_id, ae); |
| 1099 | |
| 1100 | accesskit_node_set_column_count(ae->node, p_count); |
| 1101 | } |
| 1102 | |
| 1103 | void AccessibilityDriverAccessKit::accessibility_update_set_table_row_index(const RID &p_id, int p_index) { |
| 1104 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1105 | |
| 1106 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1107 | ERR_FAIL_NULL(ae); |
| 1108 | _ensure_node(p_id, ae); |
| 1109 | |
| 1110 | accesskit_node_set_row_index(ae->node, p_index); |
| 1111 | } |
| 1112 | |
| 1113 | void AccessibilityDriverAccessKit::accessibility_update_set_table_column_index(const RID &p_id, int p_index) { |
| 1114 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1115 | |
| 1116 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1117 | ERR_FAIL_NULL(ae); |
| 1118 | _ensure_node(p_id, ae); |
| 1119 | |
| 1120 | accesskit_node_set_column_index(ae->node, p_index); |
| 1121 | } |
| 1122 | |
| 1123 | void AccessibilityDriverAccessKit::accessibility_update_set_table_cell_position(const RID &p_id, int p_row_index, int p_column_index) { |
| 1124 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1125 | |
| 1126 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1127 | ERR_FAIL_NULL(ae); |
| 1128 | _ensure_node(p_id, ae); |
| 1129 | |
| 1130 | accesskit_node_set_row_index(ae->node, p_row_index); |
| 1131 | accesskit_node_set_column_index(ae->node, p_column_index); |
| 1132 | } |
| 1133 | |
| 1134 | void AccessibilityDriverAccessKit::accessibility_update_set_table_cell_span(const RID &p_id, int p_row_span, int p_column_span) { |
| 1135 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1136 | |
| 1137 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1138 | ERR_FAIL_NULL(ae); |
| 1139 | _ensure_node(p_id, ae); |
| 1140 | |
| 1141 | accesskit_node_set_row_span(ae->node, p_row_span); |
| 1142 | accesskit_node_set_column_span(ae->node, p_column_span); |
| 1143 | } |
| 1144 | |
| 1145 | void AccessibilityDriverAccessKit::accessibility_update_set_list_item_count(const RID &p_id, int p_size) { |
| 1146 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1147 | |
| 1148 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1149 | ERR_FAIL_NULL(ae); |
| 1150 | _ensure_node(p_id, ae); |
| 1151 | |
| 1152 | accesskit_node_set_size_of_set(ae->node, p_size); |
| 1153 | } |
| 1154 | |
| 1155 | void AccessibilityDriverAccessKit::accessibility_update_set_list_item_index(const RID &p_id, int p_index) { |
| 1156 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1157 | |
| 1158 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1159 | ERR_FAIL_NULL(ae); |
| 1160 | _ensure_node(p_id, ae); |
| 1161 | |
| 1162 | accesskit_node_set_position_in_set(ae->node, p_index); |
| 1163 | } |
| 1164 | |
| 1165 | void AccessibilityDriverAccessKit::accessibility_update_set_list_item_level(const RID &p_id, int p_level) { |
| 1166 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1167 | |
| 1168 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1169 | ERR_FAIL_NULL(ae); |
| 1170 | _ensure_node(p_id, ae); |
| 1171 | |
| 1172 | accesskit_node_set_level(ae->node, p_level); |
| 1173 | } |
| 1174 | |
| 1175 | void AccessibilityDriverAccessKit::accessibility_update_set_list_item_selected(const RID &p_id, bool p_selected) { |
| 1176 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1177 | |
| 1178 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1179 | ERR_FAIL_NULL(ae); |
| 1180 | _ensure_node(p_id, ae); |
| 1181 | |
| 1182 | accesskit_node_set_selected(ae->node, p_selected); |
| 1183 | } |
| 1184 | |
| 1185 | void AccessibilityDriverAccessKit::accessibility_update_set_list_item_expanded(const RID &p_id, bool p_expanded) { |
| 1186 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1187 | |
| 1188 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1189 | ERR_FAIL_NULL(ae); |
| 1190 | _ensure_node(p_id, ae); |
| 1191 | |
| 1192 | accesskit_node_set_expanded(ae->node, p_expanded); |
| 1193 | } |
| 1194 | |
| 1195 | void AccessibilityDriverAccessKit::accessibility_update_set_popup_type(const RID &p_id, DisplayServer::AccessibilityPopupType p_popup) { |
| 1196 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1197 | |
| 1198 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1199 | ERR_FAIL_NULL(ae); |
| 1200 | _ensure_node(p_id, ae); |
| 1201 | |
| 1202 | switch (p_popup) { |
| 1203 | case DisplayServer::AccessibilityPopupType::POPUP_MENU: { |
| 1204 | accesskit_node_set_has_popup(ae->node, ACCESSKIT_HAS_POPUP_MENU); |
| 1205 | } break; |
| 1206 | case DisplayServer::AccessibilityPopupType::POPUP_LIST: { |
| 1207 | accesskit_node_set_has_popup(ae->node, ACCESSKIT_HAS_POPUP_LISTBOX); |
| 1208 | } break; |
| 1209 | case DisplayServer::AccessibilityPopupType::POPUP_TREE: { |
| 1210 | accesskit_node_set_has_popup(ae->node, ACCESSKIT_HAS_POPUP_TREE); |
| 1211 | } break; |
| 1212 | case DisplayServer::AccessibilityPopupType::POPUP_DIALOG: { |
| 1213 | accesskit_node_set_has_popup(ae->node, ACCESSKIT_HAS_POPUP_DIALOG); |
| 1214 | } break; |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | void AccessibilityDriverAccessKit::accessibility_update_set_checked(const RID &p_id, bool p_checekd) { |
| 1219 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1220 | |
| 1221 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1222 | ERR_FAIL_NULL(ae); |
| 1223 | _ensure_node(p_id, ae); |
| 1224 | |
| 1225 | if (p_checekd) { |
| 1226 | accesskit_node_set_toggled(ae->node, ACCESSKIT_TOGGLED_TRUE); |
| 1227 | } else { |
| 1228 | accesskit_node_set_toggled(ae->node, ACCESSKIT_TOGGLED_FALSE); |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | void AccessibilityDriverAccessKit::accessibility_update_set_num_value(const RID &p_id, double p_position) { |
| 1233 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1234 | |
| 1235 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1236 | ERR_FAIL_NULL(ae); |
| 1237 | _ensure_node(p_id, ae); |
| 1238 | |
| 1239 | accesskit_node_set_numeric_value(ae->node, p_position); |
| 1240 | } |
| 1241 | |
| 1242 | void AccessibilityDriverAccessKit::accessibility_update_set_num_range(const RID &p_id, double p_min, double p_max) { |
| 1243 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1244 | |
| 1245 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1246 | ERR_FAIL_NULL(ae); |
| 1247 | _ensure_node(p_id, ae); |
| 1248 | |
| 1249 | accesskit_node_set_min_numeric_value(ae->node, p_min); |
| 1250 | accesskit_node_set_max_numeric_value(ae->node, p_max); |
| 1251 | } |
| 1252 | |
| 1253 | void AccessibilityDriverAccessKit::accessibility_update_set_num_step(const RID &p_id, double p_step) { |
| 1254 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1255 | |
| 1256 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1257 | ERR_FAIL_NULL(ae); |
| 1258 | _ensure_node(p_id, ae); |
| 1259 | |
| 1260 | accesskit_node_set_numeric_value_step(ae->node, p_step); |
| 1261 | } |
| 1262 | |
| 1263 | void AccessibilityDriverAccessKit::accessibility_update_set_num_jump(const RID &p_id, double p_jump) { |
| 1264 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1265 | |
| 1266 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1267 | ERR_FAIL_NULL(ae); |
| 1268 | _ensure_node(p_id, ae); |
| 1269 | |
| 1270 | accesskit_node_set_numeric_value_jump(ae->node, p_jump); |
| 1271 | } |
| 1272 | |
| 1273 | void AccessibilityDriverAccessKit::accessibility_update_set_scroll_x(const RID &p_id, double p_position) { |
| 1274 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1275 | |
| 1276 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1277 | ERR_FAIL_NULL(ae); |
| 1278 | _ensure_node(p_id, ae); |
| 1279 | |
| 1280 | accesskit_node_set_scroll_x(ae->node, p_position); |
| 1281 | } |
| 1282 | |
| 1283 | void AccessibilityDriverAccessKit::accessibility_update_set_scroll_x_range(const RID &p_id, double p_min, double p_max) { |
| 1284 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1285 | |
| 1286 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1287 | ERR_FAIL_NULL(ae); |
| 1288 | _ensure_node(p_id, ae); |
| 1289 | |
| 1290 | accesskit_node_set_scroll_x_min(ae->node, p_min); |
| 1291 | accesskit_node_set_scroll_x_max(ae->node, p_max); |
| 1292 | } |
| 1293 | |
| 1294 | void AccessibilityDriverAccessKit::accessibility_update_set_scroll_y(const RID &p_id, double p_position) { |
| 1295 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1296 | |
| 1297 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1298 | ERR_FAIL_NULL(ae); |
| 1299 | _ensure_node(p_id, ae); |
| 1300 | |
| 1301 | accesskit_node_set_scroll_y(ae->node, p_position); |
| 1302 | } |
| 1303 | |
| 1304 | void AccessibilityDriverAccessKit::accessibility_update_set_scroll_y_range(const RID &p_id, double p_min, double p_max) { |
| 1305 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1306 | |
| 1307 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1308 | ERR_FAIL_NULL(ae); |
| 1309 | _ensure_node(p_id, ae); |
| 1310 | |
| 1311 | accesskit_node_set_scroll_y_min(ae->node, p_min); |
| 1312 | accesskit_node_set_scroll_y_max(ae->node, p_max); |
| 1313 | } |
| 1314 | |
| 1315 | void AccessibilityDriverAccessKit::accessibility_update_set_text_decorations(const RID &p_id, bool p_underline, bool p_strikethrough, bool p_overline) { |
| 1316 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1317 | |
| 1318 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1319 | ERR_FAIL_NULL(ae); |
| 1320 | _ensure_node(p_id, ae); |
| 1321 | |
| 1322 | accesskit_color color; |
| 1323 | color.red = 0; |
| 1324 | color.blue = 0; |
| 1325 | color.green = 0; |
| 1326 | color.alpha = 255; |
| 1327 | |
| 1328 | if (p_underline) { |
| 1329 | accesskit_node_set_underline(ae->node, { ACCESSKIT_TEXT_DECORATION_STYLE_SOLID, color }); |
| 1330 | } else { |
| 1331 | accesskit_node_clear_underline(ae->node); |
| 1332 | } |
| 1333 | if (p_overline) { |
| 1334 | accesskit_node_set_overline(ae->node, { ACCESSKIT_TEXT_DECORATION_STYLE_SOLID, color }); |
| 1335 | } else { |
| 1336 | accesskit_node_clear_overline(ae->node); |
| 1337 | } |
| 1338 | if (p_strikethrough) { |
| 1339 | accesskit_node_set_strikethrough(ae->node, { ACCESSKIT_TEXT_DECORATION_STYLE_SOLID, color }); |
| 1340 | } else { |
| 1341 | accesskit_node_clear_strikethrough(ae->node); |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | void AccessibilityDriverAccessKit::accessibility_update_set_text_align(const RID &p_id, HorizontalAlignment p_align) { |
| 1346 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1347 | |
| 1348 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1349 | ERR_FAIL_NULL(ae); |
| 1350 | _ensure_node(p_id, ae); |
| 1351 | |
| 1352 | switch (p_align) { |
| 1353 | case HORIZONTAL_ALIGNMENT_LEFT: { |
| 1354 | accesskit_node_set_text_align(ae->node, ACCESSKIT_TEXT_ALIGN_LEFT); |
| 1355 | } break; |
| 1356 | case HORIZONTAL_ALIGNMENT_CENTER: { |
| 1357 | accesskit_node_set_text_align(ae->node, ACCESSKIT_TEXT_ALIGN_RIGHT); |
| 1358 | } break; |
| 1359 | case HORIZONTAL_ALIGNMENT_RIGHT: { |
| 1360 | accesskit_node_set_text_align(ae->node, ACCESSKIT_TEXT_ALIGN_CENTER); |
| 1361 | } break; |
| 1362 | case HORIZONTAL_ALIGNMENT_FILL: { |
| 1363 | accesskit_node_set_text_align(ae->node, ACCESSKIT_TEXT_ALIGN_JUSTIFY); |
| 1364 | } break; |
| 1365 | } |
| 1366 | } |
| 1367 | |
| 1368 | void 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) { |
| 1369 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1370 | |
| 1371 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1372 | ERR_FAIL_NULL(ae); |
| 1373 | AccessibilityElement *start_ae = rid_owner.get_or_null(p_text_start_id); |
| 1374 | ERR_FAIL_NULL(start_ae); |
| 1375 | ERR_FAIL_COND(start_ae->window_id != ae->window_id); |
| 1376 | AccessibilityElement *end_ae = rid_owner.get_or_null(p_text_end_id); |
| 1377 | ERR_FAIL_NULL(end_ae); |
| 1378 | ERR_FAIL_COND(end_ae->window_id != ae->window_id); |
| 1379 | |
| 1380 | int start_pos = p_start_char; |
| 1381 | int end_pos = p_end_char; |
| 1382 | RID start_rid; |
| 1383 | RID end_rid; |
| 1384 | for (const RID &rid : start_ae->children) { |
| 1385 | const AccessibilityElement *child_ae = rid_owner.get_or_null(rid); |
| 1386 | if (child_ae && child_ae->role == ACCESSKIT_ROLE_TEXT_RUN) { |
| 1387 | if (p_start_char >= child_ae->run.x && p_start_char <= child_ae->run.y) { |
| 1388 | start_rid = rid; |
| 1389 | start_pos = p_start_char - child_ae->run.x; |
| 1390 | break; |
| 1391 | } |
| 1392 | } |
| 1393 | } |
| 1394 | for (const RID &rid : end_ae->children) { |
| 1395 | const AccessibilityElement *child_ae = rid_owner.get_or_null(rid); |
| 1396 | if (child_ae && child_ae->role == ACCESSKIT_ROLE_TEXT_RUN) { |
| 1397 | if (p_end_char >= child_ae->run.x && p_end_char <= child_ae->run.y) { |
| 1398 | end_rid = rid; |
| 1399 | end_pos = p_end_char - child_ae->run.x; |
| 1400 | break; |
| 1401 | } |
| 1402 | } |
| 1403 | } |
| 1404 | ERR_FAIL_COND(start_rid.is_null() && end_rid.is_null()); |
| 1405 | _ensure_node(p_id, ae); |
| 1406 | |
| 1407 | accesskit_text_selection sel; |
| 1408 | sel.anchor.node = (accesskit_node_id)start_rid.get_id(); |
| 1409 | sel.anchor.character_index = start_pos; |
| 1410 | sel.focus.node = (accesskit_node_id)end_rid.get_id(); |
| 1411 | sel.focus.character_index = end_pos; |
| 1412 | accesskit_node_set_text_selection(ae->node, sel); |
| 1413 | } |
| 1414 | |
| 1415 | void AccessibilityDriverAccessKit::accessibility_update_set_flag(const RID &p_id, DisplayServer::AccessibilityFlags p_flag, bool p_value) { |
| 1416 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1417 | |
| 1418 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1419 | ERR_FAIL_NULL(ae); |
| 1420 | _ensure_node(p_id, ae); |
| 1421 | |
| 1422 | switch (p_flag) { |
| 1423 | case DisplayServer::AccessibilityFlags::FLAG_HIDDEN: { |
| 1424 | if (p_value) { |
| 1425 | accesskit_node_set_hidden(ae->node); |
| 1426 | } else { |
| 1427 | accesskit_node_clear_hidden(ae->node); |
| 1428 | } |
| 1429 | } break; |
| 1430 | case DisplayServer::AccessibilityFlags::FLAG_MULTISELECTABLE: { |
| 1431 | if (p_value) { |
| 1432 | accesskit_node_set_multiselectable(ae->node); |
| 1433 | } else { |
| 1434 | accesskit_node_clear_multiselectable(ae->node); |
| 1435 | } |
| 1436 | } break; |
| 1437 | case DisplayServer::AccessibilityFlags::FLAG_REQUIRED: { |
| 1438 | if (p_value) { |
| 1439 | accesskit_node_set_required(ae->node); |
| 1440 | } else { |
| 1441 | accesskit_node_clear_required(ae->node); |
| 1442 | } |
| 1443 | } break; |
| 1444 | case DisplayServer::AccessibilityFlags::FLAG_VISITED: { |
| 1445 | if (p_value) { |
| 1446 | accesskit_node_set_visited(ae->node); |
| 1447 | } else { |
| 1448 | accesskit_node_clear_visited(ae->node); |
| 1449 | } |
| 1450 | } break; |
| 1451 | case DisplayServer::AccessibilityFlags::FLAG_BUSY: { |
| 1452 | if (p_value) { |
| 1453 | accesskit_node_set_busy(ae->node); |
| 1454 | } else { |
| 1455 | accesskit_node_clear_busy(ae->node); |
| 1456 | } |
| 1457 | } break; |
| 1458 | case DisplayServer::AccessibilityFlags::FLAG_MODAL: { |
| 1459 | if (p_value) { |
| 1460 | accesskit_node_set_modal(ae->node); |
| 1461 | } else { |
| 1462 | accesskit_node_clear_modal(ae->node); |
| 1463 | } |
| 1464 | } break; |
| 1465 | case DisplayServer::AccessibilityFlags::FLAG_TOUCH_PASSTHROUGH: { |
| 1466 | if (p_value) { |
| 1467 | accesskit_node_set_touch_transparent(ae->node); |
| 1468 | } else { |
| 1469 | accesskit_node_clear_touch_transparent(ae->node); |
| 1470 | } |
| 1471 | } break; |
| 1472 | case DisplayServer::AccessibilityFlags::FLAG_READONLY: { |
| 1473 | if (p_value) { |
| 1474 | accesskit_node_set_read_only(ae->node); |
| 1475 | } else { |
| 1476 | accesskit_node_clear_read_only(ae->node); |
| 1477 | } |
| 1478 | } break; |
| 1479 | case DisplayServer::AccessibilityFlags::FLAG_DISABLED: { |
| 1480 | if (p_value) { |
| 1481 | accesskit_node_set_disabled(ae->node); |
| 1482 | } else { |
| 1483 | accesskit_node_clear_disabled(ae->node); |
| 1484 | } |
| 1485 | } break; |
| 1486 | case DisplayServer::AccessibilityFlags::FLAG_CLIPS_CHILDREN: { |
| 1487 | if (p_value) { |
| 1488 | accesskit_node_set_clips_children(ae->node); |
| 1489 | } else { |
| 1490 | accesskit_node_clear_clips_children(ae->node); |
| 1491 | } |
| 1492 | } break; |
| 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | void AccessibilityDriverAccessKit::accessibility_update_set_classname(const RID &p_id, const String &p_classname) { |
| 1497 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1498 | |
| 1499 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1500 | ERR_FAIL_NULL(ae); |
| 1501 | _ensure_node(p_id, ae); |
| 1502 | |
| 1503 | if (!p_classname.is_empty()) { |
| 1504 | accesskit_node_set_class_name(ae->node, p_classname.utf8().ptr()); |
| 1505 | } else { |
| 1506 | accesskit_node_clear_class_name(ae->node); |
| 1507 | } |
| 1508 | } |
| 1509 | |
| 1510 | void AccessibilityDriverAccessKit::accessibility_update_set_placeholder(const RID &p_id, const String &p_placeholder) { |
| 1511 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1512 | |
| 1513 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1514 | ERR_FAIL_NULL(ae); |
| 1515 | _ensure_node(p_id, ae); |
| 1516 | |
| 1517 | if (!p_placeholder.is_empty()) { |
| 1518 | accesskit_node_set_placeholder(ae->node, p_placeholder.utf8().ptr()); |
| 1519 | } else { |
| 1520 | accesskit_node_clear_placeholder(ae->node); |
| 1521 | } |
| 1522 | } |
| 1523 | |
| 1524 | void AccessibilityDriverAccessKit::accessibility_update_set_language(const RID &p_id, const String &p_language) { |
| 1525 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1526 | |
| 1527 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1528 | ERR_FAIL_NULL(ae); |
| 1529 | _ensure_node(p_id, ae); |
| 1530 | |
| 1531 | accesskit_node_set_language(ae->node, p_language.utf8().ptr()); |
| 1532 | } |
| 1533 | |
| 1534 | void AccessibilityDriverAccessKit::accessibility_update_set_text_orientation(const RID &p_id, bool p_vertical) { |
| 1535 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1536 | |
| 1537 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1538 | ERR_FAIL_NULL(ae); |
| 1539 | _ensure_node(p_id, ae); |
| 1540 | |
| 1541 | if (p_vertical) { |
| 1542 | accesskit_node_set_text_direction(ae->node, ACCESSKIT_TEXT_DIRECTION_TOP_TO_BOTTOM); |
| 1543 | } else { |
| 1544 | accesskit_node_set_text_direction(ae->node, ACCESSKIT_TEXT_DIRECTION_LEFT_TO_RIGHT); |
| 1545 | } |
| 1546 | } |
| 1547 | |
| 1548 | void AccessibilityDriverAccessKit::accessibility_update_set_list_orientation(const RID &p_id, bool p_vertical) { |
| 1549 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1550 | |
| 1551 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1552 | ERR_FAIL_NULL(ae); |
| 1553 | _ensure_node(p_id, ae); |
| 1554 | |
| 1555 | if (p_vertical) { |
| 1556 | accesskit_node_set_orientation(ae->node, ACCESSKIT_ORIENTATION_VERTICAL); |
| 1557 | } else { |
| 1558 | accesskit_node_set_orientation(ae->node, ACCESSKIT_ORIENTATION_HORIZONTAL); |
| 1559 | } |
| 1560 | } |
| 1561 | |
| 1562 | void AccessibilityDriverAccessKit::accessibility_update_set_shortcut(const RID &p_id, const String &p_shortcut) { |
| 1563 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1564 | |
| 1565 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1566 | ERR_FAIL_NULL(ae); |
| 1567 | _ensure_node(p_id, ae); |
| 1568 | |
| 1569 | if (!p_shortcut.is_empty()) { |
| 1570 | accesskit_node_set_keyboard_shortcut(ae->node, p_shortcut.utf8().ptr()); |
| 1571 | } else { |
| 1572 | accesskit_node_clear_keyboard_shortcut(ae->node); |
| 1573 | } |
| 1574 | } |
| 1575 | |
| 1576 | void AccessibilityDriverAccessKit::accessibility_update_set_url(const RID &p_id, const String &p_url) { |
| 1577 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1578 | |
| 1579 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1580 | ERR_FAIL_NULL(ae); |
| 1581 | _ensure_node(p_id, ae); |
| 1582 | |
| 1583 | if (!p_url.is_empty()) { |
| 1584 | accesskit_node_set_url(ae->node, p_url.utf8().ptr()); |
| 1585 | } else { |
| 1586 | accesskit_node_clear_url(ae->node); |
| 1587 | } |
| 1588 | } |
| 1589 | |
| 1590 | void AccessibilityDriverAccessKit::accessibility_update_set_role_description(const RID &p_id, const String &p_description) { |
| 1591 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1592 | |
| 1593 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1594 | ERR_FAIL_NULL(ae); |
| 1595 | _ensure_node(p_id, ae); |
| 1596 | |
| 1597 | if (!p_description.is_empty()) { |
| 1598 | accesskit_node_set_role_description(ae->node, p_description.utf8().ptr()); |
| 1599 | } else { |
| 1600 | accesskit_node_clear_role_description(ae->node); |
| 1601 | } |
| 1602 | } |
| 1603 | |
| 1604 | void AccessibilityDriverAccessKit::accessibility_update_set_state_description(const RID &p_id, const String &p_description) { |
| 1605 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1606 | |
| 1607 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1608 | ERR_FAIL_NULL(ae); |
| 1609 | _ensure_node(p_id, ae); |
| 1610 | |
| 1611 | if (!p_description.is_empty()) { |
| 1612 | accesskit_node_set_state_description(ae->node, p_description.utf8().ptr()); |
| 1613 | } else { |
| 1614 | accesskit_node_clear_state_description(ae->node); |
| 1615 | } |
| 1616 | } |
| 1617 | |
| 1618 | void AccessibilityDriverAccessKit::accessibility_update_set_color_value(const RID &p_id, const Color &p_color) { |
| 1619 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1620 | |
| 1621 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1622 | ERR_FAIL_NULL(ae); |
| 1623 | _ensure_node(p_id, ae); |
| 1624 | |
| 1625 | accesskit_color color; |
| 1626 | color.red = p_color.get_r8(); |
| 1627 | color.blue = p_color.get_b8(); |
| 1628 | color.green = p_color.get_g8(); |
| 1629 | color.alpha = p_color.get_a8(); |
| 1630 | |
| 1631 | accesskit_node_set_color_value(ae->node, color); |
| 1632 | } |
| 1633 | |
| 1634 | void AccessibilityDriverAccessKit::accessibility_update_set_background_color(const RID &p_id, const Color &p_color) { |
| 1635 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1636 | |
| 1637 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1638 | ERR_FAIL_NULL(ae); |
| 1639 | _ensure_node(p_id, ae); |
| 1640 | |
| 1641 | accesskit_color color; |
| 1642 | color.red = p_color.get_r8(); |
| 1643 | color.blue = p_color.get_b8(); |
| 1644 | color.green = p_color.get_g8(); |
| 1645 | color.alpha = p_color.get_a8(); |
| 1646 | |
| 1647 | accesskit_node_set_background_color(ae->node, color); |
| 1648 | } |
| 1649 | |
| 1650 | void AccessibilityDriverAccessKit::accessibility_update_set_foreground_color(const RID &p_id, const Color &p_color) { |
| 1651 | ERR_FAIL_COND_MSG(!in_accessibility_update, "Accessibility updates are only allowed inside the NOTIFICATION_ACCESSIBILITY_UPDATE notification."); |
| 1652 | |
| 1653 | AccessibilityElement *ae = rid_owner.get_or_null(p_id); |
| 1654 | ERR_FAIL_NULL(ae); |
| 1655 | _ensure_node(p_id, ae); |
| 1656 | |
| 1657 | accesskit_color color; |
| 1658 | color.red = p_color.get_r8(); |
| 1659 | color.blue = p_color.get_b8(); |
| 1660 | color.green = p_color.get_g8(); |
| 1661 | color.alpha = p_color.get_a8(); |
| 1662 | |
| 1663 | accesskit_node_set_foreground_color(ae->node, color); |
| 1664 | } |
| 1665 | |
| 1666 | Error AccessibilityDriverAccessKit::init() { |
| 1667 | #ifdef ACCESSKIT_DYNAMIC |
| 1668 | #ifdef DEBUG_ENABLED |
| 1669 | int dylibloader_verbose = 1; |
| 1670 | #else |
| 1671 | int dylibloader_verbose = 0; |
| 1672 | #endif |
| 1673 | void *library_handle = nullptr; |
| 1674 | String path; |
| 1675 | String arch = Engine::get_singleton()->get_architecture_name(); |
| 1676 | #ifdef LINUXBSD_ENABLED |
| 1677 | path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("libaccesskit." + arch + ".so"); |
| 1678 | if (!FileAccess::exists(path)) { |
| 1679 | path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("../lib").path_join("libaccesskit." + arch + ".so"); |
| 1680 | } |
| 1681 | if (!FileAccess::exists(path)) { |
| 1682 | path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("libaccesskit.so"); |
| 1683 | } |
| 1684 | if (!FileAccess::exists(path)) { |
| 1685 | path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("../lib").path_join("libaccesskit.so"); |
| 1686 | } |
| 1687 | if (!FileAccess::exists(path)) { |
| 1688 | return ERR_CANT_CREATE; |
| 1689 | } |
| 1690 | #endif |
| 1691 | #ifdef MACOS_ENABLED |
| 1692 | path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("libaccesskit." + arch + ".dylib"); |
| 1693 | if (!FileAccess::exists(path)) { |
| 1694 | path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("../Frameworks").path_join("libaccesskit." + arch + ".dylib"); |
| 1695 | } |
| 1696 | if (!FileAccess::exists(path)) { |
| 1697 | path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("libaccesskit.dylib"); |
| 1698 | } |
| 1699 | if (!FileAccess::exists(path)) { |
| 1700 | path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("../Frameworks").path_join("libaccesskit.dylib"); |
| 1701 | } |
| 1702 | if (!FileAccess::exists(path)) { |
| 1703 | return ERR_CANT_CREATE; |
| 1704 | } |
| 1705 | #endif |
| 1706 | #ifdef WINDOWS_ENABLED |
| 1707 | path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("accesskit." + arch + ".dll"); |
| 1708 | if (!FileAccess::exists(path)) { |
| 1709 | path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("accesskit.dll"); |
| 1710 | } |
| 1711 | if (!FileAccess::exists(path)) { |
| 1712 | return ERR_CANT_CREATE; |
| 1713 | } |
| 1714 | #endif |
| 1715 | |
| 1716 | Error err = OS::get_singleton()->open_dynamic_library(path, library_handle); |
| 1717 | if (err == OK && initialize_libaccesskit(dylibloader_verbose, library_handle) == 0) { |
| 1718 | print_verbose("AccessKit loaded."); |
| 1719 | } else { |
| 1720 | return ERR_CANT_CREATE; |
| 1721 | } |
| 1722 | #endif |
| 1723 | #ifdef MACOS_ENABLED |
| 1724 | //accesskit_macos_add_focus_forwarder_to_window_class("GodotWindow"); |
| 1725 | #endif |
| 1726 | return OK; |
| 1727 | } |
| 1728 | |
| 1729 | AccessibilityDriverAccessKit::AccessibilityDriverAccessKit() { |
| 1730 | singleton = this; |
| 1731 | |
| 1732 | role_map[DisplayServer::AccessibilityRole::ROLE_UNKNOWN] = ACCESSKIT_ROLE_UNKNOWN; |
| 1733 | role_map[DisplayServer::AccessibilityRole::ROLE_DEFAULT_BUTTON] = ACCESSKIT_ROLE_DEFAULT_BUTTON; |
| 1734 | role_map[DisplayServer::AccessibilityRole::ROLE_AUDIO] = ACCESSKIT_ROLE_AUDIO; |
| 1735 | role_map[DisplayServer::AccessibilityRole::ROLE_VIDEO] = ACCESSKIT_ROLE_VIDEO; |
| 1736 | role_map[DisplayServer::AccessibilityRole::ROLE_STATIC_TEXT] = ACCESSKIT_ROLE_LABEL; |
| 1737 | role_map[DisplayServer::AccessibilityRole::ROLE_CONTAINER] = ACCESSKIT_ROLE_GENERIC_CONTAINER; |
| 1738 | role_map[DisplayServer::AccessibilityRole::ROLE_PANEL] = ACCESSKIT_ROLE_PANE; |
| 1739 | role_map[DisplayServer::AccessibilityRole::ROLE_BUTTON] = ACCESSKIT_ROLE_BUTTON; |
| 1740 | role_map[DisplayServer::AccessibilityRole::ROLE_LINK] = ACCESSKIT_ROLE_LINK; |
| 1741 | role_map[DisplayServer::AccessibilityRole::ROLE_CHECK_BOX] = ACCESSKIT_ROLE_CHECK_BOX; |
| 1742 | role_map[DisplayServer::AccessibilityRole::ROLE_RADIO_BUTTON] = ACCESSKIT_ROLE_RADIO_BUTTON; |
| 1743 | role_map[DisplayServer::AccessibilityRole::ROLE_CHECK_BUTTON] = ACCESSKIT_ROLE_SWITCH; |
| 1744 | role_map[DisplayServer::AccessibilityRole::ROLE_SCROLL_BAR] = ACCESSKIT_ROLE_SCROLL_BAR; |
| 1745 | role_map[DisplayServer::AccessibilityRole::ROLE_SCROLL_VIEW] = ACCESSKIT_ROLE_SCROLL_VIEW; |
| 1746 | role_map[DisplayServer::AccessibilityRole::ROLE_SPLITTER] = ACCESSKIT_ROLE_SPLITTER; |
| 1747 | role_map[DisplayServer::AccessibilityRole::ROLE_SLIDER] = ACCESSKIT_ROLE_SLIDER; |
| 1748 | role_map[DisplayServer::AccessibilityRole::ROLE_SPIN_BUTTON] = ACCESSKIT_ROLE_SPIN_BUTTON; |
| 1749 | role_map[DisplayServer::AccessibilityRole::ROLE_PROGRESS_INDICATOR] = ACCESSKIT_ROLE_PROGRESS_INDICATOR; |
| 1750 | role_map[DisplayServer::AccessibilityRole::ROLE_TEXT_FIELD] = ACCESSKIT_ROLE_TEXT_INPUT; |
| 1751 | role_map[DisplayServer::AccessibilityRole::ROLE_MULTILINE_TEXT_FIELD] = ACCESSKIT_ROLE_MULTILINE_TEXT_INPUT; |
| 1752 | role_map[DisplayServer::AccessibilityRole::ROLE_COLOR_PICKER] = ACCESSKIT_ROLE_COLOR_WELL; |
| 1753 | role_map[DisplayServer::AccessibilityRole::ROLE_TABLE] = ACCESSKIT_ROLE_TABLE; |
| 1754 | role_map[DisplayServer::AccessibilityRole::ROLE_CELL] = ACCESSKIT_ROLE_CELL; |
| 1755 | role_map[DisplayServer::AccessibilityRole::ROLE_ROW] = ACCESSKIT_ROLE_ROW; |
| 1756 | role_map[DisplayServer::AccessibilityRole::ROLE_ROW_GROUP] = ACCESSKIT_ROLE_ROW_GROUP; |
| 1757 | role_map[DisplayServer::AccessibilityRole::ROLE_ROW_HEADER] = ACCESSKIT_ROLE_ROW_HEADER; |
| 1758 | role_map[DisplayServer::AccessibilityRole::ROLE_COLUMN_HEADER] = ACCESSKIT_ROLE_COLUMN_HEADER; |
| 1759 | role_map[DisplayServer::AccessibilityRole::ROLE_TREE] = ACCESSKIT_ROLE_TREE; |
| 1760 | role_map[DisplayServer::AccessibilityRole::ROLE_TREE_ITEM] = ACCESSKIT_ROLE_TREE_ITEM; |
| 1761 | role_map[DisplayServer::AccessibilityRole::ROLE_LIST] = ACCESSKIT_ROLE_LIST; |
| 1762 | role_map[DisplayServer::AccessibilityRole::ROLE_LIST_ITEM] = ACCESSKIT_ROLE_LIST_ITEM; |
| 1763 | role_map[DisplayServer::AccessibilityRole::ROLE_LIST_BOX] = ACCESSKIT_ROLE_LIST_BOX; |
| 1764 | role_map[DisplayServer::AccessibilityRole::ROLE_LIST_BOX_OPTION] = ACCESSKIT_ROLE_LIST_BOX_OPTION; |
| 1765 | role_map[DisplayServer::AccessibilityRole::ROLE_TAB_BAR] = ACCESSKIT_ROLE_TAB_LIST; |
| 1766 | role_map[DisplayServer::AccessibilityRole::ROLE_TAB] = ACCESSKIT_ROLE_TAB; |
| 1767 | role_map[DisplayServer::AccessibilityRole::ROLE_TAB_PANEL] = ACCESSKIT_ROLE_TAB_PANEL; |
| 1768 | role_map[DisplayServer::AccessibilityRole::ROLE_MENU_BAR] = ACCESSKIT_ROLE_MENU_BAR; |
| 1769 | role_map[DisplayServer::AccessibilityRole::ROLE_MENU] = ACCESSKIT_ROLE_MENU; |
| 1770 | role_map[DisplayServer::AccessibilityRole::ROLE_MENU_ITEM] = ACCESSKIT_ROLE_MENU_ITEM; |
| 1771 | role_map[DisplayServer::AccessibilityRole::ROLE_MENU_ITEM_CHECK_BOX] = ACCESSKIT_ROLE_MENU_ITEM_CHECK_BOX; |
| 1772 | role_map[DisplayServer::AccessibilityRole::ROLE_MENU_ITEM_RADIO] = ACCESSKIT_ROLE_MENU_ITEM_RADIO; |
| 1773 | role_map[DisplayServer::AccessibilityRole::ROLE_IMAGE] = ACCESSKIT_ROLE_IMAGE; |
| 1774 | role_map[DisplayServer::AccessibilityRole::ROLE_WINDOW] = ACCESSKIT_ROLE_WINDOW; |
| 1775 | role_map[DisplayServer::AccessibilityRole::ROLE_TITLE_BAR] = ACCESSKIT_ROLE_TITLE_BAR; |
| 1776 | role_map[DisplayServer::AccessibilityRole::ROLE_DIALOG] = ACCESSKIT_ROLE_DIALOG; |
| 1777 | role_map[DisplayServer::AccessibilityRole::ROLE_TOOLTIP] = ACCESSKIT_ROLE_TOOLTIP; |
| 1778 | |
| 1779 | action_map[DisplayServer::AccessibilityAction::ACTION_CLICK] = ACCESSKIT_ACTION_CLICK; |
| 1780 | action_map[DisplayServer::AccessibilityAction::ACTION_FOCUS] = ACCESSKIT_ACTION_FOCUS; |
| 1781 | action_map[DisplayServer::AccessibilityAction::ACTION_BLUR] = ACCESSKIT_ACTION_BLUR; |
| 1782 | action_map[DisplayServer::AccessibilityAction::ACTION_COLLAPSE] = ACCESSKIT_ACTION_COLLAPSE; |
| 1783 | action_map[DisplayServer::AccessibilityAction::ACTION_EXPAND] = ACCESSKIT_ACTION_EXPAND; |
| 1784 | action_map[DisplayServer::AccessibilityAction::ACTION_DECREMENT] = ACCESSKIT_ACTION_DECREMENT; |
| 1785 | action_map[DisplayServer::AccessibilityAction::ACTION_INCREMENT] = ACCESSKIT_ACTION_INCREMENT; |
| 1786 | action_map[DisplayServer::AccessibilityAction::ACTION_HIDE_TOOLTIP] = ACCESSKIT_ACTION_HIDE_TOOLTIP; |
| 1787 | action_map[DisplayServer::AccessibilityAction::ACTION_SHOW_TOOLTIP] = ACCESSKIT_ACTION_SHOW_TOOLTIP; |
| 1788 | //action_map[DisplayServer::AccessibilityAction::ACTION_INVALIDATE_TREE] = ACCESSKIT_ACTION_INVALIDATE_TREE; |
| 1789 | //action_map[DisplayServer::AccessibilityAction::ACTION_LOAD_INLINE_TEXT_BOXES] = ACCESSKIT_ACTION_LOAD_INLINE_TEXT_BOXES; |
| 1790 | action_map[DisplayServer::AccessibilityAction::ACTION_SET_TEXT_SELECTION] = ACCESSKIT_ACTION_SET_TEXT_SELECTION; |
| 1791 | action_map[DisplayServer::AccessibilityAction::ACTION_REPLACE_SELECTED_TEXT] = ACCESSKIT_ACTION_REPLACE_SELECTED_TEXT; |
| 1792 | action_map[DisplayServer::AccessibilityAction::ACTION_SCROLL_BACKWARD] = ACCESSKIT_ACTION_SCROLL_UP; |
| 1793 | action_map[DisplayServer::AccessibilityAction::ACTION_SCROLL_DOWN] = ACCESSKIT_ACTION_SCROLL_DOWN; |
| 1794 | action_map[DisplayServer::AccessibilityAction::ACTION_SCROLL_FORWARD] = ACCESSKIT_ACTION_SCROLL_DOWN; |
| 1795 | action_map[DisplayServer::AccessibilityAction::ACTION_SCROLL_LEFT] = ACCESSKIT_ACTION_SCROLL_LEFT; |
| 1796 | action_map[DisplayServer::AccessibilityAction::ACTION_SCROLL_RIGHT] = ACCESSKIT_ACTION_SCROLL_RIGHT; |
| 1797 | action_map[DisplayServer::AccessibilityAction::ACTION_SCROLL_UP] = ACCESSKIT_ACTION_SCROLL_UP; |
| 1798 | action_map[DisplayServer::AccessibilityAction::ACTION_SCROLL_INTO_VIEW] = ACCESSKIT_ACTION_SCROLL_INTO_VIEW; |
| 1799 | action_map[DisplayServer::AccessibilityAction::ACTION_SCROLL_TO_POINT] = ACCESSKIT_ACTION_SCROLL_TO_POINT; |
| 1800 | action_map[DisplayServer::AccessibilityAction::ACTION_SET_SCROLL_OFFSET] = ACCESSKIT_ACTION_SET_SCROLL_OFFSET; |
| 1801 | //action_map[DisplayServer::AccessibilityAction::ACTION_SET_SEQUENTIAL_FOCUS_NAVIGATION_STARTING_POINT] = ACCESSKIT_ACTION_SET_SEQUENTIAL_FOCUS_NAVIGATION_STARTING_POINT; |
| 1802 | action_map[DisplayServer::AccessibilityAction::ACTION_SET_VALUE] = ACCESSKIT_ACTION_SET_VALUE; |
| 1803 | action_map[DisplayServer::AccessibilityAction::ACTION_SHOW_CONTEXT_MENU] = ACCESSKIT_ACTION_SHOW_CONTEXT_MENU; |
| 1804 | action_map[DisplayServer::AccessibilityAction::ACTION_CUSTOM] = ACCESSKIT_ACTION_CUSTOM_ACTION; |
| 1805 | } |
| 1806 | |
| 1807 | AccessibilityDriverAccessKit::~AccessibilityDriverAccessKit() { |
| 1808 | singleton = nullptr; |
| 1809 | } |
| 1810 | |
| 1811 | #endif // ACCESSKIT_ENABLED |