[gtk/a11y/atspi-action] a11y: Add atspi.Action for GtkEntry



commit e5a5e35995b78d0301c61b1474ed2f724751e4b0
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Oct 15 19:15:12 2020 +0100

    a11y: Add atspi.Action for GtkEntry
    
    We need to handle the activation on the entry widget, as well as the
    activation of the primary and secondary icons.

 gtk/a11y/gtkatspiaction.c | 123 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 120 insertions(+), 3 deletions(-)
---
diff --git a/gtk/a11y/gtkatspiaction.c b/gtk/a11y/gtkatspiaction.c
index bd5e54c77c..56a84a2abd 100644
--- a/gtk/a11y/gtkatspiaction.c
+++ b/gtk/a11y/gtkatspiaction.c
@@ -30,6 +30,7 @@
 #include "gtkactionable.h"
 #include "gtkactionmuxerprivate.h"
 #include "gtkbutton.h"
+#include "gtkentry.h"
 #include "gtkexpander.h"
 #include "gtkswitch.h"
 #include "gtkwidgetprivate.h"
@@ -44,6 +45,8 @@ struct _Action
   const char *localized_name;
   const char *description;
   const char *keybinding;
+
+  gboolean (* is_enabled) (GtkAtSpiContext *context);
 };
 
 static void
@@ -140,6 +143,9 @@ action_handle_method (GtkAtSpiContext        *self,
         {
           const Action *action = &actions[i];
 
+          if (action->is_enabled != NULL && !action->is_enabled (self))
+            continue;
+
           g_variant_builder_add (&builder, "(sss)",
                                  g_dpgettext2 (GETTEXT_PACKAGE, "accessibility", action->localized_name),
                                  g_dpgettext2 (GETTEXT_PACKAGE, "accessibility", action->description),
@@ -164,8 +170,17 @@ action_handle_method (GtkAtSpiContext        *self,
 
       if (idx >= 0 && idx < n_actions)
         {
-          gtk_widget_activate (widget);
-          g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
+          const Action *action = &actions[idx];
+
+          if (action->is_enabled == NULL || action->is_enabled (self))
+            {
+              gtk_widget_activate (widget);
+              g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
+            }
+          else
+            {
+              g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", FALSE));
+            }
         }
       else
         {
@@ -186,7 +201,19 @@ action_handle_get_property (GtkAtSpiContext  *self,
                             int               n_actions)
 {
   if (g_strcmp0 (property_name, "NActions") == 0)
-    return g_variant_new_int32 (n_actions);
+    {
+      int n_valid_actions = 0;
+
+      for (int i = 0; i < n_actions; i++)
+        {
+          const Action *action = &actions[i];
+
+          if (action->is_enabled == NULL || action->is_enabled (self))
+            n_valid_actions += 1;
+        }
+
+      return g_variant_new_int32 (n_valid_actions);
+    }
 
   g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
                "Unknown property '%s'", property_name);
@@ -349,6 +376,94 @@ static const GDBusInterfaceVTable expander_action_vtable = {
 
 /* }}} */
 
+/* {{{ GtkEntry */
+
+static gboolean is_primary_icon_enabled (GtkAtSpiContext *self);
+static gboolean is_secondary_icon_enabled (GtkAtSpiContext *self);
+
+static const Action entry_actions[] = {
+  {
+    .name = "activate",
+    .localized_name = NC_("accessibility", "Activate"),
+    .description = NC_("accessibility", "Activates the entry"),
+    .keybinding = "<Return>",
+    .is_enabled = NULL,
+  },
+  {
+    .name = "activate-primary-icon",
+    .localized_name = NC_("accessibility", "Activate primary icon"),
+    .description = NC_("accessibility", "Activates the primary icon of the entry"),
+    .keybinding = "<VoidSymbol>",
+    .is_enabled = is_primary_icon_enabled,
+  },
+  {
+    .name = "activate-secondary-icon",
+    .localized_name = NC_("accessibility", "Activate secondary icon"),
+    .description = NC_("accessibility", "Activates the secondary icon of the entry"),
+    .keybinding = "<VoidSymbol>",
+    .is_enabled = is_secondary_icon_enabled,
+  },
+};
+
+static gboolean
+is_primary_icon_enabled (GtkAtSpiContext *self)
+{
+  GtkAccessible *accessible = gtk_at_context_get_accessible (GTK_AT_CONTEXT (self));
+  GtkEntry *entry = GTK_ENTRY (accessible);
+
+  return gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_PRIMARY) != GTK_IMAGE_EMPTY;
+}
+
+static gboolean
+is_secondary_icon_enabled (GtkAtSpiContext *self)
+{
+  GtkAccessible *accessible = gtk_at_context_get_accessible (GTK_AT_CONTEXT (self));
+  GtkEntry *entry = GTK_ENTRY (accessible);
+
+  return gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) != GTK_IMAGE_EMPTY;
+}
+
+static void
+entry_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)
+{
+  GtkAtSpiContext *self = user_data;
+
+  action_handle_method (self, method_name, parameters, invocation,
+                        entry_actions,
+                        G_N_ELEMENTS (entry_actions));
+}
+
+static GVariant *
+entry_handle_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;
+
+  return action_handle_get_property (self, property_name, error,
+                                     entry_actions,
+                                     G_N_ELEMENTS (entry_actions));
+}
+
+static const GDBusInterfaceVTable entry_action_vtable = {
+  entry_handle_method,
+  entry_handle_get_property,
+  NULL,
+};
+
+/* }}} */
+
 static gboolean
 is_valid_action (GtkActionMuxer *muxer,
                  const char     *action_name)
@@ -562,6 +677,8 @@ gtk_atspi_get_action_vtable (GtkAccessible *accessible)
 {
   if (GTK_IS_BUTTON (accessible))
     return &button_action_vtable;
+  else if (GTK_IS_ENTRY (accessible))
+    return &entry_action_vtable;
   else if (GTK_IS_EXPANDER (accessible))
     return &expander_action_vtable;
   else if (GTK_IS_SWITCH (accessible))


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