[gtk/a11y/atspi: 4/8] a11y: Turn accessible roles to string




commit f7dd1edea9b99a0dd0695a1ae65f313aa3889fa0
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Fri Oct 9 22:31:58 2020 +0100

    a11y: Turn accessible roles to string
    
    Add a simple utility function to turn GtkAccessibleRole values into the
    appropriate string, including localization.

 gtk/gtkaccessible.c        | 104 +++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkaccessibleprivate.h |   3 ++
 2 files changed, 107 insertions(+)
---
diff --git a/gtk/gtkaccessible.c b/gtk/gtkaccessible.c
index 0c9a399ef0..2b828b2254 100644
--- a/gtk/gtkaccessible.c
+++ b/gtk/gtkaccessible.c
@@ -48,6 +48,8 @@
 #include "gtkenums.h"
 #include "gtktypebuiltins.h"
 
+#include <glib/gi18n-lib.h>
+
 #include <stdarg.h>
 
 G_DEFINE_INTERFACE (GtkAccessible, gtk_accessible, G_TYPE_OBJECT)
@@ -532,3 +534,105 @@ gtk_accessible_reset_relation (GtkAccessible         *self,
   gtk_at_context_set_accessible_relation (context, relation, NULL);
   gtk_at_context_update (context);
 }
