11#include <QtCore/qtextboundaryfinder.h>
12#include <QtGui/qclipboard.h>
13#include <QtGui/qguiapplication.h>
14#include <QtGui/qtextcursor.h>
15#include <private/qguiapplication_p.h>
16#include <qpa/qplatformaccessibility.h>
17#include <qpa/qplatformintegration.h>
19#include <QtCore/qdebug.h>
20#include <QtCore/qloggingcategory.h>
21#include <QtCore/qmetaobject.h>
22#include <QtCore/private/qmetaobject_p.h>
23#include <QtCore/qhash.h>
24#include <private/qfactoryloader_p.h>
28using namespace Qt::StringLiterals;
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
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
162
163
164
165
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
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
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
412
413
414
415
416
417
418
419
420
421
422
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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
520#if QT_CONFIG(accessibility)
523
524
525QAccessibleInterface::~QAccessibleInterface()
530
531
532
533
537Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, acLoader,
538 (QAccessibleFactoryInterface_iid,
"/accessible"_L1))
539typedef QHash<QString, QAccessiblePlugin*> QAccessiblePluginsHash;
540Q_GLOBAL_STATIC(QAccessiblePluginsHash, qAccessiblePlugins)
543Q_GLOBAL_STATIC(QList<QAccessible::InterfaceFactory>, qAccessibleFactories)
544Q_GLOBAL_STATIC(QList<QAccessible::ActivationObserver *>, qAccessibleActivationObservers)
546QAccessible::UpdateHandler QAccessible::updateHandler =
nullptr;
547QAccessible::RootObjectHandler QAccessible::rootObjectHandler =
nullptr;
549static bool cleanupAdded =
false;
551static QPlatformAccessibility *platformAccessibility()
553 QPlatformIntegration *pfIntegration = QGuiApplicationPrivate::platformIntegration();
554 return pfIntegration ? pfIntegration->accessibility() :
nullptr;
558
559
560
561
562
563
567
568
569void QAccessible::cleanup()
571 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
572 pfAccessibility->cleanup();
575static void qAccessibleCleanup()
577 qAccessibleActivationObservers()->clear();
578 qAccessibleFactories()->clear();
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
602
603
604
605
606
607
608
609
610
613
614
615
616
617
618
619
620
621
625
626
627
628void QAccessible::installFactory(InterfaceFactory factory)
634 qAddPostRoutine(qAccessibleCleanup);
637 if (qAccessibleFactories()->contains(factory))
639 qAccessibleFactories()->append(factory);
643
644
645void QAccessible::removeFactory(InterfaceFactory factory)
647 qAccessibleFactories()->removeAll(factory);
651
652
653
654
655
656
657QAccessible::UpdateHandler QAccessible::installUpdateHandler(UpdateHandler handler)
659 UpdateHandler old = updateHandler;
660 updateHandler = handler;
665
666
667
668
669
670QAccessible::RootObjectHandler QAccessible::installRootObjectHandler(RootObjectHandler handler)
672 RootObjectHandler old = rootObjectHandler;
673 rootObjectHandler = handler;
678
679
680
681
682
683
685QAccessible::ActivationObserver::~ActivationObserver()
690
691
692
693
694void QAccessible::installActivationObserver(QAccessible::ActivationObserver *observer)
700 qAddPostRoutine(qAccessibleCleanup);
703 if (qAccessibleActivationObservers()->contains(observer))
705 qAccessibleActivationObservers()->append(observer);
709 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
710 pfAccessibility->clearActiveNotificationState();
714
715
716
717
718
719void QAccessible::removeActivationObserver(ActivationObserver *observer)
721 qAccessibleActivationObservers()->removeAll(observer);
725
726
727
728
729void qAccessibleNotifyActivationObservers(
bool active)
731 for (
int i = 0; i < qAccessibleActivationObservers()->size(); ++i)
732 qAccessibleActivationObservers()->at(i)->accessibilityActiveChanged(active);
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753QAccessibleInterface *QAccessible::queryAccessibleInterface(QObject *object)
758 if (Id id = QAccessibleCache::instance()->idForObject(object))
759 return QAccessibleCache::instance()->interfaceForId(id);
763 const QMetaObject *mo = object->metaObject();
764 const auto *objectPriv = QObjectPrivate::get(object);
766
767
768
769
770
771
772
773
774 const bool qmlRelated = !objectPriv->isDeletingChildren &&
775 objectPriv->declarativeData;
776 while (qmlRelated && mo) {
777 auto mop = QMetaObjectPrivate::get(mo);
778 if (!mop || !(mop->flags & DynamicMetaObject))
781 mo = mo->superClass();
784 const QString cn = QLatin1StringView(mo->className());
787 for (
int i = qAccessibleFactories()->size(); i > 0; --i) {
788 InterfaceFactory factory = qAccessibleFactories()->at(i - 1);
789 if (QAccessibleInterface *iface = factory(cn, object)) {
790 QAccessibleCache::instance()->insert(object, iface);
791 Q_ASSERT(QAccessibleCache::instance()->containsObject(object));
797 if (!qAccessiblePlugins()->contains(cn)) {
798 QAccessiblePlugin *factory =
nullptr;
799 const int index = acLoader()->indexOf(cn);
801 factory = qobject_cast<QAccessiblePlugin *>(acLoader()->instance(index));
802 qAccessiblePlugins()->insert(cn, factory);
806 Q_ASSERT(qAccessiblePlugins()->contains(cn));
807 QAccessiblePlugin *factory = qAccessiblePlugins()->value(cn);
809 QAccessibleInterface *result = factory->create(cn, object);
811 QAccessibleCache::instance()->insert(object, result);
812 Q_ASSERT(QAccessibleCache::instance()->containsObject(object));
816 mo = mo->superClass();
819 if (object == qApp) {
820 QAccessibleInterface *appInterface =
new QAccessibleApplication;
821 QAccessibleCache::instance()->insert(object, appInterface);
822 Q_ASSERT(QAccessibleCache::instance()->containsObject(qApp));
830
831
832
833
834
835
836
837
838
839
840
841
842
843QAccessible::Id QAccessible::registerAccessibleInterface(QAccessibleInterface *iface)
846 return QAccessibleCache::instance()->insert(iface->object(), iface);
850
851
852
853
854void QAccessible::deleteAccessibleInterface(Id id)
856 QAccessibleCache::instance()->deleteInterface(id);
860
861
862QAccessible::Id QAccessible::uniqueId(QAccessibleInterface *iface)
864 Id id = QAccessibleCache::instance()->idForInterface(iface);
866 id = registerAccessibleInterface(iface);
871
872
873
874
875QAccessibleInterface *QAccessible::accessibleInterface(Id id)
877 return QAccessibleCache::instance()->interfaceForId(id);
882
883
884
885
886
887
888
889
890
891
892bool QAccessible::isActive()
894 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
895 return pfAccessibility->isActive();
900
901
902void QAccessible::setActive(
bool active)
904 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
905 pfAccessibility->setActive(active);
909
910
911
912
913
914
915
916
917
918
919
920
921
922void QAccessible::setRootObject(QObject *object)
924 if (rootObjectHandler) {
925 rootObjectHandler(object);
929 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
930 pfAccessibility->setRootObject(object);
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952void QAccessible::updateAccessibility(QAccessibleEvent *event)
961 QAccessibleInterface *iface = event->accessibleInterface();
963 if (event->type() == QAccessible::TableModelChanged) {
964 if (iface->tableInterface())
965 iface->tableInterface()->modelChange(
static_cast<QAccessibleTableModelChangeEvent*>(event));
970 updateHandler(event);
974 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
975 pfAccessibility->notifyAccessibilityUpdate(event);
978static std::pair<
int,
int> qAccessibleTextBoundaryHelperHelper(QTextCursor &cursor,
979 QTextCursor::MoveOperation start,
980 QTextCursor::MoveOperation end)
982 std::pair<
int,
int> result;
983 cursor.movePosition(start, QTextCursor::MoveAnchor);
984 result.first = cursor.position();
985 cursor.movePosition(end, QTextCursor::KeepAnchor);
986 result.second = cursor.position();
991
992
993
994
995
996
997std::pair<
int,
int > QAccessible::qAccessibleTextBoundaryHelper(
const QTextCursor &offsetCursor, TextBoundaryType boundaryType)
999 Q_ASSERT(!offsetCursor.isNull());
1001 QTextCursor cursor = offsetCursor;
1002 switch (boundaryType) {
1004 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::NoMove,
1005 QTextCursor::NextCharacter);
1007 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::StartOfWord,
1008 QTextCursor::EndOfWord);
1009 case SentenceBoundary: {
1013 std::pair<
int,
int> result = qAccessibleTextBoundaryHelperHelper(
1014 cursor, QTextCursor::StartOfBlock, QTextCursor::EndOfBlock);
1015 QString blockText = cursor.selectedText();
1016 const int offsetWithinBlockText = offsetCursor.position() - result.first;
1017 QTextBoundaryFinder sentenceFinder(QTextBoundaryFinder::Sentence, blockText);
1018 sentenceFinder.setPosition(offsetWithinBlockText);
1019 int prevBoundary = offsetWithinBlockText;
1020 int nextBoundary = offsetWithinBlockText;
1021 if (!(sentenceFinder.boundaryReasons() & QTextBoundaryFinder::StartOfItem))
1022 prevBoundary = sentenceFinder.toPreviousBoundary();
1023 nextBoundary = sentenceFinder.toNextBoundary();
1024 if (nextBoundary != -1)
1025 result.second = result.first + nextBoundary;
1026 if (prevBoundary != -1)
1027 result.first += prevBoundary;
1031 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::StartOfLine,
1032 QTextCursor::EndOfLine);
1033 case ParagraphBoundary:
1034 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::StartOfBlock,
1035 QTextCursor::EndOfBlock);
1037 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::Start, QTextCursor::End);
1040 Q_UNREACHABLE_RETURN({});
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
1138
1139
1140
1141
1142
1143
1144
1145
1148
1149
1150
1151
1152
1153
1154
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1169
1170
1171
1172
1173
1174
1175
1176
1177
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189QList<std::pair<QAccessibleInterface*, QAccessible::Relation>>
1190QAccessibleInterface::relations(QAccessible::Relation match)
const
1197
1198
1199
1200
1201QAccessibleInterface *QAccessibleInterface::focusChild()
const
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1226
1227
1228
1229
1230
1231
1232
1233
1236
1237
1238
1239
1240
1241
1242
1243
1244
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
1296
1297
1298
1299
1300
1301
1302
1303
1304
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1320
1321
1322
1323
1324
1325
1326
1327
1328
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1343
1344
1345
1346
1347QColor QAccessibleInterface::foregroundColor()
const
1353
1354
1355
1356
1357QColor QAccessibleInterface::backgroundColor()
const
1363
1364
1367
1368
1369
1372
1373
1376
1377
1380
1381
1384
1385
1388
1389
1390
1393
1394
1395
1398
1399
1400
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1423
1424
1425
1426
1429
1430
1431
1432
1433
1434
1437
1438
1439QAccessibleEvent::~QAccessibleEvent()
1444
1445
1448
1449
1452
1453
1456
1457
1460
1461
1462
1463
1464
1465
1466QAccessible::Id QAccessibleEvent::uniqueId()
const
1470 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
1473 if (m_child != -1) {
1474 iface = iface->child(m_child);
1475 if (Q_UNLIKELY(!iface)) {
1476 qCWarning(lcAccessibilityCore) <<
"Invalid child in QAccessibleEvent:" << m_object <<
"child:" << m_child;
1480 return QAccessible::uniqueId(iface);
1483void QAccessibleEvent::setChild(
int chld)
1485 if (m_type == QAccessible::ObjectDestroyed)
1486 qCWarning(lcAccessibilityCore) <<
"Calling QAccessibleEvent::setChild on ObjectDestroyed event " <<
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1504
1505
1506
1507
1509
1510
1511
1512
1515
1516
1517
1519
1520
1521
1522
1525
1526
1527QAccessibleValueChangeEvent::~QAccessibleValueChangeEvent()
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1544
1545
1546
1547
1549
1550
1551
1552
1553
1554
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1568
1569
1570QAccessibleStateChangeEvent::~QAccessibleStateChangeEvent()
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1588
1589
1590
1591
1592
1593
1594
1595
1597
1598
1599
1601
1602
1603
1605
1606
1607
1609
1610
1611
1613
1614
1615
1617
1618
1619
1621
1622
1623
1625
1626
1627
1629
1630
1631
1633
1634
1635
1637
1638
1639
1641
1642
1643
1644
1645
1647
1648
1649QAccessibleTableModelChangeEvent::~QAccessibleTableModelChangeEvent()
1653
1654
1655
1656
1657
1658
1659
1660
1662
1663
1664
1665
1667
1668
1669
1671
1672
1673
1675
1676
1677QAccessibleTextCursorEvent::~QAccessibleTextCursorEvent()
1683
1684
1685
1686
1687
1690
1691
1692
1693
1694
1695
1696
1697
1699
1700
1701
1702
1703
1704
1705
1707
1708
1709
1711
1712
1713
1715
1716
1717QAccessibleTextInsertEvent::~QAccessibleTextInsertEvent()
1723
1724
1725
1726
1727
1728
1729
1730
1732
1733
1734
1735
1736
1737
1738
1740
1741
1742
1743
1744
1745
1746
1749
1750
1751
1753
1754
1755
1757
1758
1759QAccessibleTextRemoveEvent::~QAccessibleTextRemoveEvent()
1764
1765
1766
1767
1768
1771
1772
1773
1774
1775
1778
1779
1780
1781
1782
1783
1784
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1801
1802
1803
1804
1806
1807
1808
1810
1811
1812
1814
1815
1816
1818
1819
1820QAccessibleTextUpdateEvent::~QAccessibleTextUpdateEvent()
1826
1827
1828
1829
1830
1831
1832
1833
1835
1836
1837
1838
1840
1841
1842
1844
1845
1846
1848
1849
1850
1852
1853
1854QAccessibleTextSelectionEvent::~QAccessibleTextSelectionEvent()
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1871
1872
1873
1874
1875
1876
1877
1880
1881
1882
1883
1884
1885
1886
1889
1890
1891
1894
1895
1896
1899
1900
1901
1905
1906
1907QAccessibleAnnouncementEvent::~QAccessibleAnnouncementEvent()
1912
1913
1914QAccessibleInterface *QAccessibleEvent::accessibleInterface()
const
1916 if (m_object ==
nullptr)
1917 return QAccessible::accessibleInterface(m_uniqueId);
1919 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
1920 if (!iface || !iface->isValid())
1924 QAccessibleInterface *child = iface->child(m_child);
1928 qCWarning(lcAccessibilityCore) <<
"Cannot create accessible child interface for object: " << m_object <<
" index: " << m_child <<
"type: " << m_type;
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947QWindow *QAccessibleInterface::window()
const
1953
1954
1955
1956
1957
1958
1959
1960void QAccessibleInterface::virtual_hook(
int ,
void * )
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1982const char *qAccessibleRoleString(QAccessible::Role role)
1984 if (role >= QAccessible::UserRole)
1985 role = QAccessible::UserRole;
1986 static int roleEnum = QAccessible::staticMetaObject.indexOfEnumerator(
"Role");
1987 return QAccessible::staticMetaObject.enumerator(roleEnum).valueToKey(role);
1991const char *qAccessibleEventString(QAccessible::Event event)
1993 static int eventEnum = QAccessible::staticMetaObject.indexOfEnumerator(
"Event");
1994 return QAccessible::staticMetaObject.enumerator(eventEnum).valueToKey(event);
1997#ifndef QT_NO_DEBUG_STREAM
1999Q_GUI_EXPORT QDebug operator<<(QDebug d,
const QAccessibleInterface *iface)
2001 QDebugStateSaver saver(d);
2003 return d <<
"QAccessibleInterface(0x0)";
2006 d <<
"QAccessibleInterface(" << Qt::hex << (
const void *) iface << Qt::dec;
2007 if (iface->isValid()) {
2008 d <<
" name=" << iface->text(QAccessible::Name) <<
' ';
2009 d <<
"role=" << qAccessibleRoleString(iface->role()) <<
' ';
2010 if (iface->childCount())
2011 d <<
"childc=" << iface->childCount() <<
' ';
2012 if (iface->object()) {
2013 d <<
"obj=" << iface->object();
2015 QStringList stateStrings;
2016 QAccessible::State st = iface->state();
2018 stateStrings << u"focusable"_s;
2020 stateStrings << u"focused"_s;
2022 stateStrings << u"selected"_s;
2024 stateStrings << u"invisible"_s;
2026 if (!stateStrings.isEmpty())
2027 d << stateStrings.join(u'|');
2030 d <<
"rect=" << iface->rect();
2040QDebug operator<<(QDebug d,
const QAccessibleEvent &ev)
2042 QDebugStateSaver saver(d);
2043 d.nospace() <<
"QAccessibleEvent(";
2045 d.nospace() <<
"object=" << Qt::hex << ev.object() << Qt::dec;
2046 d.nospace() <<
"child=" << ev.child();
2048 d.nospace() <<
"no object, uniqueId=" << ev.uniqueId();
2050 d <<
" event=" << qAccessibleEventString(ev.type());
2051 if (ev.type() == QAccessible::StateChanged) {
2052 QAccessible::State changed =
static_cast<
const QAccessibleStateChangeEvent*>(&ev)->changedStates();
2053 d <<
"State changed:";
2054 if (changed.disabled) d <<
"disabled";
2055 if (changed.selected) d <<
"selected";
2056 if (changed.focusable) d <<
"focusable";
2057 if (changed.focused) d <<
"focused";
2058 if (changed.pressed) d <<
"pressed";
2059 if (changed.checkable) d <<
"checkable";
2060 if (changed.checked) d <<
"checked";
2061 if (changed.checkStateMixed) d <<
"checkStateMixed";
2062 if (changed.readOnly) d <<
"readOnly";
2063 if (changed.hotTracked) d <<
"hotTracked";
2064 if (changed.defaultButton) d <<
"defaultButton";
2065 if (changed.expanded) d <<
"expanded";
2066 if (changed.collapsed) d <<
"collapsed";
2067 if (changed.busy) d <<
"busy";
2068 if (changed.expandable) d <<
"expandable";
2069 if (changed.marqueed) d <<
"marqueed";
2070 if (changed.animated) d <<
"animated";
2071 if (changed.invisible) d <<
"invisible";
2072 if (changed.offscreen) d <<
"offscreen";
2073 if (changed.sizeable) d <<
"sizeable";
2074 if (changed.movable) d <<
"movable";
2075 if (changed.selfVoicing) d <<
"selfVoicing";
2076 if (changed.selectable) d <<
"selectable";
2077 if (changed.linked) d <<
"linked";
2078 if (changed.traversed) d <<
"traversed";
2079 if (changed.multiSelectable) d <<
"multiSelectable";
2080 if (changed.extSelectable) d <<
"extSelectable";
2081 if (changed.passwordEdit) d <<
"passwordEdit";
2082 if (changed.hasPopup) d <<
"hasPopup";
2083 if (changed.modal) d <<
"modal";
2087 if (changed.active) d <<
"active";
2088 if (changed.invalid) d <<
"invalid";
2089 if (changed.editable) d <<
"editable";
2090 if (changed.multiLine) d <<
"multiLine";
2091 if (changed.selectableText) d <<
"selectableText";
2092 if (changed.supportsAutoCompletion) d <<
"supportsAutoCompletion";
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2120
2121
2122
2123QAccessibleTextInterface::~QAccessibleTextInterface()
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2141
2142
2143
2144
2145
2148
2149
2150
2151
2154
2155
2156
2157
2160
2161
2162
2163
2166
2167
2168
2169
2172
2173
2174
2175
2176
2177
2178
2179
2182
2183
2184
2185
2186
2187
2190
2191
2192
2193
2194static QString textLineBoundary(
int beforeAtAfter,
const QString &text,
int offset,
int *startOffset,
int *endOffset)
2196 Q_ASSERT(beforeAtAfter >= -1 && beforeAtAfter <= 1);
2197 Q_ASSERT(*startOffset == -1 && *endOffset == -1);
2198 int length = text.size();
2199 Q_ASSERT(offset >= 0 && offset <= length);
2202 if (beforeAtAfter == 1) {
2203 offset = text.indexOf(QChar::LineFeed, qMin(offset, length - 1));
2207 }
else if (beforeAtAfter == -1) {
2208 offset = text.lastIndexOf(QChar::LineFeed, qMax(offset - 1, 0));
2214 *startOffset = text.lastIndexOf(QChar::LineFeed, offset - 1);
2217 *endOffset = text.indexOf(QChar::LineFeed, qMin(offset, length - 1)) + 1;
2218 if (*endOffset <= 0 || *endOffset > length)
2219 *endOffset = length;
2221 return text.mid(*startOffset, *endOffset - *startOffset);
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241QString QAccessibleTextInterface::textBeforeOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2242 int *startOffset,
int *endOffset)
const
2244 const QString txt = text(0, characterCount());
2247 offset = txt.size();
2249 *startOffset = *endOffset = -1;
2250 if (txt.isEmpty() || offset <= 0 || offset > txt.size())
2254 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2255 switch (boundaryType) {
2256 case QAccessible::CharBoundary:
2257 type = QTextBoundaryFinder::Grapheme;
2259 case QAccessible::WordBoundary:
2260 type = QTextBoundaryFinder::Word;
2262 case QAccessible::SentenceBoundary:
2263 type = QTextBoundaryFinder::Sentence;
2265 case QAccessible::LineBoundary:
2266 case QAccessible::ParagraphBoundary:
2268 return textLineBoundary(-1, txt, offset, startOffset, endOffset);
2269 case QAccessible::NoBoundary:
2278 QTextBoundaryFinder boundary(type, txt);
2279 boundary.setPosition(offset);
2282 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2284 }
while (boundary.toPreviousBoundary() > 0);
2285 Q_ASSERT(boundary.position() >= 0);
2286 const int endPos = boundary.position();
2288 while (boundary.toPreviousBoundary() > 0) {
2289 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2292 if (boundary.position() < 0)
2295 *endOffset = endPos;
2296 *startOffset = boundary.position();
2298 return txt.mid(*startOffset, *endOffset - *startOffset);
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318QString QAccessibleTextInterface::textAfterOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2319 int *startOffset,
int *endOffset)
const
2321 const QString txt = text(0, characterCount());
2324 offset = txt.size();
2326 *startOffset = *endOffset = -1;
2327 if (txt.isEmpty() || offset < 0 || offset >= txt.size())
2331 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2332 switch (boundaryType) {
2333 case QAccessible::CharBoundary:
2334 type = QTextBoundaryFinder::Grapheme;
2336 case QAccessible::WordBoundary:
2337 type = QTextBoundaryFinder::Word;
2339 case QAccessible::SentenceBoundary:
2340 type = QTextBoundaryFinder::Sentence;
2342 case QAccessible::LineBoundary:
2343 case QAccessible::ParagraphBoundary:
2345 return textLineBoundary(1, txt, offset, startOffset, endOffset);
2346 case QAccessible::NoBoundary:
2355 QTextBoundaryFinder boundary(type, txt);
2356 boundary.setPosition(offset);
2359 int toNext = boundary.toNextBoundary();
2360 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2362 if (toNext < 0 || toNext >= txt.size())
2365 Q_ASSERT(boundary.position() <= txt.size());
2366 *startOffset = boundary.position();
2369 int toNext = boundary.toNextBoundary();
2370 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2372 if (toNext < 0 || toNext >= txt.size())
2375 Q_ASSERT(boundary.position() <= txt.size());
2376 *endOffset = boundary.position();
2378 if ((*startOffset == -1) || (*endOffset == -1) || (*startOffset == *endOffset)) {
2383 return txt.mid(*startOffset, *endOffset - *startOffset);
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403QString QAccessibleTextInterface::textAtOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2404 int *startOffset,
int *endOffset)
const
2406 const QString txt = text(0, characterCount());
2409 offset = txt.size();
2411 *startOffset = *endOffset = -1;
2412 if (txt.isEmpty() || offset < 0 || offset > txt.size())
2415 if (offset == txt.size() && boundaryType == QAccessible::CharBoundary)
2419 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2420 switch (boundaryType) {
2421 case QAccessible::CharBoundary:
2422 type = QTextBoundaryFinder::Grapheme;
2424 case QAccessible::WordBoundary:
2425 type = QTextBoundaryFinder::Word;
2427 case QAccessible::SentenceBoundary:
2428 type = QTextBoundaryFinder::Sentence;
2430 case QAccessible::LineBoundary:
2431 case QAccessible::ParagraphBoundary:
2433 return textLineBoundary(0, txt, offset, startOffset, endOffset);
2434 case QAccessible::NoBoundary:
2436 *endOffset = txt.size();
2444 QTextBoundaryFinder boundary(type, txt);
2445 boundary.setPosition(offset);
2448 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2450 }
while (boundary.toPreviousBoundary() > 0);
2451 Q_ASSERT(boundary.position() >= 0);
2452 const int startPos = boundary.position();
2454 while (boundary.toNextBoundary() < txt.size()) {
2455 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2457 if (boundary.position() == -1)
2461 Q_ASSERT(boundary.position() <= txt.size());
2462 *startOffset = startPos;
2463 *endOffset = boundary.position();
2465 return txt.mid(*startOffset, *endOffset - *startOffset);
2469
2470
2471
2472
2475
2476
2477
2478
2481
2482
2483
2484
2485
2486
2489
2490
2491
2492
2495
2496
2497
2498
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2515
2516
2517
2518QAccessibleEditableTextInterface::~QAccessibleEditableTextInterface()
2523
2524
2525
2526
2529
2530
2531
2532
2535
2536
2537
2538
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2559
2560
2561
2562QAccessibleValueInterface::~QAccessibleValueInterface()
2567
2568
2569
2570
2571
2574
2575
2576
2577
2578
2579
2580
2583
2584
2585
2586
2587
2590
2591
2592
2593
2594
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2623
2624
2625QAccessibleImageInterface::~QAccessibleImageInterface()
2630
2631
2632
2633
2634
2635
2636
2637
2638
2641
2642
2643
2644QAccessibleTableCellInterface::~QAccessibleTableCellInterface()
2649
2650
2651
2652
2655
2656
2657
2658
2661
2662
2663
2664
2667
2668
2669
2670
2673
2674
2675
2676
2679
2680
2681
2682
2685
2686
2687
2688
2691
2692
2693
2694
2698
2699
2700
2701
2702
2703
2704
2705
2706
2709
2710
2711
2712QAccessibleTableInterface::~QAccessibleTableInterface()
2717
2718
2719
2720
2723
2724
2725
2726
2729
2730
2731
2732
2735
2736
2737
2738
2741
2742
2743
2744
2747
2748
2749
2750
2753
2754
2755
2756
2759
2760
2761
2762
2765
2766
2767
2768
2771
2772
2773
2774
2777
2778
2779
2780
2783
2784
2785
2786
2789
2790
2791
2792
2793
2796
2797
2798
2799
2802
2803
2804
2805
2808
2809
2810
2811
2812
2815
2816
2817
2818
2819
2822
2823
2824
2825
2826
2829
2830
2831
2832
2833
2836
2837
2838
2839
2840
2841
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2886
2887
2888
2889QAccessibleActionInterface::~QAccessibleActionInterface()
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2925
2926
2927
2928
2929
2930
2931
2932
2933
2936
2937
2938
2939
2940
2941
2942
2943
2944
2947
2948
2949
2950
2951
2952
2953
2954
2957struct QAccessibleActionStrings
2959 QAccessibleActionStrings() :
2960 pressAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Press"))),
2961 increaseAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Increase"))),
2962 decreaseAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Decrease"))),
2963 showMenuAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Show Menu"))),
2964 setFocusAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Set Focus"))),
2965 showOnScreenAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Show on Screen"))),
2966 toggleAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Toggle"))),
2967 scrollLeftAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Left"))),
2968 scrollRightAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Right"))),
2969 scrollUpAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Up"))),
2970 scrollDownAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Down"))),
2971 previousPageAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Previous Page"))),
2972 nextPageAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Next Page")))
2975 const QString pressAction;
2976 const QString increaseAction;
2977 const QString decreaseAction;
2978 const QString showMenuAction;
2979 const QString setFocusAction;
2980 const QString showOnScreenAction;
2981 const QString toggleAction;
2982 const QString scrollLeftAction;
2983 const QString scrollRightAction;
2984 const QString scrollUpAction;
2985 const QString scrollDownAction;
2986 const QString previousPageAction;
2987 const QString nextPageAction;
2989 QString localizedDescription(
const QString &actionName)
2991 if (actionName == pressAction)
2992 return QAccessibleActionInterface::tr(
"Triggers the action");
2993 else if (actionName == increaseAction)
2994 return QAccessibleActionInterface::tr(
"Increase the value");
2995 else if (actionName == decreaseAction)
2996 return QAccessibleActionInterface::tr(
"Decrease the value");
2997 else if (actionName == showMenuAction)
2998 return QAccessibleActionInterface::tr(
"Shows the menu");
2999 else if (actionName == setFocusAction)
3000 return QAccessibleActionInterface::tr(
"Sets the focus");
3001 else if (actionName == showOnScreenAction)
3002 return QAccessibleActionInterface::tr(
"Moves the element into the visible area");
3003 else if (actionName == toggleAction)
3004 return QAccessibleActionInterface::tr(
"Toggles the state");
3005 else if (actionName == scrollLeftAction)
3006 return QAccessibleActionInterface::tr(
"Scrolls to the left");
3007 else if (actionName == scrollRightAction)
3008 return QAccessibleActionInterface::tr(
"Scrolls to the right");
3009 else if (actionName == scrollUpAction)
3010 return QAccessibleActionInterface::tr(
"Scrolls up");
3011 else if (actionName == scrollDownAction)
3012 return QAccessibleActionInterface::tr(
"Scrolls down");
3013 else if (actionName == previousPageAction)
3014 return QAccessibleActionInterface::tr(
"Goes back a page");
3015 else if (actionName == nextPageAction)
3016 return QAccessibleActionInterface::tr(
"Goes to the next page");
3023Q_GLOBAL_STATIC(QAccessibleActionStrings, accessibleActionStrings)
3025QString QAccessibleActionInterface::localizedActionName(
const QString &actionName)
const
3027 return QAccessibleActionInterface::tr(qPrintable(actionName));
3030QString QAccessibleActionInterface::localizedActionDescription(
const QString &actionName)
const
3032 return accessibleActionStrings()->localizedDescription(actionName);
3036
3037
3038
3039const QString &QAccessibleActionInterface::pressAction()
3041 return accessibleActionStrings()->pressAction;
3045
3046
3047
3048const QString &QAccessibleActionInterface::increaseAction()
3050 return accessibleActionStrings()->increaseAction;
3054
3055
3056
3057const QString &QAccessibleActionInterface::decreaseAction()
3059 return accessibleActionStrings()->decreaseAction;
3063
3064
3065
3066const QString &QAccessibleActionInterface::showMenuAction()
3068 return accessibleActionStrings()->showMenuAction;
3072
3073
3074
3075const QString &QAccessibleActionInterface::setFocusAction()
3077 return accessibleActionStrings()->setFocusAction;
3081
3082
3083
3084const QString &QAccessibleActionInterface::showOnScreenAction()
3086 return accessibleActionStrings()->showOnScreenAction;
3090
3091
3092
3093const QString &QAccessibleActionInterface::toggleAction()
3095 return accessibleActionStrings()->toggleAction;
3099
3100
3101
3102QString QAccessibleActionInterface::scrollLeftAction()
3104 return accessibleActionStrings()->scrollLeftAction;
3108
3109
3110
3111QString QAccessibleActionInterface::scrollRightAction()
3113 return accessibleActionStrings()->scrollRightAction;
3117
3118
3119
3120QString QAccessibleActionInterface::scrollUpAction()
3122 return accessibleActionStrings()->scrollUpAction;
3126
3127
3128
3129QString QAccessibleActionInterface::scrollDownAction()
3131 return accessibleActionStrings()->scrollDownAction;
3135
3136
3137
3138QString QAccessibleActionInterface::previousPageAction()
3140 return accessibleActionStrings()->previousPageAction;
3144
3145
3146
3147QString QAccessibleActionInterface::nextPageAction()
3149 return accessibleActionStrings()->nextPageAction;
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3169
3170
3171
3172QAccessibleSelectionInterface::~QAccessibleSelectionInterface()
3177
3178
3179
3180
3183
3184
3185
3186
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201QAccessibleInterface* QAccessibleSelectionInterface::selectedItem(
int selectionIndex)
const
3203 QList<QAccessibleInterface*> items = selectedItems();
3204 if (selectionIndex < 0 || selectionIndex > items.length() -1) {
3205 qCWarning(lcAccessibilityCore) <<
"Selection index" << selectionIndex <<
"out of range.";
3209 return items.at(selectionIndex);
3213
3214
3215
3216
3217
3218bool QAccessibleSelectionInterface::isSelected(QAccessibleInterface *childItem)
const
3220 return selectedItems().contains(childItem);
3224
3225
3226
3227
3228
3229
3230
3231
3234
3235
3236
3237
3238
3239
3242
3243
3244
3245
3246
3247
3250
3251
3252
3253
3254
3255
3256
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3284
3285
3286
3287QAccessibleAttributesInterface::~QAccessibleAttributesInterface()
3292
3293
3294
3295
3296
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3311QString qAccessibleLocalizedActionDescription(
const QString &actionName)
3313 return accessibleActionStrings()->localizedDescription(actionName);
3317
3318
3319
3320
3321
3324
3325
3326
3327
3328
3331
3332
3333
3334
3335
3336
3337
3338
3341
3342
3343
3344
3345
3346
3347
3349QAccessibleHyperlinkInterface::~QAccessibleHyperlinkInterface()
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3368
3369
3370
3371QAccessibleViewportInterface::~QAccessibleViewportInterface()
3376
3377
3378
3379
3380
3381
3384
3385
3386
3387
3390
3391
3392
3393
3396
3397
3398
3399
3402
3403
3404
3405
3411#include "moc_qaccessible_base.cpp"
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)