mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-12 13:30:19 +00:00
a11y: Fix some GtkATContext reference leaks
`gtk_accessible_get_at_context()` is transfer-full, so the returned reference needs to be dropped. This was missing in a couple places.
This commit is contained in:
parent
42a704fefb
commit
81e9de3778
@ -1333,6 +1333,8 @@ gtk_at_context_get_text_accumulate (GtkATContext *self,
|
||||
GtkATContext *rel_context = gtk_accessible_get_at_context (rel);
|
||||
|
||||
gtk_at_context_get_text_accumulate (rel_context, nodes, s, property, relation, FALSE, TRUE);
|
||||
|
||||
g_object_unref (rel_context);
|
||||
}
|
||||
|
||||
if (s->len > 0)
|
||||
|
@ -243,6 +243,8 @@ update_name (GtkInspectorA11y *sl)
|
||||
|
||||
name = gtk_at_context_get_name (context);
|
||||
gtk_label_set_label (GTK_LABEL (sl->name), name);
|
||||
|
||||
g_object_unref (context);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -257,6 +259,8 @@ update_description (GtkInspectorA11y *sl)
|
||||
|
||||
description = gtk_at_context_get_description (context);
|
||||
gtk_label_set_label (GTK_LABEL (sl->description), description);
|
||||
|
||||
g_object_unref (context);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -110,12 +110,11 @@ static struct {
|
||||
};
|
||||
|
||||
static FixSeverity
|
||||
check_accessibility_errors (GtkWidget *widget,
|
||||
GArray *context_elements,
|
||||
char **hint)
|
||||
check_accessibility_errors (GtkATContext *context,
|
||||
GtkAccessibleRole role,
|
||||
GArray *context_elements,
|
||||
char **hint)
|
||||
{
|
||||
GtkAccessibleRole role;
|
||||
GtkATContext *context;
|
||||
gboolean label_set;
|
||||
const char *role_name;
|
||||
GEnumClass *states;
|
||||
@ -124,11 +123,8 @@ check_accessibility_errors (GtkWidget *widget,
|
||||
gboolean has_context;
|
||||
|
||||
*hint = NULL;
|
||||
|
||||
role = gtk_accessible_get_accessible_role (GTK_ACCESSIBLE (widget));
|
||||
role_name = gtk_accessible_role_to_name (role, NULL);
|
||||
|
||||
context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (widget));
|
||||
if (!gtk_at_context_is_realized (context))
|
||||
gtk_at_context_realize (context);
|
||||
|
||||
@ -314,6 +310,23 @@ check_accessibility_errors (GtkWidget *widget,
|
||||
return SEVERITY_GOOD;
|
||||
}
|
||||
|
||||
static FixSeverity
|
||||
check_widget_accessibility_errors (GtkWidget *widget,
|
||||
GArray *context_elements,
|
||||
char **hint)
|
||||
{
|
||||
GtkAccessibleRole role;
|
||||
GtkATContext *context;
|
||||
FixSeverity ret;
|
||||
|
||||
role = gtk_accessible_get_accessible_role (GTK_ACCESSIBLE (widget));
|
||||
context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (widget));
|
||||
ret = check_accessibility_errors (context, role, context_elements, hint);
|
||||
g_object_unref (context);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
recurse_child_widgets (GtkA11yOverlay *self,
|
||||
GtkWidget *widget,
|
||||
@ -327,7 +340,7 @@ recurse_child_widgets (GtkA11yOverlay *self,
|
||||
if (!gtk_widget_get_mapped (widget))
|
||||
return;
|
||||
|
||||
severity = check_accessibility_errors (widget, self->context, &hint);
|
||||
severity = check_widget_accessibility_errors (widget, self->context, &hint);
|
||||
|
||||
if (severity != SEVERITY_GOOD)
|
||||
{
|
||||
|
@ -6,6 +6,7 @@ static void
|
||||
test_name_content (void)
|
||||
{
|
||||
GtkWidget *window, *label1, *label2, *box, *button;
|
||||
GtkATContext *context;
|
||||
char *name;
|
||||
|
||||
label1 = gtk_label_new ("a");
|
||||
@ -21,24 +22,32 @@ test_name_content (void)
|
||||
gtk_window_set_child (GTK_WINDOW (window), button);
|
||||
gtk_window_present (GTK_WINDOW (window));
|
||||
|
||||
name = gtk_at_context_get_name (gtk_accessible_get_at_context (GTK_ACCESSIBLE (label1)));
|
||||
context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (label1));
|
||||
name = gtk_at_context_get_name (context);
|
||||
g_assert_cmpstr (name, ==, "a");
|
||||
g_free (name);
|
||||
g_object_unref (context);
|
||||
|
||||
/* this is because generic doesn't allow naming */
|
||||
name = gtk_at_context_get_name (gtk_accessible_get_at_context (GTK_ACCESSIBLE (box)));
|
||||
context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (box));
|
||||
name = gtk_at_context_get_name (context);
|
||||
g_assert_cmpstr (name, ==, "");
|
||||
g_free (name);
|
||||
g_object_unref (context);
|
||||
|
||||
name = gtk_at_context_get_name (gtk_accessible_get_at_context (GTK_ACCESSIBLE (button)));
|
||||
context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (button));
|
||||
name = gtk_at_context_get_name (context);
|
||||
g_assert_cmpstr (name, ==, "a b");
|
||||
g_free (name);
|
||||
g_object_unref (context);
|
||||
|
||||
gtk_widget_set_visible (label2, FALSE);
|
||||
|
||||
name = gtk_at_context_get_name (gtk_accessible_get_at_context (GTK_ACCESSIBLE (button)));
|
||||
context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (button));
|
||||
name = gtk_at_context_get_name (context);
|
||||
g_assert_cmpstr (name, ==, "a");
|
||||
g_free (name);
|
||||
g_object_unref (context);
|
||||
|
||||
gtk_window_destroy (GTK_WINDOW (window));
|
||||
}
|
||||
@ -47,6 +56,7 @@ static void
|
||||
test_name_tooltip (void)
|
||||
{
|
||||
GtkWidget *window, *image;
|
||||
GtkATContext *context;
|
||||
char *name;
|
||||
|
||||
image = gtk_image_new ();
|
||||
@ -57,10 +67,14 @@ test_name_tooltip (void)
|
||||
|
||||
gtk_widget_set_tooltip_text (image, "tooltip");
|
||||
|
||||
name = gtk_at_context_get_name (gtk_accessible_get_at_context (GTK_ACCESSIBLE (image)));
|
||||
context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (image));
|
||||
|
||||
name = gtk_at_context_get_name (context);
|
||||
g_assert_cmpstr (name, ==, "tooltip");
|
||||
g_free (name);
|
||||
|
||||
g_object_unref (context);
|
||||
|
||||
gtk_window_destroy (GTK_WINDOW (window));
|
||||
}
|
||||
|
||||
@ -68,6 +82,7 @@ static void
|
||||
test_name_menubutton (void)
|
||||
{
|
||||
GtkWidget *window, *widget;
|
||||
GtkATContext *context;
|
||||
char *name;
|
||||
|
||||
widget = gtk_menu_button_new ();
|
||||
@ -79,10 +94,14 @@ test_name_menubutton (void)
|
||||
|
||||
gtk_widget_set_tooltip_text (widget, "tooltip");
|
||||
|
||||
name = gtk_at_context_get_name (gtk_accessible_get_at_context (GTK_ACCESSIBLE (widget)));
|
||||
context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (widget));
|
||||
|
||||
name = gtk_at_context_get_name (context);
|
||||
g_assert_cmpstr (name, ==, "tooltip");
|
||||
g_free (name);
|
||||
|
||||
g_object_unref (context);
|
||||
|
||||
gtk_window_destroy (GTK_WINDOW (window));
|
||||
}
|
||||
|
||||
@ -90,6 +109,7 @@ static void
|
||||
test_name_label (void)
|
||||
{
|
||||
GtkWidget *window, *image;
|
||||
GtkATContext *context;
|
||||
char *name;
|
||||
char *desc;
|
||||
|
||||
@ -108,8 +128,10 @@ test_name_label (void)
|
||||
GTK_ACCESSIBLE_PROPERTY_LABEL, "label",
|
||||
-1);
|
||||
|
||||
name = gtk_at_context_get_name (gtk_accessible_get_at_context (GTK_ACCESSIBLE (image)));
|
||||
desc = gtk_at_context_get_description (gtk_accessible_get_at_context (GTK_ACCESSIBLE (image)));
|
||||
context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (image));
|
||||
|
||||
name = gtk_at_context_get_name (context);
|
||||
desc = gtk_at_context_get_description (context);
|
||||
|
||||
g_assert_cmpstr (name, ==, "label");
|
||||
g_assert_cmpstr (desc, ==, "tooltip");
|
||||
@ -117,6 +139,8 @@ test_name_label (void)
|
||||
g_free (name);
|
||||
g_free (desc);
|
||||
|
||||
g_object_unref (context);
|
||||
|
||||
gtk_window_destroy (GTK_WINDOW (window));
|
||||
}
|
||||
|
||||
@ -124,6 +148,7 @@ static void
|
||||
test_name_prohibited (void)
|
||||
{
|
||||
GtkWidget *window, *widget;
|
||||
GtkATContext *context;
|
||||
char *name;
|
||||
char *desc;
|
||||
|
||||
@ -136,8 +161,10 @@ test_name_prohibited (void)
|
||||
gtk_window_set_child (GTK_WINDOW (window), widget);
|
||||
gtk_window_present (GTK_WINDOW (window));
|
||||
|
||||
name = gtk_at_context_get_name (gtk_accessible_get_at_context (GTK_ACCESSIBLE (widget)));
|
||||
desc = gtk_at_context_get_description (gtk_accessible_get_at_context (GTK_ACCESSIBLE (widget)));
|
||||
context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (widget));
|
||||
|
||||
name = gtk_at_context_get_name (context);
|
||||
desc = gtk_at_context_get_description (context);
|
||||
|
||||
g_assert_cmpstr (name, ==, "");
|
||||
g_assert_cmpstr (desc, ==, "");
|
||||
@ -145,6 +172,8 @@ test_name_prohibited (void)
|
||||
g_free (name);
|
||||
g_free (desc);
|
||||
|
||||
g_object_unref (context);
|
||||
|
||||
gtk_window_destroy (GTK_WINDOW (window));
|
||||
}
|
||||
|
||||
@ -152,6 +181,7 @@ static void
|
||||
test_name_range (void)
|
||||
{
|
||||
GtkWidget *window, *scale;
|
||||
GtkATContext *context;
|
||||
char *name;
|
||||
|
||||
scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0, 100, 10);
|
||||
@ -160,16 +190,20 @@ test_name_range (void)
|
||||
gtk_window_set_child (GTK_WINDOW (window), scale);
|
||||
gtk_window_present (GTK_WINDOW (window));
|
||||
|
||||
context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (scale));
|
||||
|
||||
g_assert_true (gtk_accessible_get_accessible_role (GTK_ACCESSIBLE (scale)) == GTK_ACCESSIBLE_ROLE_SLIDER);
|
||||
g_assert_true (gtk_at_context_get_accessible_role (gtk_accessible_get_at_context (GTK_ACCESSIBLE (scale))) == GTK_ACCESSIBLE_ROLE_SLIDER);
|
||||
g_assert_true (gtk_at_context_get_accessible_role (context) == GTK_ACCESSIBLE_ROLE_SLIDER);
|
||||
|
||||
gtk_range_set_value (GTK_RANGE (scale), 50);
|
||||
|
||||
name = gtk_at_context_get_name (gtk_accessible_get_at_context (GTK_ACCESSIBLE (scale)));
|
||||
name = gtk_at_context_get_name (context);
|
||||
g_assert_cmpstr (name, ==, "50");
|
||||
|
||||
g_free (name);
|
||||
|
||||
g_object_unref (context);
|
||||
|
||||
gtk_window_destroy (GTK_WINDOW (window));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user