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

Unified Diff: Source/modules/accessibility/AXObject.cpp

Issue 742353004: Implement computedRole and computedName (behind a flag) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Move interfaces on to Element Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: Source/modules/accessibility/AXObject.cpp
diff --git a/Source/modules/accessibility/AXObject.cpp b/Source/modules/accessibility/AXObject.cpp
index d4d99c2affaec06beb3b5ba635a6332c91b0ebb0..afd5c64a815474921c57bcedfdf9cf4bb97405bc 100644
--- a/Source/modules/accessibility/AXObject.cpp
+++ b/Source/modules/accessibility/AXObject.cpp
@@ -49,6 +49,7 @@ namespace blink {
using namespace HTMLNames;
+namespace {
typedef HashMap<String, AccessibilityRole, CaseFoldingHash> ARIARoleMap;
struct RoleEntry {
@@ -56,9 +57,9 @@ struct RoleEntry {
AccessibilityRole webcoreRole;
};
-static ARIARoleMap* createARIARoleMap()
+void fillRoles(Vector<RoleEntry>* rolesVector)
{
- const RoleEntry roles[] = {
+ RoleEntry roles[] = {
{ "alert", AlertRole },
{ "alertdialog", AlertDialogRole },
{ "application", ApplicationRole },
@@ -86,7 +87,6 @@ static ARIARoleMap* createARIARoleMap()
{ "listitem", ListItemRole },
{ "listbox", ListBoxRole },
{ "log", LogRole },
- // "option" isn't here because it may map to different roles depending on the parent element's role
{ "main", MainRole },
{ "marquee", MarqueeRole },
{ "math", MathRole },
@@ -123,13 +123,41 @@ static ARIARoleMap* createARIARoleMap()
{ "treegrid", TreeGridRole },
{ "treeitem", TreeItemRole }
};
+ size_t numRoles = WTF_ARRAY_LENGTH(roles);
+ rolesVector->resize(numRoles);
+ for (size_t i = 0; i < numRoles; ++i)
+ rolesVector->at(i) = roles[i];
+}
+
+static ARIARoleMap* createARIARoleMap()
+{
ARIARoleMap* roleMap = new ARIARoleMap;
- for (size_t i = 0; i < WTF_ARRAY_LENGTH(roles); ++i)
+ Vector<RoleEntry> roles;
+ fillRoles(&roles);
+ for (size_t i = 0; i < roles.size(); ++i)
roleMap->set(roles[i].ariaRole, roles[i].webcoreRole);
return roleMap;
}
+static Vector<AtomicString>* createRoleNameVector()
adamk 2014/12/16 01:54:49 Sorry, I'm having trouble figuring out exactly why
aboxhall 2014/12/16 04:15:26 It's just a map of role enum to name; used on line
adamk 2014/12/16 18:25:15 What about making the array of roles statically sc
aboxhall 2014/12/17 22:21:26 Sorry, I missed this comment. I think what you're
+{
+ Vector<AtomicString>* roleNameVector = new Vector<AtomicString>;
+ roleNameVector->resize(NumRoles);
+ for (int i = 0; i < NumRoles; i++)
+ roleNameVector->at(i) = nullAtom;
+
+ Vector<RoleEntry> roles;
+ fillRoles(&roles);
+
+ for (size_t i = 0; i < roles.size(); ++i)
+ (*roleNameVector)[roles[i].webcoreRole] = AtomicString(roles[i].ariaRole);
+
+ return roleNameVector;
+}
+
+} // namespace
+
AXObject::AXObject(AXObjectCacheImpl* axObjectCache)
: m_id(0)
, m_haveChildren(false)
@@ -954,4 +982,13 @@ AccessibilityRole AXObject::buttonRoleType() const
return ButtonRole;
}
+const AtomicString& AXObject::roleName(const AccessibilityRole role)
+{
+ static const Vector<AtomicString>* roleNameVector = createRoleNameVector();
+
+ // TODO(aboxhall): assert with security (maybe)
+ ASSERT(role < roleNameVector->size());
+ return roleNameVector->at(role);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698