| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 1546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1900 AccessibilityRole role = kUnknownRole; | 1873 AccessibilityRole role = kUnknownRole; |
| 1901 for (const auto& child : role_vector) { | 1874 for (const auto& child : role_vector) { |
| 1902 role = role_map->at(child); | 1875 role = role_map->at(child); |
| 1903 if (role) | 1876 if (role) |
| 1904 return role; | 1877 return role; |
| 1905 } | 1878 } |
| 1906 | 1879 |
| 1907 return role; | 1880 return role; |
| 1908 } | 1881 } |
| 1909 | 1882 |
| 1910 bool AXObjectImpl::IsInsideFocusableElementOrARIAWidget(const Node& node) { | |
| 1911 const Node* cur_node = &node; | |
| 1912 do { | |
| 1913 if (cur_node->IsElementNode()) { | |
| 1914 const Element* element = ToElement(cur_node); | |
| 1915 if (element->IsFocusable()) | |
| 1916 return true; | |
| 1917 String role = element->getAttribute("role"); | |
| 1918 if (!role.IsEmpty() && AXObjectImpl::IncludesARIAWidgetRole(role)) | |
| 1919 return true; | |
| 1920 if (HasInteractiveARIAAttribute(*element)) | |
| 1921 return true; | |
| 1922 } | |
| 1923 cur_node = cur_node->parentNode(); | |
| 1924 } while (cur_node && !isHTMLBodyElement(node)); | |
| 1925 return false; | |
| 1926 } | |
| 1927 | |
| 1928 bool AXObjectImpl::HasInteractiveARIAAttribute(const Element& element) { | |
| 1929 for (size_t i = 0; i < WTF_ARRAY_LENGTH(g_aria_interactive_widget_attributes); | |
| 1930 ++i) { | |
| 1931 const char* attribute = g_aria_interactive_widget_attributes[i]; | |
| 1932 if (element.hasAttribute(attribute)) { | |
| 1933 return true; | |
| 1934 } | |
| 1935 } | |
| 1936 return false; | |
| 1937 } | |
| 1938 | |
| 1939 bool AXObjectImpl::IncludesARIAWidgetRole(const String& role) { | |
| 1940 static const HashSet<String, CaseFoldingHash>* role_set = | |
| 1941 CreateARIARoleWidgetSet(); | |
| 1942 | |
| 1943 Vector<String> role_vector; | |
| 1944 role.Split(' ', role_vector); | |
| 1945 for (const auto& child : role_vector) { | |
| 1946 if (role_set->Contains(child)) | |
| 1947 return true; | |
| 1948 } | |
| 1949 return false; | |
| 1950 } | |
| 1951 | |
| 1952 bool AXObjectImpl::NameFromContents(bool recursive) const { | 1883 bool AXObjectImpl::NameFromContents(bool recursive) const { |
| 1953 // ARIA 1.1, section 5.2.7.5. | 1884 // ARIA 1.1, section 5.2.7.5. |
| 1954 bool result = false; | 1885 bool result = false; |
| 1955 | 1886 |
| 1956 switch (RoleValue()) { | 1887 switch (RoleValue()) { |
| 1957 // ----- NameFrom: contents ------------------------- | 1888 // ----- NameFrom: contents ------------------------- |
| 1958 // Get their own name from contents, or contribute to ancestors | 1889 // Get their own name from contents, or contribute to ancestors |
| 1959 case kAnchorRole: | 1890 case kAnchorRole: |
| 1960 case kButtonRole: | 1891 case kButtonRole: |
| 1961 case kCellRole: | 1892 case kCellRole: |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2135 } | 2066 } |
| 2136 | 2067 |
| 2137 DEFINE_TRACE(AXObjectImpl) { | 2068 DEFINE_TRACE(AXObjectImpl) { |
| 2138 visitor->Trace(children_); | 2069 visitor->Trace(children_); |
| 2139 visitor->Trace(parent_); | 2070 visitor->Trace(parent_); |
| 2140 visitor->Trace(cached_live_region_root_); | 2071 visitor->Trace(cached_live_region_root_); |
| 2141 visitor->Trace(ax_object_cache_); | 2072 visitor->Trace(ax_object_cache_); |
| 2142 } | 2073 } |
| 2143 | 2074 |
| 2144 } // namespace blink | 2075 } // namespace blink |
| OLD | NEW |