a11y: Redo cell accessible action handling

Multiple changes:
- actions are now available unconditionally, but only work in the right
  state. This mirrors other actions.
- instead of adding actions manually, they invoke the action on the
  GtkCellAccessibleParent interface.

Tests have been updated to reflect the changes
This commit is contained in:
Benjamin Otte 2011-12-12 15:18:54 +01:00
parent f840efae96
commit 9e9533fc88
7 changed files with 247 additions and 280 deletions

View File

@ -24,14 +24,6 @@
#include "gtkcellaccessible.h"
#include "gtkcellaccessibleparent.h"
typedef struct _ActionInfo ActionInfo;
struct _ActionInfo {
gchar *name;
gchar *description;
gchar *keybinding;
void (*do_action_func) (GtkCellAccessible *cell);
};
static const struct {
AtkState atk_state;
GtkCellRendererState renderer_state;
@ -54,30 +46,15 @@ G_DEFINE_TYPE_WITH_CODE (GtkCellAccessible, _gtk_cell_accessible, ATK_TYPE_OBJEC
G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init)
G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init))
static void
destroy_action_info (gpointer action_info)
{
ActionInfo *info = (ActionInfo *)action_info;
g_free (info->name);
g_free (info->description);
g_free (info->keybinding);
g_free (info);
}
static void
gtk_cell_accessible_object_finalize (GObject *obj)
{
GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (obj);
AtkRelationSet *relation_set;
AtkRelation *relation;
GPtrArray *target;
gpointer target_object;
gint i;
if (cell->action_list)
g_list_free_full (cell->action_list, destroy_action_info);
relation_set = atk_object_ref_relation_set (ATK_OBJECT (obj));
if (ATK_IS_RELATION_SET (relation_set))
{
@ -179,7 +156,6 @@ static void
_gtk_cell_accessible_init (GtkCellAccessible *cell)
{
cell->widget = NULL;
cell->action_list = NULL;
}
static void
@ -260,129 +236,51 @@ _gtk_cell_accessible_remove_state (GtkCellAccessible *cell,
return TRUE;
}
gboolean
_gtk_cell_accessible_add_action (GtkCellAccessible *cell,
const gchar *name,
const gchar *description,
const gchar *keybinding,
void (*func) (GtkCellAccessible *))
{
ActionInfo *info;
info = g_new (ActionInfo, 1);
info->name = g_strdup (name);
info->description = g_strdup (description);
info->keybinding = g_strdup (keybinding);
info->do_action_func = func;
cell->action_list = g_list_append (cell->action_list, info);
return TRUE;
}
gboolean
_gtk_cell_accessible_remove_action (GtkCellAccessible *cell,
gint index)
{
GList *l;
l = g_list_nth (cell->action_list, index);
if (l == NULL)
return FALSE;
destroy_action_info (l->data);
cell->action_list = g_list_remove_link (cell->action_list, l);
return TRUE;
}
gboolean
_gtk_cell_accessible_remove_action_by_name (GtkCellAccessible *cell,
const gchar *name)
{
GList *l;
for (l = cell->action_list; l; l = l->next)
{
ActionInfo *info = l->data;
if (g_strcmp0 (info->name, name) == 0)
break;
}
if (l == NULL)
return FALSE;
destroy_action_info (l->data);
cell->action_list = g_list_remove_link (cell->action_list, l);
return TRUE;
}
static ActionInfo *
get_action_info (GtkCellAccessible *cell,
gint index)
{
GList *l;
l = g_list_nth (cell->action_list, index);
if (l == NULL)
return NULL;
return (ActionInfo *) (l->data);
}
static gint
gtk_cell_accessible_action_get_n_actions (AtkAction *action)
{
GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE(action);
if (cell->action_list != NULL)
return g_list_length (cell->action_list);
else
return 0;
return 3;
}
static const gchar *
gtk_cell_accessible_action_get_name (AtkAction *action,
gint index)
{
GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (action);
ActionInfo *info;
info = get_action_info (cell, index);
if (info == NULL)
return NULL;
return info->name;
switch (index)
{
case 0:
return "expand or contract";
case 1:
return "edit";
case 2:
return "activate";
default:
return NULL;
}
}
static const gchar *
gtk_cell_accessible_action_get_description (AtkAction *action,
gint index)
{
GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (action);
ActionInfo *info;
info = get_action_info (cell, index);
if (info == NULL)
return NULL;
return info->description;
switch (index)
{
case 0:
return "expands or contracts the row in the tree view containing this cell";
case 1:
return "creates a widget in which the contents of the cell can be edited";
case 2:
return "activate the cell";
default:
return NULL;
}
}
static const gchar *
gtk_cell_accessible_action_get_keybinding (AtkAction *action,
gint index)
{
GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (action);
ActionInfo *info;
info = get_action_info (cell, index);
if (info == NULL)
return NULL;
return info->keybinding;
return NULL;
}
static gboolean
@ -390,16 +288,25 @@ gtk_cell_accessible_action_do_action (AtkAction *action,
gint index)
{
GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (action);
ActionInfo *info;
GtkCellAccessibleParent *parent;
info = get_action_info (cell, index);
if (info == NULL)
cell = GTK_CELL_ACCESSIBLE (action);
if (cell->widget == NULL)
return FALSE;
if (info->do_action_func == NULL)
return FALSE;
parent = GTK_CELL_ACCESSIBLE_PARENT (gtk_widget_get_accessible (cell->widget));
info->do_action_func (cell);
switch (index)
{
case 0:
_gtk_cell_accessible_parent_expand_collapse (parent, cell);
case 1:
_gtk_cell_accessible_parent_edit (parent, cell);
case 2:
_gtk_cell_accessible_parent_activate (parent, cell);
default:
return FALSE;
}
return TRUE;
}

View File

@ -39,7 +39,6 @@ struct _GtkCellAccessible
AtkObject parent;
GtkWidget *widget;
GList *action_list;
};
struct _GtkCellAccessibleClass
@ -65,17 +64,6 @@ gboolean _gtk_cell_accessible_add_state (GtkCellAccessible *cell,
gboolean _gtk_cell_accessible_remove_state (GtkCellAccessible *cell,
AtkStateType state_type,
gboolean emit_signal);
gboolean _gtk_cell_accessible_add_action (GtkCellAccessible *cell,
const gchar *name,
const gchar *description,
const gchar *keybinding,
void (*func) (GtkCellAccessible *));
gboolean _gtk_cell_accessible_remove_action (GtkCellAccessible *cell,
gint index);
gboolean _gtk_cell_accessible_remove_action_by_name
(GtkCellAccessible *cell,
const gchar *name);
G_END_DECLS

View File

@ -144,3 +144,47 @@ _gtk_cell_accessible_parent_set_cell_data (GtkCellAccessibleParent *parent,
(iface->set_cell_data) (parent, cell);
}
void
_gtk_cell_accessible_parent_expand_collapse (GtkCellAccessibleParent *parent,
GtkCellAccessible *cell)
{
GtkCellAccessibleParentIface *iface;
g_return_if_fail (GTK_IS_CELL_ACCESSIBLE_PARENT (parent));
g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (cell));
iface = GTK_CELL_ACCESSIBLE_PARENT_GET_IFACE (parent);
if (iface->expand_collapse)
(iface->expand_collapse) (parent, cell);
}
void
_gtk_cell_accessible_parent_activate (GtkCellAccessibleParent *parent,
GtkCellAccessible *cell)
{
GtkCellAccessibleParentIface *iface;
g_return_if_fail (GTK_IS_CELL_ACCESSIBLE_PARENT (parent));
g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (cell));
iface = GTK_CELL_ACCESSIBLE_PARENT_GET_IFACE (parent);
if (iface->activate)
(iface->activate) (parent, cell);
}
void
_gtk_cell_accessible_parent_edit (GtkCellAccessibleParent *parent,
GtkCellAccessible *cell)
{
GtkCellAccessibleParentIface *iface;
g_return_if_fail (GTK_IS_CELL_ACCESSIBLE_PARENT (parent));
g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (cell));
iface = GTK_CELL_ACCESSIBLE_PARENT_GET_IFACE (parent);
if (iface->edit)
(iface->edit) (parent, cell);
}

