Skip to content

Commit

Permalink
Fix signals adding/removing a11y nodes in Linux. (#31601)
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-ancell committed Mar 11, 2022
1 parent 27e62d0 commit 5e760f6
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions shell/platform/linux/fl_accessible_node.cc
Expand Up @@ -121,6 +121,17 @@ static ActionData* get_action(FlAccessibleNode* self, gint index) {
return static_cast<ActionData*>(g_ptr_array_index(self->actions, index));
}

// Checks if [object] is in [children].
static gboolean has_child(GPtrArray* children, AtkObject* object) {
for (guint i = 0; i < children->len; i++) {
if (g_ptr_array_index(children, i) == object) {
return TRUE;
}
}

return FALSE;
}

static void fl_accessible_node_dispose(GObject* object) {
FlAccessibleNode* self = FL_ACCESSIBLE_NODE(object);

Expand Down Expand Up @@ -340,11 +351,25 @@ void fl_accessible_node_set_children(FlAccessibleNode* self,
GPtrArray* children) {
g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));

g_ptr_array_remove_range(self->children, 0, self->children->len);
// Remove nodes that are no longer required.
for (guint i = 0; i < self->children->len;) {
AtkObject* object = ATK_OBJECT(g_ptr_array_index(self->children, i));
if (has_child(children, object)) {
i++;
} else {
g_signal_emit_by_name(self, "children-changed::remove", i, object,
nullptr);
g_ptr_array_remove_index(self->children, i);
}
}

// Add new nodes.
for (guint i = 0; i < children->len; i++) {
AtkObject* object = ATK_OBJECT(g_ptr_array_index(children, i));
g_ptr_array_add(self->children, g_object_ref(object));
g_signal_emit_by_name(self, "children-changed::add", i, object, nullptr);
if (!has_child(self->children, object)) {
g_ptr_array_add(self->children, g_object_ref(object));
g_signal_emit_by_name(self, "children-changed::add", i, object, nullptr);
}
}
}

Expand Down

0 comments on commit 5e760f6

Please sign in to comment.