Implemented GetStringAtOffset in the text adaptor in the ATK bridge
authorMario Sanchez Prada <mario.prada@samsung.com>
Tue, 6 Aug 2013 11:06:36 +0000 (13:06 +0200)
committerMike Gorse <mgorse@suse.com>
Mon, 19 Aug 2013 16:26:45 +0000 (11:26 -0500)
Also, raised the version of the ATK dependency up to 2.9.4.

https://bugzilla.gnome.org/show_bug.cgi?id=705581

atk-adaptor/adaptors/text-adaptor.c
atk-adaptor/introspection.c
configure.ac

index f039d2e..bd9a4c6 100644 (file)
@@ -254,6 +254,100 @@ impl_GetCharacterAtOffset (DBusConnection * bus, DBusMessage * message,
   return reply;
 }
 
+static gchar *
+get_text_for_legacy_implementations(AtkText *text,
+                                    gint offset,
+                                    AtkTextGranularity granularity,
+                                    gint *start_offset,
+                                    gint *end_offset)
+{
+  gchar *txt = 0;
+  AtkTextBoundary boundary = 0;
+  switch (granularity) {
+  case ATK_TEXT_GRANULARITY_CHAR:
+    boundary = ATK_TEXT_BOUNDARY_CHAR;
+    break;
+
+  case ATK_TEXT_GRANULARITY_WORD:
+    boundary = ATK_TEXT_BOUNDARY_WORD_START;
+    break;
+
+  case ATK_TEXT_GRANULARITY_SENTENCE:
+    boundary = ATK_TEXT_BOUNDARY_SENTENCE_START;
+    break;
+
+  case ATK_TEXT_GRANULARITY_LINE:
+    boundary = ATK_TEXT_BOUNDARY_LINE_START;
+    break;
+
+  case ATK_TEXT_GRANULARITY_PARAGRAPH:
+    /* This is not implemented in previous versions of ATK */
+    txt = g_strdup("");
+    break;
+
+  default:
+    g_assert_not_reached();
+  }
+
+  if (!txt)
+    {
+      txt =
+        atk_text_get_text_at_offset (text, offset, boundary,
+                                     start_offset, end_offset);
+    }
+
+  return txt;
+}
+
+static DBusMessage *
+impl_GetStringAtOffset (DBusConnection * bus, DBusMessage * message,
+                        void *user_data)
+{
+  AtkText *text = (AtkText *) user_data;
+  dbus_int32_t offset;
+  dbus_uint32_t granularity;
+  gchar *txt = 0;
+  dbus_int32_t startOffset, endOffset;
+  gint intstart_offset = 0, intend_offset = 0;
+  DBusMessage *reply;
+
+  g_return_val_if_fail (ATK_IS_TEXT (user_data),
+                        droute_not_yet_handled_error (message));
+  if (!dbus_message_get_args
+      (message, NULL, DBUS_TYPE_INT32, &offset, DBUS_TYPE_UINT32, &granularity,
+       DBUS_TYPE_INVALID))
+    {
+      return droute_invalid_arguments_error (message);
+    }
+
+  txt =
+    atk_text_get_string_at_offset (text, offset, (AtkTextGranularity) granularity,
+                                   &intstart_offset, &intend_offset);
+
+  /* Accessibility layers implementing an older version of ATK (even if
+   * a new enough version of libatk is installed) might return NULL due
+   * not to provide an implementation for get_string_at_offset(), so we
+   * try with the legacy implementation if that's the case. */
+  if (!txt)
+    txt = get_text_for_legacy_implementations(text, offset,
+                                              (AtkTextGranularity) granularity,
+                                              &intstart_offset, &intend_offset);
+
+  startOffset = intstart_offset;
+  endOffset = intend_offset;
+  txt = validate_allocated_string (txt);
+  reply = dbus_message_new_method_return (message);
+  if (reply)
+    {
+      dbus_message_append_args (reply, DBUS_TYPE_STRING, &txt,
+                                DBUS_TYPE_INT32, &startOffset,
+                                DBUS_TYPE_INT32, &endOffset,
+                                DBUS_TYPE_INVALID);
+    }
+  g_free (txt);
+  return reply;
+}
+
 static DBusMessage *
 impl_GetAttributeValue (DBusConnection * bus, DBusMessage * message,
                         void *user_data)
@@ -757,6 +851,7 @@ static DRouteMethod methods[] = {
   {impl_GetTextBeforeOffset, "GetTextBeforeOffset"},
   {impl_GetTextAtOffset, "GetTextAtOffset"},
   {impl_GetTextAfterOffset, "GetTextAfterOffset"},
+  {impl_GetStringAtOffset, "GetStringAtOffset"},
   {impl_GetCharacterAtOffset, "GetCharacterAtOffset"},
   {impl_GetAttributeValue, "GetAttributeValue"},
   {impl_GetAttributes, "GetAttributes"},
index 838d933..7d0658d 100644 (file)
@@ -548,6 +548,14 @@ const char *spi_org_a11y_atspi_Text =
 "    <arg direction=\"out\" name=\"endOffset\" type=\"i\" />"
 "  </method>"
 ""
+"  <method name=\"GetStringAtOffset\">"
+"    <arg direction=\"in\" name=\"offset\" type=\"i\" />"
+"    <arg direction=\"in\" name=\"granularity\" type=\"u\" />"
+"    <arg direction=\"out\" type=\"s\" />"
+"    <arg direction=\"out\" name=\"startOffset\" type=\"i\" />"
+"    <arg direction=\"out\" name=\"endOffset\" type=\"i\" />"
+"  </method>"
+""
 "  <method name=\"GetCharacterAtOffset\">"
 "    <arg direction=\"in\" name=\"offset\" type=\"i\" />"
 "    <arg direction=\"out\" type=\"i\" />"
index 0b3604e..7409a89 100644 (file)
@@ -51,7 +51,7 @@ PKG_CHECK_MODULES(GMODULE, [gmodule-2.0 >= 2.0.0])
 AC_SUBST(GMODULE_LIBS)
 AC_SUBST(GMODULE_CFLAGS)
 
-PKG_CHECK_MODULES(ATK, [atk >= 2.7.90])
+PKG_CHECK_MODULES(ATK, [atk >= 2.9.4])
 AC_SUBST(ATK_LIBS)
 AC_SUBST(ATK_CFLAGS)