forked from microsoft/react-native-windows
/
DynamicAutomationProperties.cpp
330 lines (265 loc) · 14.1 KB
/
DynamicAutomationProperties.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "DynamicAutomationProperties.h"
#include <winrt/Windows.UI.Xaml.Interop.h>
// Needed for latest versions of C++/WinRT
#if __has_include("DynamicAutomationProperties.g.cpp")
#include "DynamicAutomationProperties.g.cpp"
#endif
namespace winrt {
using namespace Windows::Foundation;
using namespace Windows::UI;
using namespace xaml;
using namespace xaml::Interop;
using namespace winrt::Windows::UI::Xaml::Interop;
} // namespace winrt
namespace winrt::Microsoft::ReactNative::implementation {
const winrt::TypeName dynamicAutomationTypeName{
winrt::hstring{L"DynamicAutomationProperties"},
winrt::TypeKind::Metadata};
xaml::DependencyProperty DynamicAutomationProperties::AccessibilityRoleProperty() {
static xaml::DependencyProperty s_AccessibilityRoleProperty = xaml::DependencyProperty::RegisterAttached(
L"AccessibilityRole",
winrt::xaml_typename<winrt::Microsoft::ReactNative::AccessibilityRoles>(),
dynamicAutomationTypeName,
winrt::PropertyMetadata(winrt::box_value(winrt::Microsoft::ReactNative::AccessibilityRoles::Unknown)));
return s_AccessibilityRoleProperty;
}
void DynamicAutomationProperties::SetAccessibilityRole(
xaml::UIElement const &element,
winrt::Microsoft::ReactNative::AccessibilityRoles const &value) {
element.SetValue(AccessibilityRoleProperty(), winrt::box_value<Microsoft::ReactNative::AccessibilityRoles>(value));
}
winrt::Microsoft::ReactNative::AccessibilityRoles DynamicAutomationProperties::GetAccessibilityRole(
xaml::UIElement const &element) {
return winrt::unbox_value<winrt::Microsoft::ReactNative::AccessibilityRoles>(
element.GetValue(AccessibilityRoleProperty()));
}
xaml::DependencyProperty DynamicAutomationProperties::AriaRoleProperty() {
static xaml::DependencyProperty s_ariaRoleProperty = xaml::DependencyProperty::RegisterAttached(
L"AriaRole",
winrt::xaml_typename<winrt::Microsoft::ReactNative::AriaRole>(),
dynamicAutomationTypeName,
winrt::PropertyMetadata(winrt::box_value(winrt::Microsoft::ReactNative::AriaRole::Unknown)));
return s_ariaRoleProperty;
}
void DynamicAutomationProperties::SetAriaRole(
xaml::UIElement const &element,
winrt::Microsoft::ReactNative::AriaRole const &value) {
element.SetValue(AriaRoleProperty(), winrt::box_value<Microsoft::ReactNative::AriaRole>(value));
}
winrt::Microsoft::ReactNative::AriaRole DynamicAutomationProperties::GetAriaRole(xaml::UIElement const &element) {
return winrt::unbox_value<winrt::Microsoft::ReactNative::AriaRole>(element.GetValue(AriaRoleProperty()));
}
xaml::DependencyProperty DynamicAutomationProperties::AccessibilityStateSelectedProperty() {
static xaml::DependencyProperty s_AccessibilityStateSelectedProperty = xaml::DependencyProperty::RegisterAttached(
L"AccessibilityStateSelected",
winrt::xaml_typename<bool>(),
dynamicAutomationTypeName,
winrt::PropertyMetadata(winrt::box_value(false)));
return s_AccessibilityStateSelectedProperty;
}
void DynamicAutomationProperties::SetAccessibilityStateSelected(xaml::UIElement const &element, bool value) {
element.SetValue(AccessibilityStateSelectedProperty(), winrt::box_value<bool>(value));
}
bool DynamicAutomationProperties::GetAccessibilityStateSelected(xaml::UIElement const &element) {
return winrt::unbox_value<bool>(element.GetValue(AccessibilityStateSelectedProperty()));
}
xaml::DependencyProperty DynamicAutomationProperties::AccessibilityStateDisabledProperty() {
static xaml::DependencyProperty s_AccessibilityStateDisabledProperty = xaml::DependencyProperty::RegisterAttached(
L"AccessibilityStateDisabled",
winrt::xaml_typename<bool>(),
dynamicAutomationTypeName,
winrt::PropertyMetadata(winrt::box_value(false)));
return s_AccessibilityStateDisabledProperty;
}
void DynamicAutomationProperties::SetAccessibilityStateDisabled(xaml::UIElement const &element, bool value) {
element.SetValue(AccessibilityStateDisabledProperty(), winrt::box_value<bool>(value));
}
bool DynamicAutomationProperties::GetAccessibilityStateDisabled(xaml::UIElement const &element) {
return winrt::unbox_value<bool>(element.GetValue(AccessibilityStateDisabledProperty()));
}
xaml::DependencyProperty DynamicAutomationProperties::AccessibilityStateCheckedProperty() {
static xaml::DependencyProperty s_AccessibilityStateCheckedProperty = xaml::DependencyProperty::RegisterAttached(
L"AccessibilityStateChecked",
winrt::xaml_typename<AccessibilityStateCheckedValue>(),
dynamicAutomationTypeName,
winrt::PropertyMetadata(winrt::box_value(AccessibilityStateCheckedValue::Unchecked)));
return s_AccessibilityStateCheckedProperty;
}
void DynamicAutomationProperties::SetAccessibilityStateChecked(
xaml::UIElement const &element,
AccessibilityStateCheckedValue value) {
element.SetValue(AccessibilityStateCheckedProperty(), winrt::box_value<AccessibilityStateCheckedValue>(value));
}
AccessibilityStateCheckedValue DynamicAutomationProperties::GetAccessibilityStateChecked(
xaml::UIElement const &element) {
return winrt::unbox_value<AccessibilityStateCheckedValue>(element.GetValue(AccessibilityStateCheckedProperty()));
}
xaml::DependencyProperty DynamicAutomationProperties::AccessibilityStateBusyProperty() {
static xaml::DependencyProperty s_AccessibilityStateBusyProperty = xaml::DependencyProperty::RegisterAttached(
L"AccessibilityStateBusy",
winrt::xaml_typename<bool>(),
dynamicAutomationTypeName,
winrt::PropertyMetadata(winrt::box_value(false)));
return s_AccessibilityStateBusyProperty;
}
void DynamicAutomationProperties::SetAccessibilityStateBusy(xaml::UIElement const &element, bool value) {
element.SetValue(AccessibilityStateBusyProperty(), winrt::box_value<bool>(value));
}
bool DynamicAutomationProperties::GetAccessibilityStateBusy(xaml::UIElement const &element) {
return winrt::unbox_value<bool>(element.GetValue(AccessibilityStateBusyProperty()));
}
xaml::DependencyProperty DynamicAutomationProperties::AccessibilityStateExpandedProperty() {
static xaml::DependencyProperty s_AccessibilityStateExpandedProperty = xaml::DependencyProperty::RegisterAttached(
L"AccessibilityStateExpanded",
winrt::xaml_typename<bool>(),
dynamicAutomationTypeName,
winrt::PropertyMetadata(winrt::box_value(false)));
return s_AccessibilityStateExpandedProperty;
}
void DynamicAutomationProperties::SetAccessibilityStateExpanded(xaml::UIElement const &element, bool value) {
element.SetValue(AccessibilityStateExpandedProperty(), winrt::box_value<bool>(value));
}
bool DynamicAutomationProperties::GetAccessibilityStateExpanded(xaml::UIElement const &element) {
return winrt::unbox_value<bool>(element.GetValue(AccessibilityStateExpandedProperty()));
}
xaml::DependencyProperty DynamicAutomationProperties::AccessibilityValueMinProperty() {
static xaml::DependencyProperty s_AccessibilityValueMinProperty = xaml::DependencyProperty::RegisterAttached(
L"AccessibilityValueMin",
winrt::xaml_typename<double>(),
dynamicAutomationTypeName,
winrt::PropertyMetadata(winrt::box_value(0.0)));
return s_AccessibilityValueMinProperty;
}
void DynamicAutomationProperties::SetAccessibilityValueMin(xaml::UIElement const &element, double value) {
element.SetValue(AccessibilityValueMinProperty(), winrt::box_value<double>(value));
}
double DynamicAutomationProperties::GetAccessibilityValueMin(xaml::UIElement const &element) {
return winrt::unbox_value<double>(element.GetValue(AccessibilityValueMinProperty()));
}
xaml::DependencyProperty DynamicAutomationProperties::AccessibilityValueMaxProperty() {
static xaml::DependencyProperty s_AccessibilityValueMaxProperty = xaml::DependencyProperty::RegisterAttached(
L"AccessibilityValueMax",
winrt::xaml_typename<double>(),
dynamicAutomationTypeName,
winrt::PropertyMetadata(winrt::box_value(0.0)));
return s_AccessibilityValueMaxProperty;
}
void DynamicAutomationProperties::SetAccessibilityValueMax(xaml::UIElement const &element, double value) {
element.SetValue(AccessibilityValueMaxProperty(), winrt::box_value<double>(value));
}
double DynamicAutomationProperties::GetAccessibilityValueMax(xaml::UIElement const &element) {
return winrt::unbox_value<double>(element.GetValue(AccessibilityValueMaxProperty()));
}
xaml::DependencyProperty DynamicAutomationProperties::AccessibilityValueNowProperty() {
static xaml::DependencyProperty s_AccessibilityValueNowProperty = xaml::DependencyProperty::RegisterAttached(
L"AccessibilityValueNow",
winrt::xaml_typename<double>(),
dynamicAutomationTypeName,
winrt::PropertyMetadata(winrt::box_value(0.0)));
return s_AccessibilityValueNowProperty;
}
void DynamicAutomationProperties::SetAccessibilityValueNow(xaml::UIElement const &element, double value) {
element.SetValue(AccessibilityValueNowProperty(), winrt::box_value<double>(value));
}
double DynamicAutomationProperties::GetAccessibilityValueNow(xaml::UIElement const &element) {
return winrt::unbox_value<double>(element.GetValue(AccessibilityValueNowProperty()));
}
xaml::DependencyProperty DynamicAutomationProperties::AccessibilityValueTextProperty() {
static xaml::DependencyProperty s_AccessibilityValueTextProperty = xaml::DependencyProperty::RegisterAttached(
L"AccessibilityValueText",
winrt::xaml_typename<winrt::hstring>(),
dynamicAutomationTypeName,
winrt::PropertyMetadata(winrt::box_value(L"")));
return s_AccessibilityValueTextProperty;
}
void DynamicAutomationProperties::SetAccessibilityValueText(xaml::UIElement const &element, winrt::hstring value) {
element.SetValue(AccessibilityValueTextProperty(), winrt::box_value(value));
}
winrt::hstring DynamicAutomationProperties::GetAccessibilityValueText(xaml::UIElement const &element) {
return winrt::unbox_value<winrt::hstring>(element.GetValue(AccessibilityValueTextProperty()));
}
xaml::DependencyProperty DynamicAutomationProperties::AccessibilityInvokeEventHandlerProperty() {
static xaml::DependencyProperty s_AccessibilityInvokeEventHandlerProperty =
xaml::DependencyProperty::RegisterAttached(
L"AccessibilityInvokeEventHandler",
winrt::xaml_typename<winrt::Microsoft::ReactNative::AccessibilityInvokeEventHandler>(),
dynamicAutomationTypeName,
winrt::PropertyMetadata(
winrt::box_value<winrt::Microsoft::ReactNative::AccessibilityInvokeEventHandler>(nullptr)));
return s_AccessibilityInvokeEventHandlerProperty;
}
void DynamicAutomationProperties::SetAccessibilityInvokeEventHandler(
xaml::UIElement const &element,
winrt::Microsoft::ReactNative::AccessibilityInvokeEventHandler const &value) {
element.SetValue(
AccessibilityInvokeEventHandlerProperty(),
winrt::box_value<winrt::Microsoft::ReactNative::AccessibilityInvokeEventHandler>(value));
}
winrt::Microsoft::ReactNative::AccessibilityInvokeEventHandler
DynamicAutomationProperties::GetAccessibilityInvokeEventHandler(xaml::UIElement const &element) {
return winrt::unbox_value<winrt::Microsoft::ReactNative::AccessibilityInvokeEventHandler>(
element.GetValue(AccessibilityInvokeEventHandlerProperty()));
}
xaml::DependencyProperty DynamicAutomationProperties::AccessibilityActionsProperty() {
static xaml::DependencyProperty s_AccessibilityActionsProperty = xaml::DependencyProperty::RegisterAttached(
L"AccessibilityActions",
winrt::xaml_typename<
winrt::Windows::Foundation::Collections::IVector<Microsoft::ReactNative::AccessibilityAction>>(),
dynamicAutomationTypeName,
winrt::PropertyMetadata(nullptr));
return s_AccessibilityActionsProperty;
}
void DynamicAutomationProperties::SetAccessibilityActions(
xaml::UIElement const &element,
winrt::Windows::Foundation::Collections::IVector<Microsoft::ReactNative::AccessibilityAction> const &value) {
return element.SetValue(AccessibilityActionsProperty(), winrt::box_value(value));
}
winrt::Windows::Foundation::Collections::IVector<Microsoft::ReactNative::AccessibilityAction>
DynamicAutomationProperties::GetAccessibilityActions(xaml::UIElement const &element) {
return winrt::unbox_value<
winrt::Windows::Foundation::Collections::IVector<Microsoft::ReactNative::AccessibilityAction>>(
element.GetValue(AccessibilityActionsProperty()));
}
void DynamicAutomationProperties::DispatchAccessibilityAction(
xaml::UIElement const &element,
std::wstring_view const &actionName) {
if (element) {
auto vector = GetAccessibilityActions(element);
if (vector) {
for (uint32_t i = 0; i < vector.Size(); i++) {
auto item = vector.GetAt(i);
if (item.Name.operator std::wstring_view() == actionName) {
if (auto const &handler = GetAccessibilityActionEventHandler(element)) {
handler(item);
}
}
}
}
}
}
xaml::DependencyProperty DynamicAutomationProperties::AccessibilityActionEventHandlerProperty() {
static xaml::DependencyProperty s_AccessibilityActionEventHandlerProperty =
xaml::DependencyProperty::RegisterAttached(
L"AccessibilityActionEventHandler",
winrt::xaml_typename<winrt::Microsoft::ReactNative::AccessibilityActionEventHandler>(),
dynamicAutomationTypeName,
winrt::PropertyMetadata(
winrt::box_value<winrt::Microsoft::ReactNative::AccessibilityActionEventHandler>(nullptr)));
return s_AccessibilityActionEventHandlerProperty;
}
void DynamicAutomationProperties::SetAccessibilityActionEventHandler(
xaml::UIElement const &element,
winrt::Microsoft::ReactNative::AccessibilityActionEventHandler const &value) {
element.SetValue(
AccessibilityActionEventHandlerProperty(),
winrt::box_value<winrt::Microsoft::ReactNative::AccessibilityActionEventHandler>(value));
}
winrt::Microsoft::ReactNative::AccessibilityActionEventHandler
DynamicAutomationProperties::GetAccessibilityActionEventHandler(xaml::UIElement const &element) {
return winrt::unbox_value<winrt::Microsoft::ReactNative::AccessibilityActionEventHandler>(
element.GetValue(AccessibilityActionEventHandlerProperty()));
}
} // namespace winrt::Microsoft::ReactNative::implementation