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
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
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
410
411
412
413
414
415
416
417
418
419
420
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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
517#if QT_CONFIG(accessibility)
520
521
522QAccessibleInterface::~QAccessibleInterface()
527
528
529
530
534Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, acLoader,
535 (QAccessibleFactoryInterface_iid,
"/accessible"_L1))
536typedef QHash<QString, QAccessiblePlugin*> QAccessiblePluginsHash;
537Q_GLOBAL_STATIC(QAccessiblePluginsHash, qAccessiblePlugins)
540Q_GLOBAL_STATIC(QList<QAccessible::InterfaceFactory>, qAccessibleFactories)
541Q_GLOBAL_STATIC(QList<QAccessible::ActivationObserver *>, qAccessibleActivationObservers)
543QAccessible::UpdateHandler QAccessible::updateHandler =
nullptr;
544QAccessible::RootObjectHandler QAccessible::rootObjectHandler =
nullptr;
546static bool cleanupAdded =
false;
548static QPlatformAccessibility *platformAccessibility()
550 QPlatformIntegration *pfIntegration = QGuiApplicationPrivate::platformIntegration();
551 return pfIntegration ? pfIntegration->accessibility() :
nullptr;
555
556
557
558
559
560
564
565
566void QAccessible::cleanup()
568 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
569 pfAccessibility->cleanup();
572static void qAccessibleCleanup()
574 qAccessibleActivationObservers()->clear();
575 qAccessibleFactories()->clear();
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
599
600
601
602
603
604
605
606
607
610
611
612
613
614
615
616
617
618
622
623
624
625void QAccessible::installFactory(InterfaceFactory factory)
631 qAddPostRoutine(qAccessibleCleanup);
634 if (qAccessibleFactories()->contains(factory))
636 qAccessibleFactories()->append(factory);
640
641
642void QAccessible::removeFactory(InterfaceFactory factory)
644 qAccessibleFactories()->removeAll(factory);
648
649
650
651
652
653
654QAccessible::UpdateHandler QAccessible::installUpdateHandler(UpdateHandler handler)
656 UpdateHandler old = updateHandler;
657 updateHandler = handler;
662
663
664
665
666
667QAccessible::RootObjectHandler QAccessible::installRootObjectHandler(RootObjectHandler handler)
669 RootObjectHandler old = rootObjectHandler;
670 rootObjectHandler = handler;
675
676
677
678
679
680
682QAccessible::ActivationObserver::~ActivationObserver()
687
688
689
690
691void QAccessible::installActivationObserver(QAccessible::ActivationObserver *observer)
697 qAddPostRoutine(qAccessibleCleanup);
700 if (qAccessibleActivationObservers()->contains(observer))
702 qAccessibleActivationObservers()->append(observer);
706 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
707 pfAccessibility->clearActiveNotificationState();
711
712
713
714
715
716void QAccessible::removeActivationObserver(ActivationObserver *observer)
718 qAccessibleActivationObservers()->removeAll(observer);
722
723
724
725
726void qAccessibleNotifyActivationObservers(
bool active)
728 for (
int i = 0; i < qAccessibleActivationObservers()->size(); ++i)
729 qAccessibleActivationObservers()->at(i)->accessibilityActiveChanged(active);
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750QAccessibleInterface *QAccessible::queryAccessibleInterface(QObject *object)
755 if (Id id = QAccessibleCache::instance()->idForObject(object))
756 return QAccessibleCache::instance()->interfaceForId(id);
760 const QMetaObject *mo = object->metaObject();
761 const auto *objectPriv = QObjectPrivate::get(object);
763
764
765
766
767
768
769
770
771 const bool qmlRelated = !objectPriv->isDeletingChildren &&
772 objectPriv->declarativeData;
773 while (qmlRelated && mo) {
774 auto mop = QMetaObjectPrivate::get(mo);
775 if (!mop || !(mop->flags & DynamicMetaObject))
778 mo = mo->superClass();
781 const QString cn = QLatin1StringView(mo->className());
784 for (
int i = qAccessibleFactories()->size(); i > 0; --i) {
785 InterfaceFactory factory = qAccessibleFactories()->at(i - 1);
786 if (QAccessibleInterface *iface = factory(cn, object)) {
787 QAccessibleCache::instance()->insert(object, iface);
788 Q_ASSERT(QAccessibleCache::instance()->containsObject(object));
794 if (!qAccessiblePlugins()->contains(cn)) {
795 QAccessiblePlugin *factory =
nullptr;
796 const int index = acLoader()->indexOf(cn);
798 factory = qobject_cast<QAccessiblePlugin *>(acLoader()->instance(index));
799 qAccessiblePlugins()->insert(cn, factory);
803 Q_ASSERT(qAccessiblePlugins()->contains(cn));
804 QAccessiblePlugin *factory = qAccessiblePlugins()->value(cn);
806 QAccessibleInterface *result = factory->create(cn, object);
808 QAccessibleCache::instance()->insert(object, result);
809 Q_ASSERT(QAccessibleCache::instance()->containsObject(object));
813 mo = mo->superClass();
816 if (object == qApp) {
817 QAccessibleInterface *appInterface =
new QAccessibleApplication;
818 QAccessibleCache::instance()->insert(object, appInterface);
819 Q_ASSERT(QAccessibleCache::instance()->containsObject(qApp));
827
828
829
830
831
832
833
834
835
836
837
838
839
840QAccessible::Id QAccessible::registerAccessibleInterface(QAccessibleInterface *iface)
843 return QAccessibleCache::instance()->insert(iface->object(), iface);
847
848
849
850
851void QAccessible::deleteAccessibleInterface(Id id)
853 QAccessibleCache::instance()->deleteInterface(id);
857
858
859QAccessible::Id QAccessible::uniqueId(QAccessibleInterface *iface)
861 Id id = QAccessibleCache::instance()->idForInterface(iface);
863 id = registerAccessibleInterface(iface);
868
869
870
871
872QAccessibleInterface *QAccessible::accessibleInterface(Id id)
874 return QAccessibleCache::instance()->interfaceForId(id);
879
880
881
882
883
884
885
886
887
888
889bool QAccessible::isActive()
891 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
892 return pfAccessibility->isActive();
897
898
899void QAccessible::setActive(
bool active)
901 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
902 pfAccessibility->setActive(active);
906
907
908
909
910
911
912
913
914
915
916
917
918
919void QAccessible::setRootObject(QObject *object)
921 if (rootObjectHandler) {
922 rootObjectHandler(object);
926 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
927 pfAccessibility->setRootObject(object);
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949void QAccessible::updateAccessibility(QAccessibleEvent *event)
958 QAccessibleInterface *iface = event->accessibleInterface();
960 if (event->type() == QAccessible::TableModelChanged) {
961 if (iface->tableInterface())
962 iface->tableInterface()->modelChange(
static_cast<QAccessibleTableModelChangeEvent*>(event));
967 updateHandler(event);
971 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
972 pfAccessibility->notifyAccessibilityUpdate(event);
975static std::pair<
int,
int> qAccessibleTextBoundaryHelperHelper(QTextCursor &cursor,
976 QTextCursor::MoveOperation start,
977 QTextCursor::MoveOperation end)
979 std::pair<
int,
int> result;
980 cursor.movePosition(start, QTextCursor::MoveAnchor);
981 result.first = cursor.position();
982 cursor.movePosition(end, QTextCursor::KeepAnchor);
983 result.second = cursor.position();
988
989
990
991
992
993
994std::pair<
int,
int > QAccessible::qAccessibleTextBoundaryHelper(
const QTextCursor &offsetCursor, TextBoundaryType boundaryType)
996 Q_ASSERT(!offsetCursor.isNull());
998 QTextCursor cursor = offsetCursor;
999 switch (boundaryType) {
1001 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::NoMove,
1002 QTextCursor::NextCharacter);
1004 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::StartOfWord,
1005 QTextCursor::EndOfWord);
1006 case SentenceBoundary: {
1010 std::pair<
int,
int> result = qAccessibleTextBoundaryHelperHelper(
1011 cursor, QTextCursor::StartOfBlock, QTextCursor::EndOfBlock);
1012 QString blockText = cursor.selectedText();
1013 const int offsetWithinBlockText = offsetCursor.position() - result.first;
1014 QTextBoundaryFinder sentenceFinder(QTextBoundaryFinder::Sentence, blockText);
1015 sentenceFinder.setPosition(offsetWithinBlockText);
1016 int prevBoundary = offsetWithinBlockText;
1017 int nextBoundary = offsetWithinBlockText;
1018 if (!(sentenceFinder.boundaryReasons() & QTextBoundaryFinder::StartOfItem))
1019 prevBoundary = sentenceFinder.toPreviousBoundary();
1020 nextBoundary = sentenceFinder.toNextBoundary();
1021 if (nextBoundary != -1)
1022 result.second = result.first + nextBoundary;
1023 if (prevBoundary != -1)
1024 result.first += prevBoundary;
1028 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::StartOfLine,
1029 QTextCursor::EndOfLine);
1030 case ParagraphBoundary:
1031 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::StartOfBlock,
1032 QTextCursor::EndOfBlock);
1034 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::Start, QTextCursor::End);
1037 Q_UNREACHABLE_RETURN({});
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
1133
1134
1135
1136
1137
1138
1139
1140
1143
1144
1145
1146
1147
1148
1149
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1164
1165
1166
1167
1168
1169
1170
1171
1172
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184QList<std::pair<QAccessibleInterface*, QAccessible::Relation>>
1185QAccessibleInterface::relations(QAccessible::Relation match)
const
1192
1193
1194
1195
1196QAccessibleInterface *QAccessibleInterface::focusChild()
const
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1221
1222
1223
1224
1225
1226
1227
1228
1231
1232
1233
1234
1235
1236
1237
1238
1239
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
1291
1292
1293
1294
1295
1296
1297
1298
1299
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1315
1316
1317
1318
1319
1320
1321
1322
1323
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1338
1339
1340
1341
1342QColor QAccessibleInterface::foregroundColor()
const
1348
1349
1350
1351
1352QColor QAccessibleInterface::backgroundColor()
const
1358
1359
1362
1363
1364
1367
1368
1371
1372
1375
1376
1379
1380
1383
1384
1385
1388
1389
1390
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1413
1414
1415
1416
1419
1420
1421
1422
1423
1424
1427
1428
1429QAccessibleEvent::~QAccessibleEvent()
1434
1435
1438
1439
1442
1443
1446
1447
1450
1451
1452
1453
1454
1455
1456QAccessible::Id QAccessibleEvent::uniqueId()
const
1460 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
1463 if (m_child != -1) {
1464 iface = iface->child(m_child);
1465 if (Q_UNLIKELY(!iface)) {
1466 qCWarning(lcAccessibilityCore) <<
"Invalid child in QAccessibleEvent:" << m_object <<
"child:" << m_child;
1470 return QAccessible::uniqueId(iface);
1473void QAccessibleEvent::setChild(
int chld)
1475 if (m_type == QAccessible::ObjectDestroyed)
1476 qCWarning(lcAccessibilityCore) <<
"Calling QAccessibleEvent::setChild on ObjectDestroyed event " <<
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1494
1495
1496
1497
1499
1500
1501
1502
1505
1506
1507
1509
1510
1511
1512
1515
1516
1517QAccessibleValueChangeEvent::~QAccessibleValueChangeEvent()
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1534
1535
1536
1537
1539
1540
1541
1542
1543
1544
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1558
1559
1560QAccessibleStateChangeEvent::~QAccessibleStateChangeEvent()
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1578
1579
1580
1581
1582
1583
1584
1585
1587
1588
1589
1591
1592
1593
1595
1596
1597
1599
1600
1601
1603
1604
1605
1607
1608
1609
1611
1612
1613
1615
1616
1617
1619
1620
1621
1623
1624
1625
1627
1628
1629
1631
1632
1633
1634
1635
1637
1638
1639QAccessibleTableModelChangeEvent::~QAccessibleTableModelChangeEvent()
1643
1644
1645
1646
1647
1648
1649
1650
1652
1653
1654
1655
1657
1658
1659
1661
1662
1663
1665
1666
1667QAccessibleTextCursorEvent::~QAccessibleTextCursorEvent()
1673
1674
1675
1676
1677
1680
1681
1682
1683
1684
1685
1686
1687
1689
1690
1691
1692
1693
1694
1695
1697
1698
1699
1701
1702
1703
1705
1706
1707QAccessibleTextInsertEvent::~QAccessibleTextInsertEvent()
1713
1714
1715
1716
1717
1718
1719
1720
1722
1723
1724
1725
1726
1727
1728
1730
1731
1732
1733
1734
1735
1736
1739
1740
1741
1743
1744
1745
1747
1748
1749QAccessibleTextRemoveEvent::~QAccessibleTextRemoveEvent()
1754
1755
1756
1757
1758
1761
1762
1763
1764
1765
1768
1769
1770
1771
1772
1773
1774
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1791
1792
1793
1794
1796
1797
1798
1800
1801
1802
1804
1805
1806
1808
1809
1810QAccessibleTextUpdateEvent::~QAccessibleTextUpdateEvent()
1816
1817
1818
1819
1820
1821
1822
1823
1825
1826
1827
1828
1830
1831
1832
1834
1835
1836
1838
1839
1840
1842
1843
1844QAccessibleTextSelectionEvent::~QAccessibleTextSelectionEvent()
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1861
1862
1863
1864
1865
1866
1867
1870
1871
1872
1873
1874
1875
1876
1879
1880
1881
1884
1885
1886
1889
1890
1891
1895
1896
1897QAccessibleAnnouncementEvent::~QAccessibleAnnouncementEvent()
1902
1903
1904QAccessibleInterface *QAccessibleEvent::accessibleInterface()
const
1906 if (m_object ==
nullptr)
1907 return QAccessible::accessibleInterface(m_uniqueId);
1909 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
1910 if (!iface || !iface->isValid())
1914 QAccessibleInterface *child = iface->child(m_child);
1918 qCWarning(lcAccessibilityCore) <<
"Cannot create accessible child interface for object: " << m_object <<
" index: " << m_child <<
"type: " << m_type;
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937QWindow *QAccessibleInterface::window()
const
1943
1944
1945
1946
1947
1948
1949
1950void QAccessibleInterface::virtual_hook(
int ,
void * )
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1971const char *qAccessibleRoleString(QAccessible::Role role)
1973 if (role >= QAccessible::UserRole)
1974 role = QAccessible::UserRole;
1975 static int roleEnum = QAccessible::staticMetaObject.indexOfEnumerator(
"Role");
1976 return QAccessible::staticMetaObject.enumerator(roleEnum).valueToKey(role);
1980const char *qAccessibleEventString(QAccessible::Event event)
1982 static int eventEnum = QAccessible::staticMetaObject.indexOfEnumerator(
"Event");
1983 return QAccessible::staticMetaObject.enumerator(eventEnum).valueToKey(event);
1986#ifndef QT_NO_DEBUG_STREAM
1988Q_GUI_EXPORT QDebug operator<<(QDebug d,
const QAccessibleInterface *iface)
1990 QDebugStateSaver saver(d);
1992 return d <<
"QAccessibleInterface(0x0)";
1995 d <<
"QAccessibleInterface(" << Qt::hex << (
const void *) iface << Qt::dec;
1996 if (iface->isValid()) {
1997 d <<
" name=" << iface->text(QAccessible::Name) <<
' ';
1998 d <<
"role=" << qAccessibleRoleString(iface->role()) <<
' ';
1999 if (iface->childCount())
2000 d <<
"childc=" << iface->childCount() <<
' ';
2001 if (iface->object()) {
2002 d <<
"obj=" << iface->object();
2004 QStringList stateStrings;
2005 QAccessible::State st = iface->state();
2007 stateStrings << u"focusable"_s;
2009 stateStrings << u"focused"_s;
2011 stateStrings << u"selected"_s;
2013 stateStrings << u"invisible"_s;
2015 if (!stateStrings.isEmpty())
2016 d << stateStrings.join(u'|');
2019 d <<
"rect=" << iface->rect();
2029QDebug operator<<(QDebug d,
const QAccessibleEvent &ev)
2031 QDebugStateSaver saver(d);
2032 d.nospace() <<
"QAccessibleEvent(";
2034 d.nospace() <<
"object=" << Qt::hex << ev.object() << Qt::dec;
2035 d.nospace() <<
"child=" << ev.child();
2037 d.nospace() <<
"no object, uniqueId=" << ev.uniqueId();
2039 d <<
" event=" << qAccessibleEventString(ev.type());
2040 if (ev.type() == QAccessible::StateChanged) {
2041 QAccessible::State changed =
static_cast<
const QAccessibleStateChangeEvent*>(&ev)->changedStates();
2042 d <<
"State changed:";
2043 if (changed.disabled) d <<
"disabled";
2044 if (changed.selected) d <<
"selected";
2045 if (changed.focusable) d <<
"focusable";
2046 if (changed.focused) d <<
"focused";
2047 if (changed.pressed) d <<
"pressed";
2048 if (changed.checkable) d <<
"checkable";
2049 if (changed.checked) d <<
"checked";
2050 if (changed.checkStateMixed) d <<
"checkStateMixed";
2051 if (changed.readOnly) d <<
"readOnly";
2052 if (changed.hotTracked) d <<
"hotTracked";
2053 if (changed.defaultButton) d <<
"defaultButton";
2054 if (changed.expanded) d <<
"expanded";
2055 if (changed.collapsed) d <<
"collapsed";
2056 if (changed.busy) d <<
"busy";
2057 if (changed.expandable) d <<
"expandable";
2058 if (changed.marqueed) d <<
"marqueed";
2059 if (changed.animated) d <<
"animated";
2060 if (changed.invisible) d <<
"invisible";
2061 if (changed.offscreen) d <<
"offscreen";
2062 if (changed.sizeable) d <<
"sizeable";
2063 if (changed.movable) d <<
"movable";
2064 if (changed.selfVoicing) d <<
"selfVoicing";
2065 if (changed.selectable) d <<
"selectable";
2066 if (changed.linked) d <<
"linked";
2067 if (changed.traversed) d <<
"traversed";
2068 if (changed.multiSelectable) d <<
"multiSelectable";
2069 if (changed.extSelectable) d <<
"extSelectable";
2070 if (changed.passwordEdit) d <<
"passwordEdit";
2071 if (changed.hasPopup) d <<
"hasPopup";
2072 if (changed.modal) d <<
"modal";
2076 if (changed.active) d <<
"active";
2077 if (changed.invalid) d <<
"invalid";
2078 if (changed.editable) d <<
"editable";
2079 if (changed.multiLine) d <<
"multiLine";
2080 if (changed.selectableText) d <<
"selectableText";
2081 if (changed.supportsAutoCompletion) d <<
"supportsAutoCompletion";
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2109
2110
2111
2112QAccessibleTextInterface::~QAccessibleTextInterface()
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2130
2131
2132
2133
2134
2137
2138
2139
2140
2143
2144
2145
2146
2149
2150
2151
2152
2155
2156
2157
2158
2161
2162
2163
2164
2165
2166
2167
2168
2171
2172
2173
2174
2175
2176
2179
2180
2181
2182
2183static QString textLineBoundary(
int beforeAtAfter,
const QString &text,
int offset,
int *startOffset,
int *endOffset)
2185 Q_ASSERT(beforeAtAfter >= -1 && beforeAtAfter <= 1);
2186 Q_ASSERT(*startOffset == -1 && *endOffset == -1);
2187 int length = text.size();
2188 Q_ASSERT(offset >= 0 && offset <= length);
2191 if (beforeAtAfter == 1) {
2192 offset = text.indexOf(QChar::LineFeed, qMin(offset, length - 1));
2196 }
else if (beforeAtAfter == -1) {
2197 offset = text.lastIndexOf(QChar::LineFeed, qMax(offset - 1, 0));
2203 *startOffset = text.lastIndexOf(QChar::LineFeed, offset - 1);
2206 *endOffset = text.indexOf(QChar::LineFeed, qMin(offset, length - 1)) + 1;
2207 if (*endOffset <= 0 || *endOffset > length)
2208 *endOffset = length;
2210 return text.mid(*startOffset, *endOffset - *startOffset);
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230QString QAccessibleTextInterface::textBeforeOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2231 int *startOffset,
int *endOffset)
const
2233 const QString txt = text(0, characterCount());
2236 offset = txt.size();
2238 *startOffset = *endOffset = -1;
2239 if (txt.isEmpty() || offset <= 0 || offset > txt.size())
2243 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2244 switch (boundaryType) {
2245 case QAccessible::CharBoundary:
2246 type = QTextBoundaryFinder::Grapheme;
2248 case QAccessible::WordBoundary:
2249 type = QTextBoundaryFinder::Word;
2251 case QAccessible::SentenceBoundary:
2252 type = QTextBoundaryFinder::Sentence;
2254 case QAccessible::LineBoundary:
2255 case QAccessible::ParagraphBoundary:
2257 return textLineBoundary(-1, txt, offset, startOffset, endOffset);
2258 case QAccessible::NoBoundary:
2267 QTextBoundaryFinder boundary(type, txt);
2268 boundary.setPosition(offset);
2271 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2273 }
while (boundary.toPreviousBoundary() > 0);
2274 Q_ASSERT(boundary.position() >= 0);
2275 const int endPos = boundary.position();
2277 while (boundary.toPreviousBoundary() > 0) {
2278 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2281 if (boundary.position() < 0)
2284 *endOffset = endPos;
2285 *startOffset = boundary.position();
2287 return txt.mid(*startOffset, *endOffset - *startOffset);
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307QString QAccessibleTextInterface::textAfterOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2308 int *startOffset,
int *endOffset)
const
2310 const QString txt = text(0, characterCount());
2313 offset = txt.size();
2315 *startOffset = *endOffset = -1;
2316 if (txt.isEmpty() || offset < 0 || offset >= txt.size())
2320 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2321 switch (boundaryType) {
2322 case QAccessible::CharBoundary:
2323 type = QTextBoundaryFinder::Grapheme;
2325 case QAccessible::WordBoundary:
2326 type = QTextBoundaryFinder::Word;
2328 case QAccessible::SentenceBoundary:
2329 type = QTextBoundaryFinder::Sentence;
2331 case QAccessible::LineBoundary:
2332 case QAccessible::ParagraphBoundary:
2334 return textLineBoundary(1, txt, offset, startOffset, endOffset);
2335 case QAccessible::NoBoundary:
2344 QTextBoundaryFinder boundary(type, txt);
2345 boundary.setPosition(offset);
2348 int toNext = boundary.toNextBoundary();
2349 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2351 if (toNext < 0 || toNext >= txt.size())
2354 Q_ASSERT(boundary.position() <= txt.size());
2355 *startOffset = boundary.position();
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 *endOffset = boundary.position();
2367 if ((*startOffset == -1) || (*endOffset == -1) || (*startOffset == *endOffset)) {
2372 return txt.mid(*startOffset, *endOffset - *startOffset);
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392QString QAccessibleTextInterface::textAtOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2393 int *startOffset,
int *endOffset)
const
2395 const QString txt = text(0, characterCount());
2398 offset = txt.size();
2400 *startOffset = *endOffset = -1;
2401 if (txt.isEmpty() || offset < 0 || offset > txt.size())
2404 if (offset == txt.size() && boundaryType == QAccessible::CharBoundary)
2408 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2409 switch (boundaryType) {
2410 case QAccessible::CharBoundary:
2411 type = QTextBoundaryFinder::Grapheme;
2413 case QAccessible::WordBoundary:
2414 type = QTextBoundaryFinder::Word;
2416 case QAccessible::SentenceBoundary:
2417 type = QTextBoundaryFinder::Sentence;
2419 case QAccessible::LineBoundary:
2420 case QAccessible::ParagraphBoundary:
2422 return textLineBoundary(0, txt, offset, startOffset, endOffset);
2423 case QAccessible::NoBoundary:
2425 *endOffset = txt.size();
2433 QTextBoundaryFinder boundary(type, txt);
2434 boundary.setPosition(offset);
2437 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2439 }
while (boundary.toPreviousBoundary() > 0);
2440 Q_ASSERT(boundary.position() >= 0);
2441 const int startPos = boundary.position();
2443 while (boundary.toNextBoundary() < txt.size()) {
2444 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2446 if (boundary.position() == -1)
2450 Q_ASSERT(boundary.position() <= txt.size());
2451 *startOffset = startPos;
2452 *endOffset = boundary.position();
2454 return txt.mid(*startOffset, *endOffset - *startOffset);
2458
2459
2460
2461
2464
2465
2466
2467
2470
2471
2472
2473
2474
2475
2478
2479
2480
2481
2484
2485
2486
2487
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2504
2505
2506
2507QAccessibleEditableTextInterface::~QAccessibleEditableTextInterface()
2512
2513
2514
2515
2518
2519
2520
2521
2524
2525
2526
2527
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2548
2549
2550
2551QAccessibleValueInterface::~QAccessibleValueInterface()
2556
2557
2558
2559
2560
2563
2564
2565
2566
2567
2568
2569
2572
2573
2574
2575
2576
2579
2580
2581
2582
2583
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2612
2613
2614QAccessibleImageInterface::~QAccessibleImageInterface()
2619
2620
2621
2622
2623
2624
2625
2626
2627
2630
2631
2632
2633QAccessibleTableCellInterface::~QAccessibleTableCellInterface()
2638
2639
2640
2641
2644
2645
2646
2647
2650
2651
2652
2653
2656
2657
2658
2659
2662
2663
2664
2665
2668
2669
2670
2671
2674
2675
2676
2677
2680
2681
2682
2683
2687
2688
2689
2690
2691
2692
2693
2694
2695
2698
2699
2700
2701QAccessibleTableInterface::~QAccessibleTableInterface()
2706
2707
2708
2709
2712
2713
2714
2715
2718
2719
2720
2721
2724
2725
2726
2727
2730
2731
2732
2733
2736
2737
2738
2739
2742
2743
2744
2745
2748
2749
2750
2751
2754
2755
2756
2757
2760
2761
2762
2763
2766
2767
2768
2769
2772
2773
2774
2775
2778
2779
2780
2781
2782
2785
2786
2787
2788
2791
2792
2793
2794
2797
2798
2799
2800
2801
2804
2805
2806
2807
2808
2811
2812
2813
2814
2815
2818
2819
2820
2821
2822
2825
2826
2827
2828
2829
2830
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
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
2875
2876
2877
2878QAccessibleActionInterface::~QAccessibleActionInterface()
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
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
2946struct QAccessibleActionStrings
2948 QAccessibleActionStrings() :
2949 pressAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Press"))),
2950 increaseAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Increase"))),
2951 decreaseAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Decrease"))),
2952 showMenuAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"ShowMenu"))),
2953 setFocusAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"SetFocus"))),
2954 showOnScreenAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Show on Screen"))),
2955 toggleAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Toggle"))),
2956 scrollLeftAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Left"))),
2957 scrollRightAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Right"))),
2958 scrollUpAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Up"))),
2959 scrollDownAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Down"))),
2960 previousPageAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Previous Page"))),
2961 nextPageAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Next Page")))
2964 const QString pressAction;
2965 const QString increaseAction;
2966 const QString decreaseAction;
2967 const QString showMenuAction;
2968 const QString setFocusAction;
2969 const QString showOnScreenAction;
2970 const QString toggleAction;
2971 const QString scrollLeftAction;
2972 const QString scrollRightAction;
2973 const QString scrollUpAction;
2974 const QString scrollDownAction;
2975 const QString previousPageAction;
2976 const QString nextPageAction;
2978 QString localizedDescription(
const QString &actionName)
2980 if (actionName == pressAction)
2981 return QAccessibleActionInterface::tr(
"Triggers the action");
2982 else if (actionName == increaseAction)
2983 return QAccessibleActionInterface::tr(
"Increase the value");
2984 else if (actionName == decreaseAction)
2985 return QAccessibleActionInterface::tr(
"Decrease the value");
2986 else if (actionName == showMenuAction)
2987 return QAccessibleActionInterface::tr(
"Shows the menu");
2988 else if (actionName == setFocusAction)
2989 return QAccessibleActionInterface::tr(
"Sets the focus");
2990 else if (actionName == showOnScreenAction)
2991 return QAccessibleActionInterface::tr(
"Moves the accessible into viewport");
2992 else if (actionName == toggleAction)
2993 return QAccessibleActionInterface::tr(
"Toggles the state");
2994 else if (actionName == scrollLeftAction)
2995 return QAccessibleActionInterface::tr(
"Scrolls to the left");
2996 else if (actionName == scrollRightAction)
2997 return QAccessibleActionInterface::tr(
"Scrolls to the right");
2998 else if (actionName == scrollUpAction)
2999 return QAccessibleActionInterface::tr(
"Scrolls up");
3000 else if (actionName == scrollDownAction)
3001 return QAccessibleActionInterface::tr(
"Scrolls down");
3002 else if (actionName == previousPageAction)
3003 return QAccessibleActionInterface::tr(
"Goes back a page");
3004 else if (actionName == nextPageAction)
3005 return QAccessibleActionInterface::tr(
"Goes to the next page");
3012Q_GLOBAL_STATIC(QAccessibleActionStrings, accessibleActionStrings)
3014QString QAccessibleActionInterface::localizedActionName(
const QString &actionName)
const
3016 return QAccessibleActionInterface::tr(qPrintable(actionName));
3019QString QAccessibleActionInterface::localizedActionDescription(
const QString &actionName)
const
3021 return accessibleActionStrings()->localizedDescription(actionName);
3025
3026
3027
3028const QString &QAccessibleActionInterface::pressAction()
3030 return accessibleActionStrings()->pressAction;
3034
3035
3036
3037const QString &QAccessibleActionInterface::increaseAction()
3039 return accessibleActionStrings()->increaseAction;
3043
3044
3045
3046const QString &QAccessibleActionInterface::decreaseAction()
3048 return accessibleActionStrings()->decreaseAction;
3052
3053
3054
3055const QString &QAccessibleActionInterface::showMenuAction()
3057 return accessibleActionStrings()->showMenuAction;
3061
3062
3063
3064const QString &QAccessibleActionInterface::setFocusAction()
3066 return accessibleActionStrings()->setFocusAction;
3070
3071
3072
3073const QString &QAccessibleActionInterface::showOnScreenAction()
3075 return accessibleActionStrings()->showOnScreenAction;
3079
3080
3081
3082const QString &QAccessibleActionInterface::toggleAction()
3084 return accessibleActionStrings()->toggleAction;
3088
3089
3090
3091QString QAccessibleActionInterface::scrollLeftAction()
3093 return accessibleActionStrings()->scrollLeftAction;
3097
3098
3099
3100QString QAccessibleActionInterface::scrollRightAction()
3102 return accessibleActionStrings()->scrollRightAction;
3106
3107
3108
3109QString QAccessibleActionInterface::scrollUpAction()
3111 return accessibleActionStrings()->scrollUpAction;
3115
3116
3117
3118QString QAccessibleActionInterface::scrollDownAction()
3120 return accessibleActionStrings()->scrollDownAction;
3124
3125
3126
3127QString QAccessibleActionInterface::previousPageAction()
3129 return accessibleActionStrings()->previousPageAction;
3133
3134
3135
3136QString QAccessibleActionInterface::nextPageAction()
3138 return accessibleActionStrings()->nextPageAction;
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3158
3159
3160
3161QAccessibleSelectionInterface::~QAccessibleSelectionInterface()
3166
3167
3168
3169
3172
3173
3174
3175
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190QAccessibleInterface* QAccessibleSelectionInterface::selectedItem(
int selectionIndex)
const
3192 QList<QAccessibleInterface*> items = selectedItems();
3193 if (selectionIndex < 0 || selectionIndex > items.length() -1) {
3194 qCWarning(lcAccessibilityCore) <<
"Selection index" << selectionIndex <<
"out of range.";
3198 return items.at(selectionIndex);
3202
3203
3204
3205
3206
3207bool QAccessibleSelectionInterface::isSelected(QAccessibleInterface *childItem)
const
3209 return selectedItems().contains(childItem);
3213
3214
3215
3216
3217
3218
3219
3220
3223
3224
3225
3226
3227
3228
3231
3232
3233
3234
3235
3236
3239
3240
3241
3242
3243
3244
3245
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3273
3274
3275
3276QAccessibleAttributesInterface::~QAccessibleAttributesInterface()
3281
3282
3283
3284
3285
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3300QString qAccessibleLocalizedActionDescription(
const QString &actionName)
3302 return accessibleActionStrings()->localizedDescription(actionName);
3306
3307
3308
3309
3310
3313
3314
3315
3316
3317
3320
3321
3322
3323
3324
3325
3326
3327
3330
3331
3332
3333
3334
3335
3336
3338QAccessibleHyperlinkInterface::~QAccessibleHyperlinkInterface()
3347#include "moc_qaccessible_base.cpp"
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)