Mercurial > minori
annotate dep/animone/src/a11y/win32.cc @ 345:d085c05247bd
build: fix windows build
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Thu, 20 Jun 2024 07:39:01 -0400 |
parents | 1faa72660932 |
children | 886f66775f31 |
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> |
342
adb79bdde329
dep/animone: fix tons of issues
Paper <paper@paper.us.eu.org>
parents:
341
diff
changeset
|
4 #include <memory> |
340
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
5 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
6 #include <windows.h> |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
7 #include <uiautomation.h> |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
8 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
9 #include "animone/a11y.h" |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
10 #include "animone/a11y/win32.h" |
342
adb79bdde329
dep/animone: fix tons of issues
Paper <paper@paper.us.eu.org>
parents:
341
diff
changeset
|
11 #include "animone/util/win32.h" |
340
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
12 |
343
1faa72660932
*: transfer back to cmake from autotools
Paper <paper@paper.us.eu.org>
parents:
342
diff
changeset
|
13 /* need to define these separately because libtool is dysfunctional */ |
1faa72660932
*: transfer back to cmake from autotools
Paper <paper@paper.us.eu.org>
parents:
342
diff
changeset
|
14 #include <initguid.h> |
1faa72660932
*: transfer back to cmake from autotools
Paper <paper@paper.us.eu.org>
parents:
342
diff
changeset
|
15 |
1faa72660932
*: transfer back to cmake from autotools
Paper <paper@paper.us.eu.org>
parents:
342
diff
changeset
|
16 DEFINE_GUID(IID_IUIAutomation, 0x30cbe57d,0xd9d0,0x452a,0xab,0x13,0x7a,0xc5,0xac,0x48,0x25,0xee); |
1faa72660932
*: transfer back to cmake from autotools
Paper <paper@paper.us.eu.org>
parents:
342
diff
changeset
|
17 DEFINE_GUID(CLSID_CUIAutomation, 0xff48dba4,0x60ef,0x4201,0xaa,0x87,0x54,0x10,0x3e,0xef,0x59,0x4e); |
1faa72660932
*: transfer back to cmake from autotools
Paper <paper@paper.us.eu.org>
parents:
342
diff
changeset
|
18 |
340
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
19 namespace animone::internal::win32 { |
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 // Windows Accessibility API reference: |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
22 // 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
|
23 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
24 // Commonly used interfaces |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
25 using Element = IUIAutomationElement; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
26 using TreeWalker = IUIAutomationTreeWalker; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
27 using ValuePattern = IUIAutomationValuePattern; |
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 using element_proc_t = std::function<TreeScope(Element&)>; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
30 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
|
31 |
341
052ec053ee37
dep/animone: a11y/win32: fix missing ComInterface definition
Paper <paper@paper.us.eu.org>
parents:
340
diff
changeset
|
32 /* ------------------------------------------------------------------- */ |
052ec053ee37
dep/animone: a11y/win32: fix missing ComInterface definition
Paper <paper@paper.us.eu.org>
parents:
340
diff
changeset
|
33 |
052ec053ee37
dep/animone: a11y/win32: fix missing ComInterface definition
Paper <paper@paper.us.eu.org>
parents:
340
diff
changeset
|
34 template <typename T> |
052ec053ee37
dep/animone: a11y/win32: fix missing ComInterface definition
Paper <paper@paper.us.eu.org>
parents:
340
diff
changeset
|
35 struct ComInterfaceDeleter { |
342
adb79bdde329
dep/animone: fix tons of issues
Paper <paper@paper.us.eu.org>
parents:
341
diff
changeset
|
36 static_assert(std::is_base_of<IUnknown, T>::value, "Invalid COM interface"); |
adb79bdde329
dep/animone: fix tons of issues
Paper <paper@paper.us.eu.org>
parents:
341
diff
changeset
|
37 using pointer = T*; |
adb79bdde329
dep/animone: fix tons of issues
Paper <paper@paper.us.eu.org>
parents:
341
diff
changeset
|
38 void operator()(pointer p) const { if (p) p->Release(); } |
341
052ec053ee37
dep/animone: a11y/win32: fix missing ComInterface definition
Paper <paper@paper.us.eu.org>
parents:
340
diff
changeset
|
39 }; |
052ec053ee37
dep/animone: a11y/win32: fix missing ComInterface definition
Paper <paper@paper.us.eu.org>
parents:
340
diff
changeset
|
40 |
052ec053ee37
dep/animone: a11y/win32: fix missing ComInterface definition
Paper <paper@paper.us.eu.org>
parents:
340
diff
changeset
|
41 template <typename T> |
052ec053ee37
dep/animone: a11y/win32: fix missing ComInterface definition
Paper <paper@paper.us.eu.org>
parents:
340
diff
changeset
|
42 using ComInterface = std::unique_ptr<T, ComInterfaceDeleter<T>>; |
052ec053ee37
dep/animone: a11y/win32: fix missing ComInterface definition
Paper <paper@paper.us.eu.org>
parents:
340
diff
changeset
|
43 |
052ec053ee37
dep/animone: a11y/win32: fix missing ComInterface definition
Paper <paper@paper.us.eu.org>
parents:
340
diff
changeset
|
44 /* ------------------------------------------------------------------- */ |
052ec053ee37
dep/animone: a11y/win32: fix missing ComInterface definition
Paper <paper@paper.us.eu.org>
parents:
340
diff
changeset
|
45 |
340
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
46 // 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
|
47 // 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
|
48 static ComInterface<IUIAutomation> ui_automation; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
49 |
341
052ec053ee37
dep/animone: a11y/win32: fix missing ComInterface definition
Paper <paper@paper.us.eu.org>
parents:
340
diff
changeset
|
50 /* ------------------------------------------------------------------- */ |
340
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
51 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
52 static bool InitializeUIAutomation() { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
53 if (ui_automation) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
54 return true; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
55 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
56 // 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
|
57 // CoCreateInstance. |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
58 ::CoInitialize(nullptr); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
59 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
60 IUIAutomation* ui_automation_interface = nullptr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
61 const auto result = ::CoCreateInstance( |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
62 CLSID_CUIAutomation, nullptr, CLSCTX_INPROC_SERVER, IID_IUIAutomation, |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
63 reinterpret_cast<void**>(&ui_automation_interface)); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
64 ui_automation.reset(ui_automation_interface); |
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 return SUCCEEDED(result); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
67 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
68 |
341
052ec053ee37
dep/animone: a11y/win32: fix missing ComInterface definition
Paper <paper@paper.us.eu.org>
parents:
340
diff
changeset
|
69 /* ------------------------------------------------------------------- */ |
340
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
70 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
71 static Element* GetElementFromHandle(HWND hwnd) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
72 Element* element = nullptr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
73 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
|
74 return element; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
75 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
76 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
77 static std::wstring GetElementName(Element& element) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
78 std::wstring element_name; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
79 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
80 BSTR bstr = nullptr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
81 if (SUCCEEDED(element.get_CurrentName(&bstr)) && bstr) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
82 element_name = bstr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
83 ::SysFreeString(bstr); |
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 return element_name; |
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 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
89 static std::wstring GetElementValue(Element& element) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
90 std::wstring element_value; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
91 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
92 ValuePattern* value_pattern_interface = nullptr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
93 element.GetCurrentPatternAs( |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
94 UIA_ValuePatternId, IID_PPV_ARGS(&value_pattern_interface)); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
95 ComInterface<ValuePattern> value_pattern(value_pattern_interface); |
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 if (value_pattern) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
98 BSTR bstr = nullptr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
99 if (SUCCEEDED(value_pattern->get_CurrentValue(&bstr)) && bstr) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
100 element_value = bstr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
101 ::SysFreeString(bstr); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
102 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
103 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
104 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
105 return element_value; |
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 |
341
052ec053ee37
dep/animone: a11y/win32: fix missing ComInterface definition
Paper <paper@paper.us.eu.org>
parents:
340
diff
changeset
|
108 /* ------------------------------------------------------------------- */ |
340
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 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
|
111 VARIANT v = {}; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
112 for (const auto& pair : properties) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
113 if (FAILED(element.GetCurrentPropertyValue(pair.first, &v))) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
114 return false; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
115 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
|
116 return false; |
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 return true; |
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 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
122 static bool IsAddressBarElement(Element& element) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
123 static const properties_t properties = { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
124 {UIA_IsEnabledPropertyId, true}, |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
125 {UIA_IsKeyboardFocusablePropertyId, true}, |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
126 {UIA_IsValuePatternAvailablePropertyId, true}, |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
127 {UIA_ValueIsReadOnlyPropertyId, false}, |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
128 }; |
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 return VerifyElementProperties(element, properties); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
131 } |
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 static bool IsTabsElement(Element& element) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
134 static const properties_t properties = { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
135 {UIA_ValueIsReadOnlyPropertyId, true}, |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
136 }; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
137 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
138 return VerifyElementProperties(element, properties); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
139 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
140 |
341
052ec053ee37
dep/animone: a11y/win32: fix missing ComInterface definition
Paper <paper@paper.us.eu.org>
parents:
340
diff
changeset
|
141 /* ------------------------------------------------------------------- */ |
340
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
142 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
143 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
|
144 size_t depth, element_proc_t element_proc) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
145 constexpr size_t kMaxTreeDepth = 16; // arbitrary value |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
146 if (depth > kMaxTreeDepth) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
147 return; |
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 if (scope & TreeScope_Element) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
150 scope = element_proc(parent); |
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 auto descend = [](TreeScope scope) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
153 return (scope & TreeScope_Children) || (scope & TreeScope_Descendants); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
154 }; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
155 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
156 if (descend(scope)) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
157 Element* first_element = nullptr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
158 tree_walker.GetFirstChildElement(&parent, &first_element); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
159 ComInterface<Element> element(first_element); |
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 while (element) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
162 scope = element_proc(*element); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
163 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
164 if (descend(scope)) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
165 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
|
166 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
167 Element* next_element = nullptr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
168 tree_walker.GetNextSiblingElement(element.get(), &next_element); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
169 element.reset(next_element); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
170 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
171 } |
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 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
174 static bool FindWebBrowserElements(Element& parent, std::wstring& address, |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
175 std::vector<std::wstring>& tabs) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
176 TreeWalker* tree_walker_interface = nullptr; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
177 ui_automation->get_ControlViewWalker(&tree_walker_interface); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
178 ComInterface<TreeWalker> tree_walker(tree_walker_interface); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
179 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
180 if (!tree_walker) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
181 return false; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
182 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
183 auto element_proc = [&](Element& element) -> TreeScope { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
184 CONTROLTYPEID control_type_id = 0; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
185 element.get_CurrentControlType(&control_type_id); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
186 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
187 switch (control_type_id) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
188 default: |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
189 // Are we done? |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
190 if (!address.empty() && !tabs.empty()) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
191 return TreeScope_Element; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
192 // Otherwise continue descending the tree. |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
193 return TreeScope_Descendants; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
194 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
195 case UIA_DocumentControlTypeId: |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
196 case UIA_MenuBarControlTypeId: |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
197 case UIA_TitleBarControlTypeId: |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
198 // 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
|
199 // documents dramatically improves our performance on worst case |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
200 // 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
|
201 // than using FindFirst and FindAll methods. |
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_EditControlTypeId: |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
205 // 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
|
206 // 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
|
207 // 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
|
208 // (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
|
209 // 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
|
210 // 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
|
211 // 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
|
212 if (address.empty() && IsAddressBarElement(element)) { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
213 address = GetElementValue(element); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
214 return TreeScope_Element; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
215 } else { |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
216 // 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
|
217 // control ("Address bar"). |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
218 return TreeScope_Descendants; |
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 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
221 case UIA_TabControlTypeId: |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
222 if (tabs.empty() && IsTabsElement(element)) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
223 return TreeScope_Children; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
224 return TreeScope_Element; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
225 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
226 case UIA_TabItemControlTypeId: |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
227 tabs.push_back(GetElementName(element)); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
228 return TreeScope_Element; |
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 }; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
231 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
232 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
|
233 return true; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
234 } |
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 /* ------------------------------------------------------------------------------------ */ |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
237 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
238 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
|
239 if (!web_browser_proc) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
240 return false; |
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 if (!InitializeUIAutomation()) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
243 return false; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
244 |
342
adb79bdde329
dep/animone: fix tons of issues
Paper <paper@paper.us.eu.org>
parents:
341
diff
changeset
|
245 ComInterface<Element> parent(GetElementFromHandle(reinterpret_cast<HWND>(window.id.win32))); |
340
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
246 if (!parent) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
247 return false; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
248 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
249 const std::string title = ToUtf8String(GetElementName(*parent)); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
250 web_browser_proc({WebBrowserInformationType::Title, title}); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
251 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
252 std::wstring address; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
253 std::vector<std::wstring> tabs; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
254 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
255 if (!FindWebBrowserElements(*parent, address, tabs)) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
256 return false; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
257 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
258 web_browser_proc({WebBrowserInformationType::Address, ToUtf8String(address)}); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
259 for (const auto& tab : tabs) |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
260 web_browser_proc({WebBrowserInformationType::Tab, ToUtf8String(tab)}); |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
261 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
262 return true; |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
263 } |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
264 |
74e2365326c6
dep/animone: add experimental accessibility strategy
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
265 } // namespace animone::internal::win32 |