[gtk/ebassi/for-master: 3/4] a11y: Use proper role and state for tree expander image




commit c5dc0e2e4c48050bba31819ac48818cd7c3c60c5
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Nov 5 13:46:43 2020 +0000

    a11y: Use proper role and state for tree expander image
    
    The "expander" image is a button, and it controls the expansion of the
    row, so it has a state associated to it that we must update.

 gtk/gtktreeexpander.c | 36 +++++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtktreeexpander.c b/gtk/gtktreeexpander.c
index ec57b28ced..2a68df898d 100644
--- a/gtk/gtktreeexpander.c
+++ b/gtk/gtktreeexpander.c
@@ -158,7 +158,11 @@ gtk_tree_expander_update_for_list_row (GtkTreeExpander *self)
             {
               GtkGesture *gesture;
 
-              self->expander = gtk_builtin_icon_new ("expander");
+              self->expander =
+                g_object_new (GTK_TYPE_BUILTIN_ICON,
+                              "css-name", "expander",
+                              "accessible-role", GTK_ACCESSIBLE_ROLE_BUTTON,
+                              NULL);
 
               gesture = gtk_gesture_click_new ();
               gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture),
@@ -179,10 +183,22 @@ gtk_tree_expander_update_for_list_row (GtkTreeExpander *self)
                                         GTK_WIDGET (self),
                                         self->child);
             }
+
           if (gtk_tree_list_row_get_expanded (self->list_row))
-            gtk_widget_set_state_flags (self->expander, GTK_STATE_FLAG_CHECKED, FALSE);
+            {
+              gtk_widget_set_state_flags (self->expander, GTK_STATE_FLAG_CHECKED, FALSE);
+              gtk_accessible_update_state (GTK_ACCESSIBLE (self->expander),
+                                           GTK_ACCESSIBLE_STATE_EXPANDED, TRUE,
+                                           -1);
+            }
           else
-            gtk_widget_unset_state_flags (self->expander, GTK_STATE_FLAG_CHECKED);
+            {
+              gtk_widget_unset_state_flags (self->expander, GTK_STATE_FLAG_CHECKED);
+              gtk_accessible_update_state (GTK_ACCESSIBLE (self->expander),
+                                           GTK_ACCESSIBLE_STATE_EXPANDED, FALSE,
+                                           -1);
+            }
+
           child = gtk_widget_get_prev_sibling (self->expander);
         }
       else
@@ -230,9 +246,19 @@ gtk_tree_expander_list_row_notify_cb (GtkTreeListRow  *list_row,
       if (self->expander)
         {
           if (gtk_tree_list_row_get_expanded (list_row))
-            gtk_widget_set_state_flags (self->expander, GTK_STATE_FLAG_CHECKED, FALSE);
+            {
+              gtk_widget_set_state_flags (self->expander, GTK_STATE_FLAG_CHECKED, FALSE);
+              gtk_accessible_update_state (GTK_ACCESSIBLE (self->expander),
+                                           GTK_ACCESSIBLE_STATE_EXPANDED, TRUE,
+                                           -1);
+            }
           else
-            gtk_widget_unset_state_flags (self->expander, GTK_STATE_FLAG_CHECKED);
+            {
+              gtk_widget_unset_state_flags (self->expander, GTK_STATE_FLAG_CHECKED);
+              gtk_accessible_update_state (GTK_ACCESSIBLE (self->expander),
+                                           GTK_ACCESSIBLE_STATE_EXPANDED, FALSE,
+                                           -1);
+            }
         }
     }
   else if (pspec->name == g_intern_static_string ("item"))


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