Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / browser / accessibility / accessibility_tree_formatter_utils_win.cc
blob063f5cd759c4100701285a2c418fd8bd4edd1b69
1 // Copyright (c) 2012 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.
5 #include "content/browser/accessibility/accessibility_tree_formatter_utils_win.h"
7 #include <oleacc.h>
9 #include <map>
10 #include <string>
12 #include "base/memory/singleton.h"
13 #include "base/strings/string_util.h"
14 #include "third_party/iaccessible2/ia2_api_all.h"
16 namespace content {
17 namespace {
19 class AccessibilityEnumMap {
20 public:
21 static AccessibilityEnumMap* GetInstance();
23 std::map<int32, base::string16> ia_role_string_map;
24 std::map<int32, base::string16> ia2_role_string_map;
25 std::map<int32, base::string16> ia_state_string_map;
26 std::map<int32, base::string16> ia2_state_string_map;
27 std::map<int32, base::string16> event_string_map;
29 private:
30 AccessibilityEnumMap();
31 virtual ~AccessibilityEnumMap() {}
33 friend struct DefaultSingletonTraits<AccessibilityEnumMap>;
35 DISALLOW_COPY_AND_ASSIGN(AccessibilityEnumMap);
38 // static
39 AccessibilityEnumMap* AccessibilityEnumMap::GetInstance() {
40 return Singleton<AccessibilityEnumMap,
41 LeakySingletonTraits<AccessibilityEnumMap> >::get();
44 AccessibilityEnumMap::AccessibilityEnumMap() {
45 // Convenience macros for generating readable strings.
46 #define IA_ROLE_MAP(x) ia_role_string_map[x] = L###x; \
47 ia2_role_string_map[x] = L###x;
48 #define IA2_ROLE_MAP(x) ia2_role_string_map[x] = L###x;
49 #define IA_STATE_MAP(x) ia_state_string_map[STATE_SYSTEM_##x] = L###x;
50 #define IA2_STATE_MAP(x) ia2_state_string_map[x] = L###x;
51 #define EVENT_MAP(x) event_string_map[x] = L###x;
53 // MSAA / IAccessible roles. Each one of these is also a valid
54 // IAccessible2 role, the IA_ROLE_MAP macro adds it to both.
55 IA_ROLE_MAP(ROLE_SYSTEM_ALERT)
56 IA_ROLE_MAP(ROLE_SYS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
116 IA_ROLE_MAP(ROLE_SYSTEM_TOOLTIP)
117 IA_ROLE_MAP(ROLE_SYSTEM_WHITESPACE)
118 IA_ROLE_MAP(ROLE_SYSTEM_WINDOW)
120 // IAccessible2 roles.
121 IA2_ROLE_MAP(IA2_ROLE_CANVAS)
122 IA2_ROLE_MAP(IA2_ROLE_CAPTION)
123 IA2_ROLE_MAP(IA2_ROLE_CHECK_MENU_ITEM)
124 IA2_ROLE_MAP(IA2_ROLE_COLOR_CHOOSER)
125 IA2_ROLE_MAP(IA2_ROLE_DATE_EDITOR)
126 IA2_ROLE_MAP(IA2_ROLE_DESKTOP_ICON)
127 IA2_ROLE_MAP(IA2_ROLE_DESKTOP_PANE)
128 IA2_ROLE_MAP(IA2_ROLE_DIRECTORY_PANE)
129 IA2_ROLE_MAP(IA2_ROLE_EDITBAR)
130 IA2_ROLE_MAP(IA2_ROLE_EMBEDDED_OBJECT)
131 IA2_ROLE_MAP(IA2_ROLE_ENDNOTE)
132 IA2_ROLE_MAP(IA2_ROLE_FILE_CHOOSER)
133 IA2_ROLE_MAP(IA2_ROLE_FONT_CHOOSER)
134 IA2_ROLE_MAP(IA2_ROLE_FOOTER)
135 IA2_ROLE_MAP(IA2_ROLE_FOOTNOTE)
136 IA2_ROLE_MAP(IA2_ROLE_FORM)
137 IA2_ROLE_MAP(IA2_ROLE_FRAME)
138 IA2_ROLE_MAP(IA2_ROLE_GLASS_PANE)
139 IA2_ROLE_MAP(IA2_ROLE_HEADER)
140 IA2_ROLE_MAP(IA2_ROLE_HEADING)
141 IA2_ROLE_MAP(IA2_ROLE_ICON)
142 IA2_ROLE_MAP(IA2_ROLE_IMAGE_MAP)
143 IA2_ROLE_MAP(IA2_ROLE_INPUT_METHOD_WINDOW)
144 IA2_ROLE_MAP(IA2_ROLE_INTERNAL_FRAME)
145 IA2_ROLE_MAP(IA2_ROLE_LABEL)
146 IA2_ROLE_MAP(IA2_ROLE_LAYERED_PANE)
147 IA2_ROLE_MAP(IA2_ROLE_NOTE)
148 IA2_ROLE_MAP(IA2_ROLE_OPTION_PANE)
149 IA2_ROLE_MAP(IA2_ROLE_PAGE)
150 IA2_ROLE_MAP(IA2_ROLE_PARAGRAPH)
151 IA2_ROLE_MAP(IA2_ROLE_RADIO_MENU_ITEM)
152 IA2_ROLE_MAP(IA2_ROLE_REDUNDANT_OBJECT)
153 IA2_ROLE_MAP(IA2_ROLE_ROOT_PANE)
154 IA2_ROLE_MAP(IA2_ROLE_RULER)
155 IA2_ROLE_MAP(IA2_ROLE_SCROLL_PANE)
156 IA2_ROLE_MAP(IA2_ROLE_SECTION)
157 IA2_ROLE_MAP(IA2_ROLE_SHAPE)
158 IA2_ROLE_MAP(IA2_ROLE_SPLIT_PANE)
159 IA2_ROLE_MAP(IA2_ROLE_TEAR_OFF_MENU)
160 IA2_ROLE_MAP(IA2_ROLE_TERMINAL)
161 IA2_ROLE_MAP(IA2_ROLE_TEXT_FRAME)
162 IA2_ROLE_MAP(IA2_ROLE_TOGGLE_BUTTON)
163 IA2_ROLE_MAP(IA2_ROLE_UNKNOWN)
164 IA2_ROLE_MAP(IA2_ROLE_VIEW_PORT)
166 // MSAA / IAccessible states. Unlike roles, these are not also IA2 states.
167 IA_STATE_MAP(ALERT_HIGH)
168 IA_STATE_MAP(ALERT_LOW)
169 IA_STATE_MAP(ALERT_MEDIUM)
170 IA_STATE_MAP(ANIMATED)
171 IA_STATE_MAP(BUSY)
172 IA_STATE_MAP(CHECKED)
173 IA_STATE_MAP(COLLAPSED)
174 IA_STATE_MAP(DEFAULT)
175 IA_STATE_MAP(EXPANDED)
176 IA_STATE_MAP(EXTSELECTABLE)
177 IA_STATE_MAP(FLOATING)
178 IA_STATE_MAP(FOCUSABLE)
179 IA_STATE_MAP(FOCUSED)
180 IA_STATE_MAP(HASPOPUP)
181 IA_STATE_MAP(HOTTRACKED)
182 IA_STATE_MAP(INVISIBLE)
183 IA_STATE_MAP(LINKED)
184 IA_STATE_MAP(MARQUEED)
185 IA_STATE_MAP(MIXED)
186 IA_STATE_MAP(MOVEABLE)
187 IA_STATE_MAP(MULTISELECTABLE)
188 IA_STATE_MAP(OFFSCREEN)
189 IA_STATE_MAP(PRESSED)
190 IA_STATE_MAP(PROTECTED)
191 IA_STATE_MAP(READONLY)
192 IA_STATE_MAP(SELECTABLE)
193 IA_STATE_MAP(SELECTED)
194 IA_STATE_MAP(SELFVOICING)
195 IA_STATE_MAP(SIZEABLE)
196 IA_STATE_MAP(TRAVERSED)
197 IA_STATE_MAP(UNAVAILABLE)
199 // IAccessible2 states.
200 IA2_STATE_MAP(IA2_STATE_ACTIVE)
201 IA2_STATE_MAP(IA2_STATE_ARMED)
202 IA2_STATE_MAP(IA2_STATE_CHECKABLE)
203 IA2_STATE_MAP(IA2_STATE_DEFUNCT)
204 IA2_STATE_MAP(IA2_STATE_EDITABLE)
205 IA2_STATE_MAP(IA2_STATE_HORIZONTAL)
206 IA2_STATE_MAP(IA2_STATE_ICONIFIED)
207 IA2_STATE_MAP(IA2_STATE_INVALID_ENTRY)
208 IA2_STATE_MAP(IA2_STATE_MANAGES_DESCENDANTS)
209 IA2_STATE_MAP(IA2_STATE_MODAL)
210 IA2_STATE_MAP(IA2_STATE_MULTI_LINE)
211 IA2_STATE_MAP(IA2_STATE_REQUIRED)
212 IA2_STATE_MAP(IA2_STATE_SELECTABLE_TEXT)
213 IA2_STATE_MAP(IA2_STATE_SINGLE_LINE)
214 IA2_STATE_MAP(IA2_STATE_STALE)
215 IA2_STATE_MAP(IA2_STATE_SUPPORTS_AUTOCOMPLETION)
216 IA2_STATE_MAP(IA2_STATE_TRANSIENT)
217 IA2_STATE_MAP(IA2_STATE_VERTICAL)
219 // Untested states include those that would be repeated on nearly every node,
220 // or would vary based on window size.
221 // IA2_STATE_MAP(IA2_STATE_OPAQUE) // Untested.
223 EVENT_MAP(EVENT_OBJECT_CREATE)
224 EVENT_MAP(EVENT_OBJECT_DESTROY)
225 EVENT_MAP(EVENT_OBJECT_SHOW)
226 EVENT_MAP(EVENT_OBJECT_HIDE)
227 EVENT_MAP(EVENT_OBJECT_REORDER)
228 EVENT_MAP(EVENT_OBJECT_FOCUS)
229 EVENT_MAP(EVENT_OBJECT_SELECTION)
230 EVENT_MAP(EVENT_OBJECT_SELECTIONADD)
231 EVENT_MAP(EVENT_OBJECT_SELECTIONREMOVE)
232 EVENT_MAP(EVENT_OBJECT_SELECTIONWITHIN)
233 EVENT_MAP(EVENT_OBJECT_STATECHANGE)
234 EVENT_MAP(EVENT_OBJECT_LOCATIONCHANGE)
235 EVENT_MAP(EVENT_OBJECT_NAMECHANGE)
236 EVENT_MAP(EVENT_OBJECT_DESCRIPTIONCHANGE)
237 EVENT_MAP(EVENT_OBJECT_VALUECHANGE)
238 EVENT_MAP(EVENT_OBJECT_PARENTCHANGE)
239 EVENT_MAP(EVENT_OBJECT_HELPCHANGE)
240 EVENT_MAP(EVENT_OBJECT_DEFACTIONCHANGE)
241 EVENT_MAP(EVENT_OBJECT_ACCELERATORCHANGE)
242 EVENT_MAP(EVENT_OBJECT_INVOKED)
243 EVENT_MAP(EVENT_OBJECT_TEXTSELECTIONCHANGED)
244 EVENT_MAP(EVENT_OBJECT_CONTENTSCROLLED)
245 EVENT_MAP(EVENT_OBJECT_LIVEREGIONCHANGED)
246 EVENT_MAP(EVENT_OBJECT_HOSTEDOBJECTSINVALIDATED)
247 EVENT_MAP(EVENT_OBJECT_DRAGSTART)
248 EVENT_MAP(EVENT_OBJECT_DRAGCANCEL)
249 EVENT_MAP(EVENT_OBJECT_DRAGCOMPLETE)
250 EVENT_MAP(EVENT_OBJECT_DRAGENTER)
251 EVENT_MAP(EVENT_OBJECT_DRAGLEAVE)
252 EVENT_MAP(EVENT_OBJECT_DRAGDROPPED)
253 EVENT_MAP(EVENT_SYSTEM_ALERT)
254 EVENT_MAP(EVENT_SYSTEM_SCROLLINGSTART)
255 EVENT_MAP(EVENT_SYSTEM_SCROLLINGEND)
256 EVENT_MAP(IA2_EVENT_ACTION_CHANGED)
257 EVENT_MAP(IA2_EVENT_ACTIVE_DECENDENT_CHANGED)
258 EVENT_MAP(IA2_EVENT_ACTIVE_DESCENDANT_CHANGED)
259 EVENT_MAP(IA2_EVENT_DOCUMENT_ATTRIBUTE_CHANGED)
260 EVENT_MAP(IA2_EVENT_DOCUMENT_CONTENT_CHANGED)
261 EVENT_MAP(IA2_EVENT_DOCUMENT_LOAD_COMPLETE)
262 EVENT_MAP(IA2_EVENT_DOCUMENT_LOAD_STOPPED)
263 EVENT_MAP(IA2_EVENT_DOCUMENT_RELOAD)
264 EVENT_MAP(IA2_EVENT_HYPERLINK_END_INDEX_CHANGED)
265 EVENT_MAP(IA2_EVENT_HYPERLINK_NUMBER_OF_ANCHORS_CHANGED)
266 EVENT_MAP(IA2_EVENT_HYPERLINK_SELECTED_LINK_CHANGED)
267 EVENT_MAP(IA2_EVENT_HYPERTEXT_LINK_ACTIVATED)
268 EVENT_MAP(IA2_EVENT_HYPERTEXT_LINK_SELECTED)
269 EVENT_MAP(IA2_EVENT_HYPERLINK_START_INDEX_CHANGED)
270 EVENT_MAP(IA2_EVENT_HYPERTEXT_CHANGED)
271 EVENT_MAP(IA2_EVENT_HYPERTEXT_NLINKS_CHANGED)
272 EVENT_MAP(IA2_EVENT_OBJECT_ATTRIBUTE_CHANGED)
273 EVENT_MAP(IA2_EVENT_PAGE_CHANGED)
274 EVENT_MAP(IA2_EVENT_SECTION_CHANGED)
275 EVENT_MAP(IA2_EVENT_TABLE_CAPTION_CHANGED)
276 EVENT_MAP(IA2_EVENT_TABLE_COLUMN_DESCRIPTION_CHANGED)
277 EVENT_MAP(IA2_EVENT_TABLE_COLUMN_HEADER_CHANGED)
278 EVENT_MAP(IA2_EVENT_TABLE_MODEL_CHANGED)
279 EVENT_MAP(IA2_EVENT_TABLE_ROW_DESCRIPTION_CHANGED)
280 EVENT_MAP(IA2_EVENT_TABLE_ROW_HEADER_CHANGED)
281 EVENT_MAP(IA2_EVENT_TABLE_SUMMARY_CHANGED)
282 EVENT_MAP(IA2_EVENT_TEXT_ATTRIBUTE_CHANGED)
283 EVENT_MAP(IA2_EVENT_TEXT_CARET_MOVED)
284 EVENT_MAP(IA2_EVENT_TEXT_CHANGED)
285 EVENT_MAP(IA2_EVENT_TEXT_COLUMN_CHANGED)
286 EVENT_MAP(IA2_EVENT_TEXT_INSERTED)
287 EVENT_MAP(IA2_EVENT_TEXT_REMOVED)
288 EVENT_MAP(IA2_EVENT_TEXT_UPDATED)
289 EVENT_MAP(IA2_EVENT_TEXT_SELECTION_CHANGED)
290 EVENT_MAP(IA2_EVENT_VISIBLE_DATA_CHANGED)
293 } // namespace.
295 base::string16 IAccessibleRoleToString(int32 ia_role) {
296 return AccessibilityEnumMap::GetInstance()->ia_role_string_map[ia_role];
299 base::string16 IAccessible2RoleToString(int32 ia_role) {
300 return AccessibilityEnumMap::GetInstance()->ia2_role_string_map[ia_role];
303 void IAccessibleStateToStringVector(int32 ia_state,
304 std::vector<base::string16>* result) {
305 const std::map<int32, base::string16>& state_string_map =
306 AccessibilityEnumMap::GetInstance()->ia_state_string_map;
307 std::map<int32, base::string16>::const_iterator it;
308 for (it = state_string_map.begin(); it != state_string_map.end(); ++it) {
309 if (it->first & ia_state)
310 result->push_back(it->second);
314 base::string16 IAccessibleStateToString(int32 ia_state) {
315 std::vector<base::string16> strings;
316 IAccessibleStateToStringVector(ia_state, &strings);
317 return JoinString(strings, ',');
320 void IAccessible2StateToStringVector(int32 ia2_state,
321 std::vector<base::string16>* result) {
322 const std::map<int32, base::string16>& state_string_map =
323 AccessibilityEnumMap::GetInstance()->ia2_state_string_map;
324 std::map<int32, base::string16>::const_iterator it;
325 for (it = state_string_map.begin(); it != state_string_map.end(); ++it) {
326 if (it->first & ia2_state)
327 result->push_back(it->second);
331 base::string16 IAccessible2StateToString(int32 ia2_state) {
332 std::vector<base::string16> strings;
333 IAccessible2StateToStringVector(ia2_state, &strings);
334 return JoinString(strings, ',');
337 base::string16 AccessibilityEventToString(int32 event_id) {
338 return AccessibilityEnumMap::GetInstance()->event_string_map[event_id];
341 } // namespace content