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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
516#if QT_CONFIG(accessibility)
519
520
521QAccessibleInterface::~QAccessibleInterface()
526
527
528
529
533Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, acLoader,
534 (QAccessibleFactoryInterface_iid,
"/accessible"_L1))
535typedef QHash<QString, QAccessiblePlugin*> QAccessiblePluginsHash;
536Q_GLOBAL_STATIC(QAccessiblePluginsHash, qAccessiblePlugins)
539Q_GLOBAL_STATIC(QList<QAccessible::InterfaceFactory>, qAccessibleFactories)
540Q_GLOBAL_STATIC(QList<QAccessible::ActivationObserver *>, qAccessibleActivationObservers)
542QAccessible::UpdateHandler QAccessible::updateHandler =
nullptr;
543QAccessible::RootObjectHandler QAccessible::rootObjectHandler =
nullptr;
545static bool cleanupAdded =
false;
547static QPlatformAccessibility *platformAccessibility()
549 QPlatformIntegration *pfIntegration = QGuiApplicationPrivate::platformIntegration();
550 return pfIntegration ? pfIntegration->accessibility() :
nullptr;
554
555
556
557
558
559
563
564
565void QAccessible::cleanup()
567 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
568 pfAccessibility->cleanup();
571static void qAccessibleCleanup()
573 qAccessibleActivationObservers()->clear();
574 qAccessibleFactories()->clear();
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
598
599
600
601
602
603
604
605
606
609
610
611
612
613
614
615
616
617
621
622
623
624void QAccessible::installFactory(InterfaceFactory factory)
630 qAddPostRoutine(qAccessibleCleanup);
633 if (qAccessibleFactories()->contains(factory))
635 qAccessibleFactories()->append(factory);
639
640
641void QAccessible::removeFactory(InterfaceFactory factory)
643 qAccessibleFactories()->removeAll(factory);
647
648
649
650
651
652
653QAccessible::UpdateHandler QAccessible::installUpdateHandler(UpdateHandler handler)
655 UpdateHandler old = updateHandler;
656 updateHandler = handler;
661
662
663
664
665
666QAccessible::RootObjectHandler QAccessible::installRootObjectHandler(RootObjectHandler handler)
668 RootObjectHandler old = rootObjectHandler;
669 rootObjectHandler = handler;
674
675
676
677
678
679
681QAccessible::ActivationObserver::~ActivationObserver()
686
687
688
689
690void QAccessible::installActivationObserver(QAccessible::ActivationObserver *observer)
696 qAddPostRoutine(qAccessibleCleanup);
699 if (qAccessibleActivationObservers()->contains(observer))
701 qAccessibleActivationObservers()->append(observer);
705 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
706 pfAccessibility->clearActiveNotificationState();
710
711
712
713
714
715void QAccessible::removeActivationObserver(ActivationObserver *observer)
717 qAccessibleActivationObservers()->removeAll(observer);
721
722
723
724
725void qAccessibleNotifyActivationObservers(
bool active)
727 for (
int i = 0; i < qAccessibleActivationObservers()->size(); ++i)
728 qAccessibleActivationObservers()->at(i)->accessibilityActiveChanged(active);
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749QAccessibleInterface *QAccessible::queryAccessibleInterface(QObject *object)
754 if (Id id = QAccessibleCache::instance()->idForObject(object))
755 return QAccessibleCache::instance()->interfaceForId(id);
759 const QMetaObject *mo = object->metaObject();
760 const auto *objectPriv = QObjectPrivate::get(object);
762
763
764
765
766
767
768
769
770 const bool qmlRelated = !objectPriv->isDeletingChildren &&
771 objectPriv->declarativeData;
772 while (qmlRelated && mo) {
773 auto mop = QMetaObjectPrivate::get(mo);
774 if (!mop || !(mop->flags & DynamicMetaObject))
777 mo = mo->superClass();
780 const QString cn = QLatin1StringView(mo->className());
783 for (
int i = qAccessibleFactories()->size(); i > 0; --i) {
784 InterfaceFactory factory = qAccessibleFactories()->at(i - 1);
785 if (QAccessibleInterface *iface = factory(cn, object)) {
786 QAccessibleCache::instance()->insert(object, iface);
787 Q_ASSERT(QAccessibleCache::instance()->containsObject(object));
793 if (!qAccessiblePlugins()->contains(cn)) {
794 QAccessiblePlugin *factory =
nullptr;
795 const int index = acLoader()->indexOf(cn);
797 factory = qobject_cast<QAccessiblePlugin *>(acLoader()->instance(index));
798 qAccessiblePlugins()->insert(cn, factory);
802 Q_ASSERT(qAccessiblePlugins()->contains(cn));
803 QAccessiblePlugin *factory = qAccessiblePlugins()->value(cn);
805 QAccessibleInterface *result = factory->create(cn, object);
807 QAccessibleCache::instance()->insert(object, result);
808 Q_ASSERT(QAccessibleCache::instance()->containsObject(object));
812 mo = mo->superClass();
815 if (object == qApp) {
816 QAccessibleInterface *appInterface =
new QAccessibleApplication;
817 QAccessibleCache::instance()->insert(object, appInterface);
818 Q_ASSERT(QAccessibleCache::instance()->containsObject(qApp));
826
827
828
829
830
831
832
833
834
835
836
837
838
839QAccessible::Id QAccessible::registerAccessibleInterface(QAccessibleInterface *iface)
842 return QAccessibleCache::instance()->insert(iface->object(), iface);
846
847
848
849
850void QAccessible::deleteAccessibleInterface(Id id)
852 QAccessibleCache::instance()->deleteInterface(id);
856
857
858QAccessible::Id QAccessible::uniqueId(QAccessibleInterface *iface)
860 Id id = QAccessibleCache::instance()->idForInterface(iface);
862 id = registerAccessibleInterface(iface);
867
868
869
870
871QAccessibleInterface *QAccessible::accessibleInterface(Id id)
873 return QAccessibleCache::instance()->interfaceForId(id);
878
879
880
881
882
883
884
885
886
887
888bool QAccessible::isActive()
890 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
891 return pfAccessibility->isActive();
896
897
898void QAccessible::setActive(
bool active)
900 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
901 pfAccessibility->setActive(active);
905
906
907
908
909
910
911
912
913
914
915
916
917
918void QAccessible::setRootObject(QObject *object)
920 if (rootObjectHandler) {
921 rootObjectHandler(object);
925 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
926 pfAccessibility->setRootObject(object);
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948void QAccessible::updateAccessibility(QAccessibleEvent *event)
957 QAccessibleInterface *iface = event->accessibleInterface();
959 if (event->type() == QAccessible::TableModelChanged) {
960 if (iface->tableInterface())
961 iface->tableInterface()->modelChange(
static_cast<QAccessibleTableModelChangeEvent*>(event));
966 updateHandler(event);
970 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
971 pfAccessibility->notifyAccessibilityUpdate(event);
974static std::pair<
int,
int> qAccessibleTextBoundaryHelperHelper(QTextCursor &cursor,
975 QTextCursor::MoveOperation start,
976 QTextCursor::MoveOperation end)
978 std::pair<
int,
int> result;
979 cursor.movePosition(start, QTextCursor::MoveAnchor);
980 result.first = cursor.position();
981 cursor.movePosition(end, QTextCursor::KeepAnchor);
982 result.second = cursor.position();
987
988
989
990
991
992
993std::pair<
int,
int > QAccessible::qAccessibleTextBoundaryHelper(
const QTextCursor &offsetCursor, TextBoundaryType boundaryType)
995 Q_ASSERT(!offsetCursor.isNull());
997 QTextCursor cursor = offsetCursor;
998 switch (boundaryType) {
1000 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::NoMove,
1001 QTextCursor::NextCharacter);
1003 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::StartOfWord,
1004 QTextCursor::EndOfWord);
1005 case SentenceBoundary: {
1009 std::pair<
int,
int> result = qAccessibleTextBoundaryHelperHelper(
1010 cursor, QTextCursor::StartOfBlock, QTextCursor::EndOfBlock);
1011 QString blockText = cursor.selectedText();
1012 const int offsetWithinBlockText = offsetCursor.position() - result.first;
1013 QTextBoundaryFinder sentenceFinder(QTextBoundaryFinder::Sentence, blockText);
1014 sentenceFinder.setPosition(offsetWithinBlockText);
1015 int prevBoundary = offsetWithinBlockText;
1016 int nextBoundary = offsetWithinBlockText;
1017 if (!(sentenceFinder.boundaryReasons() & QTextBoundaryFinder::StartOfItem))
1018 prevBoundary = sentenceFinder.toPreviousBoundary();
1019 nextBoundary = sentenceFinder.toNextBoundary();
1020 if (nextBoundary != -1)
1021 result.second = result.first + nextBoundary;
1022 if (prevBoundary != -1)
1023 result.first += prevBoundary;
1027 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::StartOfLine,
1028 QTextCursor::EndOfLine);
1029 case ParagraphBoundary:
1030 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::StartOfBlock,
1031 QTextCursor::EndOfBlock);
1033 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::Start, QTextCursor::End);
1036 Q_UNREACHABLE_RETURN({});
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1132
1133
1134
1135
1136
1137
1138
1139
1142
1143
1144
1145
1146
1147
1148
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1163
1164
1165
1166
1167
1168
1169
1170
1171
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183QList<std::pair<QAccessibleInterface*, QAccessible::Relation>>
1184QAccessibleInterface::relations(QAccessible::Relation match)
const
1191
1192
1193
1194
1195QAccessibleInterface *QAccessibleInterface::focusChild()
const
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1220
1221
1222
1223
1224
1225
1226
1227
1230
1231
1232
1233
1234
1235
1236
1237
1238
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1290
1291
1292
1293
1294
1295
1296
1297
1298
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1314
1315
1316
1317
1318
1319
1320
1321
1322
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1337
1338
1339
1340
1341QColor QAccessibleInterface::foregroundColor()
const
1347
1348
1349
1350
1351QColor QAccessibleInterface::backgroundColor()
const
1357
1358
1361
1362
1363
1366
1367
1370
1371
1374
1375
1378
1379
1382
1383
1384
1387
1388
1389
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1412
1413
1414
1415
1418
1419
1420
1421
1422
1423
1426
1427
1428QAccessibleEvent::~QAccessibleEvent()
1433
1434
1437
1438
1441
1442
1445
1446
1449
1450
1451
1452
1453
1454
1455QAccessible::Id QAccessibleEvent::uniqueId()
const
1459 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
1462 if (m_child != -1) {
1463 iface = iface->child(m_child);
1464 if (Q_UNLIKELY(!iface)) {
1465 qCWarning(lcAccessibilityCore) <<
"Invalid child in QAccessibleEvent:" << m_object <<
"child:" << m_child;
1469 return QAccessible::uniqueId(iface);
1472void QAccessibleEvent::setChild(
int chld)
1474 if (m_type == QAccessible::ObjectDestroyed)
1475 qCWarning(lcAccessibilityCore) <<
"Calling QAccessibleEvent::setChild on ObjectDestroyed event " <<
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1493
1494
1495
1496
1498
1499
1500
1501
1504
1505
1506
1508
1509
1510
1511
1514
1515
1516QAccessibleValueChangeEvent::~QAccessibleValueChangeEvent()
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1533
1534
1535
1536
1538
1539
1540
1541
1542
1543
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1557
1558
1559QAccessibleStateChangeEvent::~QAccessibleStateChangeEvent()
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1577
1578
1579
1580
1581
1582
1583
1584
1586
1587
1588
1590
1591
1592
1594
1595
1596
1598
1599
1600
1602
1603
1604
1606
1607
1608
1610
1611
1612
1614
1615
1616
1618
1619
1620
1622
1623
1624
1626
1627
1628
1630
1631
1632
1633
1634
1636
1637
1638QAccessibleTableModelChangeEvent::~QAccessibleTableModelChangeEvent()
1642
1643
1644
1645
1646
1647
1648
1649
1651
1652
1653
1654
1656
1657
1658
1660
1661
1662
1664
1665
1666QAccessibleTextCursorEvent::~QAccessibleTextCursorEvent()
1672
1673
1674
1675
1676
1679
1680
1681
1682
1683
1684
1685
1686
1688
1689
1690
1691
1692
1693
1694
1696
1697
1698
1700
1701
1702
1704
1705
1706QAccessibleTextInsertEvent::~QAccessibleTextInsertEvent()
1712
1713
1714
1715
1716
1717
1718
1719
1721
1722
1723
1724
1725
1726
1727
1729
1730
1731
1732
1733
1734
1735
1738
1739
1740
1742
1743
1744
1746
1747
1748QAccessibleTextRemoveEvent::~QAccessibleTextRemoveEvent()
1753
1754
1755
1756
1757
1760
1761
1762
1763
1764
1767
1768
1769
1770
1771
1772
1773
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1790
1791
1792
1793
1795
1796
1797
1799
1800
1801
1803
1804
1805
1807
1808
1809QAccessibleTextUpdateEvent::~QAccessibleTextUpdateEvent()
1815
1816
1817
1818
1819
1820
1821
1822
1824
1825
1826
1827
1829
1830
1831
1833
1834
1835
1837
1838
1839
1841
1842
1843QAccessibleTextSelectionEvent::~QAccessibleTextSelectionEvent()
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1860
1861
1862
1863
1864
1865
1866
1869
1870
1871
1872
1873
1874
1875
1878
1879
1880
1883
1884
1885
1888
1889
1890
1894
1895
1896QAccessibleAnnouncementEvent::~QAccessibleAnnouncementEvent()
1901
1902
1903QAccessibleInterface *QAccessibleEvent::accessibleInterface()
const
1905 if (m_object ==
nullptr)
1906 return QAccessible::accessibleInterface(m_uniqueId);
1908 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
1909 if (!iface || !iface->isValid())
1913 QAccessibleInterface *child = iface->child(m_child);
1917 qCWarning(lcAccessibilityCore) <<
"Cannot create accessible child interface for object: " << m_object <<
" index: " << m_child <<
"type: " << m_type;
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936QWindow *QAccessibleInterface::window()
const
1942
1943
1944
1945
1946
1947
1948
1949void QAccessibleInterface::virtual_hook(
int ,
void * )
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1970const char *qAccessibleRoleString(QAccessible::Role role)
1972 if (role >= QAccessible::UserRole)
1973 role = QAccessible::UserRole;
1974 static int roleEnum = QAccessible::staticMetaObject.indexOfEnumerator(
"Role");
1975 return QAccessible::staticMetaObject.enumerator(roleEnum).valueToKey(role);
1979const char *qAccessibleEventString(QAccessible::Event event)
1981 static int eventEnum = QAccessible::staticMetaObject.indexOfEnumerator(
"Event");
1982 return QAccessible::staticMetaObject.enumerator(eventEnum).valueToKey(event);
1985#ifndef QT_NO_DEBUG_STREAM
1987Q_GUI_EXPORT QDebug operator<<(QDebug d,
const QAccessibleInterface *iface)
1989 QDebugStateSaver saver(d);
1991 return d <<
"QAccessibleInterface(0x0)";
1994 d <<
"QAccessibleInterface(" << Qt::hex << (
const void *) iface << Qt::dec;
1995 if (iface->isValid()) {
1996 d <<
" name=" << iface->text(QAccessible::Name) <<
' ';
1997 d <<
"role=" << qAccessibleRoleString(iface->role()) <<
' ';
1998 if (iface->childCount())
1999 d <<
"childc=" << iface->childCount() <<
' ';
2000 if (iface->object()) {
2001 d <<
"obj=" << iface->object();
2003 QStringList stateStrings;
2004 QAccessible::State st = iface->state();
2006 stateStrings << u"focusable"_s;
2008 stateStrings << u"focused"_s;
2010 stateStrings << u"selected"_s;
2012 stateStrings << u"invisible"_s;
2014 if (!stateStrings.isEmpty())
2015 d << stateStrings.join(u'|');
2018 d <<
"rect=" << iface->rect();
2028QDebug operator<<(QDebug d,
const QAccessibleEvent &ev)
2030 QDebugStateSaver saver(d);
2031 d.nospace() <<
"QAccessibleEvent(";
2033 d.nospace() <<
"object=" << Qt::hex << ev.object() << Qt::dec;
2034 d.nospace() <<
"child=" << ev.child();
2036 d.nospace() <<
"no object, uniqueId=" << ev.uniqueId();
2038 d <<
" event=" << qAccessibleEventString(ev.type());
2039 if (ev.type() == QAccessible::StateChanged) {
2040 QAccessible::State changed =
static_cast<
const QAccessibleStateChangeEvent*>(&ev)->changedStates();
2041 d <<
"State changed:";
2042 if (changed.disabled) d <<
"disabled";
2043 if (changed.selected) d <<
"selected";
2044 if (changed.focusable) d <<
"focusable";
2045 if (changed.focused) d <<
"focused";
2046 if (changed.pressed) d <<
"pressed";
2047 if (changed.checkable) d <<
"checkable";
2048 if (changed.checked) d <<
"checked";
2049 if (changed.checkStateMixed) d <<
"checkStateMixed";
2050 if (changed.readOnly) d <<
"readOnly";
2051 if (changed.hotTracked) d <<
"hotTracked";
2052 if (changed.defaultButton) d <<
"defaultButton";
2053 if (changed.expanded) d <<
"expanded";
2054 if (changed.collapsed) d <<
"collapsed";
2055 if (changed.busy) d <<
"busy";
2056 if (changed.expandable) d <<
"expandable";
2057 if (changed.marqueed) d <<
"marqueed";
2058 if (changed.animated) d <<
"animated";
2059 if (changed.invisible) d <<
"invisible";
2060 if (changed.offscreen) d <<
"offscreen";
2061 if (changed.sizeable) d <<
"sizeable";
2062 if (changed.movable) d <<
"movable";
2063 if (changed.selfVoicing) d <<
"selfVoicing";
2064 if (changed.selectable) d <<
"selectable";
2065 if (changed.linked) d <<
"linked";
2066 if (changed.traversed) d <<
"traversed";
2067 if (changed.multiSelectable) d <<
"multiSelectable";
2068 if (changed.extSelectable) d <<
"extSelectable";
2069 if (changed.passwordEdit) d <<
"passwordEdit";
2070 if (changed.hasPopup) d <<
"hasPopup";
2071 if (changed.modal) d <<
"modal";
2075 if (changed.active) d <<
"active";
2076 if (changed.invalid) d <<
"invalid";
2077 if (changed.editable) d <<
"editable";
2078 if (changed.multiLine) d <<
"multiLine";
2079 if (changed.selectableText) d <<
"selectableText";
2080 if (changed.supportsAutoCompletion) d <<
"supportsAutoCompletion";
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2108
2109
2110
2111QAccessibleTextInterface::~QAccessibleTextInterface()
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2129
2130
2131
2132
2133
2136
2137
2138
2139
2142
2143
2144
2145
2148
2149
2150
2151
2154
2155
2156
2157
2160
2161
2162
2163
2164
2165
2166
2167
2170
2171
2172
2173
2174
2175
2178
2179
2180
2181
2182static QString textLineBoundary(
int beforeAtAfter,
const QString &text,
int offset,
int *startOffset,
int *endOffset)
2184 Q_ASSERT(beforeAtAfter >= -1 && beforeAtAfter <= 1);
2185 Q_ASSERT(*startOffset == -1 && *endOffset == -1);
2186 int length = text.size();
2187 Q_ASSERT(offset >= 0 && offset <= length);
2190 if (beforeAtAfter == 1) {
2191 offset = text.indexOf(QChar::LineFeed, qMin(offset, length - 1));
2195 }
else if (beforeAtAfter == -1) {
2196 offset = text.lastIndexOf(QChar::LineFeed, qMax(offset - 1, 0));
2202 *startOffset = text.lastIndexOf(QChar::LineFeed, offset - 1);
2205 *endOffset = text.indexOf(QChar::LineFeed, qMin(offset, length - 1)) + 1;
2206 if (*endOffset <= 0 || *endOffset > length)
2207 *endOffset = length;
2209 return text.mid(*startOffset, *endOffset - *startOffset);
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229QString QAccessibleTextInterface::textBeforeOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2230 int *startOffset,
int *endOffset)
const
2232 const QString txt = text(0, characterCount());
2235 offset = txt.size();
2237 *startOffset = *endOffset = -1;
2238 if (txt.isEmpty() || offset <= 0 || offset > txt.size())
2242 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2243 switch (boundaryType) {
2244 case QAccessible::CharBoundary:
2245 type = QTextBoundaryFinder::Grapheme;
2247 case QAccessible::WordBoundary:
2248 type = QTextBoundaryFinder::Word;
2250 case QAccessible::SentenceBoundary:
2251 type = QTextBoundaryFinder::Sentence;
2253 case QAccessible::LineBoundary:
2254 case QAccessible::ParagraphBoundary:
2256 return textLineBoundary(-1, txt, offset, startOffset, endOffset);
2257 case QAccessible::NoBoundary:
2266 QTextBoundaryFinder boundary(type, txt);
2267 boundary.setPosition(offset);
2270 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2272 }
while (boundary.toPreviousBoundary() > 0);
2273 Q_ASSERT(boundary.position() >= 0);
2274 const int endPos = boundary.position();
2276 while (boundary.toPreviousBoundary() > 0) {
2277 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2280 if (boundary.position() < 0)
2283 *endOffset = endPos;
2284 *startOffset = boundary.position();
2286 return txt.mid(*startOffset, *endOffset - *startOffset);
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306QString QAccessibleTextInterface::textAfterOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2307 int *startOffset,
int *endOffset)
const
2309 const QString txt = text(0, characterCount());
2312 offset = txt.size();
2314 *startOffset = *endOffset = -1;
2315 if (txt.isEmpty() || offset < 0 || offset >= txt.size())
2319 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2320 switch (boundaryType) {
2321 case QAccessible::CharBoundary:
2322 type = QTextBoundaryFinder::Grapheme;
2324 case QAccessible::WordBoundary:
2325 type = QTextBoundaryFinder::Word;
2327 case QAccessible::SentenceBoundary:
2328 type = QTextBoundaryFinder::Sentence;
2330 case QAccessible::LineBoundary:
2331 case QAccessible::ParagraphBoundary:
2333 return textLineBoundary(1, txt, offset, startOffset, endOffset);
2334 case QAccessible::NoBoundary:
2343 QTextBoundaryFinder boundary(type, txt);
2344 boundary.setPosition(offset);
2347 int toNext = boundary.toNextBoundary();
2348 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2350 if (toNext < 0 || toNext >= txt.size())
2353 Q_ASSERT(boundary.position() <= txt.size());
2354 *startOffset = boundary.position();
2357 int toNext = boundary.toNextBoundary();
2358 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2360 if (toNext < 0 || toNext >= txt.size())
2363 Q_ASSERT(boundary.position() <= txt.size());
2364 *endOffset = boundary.position();
2366 if ((*startOffset == -1) || (*endOffset == -1) || (*startOffset == *endOffset)) {
2371 return txt.mid(*startOffset, *endOffset - *startOffset);
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391QString QAccessibleTextInterface::textAtOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2392 int *startOffset,
int *endOffset)
const
2394 const QString txt = text(0, characterCount());
2397 offset = txt.size();
2399 *startOffset = *endOffset = -1;
2400 if (txt.isEmpty() || offset < 0 || offset > txt.size())
2403 if (offset == txt.size() && boundaryType == QAccessible::CharBoundary)
2407 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2408 switch (boundaryType) {
2409 case QAccessible::CharBoundary:
2410 type = QTextBoundaryFinder::Grapheme;
2412 case QAccessible::WordBoundary:
2413 type = QTextBoundaryFinder::Word;
2415 case QAccessible::SentenceBoundary:
2416 type = QTextBoundaryFinder::Sentence;
2418 case QAccessible::LineBoundary:
2419 case QAccessible::ParagraphBoundary:
2421 return textLineBoundary(0, txt, offset, startOffset, endOffset);
2422 case QAccessible::NoBoundary:
2424 *endOffset = txt.size();
2432 QTextBoundaryFinder boundary(type, txt);
2433 boundary.setPosition(offset);
2436 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2438 }
while (boundary.toPreviousBoundary() > 0);
2439 Q_ASSERT(boundary.position() >= 0);
2440 const int startPos = boundary.position();
2442 while (boundary.toNextBoundary() < txt.size()) {
2443 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2445 if (boundary.position() == -1)
2449 Q_ASSERT(boundary.position() <= txt.size());
2450 *startOffset = startPos;
2451 *endOffset = boundary.position();
2453 return txt.mid(*startOffset, *endOffset - *startOffset);
2457
2458
2459
2460
2463
2464
2465
2466
2469
2470
2471
2472
2473
2474
2477
2478
2479
2480
2483
2484
2485
2486
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2503
2504
2505
2506QAccessibleEditableTextInterface::~QAccessibleEditableTextInterface()
2511
2512
2513
2514
2517
2518
2519
2520
2523
2524
2525
2526
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2547
2548
2549
2550QAccessibleValueInterface::~QAccessibleValueInterface()
2555
2556
2557
2558
2559
2562
2563
2564
2565
2566
2567
2568
2571
2572
2573
2574
2575
2578
2579
2580
2581
2582
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2611
2612
2613QAccessibleImageInterface::~QAccessibleImageInterface()
2618
2619
2620
2621
2622
2623
2624
2625
2626
2629
2630
2631
2632QAccessibleTableCellInterface::~QAccessibleTableCellInterface()
2637
2638
2639
2640
2643
2644
2645
2646
2649
2650
2651
2652
2655
2656
2657
2658
2661
2662
2663
2664
2667
2668
2669
2670
2673
2674
2675
2676
2679
2680
2681
2682
2686
2687
2688
2689
2690
2691
2692
2693
2694
2697
2698
2699
2700QAccessibleTableInterface::~QAccessibleTableInterface()
2705
2706
2707
2708
2711
2712
2713
2714
2717
2718
2719
2720
2723
2724
2725
2726
2729
2730
2731
2732
2735
2736
2737
2738
2741
2742
2743
2744
2747
2748
2749
2750
2753
2754
2755
2756
2759
2760
2761
2762
2765
2766
2767
2768
2771
2772
2773
2774
2777
2778
2779
2780
2781
2784
2785
2786
2787
2790
2791
2792
2793
2796
2797
2798
2799
2800
2803
2804
2805
2806
2807
2810
2811
2812
2813
2814
2817
2818
2819
2820
2821
2824
2825
2826
2827
2828
2829
2833
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
2873
2874
2875
2876QAccessibleActionInterface::~QAccessibleActionInterface()
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2912
2913
2914
2915
2916
2917
2918
2919
2920
2923
2924
2925
2926
2927
2928
2929
2930
2931
2934
2935
2936
2937
2938
2939
2940
2941
2944struct QAccessibleActionStrings
2946 QAccessibleActionStrings() :
2947 pressAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Press"))),
2948 increaseAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Increase"))),
2949 decreaseAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Decrease"))),
2950 showMenuAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"ShowMenu"))),
2951 setFocusAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"SetFocus"))),
2952 toggleAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Toggle"))),
2953 scrollLeftAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Left"))),
2954 scrollRightAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Right"))),
2955 scrollUpAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Up"))),
2956 scrollDownAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Down"))),
2957 previousPageAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Previous Page"))),
2958 nextPageAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Next Page")))
2961 const QString pressAction;
2962 const QString increaseAction;
2963 const QString decreaseAction;
2964 const QString showMenuAction;
2965 const QString setFocusAction;
2966 const QString toggleAction;
2967 const QString scrollLeftAction;
2968 const QString scrollRightAction;
2969 const QString scrollUpAction;
2970 const QString scrollDownAction;
2971 const QString previousPageAction;
2972 const QString nextPageAction;
2974 QString localizedDescription(
const QString &actionName)
2976 if (actionName == pressAction)
2977 return QAccessibleActionInterface::tr(
"Triggers the action");
2978 else if (actionName == increaseAction)
2979 return QAccessibleActionInterface::tr(
"Increase the value");
2980 else if (actionName == decreaseAction)
2981 return QAccessibleActionInterface::tr(
"Decrease the value");
2982 else if (actionName == showMenuAction)
2983 return QAccessibleActionInterface::tr(
"Shows the menu");
2984 else if (actionName == setFocusAction)
2985 return QAccessibleActionInterface::tr(
"Sets the focus");
2986 else if (actionName == toggleAction)
2987 return QAccessibleActionInterface::tr(
"Toggles the state");
2988 else if (actionName == scrollLeftAction)
2989 return QAccessibleActionInterface::tr(
"Scrolls to the left");
2990 else if (actionName == scrollRightAction)
2991 return QAccessibleActionInterface::tr(
"Scrolls to the right");
2992 else if (actionName == scrollUpAction)
2993 return QAccessibleActionInterface::tr(
"Scrolls up");
2994 else if (actionName == scrollDownAction)
2995 return QAccessibleActionInterface::tr(
"Scrolls down");
2996 else if (actionName == previousPageAction)
2997 return QAccessibleActionInterface::tr(
"Goes back a page");
2998 else if (actionName == nextPageAction)
2999 return QAccessibleActionInterface::tr(
"Goes to the next page");
3006Q_GLOBAL_STATIC(QAccessibleActionStrings, accessibleActionStrings)
3008QString QAccessibleActionInterface::localizedActionName(
const QString &actionName)
const
3010 return QAccessibleActionInterface::tr(qPrintable(actionName));
3013QString QAccessibleActionInterface::localizedActionDescription(
const QString &actionName)
const
3015 return accessibleActionStrings()->localizedDescription(actionName);
3019
3020
3021
3022const QString &QAccessibleActionInterface::pressAction()
3024 return accessibleActionStrings()->pressAction;
3028
3029
3030
3031const QString &QAccessibleActionInterface::increaseAction()
3033 return accessibleActionStrings()->increaseAction;
3037
3038
3039
3040const QString &QAccessibleActionInterface::decreaseAction()
3042 return accessibleActionStrings()->decreaseAction;
3046
3047
3048
3049const QString &QAccessibleActionInterface::showMenuAction()
3051 return accessibleActionStrings()->showMenuAction;
3055
3056
3057
3058const QString &QAccessibleActionInterface::setFocusAction()
3060 return accessibleActionStrings()->setFocusAction;
3064
3065
3066
3067const QString &QAccessibleActionInterface::toggleAction()
3069 return accessibleActionStrings()->toggleAction;
3073
3074
3075
3076QString QAccessibleActionInterface::scrollLeftAction()
3078 return accessibleActionStrings()->scrollLeftAction;
3082
3083
3084
3085QString QAccessibleActionInterface::scrollRightAction()
3087 return accessibleActionStrings()->scrollRightAction;
3091
3092
3093
3094QString QAccessibleActionInterface::scrollUpAction()
3096 return accessibleActionStrings()->scrollUpAction;
3100
3101
3102
3103QString QAccessibleActionInterface::scrollDownAction()
3105 return accessibleActionStrings()->scrollDownAction;
3109
3110
3111
3112QString QAccessibleActionInterface::previousPageAction()
3114 return accessibleActionStrings()->previousPageAction;
3118
3119
3120
3121QString QAccessibleActionInterface::nextPageAction()
3123 return accessibleActionStrings()->nextPageAction;
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3143
3144
3145
3146QAccessibleSelectionInterface::~QAccessibleSelectionInterface()
3151
3152
3153
3154
3157
3158
3159
3160
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175QAccessibleInterface* QAccessibleSelectionInterface::selectedItem(
int selectionIndex)
const
3177 QList<QAccessibleInterface*> items = selectedItems();
3178 if (selectionIndex < 0 || selectionIndex > items.length() -1) {
3179 qCWarning(lcAccessibilityCore) <<
"Selection index" << selectionIndex <<
"out of range.";
3183 return items.at(selectionIndex);
3187
3188
3189
3190
3191
3192bool QAccessibleSelectionInterface::isSelected(QAccessibleInterface *childItem)
const
3194 return selectedItems().contains(childItem);
3198
3199
3200
3201
3202
3203
3204
3205
3208
3209
3210
3211
3212
3213
3216
3217
3218
3219
3220
3221
3224
3225
3226
3227
3228
3229
3230
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3258
3259
3260
3261QAccessibleAttributesInterface::~QAccessibleAttributesInterface()
3266
3267
3268
3269
3270
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3285QString qAccessibleLocalizedActionDescription(
const QString &actionName)
3287 return accessibleActionStrings()->localizedDescription(actionName);
3291
3292
3293
3294
3295
3298
3299
3300
3301
3302
3305
3306
3307
3308
3309
3310
3311
3312
3315
3316
3317
3318
3319
3320
3321
3323QAccessibleHyperlinkInterface::~QAccessibleHyperlinkInterface()
3332#include "moc_qaccessible_base.cpp"
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")