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

Side by Side 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 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "platform/text/PlatformLocale.h" 42 #include "platform/text/PlatformLocale.h"
43 #include "wtf/StdLibExtras.h" 43 #include "wtf/StdLibExtras.h"
44 #include "wtf/text/WTFString.h" 44 #include "wtf/text/WTFString.h"
45 45
46 using blink::WebLocalizedString; 46 using blink::WebLocalizedString;
47 47
48 namespace blink { 48 namespace blink {
49 49
50 using namespace HTMLNames; 50 using namespace HTMLNames;
51 51
52 namespace {
52 typedef HashMap<String, AccessibilityRole, CaseFoldingHash> ARIARoleMap; 53 typedef HashMap<String, AccessibilityRole, CaseFoldingHash> ARIARoleMap;
53 54
54 struct RoleEntry { 55 struct RoleEntry {
55 String ariaRole; 56 String ariaRole;
56 AccessibilityRole webcoreRole; 57 AccessibilityRole webcoreRole;
57 }; 58 };
58 59
59 static ARIARoleMap* createARIARoleMap() 60 void fillRoles(Vector<RoleEntry>* rolesVector)
60 { 61 {
61 const RoleEntry roles[] = { 62 RoleEntry roles[] = {
62 { "alert", AlertRole }, 63 { "alert", AlertRole },
63 { "alertdialog", AlertDialogRole }, 64 { "alertdialog", AlertDialogRole },
64 { "application", ApplicationRole }, 65 { "application", ApplicationRole },
65 { "article", ArticleRole }, 66 { "article", ArticleRole },
66 { "banner", BannerRole }, 67 { "banner", BannerRole },
67 { "button", ButtonRole }, 68 { "button", ButtonRole },
68 { "checkbox", CheckBoxRole }, 69 { "checkbox", CheckBoxRole },
69 { "complementary", ComplementaryRole }, 70 { "complementary", ComplementaryRole },
70 { "contentinfo", ContentInfoRole }, 71 { "contentinfo", ContentInfoRole },
71 { "dialog", DialogRole }, 72 { "dialog", DialogRole },
72 { "directory", DirectoryRole }, 73 { "directory", DirectoryRole },
73 { "grid", GridRole }, 74 { "grid", GridRole },
74 { "gridcell", CellRole }, 75 { "gridcell", CellRole },
75 { "columnheader", ColumnHeaderRole }, 76 { "columnheader", ColumnHeaderRole },
76 { "combobox", ComboBoxRole }, 77 { "combobox", ComboBoxRole },
77 { "definition", DefinitionRole }, 78 { "definition", DefinitionRole },
78 { "document", DocumentRole }, 79 { "document", DocumentRole },
79 { "rowheader", RowHeaderRole }, 80 { "rowheader", RowHeaderRole },
80 { "form", FormRole }, 81 { "form", FormRole },
81 { "group", GroupRole }, 82 { "group", GroupRole },
82 { "heading", HeadingRole }, 83 { "heading", HeadingRole },
83 { "img", ImageRole }, 84 { "img", ImageRole },
84 { "link", LinkRole }, 85 { "link", LinkRole },
85 { "list", ListRole }, 86 { "list", ListRole },
86 { "listitem", ListItemRole }, 87 { "listitem", ListItemRole },
87 { "listbox", ListBoxRole }, 88 { "listbox", ListBoxRole },
88 { "log", LogRole }, 89 { "log", LogRole },
89 // "option" isn't here because it may map to different roles depending o n the parent element's role
90 { "main", MainRole }, 90 { "main", MainRole },
91 { "marquee", MarqueeRole }, 91 { "marquee", MarqueeRole },
92 { "math", MathRole }, 92 { "math", MathRole },
93 { "menu", MenuRole }, 93 { "menu", MenuRole },
94 { "menubar", MenuBarRole }, 94 { "menubar", MenuBarRole },
95 { "menuitem", MenuItemRole }, 95 { "menuitem", MenuItemRole },
96 { "menuitemcheckbox", MenuItemCheckBoxRole }, 96 { "menuitemcheckbox", MenuItemCheckBoxRole },
97 { "menuitemradio", MenuItemRadioRole }, 97 { "menuitemradio", MenuItemRadioRole },
98 { "note", NoteRole }, 98 { "note", NoteRole },
99 { "navigation", NavigationRole }, 99 { "navigation", NavigationRole },
(...skipping 16 matching lines...) Expand all
116 { "tabpanel", TabPanelRole }, 116 { "tabpanel", TabPanelRole },
117 { "text", StaticTextRole }, 117 { "text", StaticTextRole },
118 { "textbox", TextAreaRole }, 118 { "textbox", TextAreaRole },
119 { "timer", TimerRole }, 119 { "timer", TimerRole },
120 { "toolbar", ToolbarRole }, 120 { "toolbar", ToolbarRole },
121 { "tooltip", UserInterfaceTooltipRole }, 121 { "tooltip", UserInterfaceTooltipRole },
122 { "tree", TreeRole }, 122 { "tree", TreeRole },
123 { "treegrid", TreeGridRole }, 123 { "treegrid", TreeGridRole },
124 { "treeitem", TreeItemRole } 124 { "treeitem", TreeItemRole }
125 }; 125 };
126 size_t numRoles = WTF_ARRAY_LENGTH(roles);
127 rolesVector->resize(numRoles);
128 for (size_t i = 0; i < numRoles; ++i)
129 rolesVector->at(i) = roles[i];
130 }
131
132 static ARIARoleMap* createARIARoleMap()
133 {
126 ARIARoleMap* roleMap = new ARIARoleMap; 134 ARIARoleMap* roleMap = new ARIARoleMap;
127 135
128 for (size_t i = 0; i < WTF_ARRAY_LENGTH(roles); ++i) 136 Vector<RoleEntry> roles;
137 fillRoles(&roles);
138 for (size_t i = 0; i < roles.size(); ++i)
129 roleMap->set(roles[i].ariaRole, roles[i].webcoreRole); 139 roleMap->set(roles[i].ariaRole, roles[i].webcoreRole);
130 return roleMap; 140 return roleMap;
131 } 141 }
132 142
143 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
144 {
145 Vector<AtomicString>* roleNameVector = new Vector<AtomicString>;
146 roleNameVector->resize(NumRoles);
147 for (int i = 0; i < NumRoles; i++)
148 roleNameVector->at(i) = nullAtom;
149
150 Vector<RoleEntry> roles;
151 fillRoles(&roles);
152
153 for (size_t i = 0; i < roles.size(); ++i)
154 (*roleNameVector)[roles[i].webcoreRole] = AtomicString(roles[i].ariaRole );
155
156 return roleNameVector;
157 }
158
159 } // namespace
160
133 AXObject::AXObject(AXObjectCacheImpl* axObjectCache) 161 AXObject::AXObject(AXObjectCacheImpl* axObjectCache)
134 : m_id(0) 162 : m_id(0)
135 , m_haveChildren(false) 163 , m_haveChildren(false)
136 , m_role(UnknownRole) 164 , m_role(UnknownRole)
137 , m_lastKnownIsIgnoredValue(DefaultBehavior) 165 , m_lastKnownIsIgnoredValue(DefaultBehavior)
138 , m_detached(false) 166 , m_detached(false)
139 , m_parent(0) 167 , m_parent(0)
140 , m_lastModificationCount(-1) 168 , m_lastModificationCount(-1)
141 , m_cachedIsIgnored(false) 169 , m_cachedIsIgnored(false)
142 , m_cachedLiveRegionRoot(0) 170 , m_cachedLiveRegionRoot(0)
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 if (ariaPressedIsPresent()) 975 if (ariaPressedIsPresent())
948 return ToggleButtonRole; 976 return ToggleButtonRole;
949 if (ariaHasPopup()) 977 if (ariaHasPopup())
950 return PopUpButtonRole; 978 return PopUpButtonRole;
951 // We don't contemplate RadioButtonRole, as it depends on the input 979 // We don't contemplate RadioButtonRole, as it depends on the input
952 // type. 980 // type.
953 981
954 return ButtonRole; 982 return ButtonRole;
955 } 983 }
956 984
985 const AtomicString& AXObject::roleName(const AccessibilityRole role)
986 {
987 static const Vector<AtomicString>* roleNameVector = createRoleNameVector();
988
989 // TODO(aboxhall): assert with security (maybe)
990 ASSERT(role < roleNameVector->size());
991 return roleNameVector->at(role);
992 }
993
957 } // namespace blink 994 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698