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
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsAccessibilityService.h"
// NOTE: alphabetically ordered
#include "ApplicationAccessibleWrap.h"
#include "ARIAGridAccessibleWrap.h"
#include "ARIAMap.h"
#include "DocAccessible-inl.h"
#include "FocusManager.h"
#include "HTMLCanvasAccessible.h"
#include "HTMLElementAccessibles.h"
#include "HTMLImageMapAccessible.h"
#include "HTMLLinkAccessible.h"
#include "HTMLListAccessible.h"
#include "HTMLSelectAccessible.h"
#include "HTMLTableAccessibleWrap.h"
#include "HyperTextAccessibleWrap.h"
#include "RootAccessible.h"
#include "nsAccUtils.h"
#include "nsArrayUtils.h"
#include "nsAttrName.h"
#include "nsEventShell.h"
#include "nsIURI.h"
#include "OuterDocAccessible.h"
#include "Platform.h"
#include "Role.h"
#ifdef MOZ_ACCESSIBILITY_ATK
#include "RootAccessibleWrap.h"
#endif
#include "States.h"
#include "TextLeafAccessibleWrap.h"
#include "TreeWalker.h"
#include "xpcAccessibleApplication.h"
#include "xpcAccessibleDocument.h"
#ifdef MOZ_ACCESSIBILITY_ATK
#include "AtkSocketAccessible.h"
#endif
#ifdef XP_WIN
#include "mozilla/a11y/Compatibility.h"
#include "mozilla/dom/ContentChild.h"
#include "HTMLWin32ObjectAccessible.h"
#include "mozilla/StaticPtr.h"
#endif
#ifdef A11Y_LOG
#include "Logging.h"
#endif
#include "nsImageFrame.h"
#include "nsIObserverService.h"
#include "nsLayoutUtils.h"
#include "nsPluginFrame.h"
#include "nsSVGPathGeometryFrame.h"
#include "nsTreeBodyFrame.h"
#include "nsTreeColumns.h"
#include "nsTreeUtils.h"
#include "nsXBLPrototypeBinding.h"
#include "nsXBLBinding.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/dom/DOMStringList.h"
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
#include "nsDeckFrame.h"
#include "XULAlertAccessible.h"
#include "XULColorPickerAccessible.h"
#include "XULComboboxAccessible.h"
#include "XULElementAccessibles.h"
#include "XULFormControlAccessible.h"
#include "XULListboxAccessibleWrap.h"
#include "XULMenuAccessibleWrap.h"
#include "XULSliderAccessible.h"
#include "XULTabAccessible.h"
#include "XULTreeGridAccessibleWrap.h"
#if defined(XP_WIN) || defined(MOZ_ACCESSIBILITY_ATK)
#include "nsNPAPIPluginInstance.h"
#endif
using namespace mozilla;
using namespace mozilla::a11y;
using namespace mozilla::dom;
////////////////////////////////////////////////////////////////////////////////
// Statics
////////////////////////////////////////////////////////////////////////////////
/**
* Return true if the element must be accessible.
*/
static bool
MustBeAccessible(nsIContent* aContent, DocAccessible* aDocument)
{
if (aContent->GetPrimaryFrame()->IsFocusable())
return true;
uint32_t attrCount = aContent->GetAttrCount();
for (uint32_t attrIdx = 0; attrIdx < attrCount; attrIdx++) {
const nsAttrName* attr = aContent->GetAttrNameAt(attrIdx);
if (attr->NamespaceEquals(kNameSpaceID_None)) {
nsIAtom* attrAtom = attr->Atom();
nsDependentAtomString attrStr(attrAtom);
if (!StringBeginsWith(attrStr, NS_LITERAL_STRING("aria-")))
continue; // not ARIA
// A global state or a property and in case of token defined.
uint8_t attrFlags = aria::AttrCharacteristicsFor(attrAtom);
if ((attrFlags & ATTR_GLOBAL) && (!(attrFlags & ATTR_VALTOKEN) ||
nsAccUtils::HasDefinedARIAToken(aContent, attrAtom))) {
return true;
}
}
}
// If the given ID is referred by relation attribute then create an accessible
// for it.
nsAutoString id;
if (nsCoreUtils::GetID(aContent, id) && !id.IsEmpty())
return aDocument->IsDependentID(id);
return false;
}
////////////////////////////////////////////////////////////////////////////////
// Accessible constructors
static Accessible*
New_HTMLLink(nsIContent* aContent, Accessible* aContext)
{
// Only some roles truly enjoy life as HTMLLinkAccessibles, for details
// see closed bug 494807.
const nsRoleMapEntry* roleMapEntry = aria::GetRoleMap(aContent->AsElement());
if (roleMapEntry && roleMapEntry->role != roles::NOTHING &&
roleMapEntry->role != roles::LINK) {
return new HyperTextAccessibleWrap(aContent, aContext->Document());
}
return new HTMLLinkAccessible(aContent, aContext->Document());
}
static Accessible* New_HyperText(nsIContent* aContent, Accessible* aContext)
{ return new HyperTextAccessibleWrap(aContent, aContext->Document()); }
static Accessible* New_HTMLFigcaption(nsIContent* aContent, Accessible* aContext)
{ return new HTMLFigcaptionAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLFigure(nsIContent* aContent, Accessible* aContext)
{ return new HTMLFigureAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLLegend(nsIContent* aContent, Accessible* aContext)
{ return new HTMLLegendAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLOption(nsIContent* aContent, Accessible* aContext)
{ return new HTMLSelectOptionAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLOptgroup(nsIContent* aContent, Accessible* aContext)
{ return new HTMLSelectOptGroupAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLList(nsIContent* aContent, Accessible* aContext)
{ return new HTMLListAccessible(aContent, aContext->Document()); }
static Accessible*
New_HTMLListitem(nsIContent* aContent, Accessible* aContext)
{
// If list item is a child of accessible list then create an accessible for
// it unconditionally by tag name. nsBlockFrame creates the list item
// accessible for other elements styled as list items.
if (aContext->IsList() && aContext->GetContent() == aContent->GetParent())
return new HTMLLIAccessible(aContent, aContext->Document());
return nullptr;
}
static Accessible*
New_HTMLDefinition(nsIContent* aContent, Accessible* aContext)
{
if (aContext->IsList())
return new HyperTextAccessibleWrap(aContent, aContext->Document());
return nullptr;
}
static Accessible* New_HTMLLabel(nsIContent* aContent, Accessible* aContext)
{ return new HTMLLabelAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLOutput(nsIContent* aContent, Accessible* aContext)
{ return new HTMLOutputAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLProgress(nsIContent* aContent, Accessible* aContext)
{ return new HTMLProgressMeterAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLSummary(nsIContent* aContent, Accessible* aContext)
{ return new HTMLSummaryAccessible(aContent, aContext->Document()); }
static Accessible*
New_HTMLTableAccessible(nsIContent* aContent, Accessible* aContext)
{ return new HTMLTableAccessible(aContent, aContext->Document()); }
static Accessible*
New_HTMLTableRowAccessible(nsIContent* aContent, Accessible* aContext)
{ return new HTMLTableRowAccessible(aContent, aContext->Document()); }
static Accessible*
New_HTMLTableCellAccessible(nsIContent* aContent, Accessible* aContext)
{ return new HTMLTableCellAccessible(aContent, aContext->Document()); }
static Accessible*
New_HTMLTableHeaderCell(nsIContent* aContent, Accessible* aContext)
{
if (aContext->IsTableRow() && aContext->GetContent() == aContent->GetParent())
return new HTMLTableHeaderCellAccessibleWrap(aContent, aContext->Document());
return nullptr;
}
static Accessible*
New_HTMLTableHeaderCellIfScope(nsIContent* aContent, Accessible* aContext)
{
if (aContext->IsTableRow() && aContext->GetContent() == aContent->GetParent() &&
aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::scope))
return new HTMLTableHeaderCellAccessibleWrap(aContent, aContext->Document());
return nullptr;
}
////////////////////////////////////////////////////////////////////////////////
// Markup maps array.
#define Attr(name, value) \
{ &nsGkAtoms::name, &nsGkAtoms::value }
#define AttrFromDOM(name, DOMAttrName) \
{ &nsGkAtoms::name, nullptr, &nsGkAtoms::DOMAttrName }
#define AttrFromDOMIf(name, DOMAttrName, DOMAttrValue) \
{ &nsGkAtoms::name, nullptr, &nsGkAtoms::DOMAttrName, &nsGkAtoms::DOMAttrValue }
#define MARKUPMAP(atom, new_func, r, ... ) \
{ &nsGkAtoms::atom, new_func, static_cast<a11y::role>(r), { __VA_ARGS__ } },
static const MarkupMapInfo sMarkupMapList[] = {
#include "MarkupMap.h"
};
#undef Attr
#undef AttrFromDOM
#undef AttrFromDOMIf
#undef MARKUPMAP
////////////////////////////////////////////////////////////////////////////////
// nsAccessibilityService
////////////////////////////////////////////////////////////////////////////////
nsAccessibilityService *nsAccessibilityService::gAccessibilityService = nullptr;
ApplicationAccessible* nsAccessibilityService::gApplicationAccessible = nullptr;
xpcAccessibleApplication* nsAccessibilityService::gXPCApplicationAccessible = nullptr;
uint32_t nsAccessibilityService::gConsumers = 0;
nsAccessibilityService::nsAccessibilityService() :
DocManager(), FocusManager(), mMarkupMaps(ArrayLength(sMarkupMapList))
{
}
nsAccessibilityService::~nsAccessibilityService()
{
NS_ASSERTION(IsShutdown(), "Accessibility wasn't shutdown!");
gAccessibilityService = nullptr;
}
////////////////////////////////////////////////////////////////////////////////
// nsIListenerChangeListener
NS_IMETHODIMP
nsAccessibilityService::ListenersChanged(nsIArray* aEventChanges)
{
uint32_t targetCount;
nsresult rv = aEventChanges->GetLength(&targetCount);
NS_ENSURE_SUCCESS(rv, rv);
for (uint32_t i = 0 ; i < targetCount ; i++) {
nsCOMPtr<nsIEventListenerChange> change = do_QueryElementAt(aEventChanges, i);
nsCOMPtr<nsIDOMEventTarget> target;
change->GetTarget(getter_AddRefs(target));
nsCOMPtr<nsIContent> node(do_QueryInterface(target));
if (!node || !node->IsHTMLElement()) {
continue;
}
nsCOMPtr<nsIArray> listenerNames;
change->GetChangedListenerNames(getter_AddRefs(listenerNames));
uint32_t changeCount;
rv = listenerNames->GetLength(&changeCount);
NS_ENSURE_SUCCESS(rv, rv);
for (uint32_t i = 0 ; i < changeCount ; i++) {
nsCOMPtr<nsIAtom> listenerName = do_QueryElementAt(listenerNames, i);
// We are only interested in event listener changes which may
// make an element accessible or inaccessible.
if (listenerName != nsGkAtoms::onclick &&
listenerName != nsGkAtoms::onmousedown &&
listenerName != nsGkAtoms::onmouseup) {
continue;
}
nsIDocument* ownerDoc = node->OwnerDoc();
DocAccessible* document = GetExistingDocAccessible(ownerDoc);
// Create an accessible for a inaccessible element having click event
// handler.
if (document && !document->HasAccessible(node) &&
nsCoreUtils::HasClickListener(node)) {
nsIContent* parentEl = node->GetFlattenedTreeParent();
if (parentEl) {
document->ContentInserted(parentEl, node, node->GetNextSibling());
}
break;
}
}
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsISupports
NS_IMPL_ISUPPORTS_INHERITED(nsAccessibilityService,
DocManager,
nsIObserver,
nsIListenerChangeListener,
nsISelectionListener) // from SelectionManager
////////////////////////////////////////////////////////////////////////////////
// nsIObserver
NS_IMETHODIMP
nsAccessibilityService::Observe(nsISupports *aSubject, const char *aTopic,
const char16_t *aData)
{
if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID))
Shutdown();
return NS_OK;
}
void
nsAccessibilityService::NotifyOfAnchorJumpTo(nsIContent* aTargetNode)
{
nsIDocument* documentNode = aTargetNode->GetUncomposedDoc();
if (documentNode) {
DocAccessible* document = GetDocAccessible(documentNode);
if (document)
document->SetAnchorJump(aTargetNode);
}
}
void
nsAccessibilityService::FireAccessibleEvent(uint32_t aEvent,
Accessible* aTarget)
{
nsEventShell::FireEvent(aEvent, aTarget);
}
Accessible*
nsAccessibilityService::GetRootDocumentAccessible(nsIPresShell* aPresShell,
bool aCanCreate)
{
nsIPresShell* ps = aPresShell;
nsIDocument* documentNode = aPresShell->GetDocument();
if (documentNode) {
nsCOMPtr<nsIDocShellTreeItem> treeItem(documentNode->GetDocShell());
if (treeItem) {
nsCOMPtr<nsIDocShellTreeItem> rootTreeItem;
treeItem->GetRootTreeItem(getter_AddRefs(rootTreeItem));
if (treeItem != rootTreeItem) {
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(rootTreeItem));
ps = docShell->GetPresShell();
}
return aCanCreate ? GetDocAccessible(ps) : ps->GetDocAccessible();
}
}
return nullptr;
}
#ifdef XP_WIN
static StaticAutoPtr<nsTArray<nsCOMPtr<nsIContent> > > sPendingPlugins;
static StaticAutoPtr<nsTArray<nsCOMPtr<nsITimer> > > sPluginTimers;
class PluginTimerCallBack final : public nsITimerCallback
{
~PluginTimerCallBack() {}
public:
PluginTimerCallBack(nsIContent* aContent) : mContent(aContent) {}
NS_DECL_ISUPPORTS
NS_IMETHOD Notify(nsITimer* aTimer) final
{
if (!mContent->IsInUncomposedDoc())
return NS_OK;
nsIPresShell* ps = mContent->OwnerDoc()->GetShell();
if (ps) {
DocAccessible* doc = ps->GetDocAccessible();
if (doc) {
// Make sure that if we created an accessible for the plugin that wasn't
// a plugin accessible we remove it before creating the right accessible.
doc->RecreateAccessible(mContent);
sPluginTimers->RemoveElement(aTimer);
return NS_OK;
}
}
// We couldn't get a doc accessible so presumably the document went away.
// In this case don't leak our ref to the content or timer.
sPendingPlugins->RemoveElement(mContent);
sPluginTimers->RemoveElement(aTimer);
return NS_OK;
}
private:
nsCOMPtr<nsIContent> mContent;
};
NS_IMPL_ISUPPORTS(PluginTimerCallBack, nsITimerCallback)
#endif
already_AddRefed<Accessible>
nsAccessibilityService::CreatePluginAccessible(nsPluginFrame* aFrame,
nsIContent* aContent,
Accessible* aContext)
{
// nsPluginFrame means a plugin, so we need to use the accessibility support
// of the plugin.
if (aFrame->GetRect().IsEmpty())
return nullptr;
#if defined(XP_WIN) || defined(MOZ_ACCESSIBILITY_ATK)
RefPtr<nsNPAPIPluginInstance> pluginInstance;
if (NS_SUCCEEDED(aFrame->GetPluginInstance(getter_AddRefs(pluginInstance))) &&
pluginInstance) {
#ifdef XP_WIN
if (!sPendingPlugins->Contains(aContent) &&
(Preferences::GetBool("accessibility.delay_plugins") ||
Compatibility::IsJAWS() || Compatibility::IsWE())) {
nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID);
RefPtr<PluginTimerCallBack> cb = new PluginTimerCallBack(aContent);
timer->InitWithCallback(cb, Preferences::GetUint("accessibility.delay_plugin_time"),
nsITimer::TYPE_ONE_SHOT);
sPluginTimers->AppendElement(timer);
sPendingPlugins->AppendElement(aContent);
return nullptr;
}
// We need to remove aContent from the pending plugins here to avoid
// reentrancy. When the timer fires it calls
// DocAccessible::ContentInserted() which does the work async.
sPendingPlugins->RemoveElement(aContent);
// Note: pluginPort will be null if windowless.
HWND pluginPort = nullptr;
aFrame->GetPluginPort(&pluginPort);
RefPtr<Accessible> accessible =
new HTMLWin32ObjectOwnerAccessible(aContent, aContext->Document(),
pluginPort);
return accessible.forget();
#elif MOZ_ACCESSIBILITY_ATK
if (!AtkSocketAccessible::gCanEmbed)
return nullptr;
// Note this calls into the plugin, so crazy things may happen and aFrame
// may go away.
nsCString plugId;
nsresult rv = pluginInstance->GetValueFromPlugin(
NPPVpluginNativeAccessibleAtkPlugId, &plugId);
if (NS_SUCCEEDED(rv) && !plugId.IsEmpty()) {
RefPtr<AtkSocketAccessible> socketAccessible =
new AtkSocketAccessible(aContent, aContext->Document(), plugId);
return socketAccessible.forget();
}
#endif
}
#endif
return nullptr;
}
void
nsAccessibilityService::DeckPanelSwitched(nsIPresShell* aPresShell,
nsIContent* aDeckNode,
nsIFrame* aPrevBoxFrame,
nsIFrame* aCurrentBoxFrame)
{
// Ignore tabpanels elements (a deck having an accessible) since their
// children are accessible not depending on selected tab.
DocAccessible* document = GetDocAccessible(aPresShell);
if (!document || document->HasAccessible(aDeckNode))
return;
if (aPrevBoxFrame) {
nsIContent* panelNode = aPrevBoxFrame->GetContent();
#ifdef A11Y_LOG
if (logging::IsEnabled(logging::eTree)) {
logging::MsgBegin("TREE", "deck panel unselected");
logging::Node("container", panelNode);
logging::Node("content", aDeckNode);
logging::MsgEnd();
}
#endif
document->ContentRemoved(aDeckNode, panelNode);
}
if (aCurrentBoxFrame) {
nsIContent* panelNode = aCurrentBoxFrame->GetContent();
#ifdef A11Y_LOG
if (logging::IsEnabled(logging::eTree)) {
logging::MsgBegin("TREE", "deck panel selected");
logging::Node("container", panelNode);
logging::Node("content", aDeckNode);
logging::MsgEnd();
}
#endif
document->ContentInserted(aDeckNode, panelNode, panelNode->GetNextSibling());
}
}
void
nsAccessibilityService::ContentRangeInserted(nsIPresShell* aPresShell,
nsIContent* aContainer,
nsIContent* aStartChild,
nsIContent* aEndChild)
{
DocAccessible* document = GetDocAccessible(aPresShell);
#ifdef A11Y_LOG
if (logging::IsEnabled(logging::eTree)) {
logging::MsgBegin("TREE", "content inserted; doc: %p", document);
logging::Node("container", aContainer);
for (nsIContent* child = aStartChild; child != aEndChild;
child = child->GetNextSibling()) {
logging::Node("content", child);
}
logging::MsgEnd();
logging::Stack();
}
#endif
if (document) {
document->ContentInserted(aContainer, aStartChild, aEndChild);
}
}
void
nsAccessibilityService::ContentRemoved(nsIPresShell* aPresShell,
nsIContent* aChildNode)
{
DocAccessible* document = GetDocAccessible(aPresShell);
#ifdef A11Y_LOG
if (logging::IsEnabled(logging::eTree)) {
logging::MsgBegin("TREE", "content removed; doc: %p", document);
logging::Node("container node", aChildNode->GetFlattenedTreeParent());
logging::Node("content node", aChildNode);
logging::MsgEnd();
}
#endif
if (document) {
// Flatten hierarchy may be broken at this point so we cannot get a true
// container by traversing up the DOM tree. Find a parent of first accessible
// from the subtree of the given DOM node, that'll be a container. If no
// accessibles in subtree then we don't care about the change.
Accessible* child = document->GetAccessible(aChildNode);
if (!child) {
Accessible* container = document->GetContainerAccessible(aChildNode);
a11y::TreeWalker walker(container ? container : document, aChildNode,
a11y::TreeWalker::eWalkCache);
child = walker.Next();
}
if (child) {
document->ContentRemoved(child->Parent(), aChildNode);
#ifdef A11Y_LOG
if (logging::IsEnabled(logging::eTree))
logging::AccessibleNNode("real container", child->Parent());
#endif
}
}
#ifdef A11Y_LOG
if (logging::IsEnabled(logging::eTree)) {
logging::MsgEnd();
logging::Stack();
}
#endif
}
void
nsAccessibilityService::UpdateText(nsIPresShell* aPresShell,
nsIContent* aContent)
{
DocAccessible* document = GetDocAccessible(aPresShell);
if (document)
document->UpdateText(aContent);
}
void
nsAccessibilityService::TreeViewChanged(nsIPresShell* aPresShell,
nsIContent* aContent,
nsITreeView* aView)
{
DocAccessible* document = GetDocAccessible(aPresShell);
if (document) {
Accessible* accessible = document->GetAccessible(aContent);
if (accessible) {
XULTreeAccessible* treeAcc = accessible->AsXULTree();
if (treeAcc)
treeAcc->TreeViewChanged(aView);
}
}
}
void
nsAccessibilityService::RangeValueChanged(nsIPresShell* aPresShell,
nsIContent* aContent)
{
DocAccessible* document = GetDocAccessible(aPresShell);
if (document) {
Accessible* accessible = document->GetAccessible(aContent);
if (accessible) {
document->FireDelayedEvent(nsIAccessibleEvent::EVENT_VALUE_CHANGE,
accessible);
}
}
}
void
nsAccessibilityService::UpdateListBullet(nsIPresShell* aPresShell,
nsIContent* aHTMLListItemContent,
bool aHasBullet)
{
DocAccessible* document = GetDocAccessible(aPresShell);
if (document) {
Accessible* accessible = document->GetAccessible(aHTMLListItemContent);
if (accessible) {
HTMLLIAccessible* listItem = accessible->AsHTMLListItem();
if (listItem)
listItem->UpdateBullet(aHasBullet);
}
}
}
void
nsAccessibilityService::UpdateImageMap(nsImageFrame* aImageFrame)
{
nsIPresShell* presShell = aImageFrame->PresContext()->PresShell();
DocAccessible* document = GetDocAccessible(presShell);
if (document) {
Accessible* accessible =
document->GetAccessible(aImageFrame->GetContent());
if (accessible) {
HTMLImageMapAccessible* imageMap = accessible->AsImageMap();
if (imageMap) {
imageMap->UpdateChildAreas();
return;
}
// If image map was initialized after we created an accessible (that'll
// be an image accessible) then recreate it.
RecreateAccessible(presShell, aImageFrame->GetContent());
}
}
}
void
nsAccessibilityService::UpdateLabelValue(nsIPresShell* aPresShell,
nsIContent* aLabelElm,
const nsString& aNewValue)
{
DocAccessible* document = GetDocAccessible(aPresShell);
if (document) {
Accessible* accessible = document->GetAccessible(aLabelElm);
if (accessible) {
XULLabelAccessible* xulLabel = accessible->AsXULLabel();
NS_ASSERTION(xulLabel,
"UpdateLabelValue was called for wrong accessible!");
if (xulLabel)
xulLabel->UpdateLabelValue(aNewValue);
}
}
}
void
nsAccessibilityService::PresShellActivated(nsIPresShell* aPresShell)
{
DocAccessible* document = aPresShell->GetDocAccessible();
if (document) {
RootAccessible* rootDocument = document->RootAccessible();
NS_ASSERTION(rootDocument, "Entirely broken tree: no root document!");
if (rootDocument)
rootDocument->DocumentActivated(document);
}
}
void
nsAccessibilityService::RecreateAccessible(nsIPresShell* aPresShell,
nsIContent* aContent)
{
DocAccessible* document = GetDocAccessible(aPresShell);
if (document)
document->RecreateAccessible(aContent);
}
void
nsAccessibilityService::GetStringRole(uint32_t aRole, nsAString& aString)
{
#define ROLE(geckoRole, stringRole, atkRole, \
macRole, msaaRole, ia2Role, nameRule) \
case roles::geckoRole: \
CopyUTF8toUTF16(stringRole, aString); \
return;
switch (aRole) {
#include "RoleMap.h"
default:
aString.AssignLiteral("unknown");
return;
}
#undef ROLE
}
void
nsAccessibilityService::GetStringStates(uint32_t aState, uint32_t aExtraState,
nsISupports **aStringStates)
{
RefPtr<DOMStringList> stringStates = new DOMStringList();
uint64_t state = nsAccUtils::To64State(aState, aExtraState);
// states
if (state & states::UNAVAILABLE) {
stringStates->Add(NS_LITERAL_STRING("unavailable"));
}
if (state & states::SELECTED) {
stringStates->Add(NS_LITERAL_STRING("selected"));
}
if (state & states::FOCUSED) {
stringStates->Add(NS_LITERAL_STRING("focused"));
}
if (state & states::PRESSED) {
stringStates->Add(NS_LITERAL_STRING("pressed"));
}
if (state & states::CHECKED) {
stringStates->Add(NS_LITERAL_STRING("checked"));
}
if (state & states::MIXED) {
stringStates->Add(NS_LITERAL_STRING("mixed"));
}
if (state & states::READONLY) {
stringStates->Add(NS_LITERAL_STRING("readonly"));
}
if (state & states::HOTTRACKED) {
stringStates->Add(NS_LITERAL_STRING("hottracked"));
}
if (state & states::DEFAULT) {
stringStates->Add(NS_LITERAL_STRING("default"));
}
if (state & states::EXPANDED) {
stringStates->Add(NS_LITERAL_STRING("expanded"));
}
if (state & states::COLLAPSED) {
stringStates->Add(NS_LITERAL_STRING("collapsed"));
}
if (state & states::BUSY) {
stringStates->Add(NS_LITERAL_STRING("busy"));
}
if (state & states::FLOATING) {
stringStates->Add(NS_LITERAL_STRING("floating"));
}
if (state & states::ANIMATED) {
stringStates->Add(NS_LITERAL_STRING("animated"));
}
if (state & states::INVISIBLE) {
stringStates->Add(NS_LITERAL_STRING("invisible"));
}
if (state & states::OFFSCREEN) {
stringStates->Add(NS_LITERAL_STRING("offscreen"));
}
if (state & states::SIZEABLE) {
stringStates->Add(NS_LITERAL_STRING("sizeable"));
}
if (state & states::MOVEABLE) {
stringStates->Add(NS_LITERAL_STRING("moveable"));
}
if (state & states::SELFVOICING) {
stringStates->Add(NS_LITERAL_STRING("selfvoicing"));
}
if (state & states::FOCUSABLE) {
stringStates->Add(NS_LITERAL_STRING("focusable"));
}
if (state & states::SELECTABLE) {
stringStates->Add(NS_LITERAL_STRING("selectable"));
}
if (state & states::LINKED) {
stringStates->Add(NS_LITERAL_STRING("linked"));
}
if (state & states::TRAVERSED) {
stringStates->Add(NS_LITERAL_STRING("traversed"));
}
if (state & states::MULTISELECTABLE) {
stringStates->Add(NS_LITERAL_STRING("multiselectable"));
}
if (state & states::EXTSELECTABLE) {
stringStates->Add(NS_LITERAL_STRING("extselectable"));
}
if (state & states::PROTECTED) {
stringStates->Add(NS_LITERAL_STRING("protected"));
}
if (state & states::HASPOPUP) {
stringStates->Add(NS_LITERAL_STRING("haspopup"));
}
if (state & states::REQUIRED) {
stringStates->Add(NS_LITERAL_STRING("required"));
}
if (state & states::ALERT) {
stringStates->Add(NS_LITERAL_STRING("alert"));
}
if (state & states::INVALID) {
stringStates->Add(NS_LITERAL_STRING("invalid"));
}
if (state & states::CHECKABLE) {
stringStates->Add(NS_LITERAL_STRING("checkable"));
}
// extraStates
if (state & states::SUPPORTS_AUTOCOMPLETION) {
stringStates->Add(NS_LITERAL_STRING("autocompletion"));
}
if (state & states::DEFUNCT) {
stringStates->Add(NS_LITERAL_STRING("defunct"));
}
if (state & states::SELECTABLE_TEXT) {
stringStates->Add(NS_LITERAL_STRING("selectable text"));
}
if (state & states::EDITABLE) {
stringStates->Add(NS_LITERAL_STRING("editable"));
}
if (state & states::ACTIVE) {
stringStates->Add(NS_LITERAL_STRING("active"));
}
if (state & states::MODAL) {
stringStates->Add(NS_LITERAL_STRING("modal"));
}
if (state & states::MULTI_LINE) {
stringStates->Add(NS_LITERAL_STRING("multi line"));
}
if (state & states::HORIZONTAL) {
stringStates->Add(NS_LITERAL_STRING("horizontal"));
}
if (state & states::OPAQUE1) {
stringStates->Add(NS_LITERAL_STRING("opaque"));
}
if (state & states::SINGLE_LINE) {
stringStates->Add(NS_LITERAL_STRING("single line"));
}
if (state & states::TRANSIENT) {
stringStates->Add(NS_LITERAL_STRING("transient"));
}
if (state & states::VERTICAL) {
stringStates->Add(NS_LITERAL_STRING("vertical"));
}
if (state & states::STALE) {
stringStates->Add(NS_LITERAL_STRING("stale"));
}
if (state & states::ENABLED) {
stringStates->Add(NS_LITERAL_STRING("enabled"));
}
if (state & states::SENSITIVE) {
stringStates->Add(NS_LITERAL_STRING("sensitive"));
}
if (state & states::EXPANDABLE) {
stringStates->Add(NS_LITERAL_STRING("expandable"));
}
//unknown states
if (!stringStates->Length()) {
stringStates->Add(NS_LITERAL_STRING("unknown"));
}
stringStates.forget(aStringStates);
}
void
nsAccessibilityService::GetStringEventType(uint32_t aEventType,
nsAString& aString)
{
NS_ASSERTION(nsIAccessibleEvent::EVENT_LAST_ENTRY == ArrayLength(kEventTypeNames),
"nsIAccessibleEvent constants are out of sync to kEventTypeNames");
if (aEventType >= ArrayLength(kEventTypeNames)) {
aString.AssignLiteral("unknown");
return;
}
CopyUTF8toUTF16(kEventTypeNames[aEventType], aString);
}
void
nsAccessibilityService::GetStringRelationType(uint32_t aRelationType,
nsAString& aString)
{
NS_ENSURE_TRUE_VOID(aRelationType <= static_cast<uint32_t>(RelationType::LAST));
#define RELATIONTYPE(geckoType, geckoTypeName, atkType, msaaType, ia2Type) \
case RelationType::geckoType: \
aString.AssignLiteral(geckoTypeName); \
return;
RelationType relationType = static_cast<RelationType>(aRelationType);
switch (relationType) {
#include "RelationTypeMap.h"
default:
aString.AssignLiteral("unknown");
return;
}
#undef RELATIONTYPE
}
////////////////////////////////////////////////////////////////////////////////
// nsAccessibilityService public
Accessible*
nsAccessibilityService::CreateAccessible(nsINode* aNode,
Accessible* aContext,
bool* aIsSubtreeHidden)
{
MOZ_ASSERT(aContext, "No context provided");
MOZ_ASSERT(aNode, "No node to create an accessible for");
MOZ_ASSERT(gConsumers, "No creation after shutdown");
if (aIsSubtreeHidden)
*aIsSubtreeHidden = false;
DocAccessible* document = aContext->Document();
MOZ_ASSERT(!document->GetAccessible(aNode),
"We already have an accessible for this node.");
if (aNode->IsNodeOfType(nsINode::eDOCUMENT)) {
// If it's document node then ask accessible document loader for
// document accessible, otherwise return null.
nsCOMPtr<nsIDocument> document(do_QueryInterface(aNode));
return GetDocAccessible(document);
}
// We have a content node.
if (!aNode->GetComposedDoc()) {
NS_WARNING("Creating accessible for node with no document");
return nullptr;
}
if (aNode->OwnerDoc() != document->DocumentNode()) {
NS_ERROR("Creating accessible for wrong document");
return nullptr;
}
if (!aNode->IsContent())
return nullptr;
nsIContent* content = aNode->AsContent();
nsIFrame* frame = content->GetPrimaryFrame();
// Check frame and its visibility. Note, hidden frame allows visible
// elements in subtree.
if (!frame || !frame->StyleVisibility()->IsVisible()) {
if (aIsSubtreeHidden && !frame)
*aIsSubtreeHidden = true;
return nullptr;
}
if (frame->GetContent() != content) {
// Not the main content for this frame. This happens because <area>
// elements return the image frame as their primary frame. The main content
// for the image frame is the image content. If the frame is not an image
// frame or the node is not an area element then null is returned.
// This setup will change when bug 135040 is fixed. Make sure we don't
// create area accessible here. Hopefully assertion below will handle that.
#ifdef DEBUG
nsImageFrame* imageFrame = do_QueryFrame(frame);
NS_ASSERTION(imageFrame && content->IsHTMLElement(nsGkAtoms::area),
"Unknown case of not main content for the frame!");
#endif
return nullptr;
}
#ifdef DEBUG
nsImageFrame* imageFrame = do_QueryFrame(frame);
NS_ASSERTION(!imageFrame || !content->IsHTMLElement(nsGkAtoms::area),
"Image map manages the area accessible creation!");
#endif
// Attempt to create an accessible based on what we know.
RefPtr<Accessible> newAcc;
// Create accessible for visible text frames.
if (content->IsNodeOfType(nsINode::eTEXT)) {
nsIFrame::RenderedText text = frame->GetRenderedText(0,
UINT32_MAX, nsIFrame::TextOffsetType::OFFSETS_IN_CONTENT_TEXT,
nsIFrame::TrailingWhitespace::DONT_TRIM_TRAILING_WHITESPACE);
// Ignore not rendered text nodes and whitespace text nodes between table
// cells.
if (text.mString.IsEmpty() ||
(aContext->IsTableRow() && nsCoreUtils::IsWhitespaceString(text.mString))) {
if (aIsSubtreeHidden)
*aIsSubtreeHidden = true;
return nullptr;
}
newAcc = CreateAccessibleByFrameType(frame, content, aContext);
document->BindToDocument(newAcc, nullptr);
newAcc->AsTextLeaf()->SetText(text.mString);
return newAcc;
}
if (content->IsHTMLElement(nsGkAtoms::map)) {
// Create hyper text accessible for HTML map if it is used to group links
// (see http://www.w3.org/TR/WCAG10-HTML-TECHS/#group-bypass). If the HTML
// map rect is empty then it is used for links grouping. Otherwise it should
// be used in conjunction with HTML image element and in this case we don't
// create any accessible for it and don't walk into it. The accessibles for
// HTML area (HTMLAreaAccessible) the map contains are attached as
// children of the appropriate accessible for HTML image
// (ImageAccessible).
if (nsLayoutUtils::GetAllInFlowRectsUnion(frame,
frame->GetParent()).IsEmpty()) {
if (aIsSubtreeHidden)
*aIsSubtreeHidden = true;
return nullptr;
}
newAcc = new HyperTextAccessibleWrap(content, document);
document->BindToDocument(newAcc, aria::GetRoleMap(content->AsElement()));
return newAcc;
}
const nsRoleMapEntry* roleMapEntry = aria::GetRoleMap(content->AsElement());
// If the element is focusable or global ARIA attribute is applied to it or
// it is referenced by ARIA relationship then treat role="presentation" on
// the element as the role is not there.
if (roleMapEntry &&
(roleMapEntry->Is(nsGkAtoms::presentation) ||
roleMapEntry->Is(nsGkAtoms::none))) {
if (!MustBeAccessible(content, document))
return nullptr;
roleMapEntry = nullptr;
}
if (!newAcc && content->IsHTMLElement()) { // HTML accessibles
bool isARIATablePart = roleMapEntry &&
(roleMapEntry->accTypes & (eTableCell | eTableRow | eTable));
if (!isARIATablePart ||
frame->AccessibleType() == eHTMLTableCellType ||
frame->AccessibleType() == eHTMLTableRowType ||
frame->AccessibleType() == eHTMLTableType) {
// Prefer to use markup to decide if and what kind of accessible to create,
const MarkupMapInfo* markupMap =
mMarkupMaps.Get(content->NodeInfo()->NameAtom());
if (markupMap && markupMap->new_func)
newAcc = markupMap->new_func(content, aContext);
if (!newAcc) // try by frame accessible type.
newAcc = CreateAccessibleByFrameType(frame, content, aContext);
}
// In case of ARIA grid or table use table-specific classes if it's not
// native table based.
if (isARIATablePart && (!newAcc || newAcc->IsGenericHyperText())) {
if ((roleMapEntry->accTypes & eTableCell)) {
if (aContext->IsTableRow())
newAcc = new ARIAGridCellAccessibleWrap(content, document);
} else if (roleMapEntry->IsOfType(eTableRow)) {
if (aContext->IsTable())
newAcc = new ARIARowAccessible(content, document);
} else if (roleMapEntry->IsOfType(eTable)) {
newAcc = new ARIAGridAccessibleWrap(content, document);
}
}
// If table has strong ARIA role then all table descendants shouldn't
// expose their native roles.
if (!roleMapEntry && newAcc && aContext->HasStrongARIARole()) {
if (frame->AccessibleType() == eHTMLTableRowType) {
const nsRoleMapEntry* contextRoleMap = aContext->ARIARoleMap();
if (!contextRoleMap->IsOfType(eTable))
roleMapEntry = &aria::gEmptyRoleMap;
} else if (frame->AccessibleType() == eHTMLTableCellType &&
aContext->ARIARoleMap() == &aria::gEmptyRoleMap) {
roleMapEntry = &aria::gEmptyRoleMap;
} else if (content->IsAnyOfHTMLElements(nsGkAtoms::dt,
nsGkAtoms::li,
nsGkAtoms::dd) ||
frame->AccessibleType() == eHTMLLiType) {
const nsRoleMapEntry* contextRoleMap = aContext->ARIARoleMap();
if (!contextRoleMap->IsOfType(eList))
roleMapEntry = &aria::gEmptyRoleMap;
}
}
}
// Accessible XBL types and deck stuff are used in XUL only currently.
if (!newAcc && content->IsXULElement()) {
// No accessible for not selected deck panel and its children.
if (!aContext->IsXULTabpanels()) {
nsDeckFrame* deckFrame = do_QueryFrame(frame->GetParent());
if (deckFrame && deckFrame->GetSelectedBox() != frame) {
if (aIsSubtreeHidden)
*aIsSubtreeHidden = true;
return nullptr;
}
}
// XBL bindings may use @role attribute to point the accessible type
// they belong to.
newAcc = CreateAccessibleByType(content, document);
// Any XUL box can be used as tabpanel, make sure we create a proper
// accessible for it.
if (!newAcc && aContext->IsXULTabpanels() &&
content->GetParent() == aContext->GetContent()) {
nsIAtom* frameType = frame->GetType();
if (frameType == nsGkAtoms::boxFrame ||
frameType == nsGkAtoms::scrollFrame) {
newAcc = new XULTabpanelAccessible(content, document);
}
}
}
if (!newAcc) {
if (content->IsSVGElement()) {
nsSVGPathGeometryFrame* pathGeometryFrame = do_QueryFrame(frame);
if (pathGeometryFrame) {
// A graphic elements: rect, circle, ellipse, line, path, polygon,
// polyline and image. A 'use' and 'text' graphic elements require
// special support.
newAcc = new EnumRoleAccessible<roles::GRAPHIC>(content, document);
} else if (content->IsSVGElement(nsGkAtoms::svg)) {
newAcc = new EnumRoleAccessible<roles::DIAGRAM>(content, document);
}
} else if (content->IsMathMLElement()) {
const MarkupMapInfo* markupMap =
mMarkupMaps.Get(content->NodeInfo()->NameAtom());
if (markupMap && markupMap->new_func)
newAcc = markupMap->new_func(content, aContext);
// Fall back to text when encountering Content MathML.
if (!newAcc && !content->IsAnyOfMathMLElements(nsGkAtoms::annotation_,
nsGkAtoms::annotation_xml_,
nsGkAtoms::mpadded_,
nsGkAtoms::mphantom_,
nsGkAtoms::maligngroup_,
nsGkAtoms::malignmark_,
nsGkAtoms::mspace_,
nsGkAtoms::semantics_)) {
newAcc = new HyperTextAccessible(content, document);
}
}
}
// If no accessible, see if we need to create a generic accessible because
// of some property that makes this object interesting
// We don't do this for <body>, <html>, <window>, <dialog> etc. which
// correspond to the doc accessible and will be created in any case
if (!newAcc && !content->IsHTMLElement(nsGkAtoms::body) &&
content->GetParent() &&
(roleMapEntry || MustBeAccessible(content, document) ||
(content->IsHTMLElement() &&
nsCoreUtils::HasClickListener(content)))) {
// This content is focusable or has an interesting dynamic content accessibility property.
// If it's interesting we need it in the accessibility hierarchy so that events or
// other accessibles can point to it, or so that it can hold a state, etc.
if (content->IsHTMLElement()) {
// Interesting HTML container which may have selectable text and/or embedded objects
newAcc = new HyperTextAccessibleWrap(content, document);
} else { // XUL, SVG, MathML etc.
// Interesting generic non-HTML container
newAcc = new AccessibleWrap(content, document);
}
}
if (newAcc) {
document->BindToDocument(newAcc, roleMapEntry);
}
return newAcc;
}
////////////////////////////////////////////////////////////////////////////////
// nsAccessibilityService private
bool
nsAccessibilityService::Init()
{
// Initialize accessible document manager.
if (!DocManager::Init())
return false;
// Add observers.
nsCOMPtr<nsIObserverService> observerService =
mozilla::services::GetObserverService();
if (!observerService)
return false;
observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
static const char16_t kInitIndicator[] = { '1', 0 };
observerService->NotifyObservers(nullptr, "a11y-init-or-shutdown", kInitIndicator);
// Subscribe to EventListenerService.
nsCOMPtr<nsIEventListenerService> eventListenerService =
do_GetService("@mozilla.org/eventlistenerservice;1");
if (!eventListenerService)
return false;
eventListenerService->AddListenerChangeListener(this);
for (uint32_t i = 0; i < ArrayLength(sMarkupMapList); i++)
mMarkupMaps.Put(*sMarkupMapList[i].tag, &sMarkupMapList[i]);
#ifdef A11Y_LOG
logging::CheckEnv();
#endif
gAccessibilityService = this;
NS_ADDREF(gAccessibilityService); // will release in Shutdown()
if (XRE_IsParentProcess()) {
gApplicationAccessible = new ApplicationAccessibleWrap();
} else {
#if defined(XP_WIN)
dom::ContentChild* contentChild = dom::ContentChild::GetSingleton();
MOZ_ASSERT(contentChild);
// If we were instantiated by the chrome process, GetMsaaID() will return
// a non-zero value and we may safely continue with initialization.
if (!contentChild->GetMsaaID()) {
// Since we were not instantiated by chrome, we need to synchronously
// obtain a MSAA content process id.
contentChild->SendGetA11yContentId();
}
#endif // defined(XP_WIN)
gApplicationAccessible = new ApplicationAccessible();
}
NS_ADDREF(gApplicationAccessible); // will release in Shutdown()
gApplicationAccessible->Init();
#ifdef XP_WIN
sPendingPlugins = new nsTArray<nsCOMPtr<nsIContent> >;
sPluginTimers = new nsTArray<nsCOMPtr<nsITimer> >;
#endif
// Now its safe to start platform accessibility.
if (XRE_IsParentProcess())
PlatformInit();
return true;
}
void
nsAccessibilityService::Shutdown()
{
// Application is going to be closed, shutdown accessibility and mark
// accessibility service as shutdown to prevent calls of its methods.
// Don't null accessibility service static member at this point to be safe
// if someone will try to operate with it.
MOZ_ASSERT(gConsumers, "Accessibility was shutdown already");
gConsumers = 0;
// Remove observers.
nsCOMPtr<nsIObserverService> observerService =
mozilla::services::GetObserverService();
if (observerService) {
observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
static const char16_t kShutdownIndicator[] = { '0', 0 };
observerService->NotifyObservers(nullptr, "a11y-init-or-shutdown", kShutdownIndicator);
}
// Stop accessible document loader.
DocManager::Shutdown();
SelectionManager::Shutdown();
#ifdef XP_WIN
sPendingPlugins = nullptr;
uint32_t timerCount = sPluginTimers->Length();
for (uint32_t i = 0; i < timerCount; i++)
sPluginTimers->ElementAt(i)->Cancel();
sPluginTimers = nullptr;
#endif
if (XRE_IsParentProcess())
PlatformShutdown();
gApplicationAccessible->Shutdown();
NS_RELEASE(gApplicationAccessible);
gApplicationAccessible = nullptr;
NS_IF_RELEASE(gXPCApplicationAccessible);
gXPCApplicationAccessible = nullptr;
NS_RELEASE(gAccessibilityService);
gAccessibilityService = nullptr;
}
already_AddRefed<Accessible>
nsAccessibilityService::CreateAccessibleByType(nsIContent* aContent,
DocAccessible* aDoc)
{
nsAutoString role;
nsCoreUtils::XBLBindingRole(aContent, role);
if (role.IsEmpty() || role.EqualsLiteral("none"))
return nullptr;
if (role.EqualsLiteral("outerdoc")) {
RefPtr<Accessible> accessible = new OuterDocAccessible(aContent, aDoc);
return accessible.forget();
}
RefPtr<Accessible> accessible;
// XUL controls
if (role.EqualsLiteral("xul:alert")) {
accessible = new XULAlertAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:button")) {
accessible = new XULButtonAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:checkbox")) {
accessible = new XULCheckboxAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:colorpicker")) {
accessible = new XULColorPickerAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:colorpickertile")) {
accessible = new XULColorPickerTileAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:combobox")) {
accessible = new XULComboboxAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:tabpanels")) {
accessible = new XULTabpanelsAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:dropmarker")) {
accessible = new XULDropmarkerAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:groupbox")) {
accessible = new XULGroupboxAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:image")) {
if (aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::onclick)) {
accessible = new XULToolbarButtonAccessible(aContent, aDoc);
} else {
// Don't include nameless images in accessible tree.
if (!aContent->HasAttr(kNameSpaceID_None,
nsGkAtoms::tooltiptext))
return nullptr;
accessible = new ImageAccessibleWrap(aContent, aDoc);
}
} else if (role.EqualsLiteral("xul:link")) {
accessible = new XULLinkAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:listbox")) {
accessible = new XULListboxAccessibleWrap(aContent, aDoc);
} else if (role.EqualsLiteral("xul:listcell")) {
// Only create cells if there's more than one per row.
nsIContent* listItem = aContent->GetParent();
if (!listItem)
return nullptr;
for (nsIContent* child = listItem->GetFirstChild(); child;
child = child->GetNextSibling()) {
if (child->IsXULElement(nsGkAtoms::listcell) && child != aContent) {
accessible = new XULListCellAccessibleWrap(aContent, aDoc);
break;
}
}
} else if (role.EqualsLiteral("xul:listhead")) {
accessible = new XULColumAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:listheader")) {
accessible = new XULColumnItemAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:listitem")) {
accessible = new XULListitemAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:menubar")) {
accessible = new XULMenubarAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:menulist")) {
accessible = new XULComboboxAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:menuitem")) {
accessible = new XULMenuitemAccessibleWrap(aContent, aDoc);
} else if (role.EqualsLiteral("xul:menupopup")) {
#ifdef MOZ_ACCESSIBILITY_ATK
// ATK considers this node to be redundant when within menubars, and it makes menu
// navigation with assistive technologies more difficult
// XXX In the future we will should this for consistency across the nsIAccessible
// implementations on each platform for a consistent scripting environment, but
// then strip out redundant accessibles in the AccessibleWrap class for each platform.
nsIContent *parent = aContent->GetParent();
if (parent && parent->IsXULElement(nsGkAtoms::menu))
return nullptr;
#endif
accessible = new XULMenupopupAccessible(aContent, aDoc);
} else if(role.EqualsLiteral("xul:menuseparator")) {
accessible = new XULMenuSeparatorAccessible(aContent, aDoc);
} else if(role.EqualsLiteral("xul:pane")) {
accessible = new EnumRoleAccessible<roles::PANE>(aContent, aDoc);
} else if (role.EqualsLiteral("xul:panel")) {
if (aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::noautofocus,
nsGkAtoms::_true, eCaseMatters))
accessible = new XULAlertAccessible(aContent, aDoc);
else
accessible = new EnumRoleAccessible<roles::PANE>(aContent, aDoc);
} else if (role.EqualsLiteral("xul:progressmeter")) {
accessible = new XULProgressMeterAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:statusbar")) {
accessible = new XULStatusBarAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:scale")) {
accessible = new XULSliderAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:radiobutton")) {
accessible = new XULRadioButtonAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:radiogroup")) {
accessible = new XULRadioGroupAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:tab")) {
accessible = new XULTabAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:tabs")) {
accessible = new XULTabsAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:text")) {
accessible = new XULLabelAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:textbox")) {
accessible = new EnumRoleAccessible<roles::SECTION>(aContent, aDoc);
} else if (role.EqualsLiteral("xul:thumb")) {
accessible = new XULThumbAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:tree")) {
accessible = CreateAccessibleForXULTree(aContent, aDoc);
} else if (role.EqualsLiteral("xul:treecolumns")) {
accessible = new XULTreeColumAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:treecolumnitem")) {
accessible = new XULColumnItemAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:toolbar")) {
accessible = new XULToolbarAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:toolbarseparator")) {
accessible = new XULToolbarSeparatorAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:tooltip")) {
accessible = new XULTooltipAccessible(aContent, aDoc);
} else if (role.EqualsLiteral("xul:toolbarbutton")) {
accessible = new XULToolbarButtonAccessible(aContent, aDoc);
}
return accessible.forget();
}
already_AddRefed<Accessible>
nsAccessibilityService::CreateAccessibleByFrameType(nsIFrame* aFrame,
nsIContent* aContent,
Accessible* aContext)
{
DocAccessible* document = aContext->Document();
RefPtr<Accessible> newAcc;
switch (aFrame->AccessibleType()) {
case eNoType:
return nullptr;
case eHTMLBRType:
newAcc = new HTMLBRAccessible(aContent, document);
break;
case eHTMLButtonType:
newAcc = new HTMLButtonAccessible(aContent, document);
break;
case eHTMLCanvasType:
newAcc = new HTMLCanvasAccessible(aContent, document);
break;
case eHTMLCaptionType:
if (aContext->IsTable() &&
aContext->GetContent() == aContent->GetParent()) {
newAcc = new HTMLCaptionAccessible(aContent, document);
}
break;
case eHTMLCheckboxType:
newAcc = new HTMLCheckboxAccessible(aContent, document);
break;
case eHTMLComboboxType:
newAcc = new HTMLComboboxAccessible(aContent, document);
break;
case eHTMLFileInputType:
newAcc = new HTMLFileInputAccessible(aContent, document);
break;
case eHTMLGroupboxType:
newAcc = new HTMLGroupboxAccessible(aContent, document);
break;
case eHTMLHRType:
newAcc = new HTMLHRAccessible(aContent, document);
break;
case eHTMLImageMapType:
newAcc = new HTMLImageMapAccessible(aContent, document);
break;
case eHTMLLiType:
if (aContext->IsList() &&
aContext->GetContent() == aContent->GetParent()) {
newAcc = new HTMLLIAccessible(aContent, document);
} else {
// Otherwise create a generic text accessible to avoid text jamming.
newAcc = new HyperTextAccessibleWrap(aContent, document);
}
break;
case eHTMLSelectListType:
newAcc = new HTMLSelectListAccessible(aContent, document);
break;
case eHTMLMediaType:
newAcc = new EnumRoleAccessible<roles::GROUPING>(aContent, document);
break;
case eHTMLRadioButtonType:
newAcc = new HTMLRadioButtonAccessible(aContent, document);
break;
case eHTMLRangeType:
newAcc = new HTMLRangeAccessible(aContent, document);
break;
case eHTMLSpinnerType:
newAcc = new HTMLSpinnerAccessible(aContent, document);
break;
case eHTMLTableType:
if (aContent->IsHTMLElement(nsGkAtoms::table))
newAcc = new HTMLTableAccessibleWrap(aContent, document);
else
newAcc = new HyperTextAccessibleWrap(aContent, document);
break;
case eHTMLTableCellType:
// Accessible HTML table cell should be a child of accessible HTML table
// or its row (CSS HTML tables are polite to the used markup at
// certain degree).
// Otherwise create a generic text accessible to avoid text jamming
// when reading by AT.
if (aContext->IsHTMLTableRow() || aContext->IsHTMLTable())
newAcc = new HTMLTableCellAccessibleWrap(aContent, document);
else
newAcc = new HyperTextAccessibleWrap(aContent, document);
break;
case eHTMLTableRowType: {
// Accessible HTML table row may be a child of tbody/tfoot/thead of
// accessible HTML table or a direct child of accessible of HTML table.
Accessible* table = aContext->IsTable() ? aContext : nullptr;
if (!table && aContext->Parent() && aContext->Parent()->IsTable())
table = aContext->Parent();
if (table) {
nsIContent* parentContent = aContent->GetParent();
nsIFrame* parentFrame = parentContent->GetPrimaryFrame();
if (parentFrame->GetType() != nsGkAtoms::tableWrapperFrame) {
parentContent = parentContent->GetParent();
parentFrame = parentContent->GetPrimaryFrame();
}
if (parentFrame->GetType() == nsGkAtoms::tableWrapperFrame &&
table->GetContent() == parentContent) {
newAcc = new HTMLTableRowAccessible(aContent, document);
}
}
break;
}
case eHTMLTextFieldType:
newAcc = new HTMLTextFieldAccessible(aContent, document);
break;
case eHyperTextType:
if (!aContent->IsAnyOfHTMLElements(nsGkAtoms::dt, nsGkAtoms::dd))
newAcc = new HyperTextAccessibleWrap(aContent, document);
break;
case eImageType:
newAcc = new ImageAccessibleWrap(aContent, document);
break;
case eOuterDocType:
newAcc = new OuterDocAccessible(aContent, document);
break;
case ePluginType: {
nsPluginFrame* pluginFrame = do_QueryFrame(aFrame);
newAcc = CreatePluginAccessible(pluginFrame, aContent, aContext);
break;
}
case eTextLeafType:
newAcc = new TextLeafAccessibleWrap(aContent, document);
break;
default:
MOZ_ASSERT(false);
break;
}
return newAcc.forget();
}
void
nsAccessibilityService::MarkupAttributes(const nsIContent* aContent,
nsIPersistentProperties* aAttributes) const
{
const mozilla::a11y::MarkupMapInfo* markupMap =
mMarkupMaps.Get(aContent->NodeInfo()->NameAtom());
if (!markupMap)
return;
for (uint32_t i = 0; i < ArrayLength(markupMap->attrs); i++) {
const MarkupAttrInfo* info = markupMap->attrs + i;
if (!info->name)
break;
if (info->DOMAttrName) {
if (info->DOMAttrValue) {
if (aContent->AttrValueIs(kNameSpaceID_None, *info->DOMAttrName,
*info->DOMAttrValue, eCaseMatters)) {
nsAccUtils::SetAccAttr(aAttributes, *info->name, *info->DOMAttrValue);
}
continue;
}
nsAutoString value;
aContent->GetAttr(kNameSpaceID_None, *info->DOMAttrName, value);
if (!value.IsEmpty())
nsAccUtils::SetAccAttr(aAttributes, *info->name, value);
continue;
}
nsAccUtils::SetAccAttr(aAttributes, *info->name, *info->value);
}
}
Accessible*
nsAccessibilityService::AddNativeRootAccessible(void* aAtkAccessible)
{
#ifdef MOZ_ACCESSIBILITY_ATK
ApplicationAccessible* applicationAcc = ApplicationAcc();
if (!applicationAcc)
return nullptr;
GtkWindowAccessible* nativeWnd =
new GtkWindowAccessible(static_cast<AtkObject*>(aAtkAccessible));
if (applicationAcc->AppendChild(nativeWnd))
return nativeWnd;
#endif
return nullptr;
}
void
nsAccessibilityService::RemoveNativeRootAccessible(Accessible* aAccessible)
{
#ifdef MOZ_ACCESSIBILITY_ATK
ApplicationAccessible* applicationAcc = ApplicationAcc();
if (applicationAcc)
applicationAcc->RemoveChild(aAccessible);
#endif
}
bool
nsAccessibilityService::HasAccessible(nsIDOMNode* aDOMNode)
{
nsCOMPtr<nsINode> node(do_QueryInterface(aDOMNode));
if (!node)
return false;
DocAccessible* document = GetDocAccessible(node->OwnerDoc());
if (!document)
return false;
return document->HasAccessible(node);
}
////////////////////////////////////////////////////////////////////////////////
// nsAccessibilityService private (DON'T put methods here)
already_AddRefed<Accessible>
nsAccessibilityService::CreateAccessibleForXULTree(nsIContent* aContent,
DocAccessible* aDoc)
{
nsIContent* child = nsTreeUtils::GetDescendantChild(aContent,
nsGkAtoms::treechildren);
if (!child)
return nullptr;
nsTreeBodyFrame* treeFrame = do_QueryFrame(child->GetPrimaryFrame());
if (!treeFrame)
return nullptr;
RefPtr<nsTreeColumns> treeCols = treeFrame->Columns();
int32_t count = 0;
treeCols->GetCount(&count);
// Outline of list accessible.
if (count == 1) {
RefPtr<Accessible> accessible =
new XULTreeAccessible(aContent, aDoc, treeFrame);
return accessible.forget();
}
// Table or tree table accessible.
RefPtr<Accessible> accessible =
new XULTreeGridAccessibleWrap(aContent, aDoc, treeFrame);
return accessible.forget();
}
nsAccessibilityService*
GetOrCreateAccService(uint32_t aNewConsumer)
{
if (!nsAccessibilityService::gAccessibilityService) {
RefPtr<nsAccessibilityService> service = new nsAccessibilityService();
if (!service->Init()) {
service->Shutdown();
return nullptr;
}
}
MOZ_ASSERT(nsAccessibilityService::gAccessibilityService,
"Accessible service is not initialized.");
nsAccessibilityService::gConsumers |= aNewConsumer;
return nsAccessibilityService::gAccessibilityService;
}
void
MaybeShutdownAccService(uint32_t aFormerConsumer)
{
nsAccessibilityService* accService =
nsAccessibilityService::gAccessibilityService;
if (!accService || accService->IsShutdown()) {
return;
}
if (nsCoreUtils::AccEventObserversExist() ||
xpcAccessibilityService::IsInUse()) {
// Still used by XPCOM
nsAccessibilityService::gConsumers =
(nsAccessibilityService::gConsumers & ~aFormerConsumer) |
nsAccessibilityService::eXPCOM;
return;
}
if (nsAccessibilityService::gConsumers & ~aFormerConsumer) {
nsAccessibilityService::gConsumers &= ~aFormerConsumer;
} else {
accService->Shutdown(); // Will unset all nsAccessibilityService::gConsumers
}
}
////////////////////////////////////////////////////////////////////////////////
// Services
////////////////////////////////////////////////////////////////////////////////
namespace mozilla {
namespace a11y {
FocusManager*
FocusMgr()
{
return nsAccessibilityService::gAccessibilityService;
}
SelectionManager*
SelectionMgr()
{
return nsAccessibilityService::gAccessibilityService;
}
ApplicationAccessible*
ApplicationAcc()
{
return nsAccessibilityService::gApplicationAccessible;
}
xpcAccessibleApplication*
XPCApplicationAcc()
{
if (!nsAccessibilityService::gXPCApplicationAccessible &&
nsAccessibilityService::gApplicationAccessible) {
nsAccessibilityService::gXPCApplicationAccessible =
new xpcAccessibleApplication(nsAccessibilityService::gApplicationAccessible);
NS_ADDREF(nsAccessibilityService::gXPCApplicationAccessible);
}
return nsAccessibilityService::gXPCApplicationAccessible;
}
EPlatformDisabledState
PlatformDisabledState()
{
static int disabledState = 0xff;
if (disabledState == 0xff) {
disabledState = Preferences::GetInt("accessibility.force_disabled", 0);
if (disabledState < ePlatformIsForceEnabled)
disabledState = ePlatformIsForceEnabled;
else if (disabledState > ePlatformIsDisabled)
disabledState = ePlatformIsDisabled;
}
return (EPlatformDisabledState)disabledState;
}
}
}
|