[evince] a11y: Do not use AtkFactory to create the EvViewAccessible
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince] a11y: Do not use AtkFactory to create the EvViewAccessible
- Date: Mon, 7 Jan 2013 16:55:44 +0000 (UTC)
commit 37c58deec0b608b9807a067699c315445bf40caf
Author: Carlos Garcia Campos <carlosgc gnome org>
Date: Sat Jan 5 15:19:35 2013 +0100
a11y: Do not use AtkFactory to create the EvViewAccessible
https://bugzilla.gnome.org/show_bug.cgi?id=685828
libview/ev-view-accessible.c | 149 +++++++++++------------------------------
libview/ev-view-accessible.h | 25 +++++++-
libview/ev-view-private.h | 2 +-
libview/ev-view.c | 59 +++--------------
4 files changed, 75 insertions(+), 160 deletions(-)
---
diff --git a/libview/ev-view-accessible.c b/libview/ev-view-accessible.c
index 73b833a..f2e251b 100644
--- a/libview/ev-view-accessible.c
+++ b/libview/ev-view-accessible.c
@@ -29,11 +29,8 @@
#include "ev-view-accessible.h"
#include "ev-view-private.h"
-#define EV_TYPE_VIEW_ACCESSIBLE (ev_view_accessible_get_type ())
-#define EV_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_VIEW_ACCESSIBLE, EvViewAccessible))
-#define EV_IS_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EV_TYPE_VIEW_ACCESSIBLE))
-
-static GType ev_view_accessible_get_type (void);
+static void ev_view_accessible_text_iface_init (AtkTextIface *iface);
+static void ev_view_accessible_action_iface_init (AtkActionIface *iface);
enum {
ACTION_SCROLL_UP,
@@ -55,24 +52,24 @@ static const gchar *const ev_view_accessible_action_descriptions[] =
NULL
};
-typedef struct {
+struct _EvViewAccessiblePrivate {
/* Action */
gchar *action_descriptions[LAST_ACTION];
guint action_idle_handler;
GtkScrollType idle_scroll;
GtkTextBuffer *buffer;
guint current_page;
-} EvViewAccessiblePriv;
-
-typedef GtkAccessibleClass EvViewAccessibleClass;
-typedef GtkAccessible EvViewAccessible;
+};
-#define EV_VIEW_ACCESSIBLE_GET_PRIVATE(inst) (G_TYPE_INSTANCE_GET_PRIVATE ((inst), EV_TYPE_VIEW_ACCESSIBLE, EvViewAccessiblePriv))
+G_DEFINE_TYPE_WITH_CODE (EvViewAccessible, ev_view_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
+ G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT, ev_view_accessible_text_iface_init);
+ G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, ev_view_accessible_action_iface_init);
+ )
static void
ev_view_accessible_finalize (GObject *object)
{
- EvViewAccessiblePriv *priv = EV_VIEW_ACCESSIBLE_GET_PRIVATE (object);
+ EvViewAccessiblePrivate *priv = EV_VIEW_ACCESSIBLE (object)->priv;
int i;
if (priv->action_idle_handler)
@@ -84,13 +81,33 @@ ev_view_accessible_finalize (GObject *object)
}
+static void
+ev_view_accessible_initialize (AtkObject *obj,
+ gpointer data)
+{
+ if (ATK_OBJECT_CLASS (ev_view_accessible_parent_class)->initialize != NULL)
+ ATK_OBJECT_CLASS (ev_view_accessible_parent_class)->initialize (obj, data);
+
+ gtk_accessible_set_widget (GTK_ACCESSIBLE (obj), GTK_WIDGET (data));
+
+ atk_object_set_name (obj, _("Document View"));
+ atk_object_set_role (obj, ATK_ROLE_DOCUMENT_FRAME);
+}
+
static void ev_view_accessible_class_init (EvViewAccessibleClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
object_class->finalize = ev_view_accessible_finalize;
+ atk_class->initialize = ev_view_accessible_initialize;
+
+ g_type_class_add_private (klass, sizeof (EvViewAccessiblePrivate));
+}
- g_type_class_add_private (klass, sizeof (EvViewAccessiblePriv));
+static void ev_view_accessible_init (EvViewAccessible *accessible)
+{
+ accessible->priv = G_TYPE_INSTANCE_GET_PRIVATE (accessible, EV_TYPE_VIEW_ACCESSIBLE, EvViewAccessiblePrivate);
}
static GtkTextBuffer *
@@ -98,7 +115,7 @@ ev_view_accessible_get_text_buffer (EvViewAccessible *accessible, EvView *view)
{
EvPageCache *page_cache;
const gchar *retval = NULL;
- EvViewAccessiblePriv* priv = EV_VIEW_ACCESSIBLE_GET_PRIVATE (accessible);
+ EvViewAccessiblePrivate* priv = accessible->priv;
page_cache = view->page_cache;
if (!page_cache) {
@@ -717,7 +734,7 @@ static void ev_view_accessible_text_iface_init (AtkTextIface * iface)
static gboolean
ev_view_accessible_idle_do_action (gpointer data)
{
- EvViewAccessiblePriv* priv = EV_VIEW_ACCESSIBLE_GET_PRIVATE (data);
+ EvViewAccessiblePrivate* priv = EV_VIEW_ACCESSIBLE (data)->priv;
ev_view_scroll (EV_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (data))),
priv->idle_scroll,
@@ -730,7 +747,7 @@ static gboolean
ev_view_accessible_action_do_action (AtkAction *action,
gint i)
{
- EvViewAccessiblePriv* priv = EV_VIEW_ACCESSIBLE_GET_PRIVATE (action);
+ EvViewAccessiblePrivate* priv = EV_VIEW_ACCESSIBLE (action)->priv;
if (gtk_accessible_get_widget (GTK_ACCESSIBLE (action)) == NULL)
return FALSE;
@@ -763,7 +780,7 @@ static const gchar *
ev_view_accessible_action_get_description (AtkAction *action,
gint i)
{
- EvViewAccessiblePriv* priv = EV_VIEW_ACCESSIBLE_GET_PRIVATE (action);
+ EvViewAccessiblePrivate* priv = EV_VIEW_ACCESSIBLE (action)->priv;
if (i < 0 || i >= LAST_ACTION)
return NULL;
@@ -789,7 +806,7 @@ ev_view_accessible_action_set_description (AtkAction *action,
gint i,
const gchar *description)
{
- EvViewAccessiblePriv* priv = EV_VIEW_ACCESSIBLE_GET_PRIVATE (action);
+ EvViewAccessiblePrivate* priv = EV_VIEW_ACCESSIBLE (action)->priv;
gchar *old_description;
if (i < 0 || i >= LAST_ACTION)
@@ -811,102 +828,16 @@ static void ev_view_accessible_action_iface_init (AtkActionIface * iface)
iface->set_description = ev_view_accessible_action_set_description;
}
-GType ev_view_accessible_get_type (void)
-{
- static GType type = 0;
-
- if (G_UNLIKELY (type == 0)) {
- GTypeInfo tinfo = {
- 0, /* class size */
- (GBaseInitFunc) NULL, /* base init */
- (GBaseFinalizeFunc) NULL, /* base finalize */
- (GClassInitFunc) ev_view_accessible_class_init, /* class init */
- (GClassFinalizeFunc) NULL, /* class finalize */
- NULL, /* class data */
- 0, /* instance size */
- 0, /* nb preallocs */
- (GInstanceInitFunc) NULL, /* instance init */
- NULL /* value table */
- };
-
- const GInterfaceInfo atk_text_info = {
- (GInterfaceInitFunc)
- ev_view_accessible_text_iface_init,
- (GInterfaceFinalizeFunc) NULL,
- NULL
- };
-
- const GInterfaceInfo atk_action_info = {
- (GInterfaceInitFunc)
- ev_view_accessible_action_iface_init,
- (GInterfaceFinalizeFunc) NULL,
- NULL
- };
- /*
- * Figure out the size of the class and instance
- * we are deriving from
- */
- AtkObjectFactory *factory;
- GType derived_type;
- GTypeQuery query;
- GType derived_atk_type;
-
- derived_type = g_type_parent (EV_TYPE_VIEW);
- factory = atk_registry_get_factory (atk_get_default_registry (),
- derived_type);
- derived_atk_type = atk_object_factory_get_accessible_type (factory);
-
- g_type_query (derived_atk_type, &query);
- tinfo.class_size = query.class_size;
- tinfo.instance_size = query.instance_size;
-
- type = g_type_register_static (derived_atk_type, "EvViewAccessible",
- &tinfo, 0);
- g_type_add_interface_static (type, ATK_TYPE_TEXT,
- &atk_text_info);
- g_type_add_interface_static (type, ATK_TYPE_ACTION,
- &atk_action_info);
- }
-
- return type;
-}
-
-static AtkObject *ev_view_accessible_new(GObject * obj)
+AtkObject *
+ev_view_accessible_new (GtkWidget *widget)
{
AtkObject *accessible;
- g_return_val_if_fail(EV_IS_VIEW (obj), NULL);
-
- accessible = g_object_new (ev_view_accessible_get_type (), NULL);
- atk_object_initialize (accessible, obj);
+ g_return_val_if_fail (EV_IS_VIEW (widget), NULL);
- atk_object_set_name (ATK_OBJECT (accessible), _("Document View"));
- atk_object_set_role (ATK_OBJECT (accessible), ATK_ROLE_DOCUMENT_FRAME);
+ accessible = g_object_new (EV_TYPE_VIEW_ACCESSIBLE, NULL);
+ atk_object_initialize (accessible, widget);
return accessible;
}
-typedef AtkObjectFactory EvViewAccessibleFactory;
-typedef AtkObjectFactoryClass EvViewAccessibleFactoryClass;
-
-static void ev_view_accessible_factory_init (EvViewAccessibleFactory *factory)
-{
-}
-
-static GType ev_view_accessible_factory_get_accessible_type(void)
-{
- return ev_view_accessible_get_type();
-}
-
-static AtkObject *ev_view_accessible_factory_create_accessible (GObject * obj)
-{
- return ev_view_accessible_new(obj);
-}
-
-static void ev_view_accessible_factory_class_init (AtkObjectFactoryClass * klass)
-{
- klass->create_accessible = ev_view_accessible_factory_create_accessible;
- klass->get_accessible_type = ev_view_accessible_factory_get_accessible_type;
-}
-
-G_DEFINE_TYPE (EvViewAccessibleFactory, ev_view_accessible_factory, ATK_TYPE_OBJECT_FACTORY)
diff --git a/libview/ev-view-accessible.h b/libview/ev-view-accessible.h
index 31a21bb..7272c6f 100644
--- a/libview/ev-view-accessible.h
+++ b/libview/ev-view-accessible.h
@@ -25,9 +25,30 @@
#ifndef __EV_VIEW_ACCESSIBLE_H__
#define __EV_VIEW_ACCESSIBLE_H__
-#include "ev-view.h"
+#include <gtk/gtk-a11y.h>
-GType ev_view_accessible_factory_get_type (void);
+#define EV_TYPE_VIEW_ACCESSIBLE (ev_view_accessible_get_type ())
+#define EV_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_VIEW_ACCESSIBLE, EvViewAccessible))
+#define EV_IS_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EV_TYPE_VIEW_ACCESSIBLE))
+
+typedef struct _EvViewAccessible EvViewAccessible;
+typedef struct _EvViewAccessibleClass EvViewAccessibleClass;
+typedef struct _EvViewAccessiblePrivate EvViewAccessiblePrivate;
+
+struct _EvViewAccessible
+{
+ GtkContainerAccessible parent;
+
+ EvViewAccessiblePrivate *priv;
+};
+
+struct _EvViewAccessibleClass
+{
+ GtkContainerAccessibleClass parent_class;
+};
+
+GType ev_view_accessible_get_type (void);
+AtkObject *ev_view_accessible_new (GtkWidget *widget);
#endif /* __EV_VIEW_ACCESSIBLE_H__ */
diff --git a/libview/ev-view-private.h b/libview/ev-view-private.h
index d00f66c..75cac9a 100644
--- a/libview/ev-view-private.h
+++ b/libview/ev-view-private.h
@@ -204,7 +204,7 @@ struct _EvView {
EvMapping *synctex_result;
/* Accessibility */
- gboolean a11y_enabled;
+ AtkObject *accessible;
};
struct _EvViewClass {
diff --git a/libview/ev-view.c b/libview/ev-view.c
index 1aa3b41..7aa2c73 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -4565,6 +4565,8 @@ ev_view_dispose (GObject *object)
gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (view), NULL);
gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (view), NULL);
+ g_clear_object(&view->accessible);
+
G_OBJECT_CLASS (ev_view_parent_class)->dispose (object);
}
@@ -4639,50 +4641,14 @@ ev_view_set_property (GObject *object,
}
/* Accessibility */
-static void
-ev_view_init_accessibility (EvView *view)
-{
- static gboolean first_time = TRUE;
-
- if (first_time) {
- AtkObjectFactory *factory;
- AtkRegistry *registry;
- GType derived_type;
- GType derived_atk_type;
-
- /*
- * Figure out whether accessibility is enabled by looking at the
- * type of the accessible object which would be created for
- * the parent type of EvView.
- */
- derived_type = g_type_parent (EV_TYPE_VIEW);
-
- registry = atk_get_default_registry ();
- factory = atk_registry_get_factory (registry,
- derived_type);
- derived_atk_type = atk_object_factory_get_accessible_type (factory);
- if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE)) {
- atk_registry_set_factory_type (registry,
- EV_TYPE_VIEW,
- ev_view_accessible_factory_get_type ());
- view->a11y_enabled = TRUE;
- }
- first_time = FALSE;
- }
-}
-
static AtkObject *
ev_view_get_accessible (GtkWidget *widget)
{
- ev_view_init_accessibility (EV_VIEW (widget));
- return GTK_WIDGET_CLASS (ev_view_parent_class)->get_accessible (widget);
-}
+ EvView *view = EV_VIEW (widget);
-static gboolean
-ev_view_is_a11y_enabled (EvView *view)
-{
- ev_view_init_accessibility (view);
- return view->a11y_enabled;
+ if (!view->accessible)
+ view->accessible = ev_view_accessible_new (widget);
+ return view->accessible;
}
/* GtkContainer */
@@ -4928,7 +4894,6 @@ ev_view_class_init (EvViewClass *class)
GTK_SCROLL_STEP_BACKWARD, G_TYPE_BOOLEAN, FALSE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_L, 0, "binding_activated", 2, GTK_TYPE_SCROLL_TYPE,
GTK_SCROLL_STEP_FORWARD, G_TYPE_BOOLEAN, TRUE);
-
}
static void
@@ -5106,14 +5071,12 @@ setup_caches (EvView *view)
view->height_to_page_cache = ev_view_get_height_to_page_cache (view);
view->pixbuf_cache = ev_pixbuf_cache_new (GTK_WIDGET (view), view->model, view->pixbuf_cache_size);
view->page_cache = ev_page_cache_new (view->document);
- if (ev_view_is_a11y_enabled (view)) {
- EvJobPageDataFlags flags = ev_page_cache_get_flags (view->page_cache);
- ev_page_cache_set_flags (view->page_cache,
- flags |
- EV_PAGE_DATA_INCLUDE_TEXT_LAYOUT |
- EV_PAGE_DATA_INCLUDE_TEXT);
- }
+ ev_page_cache_set_flags (view->page_cache,
+ ev_page_cache_get_flags (view->page_cache) |
+ EV_PAGE_DATA_INCLUDE_TEXT_LAYOUT |
+ EV_PAGE_DATA_INCLUDE_TEXT);
+
inverted_colors = ev_document_model_get_inverted_colors (view->model);
ev_pixbuf_cache_set_inverted_colors (view->pixbuf_cache, inverted_colors);
g_signal_connect (view->pixbuf_cache, "job-finished", G_CALLBACK (job_finished_cb), view);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]