summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2014-01-05 11:56:31 -0500
committerMatthias Clasen <mclasen@redhat.com>2014-01-05 11:56:31 -0500
commite015102fa987281fb53bcdefc3044498cf970207 (patch)
tree7afb1dea85dfe033cc7ac7acfd3a1ee702d30507
parent7e3f68d950c3d29bcf2e630a0ebeaec67b4f5901 (diff)
downloadgtk+-e015102fa987281fb53bcdefc3044498cf970207.tar.gz
a11y: Fix keybindings in menus
GtkMenuItemAccessible was assuming that an accel label is always the immediate child of a menu item. It also did not deal with manually set accels. Fix both of these. https://bugzilla.gnome.org/show_bug.cgi?id=721086
-rw-r--r--gtk/a11y/gtkmenuitemaccessible.c65
1 files changed, 51 insertions, 14 deletions
diff --git a/gtk/a11y/gtkmenuitemaccessible.c b/gtk/a11y/gtkmenuitemaccessible.c
index ff1fd260e0..2e3fe75e48 100644
--- a/gtk/a11y/gtkmenuitemaccessible.c
+++ b/gtk/a11y/gtkmenuitemaccessible.c
@@ -462,6 +462,33 @@ find_accel_by_closure (GtkAccelKey *key,
return data == (gpointer) closure;
}
+static GtkWidget *
+find_item_label (GtkWidget *item)
+{
+ GtkWidget *child;
+
+ child = gtk_bin_get_child (GTK_BIN (item));
+ if (GTK_IS_CONTAINER (child))
+ {
+ GList *children, *l;
+ children = gtk_container_get_children (GTK_CONTAINER (child));
+ for (l = children; l; l = l->next)
+ {
+ if (GTK_IS_LABEL (l->data))
+ {
+ child = l->data;
+ break;
+ }
+ }
+ g_list_free (children);
+ }
+
+ if (GTK_IS_LABEL (child))
+ return child;
+
+ return NULL;
+}
+
/* This function returns a string of the form A;B;C where A is
* the keybinding for the widget; B is the keybinding to traverse
* from the menubar and C is the accelerator. The items in the
@@ -494,8 +521,7 @@ gtk_menu_item_accessible_get_keybinding (AtkAction *action,
guint key_val;
gchar *key, *temp_keybinding;
- child = gtk_bin_get_child (GTK_BIN (temp_item));
- if (child == NULL)
+ if (gtk_bin_get_child (GTK_BIN (temp_item)) == NULL)
return NULL;
parent = gtk_widget_get_parent (temp_item);
@@ -513,6 +539,7 @@ gtk_menu_item_accessible_get_keybinding (AtkAction *action,
gtk_window_get_mnemonic_modifier (GTK_WINDOW (toplevel));
}
+ child = find_item_label (temp_item);
if (GTK_IS_LABEL (child))
{
key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (child));
@@ -560,17 +587,27 @@ gtk_menu_item_accessible_get_keybinding (AtkAction *action,
parent = gtk_widget_get_parent (item);
if (GTK_IS_MENU (parent))
{
- GtkAccelGroup *group;
- GtkAccelKey *key;
+ child = find_item_label (item);
+ if (GTK_IS_ACCEL_LABEL (child))
+ {
+ guint accel_key;
+ GdkModifierType accel_mods;
- group = gtk_menu_get_accel_group (GTK_MENU (parent));
- if (group)
- key = gtk_accel_group_find (group, find_accel_by_widget, item);
- else
+ gtk_accel_label_get_accel (GTK_ACCEL_LABEL (child), &accel_key, &accel_mods);
+
+ if (accel_key)
+ accelerator = gtk_accelerator_name (accel_key, accel_mods);
+ }
+
+ if (!accelerator)
{
- key = NULL;
- child = gtk_bin_get_child (GTK_BIN (item));
- if (GTK_IS_ACCEL_LABEL (child))
+ GtkAccelGroup *group;
+ GtkAccelKey *key = NULL;
+
+ group = gtk_menu_get_accel_group (GTK_MENU (parent));
+ if (group)
+ key = gtk_accel_group_find (group, find_accel_by_widget, item);
+ else if (GTK_IS_ACCEL_LABEL (child))
{
GtkAccelLabel *accel_label;
GClosure *accel_closure;
@@ -585,10 +622,10 @@ gtk_menu_item_accessible_get_keybinding (AtkAction *action,
g_closure_unref (accel_closure);
}
}
- }
- if (key)
- accelerator = gtk_accelerator_name (key->accel_key, key->accel_mods);
+ if (key)
+ accelerator = gtk_accelerator_name (key->accel_key, key->accel_mods);
+ }
}
/* Concatenate the bindings */