a11y: Set focus-related states properly

Entries and menubuttons are no longer focusable themselves,
they have focusable children. Since we don't have accessible
objects for those, transfer the focus-related state (focusable
and focused) from the children to the main accessible object.
This commit is contained in:
Matthias Clasen 2020-03-29 21:48:57 -04:00
parent 1f8e633fff
commit 8a0035333a
2 changed files with 30 additions and 0 deletions

View File

@ -387,13 +387,20 @@ gtk_entry_accessible_ref_state_set (AtkObject *accessible)
AtkStateSet *state_set;
gboolean value;
GtkWidget *widget;
GtkWidget *text;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
if (widget == NULL)
return NULL;
text = gtk_widget_get_first_child (widget);
state_set = ATK_OBJECT_CLASS (gtk_entry_accessible_parent_class)->ref_state_set (accessible);
atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE);
if (gtk_widget_has_focus (text))
atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
g_object_get (G_OBJECT (widget), "editable", &value, NULL);
if (value)
atk_state_set_add_state (state_set, ATK_STATE_EDITABLE);

View File

@ -77,6 +77,28 @@ gtk_menu_button_accessible_get_name (AtkObject *obj)
return _("Menu");
}
static AtkStateSet *
gtk_menu_button_accessible_ref_state_set (AtkObject *obj)
{
AtkStateSet *state_set;
GtkWidget *widget;
GtkWidget *button;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
if (widget == NULL)
return NULL;
button = gtk_widget_get_first_child (widget);
state_set = ATK_OBJECT_CLASS (gtk_menu_button_accessible_parent_class)->ref_state_set (obj);
atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE);
if (gtk_widget_has_focus (button))
atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
return state_set;
}
static void
gtk_menu_button_accessible_class_init (GtkMenuButtonAccessibleClass *klass)
{
@ -86,6 +108,7 @@ gtk_menu_button_accessible_class_init (GtkMenuButtonAccessibleClass *klass)
class->initialize = gtk_menu_button_accessible_initialize;
class->get_n_children = gtk_menu_button_accessible_get_n_children;
class->ref_child = gtk_menu_button_accessible_ref_child;
class->ref_state_set = gtk_menu_button_accessible_ref_state_set;
}
static void