[gtk/wip/ebassi/a11y-2: 430/442] a11y: Simplify GtkExpanderAccessible
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/ebassi/a11y-2: 430/442] a11y: Simplify GtkExpanderAccessible
- Date: Fri, 5 Jun 2020 19:37:27 +0000 (UTC)
commit d60f7f2e7a5e3ba4c7f02f7b5190c3e8ed2a8e0d
Author: Emmanuele Bassi <ebassi gnome org>
Date: Wed May 27 20:02:07 2020 +0100
a11y: Simplify GtkExpanderAccessible
Drop the GtkWidgetAccessible.notify_gtk and AtkObject.initialize
overrides, and have GtkExpander update the state of the accessible
object directly.
gtk/a11y/gtkexpanderaccessible.c | 55 ++++++++++++---------------------
gtk/a11y/gtkexpanderaccessibleprivate.h | 31 +++++++++++++++++++
gtk/gtkexpander.c | 17 +++++++++-
3 files changed, 66 insertions(+), 37 deletions(-)
---
diff --git a/gtk/a11y/gtkexpanderaccessible.c b/gtk/a11y/gtkexpanderaccessible.c
index be54d83e53..a4d323df15 100644
--- a/gtk/a11y/gtkexpanderaccessible.c
+++ b/gtk/a11y/gtkexpanderaccessible.c
@@ -17,9 +17,10 @@
#include "config.h"
+#include "gtkexpanderaccessibleprivate.h"
+
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
-#include "gtkexpanderaccessible.h"
static void atk_action_interface_init (AtkActionIface *iface);
@@ -91,41 +92,27 @@ gtk_expander_accessible_ref_child (AtkObject *obj,
return accessible;
}
-static void
-gtk_expander_accessible_initialize (AtkObject *obj,
- gpointer data)
+void
+gtk_expander_accessible_update_label (GtkExpanderAccessible *self)
{
- ATK_OBJECT_CLASS (gtk_expander_accessible_parent_class)->initialize (obj, data);
+ AtkObject *atk_obj = ATK_OBJECT (self);
+
+ if (atk_obj->name == NULL)
+ g_object_notify (G_OBJECT (atk_obj), "accessible-name");
- obj->role = ATK_ROLE_TOGGLE_BUTTON;
+ g_signal_emit_by_name (atk_obj, "visible-data-changed");
}
-static void
-gtk_expander_accessible_notify_gtk (GObject *obj,
- GParamSpec *pspec)
+void
+gtk_expander_accessible_update_state (GtkExpanderAccessible *self,
+ gboolean expanded)
{
- AtkObject* atk_obj;
- GtkExpander *expander;
+ AtkObject *atk_obj = ATK_OBJECT (self);
- expander = GTK_EXPANDER (obj);
- atk_obj = gtk_widget_get_accessible (GTK_WIDGET (expander));
-;
- if (g_strcmp0 (pspec->name, "label") == 0)
- {
- if (atk_obj->name == NULL)
- g_object_notify (G_OBJECT (atk_obj), "accessible-name");
- g_signal_emit_by_name (atk_obj, "visible-data-changed");
- }
- else if (g_strcmp0 (pspec->name, "expanded") == 0)
- {
- atk_object_notify_state_change (atk_obj, ATK_STATE_CHECKED,
- gtk_expander_get_expanded (expander));
- atk_object_notify_state_change (atk_obj, ATK_STATE_EXPANDED,
- gtk_expander_get_expanded (expander));
- g_signal_emit_by_name (atk_obj, "visible-data-changed");
- }
- else
- GTK_WIDGET_ACCESSIBLE_CLASS (gtk_expander_accessible_parent_class)->notify_gtk (obj, pspec);
+ atk_object_notify_state_change (atk_obj, ATK_STATE_CHECKED, expanded);
+ atk_object_notify_state_change (atk_obj, ATK_STATE_EXPANDED, expanded);
+
+ g_signal_emit_by_name (atk_obj, "visible-data-changed");
}
static AtkStateSet *
@@ -158,21 +145,17 @@ static void
gtk_expander_accessible_class_init (GtkExpanderAccessibleClass *klass)
{
AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
- GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
-
- widget_class->notify_gtk = gtk_expander_accessible_notify_gtk;
class->get_name = gtk_expander_accessible_get_name;
class->get_n_children = gtk_expander_accessible_get_n_children;
class->ref_child = gtk_expander_accessible_ref_child;
class->ref_state_set = gtk_expander_accessible_ref_state_set;
-
- class->initialize = gtk_expander_accessible_initialize;
}
static void
-gtk_expander_accessible_init (GtkExpanderAccessible *expander)
+gtk_expander_accessible_init (GtkExpanderAccessible *self)
{
+ ATK_OBJECT (self)->role = ATK_ROLE_TOGGLE_BUTTON;
}
static gboolean
diff --git a/gtk/a11y/gtkexpanderaccessibleprivate.h b/gtk/a11y/gtkexpanderaccessibleprivate.h
new file mode 100644
index 0000000000..aab9ee5e5e
--- /dev/null
+++ b/gtk/a11y/gtkexpanderaccessibleprivate.h
@@ -0,0 +1,31 @@
+/* gtkexpanderaccessibleprivate.h: GtkExpanderAccessible private API
+ *
+ * Copyright 2020 GNOME Foundation
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "gtkexpanderaccessible.h"
+
+G_BEGIN_DECLS
+
+void gtk_expander_accessible_update_label (GtkExpanderAccessible *self);
+void gtk_expander_accessible_update_state (GtkExpanderAccessible *self,
+ gboolean expanded);
+
+G_END_DECLS
diff --git a/gtk/gtkexpander.c b/gtk/gtkexpander.c
index 819af9d502..396c769989 100644
--- a/gtk/gtkexpander.c
+++ b/gtk/gtkexpander.c
@@ -126,7 +126,7 @@
#include "gtkstylecontextprivate.h"
#include "gtkwidgetprivate.h"
-#include "a11y/gtkexpanderaccessible.h"
+#include "a11y/gtkexpanderaccessibleprivate.h"
#include <string.h>
@@ -882,6 +882,14 @@ gtk_expander_set_expanded (GtkExpander *expander,
gtk_expander_resize_toplevel (expander);
}
+ {
+ AtkObject *accessible = _gtk_widget_peek_accessible (GTK_WIDGET (expander));
+
+ if (accessible != NULL)
+ gtk_expander_accessible_update_state (GTK_EXPANDER_ACCESSIBLE (accessible),
+ expander->expanded);
+ }
+
g_object_notify (G_OBJECT (expander), "expanded");
}
@@ -935,6 +943,13 @@ gtk_expander_set_label (GtkExpander *expander,
gtk_expander_set_label_widget (expander, child);
}
+ {
+ AtkObject *accessible = _gtk_widget_peek_accessible (GTK_WIDGET (expander));
+
+ if (accessible != NULL)
+ gtk_expander_accessible_update_label (GTK_EXPANDER_ACCESSIBLE (accessible));
+ }
+
g_object_notify (G_OBJECT (expander), "label");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]