View File

@ -65,7 +65,13 @@ struct _GtkCellAccessibleParentIface
GtkCellAccessible *cell);
void ( *set_cell_data) (GtkCellAccessibleParent *parent,
GtkCellAccessible *cell);
/* actions */
void ( *expand_collapse) (GtkCellAccessibleParent *parent,
GtkCellAccessible *cell);
void ( *activate) (GtkCellAccessibleParent *parent,
GtkCellAccessible *cell);
void ( *edit) (GtkCellAccessibleParent *parent,
GtkCellAccessible *cell);
};
GType _gtk_cell_accessible_parent_get_type (void);
@ -89,6 +95,12 @@ GtkCellRendererState
GtkCellAccessible *cell);
void _gtk_cell_accessible_parent_set_cell_data (GtkCellAccessibleParent *parent,
GtkCellAccessible *cell);
void _gtk_cell_accessible_parent_expand_collapse (GtkCellAccessibleParent *parent,
GtkCellAccessible *cell);
void _gtk_cell_accessible_parent_activate (GtkCellAccessibleParent *parent,
GtkCellAccessible *cell);
void _gtk_cell_accessible_parent_edit (GtkCellAccessibleParent *parent,
GtkCellAccessible *cell);
G_END_DECLS

View File

@ -81,11 +81,7 @@ static void set_expand_state (GtkTreeView
GtkTreePath *tree_path,
gboolean set_on_ancestor);
static void set_cell_expandable (GtkCellAccessible *cell);
static void add_cell_actions (GtkCellAccessible *cell,
gboolean editable);
static void edit_cell (GtkCellAccessible *cell);
static void activate_cell (GtkCellAccessible *cell);
static void cell_destroyed (gpointer data);
static void cell_info_new (GtkTreeViewAccessible *accessible,
GtkTreeModel *tree_model,
@ -533,9 +529,6 @@ gtk_tree_view_accessible_ref_child (AtkObject *obj,
update_cell_value (renderer_cell, accessible, FALSE);
/* Add the actions appropriate for this cell */
add_cell_actions (cell, editable);
/* Set state if it is expandable */
if (is_expander)
{
@ -1489,6 +1482,68 @@ gtk_tree_view_accessible_set_cell_data (GtkCellAccessibleParent *parent,
is_expanded);
}
static void
gtk_tree_view_accessible_expand_collapse (GtkCellAccessibleParent *parent,
GtkCellAccessible *cell)
{
GtkTreeViewAccessibleCellInfo *cell_info;
GtkTreeView *treeview;
GtkTreePath *path;
treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
if (!cell_info ||
cell_info->cell_col_ref != gtk_tree_view_get_expander_column (treeview))
return;
path = cell_info_get_path (cell_info);
if (cell_info->node->children)
gtk_tree_view_collapse_row (treeview, path);
else
gtk_tree_view_expand_row (treeview, path, FALSE);
gtk_tree_path_free (path);
}
static void
gtk_tree_view_accessible_activate (GtkCellAccessibleParent *parent,
GtkCellAccessible *cell)
{
GtkTreeViewAccessibleCellInfo *cell_info;
GtkTreeView *treeview;
GtkTreePath *path;
treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
if (!cell_info)
return;
path = cell_info_get_path (cell_info);
gtk_tree_view_row_activated (treeview, path, cell_info->cell_col_ref);
gtk_tree_path_free (path);
}
static void
gtk_tree_view_accessible_edit (GtkCellAccessibleParent *parent,
GtkCellAccessible *cell)
{
GtkTreeView *treeview;
if (!gtk_tree_view_accessible_grab_cell_focus (parent, cell))
return;
treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
g_signal_emit_by_name (treeview,
"real-select-cursor-row",
TRUE);
}
static void
gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface)
{
@ -1498,6 +1553,9 @@ gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface)
iface->get_child_index = gtk_tree_view_accessible_get_child_index;
iface->get_renderer_state = gtk_tree_view_accessible_get_renderer_state;
iface->set_cell_data = gtk_tree_view_accessible_set_cell_data;
iface->expand_collapse = gtk_tree_view_accessible_expand_collapse;
iface->activate = gtk_tree_view_accessible_activate;
iface->edit = gtk_tree_view_accessible_edit;
}
/* signal handling */
@ -2185,11 +2243,7 @@ set_expand_state (GtkTreeView *tree_view,
}
else
{
if (_gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDABLE, TRUE))
/* The state may have been propagated to the container cell */
if (!GTK_IS_CONTAINER_CELL_ACCESSIBLE (cell))
_gtk_cell_accessible_remove_action_by_name (cell,
"expand or contract");
_gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDABLE, TRUE);
}
/* We assume that each cell in the cache once and
@ -2204,98 +2258,6 @@ set_expand_state (GtkTreeView *tree_view,
}
}
static void
add_cell_actions (GtkCellAccessible *cell,
gboolean editable)
{
if (editable)
_gtk_cell_accessible_add_action (cell,
"edit", "creates a widget in which the contents of the cell can be edited",
NULL, edit_cell);
_gtk_cell_accessible_add_action (cell,
"activate", "activate the cell",
NULL, activate_cell);
}
static void
toggle_cell_expanded (GtkCellAccessible *cell)
{
GtkTreeViewAccessibleCellInfo *cell_info;
GtkTreeView *tree_view;
GtkTreePath *path;
AtkObject *parent;
AtkStateSet *stateset;
parent = atk_object_get_parent (ATK_OBJECT (cell));
if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
parent = atk_object_get_parent (parent);
cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
if (!cell_info)
return;
tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
path = cell_info_get_path (cell_info);
if (!path)
return;
stateset = atk_object_ref_state_set (ATK_OBJECT (cell));
if (atk_state_set_contains_state (stateset, ATK_STATE_EXPANDED))
gtk_tree_view_collapse_row (tree_view, path);
else
gtk_tree_view_expand_row (tree_view, path, TRUE);
g_object_unref (stateset);
gtk_tree_path_free (path);
}
static void
edit_cell (GtkCellAccessible *cell)
{
GtkTreeViewAccessibleCellInfo *cell_info;
GtkTreeView *tree_view;
GtkTreePath *path;
AtkObject *parent;
parent = atk_object_get_parent (ATK_OBJECT (cell));
if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
parent = atk_object_get_parent (parent);
cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
if (!cell_info)
return;
tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
path = cell_info_get_path (cell_info);
if (!path)
return;
gtk_tree_view_set_cursor (tree_view, path, cell_info->cell_col_ref, TRUE);
gtk_tree_path_free (path);
}
static void
activate_cell (GtkCellAccessible *cell)
{
GtkTreeViewAccessibleCellInfo *cell_info;
GtkTreeView *tree_view;
GtkTreePath *path;
AtkObject *parent;
parent = atk_object_get_parent (ATK_OBJECT (cell));
if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
parent = atk_object_get_parent (parent);
cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
if (!cell_info)
return;
tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
path = cell_info_get_path (cell_info);
if (!path)
return;
gtk_tree_view_row_activated (tree_view, path, cell_info->cell_col_ref);
gtk_tree_path_free (path);
}
static void
cell_destroyed (gpointer data)
{
@ -2573,11 +2535,7 @@ get_rbtree_column_from_index (GtkTreeView *tree_view,
static void
set_cell_expandable (GtkCellAccessible *cell)
{
if (_gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDABLE, FALSE))
_gtk_cell_accessible_add_action (cell,
"expand or contract",
"expands or contracts the row in the tree view containing this cell",
NULL, toggle_cell_expanded);
_gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDABLE, FALSE);
}
static GtkTreeViewAccessibleCellInfo *

View File

@ -132,6 +132,12 @@ window1
layer: widget
alpha: 1
<AtkAction>
action 0 name: expand or contract
action 0 description: expands or contracts the row in the tree view containing this cell
action 1 name: edit
action 1 description: creates a widget in which the contents of the cell can be edited
action 2 name: activate
action 2 description: activate the cell
"table cell"
index: 0
@ -169,8 +175,12 @@ window1
weight: <omitted>
wrap-mode: word
<AtkAction>
action 0 name: activate
action 0 description: activate the cell
action 0 name: expand or contract
action 0 description: expands or contracts the row in the tree view containing this cell
action 1 name: edit
action 1 description: creates a widget in which the contents of the cell can be edited
action 2 name: activate
action 2 description: activate the cell
No applications available to open "(null)" files
Click "Show other applications", for more options, or "Find applications online" to install a new application
"table cell"
@ -211,8 +221,12 @@ Click "Show other applications", for more options, or "Find applications online"
weight: <omitted>
wrap-mode: word
<AtkAction>
action 0 name: activate
action 0 description: activate the cell
action 0 name: expand or contract
action 0 description: expands or contracts the row in the tree view containing this cell
action 1 name: edit
action 1 description: creates a widget in which the contents of the cell can be edited
action 2 name: activate
action 2 description: activate the cell
"table cell"
index: 2
@ -250,8 +264,12 @@ Click "Show other applications", for more options, or "Find applications online"
weight: <omitted>
wrap-mode: word
<AtkAction>
action 0 name: activate
action 0 description: activate the cell
action 0 name: expand or contract
action 0 description: expands or contracts the row in the tree view containing this cell
action 1 name: edit
action 1 description: creates a widget in which the contents of the cell can be edited
action 2 name: activate
action 2 description: activate the cell
unnamed-GtkImageCellAccessible-8
"table cell"
index: 3
@ -263,8 +281,12 @@ Click "Show other applications", for more options, or "Find applications online"
image size: 0 x 0
image description: (null)
<AtkAction>
action 0 name: activate
action 0 description: activate the cell
action 0 name: expand or contract
action 0 description: expands or contracts the row in the tree view containing this cell
action 1 name: edit
action 1 description: creates a widget in which the contents of the cell can be edited
action 2 name: activate
action 2 description: activate the cell
"table cell"
index: 4
@ -302,8 +324,12 @@ Click "Show other applications", for more options, or "Find applications online"
weight: <omitted>
wrap-mode: word
<AtkAction>
action 0 name: activate
action 0 description: activate the cell
action 0 name: expand or contract
action 0 description: expands or contracts the row in the tree view containing this cell
action 1 name: edit
action 1 description: creates a widget in which the contents of the cell can be edited
action 2 name: activate
action 2 description: activate the cell
unnamed-GtkScrollbarAccessible-9
"scroll bar"
parent: unnamed-GtkScrolledWindowAccessible-4

View File

@ -99,8 +99,12 @@ window1
weight: <omitted>
wrap-mode: word
<AtkAction>
action 0 name: activate
action 0 description: activate the cell
action 0 name: expand or contract
action 0 description: expands or contracts the row in the tree view containing this cell
action 1 name: edit
action 1 description: creates a widget in which the contents of the cell can be edited
action 2 name: activate
action 2 description: activate the cell
Two
"table cell"
parent: tree1
@ -139,8 +143,12 @@ window1
weight: <omitted>
wrap-mode: word
<AtkAction>
action 0 name: activate
action 0 description: activate the cell
action 0 name: expand or contract
action 0 description: expands or contracts the row in the tree view containing this cell
action 1 name: edit
action 1 description: creates a widget in which the contents of the cell can be edited
action 2 name: activate
action 2 description: activate the cell
Three
"table cell"
parent: tree1
@ -179,8 +187,12 @@ window1
weight: <omitted>
wrap-mode: word
<AtkAction>
action 0 name: activate
action 0 description: activate the cell
action 0 name: expand or contract
action 0 description: expands or contracts the row in the tree view containing this cell
action 1 name: edit
action 1 description: creates a widget in which the contents of the cell can be edited
action 2 name: activate
action 2 description: activate the cell
Four
"table cell"
parent: tree1
@ -219,8 +231,12 @@ window1
weight: <omitted>
wrap-mode: word
<AtkAction>
action 0 name: activate
action 0 description: activate the cell
action 0 name: expand or contract
action 0 description: expands or contracts the row in the tree view containing this cell
action 1 name: edit
action 1 description: creates a widget in which the contents of the cell can be edited
action 2 name: activate
action 2 description: activate the cell
Five
"table cell"
parent: tree1
@ -259,8 +275,12 @@ window1
weight: <omitted>
wrap-mode: word
<AtkAction>
action 0 name: activate
action 0 description: activate the cell
action 0 name: expand or contract
action 0 description: expands or contracts the row in the tree view containing this cell
action 1 name: edit
action 1 description: creates a widget in which the contents of the cell can be edited
action 2 name: activate
action 2 description: activate the cell
Six
"table cell"
parent: tree1
@ -299,8 +319,12 @@ window1
weight: <omitted>
wrap-mode: word
<AtkAction>
action 0 name: activate
action 0 description: activate the cell
action 0 name: expand or contract
action 0 description: expands or contracts the row in the tree view containing this cell
action 1 name: edit
action 1 description: creates a widget in which the contents of the cell can be edited
action 2 name: activate
action 2 description: activate the cell
Seven
"table cell"
parent: tree1
@ -339,8 +363,12 @@ window1
weight: <omitted>
wrap-mode: word
<AtkAction>
action 0 name: activate
action 0 description: activate the cell
action 0 name: expand or contract
action 0 description: expands or contracts the row in the tree view containing this cell
action 1 name: edit
action 1 description: creates a widget in which the contents of the cell can be edited
action 2 name: activate
action 2 description: activate the cell
Eight
"table cell"
parent: tree1
@ -379,5 +407,9 @@ window1
weight: <omitted>
wrap-mode: word
<AtkAction>
action 0 name: activate
action 0 description: activate the cell
action 0 name: expand or contract
action 0 description: expands or contracts the row in the tree view containing this cell
action 1 name: edit
action 1 description: creates a widget in which the contents of the cell can be edited
action 2 name: activate
action 2 description: activate the cell