[gtk/matthiasc/for-master: 3/5] modelbutton: Initial accessibility setup




commit f96a1cfadd82d5a2996d849ef6e594beda0d1c8a
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Oct 21 16:35:39 2020 -0400

    modelbutton: Initial accessibility setup
    
    Set the accessible role to GTK_ACCESSIBLE_ROLE_MENU_ITEM.
    This is incomplete, we need to recreate the context when
    the buttons role changes, and there are other things that
    need to be set.

 gtk/gtkmodelbutton.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkmodelbutton.c b/gtk/gtkmodelbutton.c
index 93f9d011fc..7a7b10d76a 100644
--- a/gtk/gtkmodelbutton.c
+++ b/gtk/gtkmodelbutton.c
@@ -627,6 +627,26 @@ gtk_model_button_set_active (GtkModelButton *button,
   g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_ACTIVE]);
 }
 
+static void
+update_accessible_properties (GtkModelButton *button)
+{
+  if (button->menu_name || button->popover)
+    gtk_accessible_update_property (GTK_ACCESSIBLE (button),
+                                    GTK_ACCESSIBLE_PROPERTY_HAS_POPUP, TRUE,
+                                    -1);
+  else
+    gtk_accessible_reset_property (GTK_ACCESSIBLE (button),
+                                   GTK_ACCESSIBLE_PROPERTY_HAS_POPUP);
+
+  if (button->popover)
+    gtk_accessible_update_relation (GTK_ACCESSIBLE (button),
+                                    GTK_ACCESSIBLE_RELATION_CONTROLS, g_list_append (NULL, button->popover),
+                                    -1);
+  else
+    gtk_accessible_reset_relation (GTK_ACCESSIBLE (button),
+                                   GTK_ACCESSIBLE_RELATION_CONTROLS);
+}
+
 static void
 gtk_model_button_set_menu_name (GtkModelButton *button,
                                 const char     *menu_name)
@@ -637,6 +657,8 @@ gtk_model_button_set_menu_name (GtkModelButton *button,
   update_node_name (button);
   gtk_model_button_update_state (button);
 
+  update_accessible_properties (button);
+
   gtk_widget_queue_resize (GTK_WIDGET (button));
   g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_MENU_NAME]);
 }
@@ -704,6 +726,8 @@ gtk_model_button_set_popover (GtkModelButton *button,
       gtk_popover_set_position (GTK_POPOVER (button->popover), GTK_POS_RIGHT);
     }
 
+  update_accessible_properties (button);
+
   update_node_name (button);
   gtk_model_button_update_state (button);
 
@@ -1186,7 +1210,8 @@ gtk_model_button_class_init (GtkModelButtonClass *class)
   widget_class->activate_signal = signals[SIGNAL_CLICKED];
 
   gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
-  gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (class), I_("modelbutton"));
+  gtk_widget_class_set_css_name (widget_class, I_("modelbutton"));
+  gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_MENU_ITEM);
 }
 
 static void


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