Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5e760f6

Browse files
Fix signals adding/removing a11y nodes in Linux. (#31601)
1 parent 27e62d0 commit 5e760f6

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

shell/platform/linux/fl_accessible_node.cc

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ static ActionData* get_action(FlAccessibleNode* self, gint index) {
121121
return static_cast<ActionData*>(g_ptr_array_index(self->actions, index));
122122
}
123123

124+
// Checks if [object] is in [children].
125+
static gboolean has_child(GPtrArray* children, AtkObject* object) {
126+
for (guint i = 0; i < children->len; i++) {
127+
if (g_ptr_array_index(children, i) == object) {
128+
return TRUE;
129+
}
130+
}
131+
132+
return FALSE;
133+
}
134+
124135
static void fl_accessible_node_dispose(GObject* object) {
125136
FlAccessibleNode* self = FL_ACCESSIBLE_NODE(object);
126137

@@ -340,11 +351,25 @@ void fl_accessible_node_set_children(FlAccessibleNode* self,
340351
GPtrArray* children) {
341352
g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
342353

343-
g_ptr_array_remove_range(self->children, 0, self->children->len);
354+
// Remove nodes that are no longer required.
355+
for (guint i = 0; i < self->children->len;) {
356+
AtkObject* object = ATK_OBJECT(g_ptr_array_index(self->children, i));
357+
if (has_child(children, object)) {
358+
i++;
359+
} else {
360+
g_signal_emit_by_name(self, "children-changed::remove", i, object,
361+
nullptr);
362+
g_ptr_array_remove_index(self->children, i);
363+
}
364+
}
365+
366+
// Add new nodes.
344367
for (guint i = 0; i < children->len; i++) {
345368
AtkObject* object = ATK_OBJECT(g_ptr_array_index(children, i));
346-
g_ptr_array_add(self->children, g_object_ref(object));
347-
g_signal_emit_by_name(self, "children-changed::add", i, object, nullptr);
369+
if (!has_child(self->children, object)) {
370+
g_ptr_array_add(self->children, g_object_ref(object));
371+
g_signal_emit_by_name(self, "children-changed::add", i, object, nullptr);
372+
}
348373
}
349374
}
350375

0 commit comments

Comments
 (0)