From ac3f0df0834da27e4448a0b0e14c375736dcd384 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 27 May 2020 16:04:29 +0100 Subject: [PATCH] a11y: Simplify GtkProgressBarAccessible Drop the GtkWidgetAccessibleClass.notify_gtk and the AtkObjectClass.initialize overrides: they don't do anything relevant. Instead, have GtkProgressBar update the accessible state when the fraction changes. --- gtk/a11y/gtkprogressbaraccessible.c | 36 ++++------------------ gtk/a11y/gtkprogressbaraccessibleprivate.h | 29 +++++++++++++++++ gtk/gtkprogressbar.c | 10 +++++- 3 files changed, 44 insertions(+), 31 deletions(-) create mode 100644 gtk/a11y/gtkprogressbaraccessibleprivate.h diff --git a/gtk/a11y/gtkprogressbaraccessible.c b/gtk/a11y/gtkprogressbaraccessible.c index 62313f0ccc..99aaf95624 100644 --- a/gtk/a11y/gtkprogressbaraccessible.c +++ b/gtk/a11y/gtkprogressbaraccessible.c @@ -21,52 +21,28 @@ #include -#include "gtkprogressbaraccessible.h" - +#include "gtkprogressbaraccessibleprivate.h" static void atk_value_interface_init (AtkValueIface *iface); G_DEFINE_TYPE_WITH_CODE (GtkProgressBarAccessible, gtk_progress_bar_accessible, GTK_TYPE_WIDGET_ACCESSIBLE, G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init)) -static void -gtk_progress_bar_accessible_initialize (AtkObject *obj, - gpointer data) +void +gtk_progress_bar_accessible_update_value (GtkProgressBarAccessible *self) { - ATK_OBJECT_CLASS (gtk_progress_bar_accessible_parent_class)->initialize (obj, data); - - obj->role = ATK_ROLE_PROGRESS_BAR; -} - -static void -gtk_progress_bar_accessible_notify_gtk (GObject *obj, - GParamSpec *pspec) -{ - GtkWidget *widget = GTK_WIDGET (obj); - AtkObject *accessible; - - accessible = gtk_widget_get_accessible (widget); - - if (strcmp (pspec->name, "fraction") == 0) - g_object_notify (G_OBJECT (accessible), "accessible-value"); - else - GTK_WIDGET_ACCESSIBLE_CLASS (gtk_progress_bar_accessible_parent_class)->notify_gtk (obj, pspec); + g_object_notify (G_OBJECT (self), "accessible-value"); } static void gtk_progress_bar_accessible_class_init (GtkProgressBarAccessibleClass *klass) { - AtkObjectClass *class = ATK_OBJECT_CLASS (klass); - GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass; - - widget_class->notify_gtk = gtk_progress_bar_accessible_notify_gtk; - - class->initialize = gtk_progress_bar_accessible_initialize; } static void -gtk_progress_bar_accessible_init (GtkProgressBarAccessible *bar) +gtk_progress_bar_accessible_init (GtkProgressBarAccessible *self) { + ATK_OBJECT (self)->role = ATK_ROLE_PROGRESS_BAR; } static void diff --git a/gtk/a11y/gtkprogressbaraccessibleprivate.h b/gtk/a11y/gtkprogressbaraccessibleprivate.h new file mode 100644 index 0000000000..120d21c5b2 --- /dev/null +++ b/gtk/a11y/gtkprogressbaraccessibleprivate.h @@ -0,0 +1,29 @@ +/* gtkprogressbaraccessibleprivate.h: Private GtkProgressBarAccessible 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 . + */ + +#pragma once + +#include "gtkprogressbaraccessible.h" + +G_BEGIN_DECLS + +void gtk_progress_bar_accessible_update_value (GtkProgressBarAccessible *self); + +G_END_DECLS diff --git a/gtk/gtkprogressbar.c b/gtk/gtkprogressbar.c index 53104999aa..8490024f4b 100644 --- a/gtk/gtkprogressbar.c +++ b/gtk/gtkprogressbar.c @@ -39,7 +39,7 @@ #include "gtkstylecontextprivate.h" #include "gtkwidgetprivate.h" -#include "a11y/gtkprogressbaraccessible.h" +#include "a11y/gtkprogressbaraccessibleprivate.h" #include @@ -732,6 +732,14 @@ gtk_progress_bar_set_fraction (GtkProgressBar *pbar, gtk_widget_queue_allocate (pbar->trough_widget); update_fraction_classes (pbar); + { + AtkObject *accessible = + _gtk_widget_peek_accessible (GTK_WIDGET (pbar)); + + if (accessible != NULL) + gtk_progress_bar_accessible_update_value (GTK_PROGRESS_BAR_ACCESSIBLE (accessible)); + } + g_object_notify_by_pspec (G_OBJECT (pbar), progress_props[PROP_FRACTION]); }