Fix search results being clipped in app list.
[chromium-blink-merge.git] / ui / accessibility / platform / ax_platform_node_auralinux.cc
blob85382004c3c9a5e300fc492e0204625296409d1e
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/accessibility/platform/ax_platform_node_auralinux.h"
7 #include "base/command_line.h"
8 #include "base/strings/sys_string_conversions.h"
9 #include "ui/accessibility/ax_node_data.h"
10 #include "ui/accessibility/platform/atk_util_auralinux.h"
11 #include "ui/accessibility/platform/ax_platform_node_delegate.h"
14 // ax_platform_node_auralinux AtkObject definition and implementation.
17 G_BEGIN_DECLS
19 #define AX_PLATFORM_NODE_AURALINUX_TYPE (ax_platform_node_auralinux_get_type())
20 #define AX_PLATFORM_NODE_AURALINUX(obj) \
21 (G_TYPE_CHECK_INSTANCE_CAST( \
22 (obj), AX_PLATFORM_NODE_AURALINUX_TYPE, AXPlatformNodeAuraLinuxObject))
23 #define AX_PLATFORM_NODE_AURALINUX_CLASS(klass) \
24 (G_TYPE_CHECK_CLASS_CAST( \
25 (klass), AX_PLATFORM_NODE_AURALINUX_TYPE, AXPlatformNodeAuraLinuxClass))
26 #define IS_AX_PLATFORM_NODE_AURALINUX(obj) \
27 (G_TYPE_CHECK_INSTANCE_TYPE((obj), AX_PLATFORM_NODE_AURALINUX_TYPE))
28 #define IS_AX_PLATFORM_NODE_AURALINUX_CLASS(klass) \
29 (G_TYPE_CHECK_CLASS_TYPE((klass), AX_PLATFORM_NODE_AURALINUX_TYPE))
30 #define AX_PLATFORM_NODE_AURALINUX_GET_CLASS(obj) \
31 (G_TYPE_INSTANCE_GET_CLASS( \
32 (obj), AX_PLATFORM_NODE_AURALINUX_TYPE, AXPlatformNodeAuraLinuxClass))
34 typedef struct _AXPlatformNodeAuraLinuxObject AXPlatformNodeAuraLinuxObject;
35 typedef struct _AXPlatformNodeAuraLinuxClass AXPlatformNodeAuraLinuxClass;
37 struct _AXPlatformNodeAuraLinuxObject {
38 AtkObject parent;
39 ui::AXPlatformNodeAuraLinux* m_object;
42 struct _AXPlatformNodeAuraLinuxClass {
43 AtkObjectClass parent_class;
46 GType ax_platform_node_auralinux_get_type();
48 static gpointer ax_platform_node_auralinux_parent_class = nullptr;
50 static ui::AXPlatformNodeAuraLinux* ToAXPlatformNodeAuraLinux(
51 AXPlatformNodeAuraLinuxObject* atk_object) {
52 if (!atk_object)
53 return nullptr;
55 return atk_object->m_object;
58 static ui::AXPlatformNodeAuraLinux* AtkObjectToAXPlatformNodeAuraLinux(
59 AtkObject* atk_object) {
60 if (!atk_object)
61 return nullptr;
63 if (IS_AX_PLATFORM_NODE_AURALINUX(atk_object))
64 return ToAXPlatformNodeAuraLinux(AX_PLATFORM_NODE_AURALINUX(atk_object));
66 return nullptr;
69 static const gchar* ax_platform_node_auralinux_get_name(AtkObject* atk_object) {
70 ui::AXPlatformNodeAuraLinux* obj =
71 AtkObjectToAXPlatformNodeAuraLinux(atk_object);
72 if (!obj)
73 return nullptr;
75 return obj->GetStringAttribute(ui::AX_ATTR_NAME).c_str();
78 static const gchar* ax_platform_node_auralinux_get_description(
79 AtkObject* atk_object) {
80 ui::AXPlatformNodeAuraLinux* obj =
81 AtkObjectToAXPlatformNodeAuraLinux(atk_object);
82 if (!obj)
83 return nullptr;
85 return obj->GetStringAttribute(
86 ui::AX_ATTR_DESCRIPTION).c_str();
89 static gint ax_platform_node_auralinux_get_index_in_parent(
90 AtkObject* atk_object) {
91 ui::AXPlatformNodeAuraLinux* obj =
92 AtkObjectToAXPlatformNodeAuraLinux(atk_object);
94 if (!obj || !obj->GetParent())
95 return -1;
97 AtkObject* obj_parent = obj->GetParent();
99 unsigned child_count = atk_object_get_n_accessible_children(obj_parent);
100 for (unsigned index = 0; index < child_count; index++) {
101 AtkObject* child = atk_object_ref_accessible_child(obj_parent, index);
102 bool atk_object_found = child == atk_object;
103 g_object_unref(child);
104 if (atk_object_found)
105 return index;
108 return obj->GetIndexInParent();
111 static AtkObject* ax_platform_node_auralinux_get_parent(AtkObject* atk_object) {
112 ui::AXPlatformNodeAuraLinux* obj =
113 AtkObjectToAXPlatformNodeAuraLinux(atk_object);
114 if (!obj)
115 return nullptr;
117 return obj->GetParent();
120 static gint ax_platform_node_auralinux_get_n_children(AtkObject* atk_object) {
121 ui::AXPlatformNodeAuraLinux* obj =
122 AtkObjectToAXPlatformNodeAuraLinux(atk_object);
123 if (!obj)
124 return 0;
126 return obj->GetChildCount();
129 static AtkObject* ax_platform_node_auralinux_ref_child(
130 AtkObject* atk_object, gint index) {
131 ui::AXPlatformNodeAuraLinux* obj =
132 AtkObjectToAXPlatformNodeAuraLinux(atk_object);
133 if (!obj)
134 return nullptr;
136 AtkObject* result = obj->ChildAtIndex(index);
137 if (result)
138 g_object_ref(result);
139 return result;
142 static AtkRelationSet* ax_platform_node_auralinux_ref_relation_set(
143 AtkObject* atk_object) {
144 ui::AXPlatformNodeAuraLinux* obj =
145 AtkObjectToAXPlatformNodeAuraLinux(atk_object);
146 AtkRelationSet* atk_relation_set =
147 ATK_OBJECT_CLASS(ax_platform_node_auralinux_parent_class)->
148 ref_relation_set(atk_object);
150 if (!obj)
151 return atk_relation_set;
153 obj->GetAtkRelations(atk_relation_set);
154 return atk_relation_set;
157 static AtkAttributeSet* ax_platform_node_auralinux_get_attributes(
158 AtkObject* atk_object) {
159 return NULL;
162 static AtkRole ax_platform_node_auralinux_get_role(AtkObject* atk_object) {
163 ui::AXPlatformNodeAuraLinux* obj =
164 AtkObjectToAXPlatformNodeAuraLinux(atk_object);
165 if (!obj)
166 return ATK_ROLE_INVALID;
167 return obj->GetAtkRole();
170 static AtkStateSet* ax_platform_node_auralinux_ref_state_set(
171 AtkObject* atk_object) {
172 ui::AXPlatformNodeAuraLinux* obj =
173 AtkObjectToAXPlatformNodeAuraLinux(atk_object);
174 if (!obj)
175 return NULL;
177 AtkStateSet* atk_state_set =
178 ATK_OBJECT_CLASS(ax_platform_node_auralinux_parent_class)->
179 ref_state_set(atk_object);
181 obj->GetAtkState(atk_state_set);
182 return atk_state_set;
186 // The rest of the AXPlatformNodeAuraLinux code, not specific to one
187 // of the Atk* interfaces.
190 static void ax_platform_node_auralinux_init(AtkObject* atk_object,
191 gpointer data) {
192 if (ATK_OBJECT_CLASS(ax_platform_node_auralinux_parent_class)->initialize) {
193 ATK_OBJECT_CLASS(ax_platform_node_auralinux_parent_class)->initialize(
194 atk_object, data);
197 AX_PLATFORM_NODE_AURALINUX(atk_object)->m_object =
198 reinterpret_cast<ui::AXPlatformNodeAuraLinux*>(data);
201 static void ax_platform_node_auralinux_finalize(GObject* atk_object) {
202 G_OBJECT_CLASS(ax_platform_node_auralinux_parent_class)->finalize(atk_object);
205 static void ax_platform_node_auralinux_class_init(AtkObjectClass* klass) {
206 GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
207 ax_platform_node_auralinux_parent_class = g_type_class_peek_parent(klass);
209 gobject_class->finalize = ax_platform_node_auralinux_finalize;
210 klass->initialize = ax_platform_node_auralinux_init;
211 klass->get_name = ax_platform_node_auralinux_get_name;
212 klass->get_description = ax_platform_node_auralinux_get_description;
213 klass->get_parent = ax_platform_node_auralinux_get_parent;
214 klass->get_n_children = ax_platform_node_auralinux_get_n_children;
215 klass->ref_child = ax_platform_node_auralinux_ref_child;
216 klass->get_role = ax_platform_node_auralinux_get_role;
217 klass->ref_state_set = ax_platform_node_auralinux_ref_state_set;
218 klass->get_index_in_parent = ax_platform_node_auralinux_get_index_in_parent;
219 klass->ref_relation_set = ax_platform_node_auralinux_ref_relation_set;
220 klass->get_attributes = ax_platform_node_auralinux_get_attributes;
223 GType ax_platform_node_auralinux_get_type() {
224 static volatile gsize type_volatile = 0;
226 if (g_once_init_enter(&type_volatile)) {
227 static const GTypeInfo tinfo = {
228 sizeof(AXPlatformNodeAuraLinuxClass),
229 (GBaseInitFunc) 0,
230 (GBaseFinalizeFunc) 0,
231 (GClassInitFunc) ax_platform_node_auralinux_class_init,
232 (GClassFinalizeFunc) 0,
233 0, /* class data */
234 sizeof(AXPlatformNodeAuraLinuxObject), /* instance size */
235 0, /* nb preallocs */
236 (GInstanceInitFunc) 0,
237 0 /* value table */
240 GType type = g_type_register_static(
241 ATK_TYPE_OBJECT, "AXPlatformNodeAuraLinux", &tinfo, GTypeFlags(0));
242 g_once_init_leave(&type_volatile, type);
245 return type_volatile;
248 AXPlatformNodeAuraLinuxObject* ax_platform_node_auralinux_new(
249 ui::AXPlatformNodeAuraLinux* obj) {
250 #if !GLIB_CHECK_VERSION(2, 36, 0)
251 static bool first_time = true;
252 if (first_time) {
253 g_type_init();
254 first_time = false;
256 #endif
258 GType type = AX_PLATFORM_NODE_AURALINUX_TYPE;
259 AtkObject* atk_object = static_cast<AtkObject*>(g_object_new(type, 0));
260 atk_object_initialize(atk_object, obj);
261 return AX_PLATFORM_NODE_AURALINUX(atk_object);
264 void ax_platform_node_auralinux_detach(
265 AXPlatformNodeAuraLinuxObject* atk_object) {
266 atk_object->m_object = nullptr;
269 G_END_DECLS
272 // AXPlatformNodeAuraLinux implementation.
275 namespace ui {
277 // static
278 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) {
279 AXPlatformNodeAuraLinux* node = new AXPlatformNodeAuraLinux();
280 node->Init(delegate);
281 return node;
284 // static
285 AXPlatformNode* AXPlatformNodeAuraLinux::application_ = nullptr;
287 // static
288 void AXPlatformNodeAuraLinux::SetApplication(AXPlatformNode* application) {
289 application_ = application;
290 AtkUtilAuraLinux::GetInstance();
293 AtkRole AXPlatformNodeAuraLinux::GetAtkRole() {
294 switch (GetData().role) {
295 case ui::AX_ROLE_ALERT:
296 return ATK_ROLE_ALERT;
297 case ui::AX_ROLE_APPLICATION:
298 return ATK_ROLE_APPLICATION;
299 case ui::AX_ROLE_BUTTON:
300 return ATK_ROLE_PUSH_BUTTON;
301 case ui::AX_ROLE_CHECK_BOX:
302 return ATK_ROLE_CHECK_BOX;
303 case ui::AX_ROLE_COMBO_BOX:
304 return ATK_ROLE_COMBO_BOX;
305 case ui::AX_ROLE_DIALOG:
306 return ATK_ROLE_DIALOG;
307 case ui::AX_ROLE_GROUP:
308 return ATK_ROLE_PANEL;
309 case ui::AX_ROLE_IMAGE:
310 return ATK_ROLE_IMAGE;
311 case ui::AX_ROLE_MENU_ITEM:
312 return ATK_ROLE_MENU_ITEM;
313 case ui::AX_ROLE_SCROLL_BAR:
314 return ATK_ROLE_SCROLL_BAR;
315 case ui::AX_ROLE_SLIDER:
316 return ATK_ROLE_SLIDER;
317 case ui::AX_ROLE_SPLITTER:
318 return ATK_ROLE_SEPARATOR;
319 case ui::AX_ROLE_STATIC_TEXT:
320 return ATK_ROLE_TEXT;
321 case ui::AX_ROLE_TAB:
322 return ATK_ROLE_PAGE_TAB;
323 case ui::AX_ROLE_TAB_LIST:
324 return ATK_ROLE_PAGE_TAB_LIST;
325 case ui::AX_ROLE_TEXT_FIELD:
326 return ATK_ROLE_ENTRY;
327 case ui::AX_ROLE_TOOLBAR:
328 return ATK_ROLE_TOOL_BAR;
329 case ui::AX_ROLE_WINDOW:
330 return ATK_ROLE_WINDOW;
331 default:
332 return ATK_ROLE_UNKNOWN;
336 void AXPlatformNodeAuraLinux::GetAtkState(AtkStateSet* atk_state_set) {
337 uint32 state = GetData().state;
339 if (state & (1 << ui::AX_STATE_CHECKED))
340 atk_state_set_add_state(atk_state_set, ATK_STATE_CHECKED);
341 if (state & (1 << ui::AX_STATE_DEFAULT))
342 atk_state_set_add_state(atk_state_set, ATK_STATE_DEFAULT);
343 if (state & (1 << ui::AX_STATE_EDITABLE))
344 atk_state_set_add_state(atk_state_set, ATK_STATE_EDITABLE);
345 if (state & (1 << ui::AX_STATE_ENABLED))
346 atk_state_set_add_state(atk_state_set, ATK_STATE_ENABLED);
347 if (state & (1 << ui::AX_STATE_EXPANDED))
348 atk_state_set_add_state(atk_state_set, ATK_STATE_EXPANDED);
349 if (state & (1 << ui::AX_STATE_FOCUSABLE))
350 atk_state_set_add_state(atk_state_set, ATK_STATE_FOCUSABLE);
351 if (state & (1 << ui::AX_STATE_FOCUSED))
352 atk_state_set_add_state(atk_state_set, ATK_STATE_FOCUSED);
353 if (state & (1 << ui::AX_STATE_PRESSED))
354 atk_state_set_add_state(atk_state_set, ATK_STATE_PRESSED);
355 if (state & (1 << ui::AX_STATE_SELECTABLE))
356 atk_state_set_add_state(atk_state_set, ATK_STATE_SELECTABLE);
357 if (state & (1 << ui::AX_STATE_SELECTED))
358 atk_state_set_add_state(atk_state_set, ATK_STATE_SELECTED);
361 void AXPlatformNodeAuraLinux::GetAtkRelations(AtkRelationSet* atk_relation_set)
365 AXPlatformNodeAuraLinux::AXPlatformNodeAuraLinux()
366 : atk_object_(nullptr) {
369 AXPlatformNodeAuraLinux::~AXPlatformNodeAuraLinux() {
370 g_object_unref(atk_object_);
373 void AXPlatformNodeAuraLinux::Init(AXPlatformNodeDelegate* delegate) {
374 // Initialize ATK.
375 AXPlatformNodeBase::Init(delegate);
376 atk_object_ = ATK_OBJECT(ax_platform_node_auralinux_new(this));
379 void AXPlatformNodeAuraLinux::Destroy() {
380 delegate_ = nullptr;
381 delete this;
384 gfx::NativeViewAccessible AXPlatformNodeAuraLinux::GetNativeViewAccessible() {
385 return atk_object_;
388 void AXPlatformNodeAuraLinux::NotifyAccessibilityEvent(ui::AXEvent event_type) {
391 int AXPlatformNodeAuraLinux::GetIndexInParent() {
392 return 0;
395 } // namespace ui