[gtk/a11y/atspi] atspi: Implement Selection for notebook tabs
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/a11y/atspi] atspi: Implement Selection for notebook tabs
- Date: Thu, 15 Oct 2020 01:04:53 +0000 (UTC)
commit bf04beb7111580e5ca3d2d71a362a009e9b49b6d
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Oct 14 20:52:33 2020 -0400
atspi: Implement Selection for notebook tabs
This is a bit different from the way things were done
in GTK 3 - we follow what was done for GtkStackSwitcher,
and make the tab bar carry the GTK_ACCESSIBLE_TAB_LIST
role, and implement Selection there.
gtk/a11y/gtkatspicontext.c | 6 +-
gtk/a11y/gtkatspiselection.c | 161 +++++++++++++++++++++++++++++++++++-
gtk/a11y/gtkatspiselectionprivate.h | 3 +-
3 files changed, 167 insertions(+), 3 deletions(-)
---
diff --git a/gtk/a11y/gtkatspicontext.c b/gtk/a11y/gtkatspicontext.c
index 084c6a14be..40c655f04a 100644
--- a/gtk/a11y/gtkatspicontext.c
+++ b/gtk/a11y/gtkatspicontext.c
@@ -735,7 +735,11 @@ gtk_at_spi_context_register_object (GtkAtSpiContext *self)
self->n_registered_objects++;
}
- vtable = gtk_atspi_get_selection_vtable (accessible);
+ /* Calling gtk_accessible_get_accessible_role() in here will recurse,
+ * so pass the role in explicitly.
+ */
+ vtable = gtk_atspi_get_selection_vtable (accessible,
+ GTK_AT_CONTEXT (self)->accessible_role);
if (vtable)
{
g_variant_builder_add (&interfaces, "s", atspi_selection_interface.name);
diff --git a/gtk/a11y/gtkatspiselection.c b/gtk/a11y/gtkatspiselection.c
index 2b216cab48..479f88dc24 100644
--- a/gtk/a11y/gtkatspiselection.c
+++ b/gtk/a11y/gtkatspiselection.c
@@ -32,6 +32,7 @@
#include "gtkflowbox.h"
#include "gtkcombobox.h"
#include "gtkstackswitcher.h"
+#include "gtknotebook.h"
#include <gio/gio.h>
@@ -575,14 +576,146 @@ stackswitcher_get_property (GDBusConnection *connection,
return NULL;
}
+
static const GDBusInterfaceVTable stackswitcher_vtable = {
stackswitcher_handle_method,
stackswitcher_get_property,
NULL
};
+
+static void
+notebook_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);
+ GtkWidget *notebook = gtk_widget_get_parent (gtk_widget_get_parent (widget));
+
+ if (g_strcmp0 (method_name, "GetSelectedChild") == 0)
+ {
+ int i;
+ GtkWidget *child;
+
+ i = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
+
+ for (child = gtk_widget_get_first_child (widget);
+ child;
+ child = gtk_widget_get_next_sibling (widget))
+ {
+ /* skip actions */
+ if (gtk_accessible_get_accessible_role (GTK_ACCESSIBLE (child)) != GTK_ACCESSIBLE_ROLE_TAB)
+ continue;
+
+ if (i == 0)
+ break;
+
+ i--;
+ }
+
+ if (child == NULL)
+ {
+ g_dbus_method_invocation_return_error_literal (invocation,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_INVALID_ARGS,
+ "No selected child");
+ }
+ else
+ {
+ GtkATContext *ctx = 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 (GTK_AT_SPI_CONTEXT (ctx))));
+ }
+ }
+ else if (g_strcmp0 (method_name, "SelectChild") == 0)
+ {
+ int i;
+ GtkWidget *child;
+
+ g_variant_get (parameters, "(i)", &i);
+
+ /* skip an action widget */
+ child = gtk_widget_get_first_child (widget);
+ if (gtk_accessible_get_accessible_role (GTK_ACCESSIBLE (child)) != GTK_ACCESSIBLE_ROLE_TAB)
+ i--;
+
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), i);
+
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
+ }
+ else if (g_strcmp0 (method_name, "DeselectChild") == 0)
+ {
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", FALSE));
+ }
+ else if (g_strcmp0 (method_name, "DeselectSelectedChild") == 0)
+ {
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", FALSE));
+ }
+ else if (g_strcmp0 (method_name, "IsChildSelected") == 0)
+ {
+ int i;
+ gboolean active;
+ GtkWidget *child;
+
+ g_variant_get (parameters, "(i)", &i);
+
+ /* skip an action widget */
+ child = gtk_widget_get_first_child (widget);
+ if (gtk_accessible_get_accessible_role (GTK_ACCESSIBLE (child)) != GTK_ACCESSIBLE_ROLE_TAB)
+ i--;
+
+ active = i == gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
+
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", active));
+ }
+ else if (g_strcmp0 (method_name, "SelectAll") == 0)
+ {
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", FALSE));
+ }
+ else if (g_strcmp0 (method_name, "ClearSelection") == 0)
+ {
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", FALSE));
+ }
+}
+
+static GVariant *
+notebook_get_property (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *property_name,
+ GError **error,
+ gpointer user_data)
+{
+ if (g_strcmp0 (property_name, "NSelectedChildren") == 0)
+ {
+ return g_variant_new_int32 (1);
+ }
+
+ return NULL;
+}
+
+static const GDBusInterfaceVTable notebook_vtable = {
+ notebook_handle_method,
+ notebook_get_property,
+ NULL
+};
+
+#define IS_NOTEBOOK_TAB_LIST(s,r) \
+ ((r == GTK_ACCESSIBLE_ROLE_TAB_LIST) && \
+ (gtk_widget_get_parent (GTK_WIDGET (s)) != NULL) && \
+ GTK_IS_NOTEBOOK (gtk_widget_get_parent (gtk_widget_get_parent (GTK_WIDGET (s)))))
+
const GDBusInterfaceVTable *
-gtk_atspi_get_selection_vtable (GtkAccessible *accessible)
+gtk_atspi_get_selection_vtable (GtkAccessible *accessible,
+ GtkAccessibleRole role)
{
if (GTK_IS_LIST_BOX (accessible))
return &listbox_vtable;
@@ -592,6 +725,8 @@ gtk_atspi_get_selection_vtable (GtkAccessible *accessible)
return &combobox_vtable;
else if (GTK_IS_STACK_SWITCHER (accessible))
return &stackswitcher_vtable;
+ else if (IS_NOTEBOOK_TAB_LIST (accessible, role))
+ return ¬ebook_vtable;
return NULL;
}
@@ -654,6 +789,19 @@ gtk_atspi_connect_selection_signals (GtkAccessible *accessible,
g_signal_connect_swapped (accessible, "notify::visible-child", G_CALLBACK (selection_changed), data);
}
+ else if (IS_NOTEBOOK_TAB_LIST (accessible, GTK_AT_CONTEXT (data)->accessible_role))
+ {
+ GtkWidget *notebook = gtk_widget_get_parent (gtk_widget_get_parent (GTK_WIDGET (accessible)));
+ SelectionChanged *changed;
+
+ changed = g_new (SelectionChanged, 1);
+ changed->changed = selection_changed;
+ changed->data = data;
+
+ g_object_set_data_full (G_OBJECT (accessible), "accessible-selection-data", changed, g_free);
+
+ g_signal_connect_swapped (notebook, "notify::page", G_CALLBACK (selection_changed), data);
+ }
}
void
@@ -670,6 +818,17 @@ gtk_atspi_disconnect_selection_signals (GtkAccessible *accessible)
g_signal_handlers_disconnect_by_func (accessible, changed->changed, changed->data);
+ g_object_set_data (G_OBJECT (accessible), "accessible-selection-data", NULL);
+ }
+ else if (IS_NOTEBOOK_TAB_LIST (accessible, gtk_accessible_get_accessible_role (accessible)))
+ {
+ GtkWidget *notebook = gtk_widget_get_parent (gtk_widget_get_parent (GTK_WIDGET (accessible)));
+ SelectionChanged *changed;
+
+ changed = g_object_get_data (G_OBJECT (accessible), "accessible-selection-data");
+
+ g_signal_handlers_disconnect_by_func (notebook, changed->changed, changed->data);
+
g_object_set_data (G_OBJECT (accessible), "accessible-selection-data", NULL);
}
}
diff --git a/gtk/a11y/gtkatspiselectionprivate.h b/gtk/a11y/gtkatspiselectionprivate.h
index 142e59a800..2a9da6738e 100644
--- a/gtk/a11y/gtkatspiselectionprivate.h
+++ b/gtk/a11y/gtkatspiselectionprivate.h
@@ -25,7 +25,8 @@
G_BEGIN_DECLS
-const GDBusInterfaceVTable *gtk_atspi_get_selection_vtable (GtkAccessible *accessible);
+const GDBusInterfaceVTable *gtk_atspi_get_selection_vtable (GtkAccessible *accessible,
+ GtkAccessibleRole role);
typedef void (GtkAtspiSelectionCallback) (gpointer data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]