eel: Remove a11y utilities

In theory, it would be possible to just drop the GAIL code and keep the
header, but, given that NautilusCanvasItem is the only remaining
consumer, the needed bits can be moved over.
This commit is contained in:
Ernestas Kulik 2018-05-14 09:46:43 +03:00
parent 0cad9482c0
commit bde55f4189
8 changed files with 67 additions and 307 deletions

View file

@ -94,7 +94,7 @@ ubuntu:devel:
libgnome-autoar-0-dev
gobject-introspection libxml2-dev
libtracker-control-2.0-dev desktop-file-utils libgexiv2-dev
libgail-3-dev libtracker-sparql-2.0-dev
libtracker-sparql-2.0-dev
libgirepository1.0-dev
<<: *distro_test
only:

View file

@ -1,183 +0,0 @@
/* eel-accessibility.h - Utility functions for accessibility
*
* Copyright (C) 2002 Anders Carlsson, Sun Microsystems, Inc.
*
* The Eel Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* The Eel 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with the Eel Library; see the file COPYING.LIB. If not,
* see <http://www.gnu.org/licenses/>.
*
* Authors:
* Anders Carlsson <andersca@gnu.org>
* Michael Meeks <michael@ximian.com>
*/
#include <config.h>
#include <gtk/gtk.h>
#include <atk/atkrelationset.h>
#include <eel/eel-accessibility.h>
void
eel_accessibility_set_up_label_widget_relation (GtkWidget *label,
GtkWidget *widget)
{
AtkObject *atk_widget, *atk_label;
atk_label = gtk_widget_get_accessible (label);
atk_widget = gtk_widget_get_accessible (widget);
/* Create the label -> widget relation */
atk_object_add_relationship (atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
/* Create the widget -> label relation */
atk_object_add_relationship (atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
}
static GailTextUtil *
get_simple_text (gpointer object)
{
GObject *gobject;
EelAccessibleTextIface *aif;
if (GTK_IS_ACCESSIBLE (object))
{
gobject = G_OBJECT (gtk_accessible_get_widget (GTK_ACCESSIBLE (object)));
}
else
{
gobject = atk_gobject_accessible_get_object (object);
}
if (!gobject)
{
return NULL;
}
aif = EEL_ACCESSIBLE_TEXT_GET_IFACE (gobject);
if (!aif)
{
g_warning ("No accessible text inferface on '%s'",
g_type_name_from_instance ((gpointer) gobject));
}
else if (aif->get_text)
{
return aif->get_text (gobject);
}
return NULL;
}
char *
eel_accessibility_text_get_text (AtkText *text,
gint start_pos,
gint end_pos)
{
GailTextUtil *util = get_simple_text (text);
g_return_val_if_fail (util != NULL, NULL);
return gail_text_util_get_substring (util, start_pos, end_pos);
}
gunichar
eel_accessibility_text_get_character_at_offset (AtkText *text,
gint offset)
{
char *txt, *index;
gint sucks1 = 0, sucks2 = -1;
gunichar c;
GailTextUtil *util = get_simple_text (text);
g_return_val_if_fail (util != NULL, 0);
txt = gail_text_util_get_substring (util, sucks1, sucks2);
index = g_utf8_offset_to_pointer (txt, offset);
c = g_utf8_get_char (index);
g_free (txt);
return c;
}
char *
eel_accessibility_text_get_text_before_offset (AtkText *text,
gint offset,
AtkTextBoundary boundary_type,
gint *start_offset,
gint *end_offset)
{
GailTextUtil *util = get_simple_text (text);
g_return_val_if_fail (util != NULL, NULL);
return gail_text_util_get_text (
util, NULL, GAIL_BEFORE_OFFSET,
boundary_type, offset, start_offset, end_offset);
}
char *
eel_accessibility_text_get_text_at_offset (AtkText *text,
gint offset,
AtkTextBoundary boundary_type,
gint *start_offset,
gint *end_offset)
{
GailTextUtil *util = get_simple_text (text);
g_return_val_if_fail (util != NULL, NULL);
return gail_text_util_get_text (
util, NULL, GAIL_AT_OFFSET,
boundary_type, offset, start_offset, end_offset);
}
gchar *
eel_accessibility_text_get_text_after_offset (AtkText *text,
gint offset,
AtkTextBoundary boundary_type,
gint *start_offset,
gint *end_offset)
{
GailTextUtil *util = get_simple_text (text);
g_return_val_if_fail (util != NULL, NULL);
return gail_text_util_get_text (
util, NULL, GAIL_AFTER_OFFSET,
boundary_type, offset, start_offset, end_offset);
}
gint
eel_accessibility_text_get_character_count (AtkText *text)
{
GailTextUtil *util = get_simple_text (text);
g_return_val_if_fail (util != NULL, -1);
return gtk_text_buffer_get_char_count (util->buffer);
}
GType
eel_accessible_text_get_type (void)
{
static GType type = 0;
if (!type)
{
const GTypeInfo tinfo =
{
sizeof (AtkTextIface),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) NULL,
(GClassFinalizeFunc) NULL
};
type = g_type_register_static (
G_TYPE_INTERFACE, "EelAccessibleText", &tinfo, 0);
}
return type;
}

View file

@ -1,76 +0,0 @@
/* eel-accessibility.h - Utility functions for accessibility
Copyright (C) 2002 Anders Carlsson
The Eel Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Eel 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Eel Library; see the file COPYING.LIB. If not,
see <http://www.gnu.org/licenses/>.
Authors: Anders Carlsson <andersca@gnu.org>
*/
#pragma once
#include <glib-object.h>
#include <atk/atkobject.h>
#include <atk/atkregistry.h>
#include <atk/atkobjectfactory.h>
#include <gtk/gtk.h>
#include <libgail-util/gailtextutil.h>
void eel_accessibility_set_up_label_widget_relation (GtkWidget *label, GtkWidget *widget);
char* eel_accessibility_text_get_text (AtkText *text,
gint start_pos,
gint end_pos);
gunichar eel_accessibility_text_get_character_at_offset
(AtkText *text,
gint offset);
char* eel_accessibility_text_get_text_before_offset
(AtkText *text,
gint offset,
AtkTextBoundary boundary_type,
gint *start_offset,
gint *end_offset);
char* eel_accessibility_text_get_text_at_offset
(AtkText *text,
gint offset,
AtkTextBoundary boundary_type,
gint *start_offset,
gint *end_offset);
char* eel_accessibility_text_get_text_after_offset
(AtkText *text,
gint offset,
AtkTextBoundary boundary_type,
gint *start_offset,
gint *end_offset);
gint eel_accessibility_text_get_character_count
(AtkText *text);
#define EEL_TYPE_ACCESSIBLE_TEXT (eel_accessible_text_get_type ())
#define EEL_IS_ACCESSIBLE_TEXT(obj) G_TYPE_CHECK_INSTANCE_TYPE ((obj), EEL_TYPE_ACCESSIBLE_TEXT)
#define EEL_ACCESSIBLE_TEXT(obj) G_TYPE_CHECK_INSTANCE_CAST ((obj), EEL_TYPE_ACCESSIBLE_TEXT, EelAccessibleText)
#define EEL_ACCESSIBLE_TEXT_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), EEL_TYPE_ACCESSIBLE_TEXT, EelAccessibleTextIface))
/* Instead of implementing the AtkText interface, implement this */
typedef struct _EelAccessibleText EelAccessibleText;
typedef struct {
GTypeInterface parent;
GailTextUtil *(*get_text) (GObject *text);
PangoLayout *(*get_layout) (GObject *text);
} EelAccessibleTextIface;
GType eel_accessible_text_get_type (void);

View file

@ -1,6 +1,4 @@
libeel_2_sources = [
'eel-accessibility.h',
'eel-accessibility.c',
'eel-art-extensions.h',
'eel-art-extensions.c',
'eel-canvas.h',
@ -27,7 +25,6 @@ libeel_2_sources = [
libeel_2_deps = [
config_h,
gail,
glib,
gtk,
libm,

View file

@ -69,7 +69,6 @@ libgd_dep = libgd.get_variable('libgd_dep')
libm = cc.find_library('m')
gail = dependency('gail-3.0')
if get_option('extensions')
gexiv = dependency('gexiv2', version: '>= 0.10.0')
endif

View file

@ -25,7 +25,6 @@
#include "nautilus-canvas-container.h"
#include <atk/atkaction.h>
#include <eel/eel-accessibility.h>
#include <eel/eel-art-extensions.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-vfs-extensions.h>

View file

@ -31,7 +31,6 @@
#include <eel/eel-glib-extensions.h>
#include <eel/eel-graphic-effects.h>
#include <eel/eel-string.h>
#include <eel/eel-accessibility.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
@ -131,8 +130,7 @@ struct NautilusCanvasItemDetails
GdkWindow *cursor_window;
/* Accessibility bits */
GailTextUtil *text_util;
GString *text;
};
/* Object argument IDs. */
@ -155,12 +153,9 @@ typedef enum
TOP_SIDE
} RectangleSide;
static void nautilus_canvas_item_text_interface_init (EelAccessibleTextIface *iface);
static GType nautilus_canvas_item_accessible_factory_get_type (void);
G_DEFINE_TYPE_WITH_CODE (NautilusCanvasItem, nautilus_canvas_item, EEL_TYPE_CANVAS_ITEM,
G_IMPLEMENT_INTERFACE (EEL_TYPE_ACCESSIBLE_TEXT,
nautilus_canvas_item_text_interface_init));
G_DEFINE_TYPE (NautilusCanvasItem, nautilus_canvas_item, EEL_TYPE_CANVAS_ITEM)
/* private */
static void get_icon_rectangle (NautilusCanvasItem *item,
@ -199,9 +194,10 @@ nautilus_canvas_item_finalize (GObject *object)
g_object_unref (details->pixbuf);
}
if (details->text_util != NULL)
if (details->text != NULL)
{
g_object_unref (details->text_util);
g_string_free (details->text, TRUE);
details->text = NULL;
}
g_free (details->editable_text);
@ -295,10 +291,10 @@ nautilus_canvas_item_set_property (GObject *object,
is_rename = details->editable_text != NULL;
g_free (details->editable_text);
details->editable_text = g_strdup (g_value_get_string (value));
if (details->text_util)
if (details->text)
{
gail_text_util_text_setup (details->text_util,
details->editable_text);
details->text = g_string_assign (details->text, details->editable_text);
if (is_rename)
g_object_notify (G_OBJECT (accessible), "accessible-name");
}
@ -1901,18 +1897,6 @@ nautilus_canvas_item_class_init (NautilusCanvasItemClass *class)
g_type_class_add_private (class, sizeof (NautilusCanvasItemDetails));
}
static GailTextUtil *
nautilus_canvas_item_get_text (GObject *text)
{
return NAUTILUS_CANVAS_ITEM (text)->details->text_util;
}
static void
nautilus_canvas_item_text_interface_init (EelAccessibleTextIface *iface)
{
iface->get_text = nautilus_canvas_item_get_text;
}
/* ============================= a11y interfaces =========================== */
static const char *nautilus_canvas_item_accessible_action_names[] =
@ -2549,15 +2533,53 @@ nautilus_canvas_item_accessible_get_character_extents (AtkText *text,
*height = PANGO_PIXELS (rect.height);
}
static char *
nautilus_canvas_item_accessible_text_get_text (AtkText *text,
gint start_pos,
gint end_pos)
{
GObject *object;
NautilusCanvasItem *item;
object = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text));
item = NAUTILUS_CANVAS_ITEM (object);
return g_utf8_substring (item->details->text->str, start_pos, end_pos);
}
static gunichar
nautilus_canvas_item_accessible_text_get_character_at_offset (AtkText *text,
gint offset)
{
GObject *object;
NautilusCanvasItem *item;
gchar *pointer;
object = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text));
item = NAUTILUS_CANVAS_ITEM (object);
pointer = g_utf8_offset_to_pointer (item->details->text->str, offset);
return g_utf8_get_char (pointer);
}
static gint
nautilus_canvas_item_accessible_text_get_character_count (AtkText *text)
{
GObject *object;
NautilusCanvasItem *item;
object = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text));
item = NAUTILUS_CANVAS_ITEM (object);
return g_utf8_strlen (item->details->text->str, -1);
}
static void
nautilus_canvas_item_accessible_text_interface_init (AtkTextIface *iface)
{
iface->get_text = eel_accessibility_text_get_text;
iface->get_character_at_offset = eel_accessibility_text_get_character_at_offset;
iface->get_text_before_offset = eel_accessibility_text_get_text_before_offset;
iface->get_text_at_offset = eel_accessibility_text_get_text_at_offset;
iface->get_text_after_offset = eel_accessibility_text_get_text_after_offset;
iface->get_character_count = eel_accessibility_text_get_character_count;
iface->get_text = nautilus_canvas_item_accessible_text_get_text;
iface->get_character_at_offset = nautilus_canvas_item_accessible_text_get_character_at_offset;
iface->get_character_count = nautilus_canvas_item_accessible_text_get_character_count;
iface->get_character_extents = nautilus_canvas_item_accessible_get_character_extents;
iface->get_offset_at_point = nautilus_canvas_item_accessible_get_offset_at_point;
}
@ -2678,26 +2700,20 @@ nautilus_canvas_item_accessible_factory_create_accessible (GObject *for_object)
{
AtkObject *accessible;
NautilusCanvasItem *item;
GString *item_text;
item = NAUTILUS_CANVAS_ITEM (for_object);
g_assert (item != NULL);
item_text = g_string_new (NULL);
item->details->text = g_string_new (NULL);
if (item->details->editable_text)
{
g_string_append (item_text, item->details->editable_text);
g_string_append (item->details->text, item->details->editable_text);
}
if (item->details->additional_text)
{
g_string_append (item_text, item->details->additional_text);
g_string_append (item->details->text, item->details->additional_text);
}
item->details->text_util = gail_text_util_new ();
gail_text_util_text_setup (item->details->text_util,
item_text->str);
g_string_free (item_text, TRUE);
accessible = g_object_new (nautilus_canvas_item_accessible_get_type (), NULL);
atk_object_initialize (accessible, for_object);

View file

@ -22,7 +22,6 @@
#include "nautilus-properties-window.h"
#include <cairo.h>
#include <eel/eel-accessibility.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-stock-dialogs.h>
#include <eel/eel-string.h>
@ -3714,8 +3713,17 @@ add_execute_checkbox_with_label (NautilusPropertiesWindow *window,
a11y_enabled = GTK_IS_ACCESSIBLE (gtk_widget_get_accessible (check_button));
if (a11y_enabled && label_for != NULL)
{
eel_accessibility_set_up_label_widget_relation (GTK_WIDGET (label_for),
check_button);
AtkObject *atk_widget;
AtkObject *atk_label;
atk_label = gtk_widget_get_accessible (GTK_WIDGET (label_for));
atk_widget = gtk_widget_get_accessible (check_button);
/* Create the label -> widget relation */
atk_object_add_relationship (atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
/* Create the widget -> label relation */
atk_object_add_relationship (atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
}
return check_button;