[gtk/wip/matthiasc/can-focus: 27/31] a11y: Fix focusable state



commit 508cb6160c8be003db52a749fe3a61cf4f665c6f
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Apr 9 17:50:02 2020 -0400

    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);
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]