[gtk/a11y/component: 1/4] atspi: Implement Component
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/a11y/component: 1/4] atspi: Implement Component
- Date: Wed, 14 Oct 2020 01:28:58 +0000 (UTC)
commit 82312f6d4b3a5fede93d21057dad5ae8328f4467
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Oct 13 21:23:22 2020 -0400
atspi: Implement Component
We only implement parts of this interface that
are not questionable, and we ignore coordinate
types - the coordinates we return are always
local (ie ATK_XY_WINDOW, in atk terminology).
gtk/a11y/gtkatspicomponent.c | 187 ++++++++++++++++++++++++++++++++++++
gtk/a11y/gtkatspicomponentprivate.h | 30 ++++++
gtk/a11y/gtkatspicontext.c | 17 ++++
gtk/a11y/gtkatspiprivate.h | 59 ++++++------
gtk/a11y/meson.build | 1 +
5 files changed, 267 insertions(+), 27 deletions(-)
---
diff --git a/gtk/a11y/gtkatspicomponent.c b/gtk/a11y/gtkatspicomponent.c
new file mode 100644
index 0000000000..26f4b45f83
--- /dev/null
+++ b/gtk/a11y/gtkatspicomponent.c
@@ -0,0 +1,187 @@
+/* gtkatspicomponent.c: AT-SPI Component implementation
+ *
+ * Copyright 2020 Red Hat, Inc.
+ *
+ * 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 "gtkatspicomponentprivate.h"
+
+#include "gtkatspicontextprivate.h"
+#include "gtkatspiprivate.h"
+#include "gtkatspiutilsprivate.h"
+#include "gtkaccessibleprivate.h"
+
+#include "a11y/atspi/atspi-component.h"
+
+#include "gtkdebug.h"
+
+#include <gio/gio.h>
+
+static void
+component_handle_method (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ GtkATContext *self = user_data;
+ GtkAccessible *accessible = gtk_at_context_get_accessible (self);
+ GtkWidget *widget = GTK_WIDGET (accessible);
+
+g_print ("%s %s\n", interface_name, method_name);
+ if (g_strcmp0 (method_name, "Contains") == 0)
+ {
+ int x, y;
+ AtspiCoordType coordtype;
+ double xo, yo;
+ gboolean ret;
+
+ g_variant_get (parameters, "(iiu)", &x, &y, &coordtype);
+
+ if (coordtype != ATSPI_COORD_TYPE_WINDOW)
+ g_warning ("Not suppporting screen coordinates, reported positions will be wrong");
+
+ gtk_widget_translate_coordinates (GTK_WIDGET (gtk_widget_get_root (widget)),
+ widget,
+ x, y,
+ &xo, &yo);
+
+ ret = gtk_widget_contains (widget, xo, yo);
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", ret));
+ }
+ else if (g_strcmp0 (method_name, "GetAccessibleAtPoint") == 0)
+ {
+ int x, y;
+ AtspiCoordType coordtype;
+ double xo, yo;
+ GtkWidget *child;
+
+ g_variant_get (parameters, "(iiu)", &x, &y, &coordtype);
+
+ if (coordtype != ATSPI_COORD_TYPE_WINDOW)
+ g_warning ("Not suppporting screen coordinates, reported positions will be wrong");
+
+ gtk_widget_translate_coordinates (GTK_WIDGET (gtk_widget_get_root (widget)),
+ widget,
+ x, y,
+ &xo, &yo);
+
+ child = gtk_widget_pick (widget, xo, yo, GTK_PICK_DEFAULT);
+ if (!child)
+ {
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(@(so))", gtk_at_spi_null_ref
()));
+ }
+ else
+ {
+ GtkAtSpiContext *ctx = GTK_AT_SPI_CONTEXT (gtk_accessible_get_at_context (GTK_ACCESSIBLE (child)));
+
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(@(so))",
gtk_at_spi_context_to_ref (ctx)));
+ }
+ }
+ else if (g_strcmp0 (method_name, "GetExtents") == 0)
+ {
+ AtspiCoordType coordtype;
+ double x, y;
+ int width = gtk_widget_get_width (widget);
+ int height = gtk_widget_get_height (widget);
+
+ g_variant_get (parameters, "(u)", &coordtype);
+
+ if (coordtype != ATSPI_COORD_TYPE_WINDOW)
+ g_warning ("Not suppporting screen coordinates, reported positions will be wrong");
+
+ gtk_widget_translate_coordinates (widget,
+ GTK_WIDGET (gtk_widget_get_root (widget)),
+ 0., 0.,
+ &x, &y);
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("((iiii))", (int)x, (int)y, width,
height));
+ }
+ else if (g_strcmp0 (method_name, "GetPosition") == 0)
+ {
+ AtspiCoordType coordtype;
+ double x, y;
+
+ g_variant_get (parameters, "(u)", &coordtype);
+
+ if (coordtype != ATSPI_COORD_TYPE_WINDOW)
+ g_warning ("Not suppporting screen coordinates, reported positions will be wrong");
+
+ gtk_widget_translate_coordinates (widget,
+ GTK_WIDGET (gtk_widget_get_root (widget)),
+ 0, 0,
+ &x, &y);
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(ii)", (int)x, (int)y));
+ }
+ else if (g_strcmp0 (method_name, "GetSize") == 0)
+ {
+ int width = gtk_widget_get_width (widget);
+ int height = gtk_widget_get_height (widget);
+
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(ii)", width, height));
+ }
+ else if (g_strcmp0 (method_name, "GetLayer") == 0)
+ {
+ g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR, G_DBUS_ERROR_NOT_SUPPORTED,
"");
+ }
+ else if (g_strcmp0 (method_name, "GetMDIZOrder") == 0)
+ {
+ g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR, G_DBUS_ERROR_NOT_SUPPORTED,
"");
+ }
+ else if (g_strcmp0 (method_name, "GrabFocus") == 0)
+ {
+ g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR, G_DBUS_ERROR_NOT_SUPPORTED,
"");
+ }
+ else if (g_strcmp0 (method_name, "GetAlpha") == 0)
+ {
+ g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR, G_DBUS_ERROR_NOT_SUPPORTED,
"");
+ }
+ else if (g_strcmp0 (method_name, "SetExtents") == 0)
+ {
+ g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR, G_DBUS_ERROR_NOT_SUPPORTED,
"");
+ }
+ else if (g_strcmp0 (method_name, "SetPosition") == 0)
+ {
+ g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR, G_DBUS_ERROR_NOT_SUPPORTED,
"");
+ }
+ else if (g_strcmp0 (method_name, "SetSize") == 0)
+ {
+ g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR, G_DBUS_ERROR_NOT_SUPPORTED,
"");
+ }
+ else if (g_strcmp0 (method_name, "ScrollTo") == 0)
+ {
+ g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR, G_DBUS_ERROR_NOT_SUPPORTED,
"");
+ }
+ else if (g_strcmp0 (method_name, "ScrollToPoint") == 0)
+ {
+ g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR, G_DBUS_ERROR_NOT_SUPPORTED,
"");
+ }
+}
+
+static const GDBusInterfaceVTable component_vtable = {
+ component_handle_method,
+};
+
+const GDBusInterfaceVTable *
+gtk_atspi_get_component_vtable (GtkWidget *widget)
+{
+ return &component_vtable;
+}
diff --git a/gtk/a11y/gtkatspicomponentprivate.h b/gtk/a11y/gtkatspicomponentprivate.h
new file mode 100644
index 0000000000..6321ecada5
--- /dev/null
+++ b/gtk/a11y/gtkatspicomponentprivate.h
@@ -0,0 +1,30 @@
+/* gtkatspicomponentprivate.h: AT-SPI Component implementation
+ *
+ * Copyright 2020 Red Hat, Inc.
+ *
+ * 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/>.
+ */
+
+#pragma once
+
+#include <gio/gio.h>
+#include "gtkwidget.h"
+
+G_BEGIN_DECLS
+
+const GDBusInterfaceVTable *gtk_atspi_get_component_vtable (GtkWidget *widget);
+
+G_END_DECLS
diff --git a/gtk/a11y/gtkatspicontext.c b/gtk/a11y/gtkatspicontext.c
index 96d546f78e..99987d6250 100644
--- a/gtk/a11y/gtkatspicontext.c
+++ b/gtk/a11y/gtkatspicontext.c
@@ -32,12 +32,14 @@
#include "gtkatspieditabletextprivate.h"
#include "gtkatspivalueprivate.h"
#include "gtkatspiselectionprivate.h"
+#include "gtkatspicomponentprivate.h"
#include "a11y/atspi/atspi-accessible.h"
#include "a11y/atspi/atspi-text.h"
#include "a11y/atspi/atspi-editabletext.h"
#include "a11y/atspi/atspi-value.h"
#include "a11y/atspi/atspi-selection.h"
+#include "a11y/atspi/atspi-component.h"
#include "gtkdebug.h"
#include "gtkeditable.h"
@@ -614,6 +616,21 @@ gtk_at_spi_context_register_object (GtkAtSpiContext *self)
NULL);
self->n_registered_objects++;
+ vtable = gtk_atspi_get_component_vtable (widget);
+ if (vtable)
+ {
+ g_variant_builder_add (&interfaces, "s", atspi_component_interface.name);
+ self->registration_ids[self->n_registered_objects] =
+ g_dbus_connection_register_object (self->connection,
+ self->context_path,
+ (GDBusInterfaceInfo *) &atspi_component_interface,
+ vtable,
+ self,
+ NULL,
+ NULL);
+ self->n_registered_objects++;
+ }
+
vtable = gtk_atspi_get_text_vtable (widget);
if (vtable)
{
diff --git a/gtk/a11y/gtkatspiprivate.h b/gtk/a11y/gtkatspiprivate.h
index c3fa225df8..fc458f41c0 100644
--- a/gtk/a11y/gtkatspiprivate.h
+++ b/gtk/a11y/gtkatspiprivate.h
@@ -206,36 +206,36 @@ typedef enum {
} AtspiStateType;
typedef enum {
- ATSPI_RELATION_NULL,
- ATSPI_RELATION_LABEL_FOR,
- ATSPI_RELATION_LABELLED_BY,
- ATSPI_RELATION_CONTROLLER_FOR,
- ATSPI_RELATION_CONTROLLED_BY,
- ATSPI_RELATION_MEMBER_OF,
- ATSPI_RELATION_TOOLTIP_FOR,
- ATSPI_RELATION_NODE_CHILD_OF,
- ATSPI_RELATION_NODE_PARENT_OF,
- ATSPI_RELATION_EXTENDED,
- ATSPI_RELATION_FLOWS_TO,
- ATSPI_RELATION_FLOWS_FROM,
- ATSPI_RELATION_SUBWINDOW_OF,
- ATSPI_RELATION_EMBEDS,
- ATSPI_RELATION_EMBEDDED_BY,
- ATSPI_RELATION_POPUP_FOR,
- ATSPI_RELATION_PARENT_WINDOW_OF,
- ATSPI_RELATION_DESCRIPTION_FOR,
- ATSPI_RELATION_DESCRIBED_BY,
- ATSPI_RELATION_LAST_DEFINED,
+ ATSPI_RELATION_NULL,
+ ATSPI_RELATION_LABEL_FOR,
+ ATSPI_RELATION_LABELLED_BY,
+ ATSPI_RELATION_CONTROLLER_FOR,
+ ATSPI_RELATION_CONTROLLED_BY,
+ ATSPI_RELATION_MEMBER_OF,
+ ATSPI_RELATION_TOOLTIP_FOR,
+ ATSPI_RELATION_NODE_CHILD_OF,
+ ATSPI_RELATION_NODE_PARENT_OF,
+ ATSPI_RELATION_EXTENDED,
+ ATSPI_RELATION_FLOWS_TO,
+ ATSPI_RELATION_FLOWS_FROM,
+ ATSPI_RELATION_SUBWINDOW_OF,
+ ATSPI_RELATION_EMBEDS,
+ ATSPI_RELATION_EMBEDDED_BY,
+ ATSPI_RELATION_POPUP_FOR,
+ ATSPI_RELATION_PARENT_WINDOW_OF,
+ ATSPI_RELATION_DESCRIPTION_FOR,
+ ATSPI_RELATION_DESCRIBED_BY,
+ ATSPI_RELATION_LAST_DEFINED,
} AtspiRelationType;
typedef enum {
- ATSPI_TEXT_BOUNDARY_CHAR,
- ATSPI_TEXT_BOUNDARY_WORD_START,
- ATSPI_TEXT_BOUNDARY_WORD_END,
- ATSPI_TEXT_BOUNDARY_SENTENCE_START,
- ATSPI_TEXT_BOUNDARY_SENTENCE_END,
- ATSPI_TEXT_BOUNDARY_LINE_START,
- ATSPI_TEXT_BOUNDARY_LINE_END,
+ ATSPI_TEXT_BOUNDARY_CHAR,
+ ATSPI_TEXT_BOUNDARY_WORD_START,
+ ATSPI_TEXT_BOUNDARY_WORD_END,
+ ATSPI_TEXT_BOUNDARY_SENTENCE_START,
+ ATSPI_TEXT_BOUNDARY_SENTENCE_END,
+ ATSPI_TEXT_BOUNDARY_LINE_START,
+ ATSPI_TEXT_BOUNDARY_LINE_END,
} AtspiTextBoundaryType;
typedef enum {
@@ -246,4 +246,9 @@ typedef enum {
ATSPI_TEXT_GRANULARITY_PARAGRAPH
} AtspiTextGranularity;
+typedef enum {
+ ATSPI_COORD_TYPE_SCREEN,
+ ATSPI_COORD_TYPE_WINDOW,
+} AtspiCoordType;
+
G_END_DECLS
diff --git a/gtk/a11y/meson.build b/gtk/a11y/meson.build
index 49359159ae..a28e5f27de 100644
--- a/gtk/a11y/meson.build
+++ b/gtk/a11y/meson.build
@@ -19,5 +19,6 @@ if gtk_a11y_backends.contains('atspi')
'gtkatspivalue.c',
'gtkatspieditabletext.c',
'gtkatspiselection.c',
+ 'gtkatspicomponent.c',
])
endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]