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
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
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
411
412
413
414
415
416
417
418
419
420
421
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
519#if QT_CONFIG(accessibility)
522
523
524QAccessibleInterface::~QAccessibleInterface()
529
530
531
532
536Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, acLoader,
537 (QAccessibleFactoryInterface_iid,
"/accessible"_L1))
538typedef QHash<QString, QAccessiblePlugin*> QAccessiblePluginsHash;
539Q_GLOBAL_STATIC(QAccessiblePluginsHash, qAccessiblePlugins)
542Q_GLOBAL_STATIC(QList<QAccessible::InterfaceFactory>, qAccessibleFactories)
543Q_GLOBAL_STATIC(QList<QAccessible::ActivationObserver *>, qAccessibleActivationObservers)
545QAccessible::UpdateHandler QAccessible::updateHandler =
nullptr;
546QAccessible::RootObjectHandler QAccessible::rootObjectHandler =
nullptr;
548static bool cleanupAdded =
false;
550static QPlatformAccessibility *platformAccessibility()
552 QPlatformIntegration *pfIntegration = QGuiApplicationPrivate::platformIntegration();
553 return pfIntegration ? pfIntegration->accessibility() :
nullptr;
557
558
559
560
561
562
566
567
568void QAccessible::cleanup()
570 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
571 pfAccessibility->cleanup();
574static void qAccessibleCleanup()
576 qAccessibleActivationObservers()->clear();
577 qAccessibleFactories()->clear();
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
601
602
603
604
605
606
607
608
609
612
613
614
615
616
617
618
619
620
624
625
626
627void QAccessible::installFactory(InterfaceFactory factory)
633 qAddPostRoutine(qAccessibleCleanup);
636 if (qAccessibleFactories()->contains(factory))
638 qAccessibleFactories()->append(factory);
642
643
644void QAccessible::removeFactory(InterfaceFactory factory)
646 qAccessibleFactories()->removeAll(factory);
650
651
652
653
654
655
656QAccessible::UpdateHandler QAccessible::installUpdateHandler(UpdateHandler handler)
658 UpdateHandler old = updateHandler;
659 updateHandler = handler;
664
665
666
667
668
669QAccessible::RootObjectHandler QAccessible::installRootObjectHandler(RootObjectHandler handler)
671 RootObjectHandler old = rootObjectHandler;
672 rootObjectHandler = handler;
677
678
679
680
681
682
684QAccessible::ActivationObserver::~ActivationObserver()
689
690
691
692
693void QAccessible::installActivationObserver(QAccessible::ActivationObserver *observer)
699 qAddPostRoutine(qAccessibleCleanup);
702 if (qAccessibleActivationObservers()->contains(observer))
704 qAccessibleActivationObservers()->append(observer);
708 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
709 pfAccessibility->clearActiveNotificationState();
713
714
715
716
717
718void QAccessible::removeActivationObserver(ActivationObserver *observer)
720 qAccessibleActivationObservers()->removeAll(observer);
724
725
726
727
728void qAccessibleNotifyActivationObservers(
bool active)
730 for (
int i = 0; i < qAccessibleActivationObservers()->size(); ++i)
731 qAccessibleActivationObservers()->at(i)->accessibilityActiveChanged(active);
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752QAccessibleInterface *QAccessible::queryAccessibleInterface(QObject *object)
757 if (Id id = QAccessibleCache::instance()->idForObject(object))
758 return QAccessibleCache::instance()->interfaceForId(id);
762 const QMetaObject *mo = object->metaObject();
763 const auto *objectPriv = QObjectPrivate::get(object);
765
766
767
768
769
770
771
772
773 const bool qmlRelated = !objectPriv->isDeletingChildren &&
774 objectPriv->declarativeData;
775 while (qmlRelated && mo) {
776 auto mop = QMetaObjectPrivate::get(mo);
777 if (!mop || !(mop->flags & DynamicMetaObject))
780 mo = mo->superClass();
783 const QString cn = QLatin1StringView(mo->className());
786 for (
int i = qAccessibleFactories()->size(); i > 0; --i) {
787 InterfaceFactory factory = qAccessibleFactories()->at(i - 1);
788 if (QAccessibleInterface *iface = factory(cn, object)) {
789 QAccessibleCache::instance()->insert(object, iface);
790 Q_ASSERT(QAccessibleCache::instance()->containsObject(object));
796 if (!qAccessiblePlugins()->contains(cn)) {
797 QAccessiblePlugin *factory =
nullptr;
798 const int index = acLoader()->indexOf(cn);
800 factory = qobject_cast<QAccessiblePlugin *>(acLoader()->instance(index));
801 qAccessiblePlugins()->insert(cn, factory);
805 Q_ASSERT(qAccessiblePlugins()->contains(cn));
806 QAccessiblePlugin *factory = qAccessiblePlugins()->value(cn);
808 QAccessibleInterface *result = factory->create(cn, object);
810 QAccessibleCache::instance()->insert(object, result);
811 Q_ASSERT(QAccessibleCache::instance()->containsObject(object));
815 mo = mo->superClass();
818 if (object == qApp) {
819 QAccessibleInterface *appInterface =
new QAccessibleApplication;
820 QAccessibleCache::instance()->insert(object, appInterface);
821 Q_ASSERT(QAccessibleCache::instance()->containsObject(qApp));
829
830
831
832
833
834
835
836
837
838
839
840
841
842QAccessible::Id QAccessible::registerAccessibleInterface(QAccessibleInterface *iface)
845 return QAccessibleCache::instance()->insert(iface->object(), iface);
849
850
851
852
853void QAccessible::deleteAccessibleInterface(Id id)
855 QAccessibleCache::instance()->deleteInterface(id);
859
860
861QAccessible::Id QAccessible::uniqueId(QAccessibleInterface *iface)
863 Id id = QAccessibleCache::instance()->idForInterface(iface);
865 id = registerAccessibleInterface(iface);
870
871
872
873
874QAccessibleInterface *QAccessible::accessibleInterface(Id id)
876 return QAccessibleCache::instance()->interfaceForId(id);
881
882
883
884
885
886
887
888
889
890
891bool QAccessible::isActive()
893 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
894 return pfAccessibility->isActive();
899
900
901void QAccessible::setActive(
bool active)
903 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
904 pfAccessibility->setActive(active);
908
909
910
911
912
913
914
915
916
917
918
919
920
921void QAccessible::setRootObject(QObject *object)
923 if (rootObjectHandler) {
924 rootObjectHandler(object);
928 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
929 pfAccessibility->setRootObject(object);
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951void QAccessible::updateAccessibility(QAccessibleEvent *event)
960 QAccessibleInterface *iface = event->accessibleInterface();
962 if (event->type() == QAccessible::TableModelChanged) {
963 if (iface->tableInterface())
964 iface->tableInterface()->modelChange(
static_cast<QAccessibleTableModelChangeEvent*>(event));
969 updateHandler(event);
973 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
974 pfAccessibility->notifyAccessibilityUpdate(event);
977static std::pair<
int,
int> qAccessibleTextBoundaryHelperHelper(QTextCursor &cursor,
978 QTextCursor::MoveOperation start,
979 QTextCursor::MoveOperation end)
981 std::pair<
int,
int> result;
982 cursor.movePosition(start, QTextCursor::MoveAnchor);
983 result.first = cursor.position();
984 cursor.movePosition(end, QTextCursor::KeepAnchor);
985 result.second = cursor.position();
990
991
992
993
994
995
996std::pair<
int,
int > QAccessible::qAccessibleTextBoundaryHelper(
const QTextCursor &offsetCursor, TextBoundaryType boundaryType)
998 Q_ASSERT(!offsetCursor.isNull());
1000 QTextCursor cursor = offsetCursor;
1001 switch (boundaryType) {
1003 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::NoMove,
1004 QTextCursor::NextCharacter);
1006 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::StartOfWord,
1007 QTextCursor::EndOfWord);
1008 case SentenceBoundary: {
1012 std::pair<
int,
int> result = qAccessibleTextBoundaryHelperHelper(
1013 cursor, QTextCursor::StartOfBlock, QTextCursor::EndOfBlock);
1014 QString blockText = cursor.selectedText();
1015 const int offsetWithinBlockText = offsetCursor.position() - result.first;
1016 QTextBoundaryFinder sentenceFinder(QTextBoundaryFinder::Sentence, blockText);
1017 sentenceFinder.setPosition(offsetWithinBlockText);
1018 int prevBoundary = offsetWithinBlockText;
1019 int nextBoundary = offsetWithinBlockText;
1020 if (!(sentenceFinder.boundaryReasons() & QTextBoundaryFinder::StartOfItem))
1021 prevBoundary = sentenceFinder.toPreviousBoundary();
1022 nextBoundary = sentenceFinder.toNextBoundary();
1023 if (nextBoundary != -1)
1024 result.second = result.first + nextBoundary;
1025 if (prevBoundary != -1)
1026 result.first += prevBoundary;
1030 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::StartOfLine,
1031 QTextCursor::EndOfLine);
1032 case ParagraphBoundary:
1033 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::StartOfBlock,
1034 QTextCursor::EndOfBlock);
1036 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::Start, QTextCursor::End);
1039 Q_UNREACHABLE_RETURN({});
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
1137
1138
1139
1140
1141
1142
1143
1144
1147
1148
1149
1150
1151
1152
1153
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1168
1169
1170
1171
1172
1173
1174
1175
1176
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188QList<std::pair<QAccessibleInterface*, QAccessible::Relation>>
1189QAccessibleInterface::relations(QAccessible::Relation match)
const
1196
1197
1198
1199
1200QAccessibleInterface *QAccessibleInterface::focusChild()
const
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1225
1226
1227
1228
1229
1230
1231
1232
1235
1236
1237
1238
1239
1240
1241
1242
1243
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
1295
1296
1297
1298
1299
1300
1301
1302
1303
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1319
1320
1321
1322
1323
1324
1325
1326
1327
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1342
1343
1344
1345
1346QColor QAccessibleInterface::foregroundColor()
const
1352
1353
1354
1355
1356QColor QAccessibleInterface::backgroundColor()
const
1362
1363
1366
1367
1368
1371
1372
1375
1376
1379
1380
1383
1384
1387
1388
1389
1392
1393
1394
1397
1398
1399
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1422
1423
1424
1425
1428
1429
1430
1431
1432
1433
1436
1437
1438QAccessibleEvent::~QAccessibleEvent()
1443
1444
1447
1448
1451
1452
1455
1456
1459
1460
1461
1462
1463
1464
1465QAccessible::Id QAccessibleEvent::uniqueId()
const
1469 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
1472 if (m_child != -1) {
1473 iface = iface->child(m_child);
1474 if (Q_UNLIKELY(!iface)) {
1475 qCWarning(lcAccessibilityCore) <<
"Invalid child in QAccessibleEvent:" << m_object <<
"child:" << m_child;
1479 return QAccessible::uniqueId(iface);
1482void QAccessibleEvent::setChild(
int chld)
1484 if (m_type == QAccessible::ObjectDestroyed)
1485 qCWarning(lcAccessibilityCore) <<
"Calling QAccessibleEvent::setChild on ObjectDestroyed event " <<
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1503
1504
1505
1506
1508
1509
1510
1511
1514
1515
1516
1518
1519
1520
1521
1524
1525
1526QAccessibleValueChangeEvent::~QAccessibleValueChangeEvent()
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1543
1544
1545
1546
1548
1549
1550
1551
1552
1553
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1567
1568
1569QAccessibleStateChangeEvent::~QAccessibleStateChangeEvent()
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1587
1588
1589
1590
1591
1592
1593
1594
1596
1597
1598
1600
1601
1602
1604
1605
1606
1608
1609
1610
1612
1613
1614
1616
1617
1618
1620
1621
1622
1624
1625
1626
1628
1629
1630
1632
1633
1634
1636
1637
1638
1640
1641
1642
1643
1644
1646
1647
1648QAccessibleTableModelChangeEvent::~QAccessibleTableModelChangeEvent()
1652
1653
1654
1655
1656
1657
1658
1659
1661
1662
1663
1664
1666
1667
1668
1670
1671
1672
1674
1675
1676QAccessibleTextCursorEvent::~QAccessibleTextCursorEvent()
1682
1683
1684
1685
1686
1689
1690
1691
1692
1693
1694
1695
1696
1698
1699
1700
1701
1702
1703
1704
1706
1707
1708
1710
1711
1712
1714
1715
1716QAccessibleTextInsertEvent::~QAccessibleTextInsertEvent()
1722
1723
1724
1725
1726
1727
1728
1729
1731
1732
1733
1734
1735
1736
1737
1739
1740
1741
1742
1743
1744
1745
1748
1749
1750
1752
1753
1754
1756
1757
1758QAccessibleTextRemoveEvent::~QAccessibleTextRemoveEvent()
1763
1764
1765
1766
1767
1770
1771
1772
1773
1774
1777
1778
1779
1780
1781
1782
1783
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1800
1801
1802
1803
1805
1806
1807
1809
1810
1811
1813
1814
1815
1817
1818
1819QAccessibleTextUpdateEvent::~QAccessibleTextUpdateEvent()
1825
1826
1827
1828
1829
1830
1831
1832
1834
1835
1836
1837
1839
1840
1841
1843
1844
1845
1847
1848
1849
1851
1852
1853QAccessibleTextSelectionEvent::~QAccessibleTextSelectionEvent()
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1870
1871
1872
1873
1874
1875
1876
1879
1880
1881
1882
1883
1884
1885
1888
1889
1890
1893
1894
1895
1898
1899
1900
1904
1905
1906QAccessibleAnnouncementEvent::~QAccessibleAnnouncementEvent()
1911
1912
1913QAccessibleInterface *QAccessibleEvent::accessibleInterface()
const
1915 if (m_object ==
nullptr)
1916 return QAccessible::accessibleInterface(m_uniqueId);
1918 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
1919 if (!iface || !iface->isValid())
1923 QAccessibleInterface *child = iface->child(m_child);
1927 qCWarning(lcAccessibilityCore) <<
"Cannot create accessible child interface for object: " << m_object <<
" index: " << m_child <<
"type: " << m_type;
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946QWindow *QAccessibleInterface::window()
const
1952
1953
1954
1955
1956
1957
1958
1959void QAccessibleInterface::virtual_hook(
int ,
void * )
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1981const char *qAccessibleRoleString(QAccessible::Role role)
1983 if (role >= QAccessible::UserRole)
1984 role = QAccessible::UserRole;
1985 static int roleEnum = QAccessible::staticMetaObject.indexOfEnumerator(
"Role");
1986 return QAccessible::staticMetaObject.enumerator(roleEnum).valueToKey(role);
1990const char *qAccessibleEventString(QAccessible::Event event)
1992 static int eventEnum = QAccessible::staticMetaObject.indexOfEnumerator(
"Event");
1993 return QAccessible::staticMetaObject.enumerator(eventEnum).valueToKey(event);
1996#ifndef QT_NO_DEBUG_STREAM
1998Q_GUI_EXPORT QDebug operator<<(QDebug d,
const QAccessibleInterface *iface)
2000 QDebugStateSaver saver(d);
2002 return d <<
"QAccessibleInterface(0x0)";
2005 d <<
"QAccessibleInterface(" << Qt::hex << (
const void *) iface << Qt::dec;
2006 if (iface->isValid()) {
2007 d <<
" name=" << iface->text(QAccessible::Name) <<
' ';
2008 d <<
"role=" << qAccessibleRoleString(iface->role()) <<
' ';
2009 if (iface->childCount())
2010 d <<
"childc=" << iface->childCount() <<
' ';
2011 if (iface->object()) {
2012 d <<
"obj=" << iface->object();
2014 QStringList stateStrings;
2015 QAccessible::State st = iface->state();
2017 stateStrings << u"focusable"_s;
2019 stateStrings << u"focused"_s;
2021 stateStrings << u"selected"_s;
2023 stateStrings << u"invisible"_s;
2025 if (!stateStrings.isEmpty())
2026 d << stateStrings.join(u'|');
2029 d <<
"rect=" << iface->rect();
2039QDebug operator<<(QDebug d,
const QAccessibleEvent &ev)
2041 QDebugStateSaver saver(d);
2042 d.nospace() <<
"QAccessibleEvent(";
2044 d.nospace() <<
"object=" << Qt::hex << ev.object() << Qt::dec;
2045 d.nospace() <<
"child=" << ev.child();
2047 d.nospace() <<
"no object, uniqueId=" << ev.uniqueId();
2049 d <<
" event=" << qAccessibleEventString(ev.type());
2050 if (ev.type() == QAccessible::StateChanged) {
2051 QAccessible::State changed =
static_cast<
const QAccessibleStateChangeEvent*>(&ev)->changedStates();
2052 d <<
"State changed:";
2053 if (changed.disabled) d <<
"disabled";
2054 if (changed.selected) d <<
"selected";
2055 if (changed.focusable) d <<
"focusable";
2056 if (changed.focused) d <<
"focused";
2057 if (changed.pressed) d <<
"pressed";
2058 if (changed.checkable) d <<
"checkable";
2059 if (changed.checked) d <<
"checked";
2060 if (changed.checkStateMixed) d <<
"checkStateMixed";
2061 if (changed.readOnly) d <<
"readOnly";
2062 if (changed.hotTracked) d <<
"hotTracked";
2063 if (changed.defaultButton) d <<
"defaultButton";
2064 if (changed.expanded) d <<
"expanded";
2065 if (changed.collapsed) d <<
"collapsed";
2066 if (changed.busy) d <<
"busy";
2067 if (changed.expandable) d <<
"expandable";
2068 if (changed.marqueed) d <<
"marqueed";
2069 if (changed.animated) d <<
"animated";
2070 if (changed.invisible) d <<
"invisible";
2071 if (changed.offscreen) d <<
"offscreen";
2072 if (changed.sizeable) d <<
"sizeable";
2073 if (changed.movable) d <<
"movable";
2074 if (changed.selfVoicing) d <<
"selfVoicing";
2075 if (changed.selectable) d <<
"selectable";
2076 if (changed.linked) d <<
"linked";
2077 if (changed.traversed) d <<
"traversed";
2078 if (changed.multiSelectable) d <<
"multiSelectable";
2079 if (changed.extSelectable) d <<
"extSelectable";
2080 if (changed.passwordEdit) d <<
"passwordEdit";
2081 if (changed.hasPopup) d <<
"hasPopup";
2082 if (changed.modal) d <<
"modal";
2086 if (changed.active) d <<
"active";
2087 if (changed.invalid) d <<
"invalid";
2088 if (changed.editable) d <<
"editable";
2089 if (changed.multiLine) d <<
"multiLine";
2090 if (changed.selectableText) d <<
"selectableText";
2091 if (changed.supportsAutoCompletion) d <<
"supportsAutoCompletion";
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2119
2120
2121
2122QAccessibleTextInterface::~QAccessibleTextInterface()
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2140
2141
2142
2143
2144
2147
2148
2149
2150
2153
2154
2155
2156
2159
2160
2161
2162
2165
2166
2167
2168
2171
2172
2173
2174
2175
2176
2177
2178
2181
2182
2183
2184
2185
2186
2189
2190
2191
2192
2193static QString textLineBoundary(
int beforeAtAfter,
const QString &text,
int offset,
int *startOffset,
int *endOffset)
2195 Q_ASSERT(beforeAtAfter >= -1 && beforeAtAfter <= 1);
2196 Q_ASSERT(*startOffset == -1 && *endOffset == -1);
2197 int length = text.size();
2198 Q_ASSERT(offset >= 0 && offset <= length);
2201 if (beforeAtAfter == 1) {
2202 offset = text.indexOf(QChar::LineFeed, qMin(offset, length - 1));
2206 }
else if (beforeAtAfter == -1) {
2207 offset = text.lastIndexOf(QChar::LineFeed, qMax(offset - 1, 0));
2213 *startOffset = text.lastIndexOf(QChar::LineFeed, offset - 1);
2216 *endOffset = text.indexOf(QChar::LineFeed, qMin(offset, length - 1)) + 1;
2217 if (*endOffset <= 0 || *endOffset > length)
2218 *endOffset = length;
2220 return text.mid(*startOffset, *endOffset - *startOffset);
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240QString QAccessibleTextInterface::textBeforeOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2241 int *startOffset,
int *endOffset)
const
2243 const QString txt = text(0, characterCount());
2246 offset = txt.size();
2248 *startOffset = *endOffset = -1;
2249 if (txt.isEmpty() || offset <= 0 || offset > txt.size())
2253 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2254 switch (boundaryType) {
2255 case QAccessible::CharBoundary:
2256 type = QTextBoundaryFinder::Grapheme;
2258 case QAccessible::WordBoundary:
2259 type = QTextBoundaryFinder::Word;
2261 case QAccessible::SentenceBoundary:
2262 type = QTextBoundaryFinder::Sentence;
2264 case QAccessible::LineBoundary:
2265 case QAccessible::ParagraphBoundary:
2267 return textLineBoundary(-1, txt, offset, startOffset, endOffset);
2268 case QAccessible::NoBoundary:
2277 QTextBoundaryFinder boundary(type, txt);
2278 boundary.setPosition(offset);
2281 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2283 }
while (boundary.toPreviousBoundary() > 0);
2284 Q_ASSERT(boundary.position() >= 0);
2285 const int endPos = boundary.position();
2287 while (boundary.toPreviousBoundary() > 0) {
2288 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2291 if (boundary.position() < 0)
2294 *endOffset = endPos;
2295 *startOffset = boundary.position();
2297 return txt.mid(*startOffset, *endOffset - *startOffset);
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317QString QAccessibleTextInterface::textAfterOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2318 int *startOffset,
int *endOffset)
const
2320 const QString txt = text(0, characterCount());
2323 offset = txt.size();
2325 *startOffset = *endOffset = -1;
2326 if (txt.isEmpty() || offset < 0 || offset >= txt.size())
2330 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2331 switch (boundaryType) {
2332 case QAccessible::CharBoundary:
2333 type = QTextBoundaryFinder::Grapheme;
2335 case QAccessible::WordBoundary:
2336 type = QTextBoundaryFinder::Word;
2338 case QAccessible::SentenceBoundary:
2339 type = QTextBoundaryFinder::Sentence;
2341 case QAccessible::LineBoundary:
2342 case QAccessible::ParagraphBoundary:
2344 return textLineBoundary(1, txt, offset, startOffset, endOffset);
2345 case QAccessible::NoBoundary:
2354 QTextBoundaryFinder boundary(type, txt);
2355 boundary.setPosition(offset);
2358 int toNext = boundary.toNextBoundary();
2359 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2361 if (toNext < 0 || toNext >= txt.size())
2364 Q_ASSERT(boundary.position() <= txt.size());
2365 *startOffset = boundary.position();
2368 int toNext = boundary.toNextBoundary();
2369 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2371 if (toNext < 0 || toNext >= txt.size())
2374 Q_ASSERT(boundary.position() <= txt.size());
2375 *endOffset = boundary.position();
2377 if ((*startOffset == -1) || (*endOffset == -1) || (*startOffset == *endOffset)) {
2382 return txt.mid(*startOffset, *endOffset - *startOffset);
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402QString QAccessibleTextInterface::textAtOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2403 int *startOffset,
int *endOffset)
const
2405 const QString txt = text(0, characterCount());
2408 offset = txt.size();
2410 *startOffset = *endOffset = -1;
2411 if (txt.isEmpty() || offset < 0 || offset > txt.size())
2414 if (offset == txt.size() && boundaryType == QAccessible::CharBoundary)
2418 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2419 switch (boundaryType) {
2420 case QAccessible::CharBoundary:
2421 type = QTextBoundaryFinder::Grapheme;
2423 case QAccessible::WordBoundary:
2424 type = QTextBoundaryFinder::Word;
2426 case QAccessible::SentenceBoundary:
2427 type = QTextBoundaryFinder::Sentence;
2429 case QAccessible::LineBoundary:
2430 case QAccessible::ParagraphBoundary:
2432 return textLineBoundary(0, txt, offset, startOffset, endOffset);
2433 case QAccessible::NoBoundary:
2435 *endOffset = txt.size();
2443 QTextBoundaryFinder boundary(type, txt);
2444 boundary.setPosition(offset);
2447 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2449 }
while (boundary.toPreviousBoundary() > 0);
2450 Q_ASSERT(boundary.position() >= 0);
2451 const int startPos = boundary.position();
2453 while (boundary.toNextBoundary() < txt.size()) {
2454 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2456 if (boundary.position() == -1)
2460 Q_ASSERT(boundary.position() <= txt.size());
2461 *startOffset = startPos;
2462 *endOffset = boundary.position();
2464 return txt.mid(*startOffset, *endOffset - *startOffset);
2468
2469
2470
2471
2474
2475
2476
2477
2480
2481
2482
2483
2484
2485
2488
2489
2490
2491
2494
2495
2496
2497
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2514
2515
2516
2517QAccessibleEditableTextInterface::~QAccessibleEditableTextInterface()
2522
2523
2524
2525
2528
2529
2530
2531
2534
2535
2536
2537
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2558
2559
2560
2561QAccessibleValueInterface::~QAccessibleValueInterface()
2566
2567
2568
2569
2570
2573
2574
2575
2576
2577
2578
2579
2582
2583
2584
2585
2586
2589
2590
2591
2592
2593
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2622
2623
2624QAccessibleImageInterface::~QAccessibleImageInterface()
2629
2630
2631
2632
2633
2634
2635
2636
2637
2640
2641
2642
2643QAccessibleTableCellInterface::~QAccessibleTableCellInterface()
2648
2649
2650
2651
2654
2655
2656
2657
2660
2661
2662
2663
2666
2667
2668
2669
2672
2673
2674
2675
2678
2679
2680
2681
2684
2685
2686
2687
2690
2691
2692
2693
2697
2698
2699
2700
2701
2702
2703
2704
2705
2708
2709
2710
2711QAccessibleTableInterface::~QAccessibleTableInterface()
2716
2717
2718
2719
2722
2723
2724
2725
2728
2729
2730
2731
2734
2735
2736
2737
2740
2741
2742
2743
2746
2747
2748
2749
2752
2753
2754
2755
2758
2759
2760
2761
2764
2765
2766
2767
2770
2771
2772
2773
2776
2777
2778
2779
2782
2783
2784
2785
2788
2789
2790
2791
2792
2795
2796
2797
2798
2801
2802
2803
2804
2807
2808
2809
2810
2811
2814
2815
2816
2817
2818
2821
2822
2823
2824
2825
2828
2829
2830
2831
2832
2835
2836
2837
2838
2839
2840
2844
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
2885
2886
2887
2888QAccessibleActionInterface::~QAccessibleActionInterface()
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2924
2925
2926
2927
2928
2929
2930
2931
2932
2935
2936
2937
2938
2939
2940
2941
2942
2943
2946
2947
2948
2949
2950
2951
2952
2953
2956struct QAccessibleActionStrings
2958 QAccessibleActionStrings() :
2959 pressAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Press"))),
2960 increaseAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Increase"))),
2961 decreaseAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Decrease"))),
2962 showMenuAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Show Menu"))),
2963 setFocusAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Set Focus"))),
2964 showOnScreenAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Show on Screen"))),
2965 toggleAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Toggle"))),
2966 scrollLeftAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Left"))),
2967 scrollRightAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Right"))),
2968 scrollUpAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Up"))),
2969 scrollDownAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Down"))),
2970 previousPageAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Previous Page"))),
2971 nextPageAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Next Page")))
2974 const QString pressAction;
2975 const QString increaseAction;
2976 const QString decreaseAction;
2977 const QString showMenuAction;
2978 const QString setFocusAction;
2979 const QString showOnScreenAction;
2980 const QString toggleAction;
2981 const QString scrollLeftAction;
2982 const QString scrollRightAction;
2983 const QString scrollUpAction;
2984 const QString scrollDownAction;
2985 const QString previousPageAction;
2986 const QString nextPageAction;
2988 QString localizedDescription(
const QString &actionName)
2990 if (actionName == pressAction)
2991 return QAccessibleActionInterface::tr(
"Triggers the action");
2992 else if (actionName == increaseAction)
2993 return QAccessibleActionInterface::tr(
"Increase the value");
2994 else if (actionName == decreaseAction)
2995 return QAccessibleActionInterface::tr(
"Decrease the value");
2996 else if (actionName == showMenuAction)
2997 return QAccessibleActionInterface::tr(
"Shows the menu");
2998 else if (actionName == setFocusAction)
2999 return QAccessibleActionInterface::tr(
"Sets the focus");
3000 else if (actionName == showOnScreenAction)
3001 return QAccessibleActionInterface::tr(
"Moves the element into the visible area");
3002 else if (actionName == toggleAction)
3003 return QAccessibleActionInterface::tr(
"Toggles the state");
3004 else if (actionName == scrollLeftAction)
3005 return QAccessibleActionInterface::tr(
"Scrolls to the left");
3006 else if (actionName == scrollRightAction)
3007 return QAccessibleActionInterface::tr(
"Scrolls to the right");
3008 else if (actionName == scrollUpAction)
3009 return QAccessibleActionInterface::tr(
"Scrolls up");
3010 else if (actionName == scrollDownAction)
3011 return QAccessibleActionInterface::tr(
"Scrolls down");
3012 else if (actionName == previousPageAction)
3013 return QAccessibleActionInterface::tr(
"Goes back a page");
3014 else if (actionName == nextPageAction)
3015 return QAccessibleActionInterface::tr(
"Goes to the next page");
3022Q_GLOBAL_STATIC(QAccessibleActionStrings, accessibleActionStrings)
3024QString QAccessibleActionInterface::localizedActionName(
const QString &actionName)
const
3026 return QAccessibleActionInterface::tr(qPrintable(actionName));
3029QString QAccessibleActionInterface::localizedActionDescription(
const QString &actionName)
const
3031 return accessibleActionStrings()->localizedDescription(actionName);
3035
3036
3037
3038const QString &QAccessibleActionInterface::pressAction()
3040 return accessibleActionStrings()->pressAction;
3044
3045
3046
3047const QString &QAccessibleActionInterface::increaseAction()
3049 return accessibleActionStrings()->increaseAction;
3053
3054
3055
3056const QString &QAccessibleActionInterface::decreaseAction()
3058 return accessibleActionStrings()->decreaseAction;
3062
3063
3064
3065const QString &QAccessibleActionInterface::showMenuAction()
3067 return accessibleActionStrings()->showMenuAction;
3071
3072
3073
3074const QString &QAccessibleActionInterface::setFocusAction()
3076 return accessibleActionStrings()->setFocusAction;
3080
3081
3082
3083const QString &QAccessibleActionInterface::showOnScreenAction()
3085 return accessibleActionStrings()->showOnScreenAction;
3089
3090
3091
3092const QString &QAccessibleActionInterface::toggleAction()
3094 return accessibleActionStrings()->toggleAction;
3098
3099
3100
3101QString QAccessibleActionInterface::scrollLeftAction()
3103 return accessibleActionStrings()->scrollLeftAction;
3107
3108
3109
3110QString QAccessibleActionInterface::scrollRightAction()
3112 return accessibleActionStrings()->scrollRightAction;
3116
3117
3118
3119QString QAccessibleActionInterface::scrollUpAction()
3121 return accessibleActionStrings()->scrollUpAction;
3125
3126
3127
3128QString QAccessibleActionInterface::scrollDownAction()
3130 return accessibleActionStrings()->scrollDownAction;
3134
3135
3136
3137QString QAccessibleActionInterface::previousPageAction()
3139 return accessibleActionStrings()->previousPageAction;
3143
3144
3145
3146QString QAccessibleActionInterface::nextPageAction()
3148 return accessibleActionStrings()->nextPageAction;
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3168
3169
3170
3171QAccessibleSelectionInterface::~QAccessibleSelectionInterface()
3176
3177
3178
3179
3182
3183
3184
3185
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200QAccessibleInterface* QAccessibleSelectionInterface::selectedItem(
int selectionIndex)
const
3202 QList<QAccessibleInterface*> items = selectedItems();
3203 if (selectionIndex < 0 || selectionIndex > items.length() -1) {
3204 qCWarning(lcAccessibilityCore) <<
"Selection index" << selectionIndex <<
"out of range.";
3208 return items.at(selectionIndex);
3212
3213
3214
3215
3216
3217bool QAccessibleSelectionInterface::isSelected(QAccessibleInterface *childItem)
const
3219 return selectedItems().contains(childItem);
3223
3224
3225
3226
3227
3228
3229
3230
3233
3234
3235
3236
3237
3238
3241
3242
3243
3244
3245
3246
3249
3250
3251
3252
3253
3254
3255
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3283
3284
3285
3286QAccessibleAttributesInterface::~QAccessibleAttributesInterface()
3291
3292
3293
3294
3295
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3310QString qAccessibleLocalizedActionDescription(
const QString &actionName)
3312 return accessibleActionStrings()->localizedDescription(actionName);
3316
3317
3318
3319
3320
3323
3324
3325
3326
3327
3330
3331
3332
3333
3334
3335
3336
3337
3340
3341
3342
3343
3344
3345
3346
3348QAccessibleHyperlinkInterface::~QAccessibleHyperlinkInterface()
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3367
3368
3369
3370QAccessibleViewportInterface::~QAccessibleViewportInterface()
3375
3376
3377
3378
3379
3380
3383
3384
3385
3386
3389
3390
3391
3392
3395
3396
3397
3398
3401
3402
3403
3404
3410#include "moc_qaccessible_base.cpp"
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)