Chromium Code Reviews| 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, | |
|
dmazzoni
2015/07/27 18:09:04
This function is to return a description of the *a
| |
| 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 obj->GetStringAttribute(ui::AX_ATTR_DESCRIPTION).c_str(); | |
| 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* attributeSet, | |
|
dmazzoni
2015/07/27 18:09:04
nit: attributeSet -> 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 attributeSet = g_slist_prepend(attributeSet, attribute); | |
| 227 return attributeSet; | |
| 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* attributeSet = 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 attributeSet = SetAtkAttributeSet(attributeSet, doc_attributes[i], value); | |
| 256 } | |
| 257 | |
| 258 return attributeSet; | |
| 259 } | |
| 260 | |
| 261 static void DocumentInterfaceInit(AtkDocumentIface* iface) { | |
| 262 iface->get_document_attribute_value = | |
| 263 browser_accessibility_get_attribute_value; | |
| 264 iface->get_document_attributes = browser_accessibility_get_attributes; | |
| 265 } | |
| 266 | |
| 267 static const GInterfaceInfo DocumentInfo = { | |
| 268 reinterpret_cast<GInterfaceInitFunc>(DocumentInterfaceInit), 0, 0}; | |
| 269 | |
| 270 // | |
| 109 // AtkValue interface. | 271 // AtkValue interface. |
| 110 // | 272 // |
| 111 | 273 |
| 112 static BrowserAccessibilityAuraLinux* ToBrowserAccessibilityAuraLinux( | 274 static BrowserAccessibilityAuraLinux* ToBrowserAccessibilityAuraLinux( |
| 113 AtkValue* atk_object) { | 275 AtkValue* atk_object) { |
| 114 if (!IS_BROWSER_ACCESSIBILITY(atk_object)) | 276 if (!IS_BROWSER_ACCESSIBILITY(atk_object)) |
| 115 return NULL; | 277 return NULL; |
| 116 | 278 |
| 117 return ToBrowserAccessibilityAuraLinux(BROWSER_ACCESSIBILITY(atk_object)); | 279 return ToBrowserAccessibilityAuraLinux(BROWSER_ACCESSIBILITY(atk_object)); |
| 118 } | 280 } |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 ATK_TEXT_INTERFACE, | 566 ATK_TEXT_INTERFACE, |
| 405 ATK_VALUE_INTERFACE, | 567 ATK_VALUE_INTERFACE, |
| 406 }; | 568 }; |
| 407 | 569 |
| 408 static int GetInterfaceMaskFromObject(BrowserAccessibilityAuraLinux* obj) { | 570 static int GetInterfaceMaskFromObject(BrowserAccessibilityAuraLinux* obj) { |
| 409 int interface_mask = 0; | 571 int interface_mask = 0; |
| 410 | 572 |
| 411 // Component interface is always supported. | 573 // Component interface is always supported. |
| 412 interface_mask |= 1 << ATK_COMPONENT_INTERFACE; | 574 interface_mask |= 1 << ATK_COMPONENT_INTERFACE; |
| 413 | 575 |
| 576 // Action interface is basic one. It just relays on executing default action | |
| 577 // for each object. | |
| 578 interface_mask |= 1 << ATK_ACTION_INTERFACE; | |
| 579 | |
| 580 // Value Interface | |
| 414 int role = obj->GetRole(); | 581 int role = obj->GetRole(); |
| 415 if (role == ui::AX_ROLE_PROGRESS_INDICATOR || | 582 if (role == ui::AX_ROLE_PROGRESS_INDICATOR || |
| 416 role == ui::AX_ROLE_SCROLL_BAR || role == ui::AX_ROLE_SLIDER) { | 583 role == ui::AX_ROLE_SCROLL_BAR || role == ui::AX_ROLE_SLIDER) { |
| 417 interface_mask |= 1 << ATK_VALUE_INTERFACE; | 584 interface_mask |= 1 << ATK_VALUE_INTERFACE; |
| 418 } | 585 } |
| 419 | 586 |
| 587 // Document Interface | |
| 588 if (role == ui::AX_ROLE_DOCUMENT || role == ui::AX_ROLE_ROOT_WEB_AREA || | |
| 589 role == ui::AX_ROLE_WEB_AREA) | |
| 590 interface_mask |= 1 << ATK_DOCUMENT_INTERFACE; | |
| 591 | |
| 420 return interface_mask; | 592 return interface_mask; |
| 421 } | 593 } |
| 422 | 594 |
| 423 static GType GetAccessibilityTypeFromObject( | 595 static GType GetAccessibilityTypeFromObject( |
| 424 BrowserAccessibilityAuraLinux* obj) { | 596 BrowserAccessibilityAuraLinux* obj) { |
| 425 static const GTypeInfo type_info = { | 597 static const GTypeInfo type_info = { |
| 426 sizeof(BrowserAccessibilityAtkClass), | 598 sizeof(BrowserAccessibilityAtkClass), |
| 427 (GBaseInitFunc)0, | 599 (GBaseInitFunc)0, |
| 428 (GBaseFinalizeFunc)0, | 600 (GBaseFinalizeFunc)0, |
| 429 (GClassInitFunc)0, | 601 (GClassInitFunc)0, |
| 430 (GClassFinalizeFunc)0, | 602 (GClassFinalizeFunc)0, |
| 431 0, /* class data */ | 603 0, /* class data */ |
| 432 sizeof(BrowserAccessibilityAtk), /* instance size */ | 604 sizeof(BrowserAccessibilityAtk), /* instance size */ |
| 433 0, /* nb preallocs */ | 605 0, /* nb preallocs */ |
| 434 (GInstanceInitFunc)0, | 606 (GInstanceInitFunc)0, |
| 435 0 /* value table */ | 607 0 /* value table */ |
| 436 }; | 608 }; |
| 437 | 609 |
| 438 int interface_mask = GetInterfaceMaskFromObject(obj); | 610 int interface_mask = GetInterfaceMaskFromObject(obj); |
| 439 const char* atk_type_name = GetUniqueAccessibilityTypeName(interface_mask); | 611 const char* atk_type_name = GetUniqueAccessibilityTypeName(interface_mask); |
| 440 GType type = g_type_from_name(atk_type_name); | 612 GType type = g_type_from_name(atk_type_name); |
| 441 if (type) | 613 if (type) |
| 442 return type; | 614 return type; |
| 443 | 615 |
| 444 type = g_type_register_static(BROWSER_ACCESSIBILITY_TYPE, atk_type_name, | 616 type = g_type_register_static(BROWSER_ACCESSIBILITY_TYPE, atk_type_name, |
| 445 &type_info, GTypeFlags(0)); | 617 &type_info, GTypeFlags(0)); |
| 618 if (interface_mask & (1 << ATK_ACTION_INTERFACE)) | |
| 619 g_type_add_interface_static(type, ATK_TYPE_ACTION, &ActionInfo); | |
| 446 if (interface_mask & (1 << ATK_COMPONENT_INTERFACE)) | 620 if (interface_mask & (1 << ATK_COMPONENT_INTERFACE)) |
| 447 g_type_add_interface_static(type, ATK_TYPE_COMPONENT, &ComponentInfo); | 621 g_type_add_interface_static(type, ATK_TYPE_COMPONENT, &ComponentInfo); |
| 622 if (interface_mask & (1 << ATK_DOCUMENT_INTERFACE)) | |
| 623 g_type_add_interface_static(type, ATK_TYPE_DOCUMENT, &DocumentInfo); | |
| 448 if (interface_mask & (1 << ATK_VALUE_INTERFACE)) | 624 if (interface_mask & (1 << ATK_VALUE_INTERFACE)) |
| 449 g_type_add_interface_static(type, ATK_TYPE_VALUE, &ValueInfo); | 625 g_type_add_interface_static(type, ATK_TYPE_VALUE, &ValueInfo); |
| 450 | 626 |
| 451 return type; | 627 return type; |
| 452 } | 628 } |
| 453 | 629 |
| 454 BrowserAccessibilityAtk* browser_accessibility_new( | 630 BrowserAccessibilityAtk* browser_accessibility_new( |
| 455 BrowserAccessibilityAuraLinux* obj) { | 631 BrowserAccessibilityAuraLinux* obj) { |
| 456 GType type = GetAccessibilityTypeFromObject(obj); | 632 GType type = GetAccessibilityTypeFromObject(obj); |
| 457 AtkObject* atk_object = static_cast<AtkObject*>(g_object_new(type, 0)); | 633 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: | 839 case ui::AX_ROLE_TREE_ITEM: |
| 664 atk_role_ = ATK_ROLE_TREE_ITEM; | 840 atk_role_ = ATK_ROLE_TREE_ITEM; |
| 665 break; | 841 break; |
| 666 default: | 842 default: |
| 667 atk_role_ = ATK_ROLE_UNKNOWN; | 843 atk_role_ = ATK_ROLE_UNKNOWN; |
| 668 break; | 844 break; |
| 669 } | 845 } |
| 670 } | 846 } |
| 671 | 847 |
| 672 } // namespace content | 848 } // namespace content |
| OLD | NEW |