fontchooser: Improve accessibility
authorMatthias Clasen <mclasen@redhat.com>
Sat, 10 Jun 2023 15:00:35 +0000 (11:00 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 10 Jun 2023 15:29:12 +0000 (11:29 -0400)
Set up missing accessible relations, labels and roles.

gtk/gtkfontchooserwidget.c
gtk/ui/gtkfontchooserwidget.ui

index e54d1f575dd2f11325f6e549c8371683a149d75d..598466d02756d69a73099e14a6fb5115a61c0247 100644 (file)
@@ -1594,6 +1594,9 @@ add_axis (GtkFontChooserWidget  *fontchooser,
                                          (double)ax->max_value,
                                          1.0, 10.0, 0.0);
   axis->scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, axis->adjustment);
+  gtk_accessible_update_relation (GTK_ACCESSIBLE (axis->scale),
+                                  GTK_ACCESSIBLE_RELATION_LABELLED_BY, axis->label, NULL,
+                                  -1);
   gtk_scale_add_mark (GTK_SCALE (axis->scale), (double)ax->default_value, GTK_POS_TOP, NULL);
   gtk_widget_set_valign (axis->scale, GTK_ALIGN_BASELINE_FILL);
   gtk_widget_set_hexpand (axis->scale, TRUE);
@@ -1601,6 +1604,9 @@ add_axis (GtkFontChooserWidget  *fontchooser,
   gtk_scale_set_draw_value (GTK_SCALE (axis->scale), FALSE);
   gtk_grid_attach (GTK_GRID (fontchooser->axis_grid), axis->scale, 1, row, 1, 1);
   axis->spin = gtk_spin_button_new (axis->adjustment, 0, 0);
+  gtk_accessible_update_relation (GTK_ACCESSIBLE (axis->spin),
+                                  GTK_ACCESSIBLE_RELATION_LABELLED_BY, axis->label, NULL,
+                                  -1);
   g_signal_connect (axis->spin, "output", G_CALLBACK (output_cb), fontchooser);
   gtk_widget_set_valign (axis->spin, GTK_ALIGN_BASELINE_FILL);
   gtk_grid_attach (GTK_GRID (fontchooser->axis_grid), axis->spin, 2, row, 1, 1);
@@ -2345,7 +2351,7 @@ add_enum_group (GtkFontChooserWidget  *fontchooser,
                 const char           **tags,
                 unsigned int           n_tags)
 {
-  GtkWidget *label;
+  GtkWidget *label = NULL;
   GtkWidget *group;
   PangoAttrList *attrs;
   int i;
@@ -2433,6 +2439,9 @@ add_radio_group (GtkFontChooserWidget  *fontchooser,
   gtk_label_set_attributes (GTK_LABEL (label), attrs);
   pango_attr_list_unref (attrs);
   gtk_box_append (GTK_BOX (group), label);
+  gtk_accessible_update_relation (GTK_ACCESSIBLE (group),
+                                  GTK_ACCESSIBLE_RELATION_LABELLED_BY, label, NULL,
+                                  -1);
 
   for (i = 0; i < n_tags; i++)
     {
index e1ccdd932c92722778d577265fa07beb6428fc1f..99b30e86a9af4b926b51f7bc398c319d1851cde5 100644 (file)
                             <child>
                               <object class="GtkEntry" id="preview">
                                 <property name="tooltip-text" translatable="yes">Preview Font</property>
+                                <accessibility>
+                                  <property name="label" translatable="yes">Preview Font</property>
+                                </accessibility>
                                 <child>
                                   <object class="GtkEventControllerScroll">
                                     <property name="flags">horizontal</property>
                                 <property name="hexpand">1</property>
                                 <property name="adjustment">slider_adjustment</property>
                                 <property name="round-digits">0</property>
+                                <accessibility>
+                                  <relation name="labelled-by">size_label</relation>
+                                </accessibility>
                                 <child>
                                   <object class="GtkEventControllerScroll">
                                     <property name="flags">horizontal</property>
                               <object class="GtkSpinButton" id="size_spin">
                                 <property name="adjustment">spin_adjustment</property>
                                 <property name="valign">3</property>
+                                <accessibility>
+                                  <relation name="labelled-by">size_label</relation>
+                                </accessibility>
                                 <signal name="output" handler="output_cb"/>
                                 <layout>
                                   <property name="column">2</property>
                             <property name="vexpand">1</property>
                             <property name="halign">3</property>
                             <property name="valign">3</property>
+                            <property name="accessible-role">alert</property>
+                            <accessibility>
+                              <relation name="labelled-by">no_fonts_label</relation>
+                            </accessibility>
                             <style>
                               <class name="dim-label"/>
                             </style>
                               </object>
                             </child>
                             <child>
-                              <object class="GtkLabel">
+                              <object class="GtkLabel" id="no_fonts_label">
                                 <property name="label" translatable="yes">No Fonts Found</property>
                                 <attributes>
                                   <attribute name="weight" value="bold"></attribute>
                     <property name="margin-end">12</property>
                     <property name="ellipsize">3</property>
                     <property name="xalign">0</property>
+                    <accessibility>
+                      <property name="description" translatable="1">Font Name</property>
+                    </accessibility>
                     <binding name="label" object="GtkFontChooserWidget">
                       <closure type="gchararray" function="get_font_name">
                         <lookup name="selected-item">selection</lookup>
                     <property name="tooltip-text" translatable="yes">Preview Font</property>
                     <property name="text" bind-source="preview" bind-property="text" bind-flags="bidirectional"/>
                     <property name="attributes" bind-source="preview" bind-property="attributes" bind-flags="bidirectional"/>
+                    <accessibility>
+                      <property name="label" translatable="yes">Preview Font</property>
+                    </accessibility>
                   </object>
                 </child>
                 <child>
                           <object class="GtkGrid" id="axis_grid">
                             <property name="row-spacing">6</property>
                             <property name="column-spacing">12</property>
+                            <accessibility>
+                              <property name="label" translatable="1">Font Variation Axes</property>
+                            </accessibility>
                             <child>
                               <object class="GtkLabel" id="size_label2">
                                 <property name="label" translatable="yes">Size</property>
                                 <property name="hexpand">1</property>
                                 <property name="adjustment">slider_adjustment</property>
                                 <property name="round-digits">0</property>
+                                <accessibility>
+                                  <relation name="labelled-by">size_label2</relation>
+                                </accessibility>
                                 <layout>
                                   <property name="column">1</property>
                                   <property name="row">0</property>
                                 <property name="adjustment">spin_adjustment</property>
                                 <property name="valign">3</property>
                                 <signal name="output" handler="output_cb"/>
+                                <accessibility>
+                                  <relation name="labelled-by">size_label2</relation>
+                                </accessibility>
                                 <layout>
                                   <property name="column">2</property>
                                   <property name="row">0</property>
                           <object class="GtkBox" id="feature_box">
                             <property name="orientation">1</property>
                             <property name="spacing">12</property>
+                            <accessibility>
+                              <property name="label" translatable="1">Font Features</property>
+                            </accessibility>
                           </object>
                         </child>
                       </object>