summaryrefslogtreecommitdiff
path: root/libview
diff options
context:
space:
mode:
Diffstat (limited to 'libview')
-rw-r--r--libview/ev-view-accessible.c149
-rw-r--r--libview/ev-view-accessible.h25
-rw-r--r--libview/ev-view-private.h2
-rw-r--r--libview/ev-view.c58
4 files changed, 75 insertions, 159 deletions
diff --git a/libview/ev-view-accessible.c b/libview/ev-view-accessible.c
index ea270fdc..59652ad0 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 d9c6b71d..04ef34e8 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 b18dcc00..3f9cfb60 100644
--- a/libview/ev-view-private.h
+++ b/libview/ev-view-private.h
@@ -201,7 +201,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 b360b22d..5195299f 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -4629,6 +4629,8 @@ ev_view_dispose (GObject *object)
view->loading_timeout = 0;
}
+ g_clear_object(&view->accessible);
+
G_OBJECT_CLASS (ev_view_parent_class)->dispose (object);
}
@@ -4691,50 +4693,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 */
@@ -5091,14 +5057,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);