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