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

Side by Side Diff: Source/modules/accessibility/AXObject.cpp

Issue 885163002: [Contextual Search] Check for ARIA widget roles. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « Source/modules/accessibility/AXObject.h ('k') | Source/web/WebAXObject.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 22 matching lines...) Expand all
33 #include "core/editing/VisibleUnits.h" 33 #include "core/editing/VisibleUnits.h"
34 #include "core/editing/htmlediting.h" 34 #include "core/editing/htmlediting.h"
35 #include "core/frame/LocalFrame.h" 35 #include "core/frame/LocalFrame.h"
36 #include "core/frame/Settings.h" 36 #include "core/frame/Settings.h"
37 #include "core/layout/LayoutTheme.h" 37 #include "core/layout/LayoutTheme.h"
38 #include "core/rendering/RenderListItem.h" 38 #include "core/rendering/RenderListItem.h"
39 #include "core/rendering/RenderView.h" 39 #include "core/rendering/RenderView.h"
40 #include "modules/accessibility/AXObjectCacheImpl.h" 40 #include "modules/accessibility/AXObjectCacheImpl.h"
41 #include "platform/UserGestureIndicator.h" 41 #include "platform/UserGestureIndicator.h"
42 #include "platform/text/PlatformLocale.h" 42 #include "platform/text/PlatformLocale.h"
43 #include "wtf/HashSet.h"
43 #include "wtf/StdLibExtras.h" 44 #include "wtf/StdLibExtras.h"
44 #include "wtf/text/WTFString.h" 45 #include "wtf/text/WTFString.h"
45 46
46 using blink::WebLocalizedString; 47 using blink::WebLocalizedString;
47 48
48 namespace blink { 49 namespace blink {
49 50
50 using namespace HTMLNames; 51 using namespace HTMLNames;
51 52
52 namespace { 53 namespace {
53 typedef HashMap<String, AccessibilityRole, CaseFoldingHash> ARIARoleMap; 54 typedef HashMap<String, AccessibilityRole, CaseFoldingHash> ARIARoleMap;
55 typedef HashSet<String, CaseFoldingHash> ARIAWidgetSet;
54 56
55 struct RoleEntry { 57 struct RoleEntry {
56 const char* ariaRole; 58 const char* ariaRole;
57 AccessibilityRole webcoreRole; 59 AccessibilityRole webcoreRole;
58 }; 60 };
59 61
60 const RoleEntry roles[] = { 62 const RoleEntry roles[] = {
61 { "alert", AlertRole }, 63 { "alert", AlertRole },
62 { "alertdialog", AlertDialogRole }, 64 { "alertdialog", AlertDialogRole },
63 { "application", ApplicationRole }, 65 { "application", ApplicationRole },
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 Vector<AtomicString>* roleNameVector = new Vector<AtomicString>(NumRoles); 138 Vector<AtomicString>* roleNameVector = new Vector<AtomicString>(NumRoles);
137 for (int i = 0; i < NumRoles; i++) 139 for (int i = 0; i < NumRoles; i++)
138 (*roleNameVector)[i] = nullAtom; 140 (*roleNameVector)[i] = nullAtom;
139 141
140 for (size_t i = 0; i < WTF_ARRAY_LENGTH(roles); ++i) 142 for (size_t i = 0; i < WTF_ARRAY_LENGTH(roles); ++i)
141 (*roleNameVector)[roles[i].webcoreRole] = AtomicString(roles[i].ariaRole ); 143 (*roleNameVector)[roles[i].webcoreRole] = AtomicString(roles[i].ariaRole );
142 144
143 return roleNameVector; 145 return roleNameVector;
144 } 146 }
145 147
148 /* FIXME -- seems like this would be a more natural way to list the roles,
149 but this generates a "needs global destructor" error.
dmazzoni 2015/01/30 07:30:41 Did you try const char* instead of String?
Donn Denman 2015/02/02 19:31:14 That worked, thanks -- don't know why I didn't thi
150 const String ariaWidgets[] = {
151 // From http://www.w3.org/TR/wai-aria/roles#widget_roles
152 "alert",
153 "alertdialog",
154 "button",
155 "checkbox",
156 "dialog",
157 "gridcell",
158 "link",
159 "log",
160 "marquee",
161 "menuitem",
162 "menuitemcheckbox",
163 "menuitemradio",
164 "option",
165 "progressbar",
166 "radio",
167 "scrollbar",
168 "slider",
169 "spinbutton",
170 "status",
171 "tab",
172 "tabpanel",
173 "textbox",
174 "timer",
175 "tooltip",
176 "treeitem",
177 //The following roles act as composite user interface widgets. These roles typically act as containers that manage other, contained widgets.
178 "combobox",
179 "grid",
180 "listbox",
181 "menu",
182 "menubar",
183 "radiogroup",
184 "tablist",
185 "tree",
186 "treegrid"
187 };
188 */
189
190 static ARIAWidgetSet* createARIARoleWidgetSet()
191 {
192 ARIAWidgetSet* widgetSet = new HashSet<String, CaseFoldingHash>();
193
194 // From http://www.w3.org/TR/wai-aria/roles#widget_roles
195 widgetSet->add("alert");
196 widgetSet->add("alertdialog");
197 widgetSet->add("button");
198 widgetSet->add("checkbox");
199 widgetSet->add("dialog");
200 widgetSet->add("gridcell");
201 widgetSet->add("link");
202 widgetSet->add("log");
203 widgetSet->add("marquee");
204 widgetSet->add("menuitem");
205 widgetSet->add("menuitemcheckbox");
206 widgetSet->add("menuitemradio");
207 widgetSet->add("option");
208 widgetSet->add("progressbar");
209 widgetSet->add("radio");
210 widgetSet->add("scrollbar");
211 widgetSet->add("slider");
212 widgetSet->add("spinbutton");
213 widgetSet->add("status");
214 widgetSet->add("tab");
215 widgetSet->add("tabpanel");
216 widgetSet->add("textbox");
217 widgetSet->add("timer");
218 widgetSet->add("tooltip");
219 widgetSet->add("treeitem");
220 // The following roles act as composite user interface widgets. These roles typically act as containers that manage other, contained widgets.
221 widgetSet->add("combobox");
222 widgetSet->add("grid");
223 widgetSet->add("menu");
224 widgetSet->add("menubar");
225 widgetSet->add("radiogroup");
226 widgetSet->add("tablist");
227 widgetSet->add("tree");
228 widgetSet->add("treegrid");
229
230 return widgetSet;
231 }
232
146 } // namespace 233 } // namespace
147 234
148 AXObject::AXObject(AXObjectCacheImpl* axObjectCache) 235 AXObject::AXObject(AXObjectCacheImpl* axObjectCache)
149 : m_id(0) 236 : m_id(0)
150 , m_haveChildren(false) 237 , m_haveChildren(false)
151 , m_role(UnknownRole) 238 , m_role(UnknownRole)
152 , m_lastKnownIsIgnoredValue(DefaultBehavior) 239 , m_lastKnownIsIgnoredValue(DefaultBehavior)
153 , m_detached(false) 240 , m_detached(false)
154 , m_parent(0) 241 , m_parent(0)
155 , m_lastModificationCount(-1) 242 , m_lastModificationCount(-1)
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 for (unsigned i = 0; i < size; ++i) { 1036 for (unsigned i = 0; i < size; ++i) {
950 String roleName = roleVector[i]; 1037 String roleName = roleVector[i];
951 role = roleMap->get(roleName); 1038 role = roleMap->get(roleName);
952 if (role) 1039 if (role)
953 return role; 1040 return role;
954 } 1041 }
955 1042
956 return role; 1043 return role;
957 } 1044 }
958 1045
1046 bool AXObject::includesARIAWidgetRole(const String& role)
1047 {
1048 static const HashSet<String, CaseFoldingHash>* roleSet = createARIARoleWidge tSet();
1049
1050 Vector<String> roleVector;
1051 role.split(' ', roleVector);
1052 unsigned size = roleVector.size();
1053 for (unsigned i = 0; i < size; ++i) {
1054 String roleName = roleVector[i];
1055 if (roleSet->contains(roleName))
1056 return true;
1057 }
1058
1059 return false;
1060 }
1061
959 AccessibilityRole AXObject::buttonRoleType() const 1062 AccessibilityRole AXObject::buttonRoleType() const
960 { 1063 {
961 // If aria-pressed is present, then it should be exposed as a toggle button. 1064 // If aria-pressed is present, then it should be exposed as a toggle button.
962 // http://www.w3.org/TR/wai-aria/states_and_properties#aria-pressed 1065 // http://www.w3.org/TR/wai-aria/states_and_properties#aria-pressed
963 if (ariaPressedIsPresent()) 1066 if (ariaPressedIsPresent())
964 return ToggleButtonRole; 1067 return ToggleButtonRole;
965 if (ariaHasPopup()) 1068 if (ariaHasPopup())
966 return PopUpButtonRole; 1069 return PopUpButtonRole;
967 // We don't contemplate RadioButtonRole, as it depends on the input 1070 // We don't contemplate RadioButtonRole, as it depends on the input
968 // type. 1071 // type.
969 1072
970 return ButtonRole; 1073 return ButtonRole;
971 } 1074 }
972 1075
973 const AtomicString& AXObject::roleName(AccessibilityRole role) 1076 const AtomicString& AXObject::roleName(AccessibilityRole role)
974 { 1077 {
975 static const Vector<AtomicString>* roleNameVector = createRoleNameVector(); 1078 static const Vector<AtomicString>* roleNameVector = createRoleNameVector();
976 1079
977 return roleNameVector->at(role); 1080 return roleNameVector->at(role);
978 } 1081 }
979 1082
980 } // namespace blink 1083 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/accessibility/AXObject.h ('k') | Source/web/WebAXObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698