Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/drivers/accesskit/accessibility_server_accesskit.h
45997 views
1
/**************************************************************************/
2
/* accessibility_server_accesskit.h */
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
#pragma once
32
33
#ifdef ACCESSKIT_ENABLED
34
35
#include "core/templates/rid_owner.h"
36
#include "servers/display/accessibility_server.h"
37
38
#include <accesskit.h>
39
40
class AccessibilityServerAccessKit : public AccessibilityServer {
41
GDSOFTCLASS(AccessibilityServerAccessKit, AccessibilityServer);
42
43
static AccessibilityServer *create_func(Error &r_error);
44
45
struct AccessibilityElement {
46
HashMap<accesskit_action, Callable> actions;
47
48
DisplayServerEnums::WindowID window_id = DisplayServerEnums::INVALID_WINDOW_ID;
49
RID parent;
50
LocalVector<RID> children;
51
Vector3i run;
52
Variant meta;
53
String name;
54
String name_extra_info;
55
Variant value;
56
int64_t flags = 0;
57
58
accesskit_role role = ACCESSKIT_ROLE_UNKNOWN;
59
accesskit_node *node = nullptr;
60
};
61
mutable RID_PtrOwner<AccessibilityElement> rid_owner;
62
63
struct WindowData {
64
// Adapter.
65
#ifdef WINDOWS_ENABLED
66
accesskit_windows_subclassing_adapter *adapter = nullptr;
67
#endif
68
#ifdef MACOS_ENABLED
69
accesskit_macos_subclassing_adapter *adapter = nullptr;
70
#endif
71
#ifdef LINUXBSD_ENABLED
72
accesskit_unix_adapter *adapter = nullptr;
73
#endif
74
75
RID root_id;
76
bool initial_update_completed = false;
77
HashSet<RID> update;
78
Callable activate;
79
Callable deactivate;
80
bool activated = false;
81
};
82
83
RID focus;
84
85
HashMap<DisplayServerEnums::WindowID, WindowData> windows;
86
87
HashMap<AccessibilityServerEnums::AccessibilityRole, accesskit_role> role_map;
88
HashMap<AccessibilityServerEnums::AccessibilityAction, accesskit_action> action_map;
89
90
_FORCE_INLINE_ accesskit_role _accessibility_role(AccessibilityServerEnums::AccessibilityRole p_role) const;
91
_FORCE_INLINE_ accesskit_action _accessibility_action(AccessibilityServerEnums::AccessibilityAction p_action) const;
92
93
void _free_recursive(WindowData *p_wd, const RID &p_id);
94
_FORCE_INLINE_ void _ensure_node(const RID &p_id, AccessibilityElement *p_ae);
95
96
static void _accessibility_action_callback(struct accesskit_action_request *p_request, void *p_user_data);
97
static accesskit_tree_update *_accessibility_initial_tree_update_callback(void *p_user_data);
98
static void _accessibility_deactivation_callback(void *p_user_data);
99
static accesskit_tree_update *_accessibility_build_tree_update(void *p_user_data);
100
101
bool in_accessibility_update = false;
102
Callable update_cb;
103
104
public:
105
bool is_supported() const override { return true; }
106
107
bool window_create(DisplayServerEnums::WindowID p_window_id, void *p_handle) override;
108
void window_destroy(DisplayServerEnums::WindowID p_window_id) override;
109
110
RID create_element(DisplayServerEnums::WindowID p_window_id, AccessibilityServerEnums::AccessibilityRole p_role) override;
111
RID create_sub_element(const RID &p_parent_rid, AccessibilityServerEnums::AccessibilityRole p_role, int p_insert_pos = -1) override;
112
virtual RID create_sub_text_edit_elements(const RID &p_parent_rid, const RID &p_shaped_text, float p_min_height, int p_insert_pos = -1, bool p_is_last_line = false) override;
113
bool has_element(const RID &p_id) const override;
114
void free_element(const RID &p_id) override;
115
116
void element_set_meta(const RID &p_id, const Variant &p_meta) override;
117
Variant element_get_meta(const RID &p_id) const override;
118
119
void update_if_active(const Callable &p_callable) override;
120
121
void update_set_focus(const RID &p_id) override;
122
RID get_window_root(DisplayServerEnums::WindowID p_window_id) const override;
123
124
void set_window_rect(DisplayServerEnums::WindowID p_window_id, const Rect2 &p_rect_out, const Rect2 &p_rect_in) override;
125
void set_window_focused(DisplayServerEnums::WindowID p_window_id, bool p_focused) override;
126
void set_window_callbacks(DisplayServerEnums::WindowID p_window_id, const Callable &p_activate_callable, const Callable &p_deativate_callable) override;
127
void window_activation_completed(DisplayServerEnums::WindowID p_window_id) override;
128
void window_deactivation_completed(DisplayServerEnums::WindowID p_window_id) override;
129
130
void update_set_role(const RID &p_id, AccessibilityServerEnums::AccessibilityRole p_role) override;
131
void update_set_name(const RID &p_id, const String &p_name) override;
132
void update_set_braille_label(const RID &p_id, const String &p_name) override;
133
void update_set_braille_role_description(const RID &p_id, const String &p_description) override;
134
void update_set_extra_info(const RID &p_id, const String &p_name_extra_info) override;
135
void update_set_description(const RID &p_id, const String &p_description) override;
136
void update_set_value(const RID &p_id, const String &p_value) override;
137
void update_set_tooltip(const RID &p_id, const String &p_tooltip) override;
138
void update_set_bounds(const RID &p_id, const Rect2 &p_rect) override;
139
void update_set_transform(const RID &p_id, const Transform2D &p_transform) override;
140
void update_add_child(const RID &p_id, const RID &p_child_id) override;
141
void update_add_related_controls(const RID &p_id, const RID &p_related_id) override;
142
void update_add_related_details(const RID &p_id, const RID &p_related_id) override;
143
void update_add_related_described_by(const RID &p_id, const RID &p_related_id) override;
144
void update_add_related_flow_to(const RID &p_id, const RID &p_related_id) override;
145
void update_add_related_labeled_by(const RID &p_id, const RID &p_related_id) override;
146
void update_add_related_radio_group(const RID &p_id, const RID &p_related_id) override;
147
void update_set_active_descendant(const RID &p_id, const RID &p_other_id) override;
148
void update_set_next_on_line(const RID &p_id, const RID &p_other_id) override;
149
void update_set_previous_on_line(const RID &p_id, const RID &p_other_id) override;
150
void update_set_member_of(const RID &p_id, const RID &p_group_id) override;
151
void update_set_in_page_link_target(const RID &p_id, const RID &p_other_id) override;
152
void update_set_error_message(const RID &p_id, const RID &p_other_id) override;
153
void update_set_live(const RID &p_id, AccessibilityServerEnums::AccessibilityLiveMode p_live) override;
154
void update_add_action(const RID &p_id, AccessibilityServerEnums::AccessibilityAction p_action, const Callable &p_callable) override;
155
void update_add_custom_action(const RID &p_id, int p_action_id, const String &p_action_description) override;
156
void update_set_table_row_count(const RID &p_id, int p_count) override;
157
void update_set_table_column_count(const RID &p_id, int p_count) override;
158
void update_set_table_row_index(const RID &p_id, int p_index) override;
159
void update_set_table_column_index(const RID &p_id, int p_index) override;
160
void update_set_table_cell_position(const RID &p_id, int p_row_index, int p_column_index) override;
161
void update_set_table_cell_span(const RID &p_id, int p_row_span, int p_column_span) override;
162
void update_set_list_item_count(const RID &p_id, int p_size) override;
163
void update_set_list_item_index(const RID &p_id, int p_index) override;
164
void update_set_list_item_level(const RID &p_id, int p_level) override;
165
void update_set_list_item_selected(const RID &p_id, bool p_selected) override;
166
void update_set_list_item_expanded(const RID &p_id, bool p_expanded) override;
167
void update_set_popup_type(const RID &p_id, AccessibilityServerEnums::AccessibilityPopupType p_popup) override;
168
void update_set_checked(const RID &p_id, bool p_checekd) override;
169
void update_set_num_value(const RID &p_id, double p_position) override;
170
void update_set_num_range(const RID &p_id, double p_min, double p_max) override;
171
void update_set_num_step(const RID &p_id, double p_step) override;
172
void update_set_num_jump(const RID &p_id, double p_jump) override;
173
void update_set_scroll_x(const RID &p_id, double p_position) override;
174
void update_set_scroll_x_range(const RID &p_id, double p_min, double p_max) override;
175
void update_set_scroll_y(const RID &p_id, double p_position) override;
176
void update_set_scroll_y_range(const RID &p_id, double p_min, double p_max) override;
177
void update_set_text_decorations(const RID &p_id, bool p_underline, bool p_strikethrough, bool p_overline, const Color &p_color) override;
178
void update_set_text_align(const RID &p_id, HorizontalAlignment p_align) override;
179
void 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) override;
180
void update_set_flag(const RID &p_id, AccessibilityServerEnums::AccessibilityFlags p_flag, bool p_value) override;
181
void update_set_classname(const RID &p_id, const String &p_classname) override;
182
void update_set_placeholder(const RID &p_id, const String &p_placeholder) override;
183
void update_set_language(const RID &p_id, const String &p_language) override;
184
void update_set_text_orientation(const RID &p_id, bool p_vertical) override;
185
void update_set_list_orientation(const RID &p_id, bool p_vertical) override;
186
void update_set_shortcut(const RID &p_id, const String &p_shortcut) override;
187
void update_set_url(const RID &p_id, const String &p_url) override;
188
void update_set_role_description(const RID &p_id, const String &p_description) override;
189
void update_set_state_description(const RID &p_id, const String &p_description) override;
190
void update_set_color_value(const RID &p_id, const Color &p_color) override;
191
void update_set_background_color(const RID &p_id, const Color &p_color) override;
192
void update_set_foreground_color(const RID &p_id, const Color &p_color) override;
193
194
static void register_create_func();
195
196
AccessibilityServerAccessKit();
197
~AccessibilityServerAccessKit();
198
};
199
200
#endif // ACCESSKIT_ENABLED
201
202