[gtk/a11y-work: 3/5] a11y: Set accessible role for GtkLinkButton




commit f345f755572c231720a09bee5d531ac6ab51c450
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jul 29 20:26:16 2020 -0400

    a11y: Set accessible role for GtkLinkButton
    
    Set the accessible role for GtkLinkButton to button.
    We don't use the 'link' role since ARIA says "if it
    behaves like a button, use 'button'".
    
    Update docs and add a test.
    
    This changes should not be neccessary, since
    GtkLinkButton derives from GtkButton, see #2965.

 docs/reference/gtk/section-accessibility.md |  2 +-
 gtk/gtklinkbutton.c                         |  5 +++++
 testsuite/a11y/button.c                     | 24 ++++++++++++++++++++++++
 3 files changed, 30 insertions(+), 1 deletion(-)
---
diff --git a/docs/reference/gtk/section-accessibility.md b/docs/reference/gtk/section-accessibility.md
index 4dd51c6a7e..d4bc80590c 100644
--- a/docs/reference/gtk/section-accessibility.md
+++ b/docs/reference/gtk/section-accessibility.md
@@ -46,7 +46,7 @@ Each role name is part of the #GtkAccessibleRole enumeration.
 | Role name | Description | Related GTK widget |
 |-----------|-------------|--------------------|
 | `ALERT` | A message with important information | - |
-| `BUTTON` | A control that performs an action when pressed | #GtkButton |
+| `BUTTON` | A control that performs an action when pressed | #GtkButton, #GtkLinkButton |
 | `CHECKBOX` | A control that has three possible value: `true`, `false`, or `undefined` | #GtkCheckButton |
 | `COLUMNHEADER` | The header of a column in a list or grid | - |
 | `COMBOBOX` | A control that can be expanded to show a list of possible values to select | #GtkComboBox |
diff --git a/gtk/gtklinkbutton.c b/gtk/gtklinkbutton.c
index df25f264ae..521c196a04 100644
--- a/gtk/gtklinkbutton.c
+++ b/gtk/gtklinkbutton.c
@@ -47,6 +47,10 @@
  *
  * GtkLinkButton has a single CSS node with name button. To differentiate
  * it from a plain #GtkButton, it gets the .link style class.
+ *
+ * # Accessibility
+ *
+ * GtkLinkButton uses the #GTK_ACCESSIBKE_ROLE_BUTTON role.
  */
 
 #include "config.h"
@@ -217,6 +221,7 @@ gtk_link_button_class_init (GtkLinkButtonClass *klass)
                   G_TYPE_BOOLEAN, 0);
 
   gtk_widget_class_set_css_name (widget_class, I_("button"));
+  gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_BUTTON);
 
   /**
    * GtkLinkButton|clipboard.copy:
diff --git a/testsuite/a11y/button.c b/testsuite/a11y/button.c
index 9c5fdad777..f78207fb31 100644
--- a/testsuite/a11y/button.c
+++ b/testsuite/a11y/button.c
@@ -25,6 +25,28 @@ button_label (void)
   g_object_unref (button);
 }
 
+static void
+linkbutton_role (void)
+{
+  GtkWidget *button = gtk_link_button_new ("Hello");
+  g_object_ref_sink (button);
+
+  gtk_test_accessible_assert_role (button, GTK_ACCESSIBLE_ROLE_BUTTON);
+
+  g_object_unref (button);
+}
+
+static void
+linkbutton_label (void)
+{
+  GtkWidget *button = gtk_link_button_new ("Hello");
+  g_object_ref_sink (button);
+
+  gtk_test_accessible_assert_property (button, GTK_ACCESSIBLE_PROPERTY_LABEL, "Hello");
+
+  g_object_unref (button);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -32,6 +54,8 @@ main (int argc, char *argv[])
 
   g_test_add_func ("/a11y/button/role", button_role);
   g_test_add_func ("/a11y/button/label", button_label);
+  g_test_add_func ("/a11y/linkbutton/role", linkbutton_role);
+  g_test_add_func ("/a11y/linkbutton/label", linkbutton_label);
 
   return g_test_run ();
 }


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