OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/accessibility/browser_accessibility_auralinux.h" | 5 #include "content/browser/accessibility/browser_accessibility_auralinux.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "content/browser/accessibility/browser_accessibility_manager_auralinux.
h" | 8 #include "content/browser/accessibility/browser_accessibility_manager_auralinux.
h" |
9 #include "content/common/accessibility_messages.h" | 9 #include "content/common/accessibility_messages.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 | 12 |
13 static gpointer browser_accessibility_parent_class = NULL; | 13 static gpointer browser_accessibility_parent_class = NULL; |
14 | 14 |
15 static BrowserAccessibilityAuraLinux* ToBrowserAccessibilityAuraLinux( | 15 static BrowserAccessibilityAuraLinux* ToBrowserAccessibilityAuraLinux( |
16 BrowserAccessibilityAtk* atk_object) { | 16 BrowserAccessibilityAtk* atk_object) { |
17 if (!atk_object) | 17 if (!atk_object) |
18 return NULL; | 18 return NULL; |
19 | 19 |
20 return atk_object->m_object; | 20 return atk_object->m_object; |
21 } | 21 } |
22 | 22 |
23 // | 23 // |
| 24 // AtkAction interface. |
| 25 // |
| 26 |
| 27 static BrowserAccessibilityAuraLinux* ToBrowserAccessibilityAuraLinux( |
| 28 AtkAction* atk_action) { |
| 29 if (!IS_BROWSER_ACCESSIBILITY(atk_action)) |
| 30 return NULL; |
| 31 |
| 32 return ToBrowserAccessibilityAuraLinux(BROWSER_ACCESSIBILITY(atk_action)); |
| 33 } |
| 34 |
| 35 static gboolean browser_accessibility_do_action(AtkAction* atk_action, |
| 36 gint index) { |
| 37 g_return_val_if_fail(ATK_IS_ACTION(atk_action), FALSE); |
| 38 g_return_val_if_fail(!index, FALSE); |
| 39 |
| 40 BrowserAccessibilityAuraLinux* obj = |
| 41 ToBrowserAccessibilityAuraLinux(atk_action); |
| 42 if (!obj) |
| 43 return FALSE; |
| 44 |
| 45 obj->manager()->DoDefaultAction(*obj); |
| 46 |
| 47 return TRUE; |
| 48 } |
| 49 |
| 50 static gint browser_accessibility_get_n_actions(AtkAction* atk_action) { |
| 51 g_return_val_if_fail(ATK_IS_ACTION(atk_action), 0); |
| 52 |
| 53 BrowserAccessibilityAuraLinux* obj = |
| 54 ToBrowserAccessibilityAuraLinux(atk_action); |
| 55 if (!obj) |
| 56 return 0; |
| 57 |
| 58 return 1; |
| 59 } |
| 60 |
| 61 static const gchar* browser_accessibility_get_description(AtkAction* atk_action, |
| 62 gint) { |
| 63 g_return_val_if_fail(ATK_IS_ACTION(atk_action), 0); |
| 64 BrowserAccessibilityAuraLinux* obj = |
| 65 ToBrowserAccessibilityAuraLinux(atk_action); |
| 66 if (!obj) |
| 67 return 0; |
| 68 |
| 69 return 0; |
| 70 } |
| 71 |
| 72 static const gchar* browser_accessibility_get_name(AtkAction* atk_action, |
| 73 gint index) { |
| 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); |
| 78 if (!obj) |
| 79 return 0; |
| 80 |
| 81 return obj->GetStringAttribute(ui::AX_ATTR_ACTION).c_str(); |
| 82 } |
| 83 |
| 84 static const gchar* browser_accessibility_get_keybinding(AtkAction* atk_action, |
| 85 gint index) { |
| 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); |
| 90 if (!obj) |
| 91 return 0; |
| 92 |
| 93 return obj->GetStringAttribute(ui::AX_ATTR_ACCESS_KEY).c_str(); |
| 94 } |
| 95 |
| 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; |
| 102 } |
| 103 |
| 104 static const GInterfaceInfo ActionInfo = { |
| 105 reinterpret_cast<GInterfaceInitFunc>(ActionInterfaceInit), 0, 0}; |
| 106 |
| 107 // |
24 // AtkComponent interface. | 108 // AtkComponent interface. |
25 // | 109 // |
26 | 110 |
27 static BrowserAccessibilityAuraLinux* ToBrowserAccessibilityAuraLinux( | 111 static BrowserAccessibilityAuraLinux* ToBrowserAccessibilityAuraLinux( |
28 AtkComponent* atk_component) { | 112 AtkComponent* atk_component) { |
29 if (!IS_BROWSER_ACCESSIBILITY(atk_component)) | 113 if (!IS_BROWSER_ACCESSIBILITY(atk_component)) |
30 return NULL; | 114 return NULL; |
31 | 115 |
32 return ToBrowserAccessibilityAuraLinux(BROWSER_ACCESSIBILITY(atk_component)); | 116 return ToBrowserAccessibilityAuraLinux(BROWSER_ACCESSIBILITY(atk_component)); |
33 } | 117 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 iface->get_extents = browser_accessibility_get_extents; | 183 iface->get_extents = browser_accessibility_get_extents; |
100 iface->grab_focus = browser_accessibility_grab_focus; | 184 iface->grab_focus = browser_accessibility_grab_focus; |
101 } | 185 } |
102 | 186 |
103 static const GInterfaceInfo ComponentInfo = { | 187 static const GInterfaceInfo ComponentInfo = { |
104 reinterpret_cast<GInterfaceInitFunc>(ComponentInterfaceInit), | 188 reinterpret_cast<GInterfaceInitFunc>(ComponentInterfaceInit), |
105 0, | 189 0, |
106 0}; | 190 0}; |
107 | 191 |
108 // | 192 // |
| 193 // AtkDocument interface. |
| 194 // |
| 195 |
| 196 static BrowserAccessibilityAuraLinux* ToBrowserAccessibilityAuraLinux( |
| 197 AtkDocument* atk_doc) { |
| 198 if (!IS_BROWSER_ACCESSIBILITY(atk_doc)) |
| 199 return NULL; |
| 200 |
| 201 return ToBrowserAccessibilityAuraLinux(BROWSER_ACCESSIBILITY(atk_doc)); |
| 202 } |
| 203 |
| 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(); |
| 215 |
| 216 return 0; |
| 217 } |
| 218 |
| 219 AtkAttributeSet* SetAtkAttributeSet(AtkAttributeSet* attribute_set, |
| 220 const char* name, |
| 221 const char* value) { |
| 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; |
| 228 } |
| 229 |
| 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); |
| 235 if (!obj) |
| 236 return 0; |
| 237 |
| 238 return GetDocumentAttributeValue(obj, attribute); |
| 239 } |
| 240 |
| 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); |
| 245 if (!obj) |
| 246 return 0; |
| 247 |
| 248 AtkAttributeSet* attribute_set = 0; |
| 249 const gchar* doc_attributes[] = {"DocType", "MimeType", "Title", "URI"}; |
| 250 const gchar* value = 0; |
| 251 |
| 252 for (unsigned i = 0; i < G_N_ELEMENTS(doc_attributes); i++) { |
| 253 value = GetDocumentAttributeValue(obj, doc_attributes[i]); |
| 254 if (value) |
| 255 attribute_set = |
| 256 SetAtkAttributeSet(attribute_set, doc_attributes[i], value); |
| 257 } |
| 258 |
| 259 return attribute_set; |
| 260 } |
| 261 |
| 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; |
| 266 } |
| 267 |
| 268 static const GInterfaceInfo DocumentInfo = { |
| 269 reinterpret_cast<GInterfaceInitFunc>(DocumentInterfaceInit), 0, 0}; |
| 270 |
| 271 // |
109 // AtkValue interface. | 272 // AtkValue interface. |
110 // | 273 // |
111 | 274 |
112 static BrowserAccessibilityAuraLinux* ToBrowserAccessibilityAuraLinux( | 275 static BrowserAccessibilityAuraLinux* ToBrowserAccessibilityAuraLinux( |
113 AtkValue* atk_object) { | 276 AtkValue* atk_object) { |
114 if (!IS_BROWSER_ACCESSIBILITY(atk_object)) | 277 if (!IS_BROWSER_ACCESSIBILITY(atk_object)) |
115 return NULL; | 278 return NULL; |
116 | 279 |
117 return ToBrowserAccessibilityAuraLinux(BROWSER_ACCESSIBILITY(atk_object)); | 280 return ToBrowserAccessibilityAuraLinux(BROWSER_ACCESSIBILITY(atk_object)); |
118 } | 281 } |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 ATK_TEXT_INTERFACE, | 567 ATK_TEXT_INTERFACE, |
405 ATK_VALUE_INTERFACE, | 568 ATK_VALUE_INTERFACE, |
406 }; | 569 }; |
407 | 570 |
408 static int GetInterfaceMaskFromObject(BrowserAccessibilityAuraLinux* obj) { | 571 static int GetInterfaceMaskFromObject(BrowserAccessibilityAuraLinux* obj) { |
409 int interface_mask = 0; | 572 int interface_mask = 0; |
410 | 573 |
411 // Component interface is always supported. | 574 // Component interface is always supported. |
412 interface_mask |= 1 << ATK_COMPONENT_INTERFACE; | 575 interface_mask |= 1 << ATK_COMPONENT_INTERFACE; |
413 | 576 |
| 577 // Action interface is basic one. It just relays on executing default action |
| 578 // for each object. |
| 579 interface_mask |= 1 << ATK_ACTION_INTERFACE; |
| 580 |
| 581 // Value Interface |
414 int role = obj->GetRole(); | 582 int role = obj->GetRole(); |
415 if (role == ui::AX_ROLE_PROGRESS_INDICATOR || | 583 if (role == ui::AX_ROLE_PROGRESS_INDICATOR || |
416 role == ui::AX_ROLE_SCROLL_BAR || role == ui::AX_ROLE_SLIDER) { | 584 role == ui::AX_ROLE_SCROLL_BAR || role == ui::AX_ROLE_SLIDER) { |
417 interface_mask |= 1 << ATK_VALUE_INTERFACE; | 585 interface_mask |= 1 << ATK_VALUE_INTERFACE; |
418 } | 586 } |
419 | 587 |
| 588 // Document Interface |
| 589 if (role == ui::AX_ROLE_DOCUMENT || role == ui::AX_ROLE_ROOT_WEB_AREA || |
| 590 role == ui::AX_ROLE_WEB_AREA) |
| 591 interface_mask |= 1 << ATK_DOCUMENT_INTERFACE; |
| 592 |
420 return interface_mask; | 593 return interface_mask; |
421 } | 594 } |
422 | 595 |
423 static GType GetAccessibilityTypeFromObject( | 596 static GType GetAccessibilityTypeFromObject( |
424 BrowserAccessibilityAuraLinux* obj) { | 597 BrowserAccessibilityAuraLinux* obj) { |
425 static const GTypeInfo type_info = { | 598 static const GTypeInfo type_info = { |
426 sizeof(BrowserAccessibilityAtkClass), | 599 sizeof(BrowserAccessibilityAtkClass), |
427 (GBaseInitFunc)0, | 600 (GBaseInitFunc)0, |
428 (GBaseFinalizeFunc)0, | 601 (GBaseFinalizeFunc)0, |
429 (GClassInitFunc)0, | 602 (GClassInitFunc)0, |
430 (GClassFinalizeFunc)0, | 603 (GClassFinalizeFunc)0, |
431 0, /* class data */ | 604 0, /* class data */ |
432 sizeof(BrowserAccessibilityAtk), /* instance size */ | 605 sizeof(BrowserAccessibilityAtk), /* instance size */ |
433 0, /* nb preallocs */ | 606 0, /* nb preallocs */ |
434 (GInstanceInitFunc)0, | 607 (GInstanceInitFunc)0, |
435 0 /* value table */ | 608 0 /* value table */ |
436 }; | 609 }; |
437 | 610 |
438 int interface_mask = GetInterfaceMaskFromObject(obj); | 611 int interface_mask = GetInterfaceMaskFromObject(obj); |
439 const char* atk_type_name = GetUniqueAccessibilityTypeName(interface_mask); | 612 const char* atk_type_name = GetUniqueAccessibilityTypeName(interface_mask); |
440 GType type = g_type_from_name(atk_type_name); | 613 GType type = g_type_from_name(atk_type_name); |
441 if (type) | 614 if (type) |
442 return type; | 615 return type; |
443 | 616 |
444 type = g_type_register_static(BROWSER_ACCESSIBILITY_TYPE, atk_type_name, | 617 type = g_type_register_static(BROWSER_ACCESSIBILITY_TYPE, atk_type_name, |
445 &type_info, GTypeFlags(0)); | 618 &type_info, GTypeFlags(0)); |
| 619 if (interface_mask & (1 << ATK_ACTION_INTERFACE)) |
| 620 g_type_add_interface_static(type, ATK_TYPE_ACTION, &ActionInfo); |
446 if (interface_mask & (1 << ATK_COMPONENT_INTERFACE)) | 621 if (interface_mask & (1 << ATK_COMPONENT_INTERFACE)) |
447 g_type_add_interface_static(type, ATK_TYPE_COMPONENT, &ComponentInfo); | 622 g_type_add_interface_static(type, ATK_TYPE_COMPONENT, &ComponentInfo); |
| 623 if (interface_mask & (1 << ATK_DOCUMENT_INTERFACE)) |
| 624 g_type_add_interface_static(type, ATK_TYPE_DOCUMENT, &DocumentInfo); |
448 if (interface_mask & (1 << ATK_VALUE_INTERFACE)) | 625 if (interface_mask & (1 << ATK_VALUE_INTERFACE)) |
449 g_type_add_interface_static(type, ATK_TYPE_VALUE, &ValueInfo); | 626 g_type_add_interface_static(type, ATK_TYPE_VALUE, &ValueInfo); |
450 | 627 |
451 return type; | 628 return type; |
452 } | 629 } |
453 | 630 |
454 BrowserAccessibilityAtk* browser_accessibility_new( | 631 BrowserAccessibilityAtk* browser_accessibility_new( |
455 BrowserAccessibilityAuraLinux* obj) { | 632 BrowserAccessibilityAuraLinux* obj) { |
456 GType type = GetAccessibilityTypeFromObject(obj); | 633 GType type = GetAccessibilityTypeFromObject(obj); |
457 AtkObject* atk_object = static_cast<AtkObject*>(g_object_new(type, 0)); | 634 AtkObject* atk_object = static_cast<AtkObject*>(g_object_new(type, 0)); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 case ui::AX_ROLE_TREE_ITEM: | 840 case ui::AX_ROLE_TREE_ITEM: |
664 atk_role_ = ATK_ROLE_TREE_ITEM; | 841 atk_role_ = ATK_ROLE_TREE_ITEM; |
665 break; | 842 break; |
666 default: | 843 default: |
667 atk_role_ = ATK_ROLE_UNKNOWN; | 844 atk_role_ = ATK_ROLE_UNKNOWN; |
668 break; | 845 break; |
669 } | 846 } |
670 } | 847 } |
671 | 848 |
672 } // namespace content | 849 } // namespace content |
OLD | NEW |