a11y: Simplify GtkNotebookAccessible

Let the GtkNotebook explicitly update the accessible object that the
current page has changed, instead of overriding
GtkWidgetAccessible.notify_gtk.
This commit is contained in:
Emmanuele Bassi 2020-05-28 14:54:57 +01:00
parent 24e8b484e0
commit 7480fb703e
3 changed files with 66 additions and 47 deletions

View File

@ -17,10 +17,12 @@
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "gtknotebookaccessible.h"
#include "gtknotebookaccessibleprivate.h"
#include "gtknotebookpageaccessible.h"
#include "gtknotebook.h"
#include <string.h>
struct _GtkNotebookAccessiblePrivate
{
@ -153,30 +155,17 @@ gtk_notebook_accessible_ref_child (AtkObject *obj,
return child;
}
static void
gtk_notebook_accessible_notify_gtk (GObject *obj,
GParamSpec *pspec)
void
gtk_notebook_accessible_update_page (GtkNotebookAccessible *self,
int page_num)
{
GtkWidget *widget;
AtkObject* atk_obj;
GtkNotebookAccessiblePrivate *priv = gtk_notebook_accessible_get_instance_private (self);
AtkObject *atk_obj = ATK_OBJECT (self);
int old_page_num = priv->selected_page;
widget = GTK_WIDGET (obj);
atk_obj = gtk_widget_get_accessible (widget);
if (strcmp (pspec->name, "page") == 0)
{
gint page_num, old_page_num;
GtkNotebookAccessible *accessible;
GtkNotebook *notebook;
accessible = GTK_NOTEBOOK_ACCESSIBLE (atk_obj);
notebook = GTK_NOTEBOOK (widget);
priv->selected_page = page_num;
/* Notify SELECTED state change for old and new page */
old_page_num = accessible->priv->selected_page;
page_num = gtk_notebook_get_current_page (notebook);
accessible->priv->selected_page = page_num;
if (page_num != old_page_num)
{
AtkObject *child;
@ -184,25 +173,24 @@ gtk_notebook_accessible_notify_gtk (GObject *obj,
if (old_page_num != -1)
{
child = gtk_notebook_accessible_ref_child (atk_obj, old_page_num);
if (child)
if (child != NULL)
{
atk_object_notify_state_change (child, ATK_STATE_SELECTED, FALSE);
g_object_unref (child);
}
}
child = gtk_notebook_accessible_ref_child (atk_obj, page_num);
if (child)
if (child != NULL)
{
atk_object_notify_state_change (child, ATK_STATE_SELECTED, TRUE);
g_object_unref (child);
}
g_signal_emit_by_name (atk_obj, "selection-changed");
g_signal_emit_by_name (atk_obj, "visible-data-changed");
}
}
else
GTK_WIDGET_ACCESSIBLE_CLASS (gtk_notebook_accessible_parent_class)->notify_gtk (obj, pspec);
}
/*
* GtkNotebook only supports the selection of one page at a time.
@ -230,14 +218,11 @@ gtk_notebook_accessible_class_init (GtkNotebookAccessibleClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
gobject_class->finalize = gtk_notebook_accessible_finalize;
class->ref_child = gtk_notebook_accessible_ref_child;
class->initialize = gtk_notebook_accessible_initialize;
widget_class->notify_gtk = gtk_notebook_accessible_notify_gtk;
}
static void

View File

@ -0,0 +1,30 @@
/* gtknotebookaccessibleprivate.h: GtkNotebookAccessible 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 "gtknotebookaccessible.h"
G_BEGIN_DECLS
void gtk_notebook_accessible_update_page (GtkNotebookAccessible *self,
int page_num);
G_END_DECLS

View File

@ -55,7 +55,7 @@
#include "gtkwidgetpaintable.h"
#include "gtknative.h"
#include "a11y/gtknotebookaccessible.h"
#include "a11y/gtknotebookaccessibleprivate.h"
#include <stdio.h>
#include <string.h>
@ -5298,6 +5298,7 @@ gtk_notebook_real_switch_page (GtkNotebook *notebook,
{
GList *list = gtk_notebook_find_child (notebook, GTK_WIDGET (child));
GtkNotebookPage *page = GTK_NOTEBOOK_PAGE_FROM_LIST (list);
AtkObject *accessible;
gboolean child_has_focus;
if (notebook->cur_page == page || !gtk_widget_get_visible (GTK_WIDGET (child)))
@ -5343,6 +5344,11 @@ gtk_notebook_real_switch_page (GtkNotebook *notebook,
update_arrow_state (notebook);
accessible = _gtk_widget_peek_accessible (GTK_WIDGET (notebook));
if (accessible != NULL)
gtk_notebook_accessible_update_page (GTK_NOTEBOOK_ACCESSIBLE (accessible),
gtk_notebook_get_current_page (notebook));
gtk_widget_queue_resize (GTK_WIDGET (notebook));
gtk_widget_queue_resize (notebook->tabs_widget);
g_object_notify_by_pspec (G_OBJECT (notebook), properties[PROP_PAGE]);
@ -5904,8 +5910,6 @@ gtk_notebook_set_current_page (GtkNotebook *notebook,
list = g_list_nth (notebook->children, page_num);
if (list)
gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE_FROM_LIST (list));
g_object_notify_by_pspec (G_OBJECT (notebook), properties[PROP_PAGE]);
}
/**