From 508cb6160c8be003db52a749fe3a61cf4f665c6f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 9 Apr 2020 17:50:02 -0400 Subject: [PATCH] a11y: Fix focusable state The :can-focus property is no longer very useful to give an indication of what is focusable, since it is TRUE for almost all widgets now. Patch things up to by looking at known widget types. --- gtk/a11y/gtkwidgetaccessible.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/gtk/a11y/gtkwidgetaccessible.c b/gtk/a11y/gtkwidgetaccessible.c index 38f96c8b7d..84732dcda5 100644 --- a/gtk/a11y/gtkwidgetaccessible.c +++ b/gtk/a11y/gtkwidgetaccessible.c @@ -293,6 +293,36 @@ gtk_widget_accessible_ref_relation_set (AtkObject *obj) return relation_set; } +static gboolean +takes_focus (GtkWidget *widget) +{ + if (GTK_IS_NOTEBOOK (widget) || + GTK_IS_BUTTON (widget)) + return TRUE; + + if (GTK_IS_ACCEL_LABEL (widget) || + GTK_IS_CONTAINER(widget) || + GTK_IS_DRAG_ICON (widget) || + GTK_IS_DRAWING_AREA (widget) || + GTK_IS_GL_AREA (widget) || + GTK_IS_IMAGE (widget) || + GTK_IS_LEVEL_BAR (widget) || + GTK_IS_MEDIA_CONTROLS (widget) || + GTK_IS_PICTURE (widget) || + GTK_IS_PROGRESS_BAR (widget) || + GTK_IS_SCROLLBAR (widget) || + GTK_IS_SEPARATOR (widget) || + GTK_IS_SHORTCUT_LABEL (widget) || + GTK_IS_SHORTCUTS_SHORTCUT (widget) || + GTK_IS_SPINNER (widget) || + GTK_IS_STACK_SIDEBAR (widget) || + GTK_IS_STATUSBAR (widget) || + GTK_IS_VIDEO (widget)) + return FALSE; + + return gtk_widget_get_can_focus (widget); +} + static AtkStateSet * gtk_widget_accessible_ref_state_set (AtkObject *accessible) { @@ -312,7 +342,7 @@ gtk_widget_accessible_ref_state_set (AtkObject *accessible) atk_state_set_add_state (state_set, ATK_STATE_ENABLED); } - if (gtk_widget_get_can_focus (widget)) + if (takes_focus (widget)) { atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE); }