+
+static const char *role_names[] = {
+  [GTK_ACCESSIBLE_ROLE_ALERT] = NC_("accessibility", "alert"),
+  [GTK_ACCESSIBLE_ROLE_ALERT_DIALOG] = NC_("accessibility", "alert dialog"),
+  [GTK_ACCESSIBLE_ROLE_BANNER] = NC_("accessibility", "banner"),
+  [GTK_ACCESSIBLE_ROLE_BUTTON] = NC_("accessibility", "button"),
+  [GTK_ACCESSIBLE_ROLE_CAPTION] = NC_("accessibility", "caption"),
+  [GTK_ACCESSIBLE_ROLE_CELL] = NC_("accessibility", "cell"),
+  [GTK_ACCESSIBLE_ROLE_CHECKBOX] = NC_("accessibility", "checkbox"),
+  [GTK_ACCESSIBLE_ROLE_COLUMN_HEADER] = NC_("accessibility", "column header"),
+  [GTK_ACCESSIBLE_ROLE_COMBO_BOX] = NC_("accessibility", "combo box"),
+  [GTK_ACCESSIBLE_ROLE_COMMAND] = NC_("accessibility", "command"),
+  [GTK_ACCESSIBLE_ROLE_COMPOSITE] = NC_("accessibility", "composite"),
+  [GTK_ACCESSIBLE_ROLE_DIALOG] = NC_("accessibility", "dialog"),
+  [GTK_ACCESSIBLE_ROLE_DOCUMENT] = NC_("accessibility", "document"),
+  [GTK_ACCESSIBLE_ROLE_FEED] = NC_("accessibility", "feed"),
+  [GTK_ACCESSIBLE_ROLE_FORM] = NC_("accessibility", "form"),
+  [GTK_ACCESSIBLE_ROLE_GENERIC] = NC_("accessibility", "generic"),
+  [GTK_ACCESSIBLE_ROLE_GRID] = NC_("accessibility", "grid"),
+  [GTK_ACCESSIBLE_ROLE_GRID_CELL] = NC_("accessibility", "grid cell"),
+  [GTK_ACCESSIBLE_ROLE_GROUP] = NC_("accessibility", "group"),
+  [GTK_ACCESSIBLE_ROLE_HEADING] = NC_("accessibility", "heading"),
+  [GTK_ACCESSIBLE_ROLE_IMG] = NC_("accessibility", "image"),
+  [GTK_ACCESSIBLE_ROLE_INPUT] = NC_("accessibility", "input"),
+  [GTK_ACCESSIBLE_ROLE_LABEL] = NC_("accessibility", "label"),
+  [GTK_ACCESSIBLE_ROLE_LANDMARK] = NC_("accessibility", "landmark"),
+  [GTK_ACCESSIBLE_ROLE_LEGEND] = NC_("accessibility", "legend"),
+  [GTK_ACCESSIBLE_ROLE_LINK] = NC_("accessibility", "link"),
+  [GTK_ACCESSIBLE_ROLE_LIST] = NC_("accessibility", "list"),
+  [GTK_ACCESSIBLE_ROLE_LIST_BOX] = NC_("accessibility", "list box"),
+  [GTK_ACCESSIBLE_ROLE_LIST_ITEM] = NC_("accessibility", "list item"),
+  [GTK_ACCESSIBLE_ROLE_LOG] = NC_("accessibility", "log"),
+  [GTK_ACCESSIBLE_ROLE_MAIN] = NC_("accessibility", "main"),
+  [GTK_ACCESSIBLE_ROLE_MARQUEE] = NC_("accessibility", "marquee"),
+  [GTK_ACCESSIBLE_ROLE_MATH] = NC_("accessibility", "math"),
+  [GTK_ACCESSIBLE_ROLE_METER] = NC_("accessibility", "meter"),
+  [GTK_ACCESSIBLE_ROLE_MENU] = NC_("accessibility", "menu"),
+  [GTK_ACCESSIBLE_ROLE_MENU_BAR] = NC_("accessibility", "menu bar"),
+  [GTK_ACCESSIBLE_ROLE_MENU_ITEM] = NC_("accessibility", "menu item"),
+  [GTK_ACCESSIBLE_ROLE_MENU_ITEM_CHECKBOX] = NC_("accessibility", "menu item checkbox"),
+  [GTK_ACCESSIBLE_ROLE_MENU_ITEM_RADIO] = NC_("accessibility", "menu item radio"),
+  [GTK_ACCESSIBLE_ROLE_NAVIGATION] = NC_("accessibility", "navigation"),
+  [GTK_ACCESSIBLE_ROLE_NONE] = NC_("accessibility", "none"),
+  [GTK_ACCESSIBLE_ROLE_NOTE] = NC_("accessibility", "note"),
+  [GTK_ACCESSIBLE_ROLE_OPTION] = NC_("accessibility", "option"),
+  [GTK_ACCESSIBLE_ROLE_PRESENTATION] = NC_("accessibility", "presentation"),
+  [GTK_ACCESSIBLE_ROLE_PROGRESS_BAR] = NC_("accessibility", "progress bar"),
+  [GTK_ACCESSIBLE_ROLE_RADIO] = NC_("accessibility", "radio"),
+  [GTK_ACCESSIBLE_ROLE_RADIO_GROUP] = NC_("accessibility", "radio group"),
+  [GTK_ACCESSIBLE_ROLE_RANGE] = NC_("accessibility", "range"),
+  [GTK_ACCESSIBLE_ROLE_REGION] = NC_("accessibility", "region"),
+  [GTK_ACCESSIBLE_ROLE_ROW] = NC_("accessibility", "row"),
+  [GTK_ACCESSIBLE_ROLE_ROW_GROUP] = NC_("accessibility", "row group"),
+  [GTK_ACCESSIBLE_ROLE_ROW_HEADER] = NC_("accessibility", "row header"),
+  [GTK_ACCESSIBLE_ROLE_SCROLLBAR] = NC_("accessibility", "scroll bar"),
+  [GTK_ACCESSIBLE_ROLE_SEARCH] = NC_("accessibility", "search"),
+  [GTK_ACCESSIBLE_ROLE_SEARCH_BOX] = NC_("accessibility", "search box"),
+  [GTK_ACCESSIBLE_ROLE_SECTION] = NC_("accessibility", "section"),
+  [GTK_ACCESSIBLE_ROLE_SECTION_HEAD] = NC_("accessibility", "section head"),
+  [GTK_ACCESSIBLE_ROLE_SELECT] = NC_("accessibility", "select"),
+  [GTK_ACCESSIBLE_ROLE_SEPARATOR] = NC_("accessibility", "separator"),
+  [GTK_ACCESSIBLE_ROLE_SLIDER] = NC_("accessibility", "slider"),
+  [GTK_ACCESSIBLE_ROLE_SPIN_BUTTON] = NC_("accessibility", "spin button"),
+  [GTK_ACCESSIBLE_ROLE_STATUS] = NC_("accessibility", "status"),
+  [GTK_ACCESSIBLE_ROLE_STRUCTURE] = NC_("accessibility", "structure"),
+  [GTK_ACCESSIBLE_ROLE_SWITCH] = NC_("accessibility", "switch"),
+  [GTK_ACCESSIBLE_ROLE_TAB] = NC_("accessibility", "tab"),
+  [GTK_ACCESSIBLE_ROLE_TABLE] = NC_("accessibility", "table"),
+  [GTK_ACCESSIBLE_ROLE_TAB_LIST] = NC_("accessibility", "tab list"),
+  [GTK_ACCESSIBLE_ROLE_TAB_PANEL] = NC_("accessibility", "tab panel"),
+  [GTK_ACCESSIBLE_ROLE_TEXT_BOX] = NC_("accessibility", "text box"),
+  [GTK_ACCESSIBLE_ROLE_TIME] = NC_("accessibility", "time"),
+  [GTK_ACCESSIBLE_ROLE_TIMER] = NC_("accessibility", "timer"),
+  [GTK_ACCESSIBLE_ROLE_TOOLBAR] = NC_("accessibility", "tool bar"),
+  [GTK_ACCESSIBLE_ROLE_TOOLTIP] = NC_("accessibility", "tool tip"),
+  [GTK_ACCESSIBLE_ROLE_TREE] = NC_("accessibility", "tree"),
+  [GTK_ACCESSIBLE_ROLE_TREE_GRID] = NC_("accessibility", "tree grid"),
+  [GTK_ACCESSIBLE_ROLE_TREE_ITEM] = NC_("accessibility", "tree item"),
+  [GTK_ACCESSIBLE_ROLE_WIDGET] = NC_("accessibility", "widget"),
+  [GTK_ACCESSIBLE_ROLE_WINDOW] = NC_("accessibility", "window"),
+};
+
+/*< private >
+ * gtk_accessible_role_to_name:
+ * @role: a #GtkAccessibleRole
+ * @domain: (nullable): the translation domain
+ *
+ * Converts a #GtkAccessibleRole value to the equivalent role name.
+ *
+ * If @domain is not %NULL, the returned string will be localized.
+ *
+ * Returns: (transfer none): the name of the role
+ */
+const char *
+gtk_accessible_role_to_name (GtkAccessibleRole  role,
+                             const char        *domain)
+{
+  if (domain != NULL)
+    return g_dpgettext2 (domain, "accessibility", role_names[role]);
+
+  return role_names[role];
+}
diff --git a/gtk/gtkaccessibleprivate.h b/gtk/gtkaccessibleprivate.h
index aa5701cf50..a118f6c150 100644
--- a/gtk/gtkaccessibleprivate.h
+++ b/gtk/gtkaccessibleprivate.h
@@ -34,4 +34,7 @@ struct _GtkAccessibleInterface
 
 GtkATContext *  gtk_accessible_get_at_context   (GtkAccessible *self);
 
+const char *    gtk_accessible_role_to_name     (GtkAccessibleRole  role,
+                                                 const char        *domain);
+
 G_END_DECLS


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