forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathax_platform_atk_hyperlink.cc
249 lines (196 loc) · 7.97 KB
/
ax_platform_atk_hyperlink.cc
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
// Copyright (c) 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/accessibility/platform/ax_platform_atk_hyperlink.h"
#include "ui/accessibility/ax_text_utils.h"
#include "ui/accessibility/platform/ax_platform_node_auralinux.h"
#include "ui/accessibility/platform/ax_platform_node_delegate.h"
namespace ui {
static gpointer ax_platform_atk_hyperlink_parent_class = nullptr;
static AXPlatformNodeAuraLinux* ToAXPlatformNodeAuraLinux(
AXPlatformAtkHyperlink* atk_hyperlink) {
if (!atk_hyperlink)
return nullptr;
return atk_hyperlink->m_object;
}
static void ax_platform_atk_hyperlink_finalize(GObject* atk_hyperlink) {
G_OBJECT_CLASS(ax_platform_atk_hyperlink_parent_class)
->finalize(atk_hyperlink);
}
static gchar* ax_platform_atk_hyperlink_get_uri(AtkHyperlink* atk_hyperlink,
gint index) {
AXPlatformNodeAuraLinux* obj =
ToAXPlatformNodeAuraLinux(AX_PLATFORM_ATK_HYPERLINK(atk_hyperlink));
if (!obj)
return nullptr;
if (index != 0)
return nullptr;
return g_strdup(
obj->GetStringAttribute(ax::mojom::StringAttribute::kUrl).c_str());
}
static AtkObject* ax_platform_atk_hyperlink_get_object(
AtkHyperlink* atk_hyperlink,
gint index) {
AXPlatformNodeAuraLinux* obj =
ToAXPlatformNodeAuraLinux(AX_PLATFORM_ATK_HYPERLINK(atk_hyperlink));
if (!obj)
return nullptr;
if (index != 0)
return nullptr;
return ATK_OBJECT(obj->GetNativeViewAccessible());
}
static gint ax_platform_atk_hyperlink_get_n_anchors(
AtkHyperlink* atk_hyperlink) {
AXPlatformNodeAuraLinux* obj =
ToAXPlatformNodeAuraLinux(AX_PLATFORM_ATK_HYPERLINK(atk_hyperlink));
return obj ? 1 : 0;
}
static gboolean ax_platform_atk_hyperlink_is_valid(
AtkHyperlink* atk_hyperlink) {
AXPlatformNodeAuraLinux* obj =
ToAXPlatformNodeAuraLinux(AX_PLATFORM_ATK_HYPERLINK(atk_hyperlink));
return obj ? TRUE : FALSE;
}
static gboolean ax_platform_atk_hyperlink_is_selected_link(
AtkHyperlink* atk_hyperlink) {
AXPlatformNodeAuraLinux* obj =
ToAXPlatformNodeAuraLinux(AX_PLATFORM_ATK_HYPERLINK(atk_hyperlink));
if (!obj)
return false;
return obj->GetDelegate()->GetFocus() == obj->GetNativeViewAccessible();
}
static void ax_platform_atk_hyperlink_class_init(AtkHyperlinkClass* klass) {
GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
ax_platform_atk_hyperlink_parent_class = g_type_class_peek_parent(klass);
gobject_class->finalize = ax_platform_atk_hyperlink_finalize;
klass->get_uri = ax_platform_atk_hyperlink_get_uri;
klass->get_object = ax_platform_atk_hyperlink_get_object;
klass->is_valid = ax_platform_atk_hyperlink_is_valid;
klass->get_n_anchors = ax_platform_atk_hyperlink_get_n_anchors;
klass->is_selected_link = ax_platform_atk_hyperlink_is_selected_link;
// TODO(jose.dapena) implement get_start_index and get_end_index methods
// that should provide the range of the link in the embedding text.
}
//
// AtkAction interface.
//
static AXPlatformNodeAuraLinux* ToAXPlatformNodeAuraLinuxFromHyperlinkAction(
AtkAction* atk_action) {
if (!IS_AX_PLATFORM_ATK_HYPERLINK(atk_action))
return nullptr;
return ToAXPlatformNodeAuraLinux(AX_PLATFORM_ATK_HYPERLINK(atk_action));
}
static gboolean ax_platform_atk_hyperlink_do_action(AtkAction* action,
gint index) {
g_return_val_if_fail(ATK_IS_ACTION(action), FALSE);
g_return_val_if_fail(!index, FALSE);
AXPlatformNodeAuraLinux* obj =
ToAXPlatformNodeAuraLinuxFromHyperlinkAction(action);
if (!obj)
return FALSE;
obj->DoDefaultAction();
return TRUE;
}
static gint ax_platform_atk_hyperlink_get_n_actions(AtkAction* action) {
g_return_val_if_fail(ATK_IS_ACTION(action), FALSE);
AXPlatformNodeAuraLinux* obj =
ToAXPlatformNodeAuraLinuxFromHyperlinkAction(action);
if (!obj)
return 0;
return 1;
}
static const gchar* ax_platform_atk_hyperlink_get_description(AtkAction* action,
gint index) {
g_return_val_if_fail(ATK_IS_ACTION(action), FALSE);
g_return_val_if_fail(!index, FALSE);
AXPlatformNodeAuraLinux* obj =
ToAXPlatformNodeAuraLinuxFromHyperlinkAction(action);
if (!obj)
return nullptr;
// Not implemented
return nullptr;
}
static const gchar* ax_platform_atk_hyperlink_get_keybinding(AtkAction* action,
gint index) {
g_return_val_if_fail(ATK_IS_ACTION(action), FALSE);
g_return_val_if_fail(!index, FALSE);
AXPlatformNodeAuraLinux* obj =
ToAXPlatformNodeAuraLinuxFromHyperlinkAction(action);
if (!obj)
return nullptr;
return obj->GetStringAttribute(ax::mojom::StringAttribute::kAccessKey)
.c_str();
}
static const gchar* ax_platform_atk_hyperlink_get_name(AtkAction* atk_action,
gint index) {
g_return_val_if_fail(ATK_IS_ACTION(atk_action), FALSE);
g_return_val_if_fail(!index, FALSE);
AXPlatformNodeAuraLinux* obj =
ToAXPlatformNodeAuraLinuxFromHyperlinkAction(atk_action);
if (!obj)
return nullptr;
int action;
if (!obj->GetIntAttribute(ax::mojom::IntAttribute::kDefaultActionVerb,
&action))
return nullptr;
base::string16 action_verb = ui::ActionVerbToUnlocalizedString(
static_cast<ax::mojom::DefaultActionVerb>(action));
ATK_AURALINUX_RETURN_STRING(base::UTF16ToUTF8(action_verb));
}
static const gchar* ax_platform_atk_hyperlink_get_localized_name(
AtkAction* atk_action,
gint index) {
g_return_val_if_fail(ATK_IS_ACTION(atk_action), FALSE);
g_return_val_if_fail(!index, FALSE);
AXPlatformNodeAuraLinux* obj =
ToAXPlatformNodeAuraLinuxFromHyperlinkAction(atk_action);
if (!obj)
return nullptr;
int action;
if (!obj->GetIntAttribute(ax::mojom::IntAttribute::kDefaultActionVerb,
&action))
return nullptr;
base::string16 action_verb = ui::ActionVerbToLocalizedString(
static_cast<ax::mojom::DefaultActionVerb>(action));
ATK_AURALINUX_RETURN_STRING(base::UTF16ToUTF8(action_verb));
}
static void atk_action_interface_init(AtkActionIface* iface) {
iface->do_action = ax_platform_atk_hyperlink_do_action;
iface->get_n_actions = ax_platform_atk_hyperlink_get_n_actions;
iface->get_description = ax_platform_atk_hyperlink_get_description;
iface->get_keybinding = ax_platform_atk_hyperlink_get_keybinding;
iface->get_name = ax_platform_atk_hyperlink_get_name;
iface->get_localized_name = ax_platform_atk_hyperlink_get_localized_name;
}
void ax_platform_atk_hyperlink_set_object(AXPlatformAtkHyperlink* atk_hyperlink,
AXPlatformNodeAuraLinux* obj) {
g_return_if_fail(AX_PLATFORM_ATK_HYPERLINK(atk_hyperlink));
atk_hyperlink->m_object = obj;
}
GType ax_platform_atk_hyperlink_get_type() {
static volatile gsize type_volatile = 0;
AXPlatformNodeAuraLinux::EnsureGTypeInit();
if (g_once_init_enter(&type_volatile)) {
static const GTypeInfo tinfo = {
sizeof(AXPlatformAtkHyperlinkClass),
(GBaseInitFunc) nullptr,
(GBaseFinalizeFunc) nullptr,
(GClassInitFunc)ax_platform_atk_hyperlink_class_init,
(GClassFinalizeFunc) nullptr,
nullptr, /* class data */
sizeof(AXPlatformAtkHyperlink), /* instance size */
0, /* nb preallocs */
(GInstanceInitFunc) nullptr,
nullptr /* value table */
};
static const GInterfaceInfo actionInfo = {
(GInterfaceInitFunc)(GInterfaceInitFunc)atk_action_interface_init,
(GInterfaceFinalizeFunc)0, 0};
GType type = g_type_register_static(
ATK_TYPE_HYPERLINK, "AXPlatformAtkHyperlink", &tinfo, GTypeFlags(0));
g_type_add_interface_static(type, ATK_TYPE_ACTION, &actionInfo);
g_once_init_leave(&type_volatile, type);
}
return type_volatile;
}
} // namespace ui