1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
/* this file is part of lector, a cafe document viewer
 *
 * Copyright (C) 2014 Igalia
 * Author: Joanmarie Diggs <jdiggs@igalia.com>
 *
 * Lector is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Lector 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <config.h>

#include "ev-image-accessible.h"
#include "ev-view-private.h"

struct _EvImageAccessiblePrivate {
        EvPageAccessible *page;
        EvImage          *image;
        EvRectangle       area;
};

static void ev_image_accessible_component_iface_init (AtkComponentIface *iface);
static void ev_image_accessible_image_iface_init     (AtkImageIface *iface);

G_DEFINE_TYPE_WITH_CODE (EvImageAccessible, ev_image_accessible, ATK_TYPE_OBJECT,<--- There is an unknown macro here somewhere. Configuration is required. If G_DEFINE_TYPE_WITH_CODE is a macro then please configure it.
			 G_ADD_PRIVATE (EvImageAccessible)
			 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, ev_image_accessible_component_iface_init)
			 G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE, ev_image_accessible_image_iface_init))

static void
ev_image_accessible_get_atk_rect (AtkObject    *atk_object,
				  AtkCoordType  coord_type,
				  EvRectangle  *atk_rect)
{
	EvImageAccessible *image;
	EvViewAccessible *view_accessible;
	gint page;

	image = EV_IMAGE_ACCESSIBLE (atk_object);
	view_accessible = ev_page_accessible_get_view_accessible (image->priv->page);
	page = ev_page_accessible_get_page (image->priv->page);
	_transform_doc_rect_to_atk_rect (view_accessible, page, &image->priv->area, atk_rect, coord_type);
}

static void
ev_image_accessible_get_extents (AtkComponent *atk_component,
				 gint         *x,
				 gint         *y,
				 gint         *width,
				 gint         *height,
				 AtkCoordType  coord_type)
{
	EvRectangle atk_rect;

	ev_image_accessible_get_atk_rect (ATK_OBJECT (atk_component), coord_type, &atk_rect);
	*x = atk_rect.x1;
	*y = atk_rect.y1;
	*width = atk_rect.x2 - atk_rect.x1;
	*height = atk_rect.y2 - atk_rect.y1;
}

static void
ev_image_accessible_component_iface_init (AtkComponentIface *iface)
{
	iface->get_extents = ev_image_accessible_get_extents;
}

static const gchar *
ev_image_accessible_get_image_description (AtkImage *image)
{
	/* This will be obtainable for tagged PDFs */
	return NULL;
}

static const gchar *
ev_image_accessible_get_image_locale (AtkImage *atk_image)
{
	/* This will be obtainable for tagged PDFs */
	return NULL;
}

static void
ev_image_accessible_get_image_size (AtkImage *atk_image,
				    int      *width,
				    int      *height)
{
	EvRectangle atk_rect;

	ev_image_accessible_get_atk_rect (ATK_OBJECT (atk_image), ATK_XY_WINDOW, &atk_rect);
	*width = atk_rect.x2 - atk_rect.x1;
	*height = atk_rect.y2 - atk_rect.y1;
}

static void
ev_image_accessible_get_image_position (AtkImage     *atk_image,
					gint         *x,
					gint         *y,
					AtkCoordType  coord_type)
{
	EvRectangle atk_rect;

	ev_image_accessible_get_atk_rect (ATK_OBJECT (atk_image), ATK_XY_WINDOW, &atk_rect);
	*x = atk_rect.x1;
	*y = atk_rect.y1;
}

static AtkStateSet *
ev_image_accessible_ref_state_set (AtkObject *atk_object)
{
	AtkStateSet *state_set;
	AtkStateSet *copy_set;
	AtkStateSet *page_accessible_state_set;
	EvImageAccessible *self;
	EvViewAccessible *view_accessible;
	gint page;

	self = EV_IMAGE_ACCESSIBLE (atk_object);
	state_set = ATK_OBJECT_CLASS (ev_image_accessible_parent_class)->ref_state_set (atk_object);
	atk_state_set_clear_states (state_set);

	page_accessible_state_set = atk_object_ref_state_set (ATK_OBJECT (self->priv->page));
	copy_set = atk_state_set_or_sets (state_set, page_accessible_state_set);
	atk_state_set_remove_state (copy_set, ATK_STATE_FOCUSABLE);
	atk_state_set_remove_state (copy_set, ATK_STATE_FOCUSED);

	view_accessible = ev_page_accessible_get_view_accessible (self->priv->page);
	page = ev_page_accessible_get_page (self->priv->page);
	if (!ev_view_accessible_is_doc_rect_showing (view_accessible, page, &self->priv->area))
		atk_state_set_remove_state (copy_set, ATK_STATE_SHOWING);

	g_object_unref (state_set);
	g_object_unref (page_accessible_state_set);

	return copy_set;
}

static AtkObject *
ev_image_accessible_get_parent (AtkObject *atk_object)
{
	EvImageAccessiblePrivate *priv = EV_IMAGE_ACCESSIBLE (atk_object)->priv;

	return ATK_OBJECT (priv->page);
}

static void
ev_image_accessible_finalize (GObject *object)
{
	EvImageAccessiblePrivate *priv = EV_IMAGE_ACCESSIBLE (object)->priv;

	g_object_unref (priv->image);

	G_OBJECT_CLASS (ev_image_accessible_parent_class)->finalize (object);
}

static void
ev_image_accessible_class_init (EvImageAccessibleClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);
	AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);

	object_class->finalize = ev_image_accessible_finalize;
	atk_class->get_parent = ev_image_accessible_get_parent;
	atk_class->ref_state_set = ev_image_accessible_ref_state_set;
}

static void
ev_image_accessible_init (EvImageAccessible *image)
{
	atk_object_set_role (ATK_OBJECT (image), ATK_ROLE_IMAGE);

	image->priv = ev_image_accessible_get_instance_private (image);
}

static void
ev_image_accessible_image_iface_init (AtkImageIface *iface)
{
	iface->get_image_description = ev_image_accessible_get_image_description;
	iface->get_image_locale = ev_image_accessible_get_image_locale;
	iface->get_image_position = ev_image_accessible_get_image_position;
	iface->get_image_size = ev_image_accessible_get_image_size;
}

EvImageAccessible *
ev_image_accessible_new (EvPageAccessible *page,
			 EvImage          *image,
			 EvRectangle      *area)
{
	EvImageAccessible *atk_image;

	atk_image = g_object_new (EV_TYPE_IMAGE_ACCESSIBLE, NULL);
	atk_image->priv->page = page;
	atk_image->priv->image = g_object_ref (image);
	atk_image->priv->area = *area;

	return EV_IMAGE_ACCESSIBLE (atk_image);
}