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/atkhyperlink.h>
31 #include "hyperlink.h"
33 static void html_a11y_hyper_link_class_init (HTMLA11YHyperLinkClass
*klass
);
34 static void html_a11y_hyper_link_init (HTMLA11YHyperLink
*a11y_hyper_link
);
36 static void atk_action_interface_init (AtkActionIface
*iface
);
38 static gboolean
html_a11y_hyper_link_do_action (AtkAction
*action
, gint i
);
39 static gint
html_a11y_hyper_link_get_n_actions (AtkAction
*action
);
40 static const gchar
* html_a11y_hyper_link_get_description (AtkAction
*action
, gint i
);
41 static const gchar
* html_a11y_hyper_link_get_name (AtkAction
*action
, gint i
);
42 static gboolean
html_a11y_hyper_link_set_description (AtkAction
*action
, gint i
, const gchar
*description
);
44 static AtkObjectClass
*parent_class
= NULL
;
47 html_a11y_hyper_link_get_type (void)
49 static GType type
= 0;
52 static const GTypeInfo tinfo
= {
53 sizeof (HTMLA11YHyperLinkClass
),
55 NULL
, /* base finalize */
56 (GClassInitFunc
) html_a11y_hyper_link_class_init
, /* class init */
57 NULL
, /* class finalize */
58 NULL
, /* class data */
59 sizeof (HTMLA11YHyperLink
), /* instance size */
61 (GInstanceInitFunc
) html_a11y_hyper_link_init
, /* instance init */
62 NULL
/* value table */
65 static const GInterfaceInfo atk_action_info
= {
66 (GInterfaceInitFunc
) atk_action_interface_init
,
67 (GInterfaceFinalizeFunc
) NULL
,
71 type
= g_type_register_static (ATK_TYPE_HYPERLINK
, "HTMLA11YHyperLink", &tinfo
, 0);
72 g_type_add_interface_static (type
, ATK_TYPE_ACTION
, &atk_action_info
);
79 atk_action_interface_init (AtkActionIface
*iface
)
81 g_return_if_fail (iface
!= NULL
);
83 iface
->do_action
= html_a11y_hyper_link_do_action
;
84 iface
->get_n_actions
= html_a11y_hyper_link_get_n_actions
;
85 iface
->get_description
= html_a11y_hyper_link_get_description
;
86 iface
->get_name
= html_a11y_hyper_link_get_name
;
87 iface
->set_description
= html_a11y_hyper_link_set_description
;
91 html_a11y_hyper_link_finalize (GObject
*obj
)
93 HTMLA11YHyperLink
*hl
= HTML_A11Y_HYPER_LINK (obj
);
96 g_object_remove_weak_pointer (G_OBJECT (hl
->a11y
.object
),
99 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
103 html_a11y_hyper_link_get_start_index (AtkHyperlink
*link
)
105 HTMLA11YHyperLink
*hl
= HTML_A11Y_HYPER_LINK (link
);
106 HTMLText
*text
= HTML_TEXT (HTML_A11Y_HTML (hl
->a11y
.object
));
107 Link
*a
= (Link
*) g_slist_nth_data (text
->links
, hl
->num
);
108 return a
? a
->start_offset
: -1;
112 html_a11y_hyper_link_get_end_index (AtkHyperlink
*link
)
114 HTMLA11YHyperLink
*hl
= HTML_A11Y_HYPER_LINK (link
);
115 Link
*a
= (Link
*) g_slist_nth_data (HTML_TEXT (HTML_A11Y_HTML (hl
->a11y
.object
))->links
, hl
->num
);
116 return a
? a
->end_offset
: -1;
120 html_a11y_hyper_link_class_init (HTMLA11YHyperLinkClass
*klass
)
122 GObjectClass
*gobject_class
= G_OBJECT_CLASS (klass
);
123 AtkHyperlinkClass
*atk_hyperlink_class
= ATK_HYPERLINK_CLASS (klass
);
124 parent_class
= g_type_class_peek_parent (klass
);
126 atk_hyperlink_class
->get_start_index
= html_a11y_hyper_link_get_start_index
;
127 atk_hyperlink_class
->get_end_index
= html_a11y_hyper_link_get_end_index
;
128 gobject_class
->finalize
= html_a11y_hyper_link_finalize
;
132 html_a11y_hyper_link_init (HTMLA11YHyperLink
*a11y_hyper_link
)
134 a11y_hyper_link
->description
= NULL
;
138 html_a11y_hyper_link_new (HTMLA11Y
*a11y
,
141 HTMLA11YHyperLink
*hl
;
143 g_return_val_if_fail (G_IS_HTML_A11Y (a11y
), NULL
);
145 hl
= HTML_A11Y_HYPER_LINK (g_object_new (G_TYPE_HTML_A11Y_HYPER_LINK
, NULL
));
147 hl
->a11y
.object
= a11y
;
148 hl
->num
= link_index
;
149 hl
->offset
= ((Link
*) g_slist_nth_data (HTML_TEXT (HTML_A11Y_HTML (a11y
))->links
, link_index
))->start_offset
;
150 g_object_add_weak_pointer (G_OBJECT (hl
->a11y
.object
), &hl
->a11y
.weakref
);
152 return ATK_HYPERLINK (hl
);
160 html_a11y_hyper_link_do_action (AtkAction
*action
,
163 HTMLA11YHyperLink
*hl
;
164 gboolean result
= FALSE
;
166 hl
= HTML_A11Y_HYPER_LINK (action
);
168 if (i
== 0 && hl
->a11y
.object
) {
169 HTMLText
*text
= HTML_TEXT (HTML_A11Y_HTML (hl
->a11y
.object
));
170 gchar
*url
= html_object_get_complete_url (HTML_OBJECT (text
), hl
->offset
);
173 GObject
*gtkhtml
= GTK_HTML_A11Y_GTKHTML_POINTER
174 (html_a11y_get_gtkhtml_parent (HTML_A11Y (hl
->a11y
.object
)));
176 g_signal_emit_by_name (gtkhtml
, "link_clicked", url
);
187 html_a11y_hyper_link_get_n_actions (AtkAction
*action
)
193 html_a11y_hyper_link_get_description (AtkAction
*action
,
197 HTMLA11YHyperLink
*hl
;
199 hl
= HTML_A11Y_HYPER_LINK (action
);
201 return hl
->description
;
208 html_a11y_hyper_link_get_name (AtkAction
*action
,
211 return i
== 0 ? "link click" : NULL
;
215 html_a11y_hyper_link_set_description (AtkAction
*action
,
217 const gchar
*description
)
220 HTMLA11YHyperLink
*hl
;
222 hl
= HTML_A11Y_HYPER_LINK (action
);
224 g_free (hl
->description
);
225 hl
->description
= g_strdup (description
);