Merge branch 'a11y-debug' into 'master'

Some a11y improvements

See merge request GNOME/gtk!3455
This commit is contained in:
Matthias Clasen 2021-04-22 11:04:30 +00:00
commit dcb5a74275
17 changed files with 206 additions and 22 deletions

View File

@ -27,6 +27,8 @@
#include "gtkatspiutilsprivate.h"
#include "gtkdebug.h"
#include "a11y/atspi/atspi-accessible.h"
#include "a11y/atspi/atspi-application.h"
#include "a11y/atspi/atspi-cache.h"
/* Cached item:
@ -61,6 +63,8 @@ struct _GtkAtSpiCache
/* Re-entrancy guard */
gboolean in_get_items;
GtkAtSpiRoot *root;
};
enum
@ -144,6 +148,36 @@ collect_object (GtkAtSpiCache *self,
g_variant_builder_add (builder, "@au", gtk_at_spi_context_get_states (context));
}
static void
collect_root (GtkAtSpiCache *self,
GVariantBuilder *builder)
{
g_variant_builder_add (builder, "@(so)", gtk_at_spi_root_to_ref (self->root));
g_variant_builder_add (builder, "@(so)", gtk_at_spi_root_to_ref (self->root));
g_variant_builder_add (builder, "@(so)", gtk_at_spi_null_ref ());
g_variant_builder_add (builder, "i", -1);
g_variant_builder_add (builder, "i", 0);
GVariantBuilder interfaces = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("as"));
g_variant_builder_add (&interfaces, "s", atspi_accessible_interface.name);
g_variant_builder_add (&interfaces, "s", atspi_application_interface.name);
g_variant_builder_add (builder, "@as", g_variant_builder_end (&interfaces));
g_variant_builder_add (builder, "s", g_get_prgname () ? g_get_prgname () : "Unnamed");
g_variant_builder_add (builder, "u", ATSPI_ROLE_APPLICATION);
g_variant_builder_add (builder, "s", g_get_application_name () ? g_get_application_name () : "No description");
GVariantBuilder states = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("au"));
g_variant_builder_add (&states, "u", 0);
g_variant_builder_add (&states, "u", 0);
g_variant_builder_add (builder, "@au", g_variant_builder_end (&states));
}
static void
collect_cached_objects (GtkAtSpiCache *self,
GVariantBuilder *builder)
@ -160,6 +194,10 @@ collect_cached_objects (GtkAtSpiCache *self,
while (g_hash_table_iter_next (&iter, &key_p, &value_p))
g_hash_table_add (collection, value_p);
g_variant_builder_open (builder, G_VARIANT_TYPE ("(" ITEM_SIGNATURE ")"));
collect_root (self, builder);
g_variant_builder_close (builder);
g_hash_table_iter_init (&iter, collection);
while (g_hash_table_iter_next (&iter, &key_p, &value_p))
{
@ -355,15 +393,21 @@ gtk_at_spi_cache_init (GtkAtSpiCache *self)
GtkAtSpiCache *
gtk_at_spi_cache_new (GDBusConnection *connection,
const char *cache_path)
const char *cache_path,
GtkAtSpiRoot *root)
{
GtkAtSpiCache *cache;
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
g_return_val_if_fail (cache_path != NULL, NULL);
return g_object_new (GTK_TYPE_AT_SPI_CACHE,
cache = g_object_new (GTK_TYPE_AT_SPI_CACHE,
"connection", connection,
"cache-path", cache_path,
NULL);
cache->root = root;
return cache;
}
void

View File

@ -31,7 +31,8 @@ G_DECLARE_FINAL_TYPE (GtkAtSpiCache, gtk_at_spi_cache, GTK, AT_SPI_CACHE, GObjec
GtkAtSpiCache *
gtk_at_spi_cache_new (GDBusConnection *connection,
const char *cache_path);
const char *cache_path,
GtkAtSpiRoot *root);
void
gtk_at_spi_cache_add_context (GtkAtSpiCache *self,

View File

@ -25,7 +25,6 @@
#include "gtkaccessibleprivate.h"
#include "gtkatspiactionprivate.h"
#include "gtkatspicacheprivate.h"
#include "gtkatspieditabletextprivate.h"
#include "gtkatspiprivate.h"
#include "gtkatspirootprivate.h"
@ -91,9 +90,6 @@ struct _GtkAtSpiContext
/* The root object, used as a entry point */
GtkAtSpiRoot *root;
/* The cache object, used to retrieve ATContexts */
GtkAtSpiCache *cache;
/* The address for the ATSPI accessibility bus */
char *bus_address;
@ -154,6 +150,13 @@ collect_states (GtkAtSpiContext *self,
set_atspi_state (&states, ATSPI_STATE_VISIBLE);
if (ctx->accessible_role == GTK_ACCESSIBLE_ROLE_WINDOW)
{
set_atspi_state (&states, ATSPI_STATE_SHOWING);
if (gtk_accessible_get_platform_state (accessible, GTK_ACCESSIBLE_PLATFORM_STATE_ACTIVE))
set_atspi_state (&states, ATSPI_STATE_ACTIVE);
}
if (ctx->accessible_role == GTK_ACCESSIBLE_ROLE_TEXT_BOX ||
ctx->accessible_role == GTK_ACCESSIBLE_ROLE_SEARCH_BOX ||
ctx->accessible_role == GTK_ACCESSIBLE_ROLE_SPIN_BUTTON)
@ -861,6 +864,43 @@ emit_children_changed (GtkAtSpiContext *self,
context_ref);
}
static void
emit_focus (GtkAtSpiContext *self,
gboolean focus_in)
{
if (self->connection == NULL)
return;
if (focus_in)
g_dbus_connection_emit_signal (self->connection,
NULL,
self->context_path,
"org.a11y.atspi.Event.Focus",
"Focus",
g_variant_new ("(siiva{sv})",
"", 0, 0, g_variant_new_string ("0"), NULL),
NULL);
}
static void
emit_window_event (GtkAtSpiContext *self,
const char *event_type)
{
if (self->connection == NULL)
return;
g_dbus_connection_emit_signal (self->connection,
NULL,
self->context_path,
"org.a11y.atspi.Event.Window",
event_type,
g_variant_new ("(siiva{sv})",
"", 0, 0,
g_variant_new_string("0"),
NULL),
NULL);
}
static void
gtk_at_spi_context_state_change (GtkATContext *ctx,
GtkAccessibleStateChange changed_states,
@ -892,6 +932,7 @@ gtk_at_spi_context_state_change (GtkATContext *ctx,
if (GTK_IS_ROOT (accessible))
{
gtk_at_spi_root_child_changed (self->root, change, accessible);
emit_state_changed (self, "showing", gtk_boolean_accessible_value_get (value));
}
else
{
@ -1087,6 +1128,25 @@ gtk_at_spi_context_platform_change (GtkATContext *ctx,
gboolean state = gtk_accessible_get_platform_state (GTK_ACCESSIBLE (widget),
GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSED);
emit_state_changed (self, "focused", state);
emit_focus (self, state);
}
if (changed_platform & GTK_ACCESSIBLE_PLATFORM_CHANGE_ACTIVE)
{
gboolean state = gtk_accessible_get_platform_state (GTK_ACCESSIBLE (widget),
GTK_ACCESSIBLE_PLATFORM_STATE_ACTIVE);
emit_state_changed (self, "active", state);
/* Orca tracks the window:activate and window:deactivate events on top
* levels to decide whether to track other AT-SPI events
*/
if (gtk_accessible_get_accessible_role (accessible) == GTK_ACCESSIBLE_ROLE_WINDOW)
{
if (state)
emit_window_event (self, "activate");
else
emit_window_event (self, "deactivate");
}
}
}

View File

@ -503,7 +503,7 @@ on_registration_reply (GObject *gobject,
}
/* Register the cache object */
self->cache = gtk_at_spi_cache_new (self->connection, ATSPI_CACHE_PATH);
self->cache = gtk_at_spi_cache_new (self->connection, ATSPI_CACHE_PATH, self);
/* Drain the list of queued GtkAtSpiContexts, and add them to the cache */
if (self->queued_contexts != NULL)

View File

@ -1326,9 +1326,12 @@ update_selection (TextChanged *changed,
int selection_bound)
{
gboolean caret_moved, bound_moved;
gboolean had_selection, has_selection;
caret_moved = cursor_position != changed->cursor_position;
bound_moved = selection_bound != changed->selection_bound;
had_selection = changed->cursor_position != changed->selection_bound;
has_selection = cursor_position != selection_bound;
if (!caret_moved && !bound_moved)
return;
@ -1339,7 +1342,7 @@ update_selection (TextChanged *changed,
if (caret_moved)
changed->selection_changed (changed->data, "text-caret-moved", changed->cursor_position);
if (caret_moved || bound_moved)
if (had_selection || has_selection)
changed->selection_changed (changed->data, "text-selection-changed", 0);
}

View File

@ -1172,8 +1172,7 @@ void
gtk_at_context_platform_changed (GtkATContext *self,
GtkAccessiblePlatformChange change)
{
if (!self->realized)
return;
gtk_at_context_realize (self);
GTK_AT_CONTEXT_GET_CLASS (self)->platform_change (self, change);
}

View File

@ -83,11 +83,13 @@ typedef enum {
typedef enum {
GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSABLE,
GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSED,
GTK_ACCESSIBLE_PLATFORM_STATE_ACTIVE
} GtkAccessiblePlatformState;
typedef enum {
GTK_ACCESSIBLE_PLATFORM_CHANGE_FOCUSABLE = 1 << GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSABLE,
GTK_ACCESSIBLE_PLATFORM_CHANGE_FOCUSED = 1 << GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSED,
GTK_ACCESSIBLE_PLATFORM_CHANGE_ACTIVE = 1 << GTK_ACCESSIBLE_PLATFORM_STATE_ACTIVE,
} GtkAccessiblePlatformChange;
typedef enum {

View File

@ -351,6 +351,8 @@ gtk_entry_accessible_get_platform_state (GtkAccessible *self,
return gtk_widget_get_focusable (GTK_WIDGET (priv->text));
case GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSED:
return gtk_widget_has_focus (GTK_WIDGET (priv->text));
case GTK_ACCESSIBLE_PLATFORM_STATE_ACTIVE:
return FALSE;
default:
g_assert_not_reached ();
}

View File

@ -5461,6 +5461,9 @@ gtk_notebook_real_switch_page (GtkNotebook *notebook,
gtk_widget_set_state_flags (page->tab_widget, GTK_STATE_FLAG_CHECKED, FALSE);
gtk_widget_set_visible (notebook->header_widget, notebook->show_tabs);
if (gtk_widget_get_realized (GTK_WIDGET (notebook)))
gtk_widget_realize_at_context (notebook->cur_page->tab_widget);
gtk_accessible_update_state (GTK_ACCESSIBLE (notebook->cur_page->tab_widget),
GTK_ACCESSIBLE_STATE_SELECTED, TRUE,
-1);

View File

@ -532,6 +532,8 @@ gtk_password_entry_accessible_get_platform_state (GtkAccessible *se
return gtk_widget_get_focusable (GTK_WIDGET (entry->entry));
case GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSED:
return gtk_widget_has_focus (GTK_WIDGET (entry->entry));
case GTK_ACCESSIBLE_PLATFORM_STATE_ACTIVE:
return FALSE;
default:
g_assert_not_reached ();
}

View File

@ -475,6 +475,8 @@ gtk_search_entry_accessible_get_platform_state (GtkAccessible *self
return gtk_widget_get_focusable (GTK_WIDGET (entry->entry));
case GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSED:
return gtk_widget_has_focus (GTK_WIDGET (entry->entry));
case GTK_ACCESSIBLE_PLATFORM_STATE_ACTIVE:
return FALSE;
default:
g_assert_not_reached ();
}

View File

@ -633,6 +633,8 @@ gtk_spin_button_accessible_get_platform_state (GtkAccessible *self,
return gtk_widget_get_focusable (spin_button->entry);
case GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSED:
return gtk_widget_has_focus (spin_button->entry);
case GTK_ACCESSIBLE_PLATFORM_STATE_ACTIVE:
return FALSE;
default:
g_assert_not_reached ();
}

View File

@ -154,6 +154,10 @@ rebuild_child (GtkWidget *self,
gtk_widget_set_halign (GTK_WIDGET (button_child), GTK_ALIGN_CENTER);
gtk_button_set_child (GTK_BUTTON (self), button_child);
}
gtk_accessible_update_property (GTK_ACCESSIBLE (self),
GTK_ACCESSIBLE_PROPERTY_LABEL, title,
-1);
}
static void

View File

@ -96,6 +96,9 @@ gtk_test_at_context_platform_change (GtkATContext *self,
if (changed_platform & GTK_ACCESSIBLE_PLATFORM_CHANGE_FOCUSED)
g_print ("*** focused = %d\n",
gtk_accessible_get_platform_state (accessible, GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSED));
if (changed_platform & GTK_ACCESSIBLE_PLATFORM_CHANGE_ACTIVE)
g_print ("*** active = %d\n",
gtk_accessible_get_platform_state (accessible, GTK_ACCESSIBLE_PLATFORM_STATE_ACTIVE));
}
}

View File

@ -151,6 +151,8 @@ gtk_tree_expander_update_for_list_row (GtkTreeExpander *self)
gtk_widget_unparent (child);
}
self->expander = NULL;
gtk_accessible_reset_state (GTK_ACCESSIBLE (self), GTK_ACCESSIBLE_STATE_EXPANDED);
}
else
{
@ -192,22 +194,19 @@ gtk_tree_expander_update_for_list_row (GtkTreeExpander *self)
gtk_accessible_update_property (GTK_ACCESSIBLE (self->expander),
GTK_ACCESSIBLE_PROPERTY_LABEL, _("Expand"),
-1);
gtk_accessible_update_relation (GTK_ACCESSIBLE (self->expander),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, self->child, NULL,
-1);
}
if (gtk_tree_list_row_get_expanded (self->list_row))
{
gtk_widget_set_state_flags (self->expander, GTK_STATE_FLAG_CHECKED, FALSE);
gtk_accessible_update_state (GTK_ACCESSIBLE (self->expander),
gtk_accessible_update_state (GTK_ACCESSIBLE (self),
GTK_ACCESSIBLE_STATE_EXPANDED, TRUE,
-1);
}
else
{
gtk_widget_unset_state_flags (self->expander, GTK_STATE_FLAG_CHECKED);
gtk_accessible_update_state (GTK_ACCESSIBLE (self->expander),
gtk_accessible_update_state (GTK_ACCESSIBLE (self),
GTK_ACCESSIBLE_STATE_EXPANDED, FALSE,
-1);
}
@ -725,6 +724,14 @@ gtk_tree_expander_set_child (GtkTreeExpander *self,
{
self->child = child;
gtk_widget_set_parent (child, GTK_WIDGET (self));
gtk_accessible_update_relation (GTK_ACCESSIBLE (self),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, self->child, NULL,
-1);
}
else
{
gtk_accessible_reset_relation (GTK_ACCESSIBLE (self), GTK_ACCESSIBLE_RELATION_LABELLED_BY);
}
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CHILD]);

View File

@ -74,6 +74,7 @@
#include "gtkwidgetpaintableprivate.h"
#include "gtkwindowgroup.h"
#include "gtkwindowprivate.h"
#include "gtktestatcontextprivate.h"
#include "inspector/window.h"
@ -2449,13 +2450,13 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
priv->at_context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (widget));
}
void
gtk_widget_realize_at_context (GtkWidget *self)
static void
gtk_widget_root_at_context (GtkWidget *self)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (self);
GtkAccessibleRole role = priv->accessible_role;
if (priv->at_context == NULL || gtk_at_context_is_realized (priv->at_context))
if (priv->at_context == NULL)
return;
/* Reset the accessible role to its current value */
@ -2468,6 +2469,17 @@ gtk_widget_realize_at_context (GtkWidget *self)
gtk_at_context_set_accessible_role (priv->at_context, role);
gtk_at_context_set_display (priv->at_context, gtk_root_get_display (priv->root));
}
void
gtk_widget_realize_at_context (GtkWidget *self)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (self);
if (priv->at_context == NULL || gtk_at_context_is_realized (priv->at_context))
return;
gtk_widget_root_at_context (self);
gtk_at_context_realize (priv->at_context);
}
@ -2511,6 +2523,8 @@ gtk_widget_root (GtkWidget *widget)
if (priv->layout_manager)
gtk_layout_manager_set_root (priv->layout_manager, priv->root);
gtk_widget_root_at_context (widget);
GTK_WIDGET_GET_CLASS (widget)->root (widget);
if (!GTK_IS_ROOT (widget))
@ -8492,6 +8506,8 @@ gtk_widget_accessible_get_platform_state (GtkAccessible *self,
return gtk_widget_get_focusable (GTK_WIDGET (self));
case GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSED:
return gtk_widget_has_focus (GTK_WIDGET (self));
case GTK_ACCESSIBLE_PLATFORM_STATE_ACTIVE:
return FALSE;
default:
g_assert_not_reached ();
}

View File

@ -26,6 +26,7 @@
#include "gtkwindowprivate.h"
#include "gtkaccessibleprivate.h"
#include "gtkaccelgroupprivate.h"
#include "gtkactionable.h"
#include "gtkapplicationprivate.h"
@ -479,6 +480,9 @@ static void gtk_window_shortcut_manager_interface_init (GtkShor
static void gtk_window_root_interface_init (GtkRootInterface *iface);
static void gtk_window_native_interface_init (GtkNativeInterface *iface);
static void gtk_window_accessible_interface_init (GtkAccessibleInterface *iface);
static void ensure_state_flag_backdrop (GtkWidget *widget);
static void unset_titlebar (GtkWindow *window);
@ -493,6 +497,8 @@ gtk_window_update_csd_size (GtkWindow *window,
G_DEFINE_TYPE_WITH_CODE (GtkWindow, gtk_window, GTK_TYPE_WIDGET,
G_ADD_PRIVATE (GtkWindow)
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACCESSIBLE,
gtk_window_accessible_interface_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
gtk_window_buildable_interface_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_NATIVE,
@ -502,6 +508,32 @@ G_DEFINE_TYPE_WITH_CODE (GtkWindow, gtk_window, GTK_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE (GTK_TYPE_ROOT,
gtk_window_root_interface_init))
static GtkAccessibleInterface *parent_accessible_iface;
static gboolean
gtk_window_accessible_get_platform_state (GtkAccessible *self,
GtkAccessiblePlatformState state)
{
switch (state)
{
case GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSABLE:
case GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSED:
return parent_accessible_iface->get_platform_state (self, state);
case GTK_ACCESSIBLE_PLATFORM_STATE_ACTIVE:
return gtk_window_is_active (GTK_WINDOW (self));
default:
g_assert_not_reached ();
}
}
static void
gtk_window_accessible_interface_init (GtkAccessibleInterface *iface)
{
parent_accessible_iface = g_type_interface_peek_parent (iface);
iface->get_at_context = parent_accessible_iface->get_at_context;
iface->get_platform_state = gtk_window_accessible_get_platform_state;
}
static void
add_tab_bindings (GtkWidgetClass *widget_class,
GdkModifierType modifiers,
@ -5828,6 +5860,8 @@ _gtk_window_set_is_active (GtkWindow *window,
g_object_unref (focus);
}
gtk_accessible_platform_changed (GTK_ACCESSIBLE (window), GTK_ACCESSIBLE_PLATFORM_CHANGE_ACTIVE);
g_object_notify_by_pspec (G_OBJECT (window), window_props[PROP_IS_ACTIVE]);
}