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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
//! Accessibility types for screen reader support.
//!
//! Key types:
//! - [`AccessibilityInfo`] — full accessibility metadata for a UI element
//! - [`SmallAriaInfo`] — lightweight alternative for common cases (label + role + description)
//! - [`AccessibilityRole`] — element purpose (button, link, checkbox, etc.)
//! - [`AccessibilityState`] — dynamic state (focused, checked, expanded, etc.)
//! - [`AccessibilityAction`] — actions performable on an element (click, scroll, etc.)
//!
//! These types are consumed by `layout/src/managers/a11y.rs` and mapped to
//! platform accessibility backends in `dll/src/desktop/shell2/`.
use alloc::vec::Vec;
use azul_css::{
AzString, OptionF32, OptionString,
props::basic::length::FloatValue,
};
use crate::{
dom::OptionDomNodeId,
geom::LogicalPosition,
window::OptionVirtualKeyCodeCombo,
};
/// Holds information about a UI element for accessibility purposes (e.g., screen readers).
/// This is a wrapper for platform-specific accessibility APIs like MSAA.
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)]
#[repr(C)]
pub struct AccessibilityInfo {
/// Get the "name" of the `IAccessible`, for example the
/// name of a button, checkbox or menu item. Try to use unique names
/// for each item in a dialog so that voice dictation software doesn't
/// have to deal with extra ambiguity.
pub accessibility_name: OptionString,
/// Get the "value" of the `IAccessible`, for example a number in a slider,
/// a URL for a link, the text a user entered in a field.
pub accessibility_value: OptionString,
/// Optional text description providing additional context about the element.
/// Maps to `aria-description` / accesskit's `set_description()`.
pub description: OptionString,
/// Optional keyboard accelerator.
pub accelerator: OptionVirtualKeyCodeCombo,
/// Optional "default action" description. Only used when there is at least
/// one `ComponentEventFilter::DefaultAction` callback present on this node.
pub default_action: OptionString,
/// Possible on/off states, such as focused, focusable, selected, selectable,
/// visible, protected (for passwords), checked, etc.
pub states: AccessibilityStateVec,
/// A list of actions the user can perform on this element.
/// Maps to accesskit's Action enum.
pub supported_actions: AccessibilityActionVec,
/// ID of another node that labels this one (for `aria-labelledby`).
pub labelled_by: OptionDomNodeId,
/// ID of another node that describes this one (for `aria-describedby`).
pub described_by: OptionDomNodeId,
/// Get an enumerated value representing what this `IAccessible` is used for,
/// for example is it a link, static text, editable text, a checkbox, or a table cell, etc.
pub role: AccessibilityRole,
/// For live regions that update automatically (e.g., chat messages, timers).
/// Maps to accesskit's `Live` property.
pub is_live_region: bool,
}
/// Actions that can be performed on an accessible element.
/// This is a simplified version of `accesskit::Action` to avoid direct dependency in core.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C, u8)]
pub enum AccessibilityAction {
/// The default action for the element (usually a click).
Default,
/// Set focus to this element.
Focus,
/// Remove focus from this element.
Blur,
/// Collapse an expandable element (e.g., tree node, accordion).
Collapse,
/// Expand a collapsible element (e.g., tree node, accordion).
Expand,
/// Scroll this element into view.
ScrollIntoView,
/// Increment a numeric value (e.g., slider, spinner).
Increment,
/// Decrement a numeric value (e.g., slider, spinner).
Decrement,
/// Show a context menu.
ShowContextMenu,
/// Hide a tooltip.
HideTooltip,
/// Show a tooltip.
ShowTooltip,
/// Scroll up.
ScrollUp,
/// Scroll down.
ScrollDown,
/// Scroll left.
ScrollLeft,
/// Scroll right.
ScrollRight,
/// Replace selected text with new text.
ReplaceSelectedText(AzString),
/// Scroll to a specific point.
ScrollToPoint(LogicalPosition),
/// Set scroll offset.
SetScrollOffset(LogicalPosition),
/// Set text selection.
SetTextSelection(TextSelectionStartEnd),
/// Set sequential focus navigation starting point.
SetSequentialFocusNavigationStartingPoint,
/// Set the value of a control.
SetValue(AzString),
/// Set numeric value of a control.
SetNumericValue(FloatValue),
/// Custom action with ID.
CustomAction(i32),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C)]
pub struct TextSelectionStartEnd {
pub selection_start: usize,
pub selection_end: usize,
}
impl_vec!(AccessibilityAction, AccessibilityActionVec, AccessibilityActionVecDestructor, AccessibilityActionVecDestructorType, AccessibilityActionVecSlice, OptionAccessibilityAction);
impl_vec_debug!(AccessibilityAction, AccessibilityActionVec);
impl_vec_clone!(
AccessibilityAction,
AccessibilityActionVec,
AccessibilityActionVecDestructor
);
impl_vec_partialeq!(AccessibilityAction, AccessibilityActionVec);
impl_vec_eq!(AccessibilityAction, AccessibilityActionVec);
impl_vec_partialord!(AccessibilityAction, AccessibilityActionVec);
impl_vec_ord!(AccessibilityAction, AccessibilityActionVec);
impl_vec_hash!(AccessibilityAction, AccessibilityActionVec);
impl_option![
AccessibilityAction,
OptionAccessibilityAction,
copy = false,
[Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
];
impl_option!(
AccessibilityInfo,
OptionAccessibilityInfo,
copy = false,
[Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
);
/// Defines the element's purpose for accessibility APIs, informing assistive technologies
/// like screen readers about the function of a UI element.
///
/// Each variant corresponds to a
/// standard control type or UI structure.
///
/// For more details, see the [MSDN Role Constants page](https://docs.microsoft.com/en-us/windows/winauto/object-roles).
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
pub enum AccessibilityRole {
/// Represents the title or caption bar of a window.
/// - **Purpose**: To identify the title bar containing the window title and system commands.
/// - **When to use**: This role is typically inserted by the operating system for standard
/// windows.
/// - **Example**: The bar at the top of an application window displaying its name and the
/// minimize, maximize, and close buttons.
TitleBar,
/// Represents a menu bar at the top of a window.
/// - **Purpose**: To contain a set of top-level menus for an application.
/// - **When to use**: For the main menu bar of an application, such as one containing "File,"
/// "Edit," and "View."
/// - **Example**: The "File", "Edit", "View" menu bar at the top of a text editor.
MenuBar,
/// Represents a vertical or horizontal scroll bar.
/// - **Purpose**: To enable scrolling through content that is larger than the visible area.
/// - **When to use**: For any scrollable region of content.
/// - **Example**: The bar on the side of a web page that allows the user to scroll up and
/// down.
ScrollBar,
/// Represents a handle or grip used for moving or resizing.
/// - **Purpose**: To provide a user interface element for manipulating another element's size
/// or position.
/// - **When to use**: For handles that allow resizing of windows, panes, or other objects.
/// - **Example**: The small textured area in the bottom-right corner of a window that can be
/// dragged to resize it.
Grip,
/// Represents a system sound indicating an event.
/// - **Purpose**: To associate a sound with a UI event, providing an auditory cue.
/// - **When to use**: When a sound is the primary representation of an event.
/// - **Example**: A system notification sound that plays when a new message arrives.
Sound,
/// Represents the system's mouse pointer or other pointing device.
/// - **Purpose**: To indicate the screen position of the user's pointing device.
/// - **When to use**: This role is managed by the operating system.
/// - **Example**: The arrow that moves on the screen as you move the mouse.
Cursor,
/// Represents the text insertion point indicator.
/// - **Purpose**: To show the current text entry or editing position.
/// - **When to use**: This role is typically managed by the operating system for text input
/// fields.
/// - **Example**: The blinking vertical line in a text box that shows where the next character
/// will be typed.
Caret,
/// Represents an alert or notification.
/// - **Purpose**: To convey an important, non-modal message to the user.
/// - **When to use**: For non-intrusive notifications that do not require immediate user
/// interaction.
/// - **Example**: A small, temporary "toast" notification that appears to confirm an action,
/// like "Email sent."
Alert,
/// Represents a window frame.
/// - **Purpose**: To serve as the container for other objects like a title bar and client
/// area.
/// - **When to use**: This is a fundamental role, typically managed by the windowing system.
/// - **Example**: The main window of any application, which contains all other UI elements.
Window,
/// Represents a window's client area, where the main content is displayed.
/// - **Purpose**: To define the primary content area of a window.
/// - **When to use**: For the main content region of a window. It's often the default role for
/// a custom control container.
/// - **Example**: The area of a web browser where the web page content is rendered.
Client,
/// Represents a pop-up menu.
/// - **Purpose**: To display a list of `MenuItem` objects that appears when a user performs an
/// action.
/// - **When to use**: For context menus (right-click menus) or drop-down menus.
/// - **Example**: The menu that appears when you right-click on a file in a file explorer.
MenuPopup,
/// Represents an individual item within a menu.
/// - **Purpose**: To represent a single command, option, or separator within a menu.
/// - **When to use**: For individual options inside a `MenuBar` or `MenuPopup`.
/// - **Example**: The "Save" option within the "File" menu.
MenuItem,
/// Represents a small pop-up window that provides information.
/// - **Purpose**: To offer brief, contextual help or information about a UI element.
/// - **When to use**: For informational pop-ups that appear on mouse hover.
/// - **Example**: The small box of text that appears when you hover over a button in a
/// toolbar.
Tooltip,
/// Represents the main window of an application.
/// - **Purpose**: To identify the top-level window of an application.
/// - **When to use**: For the primary window that represents the application itself.
/// - **Example**: The main window of a calculator or notepad application.
Application,
/// Represents a document window within an application.
/// - **Purpose**: To represent a contained document, typically in a Multiple Document
/// Interface (MDI) application.
/// - **When to use**: For individual document windows inside a larger application shell.
/// - **Example**: In a photo editor that allows multiple images to be open in separate
/// windows, each image window would be a `Document`.
Document,
/// Represents a pane or a distinct section of a window.
/// - **Purpose**: To divide a window into visually and functionally distinct areas.
/// - **When to use**: For sub-regions of a window, like a navigation pane, preview pane, or
/// sidebar.
/// - **Example**: The preview pane in an email client that shows the content of the selected
/// email.
Pane,
/// Represents a graphical chart or graph.
/// - **Purpose**: To display data visually in a chart format.
/// - **When to use**: For any type of chart, such as a bar chart, line chart, or pie chart.
/// - **Example**: A bar chart displaying monthly sales figures.
Chart,
/// Represents a dialog box or message box.
/// - **Purpose**: To create a secondary window that requires user interaction before returning
/// to the main application.
/// - **When to use**: For modal or non-modal windows that prompt the user for information or a
/// response.
/// - **Example**: The "Open File" or "Print" dialog in most applications.
Dialog,
/// Represents a window's border.
/// - **Purpose**: To identify the border of a window, which is often used for resizing.
/// - **When to use**: This role is typically managed by the windowing system.
/// - **Example**: The decorative and functional frame around a window.
Border,
/// Represents a group of related controls.
/// - **Purpose**: To logically group other objects that share a common purpose.
/// - **When to use**: For grouping controls like a set of radio buttons or a fieldset with a
/// legend.
/// - **Example**: A "Settings" group box in a dialog that contains several related checkboxes.
Grouping,
/// Represents a visual separator.
/// - **Purpose**: To visually divide a space or a group of controls.
/// - **When to use**: For visual separators in menus, toolbars, or between panes.
/// - **Example**: The horizontal line in a menu that separates groups of related menu items.
Separator,
/// Represents a toolbar containing a group of controls.
/// - **Purpose**: To group controls, typically buttons, for quick access to frequently used
/// functions.
/// - **When to use**: For a bar of buttons or other controls, usually at the top of a window
/// or pane.
/// - **Example**: The toolbar at the top of a word processor with buttons for "Bold,"
/// "Italic," and "Underline."
Toolbar,
/// Represents a status bar for displaying information.
/// - **Purpose**: To display status information about the current state of the application.
/// - **When to use**: For a bar, typically at the bottom of a window, that displays messages.
/// - **Example**: The bar at the bottom of a web browser that shows the loading status of a
/// page.
StatusBar,
/// Represents a data table.
/// - **Purpose**: To present data in a two-dimensional grid of rows and columns.
/// - **When to use**: For grid-like data presentation.
/// - **Example**: A spreadsheet or a table of data in a database application.
Table,
/// Represents a column header in a table.
/// - **Purpose**: To provide a label for a column of data.
/// - **When to use**: For the headers of columns in a `Table`.
/// - **Example**: The header row in a spreadsheet with labels like "Name," "Date," and
/// "Amount."
ColumnHeader,
/// Represents a row header in a table.
/// - **Purpose**: To provide a label for a row of data.
/// - **When to use**: For the headers of rows in a `Table`.
/// - **Example**: The numbered rows on the left side of a spreadsheet.
RowHeader,
/// Represents a full column of cells in a table.
/// - **Purpose**: To represent an entire column as a single accessible object.
/// - **When to use**: When it is useful to interact with a column as a whole.
/// - **Example**: The "Amount" column in a financial data table.
Column,
/// Represents a full row of cells in a table.
/// - **Purpose**: To represent an entire row as a single accessible object.
/// - **When to use**: When it is useful to interact with a row as a whole.
/// - **Example**: A row representing a single customer's information in a customer list.
Row,
/// Represents a single cell within a table.
/// - **Purpose**: To represent a single data point or control within a `Table`.
/// - **When to use**: For individual cells in a grid or table.
/// - **Example**: A single cell in a spreadsheet containing a specific value.
Cell,
/// Represents a hyperlink to a resource.
/// - **Purpose**: To provide a navigational link to another document or location.
/// - **When to use**: For text or images that, when clicked, navigate to another resource.
/// - **Example**: A clickable link on a web page.
Link,
/// Represents a help balloon or pop-up.
/// - **Purpose**: To provide more detailed help information than a standard tooltip.
/// - **When to use**: For a pop-up that offers extended help text, often initiated by a help
/// button.
/// - **Example**: A pop-up balloon with a paragraph of help text that appears when a user
/// clicks a help icon.
HelpBalloon,
/// Represents an animated, character-like graphic object.
/// - **Purpose**: To provide an animated agent for user assistance or entertainment.
/// - **When to use**: For animated characters or avatars that provide help or guidance.
/// - **Example**: An animated paperclip that offers tips in a word processor (e.g.,
/// Microsoft's Clippy).
Character,
/// Represents a list of items.
/// - **Purpose**: To contain a set of `ListItem` objects.
/// - **When to use**: For list boxes or similar controls that present a list of selectable
/// items.
/// - **Example**: The list of files in a file selection dialog.
List,
/// Represents an individual item within a list.
/// - **Purpose**: To represent a single, selectable item within a `List`.
/// - **When to use**: For each individual item in a list box or combo box.
/// - **Example**: A single file name in a list of files.
ListItem,
/// Represents an outline or tree structure.
/// - **Purpose**: To display a hierarchical view of data.
/// - **When to use**: For tree-view controls that show nested items.
/// - **Example**: A file explorer's folder tree view.
Outline,
/// Represents an individual item within an outline or tree.
/// - **Purpose**: To represent a single node (which can be a leaf or a branch) in an
/// `Outline`.
/// - **When to use**: For each node in a tree view.
/// - **Example**: A single folder in a file explorer's tree view.
OutlineItem,
/// Represents a single tab in a tabbed interface.
/// - **Purpose**: To provide a control for switching between different `PropertyPage` views.
/// - **When to use**: For the individual tabs that the user can click to switch pages.
/// - **Example**: The "General" and "Security" tabs in a file properties dialog.
PageTab,
/// Represents the content of a page in a property sheet.
/// - **Purpose**: To serve as a container for the controls displayed when a `PageTab` is
/// selected.
/// - **When to use**: For the content area associated with a specific tab.
/// - **Example**: The set of options displayed when the "Security" tab is active.
PropertyPage,
/// Represents a visual indicator, like a slider thumb.
/// - **Purpose**: To visually indicate the current value or position of another control.
/// - **When to use**: For a sub-element that indicates status, like the thumb of a scrollbar.
/// - **Example**: The draggable thumb of a scrollbar that indicates the current scroll
/// position.
Indicator,
/// Represents a picture or graphical image.
/// - **Purpose**: To display a non-interactive image.
/// - **When to use**: For images and icons that are purely decorative or informational.
/// - **Example**: A company logo displayed in an application's "About" dialog.
Graphic,
/// Represents read-only text.
/// - **Purpose**: To provide a non-editable text label for another control or for displaying
/// information.
/// - **When to use**: For text that the user cannot edit.
/// - **Example**: The label "Username:" next to a text input field.
StaticText,
/// Represents editable text or a text area.
/// - **Purpose**: To allow for user text input or selection.
/// - **When to use**: For text input fields where the user can type.
/// - **Example**: A text box for entering a username or password.
Text,
/// Represents a standard push button.
/// - **Purpose**: To initiate an immediate action.
/// - **When to use**: For standard buttons that perform an action when clicked.
/// - **Example**: An "OK" or "Cancel" button in a dialog.
PushButton,
/// Represents a check box control.
/// - **Purpose**: To allow the user to make a binary choice (checked or unchecked).
/// - **When to use**: For options that can be toggled on or off independently.
/// - **Example**: A "Remember me" checkbox on a login form.
CheckButton,
/// Represents a radio button.
/// - **Purpose**: To allow the user to select one option from a mutually exclusive group.
/// - **When to use**: For a choice where only one option from a `Grouping` can be selected.
/// - **Example**: "Male" and "Female" radio buttons for selecting gender.
RadioButton,
/// Represents a combination of a text field and a drop-down list.
/// - **Purpose**: To allow the user to either type a value or select one from a list.
/// - **When to use**: For controls that offer a list of suggestions but also allow custom
/// input.
/// - **Example**: A font selector that allows you to type a font name or choose one from a
/// list.
ComboBox,
/// Represents a drop-down list box.
/// - **Purpose**: To allow the user to select an item from a non-editable list that drops
/// down.
/// - **When to use**: For selecting a single item from a predefined list of options.
/// - **Example**: A country selection drop-down menu.
DropList,
/// Represents a progress bar.
/// - **Purpose**: To indicate the progress of a lengthy operation.
/// - **When to use**: To provide feedback for tasks like file downloads or installations.
/// - **Example**: The bar that fills up to show the progress of a file copy operation.
ProgressBar,
/// Represents a dial or knob.
/// - **Purpose**: To allow selecting a value from a continuous or discrete range, often
/// circularly.
/// - **When to use**: For controls that resemble real-world dials, like a volume knob.
/// - **Example**: A volume control knob in a media player application.
Dial,
/// Represents a control for entering a keyboard shortcut.
/// - **Purpose**: To capture a key combination from the user.
/// - **When to use**: In settings where users can define their own keyboard shortcuts.
/// - **Example**: A text field in a settings dialog where a user can press a key combination
/// to assign it to a command.
HotkeyField,
/// Represents a slider for selecting a value within a range.
/// - **Purpose**: To allow the user to adjust a setting along a continuous or discrete range.
/// - **When to use**: For adjusting values like volume, brightness, or zoom level.
/// - **Example**: A slider to control the volume of a video.
Slider,
/// Represents a spin button (up/down arrows) for incrementing or decrementing a value.
/// - **Purpose**: To provide fine-tuned adjustment of a value, typically numeric.
/// - **When to use**: For controls that allow stepping through a range of values.
/// - **Example**: The up and down arrows next to a number input for setting the font size.
SpinButton,
/// Represents a diagram or flowchart.
/// - **Purpose**: To represent data or relationships in a schematic form.
/// - **When to use**: For visual representations of structures that are not charts, like a
/// database schema diagram.
/// - **Example**: A flowchart illustrating a business process.
Diagram,
/// Represents an animation control.
/// - **Purpose**: To display a sequence of images or indicate an ongoing process.
/// - **When to use**: For animations that show that an operation is in progress.
/// - **Example**: The animation that plays while files are being copied.
Animation,
/// Represents a mathematical equation.
/// - **Purpose**: To display a mathematical formula in the correct format.
/// - **When to use**: For displaying mathematical equations.
/// - **Example**: A rendered mathematical equation in a scientific document editor.
Equation,
/// Represents a button that drops down a list of items.
/// - **Purpose**: To combine a default action button with a list of alternative actions.
/// - **When to use**: For buttons that have a primary action and a secondary list of options.
/// - **Example**: A "Send" button with a dropdown arrow that reveals "Send and Archive."
ButtonDropdown,
/// Represents a button that drops down a full menu.
/// - **Purpose**: To provide a button that opens a menu of choices rather than performing a
/// single action.
/// - **When to use**: When a button's primary purpose is to reveal a menu.
/// - **Example**: A "Tools" button that opens a menu with various tool options.
ButtonMenu,
/// Represents a button that drops down a grid for selection.
/// - **Purpose**: To allow selection from a two-dimensional grid of options.
/// - **When to use**: For buttons that open a grid-based selection UI.
/// - **Example**: A color picker button that opens a grid of color swatches.
ButtonDropdownGrid,
/// Represents blank space between other objects.
/// - **Purpose**: To represent significant empty areas in a UI that are part of the layout.
/// - **When to use**: Sparingly, to signify that a large area is intentionally blank.
/// - **Example**: A large empty panel in a complex layout might use this role.
Whitespace,
/// Represents the container for a set of tabs.
/// - **Purpose**: To group a set of `PageTab` elements.
/// - **When to use**: To act as the parent container for a row or column of tabs.
/// - **Example**: The entire row of tabs at the top of a properties dialog.
PageTabList,
/// Represents a clock control.
/// - **Purpose**: To display the current time.
/// - **When to use**: For any UI element that displays time.
/// - **Example**: The clock in the system tray of the operating system.
Clock,
/// Represents a button with two parts: a default action and a dropdown.
/// - **Purpose**: To combine a frequently used action with a set of related, less-used
/// actions.
/// - **When to use**: When a button has a default action and other related actions available
/// in a dropdown.
/// - **Example**: A "Save" split button where the primary part saves, and the dropdown offers
/// "Save As."
SplitButton,
/// Represents a control for entering an IP address.
/// - **Purpose**: To provide a specialized input field for IP addresses, often with formatting
/// and validation.
/// - **When to use**: For dedicated IP address input fields.
/// - **Example**: A network configuration dialog with a field for entering a static IP
/// address.
IpAddress,
/// Represents an element with no specific role.
/// - **Purpose**: To indicate an element that has no semantic meaning for accessibility.
/// - **When to use**: Should be used sparingly for purely decorative elements that should be
/// ignored by assistive technologies.
/// - **Example**: A decorative graphical flourish that has no function or information to
/// convey.
Nothing,
/// Unknown or unspecified role.
/// - **Purpose**: Default fallback when no specific role is assigned.
/// - **When to use**: As a default value or when role information is unavailable.
Unknown,
}
impl_option!(
AccessibilityRole,
OptionAccessibilityRole,
[Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
);
/// Defines the current state of an element for accessibility APIs (e.g., focused, checked).
/// These states provide dynamic information to assistive technologies about the element's
/// condition.
///
/// See the [MSDN State Constants page](https://docs.microsoft.com/en-us/windows/win32/winauto/object-state-constants) for more details.
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[repr(C)]
pub enum AccessibilityState {
/// The element is unavailable and cannot be interacted with.
/// - **Purpose**: To indicate that a control is disabled or grayed out.
/// - **When to use**: For disabled buttons, non-interactive menu items, or any control that is
/// temporarily non-functional.
/// - **Example**: A "Save" button that is disabled until the user makes changes to a document.
Unavailable,
/// The element is selected.
/// - **Purpose**: To indicate that an item is currently chosen or highlighted. This is
/// distinct from having focus.
/// - **When to use**: For selected items in a list, highlighted text, or the currently active
/// tab in a tab list.
/// - **Example**: A file highlighted in a file explorer, or multiple selected emails in an
/// inbox.
Selected,
/// The element has the keyboard focus.
/// - **Purpose**: To identify the single element that will receive keyboard input.
/// - **When to use**: For the control that is currently active and ready to be manipulated by
/// the keyboard.
/// - **Example**: A text box with a blinking cursor, or a button with a dotted outline around
/// it.
Focused,
/// The element is checked, toggled, or in an "on" state.
/// - **Purpose**: To represent checked checkboxes, selected radio buttons, and active toggles.
/// - **Example**: A checked "I agree" checkbox, a selected "Yes" radio button.
CheckedTrue,
/// The element is unchecked, untoggled, or in an "off" state.
/// - **Purpose**: To explicitly represent an unchecked checkbox or unselected radio button.
/// - **Example**: An unchecked checkbox that the user has not yet ticked.
CheckedFalse,
/// The element's content cannot be edited by the user.
/// - **Purpose**: To indicate that the element's value can be viewed and copied, but not
/// modified.
/// - **When to use**: For display-only text fields or documents.
/// - **Example**: A text box displaying a license agreement that the user can scroll through
/// but cannot edit.
Readonly,
/// The element is the default action in a dialog or form.
/// - **Purpose**: To identify the button that will be activated if the user presses the Enter
/// key.
/// - **When to use**: For the primary confirmation button in a dialog.
/// - **Example**: The "OK" button in a dialog box, which often has a thicker or colored
/// border.
Default,
/// The element is expanded, showing its child items.
/// - **Purpose**: To indicate that a collapsible element is currently open and its contents
/// are visible.
/// - **When to use**: For tree view nodes, combo boxes with their lists open, or expanded
/// accordion panels.
/// - **Example**: A folder in a file explorer's tree view that has been clicked to show its
/// subfolders.
Expanded,
/// The element is collapsed, hiding its child items.
/// - **Purpose**: To indicate that a collapsible element is closed and its contents are
/// hidden.
/// - **When to use**: The counterpart to `Expanded` for any collapsible UI element.
/// - **Example**: A closed folder in a file explorer's tree view, hiding its contents.
Collapsed,
/// The element is busy and cannot respond to user interaction.
/// - **Purpose**: To indicate that the element or application is performing an operation and
/// is temporarily unresponsive.
/// - **When to use**: When an application is loading, processing data, or otherwise occupied.
/// - **Example**: A window that is grayed out and shows a spinning cursor while saving a large
/// file.
Busy,
/// The element is not currently visible on the screen.
/// - **Purpose**: To indicate that an element exists but is currently scrolled out of the
/// visible area.
/// - **When to use**: For items in a long list or a large document that are not within the
/// current viewport.
/// - **Example**: A list item in a long dropdown that you would have to scroll down to see.
Offscreen,
/// The element can accept keyboard focus.
/// - **Purpose**: To indicate that the user can navigate to this element using the keyboard
/// (e.g., with the Tab key).
/// - **When to use**: On all interactive elements like buttons, links, and input fields,
/// whether they currently have focus or not.
/// - **Example**: A button that can receive focus, even if it is not the currently focused
/// element.
Focusable,
/// The element is a container whose children can be selected.
/// - **Purpose**: To indicate that the element contains items that can be chosen.
/// - **When to use**: On container controls like list boxes, tree views, or text spans where
/// text can be highlighted.
/// - **Example**: A list box control is `Selectable`, while its individual list items have the
/// `Selected` state when chosen.
Selectable,
/// The element is a hyperlink.
/// - **Purpose**: To identify an object that navigates to another resource or location when
/// activated.
/// - **When to use**: On any object that functions as a hyperlink.
/// - **Example**: Text or an image that, when clicked, opens a web page.
Linked,
/// The element is a hyperlink that has been visited.
/// - **Purpose**: To indicate that a hyperlink has already been followed by the user.
/// - **When to use**: On a `Linked` object that the user has previously activated.
/// - **Example**: A hyperlink on a web page that has changed color to show it has been
/// visited.
Traversed,
/// The element allows multiple of its children to be selected at once.
/// - **Purpose**: To indicate that a container control supports multi-selection.
/// - **When to use**: On container controls like list boxes or file explorers that support
/// multiple selections (e.g., with Ctrl-click).
/// - **Example**: A file list that allows the user to select several files at once for a copy
/// operation.
Multiselectable,
/// The element contains protected content that should not be read aloud.
/// - **Purpose**: To prevent assistive technologies from speaking the content of a sensitive
/// field.
/// - **When to use**: Primarily for password input fields.
/// - **Example**: A password text box where typed characters are masked with asterisks or
/// dots.
Protected,
}
impl_option!(
AccessibilityState,
OptionAccessibilityState,
[Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash]
);
impl_vec!(AccessibilityState, AccessibilityStateVec, AccessibilityStateVecDestructor, AccessibilityStateVecDestructorType, AccessibilityStateVecSlice, OptionAccessibilityState);
impl_vec_clone!(
AccessibilityState,
AccessibilityStateVec,
AccessibilityStateVecDestructor
);
impl_vec_debug!(AccessibilityState, AccessibilityStateVec);
impl_vec_partialeq!(AccessibilityState, AccessibilityStateVec);
impl_vec_partialord!(AccessibilityState, AccessibilityStateVec);
impl_vec_eq!(AccessibilityState, AccessibilityStateVec);
impl_vec_ord!(AccessibilityState, AccessibilityStateVec);
impl_vec_hash!(AccessibilityState, AccessibilityStateVec);
/// Compact accessibility information for common use cases.
///
/// This is a lighter-weight alternative to `AccessibilityInfo` for cases where
/// only basic accessibility properties are needed. Developers must explicitly
/// pass `None` if they choose not to provide accessibility information.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[repr(C)]
pub struct SmallAriaInfo {
/// Accessible label/name
pub label: OptionString,
/// Element's role (button, link, etc.)
pub role: OptionAccessibilityRole,
/// Additional description
pub description: OptionString,
}
impl_option!(
SmallAriaInfo,
OptionSmallAriaInfo,
copy = false,
[Debug, Clone, PartialEq, Eq, Hash]
);
impl SmallAriaInfo {
pub fn label<S: Into<AzString>>(text: S) -> Self {
Self {
label: OptionString::Some(text.into()),
role: OptionAccessibilityRole::None,
description: OptionString::None,
}
}
#[must_use] pub const fn with_role(mut self, role: AccessibilityRole) -> Self {
self.role = OptionAccessibilityRole::Some(role);
self
}
#[must_use] pub fn with_description<S: Into<AzString>>(mut self, desc: S) -> Self {
self.description = OptionString::Some(desc.into());
self
}
/// Convert to full `AccessibilityInfo`
#[must_use] pub fn to_full_info(&self) -> AccessibilityInfo {
AccessibilityInfo {
accessibility_name: self.label.clone(),
accessibility_value: OptionString::None,
description: self.description.clone(),
role: match self.role {
OptionAccessibilityRole::Some(r) => r,
OptionAccessibilityRole::None => AccessibilityRole::Unknown,
},
states: Vec::new().into(),
accelerator: OptionVirtualKeyCodeCombo::None,
default_action: OptionString::None,
supported_actions: Vec::new().into(),
is_live_region: false,
labelled_by: OptionDomNodeId::None,
described_by: OptionDomNodeId::None,
}
}
}
/// Accessibility information for a `<progress>` indicator.
///
/// Mirrors HTML's `<progress value max>` plus an `indeterminate` flag for
/// progress bars whose end is unknown. Maps to `AccessibilityRole::ProgressBar`.
#[derive(Debug, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct ProgressAriaInfo {
/// Accessible label describing the task being measured.
pub label: OptionString,
/// Current progress value. `None` for indeterminate progress.
pub current_value: OptionF32,
/// Maximum value the progress bar can reach. `None` falls back to `1.0`.
pub max: OptionF32,
/// `true` for spinners / progress with no known endpoint. Overrides `current_value`.
pub indeterminate: bool,
/// Optional extended description (`aria-describedby` equivalent).
pub description: OptionString,
}
impl_option!(
ProgressAriaInfo,
OptionProgressAriaInfo,
copy = false,
[Debug, Clone, PartialEq, Eq]
);
impl ProgressAriaInfo {
/// Creates a `ProgressAriaInfo` with only an accessible label.
#[must_use] pub const fn create(label: AzString) -> Self {
Self {
label: OptionString::Some(label),
current_value: OptionF32::None,
max: OptionF32::None,
indeterminate: false,
description: OptionString::None,
}
}
/// Returns a copy with the given current value.
#[must_use] pub const fn with_current_value(mut self, value: f32) -> Self {
self.current_value = OptionF32::Some(value);
self
}
/// Returns a copy with the given maximum value.
#[must_use] pub const fn with_max(mut self, max: f32) -> Self {
self.max = OptionF32::Some(max);
self
}
/// Returns a copy with the indeterminate flag set.
#[must_use] pub const fn with_indeterminate(mut self, indeterminate: bool) -> Self {
self.indeterminate = indeterminate;
self
}
/// Returns a copy with the given description.
#[must_use] pub fn with_description(mut self, desc: AzString) -> Self {
self.description = OptionString::Some(desc);
self
}
/// Convert to full `AccessibilityInfo` so the value can be installed on a node.
#[must_use] pub fn to_full_info(&self) -> AccessibilityInfo {
let value_string = if self.indeterminate {
OptionString::None
} else {
match self.current_value {
OptionF32::Some(v) => OptionString::Some(format!("{v}").into()),
OptionF32::None => OptionString::None,
}
};
AccessibilityInfo {
accessibility_name: self.label.clone(),
accessibility_value: value_string,
description: self.description.clone(),
role: AccessibilityRole::ProgressBar,
states: Vec::new().into(),
accelerator: OptionVirtualKeyCodeCombo::None,
default_action: OptionString::None,
supported_actions: Vec::new().into(),
is_live_region: false,
labelled_by: OptionDomNodeId::None,
described_by: OptionDomNodeId::None,
}
}
}
/// Accessibility information for a `<meter>` gauge.
///
/// Unlike `<progress>`, `<meter>` always carries a known `value`/`min`/`max`
/// triple, so those fields are required at construction time. Maps to
/// `AccessibilityRole::Indicator`.
#[derive(Debug, Clone, PartialEq)]
#[repr(C)]
pub struct MeterAriaInfo {
/// Accessible label describing what the meter measures.
pub label: OptionString,
/// Current value of the meter (within `[min, max]`).
pub current_value: f32,
/// Lower bound of the measurement range.
pub min: f32,
/// Upper bound of the measurement range.
pub max: f32,
/// Optional "low" threshold (values below this are considered low).
pub low: OptionF32,
/// Optional "high" threshold (values above this are considered high).
pub high: OptionF32,
/// Optional optimum value within the range.
pub optimum: OptionF32,
/// Optional extended description.
pub description: OptionString,
}
impl_option!(
MeterAriaInfo,
OptionMeterAriaInfo,
copy = false,
[Debug, Clone, PartialEq]
);
impl MeterAriaInfo {
/// Creates a `MeterAriaInfo` with the required label and value/range triple.
#[must_use] pub const fn create(label: AzString, current_value: f32, min: f32, max: f32) -> Self {
Self {
label: OptionString::Some(label),
current_value,
min,
max,
low: OptionF32::None,
high: OptionF32::None,
optimum: OptionF32::None,
description: OptionString::None,
}
}
/// Returns a copy with the given low threshold.
#[must_use] pub const fn with_low(mut self, low: f32) -> Self {
self.low = OptionF32::Some(low);
self
}
/// Returns a copy with the given high threshold.
#[must_use] pub const fn with_high(mut self, high: f32) -> Self {
self.high = OptionF32::Some(high);
self
}
/// Returns a copy with the given optimum value.
#[must_use] pub const fn with_optimum(mut self, optimum: f32) -> Self {
self.optimum = OptionF32::Some(optimum);
self
}
/// Returns a copy with the given description.
#[must_use] pub fn with_description(mut self, desc: AzString) -> Self {
self.description = OptionString::Some(desc);
self
}
/// Convert to full `AccessibilityInfo` so the value can be installed on a node.
#[must_use] pub fn to_full_info(&self) -> AccessibilityInfo {
AccessibilityInfo {
accessibility_name: self.label.clone(),
accessibility_value: OptionString::Some(format!("{}", self.current_value).into()),
description: self.description.clone(),
role: AccessibilityRole::Indicator,
states: Vec::new().into(),
accelerator: OptionVirtualKeyCodeCombo::None,
default_action: OptionString::None,
supported_actions: Vec::new().into(),
is_live_region: false,
labelled_by: OptionDomNodeId::None,
described_by: OptionDomNodeId::None,
}
}
}
/// Accessibility information for a `<dialog>` element.
///
/// Captures the modal/non-modal distinction and a reference to a separate
/// node that describes the dialog (`aria-describedby`). The `role` defaults
/// to `AccessibilityRole::Dialog` but can be overridden (e.g., for alert
/// dialogs).
#[derive(Debug, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct DialogAriaInfo {
/// Accessible label / title for the dialog.
pub label: OptionString,
/// Optional ID of another node that describes the dialog content.
pub described_by: OptionString,
/// Optional inline description.
pub description: OptionString,
/// Role for the dialog. Defaults to `Dialog`; use `Alert` for urgent dialogs.
pub role: AccessibilityRole,
/// `true` if the dialog is modal (focus trapped, background inert).
pub modal: bool,
}
impl_option!(
DialogAriaInfo,
OptionDialogAriaInfo,
copy = false,
[Debug, Clone, PartialEq, Eq]
);
impl DialogAriaInfo {
/// Creates a `DialogAriaInfo` with the given accessible label. Defaults
/// to a non-modal dialog with role `Dialog`.
#[must_use] pub const fn create(label: AzString) -> Self {
Self {
label: OptionString::Some(label),
modal: false,
described_by: OptionString::None,
role: AccessibilityRole::Dialog,
description: OptionString::None,
}
}
/// Returns a copy with the given modality flag.
#[must_use] pub const fn with_modal(mut self, modal: bool) -> Self {
self.modal = modal;
self
}
/// Returns a copy with `aria-describedby` pointing at the given node ID.
#[must_use] pub fn with_described_by(mut self, described_by: AzString) -> Self {
self.described_by = OptionString::Some(described_by);
self
}
/// Returns a copy with the given role (defaults to `Dialog`).
#[must_use] pub const fn with_role(mut self, role: AccessibilityRole) -> Self {
self.role = role;
self
}
/// Returns a copy with the given inline description.
#[must_use] pub fn with_description(mut self, desc: AzString) -> Self {
self.description = OptionString::Some(desc);
self
}
/// Convert to full `AccessibilityInfo` so the value can be installed on a node.
#[must_use] pub fn to_full_info(&self) -> AccessibilityInfo {
AccessibilityInfo {
accessibility_name: self.label.clone(),
accessibility_value: OptionString::None,
description: self.description.clone(),
role: self.role,
states: Vec::new().into(),
accelerator: OptionVirtualKeyCodeCombo::None,
default_action: OptionString::None,
supported_actions: Vec::new().into(),
is_live_region: false,
labelled_by: OptionDomNodeId::None,
described_by: OptionDomNodeId::None,
}
}
}
#[cfg(test)]
mod autotest_generated {
use super::*;
use alloc::string::String;
// ---- small helpers to reach into the FFI-style option wrappers ----
fn name_str(o: &OptionString) -> Option<&str> {
o.as_ref().map(|s| s.as_str())
}
fn f32_of(o: &OptionF32) -> Option<f32> {
o.as_ref().copied()
}
/// A battery of adversarial strings: empty, embedded NUL, control chars,
/// combining unicode, emoji, RTL, and a very large allocation.
fn adversarial_strings() -> Vec<String> {
vec![
String::new(),
String::from(" "),
String::from("\0"),
String::from("a\0b\0c"),
String::from("\t\r\n\x1b[0m"),
String::from("日本語のテキスト"),
String::from("🎉👨👩👧👦🇺🇳"),
String::from("e\u{0301}\u{0301}\u{0301}"), // combining accents
String::from("\u{202e}reversed\u{202d}"), // RTL override
String::from("\u{FFFD}\u{10FFFF}"), // replacement + max scalar
"x".repeat(100_000), // huge
]
}
/// Numeric edge values for f32 fields.
fn adversarial_f32() -> Vec<f32> {
vec![
0.0,
-0.0,
1.0,
-1.0,
f32::MIN,
f32::MAX,
f32::MIN_POSITIVE,
-f32::MIN_POSITIVE,
f32::EPSILON,
f32::NAN,
f32::INFINITY,
f32::NEG_INFINITY,
]
}
// =====================================================================
// 1. SmallAriaInfo::label — no_panic_smoke
// =====================================================================
#[test]
fn small_label_no_panic_smoke() {
for s in adversarial_strings() {
let expected = s.clone();
let info = SmallAriaInfo::label(s);
// The label must round-trip verbatim and the other fields default to None.
assert_eq!(name_str(&info.label), Some(expected.as_str()));
assert!(info.role.is_none());
assert!(info.description.is_none());
// to_full_info must not panic even for pathological labels.
let full = info.to_full_info();
assert_eq!(name_str(&full.accessibility_name), Some(expected.as_str()));
}
// `&str` input path as well.
let info = SmallAriaInfo::label("hello");
assert_eq!(name_str(&info.label), Some("hello"));
}
// =====================================================================
// 2. SmallAriaInfo::with_role — no_panic + invariants
// =====================================================================
fn representative_roles() -> Vec<AccessibilityRole> {
vec![
AccessibilityRole::TitleBar, // first variant
AccessibilityRole::PushButton,
AccessibilityRole::CheckButton,
AccessibilityRole::Slider,
AccessibilityRole::Link,
AccessibilityRole::Nothing,
AccessibilityRole::Unknown, // last variant
]
}
#[test]
fn small_with_role_invariants() {
for role in representative_roles() {
let info = SmallAriaInfo::label("base").with_role(role);
// Only the role field changes; label preserved, description untouched.
assert_eq!(info.role, OptionAccessibilityRole::Some(role));
assert_eq!(name_str(&info.label), Some("base"));
assert!(info.description.is_none());
}
// Last-write-wins when applied twice.
let info = SmallAriaInfo::label("x")
.with_role(AccessibilityRole::Link)
.with_role(AccessibilityRole::Slider);
assert_eq!(info.role, OptionAccessibilityRole::Some(AccessibilityRole::Slider));
}
// =====================================================================
// 3. SmallAriaInfo::with_description — no_panic + invariants
// =====================================================================
#[test]
fn small_with_description_invariants() {
for s in adversarial_strings() {
let expected = s.clone();
let info = SmallAriaInfo::label("base").with_description(s);
assert_eq!(name_str(&info.description), Some(expected.as_str()));
// label untouched, role still None.
assert_eq!(name_str(&info.label), Some("base"));
assert!(info.role.is_none());
}
}
// =====================================================================
// 4. SmallAriaInfo::to_full_info — basic + edge
// =====================================================================
#[test]
fn small_to_full_info_basic() {
let info = SmallAriaInfo::label("Submit")
.with_role(AccessibilityRole::PushButton)
.with_description("primary action")
.to_full_info();
assert_eq!(name_str(&info.accessibility_name), Some("Submit"));
assert_eq!(info.role, AccessibilityRole::PushButton);
assert_eq!(name_str(&info.description), Some("primary action"));
assert!(info.accessibility_value.is_none());
assert_eq!(info.states.len(), 0);
assert_eq!(info.supported_actions.len(), 0);
assert!(!info.is_live_region);
assert!(info.labelled_by.is_none());
assert!(info.described_by.is_none());
}
#[test]
fn small_to_full_info_edge_missing_role_maps_to_unknown() {
// No role set => full info must fall back to `Unknown`, never panic.
let info = SmallAriaInfo::label("").to_full_info();
assert_eq!(info.role, AccessibilityRole::Unknown);
assert_eq!(name_str(&info.accessibility_name), Some(""));
assert!(info.description.is_none());
}
// =====================================================================
// 5. ProgressAriaInfo::create — no_panic_smoke
// =====================================================================
#[test]
fn progress_create_no_panic_smoke() {
for s in adversarial_strings() {
let expected = s.clone();
let p = ProgressAriaInfo::create(s.into());
assert_eq!(name_str(&p.label), Some(expected.as_str()));
// Documented defaults.
assert!(p.current_value.is_none());
assert!(p.max.is_none());
assert!(!p.indeterminate);
assert!(p.description.is_none());
}
}
// =====================================================================
// 6. ProgressAriaInfo::with_current_value — no_panic + invariants (numeric)
// =====================================================================
#[test]
fn progress_with_current_value_numeric() {
for v in adversarial_f32() {
let p = ProgressAriaInfo::create("p".into()).with_current_value(v);
match f32_of(&p.current_value) {
Some(got) if v.is_nan() => assert!(got.is_nan()),
Some(got) => assert_eq!(got, v),
None => panic!("current_value should be Some after with_current_value"),
}
// to_full_info must not panic for any float, and (since determinate)
// must emit a value string.
let full = p.to_full_info();
assert!(full.accessibility_value.is_some());
}
}
// =====================================================================
// 7. ProgressAriaInfo::with_max — no_panic + invariants (numeric)
// =====================================================================
#[test]
fn progress_with_max_numeric() {
for v in adversarial_f32() {
let p = ProgressAriaInfo::create("p".into()).with_max(v);
match f32_of(&p.max) {
Some(got) if v.is_nan() => assert!(got.is_nan()),
Some(got) => assert_eq!(got, v),
None => panic!("max should be Some after with_max"),
}
// max does not influence the value string; current_value stays None.
assert!(p.current_value.is_none());
}
}
// =====================================================================
// 8. ProgressAriaInfo::with_indeterminate — no_panic + invariants
// =====================================================================
#[test]
fn progress_with_indeterminate_invariants() {
for flag in [true, false] {
let p = ProgressAriaInfo::create("p".into()).with_indeterminate(flag);
assert_eq!(p.indeterminate, flag);
}
// indeterminate must override a present current_value in to_full_info.
let p = ProgressAriaInfo::create("p".into())
.with_current_value(0.5)
.with_indeterminate(true);
assert!(p.to_full_info().accessibility_value.is_none());
}
// =====================================================================
// 9. ProgressAriaInfo::with_description — no_panic + invariants
// =====================================================================
#[test]
fn progress_with_description_invariants() {
for s in adversarial_strings() {
let expected = s.clone();
let p = ProgressAriaInfo::create("p".into()).with_description(s.into());
assert_eq!(name_str(&p.description), Some(expected.as_str()));
assert_eq!(name_str(&p.label), Some("p"));
}
}
// =====================================================================
// 10. ProgressAriaInfo::to_full_info — basic + edge
// =====================================================================
#[test]
fn progress_to_full_info_basic() {
let info = ProgressAriaInfo::create("Loading".into())
.with_current_value(0.5)
.to_full_info();
assert_eq!(name_str(&info.accessibility_name), Some("Loading"));
assert_eq!(info.role, AccessibilityRole::ProgressBar);
assert_eq!(name_str(&info.accessibility_value), Some("0.5"));
assert_eq!(info.states.len(), 0);
assert_eq!(info.supported_actions.len(), 0);
}
#[test]
fn progress_to_full_info_edge() {
// No current value => value string is None.
let info = ProgressAriaInfo::create("x".into()).to_full_info();
assert!(info.accessibility_value.is_none());
assert_eq!(info.role, AccessibilityRole::ProgressBar);
// NaN / inf current values format to defined strings, no panic.
assert_eq!(
name_str(
&ProgressAriaInfo::create("x".into())
.with_current_value(f32::NAN)
.to_full_info()
.accessibility_value
),
Some("NaN")
);
assert_eq!(
name_str(
&ProgressAriaInfo::create("x".into())
.with_current_value(f32::INFINITY)
.to_full_info()
.accessibility_value
),
Some("inf")
);
assert_eq!(
name_str(
&ProgressAriaInfo::create("x".into())
.with_current_value(f32::NEG_INFINITY)
.to_full_info()
.accessibility_value
),
Some("-inf")
);
}
// =====================================================================
// 11. MeterAriaInfo::create — numeric (zero / min_max / negative / nan_inf)
// =====================================================================
#[test]
fn meter_create_zero() {
let m = MeterAriaInfo::create("z".into(), 0.0, 0.0, 0.0);
assert_eq!(m.current_value, 0.0);
assert_eq!(m.min, 0.0);
assert_eq!(m.max, 0.0);
assert_eq!(name_str(&m.to_full_info().accessibility_value), Some("0"));
}
#[test]
fn meter_create_min_max() {
let m = MeterAriaInfo::create("mm".into(), f32::MAX, f32::MIN, f32::MAX);
assert_eq!(m.current_value, f32::MAX);
assert_eq!(m.min, f32::MIN);
assert_eq!(m.max, f32::MAX);
// Formatting an extreme (but finite) float must not panic.
assert!(m.to_full_info().accessibility_value.is_some());
}
#[test]
fn meter_create_negative() {
let m = MeterAriaInfo::create("neg".into(), -5.0, -10.0, -1.0);
assert_eq!(m.current_value, -5.0);
assert_eq!(m.min, -10.0);
assert_eq!(m.max, -1.0);
assert_eq!(name_str(&m.to_full_info().accessibility_value), Some("-5"));
// Inverted range (min > max) is accepted verbatim; no panic, no clamping.
let inv = MeterAriaInfo::create("inv".into(), 5.0, 100.0, 0.0);
assert_eq!(inv.min, 100.0);
assert_eq!(inv.max, 0.0);
assert!(inv.to_full_info().accessibility_value.is_some());
}
#[test]
fn meter_create_overflow_saturates_to_inf() {
// f32 arithmetic saturates rather than panicking; feed the saturated
// result straight in and confirm formatting stays defined.
let over = f32::MAX * 2.0; // == +inf
assert!(over.is_infinite());
let m = MeterAriaInfo::create("o".into(), over, -over, over);
assert_eq!(name_str(&m.to_full_info().accessibility_value), Some("inf"));
}
#[test]
fn meter_create_nan_inf() {
// NaN preserved as NaN, no panic constructing or formatting.
let m = MeterAriaInfo::create("n".into(), f32::NAN, 0.0, 1.0);
assert!(m.current_value.is_nan());
assert_eq!(name_str(&m.to_full_info().accessibility_value), Some("NaN"));
let pos = MeterAriaInfo::create("n".into(), f32::INFINITY, 0.0, 1.0);
assert_eq!(name_str(&pos.to_full_info().accessibility_value), Some("inf"));
let neg = MeterAriaInfo::create("n".into(), f32::NEG_INFINITY, 0.0, 1.0);
assert_eq!(name_str(&neg.to_full_info().accessibility_value), Some("-inf"));
// Non-finite bounds must not panic either.
let bounds = MeterAriaInfo::create("n".into(), 0.5, f32::NEG_INFINITY, f32::INFINITY);
assert!(bounds.min.is_infinite());
assert!(bounds.max.is_infinite());
assert!(bounds.to_full_info().accessibility_value.is_some());
}
// =====================================================================
// 12-14. MeterAriaInfo::with_low / with_high / with_optimum — numeric invariants
// =====================================================================
#[test]
fn meter_with_low_high_optimum_numeric() {
for v in adversarial_f32() {
let m = MeterAriaInfo::create("m".into(), 0.5, 0.0, 1.0)
.with_low(v)
.with_high(v)
.with_optimum(v);
for opt in [&m.low, &m.high, &m.optimum] {
match f32_of(opt) {
Some(got) if v.is_nan() => assert!(got.is_nan()),
Some(got) => assert_eq!(got, v),
None => panic!("threshold should be Some after builder"),
}
}
// Core value/range untouched by the threshold builders.
assert_eq!(m.current_value, 0.5);
assert_eq!(m.min, 0.0);
assert_eq!(m.max, 1.0);
}
}
// =====================================================================
// 15. MeterAriaInfo::with_description — no_panic + invariants
// =====================================================================
#[test]
fn meter_with_description_invariants() {
for s in adversarial_strings() {
let expected = s.clone();
let m = MeterAriaInfo::create("m".into(), 1.0, 0.0, 2.0).with_description(s.into());
assert_eq!(name_str(&m.description), Some(expected.as_str()));
assert_eq!(m.current_value, 1.0);
}
}
// =====================================================================
// 16. MeterAriaInfo::to_full_info — basic + edge
// =====================================================================
#[test]
fn meter_to_full_info_basic() {
let info = MeterAriaInfo::create("Disk".into(), 42.0, 0.0, 100.0)
.with_description("usage".into())
.to_full_info();
assert_eq!(name_str(&info.accessibility_name), Some("Disk"));
assert_eq!(info.role, AccessibilityRole::Indicator);
assert_eq!(name_str(&info.accessibility_value), Some("42"));
assert_eq!(name_str(&info.description), Some("usage"));
assert_eq!(info.states.len(), 0);
assert_eq!(info.supported_actions.len(), 0);
}
#[test]
fn meter_to_full_info_edge() {
// Meter always emits a value string (unlike progress). Even for an
// extreme/empty-label instance it must not panic.
let info = MeterAriaInfo::create("".into(), f32::MIN, f32::MIN, f32::MAX).to_full_info();
assert!(info.accessibility_value.is_some());
assert_eq!(info.role, AccessibilityRole::Indicator);
assert_eq!(name_str(&info.accessibility_name), Some(""));
}
// =====================================================================
// 17. DialogAriaInfo::create — no_panic_smoke
// =====================================================================
#[test]
fn dialog_create_no_panic_smoke() {
for s in adversarial_strings() {
let expected = s.clone();
let d = DialogAriaInfo::create(s.into());
assert_eq!(name_str(&d.label), Some(expected.as_str()));
// Documented defaults: non-modal, role Dialog, no describers.
assert!(!d.modal);
assert_eq!(d.role, AccessibilityRole::Dialog);
assert!(d.described_by.is_none());
assert!(d.description.is_none());
}
}
// =====================================================================
// 18. DialogAriaInfo::with_modal — no_panic + invariants
// =====================================================================
#[test]
fn dialog_with_modal_invariants() {
for flag in [true, false] {
let d = DialogAriaInfo::create("t".into()).with_modal(flag);
assert_eq!(d.modal, flag);
// Unrelated fields keep their defaults.
assert_eq!(d.role, AccessibilityRole::Dialog);
assert_eq!(name_str(&d.label), Some("t"));
}
}
// =====================================================================
// 19. DialogAriaInfo::with_described_by — no_panic + invariants
// =====================================================================
#[test]
fn dialog_with_described_by_invariants() {
for s in adversarial_strings() {
let expected = s.clone();
let d = DialogAriaInfo::create("t".into()).with_described_by(s.into());
assert_eq!(name_str(&d.described_by), Some(expected.as_str()));
assert_eq!(name_str(&d.label), Some("t"));
}
}
// =====================================================================
// 20. DialogAriaInfo::with_role — no_panic + invariants
// =====================================================================
#[test]
fn dialog_with_role_invariants() {
for role in representative_roles() {
let d = DialogAriaInfo::create("t".into()).with_role(role);
assert_eq!(d.role, role);
assert!(!d.modal);
}
// to_full_info propagates the overridden role verbatim.
let info = DialogAriaInfo::create("t".into())
.with_role(AccessibilityRole::Alert)
.to_full_info();
assert_eq!(info.role, AccessibilityRole::Alert);
}
// =====================================================================
// 21. DialogAriaInfo::with_description — no_panic + invariants
// =====================================================================
#[test]
fn dialog_with_description_invariants() {
for s in adversarial_strings() {
let expected = s.clone();
let d = DialogAriaInfo::create("t".into()).with_description(s.into());
assert_eq!(name_str(&d.description), Some(expected.as_str()));
assert_eq!(name_str(&d.label), Some("t"));
}
}
// =====================================================================
// 22. DialogAriaInfo::to_full_info — basic + edge
// =====================================================================
#[test]
fn dialog_to_full_info_basic() {
let info = DialogAriaInfo::create("Confirm".into())
.with_modal(true)
.with_role(AccessibilityRole::Alert)
.with_described_by("body-node".into())
.with_description("Are you sure?".into())
.to_full_info();
assert_eq!(name_str(&info.accessibility_name), Some("Confirm"));
assert_eq!(info.role, AccessibilityRole::Alert);
assert_eq!(name_str(&info.description), Some("Are you sure?"));
// The string `described_by` node-ref is NOT propagated into the DomNodeId field.
assert!(info.described_by.is_none());
assert!(info.labelled_by.is_none());
assert!(info.accessibility_value.is_none());
assert_eq!(info.states.len(), 0);
assert_eq!(info.supported_actions.len(), 0);
}
#[test]
fn dialog_to_full_info_edge() {
// Default (non-modal, empty) instance must convert without panic.
let info = DialogAriaInfo::create("".into()).to_full_info();
assert_eq!(info.role, AccessibilityRole::Dialog);
assert_eq!(name_str(&info.accessibility_name), Some(""));
assert!(info.description.is_none());
}
// #####################################################################
// Appended: round-trip, total-order and FFI-vec coverage.
//
// The block above exercises the 22 listed builder/getter fns. What it
// does NOT cover is the machinery those fns feed into: the FFI vec/option
// wrappers, and the `Eq`/`Ord`/`Hash` impls that `AccessibilityInfo`
// derives *through* f32-carrying payloads (`LogicalPosition`,
// `FloatValue`). Those derives are where a total-order contract can
// silently break, so they get the adversarial treatment here.
// #####################################################################
use core::hash::{Hash, Hasher};
use crate::{
dom::{DomId, DomNodeId},
styled_dom::NodeHierarchyItemId,
};
/// FNV-1a. Hand-rolled rather than `DefaultHasher` so these tests still
/// build when azul-core is compiled `--no-default-features` (i.e. `no_std`,
/// where `std::collections::hash_map` does not exist).
struct Fnv(u64);
impl Default for Fnv {
fn default() -> Self {
Self(0xcbf2_9ce4_8422_2325) // offset basis
}
}
impl Hasher for Fnv {
fn finish(&self) -> u64 {
self.0
}
fn write(&mut self, bytes: &[u8]) {
for b in bytes {
self.0 ^= u64::from(*b);
self.0 = self.0.wrapping_mul(0x0000_0100_0000_01b3); // FNV prime
}
}
}
fn hash_of<T: Hash>(t: &T) -> u64 {
let mut h = Fnv::default();
t.hash(&mut h);
h.finish()
}
/// Every `AccessibilityRole`, in declaration order.
///
/// `Ord` is derived, so declaration order *is* the sort order — the tests
/// below pin that. Kept in sync with the enum by `role_exhaustiveness_canary`.
fn all_roles() -> Vec<AccessibilityRole> {
use AccessibilityRole::*;
vec![
TitleBar, MenuBar, ScrollBar, Grip, Sound, Cursor, Caret, Alert, Window, Client,
MenuPopup, MenuItem, Tooltip, Application, Document, Pane, Chart, Dialog, Border,
Grouping, Separator, Toolbar, StatusBar, Table, ColumnHeader, RowHeader, Column, Row,
Cell, Link, HelpBalloon, Character, List, ListItem, Outline, OutlineItem, PageTab,
PropertyPage, Indicator, Graphic, StaticText, Text, PushButton, CheckButton,
RadioButton, ComboBox, DropList, ProgressBar, Dial, HotkeyField, Slider, SpinButton,
Diagram, Animation, Equation, ButtonDropdown, ButtonMenu, ButtonDropdownGrid,
Whitespace, PageTabList, Clock, SplitButton, IpAddress, Nothing, Unknown,
]
}
/// Every `AccessibilityState`, in declaration order.
fn all_states() -> Vec<AccessibilityState> {
use AccessibilityState::*;
vec![
Unavailable, Selected, Focused, CheckedTrue, CheckedFalse, Readonly, Default, Expanded,
Collapsed, Busy, Offscreen, Focusable, Selectable, Linked, Traversed, Multiselectable,
Protected,
]
}
/// Exhaustive `match`es: if a variant is added upstream without being added
/// to `all_roles()` / `all_states()`, this stops compiling. That is the
/// point — it keeps the ordering tests below honest instead of letting them
/// silently degrade into partial coverage.
#[test]
fn role_exhaustiveness_canary() {
use AccessibilityRole::*;
for r in all_roles() {
let known = match r {
TitleBar | MenuBar | ScrollBar | Grip | Sound | Cursor | Caret | Alert | Window
| Client | MenuPopup | MenuItem | Tooltip | Application | Document | Pane | Chart
| Dialog | Border | Grouping | Separator | Toolbar | StatusBar | Table
| ColumnHeader | RowHeader | Column | Row | Cell | Link | HelpBalloon | Character
| List | ListItem | Outline | OutlineItem | PageTab | PropertyPage | Indicator
| Graphic | StaticText | Text | PushButton | CheckButton | RadioButton | ComboBox
| DropList | ProgressBar | Dial | HotkeyField | Slider | SpinButton | Diagram
| Animation | Equation | ButtonDropdown | ButtonMenu | ButtonDropdownGrid
| Whitespace | PageTabList | Clock | SplitButton | IpAddress | Nothing | Unknown => true,
};
assert!(known);
}
use AccessibilityState::*;
for s in all_states() {
let known = match s {
Unavailable | Selected | Focused | CheckedTrue | CheckedFalse | Readonly
| Default | Expanded | Collapsed | Busy | Offscreen | Focusable | Selectable
| Linked | Traversed | Multiselectable | Protected => true,
};
assert!(known);
}
}
// =====================================================================
// Total-order / Eq / Hash contracts on the plain C-like enums
// =====================================================================
#[test]
fn role_ord_is_strict_declaration_order() {
let roles = all_roles();
// Strictly increasing => derived Ord follows declaration order AND the
// list has no duplicates.
for pair in roles.windows(2) {
assert!(
pair[0] < pair[1],
"roles must sort in declaration order: {:?} !< {:?}",
pair[0],
pair[1]
);
}
// Trichotomy: for every ordered pair exactly one of <, ==, > holds.
for a in &roles {
for b in &roles {
let lt = a < b;
let eq = a == b;
let gt = a > b;
assert_eq!(
u8::from(lt) + u8::from(eq) + u8::from(gt),
1,
"trichotomy violated for {a:?} vs {b:?}"
);
}
}
// Reflexivity + the documented endpoints.
assert_eq!(roles[0], AccessibilityRole::TitleBar);
assert_eq!(*roles.last().unwrap(), AccessibilityRole::Unknown);
assert!(AccessibilityRole::TitleBar < AccessibilityRole::Unknown);
}
#[test]
fn state_ord_is_strict_declaration_order() {
let states = all_states();
for pair in states.windows(2) {
assert!(pair[0] < pair[1], "{:?} !< {:?}", pair[0], pair[1]);
}
// CheckedTrue / CheckedFalse are adjacent but must never compare equal —
// aliasing them would make a checked and unchecked box indistinguishable.
assert_ne!(AccessibilityState::CheckedTrue, AccessibilityState::CheckedFalse);
assert_ne!(
hash_of(&AccessibilityState::CheckedTrue),
hash_of(&AccessibilityState::CheckedFalse)
);
}
#[test]
fn role_and_state_hash_agrees_with_eq() {
// Eq => equal hashes (the direction the Hash contract actually requires),
// and Hash is deterministic across calls.
for r in all_roles() {
let copy = r;
assert_eq!(hash_of(&r), hash_of(©));
}
for s in all_states() {
let copy = s;
assert_eq!(hash_of(&s), hash_of(©));
}
// Stronger: no two distinct variants may collide. A collision here would
// let two different roles/states alias as the same HashMap key. The
// derive hashes the (necessarily distinct) discriminant, and FNV-1a's
// multiply step is invertible mod 2^64, so distinctness is guaranteed —
// this pins that no variant is ever given a duplicate discriminant.
let role_hashes: Vec<u64> = all_roles().iter().map(hash_of).collect();
for (i, a) in role_hashes.iter().enumerate() {
for (j, b) in role_hashes.iter().enumerate() {
assert_eq!(i == j, a == b, "role hash collision at {i}/{j}");
}
}
let state_hashes: Vec<u64> = all_states().iter().map(hash_of).collect();
for (i, a) in state_hashes.iter().enumerate() {
for (j, b) in state_hashes.iter().enumerate() {
assert_eq!(i == j, a == b, "state hash collision at {i}/{j}");
}
}
}
// =====================================================================
// AccessibilityStateVec — FFI vec round-trip
// =====================================================================
#[test]
fn state_vec_round_trips_through_ffi_wrapper() {
let cases: Vec<Vec<AccessibilityState>> = vec![
Vec::new(),
vec![AccessibilityState::Focused],
all_states(),
// duplicates must survive verbatim (this is a Vec, not a Set)
vec![
AccessibilityState::Busy,
AccessibilityState::Busy,
AccessibilityState::Busy,
],
// large allocation: the FFI wrapper owns the buffer, so this is the
// shape most likely to trip a bad len/cap or double-free.
core::iter::repeat(AccessibilityState::Selected).take(10_000).collect(),
];
for original in cases {
let wrapped: AccessibilityStateVec = original.clone().into();
// len / is_empty stay consistent with the source Vec.
assert_eq!(wrapped.len(), original.len());
assert_eq!(wrapped.is_empty(), original.is_empty());
assert_eq!(wrapped.as_slice(), original.as_slice());
assert_eq!(wrapped.iter().count(), original.len());
// Clone must deep-copy: equal content, and dropping the clone must
// not invalidate the original (both are dropped at end of scope).
let cloned = wrapped.clone();
assert_eq!(cloned.as_slice(), original.as_slice());
assert_eq!(cloned, wrapped);
assert_eq!(hash_of(&cloned), hash_of(&wrapped));
drop(cloned);
assert_eq!(wrapped.as_slice(), original.as_slice());
// Round-trip back out: decode(encode(x)) == x.
let back = wrapped.into_library_owned_vec();
assert_eq!(back, original);
}
}
#[test]
fn state_vec_indexing_is_bounds_safe() {
let v: AccessibilityStateVec = all_states().into();
let len = v.len();
for (i, expected) in all_states().into_iter().enumerate() {
assert_eq!(v.get(i), Some(&expected));
}
// One-past-the-end and the pathological index must return None, not panic.
assert_eq!(v.get(len), None);
assert_eq!(v.get(len + 1), None);
assert_eq!(v.get(usize::MAX), None);
assert!(v.c_get(usize::MAX).is_none());
assert!(v.c_get(len).is_none());
assert!(v.c_get(0).is_some());
// The empty vec has no valid index at all.
let empty = AccessibilityStateVec::new();
assert!(empty.is_empty());
assert_eq!(empty.get(0), None);
assert_eq!(empty.get(usize::MAX), None);
assert!(empty.c_get(0).is_none());
}
#[test]
fn state_vec_from_vec_preserves_order_len_and_lookup() {
// The C-ABI vec is built from a Rust Vec and is then read-only — it has
// no push/pop. Assert the round-trip is lossless and lookups agree.
let empty = AccessibilityStateVec::new();
assert_eq!(empty.len(), 0);
assert!(empty.is_empty());
assert_eq!(empty.get(0), None);
let states = all_states();
let v = AccessibilityStateVec::from_vec(states.clone());
assert_eq!(v.len(), states.len());
assert!(!v.is_empty());
assert!(v.capacity() >= v.len(), "capacity must never trail len");
// Order is preserved and every index is reachable.
assert_eq!(v.as_slice(), states.as_slice());
for (i, s) in states.iter().enumerate() {
assert_eq!(v.get(i), Some(s));
}
assert_eq!(
v.get(states.len()),
None,
"out-of-bounds must be None, not a panic"
);
assert!(v.iter().eq(states.iter()));
}
// =====================================================================
// AccessibilityAction — payload-carrying variants
// =====================================================================
/// One instance of every `AccessibilityAction` variant, in declaration order.
fn all_actions() -> Vec<AccessibilityAction> {
use AccessibilityAction::*;
vec![
Default,
Focus,
Blur,
Collapse,
Expand,
ScrollIntoView,
Increment,
Decrement,
ShowContextMenu,
HideTooltip,
ShowTooltip,
ScrollUp,
ScrollDown,
ScrollLeft,
ScrollRight,
ReplaceSelectedText("replacement".into()),
ScrollToPoint(LogicalPosition::new(1.0, 2.0)),
SetScrollOffset(LogicalPosition::new(-3.0, 4.0)),
SetTextSelection(TextSelectionStartEnd {
selection_start: 0,
selection_end: 5,
}),
SetSequentialFocusNavigationStartingPoint,
SetValue("value".into()),
SetNumericValue(FloatValue::new(1.5)),
CustomAction(42),
]
}
#[test]
fn action_vec_round_trips_with_payloads() {
let original = all_actions();
let wrapped: AccessibilityActionVec = original.clone().into();
assert_eq!(wrapped.len(), original.len());
assert_eq!(wrapped.as_slice(), original.as_slice());
// The payload variants own heap data (AzString). Cloning must deep-copy;
// dropping the clone must leave the original intact (no double-free).
let cloned = wrapped.clone();
assert_eq!(cloned, wrapped);
assert_eq!(hash_of(&cloned), hash_of(&wrapped));
drop(cloned);
assert_eq!(wrapped.as_slice(), original.as_slice());
let back = wrapped.into_library_owned_vec();
assert_eq!(back, original);
// Variant order dominates payload in the derived Ord.
for pair in original.windows(2) {
assert!(pair[0] < pair[1], "{:?} !< {:?}", pair[0], pair[1]);
}
}
#[test]
fn action_string_payloads_survive_adversarial_strings() {
for s in adversarial_strings() {
let expected = s.clone();
let replace = AccessibilityAction::ReplaceSelectedText(s.clone().into());
let set = AccessibilityAction::SetValue(s.into());
// Payload preserved verbatim — including interior NUL and lone
// combining marks, which a C-string round-trip would truncate.
match &replace {
AccessibilityAction::ReplaceSelectedText(got) => {
assert_eq!(got.as_str(), expected.as_str());
assert_eq!(got.as_str().len(), expected.len());
}
other => panic!("wrong variant: {other:?}"),
}
match &set {
AccessibilityAction::SetValue(got) => assert_eq!(got.as_str(), expected.as_str()),
other => panic!("wrong variant: {other:?}"),
}
// Clone/Eq/Hash agree even for the pathological payloads.
assert_eq!(replace.clone(), replace);
assert_eq!(hash_of(&replace.clone()), hash_of(&replace));
// Different variants with the *same* payload must never alias.
assert_ne!(replace, set);
}
}
#[test]
fn action_custom_action_i32_limits() {
let min = AccessibilityAction::CustomAction(i32::MIN);
let zero = AccessibilityAction::CustomAction(0);
let max = AccessibilityAction::CustomAction(i32::MAX);
// Signed ordering, not a bit-pattern/unsigned ordering.
assert!(min < zero, "i32::MIN must sort below 0");
assert!(zero < max);
assert!(min < max);
assert_eq!(min, AccessibilityAction::CustomAction(i32::MIN));
assert_ne!(min, max);
assert_eq!(hash_of(&min), hash_of(&AccessibilityAction::CustomAction(i32::MIN)));
// -1 must not alias u32::MAX-style onto anything.
assert_ne!(
AccessibilityAction::CustomAction(-1),
AccessibilityAction::CustomAction(i32::MAX)
);
}
#[test]
fn text_selection_start_end_limits() {
// usize::MAX bounds: constructing and comparing must not overflow.
let huge = TextSelectionStartEnd {
selection_start: usize::MAX,
selection_end: usize::MAX,
};
assert_eq!(huge.selection_start, usize::MAX);
assert_eq!(huge.selection_end, usize::MAX);
assert_eq!(huge, huge);
// Inverted range (start > end) is accepted verbatim — the type does not
// normalise or clamp, so downstream consumers must not assume start<=end.
let inverted = TextSelectionStartEnd {
selection_start: 10,
selection_end: 0,
};
assert_eq!(inverted.selection_start, 10);
assert_eq!(inverted.selection_end, 0);
assert_ne!(
inverted,
TextSelectionStartEnd {
selection_start: 0,
selection_end: 10,
}
);
// Collapsed (zero-length) selection is distinct from an empty-at-zero one.
let collapsed = TextSelectionStartEnd {
selection_start: 7,
selection_end: 7,
};
assert_ne!(
collapsed,
TextSelectionStartEnd {
selection_start: 0,
selection_end: 0,
}
);
// Ord is lexicographic (start, then end).
let a = TextSelectionStartEnd {
selection_start: 1,
selection_end: 99,
};
let b = TextSelectionStartEnd {
selection_start: 2,
selection_end: 0,
};
assert!(a < b, "selection_start must dominate the ordering");
// Wrapped in the action, the same invariants hold.
let action = AccessibilityAction::SetTextSelection(huge);
assert_eq!(action.clone(), action);
assert_eq!(hash_of(&action.clone()), hash_of(&action));
}
// =====================================================================
// f32-carrying payloads: the Eq/Ord/Hash total-order contract
//
// `AccessibilityAction` *derives* Eq + Ord + Hash while carrying
// `LogicalPosition` (two f32s) and `FloatValue`. f32 is not Eq/Ord, so
// those inner types must supply total impls. These tests pin the actual
// behaviour at NaN / inf / overflow, where a naive impl breaks the
// reflexivity (a == a) that HashMap and BTreeMap rely on.
// =====================================================================
#[test]
fn scroll_to_point_nan_is_reflexive_and_totally_ordered() {
let nan = AccessibilityAction::ScrollToPoint(LogicalPosition::new(f32::NAN, f32::NAN));
let origin = AccessibilityAction::ScrollToPoint(LogicalPosition::new(0.0, 0.0));
// Reflexivity: `Eq` promises a == a. Raw f32 PartialEq would return
// false here and quietly corrupt any HashMap keyed on this action.
assert_eq!(nan, nan.clone());
assert_eq!(hash_of(&nan), hash_of(&nan.clone()));
assert_eq!(nan.cmp(&nan.clone()), core::cmp::Ordering::Equal);
// NaN must NOT alias onto the origin (LogicalPosition::quantize maps NaN
// to a dedicated i64::MIN sentinel precisely to avoid that collision).
assert_ne!(nan, origin);
assert_ne!(hash_of(&nan), hash_of(&origin));
assert!(nan < origin, "NaN sorts below every real coordinate");
// Ord is total: every pair of these is comparable and antisymmetric.
let neg = AccessibilityAction::ScrollToPoint(LogicalPosition::new(-1.0, -1.0));
let pos = AccessibilityAction::ScrollToPoint(LogicalPosition::new(1.0, 1.0));
let mut sorted = vec![pos.clone(), origin.clone(), nan.clone(), neg.clone()];
sorted.sort();
assert_eq!(sorted, vec![nan, neg, origin, pos]);
}
#[test]
fn scroll_to_point_infinite_coords_saturate_without_panic() {
let inf = AccessibilityAction::SetScrollOffset(LogicalPosition::new(
f32::INFINITY,
f32::NEG_INFINITY,
));
let finite = AccessibilityAction::SetScrollOffset(LogicalPosition::new(1.0, 1.0));
// Defined, reflexive, no panic on the fixed-point conversion.
assert_eq!(inf, inf.clone());
assert_eq!(hash_of(&inf), hash_of(&inf.clone()));
assert!(inf > finite, "+inf x-coordinate must sort above a finite one");
// Documented saturation: the fixed-point quantisation clamps, so
// f32::MAX and +inf land in the same bucket. Asserted so a future
// change to the quantiser has to consciously break this.
let max = AccessibilityAction::SetScrollOffset(LogicalPosition::new(f32::MAX, f32::MAX));
let plus_inf =
AccessibilityAction::SetScrollOffset(LogicalPosition::new(f32::INFINITY, f32::INFINITY));
assert_eq!(
max, plus_inf,
"f32::MAX and +inf both saturate to the same quantised coordinate"
);
}
#[test]
fn set_numeric_value_float_edges_are_defined() {
// Representable-under-quantisation values round-trip exactly
// (FloatValue is fixed-point with a 1/1000 quantum).
for v in [0.0_f32, 1.5, -1.5, 2.25, -3.75, 1000.0] {
let f = FloatValue::new(v);
assert_eq!(f.get(), v, "FloatValue must round-trip {v}");
let action = AccessibilityAction::SetNumericValue(f);
assert_eq!(action.clone(), action);
}
// Non-finite input must not panic. `as isize` saturates, so:
assert_eq!(FloatValue::new(f32::INFINITY).number(), isize::MAX);
assert_eq!(FloatValue::new(f32::NEG_INFINITY).number(), isize::MIN);
// NOTE (reported, not a weakened assertion): FloatValue::new maps NaN to
// 0 via a raw `as isize` cast, so a NaN numeric value is INDISTINGUISHABLE
// from 0.0. LogicalPosition::quantize explicitly fixed this same aliasing
// (NaN -> i64::MIN sentinel); FloatValue still has it. Pinning the current
// behaviour so the aliasing is visible and a fix has to update this test.
assert_eq!(FloatValue::new(f32::NAN).number(), 0);
assert_eq!(
AccessibilityAction::SetNumericValue(FloatValue::new(f32::NAN)),
AccessibilityAction::SetNumericValue(FloatValue::new(0.0)),
"KNOWN ALIASING: NaN numeric value collides with 0.0"
);
// Reflexivity still holds for the NaN case (it is Eq-safe, just aliased).
let nan_action = AccessibilityAction::SetNumericValue(FloatValue::new(f32::NAN));
assert_eq!(hash_of(&nan_action), hash_of(&nan_action.clone()));
// f32::MAX overflows the fixed-point scale and saturates rather than wrapping.
assert_eq!(FloatValue::new(f32::MAX).number(), isize::MAX);
assert_eq!(FloatValue::new(f32::MIN).number(), isize::MIN);
}
// =====================================================================
// Float -> value-string encoding: format/parse round-trip
// =====================================================================
#[test]
fn progress_value_string_round_trips_through_parse() {
for v in adversarial_f32() {
let full = ProgressAriaInfo::create("p".into())
.with_current_value(v)
.to_full_info();
let s = name_str(&full.accessibility_value).expect("determinate => Some");
if v.is_nan() {
assert_eq!(s, "NaN");
assert!(s.parse::<f32>().unwrap().is_nan());
} else if v.is_infinite() {
assert_eq!(s, if v > 0.0 { "inf" } else { "-inf" });
} else {
// Display for f32 is shortest-round-trip: decode(encode(v)) == v.
let parsed: f32 = s.parse().expect("emitted value string must re-parse");
assert_eq!(parsed, v, "round-trip failed for {v} via {s:?}");
if v != 0.0 {
// Bit-exact for everything except +0.0/-0.0, which compare
// equal under `==` by definition.
assert_eq!(parsed.to_bits(), v.to_bits(), "lossy round-trip for {v}");
}
}
}
}
#[test]
fn meter_value_string_round_trips_through_parse() {
for v in adversarial_f32() {
let full = MeterAriaInfo::create("m".into(), v, 0.0, 1.0).to_full_info();
// Meter ALWAYS emits a value string (unlike progress).
let s = name_str(&full.accessibility_value).expect("meter always emits a value");
if v.is_nan() {
assert_eq!(s, "NaN");
} else if v.is_infinite() {
assert_eq!(s, if v > 0.0 { "inf" } else { "-inf" });
} else {
let parsed: f32 = s.parse().expect("emitted value string must re-parse");
assert_eq!(parsed, v);
if v != 0.0 {
assert_eq!(parsed.to_bits(), v.to_bits());
}
}
}
}
// =====================================================================
// Builder algebra: purity, idempotence, last-write-wins, order-independence
// =====================================================================
#[test]
fn to_full_info_is_pure_and_idempotent() {
let small = SmallAriaInfo::label("s")
.with_role(AccessibilityRole::Slider)
.with_description("d");
let progress = ProgressAriaInfo::create("p".into())
.with_current_value(0.25)
.with_max(10.0);
let meter = MeterAriaInfo::create("m".into(), 1.0, 0.0, 2.0).with_low(0.5);
let dialog = DialogAriaInfo::create("d".into()).with_modal(true);
// &self getters must not mutate the receiver, and must be deterministic:
// f(x) == f(x) for repeated calls.
let (s0, p0, m0, d0) = (small.clone(), progress.clone(), meter.clone(), dialog.clone());
assert_eq!(small.to_full_info(), small.to_full_info());
assert_eq!(progress.to_full_info(), progress.to_full_info());
assert_eq!(meter.to_full_info(), meter.to_full_info());
assert_eq!(dialog.to_full_info(), dialog.to_full_info());
assert_eq!(small, s0, "to_full_info must not mutate SmallAriaInfo");
assert_eq!(progress, p0, "to_full_info must not mutate ProgressAriaInfo");
assert_eq!(meter, m0, "to_full_info must not mutate MeterAriaInfo");
assert_eq!(dialog, d0, "to_full_info must not mutate DialogAriaInfo");
// Idempotent even when the value is NaN — the AccessibilityInfo carries a
// *string* ("NaN"), which is Eq-comparable, so this holds where a raw f32
// comparison would not.
let nan_meter = MeterAriaInfo::create("m".into(), f32::NAN, 0.0, 1.0);
assert_eq!(nan_meter.to_full_info(), nan_meter.to_full_info());
}
#[test]
fn progress_max_is_never_surfaced_in_full_info() {
// `max` has no representation in AccessibilityInfo, so setting it to
// anything at all — including inf/NaN — must not perturb the conversion.
let baseline = ProgressAriaInfo::create("p".into())
.with_current_value(0.5)
.to_full_info();
for v in adversarial_f32() {
let with_max = ProgressAriaInfo::create("p".into())
.with_current_value(0.5)
.with_max(v)
.to_full_info();
assert_eq!(with_max, baseline, "with_max({v}) leaked into to_full_info");
}
}
#[test]
fn meter_threshold_builders_are_order_independent_and_last_write_wins() {
// Order-independence: the three threshold setters touch disjoint fields.
let a = MeterAriaInfo::create("m".into(), 0.5, 0.0, 1.0)
.with_low(0.1)
.with_high(0.9)
.with_optimum(0.7);
let b = MeterAriaInfo::create("m".into(), 0.5, 0.0, 1.0)
.with_optimum(0.7)
.with_high(0.9)
.with_low(0.1);
assert_eq!(a, b);
// Last-write-wins, including when the second write is a non-finite value.
let m = MeterAriaInfo::create("m".into(), 0.5, 0.0, 1.0)
.with_low(0.1)
.with_low(f32::INFINITY);
assert_eq!(f32_of(&m.low), Some(f32::INFINITY));
// Nonsensical-but-accepted config: low > high, optimum outside [min,max].
// The type performs no validation; assert it stores them verbatim rather
// than silently clamping (downstream code must do its own validation).
let weird = MeterAriaInfo::create("m".into(), 5.0, 0.0, 1.0)
.with_low(100.0)
.with_high(-100.0)
.with_optimum(-1.0);
assert_eq!(f32_of(&weird.low), Some(100.0));
assert_eq!(f32_of(&weird.high), Some(-100.0));
assert_eq!(f32_of(&weird.optimum), Some(-1.0));
assert_eq!(weird.current_value, 5.0); // out of [min,max], not clamped
assert!(weird.to_full_info().accessibility_value.is_some());
}
#[test]
fn progress_and_dialog_builders_last_write_wins() {
let p = ProgressAriaInfo::create("p".into())
.with_current_value(1.0)
.with_current_value(2.0)
.with_indeterminate(true)
.with_indeterminate(false)
.with_description("a".into())
.with_description("b".into());
assert_eq!(f32_of(&p.current_value), Some(2.0));
assert!(!p.indeterminate);
assert_eq!(name_str(&p.description), Some("b"));
// Not indeterminate => the (last) current value is surfaced.
assert_eq!(name_str(&p.to_full_info().accessibility_value), Some("2"));
let d = DialogAriaInfo::create("d".into())
.with_modal(true)
.with_modal(false)
.with_role(AccessibilityRole::Alert)
.with_role(AccessibilityRole::Dialog)
.with_described_by("x".into())
.with_described_by("y".into());
assert!(!d.modal);
assert_eq!(d.role, AccessibilityRole::Dialog);
assert_eq!(name_str(&d.described_by), Some("y"));
}
// =====================================================================
// AccessibilityInfo — the fully-populated aggregate
// =====================================================================
fn full_info_fixture() -> AccessibilityInfo {
AccessibilityInfo {
accessibility_name: OptionString::Some("name".into()),
accessibility_value: OptionString::Some("value".into()),
description: OptionString::Some("desc".into()),
accelerator: OptionVirtualKeyCodeCombo::None,
default_action: OptionString::Some("activate".into()),
states: all_states().into(),
supported_actions: all_actions().into(),
labelled_by: OptionDomNodeId::Some(DomNodeId::ROOT),
described_by: OptionDomNodeId::Some(DomNodeId {
dom: DomId { inner: 3 },
node: NodeHierarchyItemId::from_raw(7),
}),
role: AccessibilityRole::PushButton,
is_live_region: true,
}
}
#[test]
fn full_info_clone_eq_hash_ord_are_consistent() {
let a = full_info_fixture();
let b = a.clone();
// Deep clone: equal, equally hashed, mutually Equal under Ord.
assert_eq!(a, b);
assert_eq!(hash_of(&a), hash_of(&b));
assert_eq!(a.cmp(&b), core::cmp::Ordering::Equal);
// The clone owns its own heap buffers — dropping it must leave `a` intact.
drop(b);
assert_eq!(a.states.len(), all_states().len());
assert_eq!(a.supported_actions.len(), all_actions().len());
assert_eq!(name_str(&a.accessibility_name), Some("name"));
// Perturbing any single field must break equality (no field is ignored
// by the derived PartialEq — a field silently dropped from the derive
// would let two different a11y nodes compare equal).
let mut differs = a.clone();
differs.is_live_region = false;
assert_ne!(a, differs);
let mut differs = a.clone();
differs.role = AccessibilityRole::Unknown;
assert_ne!(a, differs);
let mut differs = a.clone();
differs.labelled_by = OptionDomNodeId::None;
assert_ne!(a, differs);
let mut differs = a.clone();
differs.states = Vec::new().into();
assert_ne!(a, differs);
let mut differs = a.clone();
differs.supported_actions = Vec::new().into();
assert_ne!(a, differs);
let mut differs = a.clone();
differs.default_action = OptionString::None;
assert_ne!(a, differs);
}
// =====================================================================
// Option<T> FFI wrappers — Some/None round-trip
// =====================================================================
#[test]
fn option_wrappers_round_trip() {
// Copy payloads.
for r in all_roles() {
let opt = OptionAccessibilityRole::Some(r);
assert!(opt.is_some());
assert!(!opt.is_none());
assert_eq!(opt.as_ref(), Some(&r));
assert_eq!(opt.into_option(), Some(r));
}
assert!(OptionAccessibilityRole::None.is_none());
assert_eq!(OptionAccessibilityRole::None.into_option(), None);
for s in all_states() {
assert_eq!(OptionAccessibilityState::Some(s).into_option(), Some(s));
}
assert_eq!(OptionAccessibilityState::None.into_option(), None);
// Non-Copy payloads (heap-owning) must round-trip without a double-free.
for a in all_actions() {
let opt = OptionAccessibilityAction::Some(a.clone());
assert!(opt.is_some());
assert_eq!(opt.into_option(), Some(a));
}
assert!(OptionAccessibilityAction::None.is_none());
let small = SmallAriaInfo::label("s").with_role(AccessibilityRole::Link);
assert_eq!(
OptionSmallAriaInfo::Some(small.clone()).into_option(),
Some(small)
);
assert!(OptionSmallAriaInfo::None.is_none());
let progress = ProgressAriaInfo::create("p".into()).with_current_value(0.5);
assert_eq!(
OptionProgressAriaInfo::Some(progress.clone()).into_option(),
Some(progress)
);
let meter = MeterAriaInfo::create("m".into(), 1.0, 0.0, 2.0);
assert_eq!(
OptionMeterAriaInfo::Some(meter.clone()).into_option(),
Some(meter)
);
let dialog = DialogAriaInfo::create("d".into()).with_modal(true);
assert_eq!(
OptionDialogAriaInfo::Some(dialog.clone()).into_option(),
Some(dialog)
);
// The big aggregate, which owns two FFI vecs.
let info = full_info_fixture();
assert_eq!(
OptionAccessibilityInfo::Some(info.clone()).into_option(),
Some(info)
);
assert!(OptionAccessibilityInfo::None.is_none());
}
}