| Flutter Linux Embedder |

fl_accessible_node.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "flutter/shell/platform/linux/fl_accessible_node.h"
6 #include "flutter/shell/platform/linux/fl_engine_private.h"
7
8 // Maps Flutter semantics actions to ATK actions.
9 typedef struct {
10 FlutterSemanticsAction action;
11 const gchar* name;
12 } ActionData;
13 static ActionData action_mapping[] = {
14 {kFlutterSemanticsActionTap, "Tap"},
15 {kFlutterSemanticsActionLongPress, "LongPress"},
16 {kFlutterSemanticsActionScrollLeft, "ScrollLeft"},
17 {kFlutterSemanticsActionScrollRight, "ScrollRight"},
18 {kFlutterSemanticsActionScrollUp, "ScrollUp"},
19 {kFlutterSemanticsActionScrollDown, "ScrollDown"},
20 {kFlutterSemanticsActionIncrease, "Increase"},
21 {kFlutterSemanticsActionDecrease, "Decrease"},
22 {kFlutterSemanticsActionShowOnScreen, "ShowOnScreen"},
23 {kFlutterSemanticsActionMoveCursorForwardByCharacter,
24 "MoveCursorForwardByCharacter"},
25 {kFlutterSemanticsActionMoveCursorBackwardByCharacter,
26 "MoveCursorBackwardByCharacter"},
27 {kFlutterSemanticsActionCopy, "Copy"},
28 {kFlutterSemanticsActionCut, "Cut"},
29 {kFlutterSemanticsActionPaste, "Paste"},
30 {kFlutterSemanticsActionDidGainAccessibilityFocus,
31 "DidGainAccessibilityFocus"},
32 {kFlutterSemanticsActionDidLoseAccessibilityFocus,
33 "DidLoseAccessibilityFocus"},
34 {kFlutterSemanticsActionCustomAction, "CustomAction"},
35 {kFlutterSemanticsActionDismiss, "Dismiss"},
36 {kFlutterSemanticsActionMoveCursorForwardByWord, "MoveCursorForwardByWord"},
37 {kFlutterSemanticsActionMoveCursorBackwardByWord,
38 "MoveCursorBackwardByWord"},
39 {kFlutterSemanticsActionFocus, "Focus"},
40 {static_cast<FlutterSemanticsAction>(0), nullptr}};
41
42 struct FlAccessibleNodePrivate {
43 AtkObject parent_instance;
44
45 // Weak reference to the engine this node is created for.
46 FlEngine* engine;
47
48 /// The unique identifier of the view to which this node belongs.
49 FlutterViewId view_id;
50
51 // Weak reference to the parent node of this one or %NULL.
52 AtkObject* parent;
53
54 int32_t node_id;
55 gchar* name;
56 gint index;
57 gint x, y, width, height;
58 GPtrArray* actions;
59 gsize actions_length;
60 GPtrArray* children;
61 FlutterSemanticsFlags flags;
62 };
63
64 enum { PROP_0, PROP_ENGINE, PROP_VIEW_ID, PROP_ID, PROP_LAST };
65
66 #define FL_ACCESSIBLE_NODE_GET_PRIVATE(node) \
67 ((FlAccessibleNodePrivate*)fl_accessible_node_get_instance_private( \
68 FL_ACCESSIBLE_NODE(node)))
69
70 static void fl_accessible_node_component_interface_init(
71 AtkComponentIface* iface);
72 static void fl_accessible_node_action_interface_init(AtkActionIface* iface);
73
74 G_DEFINE_TYPE_WITH_CODE(
75 FlAccessibleNode,
76 fl_accessible_node,
77 ATK_TYPE_OBJECT,
78 G_ADD_PRIVATE(FlAccessibleNode)
79 G_IMPLEMENT_INTERFACE(ATK_TYPE_COMPONENT,
80 fl_accessible_node_component_interface_init)
81 G_IMPLEMENT_INTERFACE(ATK_TYPE_ACTION,
82 fl_accessible_node_action_interface_init))
83
84 // Returns TRUE if [action] is set in [actions].
85 static gboolean has_action(FlutterSemanticsAction actions,
86 FlutterSemanticsAction action) {
87 return (actions & action) != 0;
88 }
89
90 // Gets the nth action.
91 static ActionData* get_action(FlAccessibleNodePrivate* priv, gint index) {
92 if (index < 0 || static_cast<guint>(index) >= priv->actions->len) {
93 return nullptr;
94 }
95 return static_cast<ActionData*>(g_ptr_array_index(priv->actions, index));
96 }
97
98 // Checks if [object] is in [children].
99 static gboolean has_child(GPtrArray* children, AtkObject* object) {
100 for (guint i = 0; i < children->len; i++) {
101 if (g_ptr_array_index(children, i) == object) {
102 return TRUE;
103 }
104 }
105
106 return FALSE;
107 }
108
109 static void fl_accessible_node_set_property(GObject* object,
110 guint prop_id,
111 const GValue* value,
112 GParamSpec* pspec) {
113 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(object);
114 switch (prop_id) {
115 case PROP_ENGINE:
116 g_assert(priv->engine == nullptr);
117 priv->engine = FL_ENGINE(g_value_get_object(value));
118 g_object_add_weak_pointer(object,
119 reinterpret_cast<gpointer*>(&priv->engine));
120 break;
121 case PROP_VIEW_ID:
122 priv->view_id = g_value_get_int64(value);
123 break;
124 case PROP_ID:
125 priv->node_id = g_value_get_int(value);
126 break;
127 default:
128 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
129 break;
130 }
131 }
132
133 static void fl_accessible_node_dispose(GObject* object) {
134 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(object);
135
136 if (priv->engine != nullptr) {
137 g_object_remove_weak_pointer(object,
138 reinterpret_cast<gpointer*>(&(priv->engine)));
139 priv->engine = nullptr;
140 }
141 if (priv->parent != nullptr) {
142 g_object_remove_weak_pointer(object,
143 reinterpret_cast<gpointer*>(&(priv->parent)));
144 priv->parent = nullptr;
145 }
146 g_clear_pointer(&priv->name, g_free);
147 g_clear_pointer(&priv->actions, g_ptr_array_unref);
148 g_clear_pointer(&priv->children, g_ptr_array_unref);
149
150 G_OBJECT_CLASS(fl_accessible_node_parent_class)->dispose(object);
151 }
152
153 // Implements AtkObject::get_name.
154 static const gchar* fl_accessible_node_get_name(AtkObject* accessible) {
155 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(accessible);
156 return priv->name;
157 }
158
159 // Implements AtkObject::get_parent.
160 static AtkObject* fl_accessible_node_get_parent(AtkObject* accessible) {
161 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(accessible);
162 return priv->parent;
163 }
164
165 // Implements AtkObject::get_index_in_parent.
166 static gint fl_accessible_node_get_index_in_parent(AtkObject* accessible) {
167 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(accessible);
168 return priv->index;
169 }
170
171 // Implements AtkObject::get_n_children.
172 static gint fl_accessible_node_get_n_children(AtkObject* accessible) {
173 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(accessible);
174 return priv->children->len;
175 }
176
177 // Implements AtkObject::ref_child.
178 static AtkObject* fl_accessible_node_ref_child(AtkObject* accessible, gint i) {
179 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(accessible);
180
181 if (i < 0 || static_cast<guint>(i) >= priv->children->len) {
182 return nullptr;
183 }
184
185 return ATK_OBJECT(g_object_ref(g_ptr_array_index(priv->children, i)));
186 }
187
188 // Implements AtkObject::get_role.
189 static AtkRole fl_accessible_node_get_role(AtkObject* accessible) {
190 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(accessible);
191 if (priv->flags.is_button) {
192 return ATK_ROLE_PUSH_BUTTON;
193 }
194 if (priv->flags.is_in_mutually_exclusive_group &&
195 priv->flags.is_checked != kFlutterCheckStateNone) {
196 return ATK_ROLE_RADIO_BUTTON;
197 }
198 if (priv->flags.is_checked != kFlutterCheckStateNone) {
199 return ATK_ROLE_CHECK_BOX;
200 }
201 if (priv->flags.is_toggled != kFlutterTristateNone) {
202 return ATK_ROLE_TOGGLE_BUTTON;
203 }
204 if (priv->flags.is_slider) {
205 return ATK_ROLE_SLIDER;
206 }
207 if (priv->flags.is_text_field && priv->flags.is_obscured) {
208 return ATK_ROLE_PASSWORD_TEXT;
209 }
210 if (priv->flags.is_text_field) {
211 return ATK_ROLE_TEXT;
212 }
213 if (priv->flags.is_header) {
214 return ATK_ROLE_HEADER;
215 }
216 if (priv->flags.is_link) {
217 return ATK_ROLE_LINK;
218 }
219 if (priv->flags.is_image) {
220 return ATK_ROLE_IMAGE;
221 }
222
223 return ATK_ROLE_PANEL;
224 }
225
226 // Implements AtkObject::ref_state_set.
227 static AtkStateSet* fl_accessible_node_ref_state_set(AtkObject* accessible) {
228 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(accessible);
229
230 AtkStateSet* state_set = atk_state_set_new();
231
232 if (!priv->flags.is_obscured) {
233 atk_state_set_add_state(state_set, ATK_STATE_SHOWING);
234 }
235 if (!priv->flags.is_hidden) {
236 atk_state_set_add_state(state_set, ATK_STATE_VISIBLE);
237 }
238 if (priv->flags.is_checked != kFlutterCheckStateNone) {
239 atk_state_set_add_state(state_set, ATK_STATE_CHECKABLE);
240 }
241 if (priv->flags.is_focused != kFlutterTristateNone) {
242 atk_state_set_add_state(state_set, ATK_STATE_FOCUSABLE);
243 }
244 if (priv->flags.is_focused == kFlutterTristateTrue) {
245 atk_state_set_add_state(state_set, ATK_STATE_FOCUSED);
246 }
247 if (priv->flags.is_checked || priv->flags.is_toggled) {
248 atk_state_set_add_state(state_set, ATK_STATE_CHECKED);
249 }
250 if (priv->flags.is_selected) {
251 atk_state_set_add_state(state_set, ATK_STATE_SELECTED);
252 }
253 if (priv->flags.is_enabled == kFlutterTristateTrue) {
254 atk_state_set_add_state(state_set, ATK_STATE_ENABLED);
255 atk_state_set_add_state(state_set, ATK_STATE_SENSITIVE);
256 }
257 if (priv->flags.is_read_only) {
258 atk_state_set_add_state(state_set, ATK_STATE_READ_ONLY);
259 }
260 if (priv->flags.is_text_field) {
261 atk_state_set_add_state(state_set, ATK_STATE_EDITABLE);
262 }
263
264 return state_set;
265 }
266
267 // Implements AtkComponent::get_extents.
268 static void fl_accessible_node_get_extents(AtkComponent* component,
269 gint* x,
270 gint* y,
271 gint* width,
272 gint* height,
273 AtkCoordType coord_type) {
274 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(component);
275
276 *x = 0;
277 *y = 0;
278 if (priv->parent != nullptr) {
279 atk_component_get_extents(ATK_COMPONENT(priv->parent), x, y, nullptr,
280 nullptr, coord_type);
281 }
282
283 *x += priv->x;
284 *y += priv->y;
285 *width = priv->width;
286 *height = priv->height;
287 }
288
289 // Implements AtkComponent::get_layer.
290 static AtkLayer fl_accessible_node_get_layer(AtkComponent* component) {
291 return ATK_LAYER_WIDGET;
292 }
293
294 // Implements AtkAction::do_action.
295 static gboolean fl_accessible_node_do_action(AtkAction* action, gint i) {
296 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(action);
297
298 if (priv->engine == nullptr) {
299 return FALSE;
300 }
301
302 ActionData* data = get_action(priv, i);
303 if (data == nullptr) {
304 return FALSE;
305 }
306
307 fl_accessible_node_perform_action(FL_ACCESSIBLE_NODE(action), data->action,
308 nullptr);
309 return TRUE;
310 }
311
312 // Implements AtkAction::get_n_actions.
313 static gint fl_accessible_node_get_n_actions(AtkAction* action) {
314 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(action);
315 return priv->actions->len;
316 }
317
318 // Implements AtkAction::get_name.
319 static const gchar* fl_accessible_node_get_name(AtkAction* action, gint i) {
320 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(action);
321
322 ActionData* data = get_action(priv, i);
323 if (data == nullptr) {
324 return nullptr;
325 }
326
327 return data->name;
328 }
329
330 // Implements FlAccessibleNode::set_name.
331 static void fl_accessible_node_set_name_impl(FlAccessibleNode* self,
332 const gchar* name) {
333 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(self);
334 g_free(priv->name);
335 priv->name = g_strdup(name);
336 }
337
338 // Implements FlAccessibleNode::set_extents.
339 static void fl_accessible_node_set_extents_impl(FlAccessibleNode* self,
340 gint x,
341 gint y,
342 gint width,
343 gint height) {
344 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(self);
345 priv->x = x;
346 priv->y = y;
347 priv->width = width;
348 priv->height = height;
349 }
350
351 // Check two boolean flags are different, in a way that handles true values
352 // being different (e.g. 1 and 2).
353 static bool flag_changed(bool old_flag, bool new_flag) {
354 return !old_flag != !new_flag;
355 }
356
357 // Implements FlAccessibleNode::set_flags.
358 static void fl_accessible_node_set_flags_impl(FlAccessibleNode* self,
359 FlutterSemanticsFlags* flags) {
360 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(self);
361
362 FlutterSemanticsFlags old_flags = priv->flags;
363 priv->flags = *flags;
364
365 if (flag_changed(old_flags.is_obscured, flags->is_obscured)) {
366 atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_SHOWING,
367 !flags->is_obscured);
368 }
369 if (flag_changed(old_flags.is_hidden, flags->is_hidden)) {
370 atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_VISIBLE,
371 !flags->is_hidden);
372 }
373 bool was_checkable = old_flags.is_checked != kFlutterCheckStateNone;
374 bool is_checkable = flags->is_checked != kFlutterCheckStateNone;
375 if (flag_changed(was_checkable, is_checkable)) {
376 atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_CHECKABLE,
377 is_checkable);
378 }
379 if (flag_changed(old_flags.is_focused, flags->is_focused)) {
380 atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_FOCUSABLE,
381 flags->is_focused != kFlutterTristateNone);
382 }
383 if (flag_changed(old_flags.is_focused, flags->is_focused)) {
384 atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_FOCUSED,
385 flags->is_focused == kFlutterTristateTrue);
386 }
387 bool old_is_checked = old_flags.is_checked || old_flags.is_toggled;
388 bool is_checked = flags->is_checked || flags->is_toggled;
389 if (flag_changed(old_is_checked, is_checked)) {
390 atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_CHECKED,
391 is_checked);
392 }
393 if (flag_changed(old_flags.is_selected, flags->is_selected)) {
394 atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_SELECTED,
395 flags->is_selected);
396 }
397 if (flag_changed(old_flags.is_enabled, flags->is_enabled)) {
398 atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_ENABLED,
399 flags->is_enabled);
400 atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_SENSITIVE,
401 flags->is_enabled);
402 }
403 if (flag_changed(old_flags.is_enabled, flags->is_enabled)) {
404 atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_ENABLED,
405 flags->is_enabled);
406 }
407 if (flag_changed(old_flags.is_enabled, flags->is_enabled)) {
408 atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_ENABLED,
409 flags->is_enabled);
410 }
411 if (flag_changed(old_flags.is_read_only, flags->is_read_only)) {
412 atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_READ_ONLY,
413 flags->is_read_only);
414 }
415 if (flag_changed(old_flags.is_text_field, flags->is_text_field)) {
416 atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_EDITABLE,
417 flags->is_text_field);
418 }
419 }
420
421 // Implements FlAccessibleNode::set_actions.
422 static void fl_accessible_node_set_actions_impl(
423 FlAccessibleNode* self,
424 FlutterSemanticsAction actions) {
425 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(self);
426
427 // NOTE(robert-ancell): It appears that AtkAction doesn't have a method of
428 // notifying that actions have changed, and even if it did an ATK client
429 // might access the old IDs before checking for new ones. Keep an eye
430 // out for a case where Flutter changes the actions on an item and see
431 // if we can resolve this in another way.
432 g_ptr_array_remove_range(priv->actions, 0, priv->actions->len);
433 for (int i = 0; action_mapping[i].name != nullptr; i++) {
434 if (has_action(actions, action_mapping[i].action)) {
435 g_ptr_array_add(priv->actions, &action_mapping[i]);
436 }
437 }
438 }
439
440 // Implements FlAccessibleNode::set_value.
441 static void fl_accessible_node_set_value_impl(FlAccessibleNode* self,
442 const gchar* value) {}
443
444 // Implements FlAccessibleNode::set_text_selection.
445 static void fl_accessible_node_set_text_selection_impl(FlAccessibleNode* self,
446 gint base,
447 gint extent) {}
448
449 // Implements FlAccessibleNode::set_text_direction.
450 static void fl_accessible_node_set_text_direction_impl(
451 FlAccessibleNode* self,
452 FlutterTextDirection direction) {}
453
454 // Implements FlAccessibleNode::perform_action.
455 static void fl_accessible_node_perform_action_impl(
456 FlAccessibleNode* self,
457 FlutterSemanticsAction action,
458 GBytes* data) {
459 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(self);
460 fl_engine_dispatch_semantics_action(priv->engine, priv->view_id,
461 priv->node_id, action, data);
462 }
463
464 static void fl_accessible_node_class_init(FlAccessibleNodeClass* klass) {
465 G_OBJECT_CLASS(klass)->set_property = fl_accessible_node_set_property;
466 G_OBJECT_CLASS(klass)->dispose = fl_accessible_node_dispose;
467 ATK_OBJECT_CLASS(klass)->get_name = fl_accessible_node_get_name;
468 ATK_OBJECT_CLASS(klass)->get_parent = fl_accessible_node_get_parent;
469 ATK_OBJECT_CLASS(klass)->get_index_in_parent =
470 fl_accessible_node_get_index_in_parent;
471 ATK_OBJECT_CLASS(klass)->get_n_children = fl_accessible_node_get_n_children;
472 ATK_OBJECT_CLASS(klass)->ref_child = fl_accessible_node_ref_child;
473 ATK_OBJECT_CLASS(klass)->get_role = fl_accessible_node_get_role;
474 ATK_OBJECT_CLASS(klass)->ref_state_set = fl_accessible_node_ref_state_set;
475 FL_ACCESSIBLE_NODE_CLASS(klass)->set_name = fl_accessible_node_set_name_impl;
476 FL_ACCESSIBLE_NODE_CLASS(klass)->set_extents =
477 fl_accessible_node_set_extents_impl;
478 FL_ACCESSIBLE_NODE_CLASS(klass)->set_flags =
479 fl_accessible_node_set_flags_impl;
480 FL_ACCESSIBLE_NODE_CLASS(klass)->set_actions =
481 fl_accessible_node_set_actions_impl;
482 FL_ACCESSIBLE_NODE_CLASS(klass)->set_value =
483 fl_accessible_node_set_value_impl;
484 FL_ACCESSIBLE_NODE_CLASS(klass)->set_text_selection =
485 fl_accessible_node_set_text_selection_impl;
486 FL_ACCESSIBLE_NODE_CLASS(klass)->set_text_direction =
487 fl_accessible_node_set_text_direction_impl;
488 FL_ACCESSIBLE_NODE_CLASS(klass)->perform_action =
489 fl_accessible_node_perform_action_impl;
490
491 g_object_class_install_property(
492 G_OBJECT_CLASS(klass), PROP_ENGINE,
493 g_param_spec_object(
494 "engine", "engine", "Flutter engine", fl_engine_get_type(),
495 static_cast<GParamFlags>(G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
496 G_PARAM_STATIC_STRINGS)));
497 g_object_class_install_property(
498 G_OBJECT_CLASS(klass), PROP_VIEW_ID,
499 g_param_spec_int64(
500 "view-id", "view-id", "View ID that this node belongs to", 0,
501 G_MAXINT64, 0,
502 static_cast<GParamFlags>(G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)));
503 g_object_class_install_property(
504 G_OBJECT_CLASS(klass), PROP_ID,
505 g_param_spec_int(
506 "node-id", "node-id", "Accessibility node ID", 0, G_MAXINT, 0,
507 static_cast<GParamFlags>(G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
508 G_PARAM_STATIC_STRINGS)));
509 }
510
511 static void fl_accessible_node_component_interface_init(
512 AtkComponentIface* iface) {
513 iface->get_extents = fl_accessible_node_get_extents;
514 iface->get_layer = fl_accessible_node_get_layer;
515 }
516
517 static void fl_accessible_node_action_interface_init(AtkActionIface* iface) {
518 iface->do_action = fl_accessible_node_do_action;
519 iface->get_n_actions = fl_accessible_node_get_n_actions;
520 iface->get_name = fl_accessible_node_get_name;
521 }
522
523 static void fl_accessible_node_init(FlAccessibleNode* self) {
524 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(self);
525 priv->actions = g_ptr_array_new();
526 priv->children = g_ptr_array_new_with_free_func(g_object_unref);
527 }
528
529 FlAccessibleNode* fl_accessible_node_new(FlEngine* engine,
530 FlutterViewId view_id,
531 int32_t node_id) {
532 FlAccessibleNode* self = FL_ACCESSIBLE_NODE(
533 g_object_new(fl_accessible_node_get_type(), "engine", engine, "view-id",
534 view_id, "node-id", node_id, nullptr));
535 return self;
536 }
537
538 void fl_accessible_node_set_parent(FlAccessibleNode* self,
539 AtkObject* parent,
540 gint index) {
541 g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
542 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(self);
543 priv->parent = parent;
544 priv->index = index;
545 g_object_add_weak_pointer(G_OBJECT(self),
546 reinterpret_cast<gpointer*>(&(priv->parent)));
547 }
548
549 void fl_accessible_node_set_children(FlAccessibleNode* self,
550 GPtrArray* children) {
551 g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
552 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE(self);
553
554 // Remove nodes that are no longer required.
555 for (guint i = 0; i < priv->children->len;) {
556 AtkObject* object = ATK_OBJECT(g_ptr_array_index(priv->children, i));
557 if (has_child(children, object)) {
558 i++;
559 } else {
560 g_signal_emit_by_name(self, "children-changed::remove", i, object,
561 nullptr);
562 g_ptr_array_remove_index(priv->children, i);
563 }
564 }
565
566 // Add new nodes.
567 for (guint i = 0; i < children->len; i++) {
568 AtkObject* object = ATK_OBJECT(g_ptr_array_index(children, i));
569 if (!has_child(priv->children, object)) {
570 g_ptr_array_add(priv->children, g_object_ref(object));
571 g_signal_emit_by_name(self, "children-changed::add", i, object, nullptr);
572 }
573 }
574 }
575
576 void fl_accessible_node_set_name(FlAccessibleNode* self, const gchar* name) {
577 g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
578
579 return FL_ACCESSIBLE_NODE_GET_CLASS(self)->set_name(self, name);
580 }
581
582 void fl_accessible_node_set_extents(FlAccessibleNode* self,
583 gint x,
584 gint y,
585 gint width,
586 gint height) {
587 g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
588
589 return FL_ACCESSIBLE_NODE_GET_CLASS(self)->set_extents(self, x, y, width,
590 height);
591 }
592
593 void fl_accessible_node_set_flags(FlAccessibleNode* self,
594 FlutterSemanticsFlags* flags) {
595 g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
596
597 return FL_ACCESSIBLE_NODE_GET_CLASS(self)->set_flags(self, flags);
598 }
599
600 void fl_accessible_node_set_actions(FlAccessibleNode* self,
601 FlutterSemanticsAction actions) {
602 g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
603
604 return FL_ACCESSIBLE_NODE_GET_CLASS(self)->set_actions(self, actions);
605 }
606
607 void fl_accessible_node_set_value(FlAccessibleNode* self, const gchar* value) {
608 g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
609
610 return FL_ACCESSIBLE_NODE_GET_CLASS(self)->set_value(self, value);
611 }
612
613 void fl_accessible_node_set_text_selection(FlAccessibleNode* self,
614 gint base,
615 gint extent) {
616 g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
617
618 return FL_ACCESSIBLE_NODE_GET_CLASS(self)->set_text_selection(self, base,
619 extent);
620 }
621
622 void fl_accessible_node_set_text_direction(FlAccessibleNode* self,
623 FlutterTextDirection direction) {
624 g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
625
626 return FL_ACCESSIBLE_NODE_GET_CLASS(self)->set_text_direction(self,
627 direction);
628 }
629
630 void fl_accessible_node_perform_action(FlAccessibleNode* self,
631 FlutterSemanticsAction action,
632 GBytes* data) {
633 g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
634
635 return FL_ACCESSIBLE_NODE_GET_CLASS(self)->perform_action(self, action, data);
636 }
has_child
static gboolean has_child(GPtrArray *children, AtkObject *object)
Definition: fl_accessible_node.cc:99
fl_accessible_node_set_property
static void fl_accessible_node_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
Definition: fl_accessible_node.cc:109
fl_accessible_node_set_name
void fl_accessible_node_set_name(FlAccessibleNode *self, const gchar *name)
Definition: fl_accessible_node.cc:576
fl_accessible_node_do_action
static gboolean fl_accessible_node_do_action(AtkAction *action, gint i)
Definition: fl_accessible_node.cc:295
fl_accessible_node_action_interface_init
static void fl_accessible_node_action_interface_init(AtkActionIface *iface)
Definition: fl_accessible_node.cc:517
fl_accessible_node_set_text_direction_impl
static void fl_accessible_node_set_text_direction_impl(FlAccessibleNode *self, FlutterTextDirection direction)
Definition: fl_accessible_node.cc:450
PROP_ENGINE
@ PROP_ENGINE
Definition: fl_accessible_node.cc:64
PROP_VIEW_ID
@ PROP_VIEW_ID
Definition: fl_accessible_node.cc:64
PROP_LAST
@ PROP_LAST
Definition: fl_accessible_node.cc:64
PROP_0
@ PROP_0
Definition: fl_accessible_node.cc:64
PROP_ID
@ PROP_ID
Definition: fl_accessible_node.cc:64
fl_accessible_node_set_text_direction
void fl_accessible_node_set_text_direction(FlAccessibleNode *self, FlutterTextDirection direction)
Definition: fl_accessible_node.cc:622
fl_accessible_node_perform_action
void fl_accessible_node_perform_action(FlAccessibleNode *self, FlutterSemanticsAction action, GBytes *data)
Definition: fl_accessible_node.cc:630
fl_accessible_node_get_role
static AtkRole fl_accessible_node_get_role(AtkObject *accessible)
Definition: fl_accessible_node.cc:189
flag_changed
static bool flag_changed(bool old_flag, bool new_flag)
Definition: fl_accessible_node.cc:353
fl_accessible_node_set_value_impl
static void fl_accessible_node_set_value_impl(FlAccessibleNode *self, const gchar *value)
Definition: fl_accessible_node.cc:441
fl_accessible_node_set_text_selection
void fl_accessible_node_set_text_selection(FlAccessibleNode *self, gint base, gint extent)
Definition: fl_accessible_node.cc:613
fl_accessible_node_class_init
static void fl_accessible_node_class_init(FlAccessibleNodeClass *klass)
Definition: fl_accessible_node.cc:464
fl_accessible_node_set_actions_impl
static void fl_accessible_node_set_actions_impl(FlAccessibleNode *self, FlutterSemanticsAction actions)
Definition: fl_accessible_node.cc:422
fl_accessible_node_component_interface_init
static void fl_accessible_node_component_interface_init(AtkComponentIface *iface)
Definition: fl_accessible_node.cc:511
fl_accessible_node_set_actions
void fl_accessible_node_set_actions(FlAccessibleNode *self, FlutterSemanticsAction actions)
Definition: fl_accessible_node.cc:600
fl_accessible_node_dispose
static void fl_accessible_node_dispose(GObject *object)
Definition: fl_accessible_node.cc:133
fl_accessible_node_set_children
void fl_accessible_node_set_children(FlAccessibleNode *self, GPtrArray *children)
Definition: fl_accessible_node.cc:549
fl_accessible_node_get_name
static const gchar * fl_accessible_node_get_name(AtkObject *accessible)
Definition: fl_accessible_node.cc:154
fl_accessible_node_set_extents
void fl_accessible_node_set_extents(FlAccessibleNode *self, gint x, gint y, gint width, gint height)
Definition: fl_accessible_node.cc:582
fl_accessible_node_get_layer
static AtkLayer fl_accessible_node_get_layer(AtkComponent *component)
Definition: fl_accessible_node.cc:290
fl_accessible_node_set_value
void fl_accessible_node_set_value(FlAccessibleNode *self, const gchar *value)
Definition: fl_accessible_node.cc:607
fl_accessible_node_get_extents
static void fl_accessible_node_get_extents(AtkComponent *component, gint *x, gint *y, gint *width, gint *height, AtkCoordType coord_type)
Definition: fl_accessible_node.cc:268
fl_accessible_node_get_n_actions
static gint fl_accessible_node_get_n_actions(AtkAction *action)
Definition: fl_accessible_node.cc:313
G_DEFINE_TYPE_WITH_CODE
G_DEFINE_TYPE_WITH_CODE(FlAccessibleNode, fl_accessible_node, ATK_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(ATK_TYPE_COMPONENT, fl_accessible_node_component_interface_init) G_IMPLEMENT_INTERFACE(ATK_TYPE_ACTION, fl_accessible_node_action_interface_init)) static gboolean has_action(FlutterSemanticsAction actions
fl_accessible_node_ref_child
static AtkObject * fl_accessible_node_ref_child(AtkObject *accessible, gint i)
Definition: fl_accessible_node.cc:178
action
FlutterSemanticsAction action
Definition: fl_accessible_node.cc:86
fl_accessible_node_get_index_in_parent
static gint fl_accessible_node_get_index_in_parent(AtkObject *accessible)
Definition: fl_accessible_node.cc:166
fl_accessible_node_get_parent
static AtkObject * fl_accessible_node_get_parent(AtkObject *accessible)
Definition: fl_accessible_node.cc:160
fl_accessible_node_init
static void fl_accessible_node_init(FlAccessibleNode *self)
Definition: fl_accessible_node.cc:523
fl_accessible_node_set_parent
void fl_accessible_node_set_parent(FlAccessibleNode *self, AtkObject *parent, gint index)
Definition: fl_accessible_node.cc:538
fl_accessible_node_ref_state_set
static AtkStateSet * fl_accessible_node_ref_state_set(AtkObject *accessible)
Definition: fl_accessible_node.cc:227
fl_accessible_node_perform_action_impl
static void fl_accessible_node_perform_action_impl(FlAccessibleNode *self, FlutterSemanticsAction action, GBytes *data)
Definition: fl_accessible_node.cc:455
action_mapping
static ActionData action_mapping[]
Definition: fl_accessible_node.cc:13
fl_accessible_node_set_text_selection_impl
static void fl_accessible_node_set_text_selection_impl(FlAccessibleNode *self, gint base, gint extent)
Definition: fl_accessible_node.cc:445
fl_accessible_node_set_flags
void fl_accessible_node_set_flags(FlAccessibleNode *self, FlutterSemanticsFlags *flags)
Definition: fl_accessible_node.cc:593
fl_accessible_node_get_n_children
static gint fl_accessible_node_get_n_children(AtkObject *accessible)
Definition: fl_accessible_node.cc:172
fl_accessible_node_set_extents_impl
static void fl_accessible_node_set_extents_impl(FlAccessibleNode *self, gint x, gint y, gint width, gint height)
Definition: fl_accessible_node.cc:339
get_action
static ActionData * get_action(FlAccessibleNodePrivate *priv, gint index)
Definition: fl_accessible_node.cc:91
FL_ACCESSIBLE_NODE_GET_PRIVATE
#define FL_ACCESSIBLE_NODE_GET_PRIVATE(node)
Definition: fl_accessible_node.cc:66
fl_accessible_node_new
FlAccessibleNode * fl_accessible_node_new(FlEngine *engine, FlutterViewId view_id, int32_t node_id)
Definition: fl_accessible_node.cc:529
fl_accessible_node_set_name_impl
static void fl_accessible_node_set_name_impl(FlAccessibleNode *self, const gchar *name)
Definition: fl_accessible_node.cc:331
fl_accessible_node_set_flags_impl
static void fl_accessible_node_set_flags_impl(FlAccessibleNode *self, FlutterSemanticsFlags *flags)
Definition: fl_accessible_node.cc:358
fl_accessible_node.h
fl_engine_dispatch_semantics_action
void fl_engine_dispatch_semantics_action(FlEngine *self, FlutterViewId view_id, uint64_t node_id, FlutterSemanticsAction action, GBytes *data)
Definition: fl_engine.cc:1364
fl_engine_private.h
priv
FlPixelBufferTexturePrivate * priv
Definition: fl_pixel_buffer_texture.cc:30
height
const uint8_t uint32_t uint32_t * height
Definition: fl_pixel_buffer_texture_test.cc:39
width
const uint8_t uint32_t * width
Definition: fl_pixel_buffer_texture_test.cc:38
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
i
int i
Definition: fl_socket_accessible.cc:18
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
prop_id
guint prop_id
Definition: fl_standard_method_codec.cc:31
pspec
guint const GValue GParamSpec * pspec
Definition: fl_standard_method_codec.cc:33
view_id
G_BEGIN_DECLS FlutterViewId view_id
Definition: fl_view_accessible.h:49
ActionData
Definition: fl_accessible_node.cc:9
ActionData::name
const gchar * name
Definition: fl_accessible_node.cc:11
ActionData::action
FlutterSemanticsAction action
Definition: fl_accessible_node.cc:10
FlAccessibleNodePrivate
Definition: fl_accessible_node.cc:42
FlAccessibleNodePrivate::flags
FlutterSemanticsFlags flags
Definition: fl_accessible_node.cc:61
FlAccessibleNodePrivate::actions_length
gsize actions_length
Definition: fl_accessible_node.cc:59
FlAccessibleNodePrivate::view_id
FlutterViewId view_id
The unique identifier of the view to which this node belongs.
Definition: fl_accessible_node.cc:49
FlAccessibleNodePrivate::name
gchar * name
Definition: fl_accessible_node.cc:55
FlAccessibleNodePrivate::y
gint y
Definition: fl_accessible_node.cc:57
FlAccessibleNodePrivate::parent_instance
AtkObject parent_instance
Definition: fl_accessible_node.cc:43
FlAccessibleNodePrivate::width
gint width
Definition: fl_accessible_node.cc:57
FlAccessibleNodePrivate::engine
FlEngine * engine
Definition: fl_accessible_node.cc:46
FlAccessibleNodePrivate::children
GPtrArray * children
Definition: fl_accessible_node.cc:60
FlAccessibleNodePrivate::x
gint x
Definition: fl_accessible_node.cc:57
FlAccessibleNodePrivate::index
gint index
Definition: fl_accessible_node.cc:56
FlAccessibleNodePrivate::height
gint height
Definition: fl_accessible_node.cc:57
FlAccessibleNodePrivate::node_id
int32_t node_id
Definition: fl_accessible_node.cc:54
FlAccessibleNodePrivate::actions
GPtrArray * actions
Definition: fl_accessible_node.cc:58
FlAccessibleNodePrivate::parent
AtkObject * parent
Definition: fl_accessible_node.cc:52