Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-image-accessible.c
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of evince, a gnome document viewer
3  *
4  * Copyright (C) 2014 Igalia
5  * Author: Joanmarie Diggs <jdiggs@igalia.com>
6  *
7  * Evince is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * Evince is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 #include <config.h>
23 
24 #include "ev-image-accessible.h"
25 #include "ev-view-private.h"
26 
31 };
32 
33 static void ev_image_accessible_component_iface_init (AtkComponentIface *iface);
34 static void ev_image_accessible_image_iface_init (AtkImageIface *iface);
35 
36 G_DEFINE_TYPE_WITH_CODE (EvImageAccessible, ev_image_accessible, ATK_TYPE_OBJECT,
37  G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, ev_image_accessible_component_iface_init)
38  G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE, ev_image_accessible_image_iface_init))
39 
40 static void
41 ev_image_accessible_get_atk_rect (AtkObject *atk_object,
42  AtkCoordType coord_type,
43  EvRectangle *atk_rect)
44 {
45  EvImageAccessible *image;
46  EvViewAccessible *view_accessible;
47  gint page;
48 
49  image = EV_IMAGE_ACCESSIBLE (atk_object);
50  view_accessible = ev_page_accessible_get_view_accessible (image->priv->page);
51  page = ev_page_accessible_get_page (image->priv->page);
52  _transform_doc_rect_to_atk_rect (view_accessible, page, &image->priv->area, atk_rect, coord_type);
53 }
54 
55 static void
56 ev_image_accessible_get_extents (AtkComponent *atk_component,
57  gint *x,
58  gint *y,
59  gint *width,
60  gint *height,
61  AtkCoordType coord_type)
62 {
63  EvRectangle atk_rect;
64 
65  ev_image_accessible_get_atk_rect (ATK_OBJECT (atk_component), coord_type, &atk_rect);
66  *x = atk_rect.x1;
67  *y = atk_rect.y1;
68  *width = atk_rect.x2 - atk_rect.x1;
69  *height = atk_rect.y2 - atk_rect.y1;
70 }
71 
72 static void
73 ev_image_accessible_component_iface_init (AtkComponentIface *iface)
74 {
75  iface->get_extents = ev_image_accessible_get_extents;
76 }
77 
78 static const gchar *
80 {
81  /* This will be obtainable for tagged PDFs */
82  return NULL;
83 }
84 
85 static const gchar *
87 {
88  /* This will be obtainable for tagged PDFs */
89  return NULL;
90 }
91 
92 static void
94  int *width,
95  int *height)
96 {
97  EvRectangle atk_rect;
98 
99  ev_image_accessible_get_atk_rect (ATK_OBJECT (atk_image), ATK_XY_WINDOW, &atk_rect);
100  *width = atk_rect.x2 - atk_rect.x1;
101  *height = atk_rect.y2 - atk_rect.y1;
102 }
103 
104 static void
106  gint *x,
107  gint *y,
108  AtkCoordType coord_type)
109 {
110  EvRectangle atk_rect;
111 
112  ev_image_accessible_get_atk_rect (ATK_OBJECT (atk_image), ATK_XY_WINDOW, &atk_rect);
113  *x = atk_rect.x1;
114  *y = atk_rect.y1;
115 }
116 
117 static AtkStateSet *
118 ev_image_accessible_ref_state_set (AtkObject *atk_object)
119 {
120  AtkStateSet *state_set;
121  AtkStateSet *copy_set;
122  AtkStateSet *page_accessible_state_set;
123  EvImageAccessible *self;
124  EvViewAccessible *view_accessible;
125  gint page;
126 
127  self = EV_IMAGE_ACCESSIBLE (atk_object);
128  state_set = ATK_OBJECT_CLASS (ev_image_accessible_parent_class)->ref_state_set (atk_object);
129  atk_state_set_clear_states (state_set);
130 
131  page_accessible_state_set = atk_object_ref_state_set (ATK_OBJECT (self->priv->page));
132  copy_set = atk_state_set_or_sets (state_set, page_accessible_state_set);
133  atk_state_set_remove_state (copy_set, ATK_STATE_FOCUSABLE);
134  atk_state_set_remove_state (copy_set, ATK_STATE_FOCUSED);
135 
136  view_accessible = ev_page_accessible_get_view_accessible (self->priv->page);
137  page = ev_page_accessible_get_page (self->priv->page);
138  if (!ev_view_accessible_is_doc_rect_showing (view_accessible, page, &self->priv->area))
139  atk_state_set_remove_state (copy_set, ATK_STATE_SHOWING);
140 
141  g_object_unref (state_set);
142  g_object_unref (page_accessible_state_set);
143 
144  return copy_set;
145 }
146 
147 static AtkObject *
148 ev_image_accessible_get_parent (AtkObject *atk_object)
149 {
150  EvImageAccessiblePrivate *priv = EV_IMAGE_ACCESSIBLE (atk_object)->priv;
151 
152  return ATK_OBJECT (priv->page);
153 }
154 
155 static void
157 {
158  EvImageAccessiblePrivate *priv = EV_IMAGE_ACCESSIBLE (object)->priv;
159 
160  g_object_unref (priv->image);
161 
162  G_OBJECT_CLASS (ev_image_accessible_parent_class)->finalize (object);
163 }
164 
165 static void
167 {
168  GObjectClass *object_class = G_OBJECT_CLASS (klass);
169  AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
170 
171  object_class->finalize = ev_image_accessible_finalize;
172  atk_class->get_parent = ev_image_accessible_get_parent;
173  atk_class->ref_state_set = ev_image_accessible_ref_state_set;
174 
175  g_type_class_add_private (klass, sizeof (EvImageAccessiblePrivate));
176 }
177 
178 static void
180 {
181  atk_object_set_role (ATK_OBJECT (image), ATK_ROLE_IMAGE);
182 
183  image->priv = G_TYPE_INSTANCE_GET_PRIVATE (image, EV_TYPE_IMAGE_ACCESSIBLE, EvImageAccessiblePrivate);
184 }
185 
186 static void
188 {
189  iface->get_image_description = ev_image_accessible_get_image_description;
190  iface->get_image_locale = ev_image_accessible_get_image_locale;
191  iface->get_image_position = ev_image_accessible_get_image_position;
192  iface->get_image_size = ev_image_accessible_get_image_size;
193 }
194 
197  EvImage *image,
198  EvRectangle *area)
199 {
200  EvImageAccessible *atk_image;
201 
202  atk_image = g_object_new (EV_TYPE_IMAGE_ACCESSIBLE, NULL);
203  atk_image->priv->page = page;
204  atk_image->priv->image = g_object_ref (image);
205  atk_image->priv->area = *area;
206 
207  return EV_IMAGE_ACCESSIBLE (atk_image);
208 }