1 // Copyright (c) 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 "content/browser/accessibility/browser_accessibility_auralinux.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "content/browser/accessibility/browser_accessibility_manager_auralinux.h"
9 #include "content/common/accessibility_messages.h"
13 static gpointer browser_accessibility_parent_class
= NULL
;
15 static BrowserAccessibilityAuraLinux
* ToBrowserAccessibilityAuraLinux(
16 BrowserAccessibilityAtk
* atk_object
) {
20 return atk_object
->m_object
;
24 // AtkAction interface.
27 static BrowserAccessibilityAuraLinux
* ToBrowserAccessibilityAuraLinux(
28 AtkAction
* atk_action
) {
29 if (!IS_BROWSER_ACCESSIBILITY(atk_action
))
32 return ToBrowserAccessibilityAuraLinux(BROWSER_ACCESSIBILITY(atk_action
));
35 static gboolean
browser_accessibility_do_action(AtkAction
* atk_action
,
37 g_return_val_if_fail(ATK_IS_ACTION(atk_action
), FALSE
);
38 g_return_val_if_fail(!index
, FALSE
);
40 BrowserAccessibilityAuraLinux
* obj
=
41 ToBrowserAccessibilityAuraLinux(atk_action
);
45 obj
->manager()->DoDefaultAction(*obj
);
50 static gint
browser_accessibility_get_n_actions(AtkAction
* atk_action
) {
51 g_return_val_if_fail(ATK_IS_ACTION(atk_action
), 0);
53 BrowserAccessibilityAuraLinux
* obj
=
54 ToBrowserAccessibilityAuraLinux(atk_action
);
61 static const gchar
* browser_accessibility_get_description(AtkAction
* atk_action
,
63 g_return_val_if_fail(ATK_IS_ACTION(atk_action
), 0);
64 BrowserAccessibilityAuraLinux
* obj
=
65 ToBrowserAccessibilityAuraLinux(atk_action
);
72 static const gchar
* browser_accessibility_get_name(AtkAction
* atk_action
,
74 g_return_val_if_fail(ATK_IS_ACTION(atk_action
), 0);
75 g_return_val_if_fail(!index
, 0);
76 BrowserAccessibilityAuraLinux
* obj
=
77 ToBrowserAccessibilityAuraLinux(atk_action
);
81 return obj
->GetStringAttribute(ui::AX_ATTR_ACTION
).c_str();
84 static const gchar
* browser_accessibility_get_keybinding(AtkAction
* atk_action
,
86 g_return_val_if_fail(ATK_IS_ACTION(atk_action
), 0);
87 g_return_val_if_fail(!index
, 0);
88 BrowserAccessibilityAuraLinux
* obj
=
89 ToBrowserAccessibilityAuraLinux(atk_action
);
93 return obj
->GetStringAttribute(ui::AX_ATTR_ACCESS_KEY
).c_str();
96 static void ActionInterfaceInit(AtkActionIface
* iface
) {
97 iface
->do_action
= browser_accessibility_do_action
;
98 iface
->get_n_actions
= browser_accessibility_get_n_actions
;
99 iface
->get_description
= browser_accessibility_get_description
;
100 iface
->get_name
= browser_accessibility_get_name
;
101 iface
->get_keybinding
= browser_accessibility_get_keybinding
;
104 static const GInterfaceInfo ActionInfo
= {
105 reinterpret_cast<GInterfaceInitFunc
>(ActionInterfaceInit
), 0, 0};
108 // AtkComponent interface.
111 static BrowserAccessibilityAuraLinux
* ToBrowserAccessibilityAuraLinux(
112 AtkComponent
* atk_component
) {
113 if (!IS_BROWSER_ACCESSIBILITY(atk_component
))
116 return ToBrowserAccessibilityAuraLinux(BROWSER_ACCESSIBILITY(atk_component
));
119 static AtkObject
* browser_accessibility_accessible_at_point(
120 AtkComponent
* atk_component
,
123 AtkCoordType coord_type
) {
124 g_return_val_if_fail(ATK_IS_COMPONENT(atk_component
), 0);
126 BrowserAccessibilityAuraLinux
* obj
=
127 ToBrowserAccessibilityAuraLinux(atk_component
);
131 gfx::Point
point(x
, y
);
132 if (!obj
->GetGlobalBoundsRect().Contains(point
))
135 BrowserAccessibility
* result
= obj
->BrowserAccessibilityForPoint(point
);
139 AtkObject
* atk_result
=
140 result
->ToBrowserAccessibilityAuraLinux()->GetAtkObject();
141 g_object_ref(atk_result
);
145 static void browser_accessibility_get_extents(AtkComponent
* atk_component
,
150 AtkCoordType coord_type
) {
151 g_return_if_fail(ATK_IS_COMPONENT(atk_component
));
153 BrowserAccessibilityAuraLinux
* obj
=
154 ToBrowserAccessibilityAuraLinux(atk_component
);
158 gfx::Rect bounds
= obj
->GetGlobalBoundsRect();
164 *width
= bounds
.width();
166 *height
= bounds
.height();
169 static gboolean
browser_accessibility_grab_focus(AtkComponent
* atk_component
) {
170 g_return_val_if_fail(ATK_IS_COMPONENT(atk_component
), FALSE
);
172 BrowserAccessibilityAuraLinux
* obj
=
173 ToBrowserAccessibilityAuraLinux(atk_component
);
177 obj
->manager()->SetFocus(obj
, true);
181 static void ComponentInterfaceInit(AtkComponentIface
* iface
) {
182 iface
->ref_accessible_at_point
= browser_accessibility_accessible_at_point
;
183 iface
->get_extents
= browser_accessibility_get_extents
;
184 iface
->grab_focus
= browser_accessibility_grab_focus
;
187 static const GInterfaceInfo ComponentInfo
= {
188 reinterpret_cast<GInterfaceInitFunc
>(ComponentInterfaceInit
),
193 // AtkDocument interface.
196 static BrowserAccessibilityAuraLinux
* ToBrowserAccessibilityAuraLinux(
197 AtkDocument
* atk_doc
) {
198 if (!IS_BROWSER_ACCESSIBILITY(atk_doc
))
201 return ToBrowserAccessibilityAuraLinux(BROWSER_ACCESSIBILITY(atk_doc
));
204 static const gchar
* GetDocumentAttributeValue(
205 BrowserAccessibilityAuraLinux
* obj
,
206 const gchar
* attribute
) {
207 if (!g_ascii_strcasecmp(attribute
, "DocType"))
208 return obj
->GetStringAttribute(ui::AX_ATTR_DOC_DOCTYPE
).c_str();
209 else if (!g_ascii_strcasecmp(attribute
, "MimeType"))
210 return obj
->GetStringAttribute(ui::AX_ATTR_DOC_MIMETYPE
).c_str();
211 else if (!g_ascii_strcasecmp(attribute
, "Title"))
212 return obj
->GetStringAttribute(ui::AX_ATTR_DOC_TITLE
).c_str();
213 else if (!g_ascii_strcasecmp(attribute
, "URI"))
214 return obj
->GetStringAttribute(ui::AX_ATTR_DOC_URL
).c_str();
219 AtkAttributeSet
* SetAtkAttributeSet(AtkAttributeSet
* attribute_set
,
222 AtkAttribute
* attribute
=
223 static_cast<AtkAttribute
*>(g_malloc(sizeof(AtkAttribute
)));
224 attribute
->name
= g_strdup(name
);
225 attribute
->value
= g_strdup(value
);
226 attribute_set
= g_slist_prepend(attribute_set
, attribute
);
227 return attribute_set
;
230 static const gchar
* browser_accessibility_get_attribute_value(
231 AtkDocument
* atk_doc
,
232 const gchar
* attribute
) {
233 g_return_val_if_fail(ATK_IS_DOCUMENT(atk_doc
), 0);
234 BrowserAccessibilityAuraLinux
* obj
= ToBrowserAccessibilityAuraLinux(atk_doc
);
238 return GetDocumentAttributeValue(obj
, attribute
);
241 static AtkAttributeSet
* browser_accessibility_get_attributes(
242 AtkDocument
* atk_doc
) {
243 g_return_val_if_fail(ATK_IS_DOCUMENT(atk_doc
), 0);
244 BrowserAccessibilityAuraLinux
* obj
= ToBrowserAccessibilityAuraLinux(atk_doc
);
248 AtkAttributeSet
* attribute_set
= 0;
249 const gchar
* doc_attributes
[] = {"DocType", "MimeType", "Title", "URI"};
250 const gchar
* value
= 0;
252 for (unsigned i
= 0; i
< G_N_ELEMENTS(doc_attributes
); i
++) {
253 value
= GetDocumentAttributeValue(obj
, doc_attributes
[i
]);
256 SetAtkAttributeSet(attribute_set
, doc_attributes
[i
], value
);
259 return attribute_set
;
262 static void DocumentInterfaceInit(AtkDocumentIface
* iface
) {
263 iface
->get_document_attribute_value
=
264 browser_accessibility_get_attribute_value
;
265 iface
->get_document_attributes
= browser_accessibility_get_attributes
;
268 static const GInterfaceInfo DocumentInfo
= {
269 reinterpret_cast<GInterfaceInitFunc
>(DocumentInterfaceInit
), 0, 0};
272 // AtkImage interface.
275 static BrowserAccessibilityAuraLinux
* ToBrowserAccessibilityAuraLinux(
277 if (!IS_BROWSER_ACCESSIBILITY(atk_img
))
280 return ToBrowserAccessibilityAuraLinux(BROWSER_ACCESSIBILITY(atk_img
));
283 void GetImagePositionSize(BrowserAccessibilityAuraLinux
* obj
,
288 gfx::Rect img_pos_size
= obj
->GetGlobalBoundsRect();
291 *x
= img_pos_size
.x();
293 *y
= img_pos_size
.y();
295 *width
= img_pos_size
.width();
297 *height
= img_pos_size
.height();
300 static void browser_accessibility_get_image_position(AtkImage
* atk_img
,
303 AtkCoordType coordType
) {
304 g_return_if_fail(ATK_IMAGE(atk_img
));
305 BrowserAccessibilityAuraLinux
* obj
= ToBrowserAccessibilityAuraLinux(atk_img
);
309 GetImagePositionSize(obj
, x
, y
, nullptr, nullptr);
312 static const gchar
* browser_accessibility_get_image_description(
314 g_return_val_if_fail(ATK_IMAGE(atk_img
), 0);
315 BrowserAccessibilityAuraLinux
* obj
= ToBrowserAccessibilityAuraLinux(atk_img
);
319 return obj
->GetStringAttribute(ui::AX_ATTR_DESCRIPTION
).c_str();
322 static void browser_accessibility_get_image_size(AtkImage
* atk_img
,
325 g_return_if_fail(ATK_IMAGE(atk_img
));
326 BrowserAccessibilityAuraLinux
* obj
= ToBrowserAccessibilityAuraLinux(atk_img
);
330 GetImagePositionSize(obj
, nullptr, nullptr, width
, height
);
333 void ImageInterfaceInit(AtkImageIface
* iface
) {
334 iface
->get_image_position
= browser_accessibility_get_image_position
;
335 iface
->get_image_description
= browser_accessibility_get_image_description
;
336 iface
->get_image_size
= browser_accessibility_get_image_size
;
339 static const GInterfaceInfo ImageInfo
= {
340 reinterpret_cast<GInterfaceInitFunc
>(ImageInterfaceInit
), 0, 0};
343 // AtkValue interface.
346 static BrowserAccessibilityAuraLinux
* ToBrowserAccessibilityAuraLinux(
347 AtkValue
* atk_object
) {
348 if (!IS_BROWSER_ACCESSIBILITY(atk_object
))
351 return ToBrowserAccessibilityAuraLinux(BROWSER_ACCESSIBILITY(atk_object
));
354 static float GetStepAttribute(BrowserAccessibilityAuraLinux
* obj
) {
355 // TODO(shreeram.k): Get Correct value of Step attribute.
359 static void browser_accessibility_get_current_value(AtkValue
* atk_value
,
361 g_return_if_fail(ATK_VALUE(atk_value
));
363 BrowserAccessibilityAuraLinux
* obj
=
364 ToBrowserAccessibilityAuraLinux(atk_value
);
369 if (obj
->GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE
, &float_val
)) {
370 memset(value
, 0, sizeof(*value
));
371 g_value_init(value
, G_TYPE_FLOAT
);
372 g_value_set_float(value
, float_val
);
376 static void browser_accessibility_get_minimum_value(AtkValue
* atk_value
,
378 g_return_if_fail(ATK_VALUE(atk_value
));
380 BrowserAccessibilityAuraLinux
* obj
=
381 ToBrowserAccessibilityAuraLinux(atk_value
);
386 if (obj
->GetFloatAttribute(ui::AX_ATTR_MIN_VALUE_FOR_RANGE
, &float_val
)) {
387 memset(value
, 0, sizeof(*value
));
388 g_value_init(value
, G_TYPE_FLOAT
);
389 g_value_set_float(value
, float_val
);
393 static void browser_accessibility_get_maximum_value(AtkValue
* atk_value
,
395 g_return_if_fail(ATK_VALUE(atk_value
));
397 BrowserAccessibilityAuraLinux
* obj
=
398 ToBrowserAccessibilityAuraLinux(atk_value
);
403 if (obj
->GetFloatAttribute(ui::AX_ATTR_MAX_VALUE_FOR_RANGE
, &float_val
)) {
404 memset(value
, 0, sizeof(*value
));
405 g_value_init(value
, G_TYPE_FLOAT
);
406 g_value_set_float(value
, float_val
);
410 static void browser_accessibility_get_minimum_increment(AtkValue
* atk_value
,
412 g_return_if_fail(ATK_VALUE(atk_value
));
414 memset(gValue
, 0, sizeof(GValue
));
415 g_value_init(gValue
, G_TYPE_FLOAT
);
417 BrowserAccessibilityAuraLinux
* obj
=
418 ToBrowserAccessibilityAuraLinux(atk_value
);
422 g_value_set_float(gValue
, GetStepAttribute(obj
));
425 static void ValueInterfaceInit(AtkValueIface
* iface
) {
426 iface
->get_current_value
= browser_accessibility_get_current_value
;
427 iface
->get_minimum_value
= browser_accessibility_get_minimum_value
;
428 iface
->get_maximum_value
= browser_accessibility_get_maximum_value
;
429 iface
->get_minimum_increment
= browser_accessibility_get_minimum_increment
;
432 static const GInterfaceInfo ValueInfo
= {
433 reinterpret_cast<GInterfaceInitFunc
>(ValueInterfaceInit
),
438 // AtkObject interface
441 static BrowserAccessibilityAuraLinux
* ToBrowserAccessibilityAuraLinux(
442 AtkObject
* atk_object
) {
443 if (!IS_BROWSER_ACCESSIBILITY(atk_object
))
446 return ToBrowserAccessibilityAuraLinux(BROWSER_ACCESSIBILITY(atk_object
));
449 static const gchar
* browser_accessibility_get_name(AtkObject
* atk_object
) {
450 BrowserAccessibilityAuraLinux
* obj
=
451 ToBrowserAccessibilityAuraLinux(atk_object
);
455 return obj
->GetStringAttribute(ui::AX_ATTR_NAME
).c_str();
458 static const gchar
* browser_accessibility_get_description(
459 AtkObject
* atk_object
) {
460 BrowserAccessibilityAuraLinux
* obj
=
461 ToBrowserAccessibilityAuraLinux(atk_object
);
465 return obj
->GetStringAttribute(ui::AX_ATTR_DESCRIPTION
).c_str();
468 static AtkObject
* browser_accessibility_get_parent(AtkObject
* atk_object
) {
469 BrowserAccessibilityAuraLinux
* obj
=
470 ToBrowserAccessibilityAuraLinux(atk_object
);
473 if (obj
->GetParent())
474 return obj
->GetParent()->ToBrowserAccessibilityAuraLinux()->GetAtkObject();
476 BrowserAccessibilityManagerAuraLinux
* manager
=
477 static_cast<BrowserAccessibilityManagerAuraLinux
*>(obj
->manager());
478 return manager
->parent_object();
481 static gint
browser_accessibility_get_n_children(AtkObject
* atk_object
) {
482 BrowserAccessibilityAuraLinux
* obj
=
483 ToBrowserAccessibilityAuraLinux(atk_object
);
487 return obj
->PlatformChildCount();
490 static AtkObject
* browser_accessibility_ref_child(AtkObject
* atk_object
,
492 BrowserAccessibilityAuraLinux
* obj
=
493 ToBrowserAccessibilityAuraLinux(atk_object
);
497 if (index
< 0 || index
>= static_cast<gint
>(obj
->PlatformChildCount()))
500 AtkObject
* result
= obj
->InternalGetChild(index
)
501 ->ToBrowserAccessibilityAuraLinux()
503 g_object_ref(result
);
507 static gint
browser_accessibility_get_index_in_parent(AtkObject
* atk_object
) {
508 BrowserAccessibilityAuraLinux
* obj
=
509 ToBrowserAccessibilityAuraLinux(atk_object
);
512 return obj
->GetIndexInParent();
515 static AtkAttributeSet
* browser_accessibility_get_attributes(
516 AtkObject
* atk_object
) {
520 static AtkRole
browser_accessibility_get_role(AtkObject
* atk_object
) {
521 BrowserAccessibilityAuraLinux
* obj
=
522 ToBrowserAccessibilityAuraLinux(atk_object
);
524 return ATK_ROLE_INVALID
;
525 return obj
->atk_role();
528 static AtkStateSet
* browser_accessibility_ref_state_set(AtkObject
* atk_object
) {
529 BrowserAccessibilityAuraLinux
* obj
=
530 ToBrowserAccessibilityAuraLinux(atk_object
);
533 AtkStateSet
* state_set
= ATK_OBJECT_CLASS(browser_accessibility_parent_class
)
534 ->ref_state_set(atk_object
);
535 int32 state
= obj
->GetState();
537 if (state
& (1 << ui::AX_STATE_FOCUSABLE
))
538 atk_state_set_add_state(state_set
, ATK_STATE_FOCUSABLE
);
539 if (obj
->manager()->GetFocus(NULL
) == obj
)
540 atk_state_set_add_state(state_set
, ATK_STATE_FOCUSED
);
541 if (state
& (1 << ui::AX_STATE_ENABLED
))
542 atk_state_set_add_state(state_set
, ATK_STATE_ENABLED
);
547 static AtkRelationSet
* browser_accessibility_ref_relation_set(
548 AtkObject
* atk_object
) {
549 AtkRelationSet
* relation_set
=
550 ATK_OBJECT_CLASS(browser_accessibility_parent_class
)
551 ->ref_relation_set(atk_object
);
556 // The rest of the BrowserAccessibilityAuraLinux code, not specific to one
557 // of the Atk* interfaces.
560 static void browser_accessibility_init(AtkObject
* atk_object
, gpointer data
) {
561 if (ATK_OBJECT_CLASS(browser_accessibility_parent_class
)->initialize
) {
562 ATK_OBJECT_CLASS(browser_accessibility_parent_class
)
563 ->initialize(atk_object
, data
);
566 BROWSER_ACCESSIBILITY(atk_object
)->m_object
=
567 reinterpret_cast<BrowserAccessibilityAuraLinux
*>(data
);
570 static void browser_accessibility_finalize(GObject
* atk_object
) {
571 G_OBJECT_CLASS(browser_accessibility_parent_class
)->finalize(atk_object
);
574 static void browser_accessibility_class_init(AtkObjectClass
* klass
) {
575 GObjectClass
* gobject_class
= G_OBJECT_CLASS(klass
);
576 browser_accessibility_parent_class
= g_type_class_peek_parent(klass
);
578 gobject_class
->finalize
= browser_accessibility_finalize
;
579 klass
->initialize
= browser_accessibility_init
;
580 klass
->get_name
= browser_accessibility_get_name
;
581 klass
->get_description
= browser_accessibility_get_description
;
582 klass
->get_parent
= browser_accessibility_get_parent
;
583 klass
->get_n_children
= browser_accessibility_get_n_children
;
584 klass
->ref_child
= browser_accessibility_ref_child
;
585 klass
->get_role
= browser_accessibility_get_role
;
586 klass
->ref_state_set
= browser_accessibility_ref_state_set
;
587 klass
->get_index_in_parent
= browser_accessibility_get_index_in_parent
;
588 klass
->get_attributes
= browser_accessibility_get_attributes
;
589 klass
->ref_relation_set
= browser_accessibility_ref_relation_set
;
592 GType
browser_accessibility_get_type() {
593 static volatile gsize type_volatile
= 0;
595 #if !GLIB_CHECK_VERSION(2, 36, 0)
599 if (g_once_init_enter(&type_volatile
)) {
600 static const GTypeInfo tinfo
= {
601 sizeof(BrowserAccessibilityAtkClass
),
603 (GBaseFinalizeFunc
)0,
604 (GClassInitFunc
)browser_accessibility_class_init
,
605 (GClassFinalizeFunc
)0,
607 sizeof(BrowserAccessibilityAtk
), /* instance size */
608 0, /* nb preallocs */
609 (GInstanceInitFunc
)0,
613 GType type
= g_type_register_static(ATK_TYPE_OBJECT
, "BrowserAccessibility",
614 &tinfo
, GTypeFlags(0));
615 g_once_init_leave(&type_volatile
, type
);
618 return type_volatile
;
621 static const char* GetUniqueAccessibilityTypeName(int interface_mask
) {
622 // 20 characters is enough for "Chrome%x" with any integer value.
623 static char name
[20];
624 snprintf(name
, sizeof(name
), "Chrome%x", interface_mask
);
629 ATK_ACTION_INTERFACE
,
630 ATK_COMPONENT_INTERFACE
,
631 ATK_DOCUMENT_INTERFACE
,
632 ATK_EDITABLE_TEXT_INTERFACE
,
633 ATK_HYPERLINK_INTERFACE
,
634 ATK_HYPERTEXT_INTERFACE
,
636 ATK_SELECTION_INTERFACE
,
642 static int GetInterfaceMaskFromObject(BrowserAccessibilityAuraLinux
* obj
) {
643 int interface_mask
= 0;
645 // Component interface is always supported.
646 interface_mask
|= 1 << ATK_COMPONENT_INTERFACE
;
648 // Action interface is basic one. It just relays on executing default action
650 interface_mask
|= 1 << ATK_ACTION_INTERFACE
;
653 int role
= obj
->GetRole();
654 if (role
== ui::AX_ROLE_PROGRESS_INDICATOR
||
655 role
== ui::AX_ROLE_SCROLL_BAR
|| role
== ui::AX_ROLE_SLIDER
) {
656 interface_mask
|= 1 << ATK_VALUE_INTERFACE
;
659 // Document Interface
660 if (role
== ui::AX_ROLE_DOCUMENT
|| role
== ui::AX_ROLE_ROOT_WEB_AREA
||
661 role
== ui::AX_ROLE_WEB_AREA
)
662 interface_mask
|= 1 << ATK_DOCUMENT_INTERFACE
;
665 if (role
== ui::AX_ROLE_IMAGE
|| role
== ui::AX_ROLE_IMAGE_MAP
)
666 interface_mask
|= 1 << ATK_IMAGE_INTERFACE
;
668 return interface_mask
;
671 static GType
GetAccessibilityTypeFromObject(
672 BrowserAccessibilityAuraLinux
* obj
) {
673 static const GTypeInfo type_info
= {
674 sizeof(BrowserAccessibilityAtkClass
),
676 (GBaseFinalizeFunc
)0,
678 (GClassFinalizeFunc
)0,
680 sizeof(BrowserAccessibilityAtk
), /* instance size */
681 0, /* nb preallocs */
682 (GInstanceInitFunc
)0,
686 int interface_mask
= GetInterfaceMaskFromObject(obj
);
687 const char* atk_type_name
= GetUniqueAccessibilityTypeName(interface_mask
);
688 GType type
= g_type_from_name(atk_type_name
);
692 type
= g_type_register_static(BROWSER_ACCESSIBILITY_TYPE
, atk_type_name
,
693 &type_info
, GTypeFlags(0));
694 if (interface_mask
& (1 << ATK_ACTION_INTERFACE
))
695 g_type_add_interface_static(type
, ATK_TYPE_ACTION
, &ActionInfo
);
696 if (interface_mask
& (1 << ATK_COMPONENT_INTERFACE
))
697 g_type_add_interface_static(type
, ATK_TYPE_COMPONENT
, &ComponentInfo
);
698 if (interface_mask
& (1 << ATK_DOCUMENT_INTERFACE
))
699 g_type_add_interface_static(type
, ATK_TYPE_DOCUMENT
, &DocumentInfo
);
700 if (interface_mask
& (1 << ATK_IMAGE_INTERFACE
))
701 g_type_add_interface_static(type
, ATK_TYPE_IMAGE
, &ImageInfo
);
702 if (interface_mask
& (1 << ATK_VALUE_INTERFACE
))
703 g_type_add_interface_static(type
, ATK_TYPE_VALUE
, &ValueInfo
);
708 BrowserAccessibilityAtk
* browser_accessibility_new(
709 BrowserAccessibilityAuraLinux
* obj
) {
710 GType type
= GetAccessibilityTypeFromObject(obj
);
711 AtkObject
* atk_object
= static_cast<AtkObject
*>(g_object_new(type
, 0));
713 atk_object_initialize(atk_object
, obj
);
715 return BROWSER_ACCESSIBILITY(atk_object
);
718 void browser_accessibility_detach(BrowserAccessibilityAtk
* atk_object
) {
719 atk_object
->m_object
= NULL
;
723 BrowserAccessibility
* BrowserAccessibility::Create() {
724 return new BrowserAccessibilityAuraLinux();
727 BrowserAccessibilityAuraLinux
*
728 BrowserAccessibility::ToBrowserAccessibilityAuraLinux() {
729 return static_cast<BrowserAccessibilityAuraLinux
*>(this);
732 BrowserAccessibilityAuraLinux::BrowserAccessibilityAuraLinux()
733 : atk_object_(NULL
) {
736 BrowserAccessibilityAuraLinux::~BrowserAccessibilityAuraLinux() {
737 browser_accessibility_detach(BROWSER_ACCESSIBILITY(atk_object_
));
739 g_object_unref(atk_object_
);
742 AtkObject
* BrowserAccessibilityAuraLinux::GetAtkObject() const {
743 if (!G_IS_OBJECT(atk_object_
))
748 void BrowserAccessibilityAuraLinux::OnDataChanged() {
749 BrowserAccessibility::OnDataChanged();
753 // If the object's role changes and that causes its
754 // interface mask to change, we need to create a new
756 int interface_mask
= GetInterfaceMaskFromObject(this);
757 if (interface_mask
!= interface_mask_
) {
758 g_object_unref(atk_object_
);
764 interface_mask_
= GetInterfaceMaskFromObject(this);
765 atk_object_
= ATK_OBJECT(browser_accessibility_new(this));
766 if (this->GetParent()) {
767 atk_object_set_parent(
769 this->GetParent()->ToBrowserAccessibilityAuraLinux()->GetAtkObject());
774 bool BrowserAccessibilityAuraLinux::IsNative() const {
778 void BrowserAccessibilityAuraLinux::InitRoleAndState() {
780 case ui::AX_ROLE_DOCUMENT
:
781 case ui::AX_ROLE_ROOT_WEB_AREA
:
782 case ui::AX_ROLE_WEB_AREA
:
783 atk_role_
= ATK_ROLE_DOCUMENT_WEB
;
785 case ui::AX_ROLE_ALERT
:
786 case ui::AX_ROLE_ALERT_DIALOG
:
787 atk_role_
= ATK_ROLE_ALERT
;
789 case ui::AX_ROLE_APPLICATION
:
790 atk_role_
= ATK_ROLE_APPLICATION
;
792 case ui::AX_ROLE_BUTTON
:
793 atk_role_
= ATK_ROLE_PUSH_BUTTON
;
795 case ui::AX_ROLE_CANVAS
:
796 atk_role_
= ATK_ROLE_CANVAS
;
798 case ui::AX_ROLE_CAPTION
:
799 atk_role_
= ATK_ROLE_CAPTION
;
801 case ui::AX_ROLE_CHECK_BOX
:
802 atk_role_
= ATK_ROLE_CHECK_BOX
;
804 case ui::AX_ROLE_COLOR_WELL
:
805 atk_role_
= ATK_ROLE_COLOR_CHOOSER
;
807 case ui::AX_ROLE_COLUMN_HEADER
:
808 atk_role_
= ATK_ROLE_COLUMN_HEADER
;
810 case ui::AX_ROLE_COMBO_BOX
:
811 atk_role_
= ATK_ROLE_COMBO_BOX
;
813 case ui::AX_ROLE_DATE
:
814 case ui::AX_ROLE_DATE_TIME
:
815 atk_role_
= ATK_ROLE_DATE_EDITOR
;
817 case ui::AX_ROLE_DIALOG
:
818 atk_role_
= ATK_ROLE_DIALOG
;
820 case ui::AX_ROLE_DIV
:
821 case ui::AX_ROLE_GROUP
:
822 atk_role_
= ATK_ROLE_SECTION
;
824 case ui::AX_ROLE_FORM
:
825 atk_role_
= ATK_ROLE_FORM
;
827 case ui::AX_ROLE_IMAGE
:
828 atk_role_
= ATK_ROLE_IMAGE
;
830 case ui::AX_ROLE_IMAGE_MAP
:
831 atk_role_
= ATK_ROLE_IMAGE_MAP
;
833 case ui::AX_ROLE_LABEL_TEXT
:
834 atk_role_
= ATK_ROLE_LABEL
;
836 case ui::AX_ROLE_LINK
:
837 atk_role_
= ATK_ROLE_LINK
;
839 case ui::AX_ROLE_LIST
:
840 atk_role_
= ATK_ROLE_LIST
;
842 case ui::AX_ROLE_LIST_BOX
:
843 atk_role_
= ATK_ROLE_LIST_BOX
;
845 case ui::AX_ROLE_LIST_ITEM
:
846 atk_role_
= ATK_ROLE_LIST_ITEM
;
848 case ui::AX_ROLE_MENU
:
849 atk_role_
= ATK_ROLE_MENU
;
851 case ui::AX_ROLE_MENU_BAR
:
852 atk_role_
= ATK_ROLE_MENU_BAR
;
854 case ui::AX_ROLE_MENU_ITEM
:
855 atk_role_
= ATK_ROLE_MENU_ITEM
;
857 case ui::AX_ROLE_MENU_ITEM_CHECK_BOX
:
858 atk_role_
= ATK_ROLE_CHECK_MENU_ITEM
;
860 case ui::AX_ROLE_MENU_ITEM_RADIO
:
861 atk_role_
= ATK_ROLE_RADIO_MENU_ITEM
;
863 case ui::AX_ROLE_METER
:
864 atk_role_
= ATK_ROLE_PROGRESS_BAR
;
866 case ui::AX_ROLE_PARAGRAPH
:
867 atk_role_
= ATK_ROLE_PARAGRAPH
;
869 case ui::AX_ROLE_RADIO_BUTTON
:
870 atk_role_
= ATK_ROLE_RADIO_BUTTON
;
872 case ui::AX_ROLE_ROW_HEADER
:
873 atk_role_
= ATK_ROLE_ROW_HEADER
;
875 case ui::AX_ROLE_SCROLL_BAR
:
876 atk_role_
= ATK_ROLE_SCROLL_BAR
;
878 case ui::AX_ROLE_SLIDER
:
879 atk_role_
= ATK_ROLE_SLIDER
;
881 case ui::AX_ROLE_SPIN_BUTTON
:
882 atk_role_
= ATK_ROLE_SPIN_BUTTON
;
884 case ui::AX_ROLE_SPLITTER
:
885 atk_role_
= ATK_ROLE_SEPARATOR
;
887 case ui::AX_ROLE_STATIC_TEXT
:
888 atk_role_
= ATK_ROLE_TEXT
;
890 case ui::AX_ROLE_STATUS
:
891 atk_role_
= ATK_ROLE_STATUSBAR
;
893 case ui::AX_ROLE_TAB
:
894 atk_role_
= ATK_ROLE_PAGE_TAB
;
896 case ui::AX_ROLE_TABLE
:
897 atk_role_
= ATK_ROLE_TABLE
;
899 case ui::AX_ROLE_TAB_LIST
:
900 atk_role_
= ATK_ROLE_PAGE_TAB_LIST
;
902 case ui::AX_ROLE_TOGGLE_BUTTON
:
903 atk_role_
= ATK_ROLE_TOGGLE_BUTTON
;
905 case ui::AX_ROLE_TOOLBAR
:
906 atk_role_
= ATK_ROLE_TOOL_BAR
;
908 case ui::AX_ROLE_TOOLTIP
:
909 atk_role_
= ATK_ROLE_TOOL_TIP
;
911 case ui::AX_ROLE_TEXT_FIELD
:
912 atk_role_
= ATK_ROLE_ENTRY
;
914 case ui::AX_ROLE_TREE
:
915 atk_role_
= ATK_ROLE_TREE
;
917 case ui::AX_ROLE_TREE_ITEM
:
918 atk_role_
= ATK_ROLE_TREE_ITEM
;
921 atk_role_
= ATK_ROLE_UNKNOWN
;
926 } // namespace content