Mercurial > minori
annotate dep/animone/src/a11y/win32.cc @ 340:74e2365326c6
dep/animone: add experimental accessibility strategy
I also moved most of the functions out of util/win32.cc, because that
file is meant for things that are shared between the different functions,
and currently that is only wide string conversion helpers.
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Wed, 19 Jun 2024 23:13:55 -0400 |
parents | |
children | 052ec053ee37 |
rev | line source |
---|---|
340
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
1 #include <functional> |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
2 #include <string> |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
3 #include <vector> |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
4 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
5 #include <windows.h> |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
6 #include <uiautomation.h> |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
7 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
8 #include "animone/a11y.h" |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
9 #include "animone/a11y/win32.h" |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
10 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
11 namespace animone::internal::win32 { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
12 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
13 // Windows Accessibility API reference: |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
14 // https://msdn.microsoft.com/en-us/library/windows/desktop/ff486375.aspx |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
15 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
16 // Commonly used interfaces |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
17 using Element = IUIAutomationElement; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
18 using TreeWalker = IUIAutomationTreeWalker; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
19 using ValuePattern = IUIAutomationValuePattern; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
20 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
21 using element_proc_t = std::function<TreeScope(Element&)>; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
22 using properties_t = std::vector<std::pair<long, bool>>; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
23 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
24 // The main interface that is used throughout this file. Must be initialized |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
25 // before it can be used for the first time. |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
26 static ComInterface<IUIAutomation> ui_automation; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
27 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
28 //////////////////////////////////////////////////////////////////////////////// |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
29 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
30 static bool InitializeUIAutomation() { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
31 if (ui_automation) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
32 return true; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
33 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
34 // COM library must be initialized on the current thread before calling |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
35 // CoCreateInstance. |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
36 ::CoInitialize(nullptr); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
37 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
38 IUIAutomation* ui_automation_interface = nullptr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
39 const auto result = ::CoCreateInstance( |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
40 CLSID_CUIAutomation, nullptr, CLSCTX_INPROC_SERVER, IID_IUIAutomation, |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
41 reinterpret_cast<void**>(&ui_automation_interface)); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
42 ui_automation.reset(ui_automation_interface); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
43 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
44 return SUCCEEDED(result); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
45 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
46 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
47 //////////////////////////////////////////////////////////////////////////////// |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
48 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
49 static Element* GetElementFromHandle(HWND hwnd) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
50 Element* element = nullptr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
51 ui_automation->ElementFromHandle(static_cast<UIA_HWND>(hwnd), &element); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
52 return element; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
53 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
54 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
55 static std::wstring GetElementName(Element& element) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
56 std::wstring element_name; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
57 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
58 BSTR bstr = nullptr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
59 if (SUCCEEDED(element.get_CurrentName(&bstr)) && bstr) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
60 element_name = bstr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
61 ::SysFreeString(bstr); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
62 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
63 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
64 return element_name; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
65 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
66 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
67 static std::wstring GetElementValue(Element& element) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
68 std::wstring element_value; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
69 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
70 ValuePattern* value_pattern_interface = nullptr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
71 element.GetCurrentPatternAs( |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
72 UIA_ValuePatternId, IID_PPV_ARGS(&value_pattern_interface)); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
73 ComInterface<ValuePattern> value_pattern(value_pattern_interface); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
74 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
75 if (value_pattern) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
76 BSTR bstr = nullptr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
77 if (SUCCEEDED(value_pattern->get_CurrentValue(&bstr)) && bstr) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
78 element_value = bstr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
79 ::SysFreeString(bstr); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
80 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
81 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
82 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
83 return element_value; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
84 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
85 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
86 //////////////////////////////////////////////////////////////////////////////// |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
87 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
88 static bool VerifyElementProperties(Element& element, const properties_t& properties) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
89 VARIANT v = {}; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
90 for (const auto& pair : properties) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
91 if (FAILED(element.GetCurrentPropertyValue(pair.first, &v))) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
92 return false; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
93 if (v.boolVal != (pair.second ? VARIANT_TRUE : VARIANT_FALSE)) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
94 return false; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
95 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
96 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
97 return true; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
98 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
99 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
100 static bool IsAddressBarElement(Element& element) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
101 static const properties_t properties = { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
102 {UIA_IsEnabledPropertyId, true}, |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
103 {UIA_IsKeyboardFocusablePropertyId, true}, |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
104 {UIA_IsValuePatternAvailablePropertyId, true}, |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
105 {UIA_ValueIsReadOnlyPropertyId, false}, |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
106 }; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
107 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
108 return VerifyElementProperties(element, properties); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
109 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
110 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
111 static bool IsTabsElement(Element& element) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
112 static const properties_t properties = { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
113 {UIA_ValueIsReadOnlyPropertyId, true}, |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
114 }; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
115 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
116 return VerifyElementProperties(element, properties); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
117 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
118 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
119 //////////////////////////////////////////////////////////////////////////////// |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
120 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
121 static void WalkElements(TreeWalker& tree_walker, Element& parent, TreeScope scope, |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
122 size_t depth, element_proc_t element_proc) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
123 constexpr size_t kMaxTreeDepth = 16; // arbitrary value |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
124 if (depth > kMaxTreeDepth) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
125 return; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
126 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
127 if (scope & TreeScope_Element) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
128 scope = element_proc(parent); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
129 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
130 auto descend = [](TreeScope scope) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
131 return (scope & TreeScope_Children) || (scope & TreeScope_Descendants); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
132 }; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
133 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
134 if (descend(scope)) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
135 Element* first_element = nullptr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
136 tree_walker.GetFirstChildElement(&parent, &first_element); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
137 ComInterface<Element> element(first_element); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
138 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
139 while (element) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
140 scope = element_proc(*element); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
141 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
142 if (descend(scope)) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
143 WalkElements(tree_walker, *element, scope, depth + 1, element_proc); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
144 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
145 Element* next_element = nullptr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
146 tree_walker.GetNextSiblingElement(element.get(), &next_element); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
147 element.reset(next_element); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
148 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
149 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
150 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
151 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
152 static bool FindWebBrowserElements(Element& parent, std::wstring& address, |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
153 std::vector<std::wstring>& tabs) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
154 TreeWalker* tree_walker_interface = nullptr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
155 ui_automation->get_ControlViewWalker(&tree_walker_interface); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
156 ComInterface<TreeWalker> tree_walker(tree_walker_interface); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
157 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
158 if (!tree_walker) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
159 return false; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
160 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
161 auto element_proc = [&](Element& element) -> TreeScope { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
162 CONTROLTYPEID control_type_id = 0; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
163 element.get_CurrentControlType(&control_type_id); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
164 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
165 switch (control_type_id) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
166 default: |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
167 // Are we done? |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
168 if (!address.empty() && !tabs.empty()) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
169 return TreeScope_Element; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
170 // Otherwise continue descending the tree. |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
171 return TreeScope_Descendants; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
172 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
173 case UIA_DocumentControlTypeId: |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
174 case UIA_MenuBarControlTypeId: |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
175 case UIA_TitleBarControlTypeId: |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
176 // We do not need to walk through these nodes. In fact, skipping |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
177 // documents dramatically improves our performance on worst case |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
178 // scenarios. This is the whole reason we are walking the tree rather |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
179 // than using FindFirst and FindAll methods. |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
180 return TreeScope_Element; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
181 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
182 case UIA_EditControlTypeId: |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
183 // Here we assume that the first edit control that fits our properties |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
184 // is the address bar (e.g. "Omnibox" on Chrome, "Awesome Bar" on |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
185 // Firefox). This element is named differently on each web browser |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
186 // (e.g. "Address and search bar" on Chrome, "Search or enter address" |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
187 // on Firefox). This name can change depending on the browser |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
188 // language. However, we are only interested in the element value, |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
189 // which usually gives us the URL of the current page. |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
190 if (address.empty() && IsAddressBarElement(element)) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
191 address = GetElementValue(element); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
192 return TreeScope_Element; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
193 } else { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
194 // Opera has an edit control ("Address field") within another edit |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
195 // control ("Address bar"). |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
196 return TreeScope_Descendants; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
197 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
198 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
199 case UIA_TabControlTypeId: |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
200 if (tabs.empty() && IsTabsElement(element)) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
201 return TreeScope_Children; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
202 return TreeScope_Element; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
203 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
204 case UIA_TabItemControlTypeId: |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
205 tabs.push_back(GetElementName(element)); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
206 return TreeScope_Element; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
207 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
208 }; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
209 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
210 WalkElements(*tree_walker, parent, TreeScope_Subtree, 0, element_proc); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
211 return true; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
212 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
213 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
214 /* ------------------------------------------------------------------------------------ */ |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
215 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
216 bool GetWebBrowserInformation(const Window& window, web_browser_proc_t web_browser_proc) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
217 if (!web_browser_proc) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
218 return false; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
219 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
220 if (!InitializeUIAutomation()) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
221 return false; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
222 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
223 ComInterface<Element> parent(GetElementFromHandle(hwnd)); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
224 if (!parent) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
225 return false; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
226 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
227 const std::string title = ToUtf8String(GetElementName(*parent)); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
228 web_browser_proc({WebBrowserInformationType::Title, title}); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
229 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
230 std::wstring address; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
231 std::vector<std::wstring> tabs; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
232 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
233 if (!FindWebBrowserElements(*parent, address, tabs)) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
234 return false; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
235 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
236 web_browser_proc({WebBrowserInformationType::Address, ToUtf8String(address)}); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
237 for (const auto& tab : tabs) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
238 web_browser_proc({WebBrowserInformationType::Tab, ToUtf8String(tab)}); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
239 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
240 return true; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
241 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
242 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
243 } // namespace animone::internal::win32 |