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

Side by Side Diff: third_party/WebKit/Source/core/dom/AXObject.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
(Empty)
1 // Copyright 2017 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.
4
5 #include "core/dom/AXObject.h"
6
7 #include "core/HTMLElementTypeHelpers.h"
8 #include "core/dom/Element.h"
9 #include "core/dom/Node.h"
10 #include "platform/wtf/HashSet.h"
11 #include "platform/wtf/text/StringHash.h"
12 #include "platform/wtf/text/WTFString.h"
13
14 namespace blink {
15
16 namespace {
17
18 typedef HashSet<String, CaseFoldingHash> ARIAWidgetSet;
19
20 const char* g_aria_widgets[] = {
21 // From http://www.w3.org/TR/wai-aria/roles#widget_roles
22 "alert", "alertdialog", "button", "checkbox", "dialog", "gridcell", "link",
23 "log", "marquee", "menuitem", "menuitemcheckbox", "menuitemradio", "option",
24 "progressbar", "radio", "scrollbar", "slider", "spinbutton", "status",
25 "tab", "tabpanel", "textbox", "timer", "tooltip", "treeitem",
26 // Composite user interface widgets.
27 // This list is also from the w3.org site referenced above.
28 "combobox", "grid", "listbox", "menu", "menubar", "radiogroup", "tablist",
29 "tree", "treegrid"};
30
31 static ARIAWidgetSet* CreateARIARoleWidgetSet() {
32 ARIAWidgetSet* widget_set = new HashSet<String, CaseFoldingHash>();
33 for (size_t i = 0; i < WTF_ARRAY_LENGTH(g_aria_widgets); ++i)
34 widget_set->insert(String(g_aria_widgets[i]));
35 return widget_set;
36 }
37
38 bool IncludesARIAWidgetRole(const String& role) {
39 static const HashSet<String, CaseFoldingHash>* role_set =
40 CreateARIARoleWidgetSet();
41
42 Vector<String> role_vector;
43 role.Split(' ', role_vector);
44 for (const auto& child : role_vector) {
45 if (role_set->Contains(child))
46 return true;
47 }
48 return false;
49 }
50
51 const char* g_aria_interactive_widget_attributes[] = {
52 // These attributes implicitly indicate the given widget is interactive.
53 // From http://www.w3.org/TR/wai-aria/states_and_properties#attrs_widgets
54 "aria-activedescendant", "aria-checked", "aria-controls",
55 "aria-disabled", // If it's disabled, it can be made interactive.
56 "aria-expanded", "aria-haspopup", "aria-multiselectable",
dmazzoni 2017/05/16 04:20:45 Optional, but could you fix this list while you're
sashab 2017/05/22 03:05:16 Done :) Cool trick
57 "aria-pressed", "aria-required", "aria-selected"};
58
59 bool HasInteractiveARIAAttribute(const Element& element) {
60 for (size_t i = 0; i < WTF_ARRAY_LENGTH(g_aria_interactive_widget_attributes);
61 ++i) {
62 const char* attribute = g_aria_interactive_widget_attributes[i];
63 if (element.hasAttribute(attribute)) {
64 return true;
65 }
66 }
67 return false;
68 }
69
70 } // namespace
71
72 bool AXObject::IsInsideFocusableElementOrARIAWidget(const Node& node) {
73 const Node* cur_node = &node;
74 do {
75 if (cur_node->IsElementNode()) {
76 const Element* element = ToElement(cur_node);
77 if (element->IsFocusable())
78 return true;
79 String role = element->getAttribute("role");
80 if (!role.IsEmpty() && IncludesARIAWidgetRole(role))
81 return true;
82 if (HasInteractiveARIAAttribute(*element))
83 return true;
84 }
85 cur_node = cur_node->parentNode();
86 } while (cur_node && !isHTMLBodyElement(node));
87 return false;
88 }
89
90 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/AXObject.h ('k') | third_party/WebKit/Source/core/dom/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698