1 /* This file is part of the GtkHTML library.
3 * Copyright 2002 Ximian, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
25 #include <atk/atkimage.h>
27 #include "htmlimage.h"
32 #include <glib/gi18n-lib.h>
34 static void html_a11y_image_class_init (HTMLA11YImageClass
*klass
);
35 static void html_a11y_image_init (HTMLA11YImage
*a11y_image
);
36 static void atk_image_interface_init (AtkImageIface
*iface
);
38 static const gchar
* html_a11y_image_get_name (AtkObject
*accessible
);
40 static void html_a11y_image_get_image_position (AtkImage
*image
, gint
*x
, gint
*y
, AtkCoordType coord_type
);
41 static void html_a11y_image_get_image_size (AtkImage
*image
, gint
*width
, gint
*height
);
42 static const gchar
*html_a11y_image_get_image_description (AtkImage
*image
);
44 static AtkObjectClass
*parent_class
= NULL
;
47 html_a11y_image_get_type (void)
49 static GType type
= 0;
52 static const GTypeInfo tinfo
= {
53 sizeof (HTMLA11YImageClass
),
55 NULL
, /* base finalize */
56 (GClassInitFunc
) html_a11y_image_class_init
, /* class init */
57 NULL
, /* class finalize */
58 NULL
, /* class data */
59 sizeof (HTMLA11YImage
), /* instance size */
61 (GInstanceInitFunc
) html_a11y_image_init
, /* instance init */
62 NULL
/* value table */
65 static const GInterfaceInfo atk_image_info
= {
66 (GInterfaceInitFunc
) atk_image_interface_init
,
67 (GInterfaceFinalizeFunc
) NULL
,
71 type
= g_type_register_static (G_TYPE_HTML_A11Y
, "HTMLA11YImage", &tinfo
, 0);
72 g_type_add_interface_static (type
, ATK_TYPE_IMAGE
, &atk_image_info
);
79 atk_image_interface_init (AtkImageIface
*iface
)
81 g_return_if_fail (iface
!= NULL
);
83 iface
->get_image_position
= html_a11y_image_get_image_position
;
84 iface
->get_image_size
= html_a11y_image_get_image_size
;
85 iface
->get_image_description
= html_a11y_image_get_image_description
;
89 html_a11y_image_finalize (GObject
*obj
)
91 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
95 html_a11y_image_initialize (AtkObject
*obj
,
98 /* printf ("html_a11y_image_initialize\n"); */
100 if (ATK_OBJECT_CLASS (parent_class
)->initialize
)
101 ATK_OBJECT_CLASS (parent_class
)->initialize (obj
, data
);
105 html_a11y_image_class_init (HTMLA11YImageClass
*klass
)
107 GObjectClass
*gobject_class
= G_OBJECT_CLASS (klass
);
108 AtkObjectClass
*atk_class
= ATK_OBJECT_CLASS (klass
);
110 parent_class
= g_type_class_peek_parent (klass
);
112 atk_class
->get_name
= html_a11y_image_get_name
;
113 atk_class
->initialize
= html_a11y_image_initialize
;
114 gobject_class
->finalize
= html_a11y_image_finalize
;
118 html_a11y_image_init (HTMLA11YImage
*a11y_image
)
123 html_a11y_image_new (HTMLObject
*html_obj
)
126 AtkObject
*accessible
;
128 g_return_val_if_fail (HTML_IS_IMAGE (html_obj
), NULL
);
130 object
= g_object_new (G_TYPE_HTML_A11Y_IMAGE
, NULL
);
132 accessible
= ATK_OBJECT (object
);
133 atk_object_initialize (accessible
, html_obj
);
135 accessible
->role
= ATK_ROLE_IMAGE
;
137 /* printf ("created new html accessible image object\n"); */
143 html_a11y_image_get_name (AtkObject
*accessible
)
145 HTMLImage
*img
= HTML_IMAGE (HTML_A11Y_HTML (accessible
));
148 if (accessible
->name
)
149 return accessible
->name
;
152 name
= g_strdup_printf (_("URL is %s, Alternative Text is %s"), img
->image_ptr
->url
, img
->alt
);
154 name
= g_strdup_printf (_("URL is %s"), img
->image_ptr
->url
);
156 atk_object_set_name (accessible
, name
);
159 return accessible
->name
;
167 html_a11y_image_get_image_position (AtkImage
*image
,
170 AtkCoordType coord_type
)
172 HTMLImage
*img
= HTML_IMAGE (HTML_A11Y_HTML (image
));
174 atk_component_get_position (ATK_COMPONENT (image
), x
, y
, coord_type
);
176 *x
+= img
->hspace
+ img
->border
;
177 *y
+= img
->vspace
+ img
->border
;
181 html_a11y_image_get_image_size (AtkImage
*image
,
185 HTMLImage
*img
= HTML_IMAGE (HTML_A11Y_HTML (image
));
187 atk_component_get_size (ATK_COMPONENT (image
), width
, height
);
189 *width
-= 2*(img
->hspace
+ img
->border
);
190 *height
-= 2*(img
->vspace
+ img
->border
);
194 html_a11y_image_get_image_description (AtkImage
*image
)
196 return html_a11y_image_get_name (ATK_OBJECT (image
));