10#include <QtCore/qtextboundaryfinder.h>
11#include <QtGui/qclipboard.h>
12#include <QtGui/qguiapplication.h>
13#include <QtGui/qtextcursor.h>
14#include <private/qguiapplication_p.h>
15#include <qpa/qplatformaccessibility.h>
16#include <qpa/qplatformintegration.h>
18#include <QtCore/qdebug.h>
19#include <QtCore/qloggingcategory.h>
20#include <QtCore/qmetaobject.h>
21#include <QtCore/private/qmetaobject_p.h>
22#include <QtCore/qhash.h>
23#include <private/qfactoryloader_p.h>
27using namespace Qt::StringLiterals;
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
161
162
163
164
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
407
408
409
410
411
412
413
414
415
416
417
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
504#if QT_CONFIG(accessibility)
507
508
509QAccessibleInterface::~QAccessibleInterface()
514
515
516
517
521Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, acLoader,
522 (QAccessibleFactoryInterface_iid,
"/accessible"_L1))
523typedef QHash<QString, QAccessiblePlugin*> QAccessiblePluginsHash;
524Q_GLOBAL_STATIC(QAccessiblePluginsHash, qAccessiblePlugins)
527Q_GLOBAL_STATIC(QList<QAccessible::InterfaceFactory>, qAccessibleFactories)
528Q_GLOBAL_STATIC(QList<QAccessible::ActivationObserver *>, qAccessibleActivationObservers)
530QAccessible::UpdateHandler QAccessible::updateHandler =
nullptr;
531QAccessible::RootObjectHandler QAccessible::rootObjectHandler =
nullptr;
533static bool cleanupAdded =
false;
535static QPlatformAccessibility *platformAccessibility()
537 QPlatformIntegration *pfIntegration = QGuiApplicationPrivate::platformIntegration();
538 return pfIntegration ? pfIntegration->accessibility() :
nullptr;
542
543
544
545
546
547
551
552
553void QAccessible::cleanup()
555 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
556 pfAccessibility->cleanup();
559static void qAccessibleCleanup()
561 qAccessibleActivationObservers()->clear();
562 qAccessibleFactories()->clear();
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
586
587
588
589
590
591
592
593
594
597
598
599
600
601
602
603
604
605
609
610
611
612void QAccessible::installFactory(InterfaceFactory factory)
618 qAddPostRoutine(qAccessibleCleanup);
621 if (qAccessibleFactories()->contains(factory))
623 qAccessibleFactories()->append(factory);
627
628
629void QAccessible::removeFactory(InterfaceFactory factory)
631 qAccessibleFactories()->removeAll(factory);
635
636
637
638
639
640
641QAccessible::UpdateHandler QAccessible::installUpdateHandler(UpdateHandler handler)
643 UpdateHandler old = updateHandler;
644 updateHandler = handler;
649
650
651
652
653
654QAccessible::RootObjectHandler QAccessible::installRootObjectHandler(RootObjectHandler handler)
656 RootObjectHandler old = rootObjectHandler;
657 rootObjectHandler = handler;
662
663
664
665
666
667
669QAccessible::ActivationObserver::~ActivationObserver()
674
675
676
677
678void QAccessible::installActivationObserver(QAccessible::ActivationObserver *observer)
684 qAddPostRoutine(qAccessibleCleanup);
687 if (qAccessibleActivationObservers()->contains(observer))
689 qAccessibleActivationObservers()->append(observer);
693
694
695
696
697
698void QAccessible::removeActivationObserver(ActivationObserver *observer)
700 qAccessibleActivationObservers()->removeAll(observer);
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721QAccessibleInterface *QAccessible::queryAccessibleInterface(QObject *object)
726 if (Id id = QAccessibleCache::instance()->idForObject(object))
727 return QAccessibleCache::instance()->interfaceForId(id);
731 const QMetaObject *mo = object->metaObject();
732 const auto *objectPriv = QObjectPrivate::get(object);
734
735
736
737
738
739
740
741
742 const bool qmlRelated = !objectPriv->isDeletingChildren &&
743 objectPriv->declarativeData;
744 while (qmlRelated && mo) {
745 auto mop = QMetaObjectPrivate::get(mo);
746 if (!mop || !(mop->flags & DynamicMetaObject))
749 mo = mo->superClass();
752 const QString cn = QLatin1StringView(mo->className());
755 for (
int i = qAccessibleFactories()->size(); i > 0; --i) {
756 InterfaceFactory factory = qAccessibleFactories()->at(i - 1);
757 if (QAccessibleInterface *iface = factory(cn, object)) {
758 QAccessibleCache::instance()->insert(object, iface);
759 Q_ASSERT(QAccessibleCache::instance()->containsObject(object));
765 if (!qAccessiblePlugins()->contains(cn)) {
766 QAccessiblePlugin *factory =
nullptr;
767 const int index = acLoader()->indexOf(cn);
769 factory = qobject_cast<QAccessiblePlugin *>(acLoader()->instance(index));
770 qAccessiblePlugins()->insert(cn, factory);
774 Q_ASSERT(qAccessiblePlugins()->contains(cn));
775 QAccessiblePlugin *factory = qAccessiblePlugins()->value(cn);
777 QAccessibleInterface *result = factory->create(cn, object);
779 QAccessibleCache::instance()->insert(object, result);
780 Q_ASSERT(QAccessibleCache::instance()->containsObject(object));
784 mo = mo->superClass();
787 if (object == qApp) {
788 QAccessibleInterface *appInterface =
new QAccessibleApplication;
789 QAccessibleCache::instance()->insert(object, appInterface);
790 Q_ASSERT(QAccessibleCache::instance()->containsObject(qApp));
798
799
800
801
802
803
804
805
806
807
808
809
810
811QAccessible::Id QAccessible::registerAccessibleInterface(QAccessibleInterface *iface)
814 return QAccessibleCache::instance()->insert(iface->object(), iface);
818
819
820
821
822void QAccessible::deleteAccessibleInterface(Id id)
824 QAccessibleCache::instance()->deleteInterface(id);
828
829
830QAccessible::Id QAccessible::uniqueId(QAccessibleInterface *iface)
832 Id id = QAccessibleCache::instance()->idForInterface(iface);
834 id = registerAccessibleInterface(iface);
839
840
841
842
843QAccessibleInterface *QAccessible::accessibleInterface(Id id)
845 return QAccessibleCache::instance()->interfaceForId(id);
850
851
852
853
854
855
856
857
858
859
860bool QAccessible::isActive()
862 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
863 return pfAccessibility->isActive();
868
869
870void QAccessible::setActive(
bool active)
872 for (
int i = 0; i < qAccessibleActivationObservers()->size() ;++i)
873 qAccessibleActivationObservers()->at(i)->accessibilityActiveChanged(active);
878
879
880
881
882
883
884
885
886
887
888
889
890
891void QAccessible::setRootObject(QObject *object)
893 if (rootObjectHandler) {
894 rootObjectHandler(object);
898 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
899 pfAccessibility->setRootObject(object);
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921void QAccessible::updateAccessibility(QAccessibleEvent *event)
929 QAccessibleInterface *iface = event->accessibleInterface();
930 if (isActive() && iface) {
931 if (event->type() == QAccessible::TableModelChanged) {
932 if (iface->tableInterface())
933 iface->tableInterface()->modelChange(
static_cast<QAccessibleTableModelChangeEvent*>(event));
938 updateHandler(event);
942 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
943 pfAccessibility->notifyAccessibilityUpdate(event);
947
948
949
950
951
952
953std::pair<
int,
int > QAccessible::qAccessibleTextBoundaryHelper(
const QTextCursor &offsetCursor, TextBoundaryType boundaryType)
955 Q_ASSERT(!offsetCursor.isNull());
957 QTextCursor endCursor = offsetCursor;
958 endCursor.movePosition(QTextCursor::End);
959 int characterCount = endCursor.position();
961 std::pair<
int,
int> result;
962 QTextCursor cursor = offsetCursor;
963 switch (boundaryType) {
965 result.first = cursor.position();
966 cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
967 result.second = cursor.position();
970 cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
971 result.first = cursor.position();
972 cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
973 result.second = cursor.position();
975 case SentenceBoundary: {
979 cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
980 result.first = cursor.position();
981 cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
982 result.second = cursor.position();
983 QString blockText = cursor.selectedText();
984 const int offsetWithinBlockText = offsetCursor.position() - result.first;
985 QTextBoundaryFinder sentenceFinder(QTextBoundaryFinder::Sentence, blockText);
986 sentenceFinder.setPosition(offsetWithinBlockText);
987 int prevBoundary = offsetWithinBlockText;
988 int nextBoundary = offsetWithinBlockText;
989 if (!(sentenceFinder.boundaryReasons() & QTextBoundaryFinder::StartOfItem))
990 prevBoundary = sentenceFinder.toPreviousBoundary();
991 nextBoundary = sentenceFinder.toNextBoundary();
992 if (nextBoundary != -1)
993 result.second = result.first + nextBoundary;
994 if (prevBoundary != -1)
995 result.first += prevBoundary;
998 cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);
999 result.first = cursor.position();
1000 cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
1001 result.second = cursor.position();
1003 case ParagraphBoundary:
1004 cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
1005 result.first = cursor.position();
1006 cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
1007 result.second = cursor.position();
1011 result.second = characterCount;
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1110
1111
1112
1113
1114
1115
1116
1117
1120
1121
1122
1123
1124
1125
1126
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1141
1142
1143
1144
1145
1146
1147
1148
1149
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161QList<std::pair<QAccessibleInterface*, QAccessible::Relation>>
1162QAccessibleInterface::relations(QAccessible::Relation match)
const
1169
1170
1171
1172
1173QAccessibleInterface *QAccessibleInterface::focusChild()
const
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1198
1199
1200
1201
1202
1203
1204
1205
1208
1209
1210
1211
1212
1213
1214
1215
1216
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1268
1269
1270
1271
1272
1273
1274
1275
1276
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1292
1293
1294
1295
1296
1297
1298
1299
1300
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1315
1316
1317
1318
1319QColor QAccessibleInterface::foregroundColor()
const
1325
1326
1327
1328
1329QColor QAccessibleInterface::backgroundColor()
const
1335
1336
1339
1340
1341
1344
1345
1348
1349
1352
1353
1356
1357
1360
1361
1362
1365
1366
1367
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1390
1391
1392
1393
1396
1397
1398
1399
1400
1401
1404
1405
1406QAccessibleEvent::~QAccessibleEvent()
1411
1412
1415
1416
1419
1420
1423
1424
1427
1428
1429
1430
1431
1432
1433QAccessible::Id QAccessibleEvent::uniqueId()
const
1437 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
1440 if (m_child != -1) {
1441 iface = iface->child(m_child);
1442 if (Q_UNLIKELY(!iface)) {
1443 qCWarning(lcAccessibilityCore) <<
"Invalid child in QAccessibleEvent:" << m_object <<
"child:" << m_child;
1447 return QAccessible::uniqueId(iface);
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1463
1464
1465
1466
1468
1469
1470
1471
1474
1475
1476
1478
1479
1480
1481
1483
1484
1485QAccessibleValueChangeEvent::~QAccessibleValueChangeEvent()
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1502
1503
1504
1505
1507
1508
1509
1510
1511
1512
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1526
1527
1528QAccessibleStateChangeEvent::~QAccessibleStateChangeEvent()
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1546
1547
1548
1549
1550
1551
1552
1553
1555
1556
1557
1559
1560
1561
1563
1564
1565
1567
1568
1569
1571
1572
1573
1575
1576
1577
1579
1580
1581
1583
1584
1585
1587
1588
1589
1591
1592
1593
1595
1596
1597
1599
1600
1601
1602
1603
1605
1606
1607QAccessibleTableModelChangeEvent::~QAccessibleTableModelChangeEvent()
1611
1612
1613
1614
1615
1616
1617
1618
1620
1621
1622
1623
1625
1626
1627
1629
1630
1631
1633
1634
1635QAccessibleTextCursorEvent::~QAccessibleTextCursorEvent()
1641
1642
1643
1644
1645
1648
1649
1650
1651
1652
1653
1654
1655
1657
1658
1659
1660
1661
1662
1663
1665
1666
1667
1669
1670
1671
1673
1674
1675QAccessibleTextInsertEvent::~QAccessibleTextInsertEvent()
1681
1682
1683
1684
1685
1686
1687
1688
1690
1691
1692
1693
1694
1695
1696
1698
1699
1700
1701
1702
1703
1704
1707
1708
1709
1711
1712
1713
1715
1716
1717QAccessibleTextRemoveEvent::~QAccessibleTextRemoveEvent()
1722
1723
1724
1725
1726
1729
1730
1731
1732
1733
1736
1737
1738
1739
1740
1741
1742
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1759
1760
1761
1762
1764
1765
1766
1768
1769
1770
1772
1773
1774
1776
1777
1778QAccessibleTextUpdateEvent::~QAccessibleTextUpdateEvent()
1784
1785
1786
1787
1788
1789
1790
1791
1793
1794
1795
1796
1798
1799
1800
1802
1803
1804
1806
1807
1808
1810
1811
1812QAccessibleTextSelectionEvent::~QAccessibleTextSelectionEvent()
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1829
1830
1831
1832
1833
1834
1835
1838
1839
1840
1841
1842
1843
1844
1847
1848
1849
1852
1853
1854
1857
1858
1859
1863
1864
1865QAccessibleAnnouncementEvent::~QAccessibleAnnouncementEvent()
1870
1871
1872QAccessibleInterface *QAccessibleEvent::accessibleInterface()
const
1874 if (m_object ==
nullptr)
1875 return QAccessible::accessibleInterface(m_uniqueId);
1877 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
1878 if (!iface || !iface->isValid())
1882 QAccessibleInterface *child = iface->child(m_child);
1886 qCWarning(lcAccessibilityCore) <<
"Cannot create accessible child interface for object: " << m_object <<
" index: " << m_child;
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905QWindow *QAccessibleInterface::window()
const
1911
1912
1913
1914
1915
1916
1917
1918void QAccessibleInterface::virtual_hook(
int ,
void * )
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1939const char *qAccessibleRoleString(QAccessible::Role role)
1941 if (role >= QAccessible::UserRole)
1942 role = QAccessible::UserRole;
1943 static int roleEnum = QAccessible::staticMetaObject.indexOfEnumerator(
"Role");
1944 return QAccessible::staticMetaObject.enumerator(roleEnum).valueToKey(role);
1948const char *qAccessibleEventString(QAccessible::Event event)
1950 static int eventEnum = QAccessible::staticMetaObject.indexOfEnumerator(
"Event");
1951 return QAccessible::staticMetaObject.enumerator(eventEnum).valueToKey(event);
1954#ifndef QT_NO_DEBUG_STREAM
1956Q_GUI_EXPORT QDebug operator<<(QDebug d,
const QAccessibleInterface *iface)
1958 QDebugStateSaver saver(d);
1960 d <<
"QAccessibleInterface(null)";
1964 d <<
"QAccessibleInterface(" << Qt::hex << (
const void *) iface << Qt::dec;
1965 if (iface->isValid()) {
1966 d <<
" name=" << iface->text(QAccessible::Name) <<
' ';
1967 d <<
"role=" << qAccessibleRoleString(iface->role()) <<
' ';
1968 if (iface->childCount())
1969 d <<
"childc=" << iface->childCount() <<
' ';
1970 if (iface->object()) {
1971 d <<
"obj=" << iface->object();
1973 QStringList stateStrings;
1974 QAccessible::State st = iface->state();
1976 stateStrings << u"focusable"_s;
1978 stateStrings << u"focused"_s;
1980 stateStrings << u"selected"_s;
1982 stateStrings << u"invisible"_s;
1984 if (!stateStrings.isEmpty())
1985 d << stateStrings.join(u'|');
1988 d <<
"rect=" << iface->rect();
1998QDebug operator<<(QDebug d,
const QAccessibleEvent &ev)
2000 QDebugStateSaver saver(d);
2001 d.nospace() <<
"QAccessibleEvent(";
2003 d.nospace() <<
"object=" << Qt::hex << ev.object() << Qt::dec;
2004 d.nospace() <<
"child=" << ev.child();
2006 d.nospace() <<
"no object, uniqueId=" << ev.uniqueId();
2008 d <<
" event=" << qAccessibleEventString(ev.type());
2009 if (ev.type() == QAccessible::StateChanged) {
2010 QAccessible::State changed =
static_cast<
const QAccessibleStateChangeEvent*>(&ev)->changedStates();
2011 d <<
"State changed:";
2012 if (changed.disabled) d <<
"disabled";
2013 if (changed.selected) d <<
"selected";
2014 if (changed.focusable) d <<
"focusable";
2015 if (changed.focused) d <<
"focused";
2016 if (changed.pressed) d <<
"pressed";
2017 if (changed.checkable) d <<
"checkable";
2018 if (changed.checked) d <<
"checked";
2019 if (changed.checkStateMixed) d <<
"checkStateMixed";
2020 if (changed.readOnly) d <<
"readOnly";
2021 if (changed.hotTracked) d <<
"hotTracked";
2022 if (changed.defaultButton) d <<
"defaultButton";
2023 if (changed.expanded) d <<
"expanded";
2024 if (changed.collapsed) d <<
"collapsed";
2025 if (changed.busy) d <<
"busy";
2026 if (changed.expandable) d <<
"expandable";
2027 if (changed.marqueed) d <<
"marqueed";
2028 if (changed.animated) d <<
"animated";
2029 if (changed.invisible) d <<
"invisible";
2030 if (changed.offscreen) d <<
"offscreen";
2031 if (changed.sizeable) d <<
"sizeable";
2032 if (changed.movable) d <<
"movable";
2033 if (changed.selfVoicing) d <<
"selfVoicing";
2034 if (changed.selectable) d <<
"selectable";
2035 if (changed.linked) d <<
"linked";
2036 if (changed.traversed) d <<
"traversed";
2037 if (changed.multiSelectable) d <<
"multiSelectable";
2038 if (changed.extSelectable) d <<
"extSelectable";
2039 if (changed.passwordEdit) d <<
"passwordEdit";
2040 if (changed.hasPopup) d <<
"hasPopup";
2041 if (changed.modal) d <<
"modal";
2045 if (changed.active) d <<
"active";
2046 if (changed.invalid) d <<
"invalid";
2047 if (changed.editable) d <<
"editable";
2048 if (changed.multiLine) d <<
"multiLine";
2049 if (changed.selectableText) d <<
"selectableText";
2050 if (changed.supportsAutoCompletion) d <<
"supportsAutoCompletion";
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2078
2079
2080
2081QAccessibleTextInterface::~QAccessibleTextInterface()
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2099
2100
2101
2102
2103
2106
2107
2108
2109
2112
2113
2114
2115
2118
2119
2120
2121
2124
2125
2126
2127
2130
2131
2132
2133
2134
2135
2136
2137
2140
2141
2142
2143
2144
2145
2148
2149
2150
2151
2152static QString textLineBoundary(
int beforeAtAfter,
const QString &text,
int offset,
int *startOffset,
int *endOffset)
2154 Q_ASSERT(beforeAtAfter >= -1 && beforeAtAfter <= 1);
2155 Q_ASSERT(*startOffset == -1 && *endOffset == -1);
2156 int length = text.size();
2157 Q_ASSERT(offset >= 0 && offset <= length);
2160 if (beforeAtAfter == 1) {
2161 offset = text.indexOf(QChar::LineFeed, qMin(offset, length - 1));
2165 }
else if (beforeAtAfter == -1) {
2166 offset = text.lastIndexOf(QChar::LineFeed, qMax(offset - 1, 0));
2172 *startOffset = text.lastIndexOf(QChar::LineFeed, offset - 1);
2175 *endOffset = text.indexOf(QChar::LineFeed, qMin(offset, length - 1)) + 1;
2176 if (*endOffset <= 0 || *endOffset > length)
2177 *endOffset = length;
2179 return text.mid(*startOffset, *endOffset - *startOffset);
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199QString QAccessibleTextInterface::textBeforeOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2200 int *startOffset,
int *endOffset)
const
2202 const QString txt = text(0, characterCount());
2205 offset = txt.size();
2207 *startOffset = *endOffset = -1;
2208 if (txt.isEmpty() || offset <= 0 || offset > txt.size())
2212 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2213 switch (boundaryType) {
2214 case QAccessible::CharBoundary:
2215 type = QTextBoundaryFinder::Grapheme;
2217 case QAccessible::WordBoundary:
2218 type = QTextBoundaryFinder::Word;
2220 case QAccessible::SentenceBoundary:
2221 type = QTextBoundaryFinder::Sentence;
2223 case QAccessible::LineBoundary:
2224 case QAccessible::ParagraphBoundary:
2226 return textLineBoundary(-1, txt, offset, startOffset, endOffset);
2227 case QAccessible::NoBoundary:
2236 QTextBoundaryFinder boundary(type, txt);
2237 boundary.setPosition(offset);
2240 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2242 }
while (boundary.toPreviousBoundary() > 0);
2243 Q_ASSERT(boundary.position() >= 0);
2244 *endOffset = boundary.position();
2246 while (boundary.toPreviousBoundary() > 0) {
2247 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2250 Q_ASSERT(boundary.position() >= 0);
2251 *startOffset = boundary.position();
2253 return txt.mid(*startOffset, *endOffset - *startOffset);
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273QString QAccessibleTextInterface::textAfterOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2274 int *startOffset,
int *endOffset)
const
2276 const QString txt = text(0, characterCount());
2279 offset = txt.size();
2281 *startOffset = *endOffset = -1;
2282 if (txt.isEmpty() || offset < 0 || offset >= txt.size())
2286 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2287 switch (boundaryType) {
2288 case QAccessible::CharBoundary:
2289 type = QTextBoundaryFinder::Grapheme;
2291 case QAccessible::WordBoundary:
2292 type = QTextBoundaryFinder::Word;
2294 case QAccessible::SentenceBoundary:
2295 type = QTextBoundaryFinder::Sentence;
2297 case QAccessible::LineBoundary:
2298 case QAccessible::ParagraphBoundary:
2300 return textLineBoundary(1, txt, offset, startOffset, endOffset);
2301 case QAccessible::NoBoundary:
2310 QTextBoundaryFinder boundary(type, txt);
2311 boundary.setPosition(offset);
2314 int toNext = boundary.toNextBoundary();
2315 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2317 if (toNext < 0 || toNext >= txt.size())
2320 Q_ASSERT(boundary.position() <= txt.size());
2321 *startOffset = boundary.position();
2324 int toNext = boundary.toNextBoundary();
2325 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2327 if (toNext < 0 || toNext >= txt.size())
2330 Q_ASSERT(boundary.position() <= txt.size());
2331 *endOffset = boundary.position();
2333 if ((*startOffset == -1) || (*endOffset == -1) || (*startOffset == *endOffset)) {
2338 return txt.mid(*startOffset, *endOffset - *startOffset);
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358QString QAccessibleTextInterface::textAtOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2359 int *startOffset,
int *endOffset)
const
2361 const QString txt = text(0, characterCount());
2364 offset = txt.size();
2366 *startOffset = *endOffset = -1;
2367 if (txt.isEmpty() || offset < 0 || offset > txt.size())
2370 if (offset == txt.size() && boundaryType == QAccessible::CharBoundary)
2374 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2375 switch (boundaryType) {
2376 case QAccessible::CharBoundary:
2377 type = QTextBoundaryFinder::Grapheme;
2379 case QAccessible::WordBoundary:
2380 type = QTextBoundaryFinder::Word;
2382 case QAccessible::SentenceBoundary:
2383 type = QTextBoundaryFinder::Sentence;
2385 case QAccessible::LineBoundary:
2386 case QAccessible::ParagraphBoundary:
2388 return textLineBoundary(0, txt, offset, startOffset, endOffset);
2389 case QAccessible::NoBoundary:
2391 *endOffset = txt.size();
2399 QTextBoundaryFinder boundary(type, txt);
2400 boundary.setPosition(offset);
2403 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2405 }
while (boundary.toPreviousBoundary() > 0);
2406 Q_ASSERT(boundary.position() >= 0);
2407 *startOffset = boundary.position();
2409 while (boundary.toNextBoundary() < txt.size()) {
2410 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2413 Q_ASSERT(boundary.position() <= txt.size());
2414 *endOffset = boundary.position();
2416 return txt.mid(*startOffset, *endOffset - *startOffset);
2420
2421
2422
2423
2426
2427
2428
2429
2432
2433
2434
2435
2436
2437
2440
2441
2442
2443
2446
2447
2448
2449
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2466
2467
2468
2469QAccessibleEditableTextInterface::~QAccessibleEditableTextInterface()
2474
2475
2476
2477
2480
2481
2482
2483
2486
2487
2488
2489
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2510
2511
2512
2513QAccessibleValueInterface::~QAccessibleValueInterface()
2518
2519
2520
2521
2522
2525
2526
2527
2528
2529
2530
2531
2534
2535
2536
2537
2538
2541
2542
2543
2544
2545
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2574
2575
2576QAccessibleImageInterface::~QAccessibleImageInterface()
2581
2582
2583
2584
2585
2586
2587
2588
2589
2592
2593
2594
2595QAccessibleTableCellInterface::~QAccessibleTableCellInterface()
2600
2601
2602
2603
2606
2607
2608
2609
2612
2613
2614
2615
2618
2619
2620
2621
2624
2625
2626
2627
2630
2631
2632
2633
2636
2637
2638
2639
2642
2643
2644
2645
2649
2650
2651
2652
2653
2654
2655
2656
2657
2660
2661
2662
2663QAccessibleTableInterface::~QAccessibleTableInterface()
2668
2669
2670
2671
2674
2675
2676
2677
2680
2681
2682
2683
2686
2687
2688
2689
2692
2693
2694
2695
2698
2699
2700
2701
2704
2705
2706
2707
2710
2711
2712
2713
2716
2717
2718
2719
2722
2723
2724
2725
2728
2729
2730
2731
2734
2735
2736
2737
2740
2741
2742
2743
2744
2747
2748
2749
2750
2753
2754
2755
2756
2759
2760
2761
2762
2763
2766
2767
2768
2769
2770
2773
2774
2775
2776
2777
2780
2781
2782
2783
2784
2787
2788
2789
2790
2791
2792
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2836
2837
2838
2839QAccessibleActionInterface::~QAccessibleActionInterface()
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2875
2876
2877
2878
2879
2880
2881
2882
2883
2886
2887
2888
2889
2890
2891
2892
2893
2894
2897
2898
2899
2900
2901
2902
2903
2904
2907struct QAccessibleActionStrings
2909 QAccessibleActionStrings() :
2910 pressAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Press"))),
2911 increaseAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Increase"))),
2912 decreaseAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Decrease"))),
2913 showMenuAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"ShowMenu"))),
2914 setFocusAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"SetFocus"))),
2915 toggleAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Toggle"))),
2916 scrollLeftAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Left"))),
2917 scrollRightAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Right"))),
2918 scrollUpAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Up"))),
2919 scrollDownAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Down"))),
2920 previousPageAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Previous Page"))),
2921 nextPageAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Next Page")))
2924 const QString pressAction;
2925 const QString increaseAction;
2926 const QString decreaseAction;
2927 const QString showMenuAction;
2928 const QString setFocusAction;
2929 const QString toggleAction;
2930 const QString scrollLeftAction;
2931 const QString scrollRightAction;
2932 const QString scrollUpAction;
2933 const QString scrollDownAction;
2934 const QString previousPageAction;
2935 const QString nextPageAction;
2937 QString localizedDescription(
const QString &actionName)
2939 if (actionName == pressAction)
2940 return QAccessibleActionInterface::tr(
"Triggers the action");
2941 else if (actionName == increaseAction)
2942 return QAccessibleActionInterface::tr(
"Increase the value");
2943 else if (actionName == decreaseAction)
2944 return QAccessibleActionInterface::tr(
"Decrease the value");
2945 else if (actionName == showMenuAction)
2946 return QAccessibleActionInterface::tr(
"Shows the menu");
2947 else if (actionName == setFocusAction)
2948 return QAccessibleActionInterface::tr(
"Sets the focus");
2949 else if (actionName == toggleAction)
2950 return QAccessibleActionInterface::tr(
"Toggles the state");
2951 else if (actionName == scrollLeftAction)
2952 return QAccessibleActionInterface::tr(
"Scrolls to the left");
2953 else if (actionName == scrollRightAction)
2954 return QAccessibleActionInterface::tr(
"Scrolls to the right");
2955 else if (actionName == scrollUpAction)
2956 return QAccessibleActionInterface::tr(
"Scrolls up");
2957 else if (actionName == scrollDownAction)
2958 return QAccessibleActionInterface::tr(
"Scrolls down");
2959 else if (actionName == previousPageAction)
2960 return QAccessibleActionInterface::tr(
"Goes back a page");
2961 else if (actionName == nextPageAction)
2962 return QAccessibleActionInterface::tr(
"Goes to the next page");
2969Q_GLOBAL_STATIC(QAccessibleActionStrings, accessibleActionStrings)
2971QString QAccessibleActionInterface::localizedActionName(
const QString &actionName)
const
2973 return QAccessibleActionInterface::tr(qPrintable(actionName));
2976QString QAccessibleActionInterface::localizedActionDescription(
const QString &actionName)
const
2978 return accessibleActionStrings()->localizedDescription(actionName);
2982
2983
2984
2985const QString &QAccessibleActionInterface::pressAction()
2987 return accessibleActionStrings()->pressAction;
2991
2992
2993
2994const QString &QAccessibleActionInterface::increaseAction()
2996 return accessibleActionStrings()->increaseAction;
3000
3001
3002
3003const QString &QAccessibleActionInterface::decreaseAction()
3005 return accessibleActionStrings()->decreaseAction;
3009
3010
3011
3012const QString &QAccessibleActionInterface::showMenuAction()
3014 return accessibleActionStrings()->showMenuAction;
3018
3019
3020
3021const QString &QAccessibleActionInterface::setFocusAction()
3023 return accessibleActionStrings()->setFocusAction;
3027
3028
3029
3030const QString &QAccessibleActionInterface::toggleAction()
3032 return accessibleActionStrings()->toggleAction;
3036
3037
3038
3039QString QAccessibleActionInterface::scrollLeftAction()
3041 return accessibleActionStrings()->scrollLeftAction;
3045
3046
3047
3048QString QAccessibleActionInterface::scrollRightAction()
3050 return accessibleActionStrings()->scrollRightAction;
3054
3055
3056
3057QString QAccessibleActionInterface::scrollUpAction()
3059 return accessibleActionStrings()->scrollUpAction;
3063
3064
3065
3066QString QAccessibleActionInterface::scrollDownAction()
3068 return accessibleActionStrings()->scrollDownAction;
3072
3073
3074
3075QString QAccessibleActionInterface::previousPageAction()
3077 return accessibleActionStrings()->previousPageAction;
3081
3082
3083
3084QString QAccessibleActionInterface::nextPageAction()
3086 return accessibleActionStrings()->nextPageAction;
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3106
3107
3108
3109QAccessibleSelectionInterface::~QAccessibleSelectionInterface()
3114
3115
3116
3117
3120
3121
3122
3123
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138QAccessibleInterface* QAccessibleSelectionInterface::selectedItem(
int selectionIndex)
const
3140 QList<QAccessibleInterface*> items = selectedItems();
3141 if (selectionIndex < 0 || selectionIndex > items.length() -1) {
3142 qCWarning(lcAccessibilityCore) <<
"Selection index" << selectionIndex <<
"out of range.";
3146 return items.at(selectionIndex);
3150
3151
3152
3153
3154
3155bool QAccessibleSelectionInterface::isSelected(QAccessibleInterface *childItem)
const
3157 return selectedItems().contains(childItem);
3161
3162
3163
3164
3165
3166
3167
3168
3171
3172
3173
3174
3175
3176
3179
3180
3181
3182
3183
3184
3187
3188
3189
3190
3191
3192
3193
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3221
3222
3223
3224QAccessibleAttributesInterface::~QAccessibleAttributesInterface()
3229
3230
3231
3232
3233
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3248QString qAccessibleLocalizedActionDescription(
const QString &actionName)
3250 return accessibleActionStrings()->localizedDescription(actionName);
3254
3255
3256
3257
3258
3261
3262
3263
3264
3265
3268
3269
3270
3271
3272
3273
3274
3275
3278
3279
3280
3281
3282
3283
3284
3286QAccessibleHyperlinkInterface::~QAccessibleHyperlinkInterface()
3295#include "moc_qaccessible_base.cpp"
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")