[gtk/a11y/atspi: 19/24] a11y: Convert GTK roles to ATSPI ones




commit bb770033c465abf5946140f495b7ba7bbf4b51c1
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Fri Oct 9 22:01:00 2020 +0100

    a11y: Convert GTK roles to ATSPI ones
    
    There's not a precise, 1:1 mapping between the newer ARIA roles and the
    older ATSPI ones. We make do with what we have.

 gtk/a11y/gtkatspiutils.c        | 277 ++++++++++++++++++++++++++++++++++++++++
 gtk/a11y/gtkatspiutilsprivate.h |  29 +++++
 gtk/a11y/meson.build            |   1 +
 3 files changed, 307 insertions(+)
---
diff --git a/gtk/a11y/gtkatspiutils.c b/gtk/a11y/gtkatspiutils.c
new file mode 100644
index 0000000000..4233904bb5
--- /dev/null
+++ b/gtk/a11y/gtkatspiutils.c
@@ -0,0 +1,277 @@
+/* gtkatspiutils.c: Shared utilities for ATSPI
+ *
+ * Copyright 2020  GNOME Foundation
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gtkatspiutilsprivate.h"
+
+/*< private >
+ * gtk_accessible_role_to_atspi_role:
+ * @role: a #GtkAccessibleRole
+ *
+ * Converts a #GtkAccessibleRole value to the equivalent ATSPI role.
+ *
+ * Returns: an #AtspiRole
+ */
+AtspiRole
+gtk_accessible_role_to_atspi_role (GtkAccessibleRole role)
+{
+  switch (role)
+    {
+    case GTK_ACCESSIBLE_ROLE_ALERT:
+      return ATSPI_ROLE_ALERT;
+
+    case GTK_ACCESSIBLE_ROLE_ALERT_DIALOG:
+      return ATSPI_ROLE_DIALOG;
+
+    case GTK_ACCESSIBLE_ROLE_BANNER:
+      break;
+
+    case GTK_ACCESSIBLE_ROLE_BUTTON:
+      return ATSPI_ROLE_PUSH_BUTTON;
+
+    case GTK_ACCESSIBLE_ROLE_CAPTION:
+      return ATSPI_ROLE_CAPTION;
+
+    case GTK_ACCESSIBLE_ROLE_CELL:
+      return ATSPI_ROLE_TABLE_CELL;
+
+    case GTK_ACCESSIBLE_ROLE_CHECKBOX:
+      return ATSPI_ROLE_CHECK_BOX;
+
+    case GTK_ACCESSIBLE_ROLE_COLUMN_HEADER:
+      break;
+
+    case GTK_ACCESSIBLE_ROLE_COMBO_BOX:
+      return ATSPI_ROLE_COMBO_BOX;
+
+    case GTK_ACCESSIBLE_ROLE_COMMAND:
+      break;
+
+    case GTK_ACCESSIBLE_ROLE_COMPOSITE:
+      break;
+
+    case GTK_ACCESSIBLE_ROLE_DIALOG:
+      return ATSPI_ROLE_DIALOG;
+
+    case GTK_ACCESSIBLE_ROLE_DOCUMENT:
+      return ATSPI_ROLE_DOCUMENT_TEXT;
+
+    case GTK_ACCESSIBLE_ROLE_FEED:
+      break;
+
+    case GTK_ACCESSIBLE_ROLE_FORM:
+      break;
+
+    case GTK_ACCESSIBLE_ROLE_GENERIC:
+      break;
+
+    case GTK_ACCESSIBLE_ROLE_GRID:
+      return ATSPI_ROLE_TABLE;
+
+    case GTK_ACCESSIBLE_ROLE_GRID_CELL:
+      return ATSPI_ROLE_TABLE_CELL;
+
+    case GTK_ACCESSIBLE_ROLE_GROUP:
+      break;
+
+    case GTK_ACCESSIBLE_ROLE_HEADING:
+      break;
+
+    case GTK_ACCESSIBLE_ROLE_IMG:
+      return ATSPI_ROLE_IMAGE;
+
+    case GTK_ACCESSIBLE_ROLE_INPUT:
+      return ATSPI_ROLE_ENTRY;
+
+    case GTK_ACCESSIBLE_ROLE_LABEL:
+      return ATSPI_ROLE_LABEL;
+
+    case GTK_ACCESSIBLE_ROLE_LANDMARK:
+      break;
+
+    case GTK_ACCESSIBLE_ROLE_LEGEND:
+      break;
+
+    case GTK_ACCESSIBLE_ROLE_LINK:
+      return ATSPI_ROLE_LINK;
+
+    case GTK_ACCESSIBLE_ROLE_LIST:
+      return ATSPI_ROLE_LIST;
+
+    case GTK_ACCESSIBLE_ROLE_LIST_BOX:
+      return ATSPI_ROLE_LIST_BOX;
+
+    case GTK_ACCESSIBLE_ROLE_LIST_ITEM:
+      return ATSPI_ROLE_LIST_ITEM;
+
+    case GTK_ACCESSIBLE_ROLE_LOG:
+      return ATSPI_ROLE_LOG;
+
+    case GTK_ACCESSIBLE_ROLE_MAIN:
+      break;
+
+    case GTK_ACCESSIBLE_ROLE_MARQUEE:
+      return ATSPI_ROLE_MARQUEE;
+
+    case GTK_ACCESSIBLE_ROLE_MATH:
+      return ATSPI_ROLE_MATH;;
+
+    case GTK_ACCESSIBLE_ROLE_METER:
+      return ATSPI_ROLE_LEVEL_BAR;
+
+    case GTK_ACCESSIBLE_ROLE_MENU:
+      return ATSPI_ROLE_MENU;
+
+    case GTK_ACCESSIBLE_ROLE_MENU_BAR:
+      return ATSPI_ROLE_MENU_BAR;
+
+    case GTK_ACCESSIBLE_ROLE_MENU_ITEM:
+      return ATSPI_ROLE_MENU_ITEM;
+
+    case GTK_ACCESSIBLE_ROLE_MENU_ITEM_CHECKBOX:
+      return ATSPI_ROLE_CHECK_MENU_ITEM;
+
+    case GTK_ACCESSIBLE_ROLE_MENU_ITEM_RADIO:
+      return ATSPI_ROLE_RADIO_MENU_ITEM;
+
+    case GTK_ACCESSIBLE_ROLE_NAVIGATION:
+      return ATSPI_ROLE_FILLER;
+
+    case GTK_ACCESSIBLE_ROLE_NONE:
+      return ATSPI_ROLE_INVALID;
+
+    case GTK_ACCESSIBLE_ROLE_NOTE:
+      return ATSPI_ROLE_FOOTNOTE;
+
+    case GTK_ACCESSIBLE_ROLE_OPTION:
+      return ATSPI_ROLE_OPTION_PANE;
+
+    case GTK_ACCESSIBLE_ROLE_PRESENTATION:
+      return ATSPI_ROLE_DOCUMENT_PRESENTATION;
+
+    case GTK_ACCESSIBLE_ROLE_PROGRESS_BAR:
+      return ATSPI_ROLE_PROGRESS_BAR;
+
+    case GTK_ACCESSIBLE_ROLE_RADIO:
+      return ATSPI_ROLE_RADIO_BUTTON;
+
+    case GTK_ACCESSIBLE_ROLE_RADIO_GROUP:
+      return ATSPI_ROLE_GROUPING;
+
+    case GTK_ACCESSIBLE_ROLE_RANGE:
+      break;
+
+    case GTK_ACCESSIBLE_ROLE_REGION:
+      return ATSPI_ROLE_FILLER;
+
+    case GTK_ACCESSIBLE_ROLE_ROW:
+      return ATSPI_ROLE_TABLE_ROW;
+
+    case GTK_ACCESSIBLE_ROLE_ROW_GROUP:
+      return ATSPI_ROLE_GROUPING;
+
+    case GTK_ACCESSIBLE_ROLE_ROW_HEADER:
+      return ATSPI_ROLE_ROW_HEADER;
+
+    case GTK_ACCESSIBLE_ROLE_SCROLLBAR:
+      return ATSPI_ROLE_SCROLL_BAR;
+
+    case GTK_ACCESSIBLE_ROLE_SEARCH:
+      return ATSPI_ROLE_FORM;
+
+    case GTK_ACCESSIBLE_ROLE_SEARCH_BOX:
+      return ATSPI_ROLE_ENTRY;
+
+    case GTK_ACCESSIBLE_ROLE_SECTION:
+      return ATSPI_ROLE_FILLER;
+
+    case GTK_ACCESSIBLE_ROLE_SECTION_HEAD:
+      return ATSPI_ROLE_FILLER;
+
+    case GTK_ACCESSIBLE_ROLE_SELECT:
+      return ATSPI_ROLE_FILLER;
+
+    case GTK_ACCESSIBLE_ROLE_SEPARATOR:
+      return ATSPI_ROLE_SEPARATOR;
+
+    case GTK_ACCESSIBLE_ROLE_SLIDER:
+      return ATSPI_ROLE_SLIDER;
+
+    case GTK_ACCESSIBLE_ROLE_SPIN_BUTTON:
+      return ATSPI_ROLE_SPIN_BUTTON;
+
+    case GTK_ACCESSIBLE_ROLE_STATUS:
+      return ATSPI_ROLE_STATUS_BAR;
+
+    case GTK_ACCESSIBLE_ROLE_STRUCTURE:
+      return ATSPI_ROLE_FILLER;
+
+    case GTK_ACCESSIBLE_ROLE_SWITCH:
+      return ATSPI_ROLE_CHECK_BOX;
+
+    case GTK_ACCESSIBLE_ROLE_TAB:
+      return ATSPI_ROLE_FILLER;
+
+    case GTK_ACCESSIBLE_ROLE_TABLE:
+      return ATSPI_ROLE_TABLE;
+
+    case GTK_ACCESSIBLE_ROLE_TAB_LIST:
+      return ATSPI_ROLE_FILLER;
+
+    case GTK_ACCESSIBLE_ROLE_TAB_PANEL:
+      return ATSPI_ROLE_FILLER;
+
+    case GTK_ACCESSIBLE_ROLE_TEXT_BOX:
+      return ATSPI_ROLE_TEXT;
+
+    case GTK_ACCESSIBLE_ROLE_TIME:
+      return ATSPI_ROLE_TEXT;
+
+    case GTK_ACCESSIBLE_ROLE_TIMER:
+      return ATSPI_ROLE_TIMER;
+
+    case GTK_ACCESSIBLE_ROLE_TOOLBAR:
+      return ATSPI_ROLE_TOOL_BAR;
+
+    case GTK_ACCESSIBLE_ROLE_TOOLTIP:
+      return ATSPI_ROLE_TOOL_TIP;
+
+    case GTK_ACCESSIBLE_ROLE_TREE:
+      return ATSPI_ROLE_TREE;
+
+    case GTK_ACCESSIBLE_ROLE_TREE_GRID:
+      return ATSPI_ROLE_TREE_TABLE;
+
+    case GTK_ACCESSIBLE_ROLE_TREE_ITEM:
+      return ATSPI_ROLE_TREE_ITEM;
+
+    case GTK_ACCESSIBLE_ROLE_WIDGET:
+      return ATSPI_ROLE_FILLER;
+
+    case GTK_ACCESSIBLE_ROLE_WINDOW:
+      return ATSPI_ROLE_WINDOW;
+
+    default:
+      break;
+    }
+
+  return GTK_ACCESSIBLE_ROLE_WIDGET;
+}
diff --git a/gtk/a11y/gtkatspiutilsprivate.h b/gtk/a11y/gtkatspiutilsprivate.h
new file mode 100644
index 0000000000..b882585a01
--- /dev/null
+++ b/gtk/a11y/gtkatspiutilsprivate.h
@@ -0,0 +1,29 @@
+/* gtkatspiutilsprivate.h: Shared utilities for AT-SPI
+ *
+ * Copyright 2020  GNOME Foundation
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gtkatspiprivate.h"
+#include "gtkenums.h"
+
+G_BEGIN_DECLS
+
+AtspiRole
+gtk_accessible_role_to_atspi_role (GtkAccessibleRole role);
+
+G_END_DECLS
diff --git a/gtk/a11y/meson.build b/gtk/a11y/meson.build
index d18682637a..e682aa33e7 100644
--- a/gtk/a11y/meson.build
+++ b/gtk/a11y/meson.build
@@ -12,5 +12,6 @@ if gtk_a11y_backends.contains('atspi')
     'gtkatspicache.c',
     'gtkatspicontext.c',
     'gtkatspiroot.c',
+    'gtkatspiutils.c',
   ])
 endif


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