Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: third_party/WebKit/Source/modules/accessibility/AXObjectImpl.cpp

Issue 2872133003: Remove dependency of WebNode.cpp on AXObjectImpl (Closed)
Patch Set: Rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2009, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2008, 2009, 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "platform/wtf/text/WTFString.h" 51 #include "platform/wtf/text/WTFString.h"
52 52
53 using blink::WebLocalizedString; 53 using blink::WebLocalizedString;
54 54
55 namespace blink { 55 namespace blink {
56 56
57 using namespace HTMLNames; 57 using namespace HTMLNames;
58 58
59 namespace { 59 namespace {
60 typedef HashMap<String, AccessibilityRole, CaseFoldingHash> ARIARoleMap; 60 typedef HashMap<String, AccessibilityRole, CaseFoldingHash> ARIARoleMap;
61 typedef HashSet<String, CaseFoldingHash> ARIAWidgetSet;
62 61
63 struct RoleEntry { 62 struct RoleEntry {
64 const char* aria_role; 63 const char* aria_role;
65 AccessibilityRole webcore_role; 64 AccessibilityRole webcore_role;
66 }; 65 };
67 66
68 const RoleEntry kRoles[] = {{"alert", kAlertRole}, 67 const RoleEntry kRoles[] = {{"alert", kAlertRole},
69 {"alertdialog", kAlertDialogRole}, 68 {"alertdialog", kAlertDialogRole},
70 {"application", kApplicationRole}, 69 {"application", kApplicationRole},
71 {"article", kArticleRole}, 70 {"article", kArticleRole},
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 Vector<AtomicString>* internal_role_name_vector = 307 Vector<AtomicString>* internal_role_name_vector =
309 new Vector<AtomicString>(kNumRoles); 308 new Vector<AtomicString>(kNumRoles);
310 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kInternalRoles); i++) { 309 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kInternalRoles); i++) {
311 (*internal_role_name_vector)[kInternalRoles[i].webcore_role] = 310 (*internal_role_name_vector)[kInternalRoles[i].webcore_role] =
312 AtomicString(kInternalRoles[i].internal_role_name); 311 AtomicString(kInternalRoles[i].internal_role_name);
313 } 312 }
314 313
315 return internal_role_name_vector; 314 return internal_role_name_vector;
316 } 315 }
317 316
318 const char* g_aria_widgets[] = {
319 // From http://www.w3.org/TR/wai-aria/roles#widget_roles
320 "alert", "alertdialog", "button", "checkbox", "dialog", "gridcell", "link",
321 "log", "marquee", "menuitem", "menuitemcheckbox", "menuitemradio", "option",
322 "progressbar", "radio", "scrollbar", "slider", "spinbutton", "status",
323 "tab", "tabpanel", "textbox", "timer", "tooltip", "treeitem",
324 // Composite user interface widgets.
325 // This list is also from the w3.org site referenced above.
326 "combobox", "grid", "listbox", "menu", "menubar", "radiogroup", "tablist",
327 "tree", "treegrid"};
328
329 static ARIAWidgetSet* CreateARIARoleWidgetSet() {
330 ARIAWidgetSet* widget_set = new HashSet<String, CaseFoldingHash>();
331 for (size_t i = 0; i < WTF_ARRAY_LENGTH(g_aria_widgets); ++i)
332 widget_set->insert(String(g_aria_widgets[i]));
333 return widget_set;
334 }
335
336 const char* g_aria_interactive_widget_attributes[] = {
337 // These attributes implicitly indicate the given widget is interactive.
338 // From http://www.w3.org/TR/wai-aria/states_and_properties#attrs_widgets
339 "aria-activedescendant", "aria-checked", "aria-controls",
340 "aria-disabled", // If it's disabled, it can be made interactive.
341 "aria-expanded", "aria-haspopup", "aria-multiselectable",
342 "aria-pressed", "aria-required", "aria-selected"};
343
344 HTMLDialogElement* GetActiveDialogElement(Node* node) { 317 HTMLDialogElement* GetActiveDialogElement(Node* node) {
345 return node->GetDocument().ActiveModalDialog(); 318 return node->GetDocument().ActiveModalDialog();
346 } 319 }
347 320
348 } // namespace 321 } // namespace
349 322
350 unsigned AXObjectImpl::number_of_live_ax_objects_ = 0; 323 unsigned AXObjectImpl::number_of_live_ax_objects_ = 0;
351 324
352 AXObjectImpl::AXObjectImpl(AXObjectCacheImpl& ax_object_cache) 325 AXObjectImpl::AXObjectImpl(AXObjectCacheImpl& ax_object_cache)
353 : id_(0), 326 : id_(0),
(...skipping 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 AccessibilityRole role = kUnknownRole; 1727 AccessibilityRole role = kUnknownRole;
1755 for (const auto& child : role_vector) { 1728 for (const auto& child : role_vector) {
1756 role = role_map->at(child); 1729 role = role_map->at(child);
1757 if (role) 1730 if (role)
1758 return role; 1731 return role;
1759 } 1732 }
1760 1733
1761 return role; 1734 return role;
1762 } 1735 }
1763 1736
1764 bool AXObjectImpl::IsInsideFocusableElementOrARIAWidget(const Node& node) {
1765 const Node* cur_node = &node;
1766 do {
1767 if (cur_node->IsElementNode()) {
1768 const Element* element = ToElement(cur_node);
1769 if (element->IsFocusable())
1770 return true;
1771 String role = element->getAttribute("role");
1772 if (!role.IsEmpty() && AXObjectImpl::IncludesARIAWidgetRole(role))
1773 return true;
1774 if (HasInteractiveARIAAttribute(*element))
1775 return true;
1776 }
1777 cur_node = cur_node->parentNode();
1778 } while (cur_node && !isHTMLBodyElement(node));
1779 return false;
1780 }
1781
1782 bool AXObjectImpl::HasInteractiveARIAAttribute(const Element& element) {
1783 for (size_t i = 0; i < WTF_ARRAY_LENGTH(g_aria_interactive_widget_attributes);
1784 ++i) {
1785 const char* attribute = g_aria_interactive_widget_attributes[i];
1786 if (element.hasAttribute(attribute)) {
1787 return true;
1788 }
1789 }
1790 return false;
1791 }
1792
1793 bool AXObjectImpl::IncludesARIAWidgetRole(const String& role) {
1794 static const HashSet<String, CaseFoldingHash>* role_set =
1795 CreateARIARoleWidgetSet();
1796
1797 Vector<String> role_vector;
1798 role.Split(' ', role_vector);
1799 for (const auto& child : role_vector) {
1800 if (role_set->Contains(child))
1801 return true;
1802 }
1803 return false;
1804 }
1805
1806 bool AXObjectImpl::NameFromContents() const { 1737 bool AXObjectImpl::NameFromContents() const {
1807 // ARIA 1.1, section 5.2.7.5. 1738 // ARIA 1.1, section 5.2.7.5.
1808 switch (RoleValue()) { 1739 switch (RoleValue()) {
1809 case kAnchorRole: 1740 case kAnchorRole:
1810 case kButtonRole: 1741 case kButtonRole:
1811 case kCellRole: 1742 case kCellRole:
1812 case kCheckBoxRole: 1743 case kCheckBoxRole:
1813 case kColumnHeaderRole: 1744 case kColumnHeaderRole:
1814 case kDirectoryRole: 1745 case kDirectoryRole:
1815 case kDisclosureTriangleRole: 1746 case kDisclosureTriangleRole:
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 } 1806 }
1876 1807
1877 DEFINE_TRACE(AXObjectImpl) { 1808 DEFINE_TRACE(AXObjectImpl) {
1878 visitor->Trace(children_); 1809 visitor->Trace(children_);
1879 visitor->Trace(parent_); 1810 visitor->Trace(parent_);
1880 visitor->Trace(cached_live_region_root_); 1811 visitor->Trace(cached_live_region_root_);
1881 visitor->Trace(ax_object_cache_); 1812 visitor->Trace(ax_object_cache_);
1882 } 1813 }
1883 1814
1884 } // namespace blink 1815 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698