a11y: Simplify GtkExpanderAccessible

Drop the GtkWidgetAccessible.notify_gtk and AtkObject.initialize
overrides, and have GtkExpander update the state of the accessible
object directly.
This commit is contained in:
Emmanuele Bassi 2020-05-27 20:02:07 +01:00
parent 0dcffe7c33
commit d60f7f2e7a
3 changed files with 66 additions and 37 deletions

View File

@ -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);
obj->role = ATK_ROLE_TOGGLE_BUTTON;
if (atk_obj->name == NULL)
g_object_notify (G_OBJECT (atk_obj), "accessible-name");
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

View File

@ -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

View File

@ -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");
}