[gtk/matthiasc/a11y: 7/7] wip: Begin implementing Text for labels
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/a11y: 7/7] wip: Begin implementing Text for labels
- Date: Sat, 10 Oct 2020 16:28:55 +0000 (UTC)
commit af3b86e43d347c902089913477c6ee1d5f3cd44c
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Oct 9 23:35:00 2020 -0400
wip: Begin implementing Text for labels
This is just a bare-bones implementation of GetText,
and a stubbed out GetAttributes. Just enough to make
label text show up in accerciser.
gtk/a11y/gtkatspicontext.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 98 insertions(+)
---
diff --git a/gtk/a11y/gtkatspicontext.c b/gtk/a11y/gtkatspicontext.c
index d932f06c2c..f531a2b288 100644
--- a/gtk/a11y/gtkatspicontext.c
+++ b/gtk/a11y/gtkatspicontext.c
@@ -421,6 +421,8 @@ handle_accessible_method (GDBusConnection *connection,
GVariantBuilder builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("as"));
g_variant_builder_add (&builder, "s", "org.a11y.atspi.Accessible");
+ if (GTK_IS_LABEL (accessible))
+ g_variant_builder_add (&builder, "s", "org.a11y.atspi.Text");
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(as)", &builder));
}
@@ -505,6 +507,91 @@ static const GDBusInterfaceVTable accessible_vtable = {
NULL,
};
+static void
+handle_text_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)
+{
+ GtkAtSpiContext *self = user_data;
+ GtkAccessible *accessible = gtk_at_context_get_accessible (GTK_AT_CONTEXT (self));
+ GtkWidget *widget = GTK_WIDGET (accessible);
+
+ if (g_strcmp0 (method_name, "GetText") == 0)
+ {
+ int start, end;
+ const char *text;
+ const char *p, *q;
+ char *substring;
+
+ g_variant_get (parameters, "(ii)", &start, &end);
+
+ text = gtk_label_get_text (GTK_LABEL (widget));
+ p = g_utf8_offset_to_pointer (text, start);
+ q = g_utf8_offset_to_pointer (text, end);
+
+ substring = g_strndup (p, q - p);
+
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", substring));
+ g_free (substring);
+ }
+ else if (g_strcmp0 (method_name, "GetAttributes") == 0)
+ {
+ int offset;
+ GVariantBuilder builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("a{ss}"));
+ const char *text;
+ int len;
+
+ g_variant_get (parameters, "(i)", &offset);
+
+ text = gtk_label_get_text (GTK_LABEL (widget));
+ len = g_utf8_strlen (text, -1);
+
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(a{ss}ii)", &builder, 0, len));
+ }
+}
+
+static GVariant *
+handle_text_get_property (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *property_name,
+ GError **error,
+ gpointer user_data)
+{
+ GtkAtSpiContext *self = user_data;
+ GtkAccessible *accessible = gtk_at_context_get_accessible (GTK_AT_CONTEXT (self));
+ GtkWidget *widget = GTK_WIDGET (accessible);
+
+ if (g_strcmp0 (property_name, "CharacterCount") == 0)
+ {
+ const char *text;
+ int len;
+
+ text = gtk_label_get_text (GTK_LABEL (widget));
+ len = g_utf8_strlen (text, -1);
+
+ return g_variant_new_int32 (len);
+ }
+ else if (g_strcmp0 (property_name, "CaretOffset") == 0)
+ {
+ return g_variant_new_int32 (0);
+ }
+
+ return NULL;
+}
+
+static const GDBusInterfaceVTable text_vtable = {
+ handle_text_method,
+ handle_text_get_property,
+ NULL,
+};
+
static void
gtk_at_spi_context_register_object (GtkAtSpiContext *self)
{
@@ -515,6 +602,17 @@ gtk_at_spi_context_register_object (GtkAtSpiContext *self)
self,
NULL,
NULL);
+
+ if (GTK_IS_LABEL (gtk_at_context_get_accessible (GTK_AT_CONTEXT (self))))
+ {
+ g_dbus_connection_register_object (self->connection,
+ self->context_path,
+ (GDBusInterfaceInfo *) &atspi_text_interface,
+ &text_vtable,
+ self,
+ NULL,
+ NULL);
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]