11#include <QtCore/qtextboundaryfinder.h>
12#include <QtGui/qclipboard.h>
13#include <QtGui/qguiapplication.h>
14#include <QtGui/qtextcursor.h>
15#include <private/qguiapplication_p.h>
16#include <qpa/qplatformaccessibility.h>
17#include <qpa/qplatformintegration.h>
19#include <QtCore/qdebug.h>
20#include <QtCore/qloggingcategory.h>
21#include <QtCore/qmetaobject.h>
22#include <QtCore/private/qmetaobject_p.h>
23#include <QtCore/qhash.h>
24#include <private/qfactoryloader_p.h>
28using namespace Qt::StringLiterals;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
162
163
164
165
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
412
413
414
415
416
417
418
419
420
421
422
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
531#if QT_CONFIG(accessibility)
534
535
536QAccessibleInterface::~QAccessibleInterface()
541
542
543
544
548Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, acLoader,
549 (QAccessibleFactoryInterface_iid,
"/accessible"_L1))
550typedef QHash<QString, QAccessiblePlugin*> QAccessiblePluginsHash;
551Q_GLOBAL_STATIC(QAccessiblePluginsHash, qAccessiblePlugins)
554Q_GLOBAL_STATIC(QList<QAccessible::InterfaceFactory>, qAccessibleFactories)
555Q_GLOBAL_STATIC(QList<QAccessible::ActivationObserver *>, qAccessibleActivationObservers)
557QAccessible::UpdateHandler QAccessible::updateHandler =
nullptr;
558QAccessible::RootObjectHandler QAccessible::rootObjectHandler =
nullptr;
560static bool cleanupAdded =
false;
562static QPlatformAccessibility *platformAccessibility()
564 QPlatformIntegration *pfIntegration = QGuiApplicationPrivate::platformIntegration();
565 return pfIntegration ? pfIntegration->accessibility() :
nullptr;
569
570
571
572
573
574
578
579
580void QAccessible::cleanup()
582 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
583 pfAccessibility->cleanup();
586static void qAccessibleCleanup()
588 qAccessibleActivationObservers()->clear();
589 qAccessibleFactories()->clear();
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
613
614
615
616
617
618
619
620
621
624
625
626
627
628
629
630
631
632
636
637
638
639void QAccessible::installFactory(InterfaceFactory factory)
645 qAddPostRoutine(qAccessibleCleanup);
648 if (qAccessibleFactories()->contains(factory))
650 qAccessibleFactories()->append(factory);
654
655
656void QAccessible::removeFactory(InterfaceFactory factory)
658 qAccessibleFactories()->removeAll(factory);
662
663
664
665
666
667
668QAccessible::UpdateHandler QAccessible::installUpdateHandler(UpdateHandler handler)
670 UpdateHandler old = updateHandler;
671 updateHandler = handler;
676
677
678
679
680
681QAccessible::RootObjectHandler QAccessible::installRootObjectHandler(RootObjectHandler handler)
683 RootObjectHandler old = rootObjectHandler;
684 rootObjectHandler = handler;
689
690
691
692
693
694
696QAccessible::ActivationObserver::~ActivationObserver()
701
702
703
704
705void QAccessible::installActivationObserver(QAccessible::ActivationObserver *observer)
711 qAddPostRoutine(qAccessibleCleanup);
714 if (qAccessibleActivationObservers()->contains(observer))
716 qAccessibleActivationObservers()->append(observer);
720 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
721 pfAccessibility->clearActiveNotificationState();
725
726
727
728
729
730void QAccessible::removeActivationObserver(ActivationObserver *observer)
732 qAccessibleActivationObservers()->removeAll(observer);
736
737
738
739
740void qAccessibleNotifyActivationObservers(
bool active)
742 for (
int i = 0; i < qAccessibleActivationObservers()->size(); ++i)
743 qAccessibleActivationObservers()->at(i)->accessibilityActiveChanged(active);
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764QAccessibleInterface *QAccessible::queryAccessibleInterface(QObject *object)
769 if (Id id = QAccessibleCache::instance()->idForObject(object))
770 return QAccessibleCache::instance()->interfaceForId(id);
774 const QMetaObject *mo = object->metaObject();
775 const auto *objectPriv = QObjectPrivate::get(object);
777
778
779
780
781
782
783
784
785 const bool qmlRelated = !objectPriv->isDeletingChildren &&
786 objectPriv->declarativeData;
787 while (qmlRelated && mo) {
788 auto mop = QMetaObjectPrivate::get(mo);
789 if (!mop || !(mop->flags & DynamicMetaObject))
792 mo = mo->superClass();
795 const QString cn = QLatin1StringView(mo->className());
798 for (
int i = qAccessibleFactories()->size(); i > 0; --i) {
799 InterfaceFactory factory = qAccessibleFactories()->at(i - 1);
800 if (QAccessibleInterface *iface = factory(cn, object)) {
801 QAccessibleCache::instance()->insert(object, iface);
802 Q_ASSERT(QAccessibleCache::instance()->containsObject(object));
808 if (!qAccessiblePlugins()->contains(cn)) {
809 QAccessiblePlugin *factory =
nullptr;
810 const int index = acLoader()->indexOf(cn);
812 factory = qobject_cast<QAccessiblePlugin *>(acLoader()->instance(index));
813 qAccessiblePlugins()->insert(cn, factory);
817 Q_ASSERT(qAccessiblePlugins()->contains(cn));
818 QAccessiblePlugin *factory = qAccessiblePlugins()->value(cn);
820 QAccessibleInterface *result = factory->create(cn, object);
822 QAccessibleCache::instance()->insert(object, result);
823 Q_ASSERT(QAccessibleCache::instance()->containsObject(object));
827 mo = mo->superClass();
830 if (object == qApp) {
831 QAccessibleInterface *appInterface =
new QAccessibleApplication;
832 QAccessibleCache::instance()->insert(object, appInterface);
833 Q_ASSERT(QAccessibleCache::instance()->containsObject(qApp));
841
842
843
844
845
846
847
848
849
850
851
852
853
854QAccessible::Id QAccessible::registerAccessibleInterface(QAccessibleInterface *iface)
857 return QAccessibleCache::instance()->insert(iface->object(), iface);
861
862
863
864
865void QAccessible::deleteAccessibleInterface(Id id)
867 QAccessibleCache::instance()->deleteInterface(id);
871
872
873QAccessible::Id QAccessible::uniqueId(QAccessibleInterface *iface)
875 Id id = QAccessibleCache::instance()->idForInterface(iface);
877 id = registerAccessibleInterface(iface);
882
883
884
885
886QAccessibleInterface *QAccessible::accessibleInterface(Id id)
888 return QAccessibleCache::instance()->interfaceForId(id);
893
894
895
896
897
898
899
900
901
902
903bool QAccessible::isActive()
905 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
906 return pfAccessibility->isActive();
911
912
913void QAccessible::setActive(
bool active)
915 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
916 pfAccessibility->setActive(active);
920
921
922
923
924
925
926
927
928
929
930
931
932
933void QAccessible::setRootObject(QObject *object)
935 if (rootObjectHandler) {
936 rootObjectHandler(object);
940 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
941 pfAccessibility->setRootObject(object);
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963void QAccessible::updateAccessibility(QAccessibleEvent *event)
972 QAccessibleInterface *iface = event->accessibleInterface();
974 if (event->type() == QAccessible::TableModelChanged) {
975 if (iface->tableInterface())
976 iface->tableInterface()->modelChange(
static_cast<QAccessibleTableModelChangeEvent*>(event));
981 updateHandler(event);
985 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
986 pfAccessibility->notifyAccessibilityUpdate(event);
989static std::pair<
int,
int> qAccessibleTextBoundaryHelperHelper(QTextCursor &cursor,
990 QTextCursor::MoveOperation start,
991 QTextCursor::MoveOperation end)
993 std::pair<
int,
int> result;
994 cursor.movePosition(start, QTextCursor::MoveAnchor);
995 result.first = cursor.position();
996 cursor.movePosition(end, QTextCursor::KeepAnchor);
997 result.second = cursor.position();
1002
1003
1004
1005
1006
1007
1008std::pair<
int,
int > QAccessible::qAccessibleTextBoundaryHelper(
const QTextCursor &offsetCursor, TextBoundaryType boundaryType)
1010 Q_ASSERT(!offsetCursor.isNull());
1012 QTextCursor cursor = offsetCursor;
1013 switch (boundaryType) {
1015 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::NoMove,
1016 QTextCursor::NextCharacter);
1018 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::StartOfWord,
1019 QTextCursor::EndOfWord);
1020 case SentenceBoundary: {
1024 std::pair<
int,
int> result = qAccessibleTextBoundaryHelperHelper(
1025 cursor, QTextCursor::StartOfBlock, QTextCursor::EndOfBlock);
1026 QString blockText = cursor.selectedText();
1027 const int offsetWithinBlockText = offsetCursor.position() - result.first;
1028 QTextBoundaryFinder sentenceFinder(QTextBoundaryFinder::Sentence, blockText);
1029 sentenceFinder.setPosition(offsetWithinBlockText);
1030 int prevBoundary = offsetWithinBlockText;
1031 int nextBoundary = offsetWithinBlockText;
1032 if (!(sentenceFinder.boundaryReasons() & QTextBoundaryFinder::StartOfItem))
1033 prevBoundary = sentenceFinder.toPreviousBoundary();
1034 nextBoundary = sentenceFinder.toNextBoundary();
1035 if (nextBoundary != -1)
1036 result.second = result.first + nextBoundary;
1037 if (prevBoundary != -1)
1038 result.first += prevBoundary;
1042 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::StartOfLine,
1043 QTextCursor::EndOfLine);
1044 case ParagraphBoundary:
1045 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::StartOfBlock,
1046 QTextCursor::EndOfBlock);
1048 return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::Start, QTextCursor::End);
1051 Q_UNREACHABLE_RETURN({});
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1149
1150
1151
1152
1153
1154
1155
1156
1159
1160
1161
1162
1163
1164
1165
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1180
1181
1182
1183
1184
1185
1186
1187
1188
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200QList<std::pair<QAccessibleInterface*, QAccessible::Relation>>
1201QAccessibleInterface::relations(QAccessible::Relation match)
const
1208
1209
1210
1211
1212QAccessibleInterface *QAccessibleInterface::focusChild()
const
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1237
1238
1239
1240
1241
1242
1243
1244
1247
1248
1249
1250
1251
1252
1253
1254
1255
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1307
1308
1309
1310
1311
1312
1313
1314
1315
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1331
1332
1333
1334
1335
1336
1337
1338
1339
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1354
1355
1356
1357
1358QColor QAccessibleInterface::foregroundColor()
const
1364
1365
1366
1367
1368QColor QAccessibleInterface::backgroundColor()
const
1374
1375
1378
1379
1380
1383
1384
1387
1388
1391
1392
1395
1396
1399
1400
1401
1404
1405
1406
1409
1410
1411
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1434
1435
1436
1437
1440
1441
1442
1443
1444
1445
1448
1449
1450QAccessibleEvent::~QAccessibleEvent()
1455
1456
1459
1460
1463
1464
1467
1468
1471
1472
1473
1474
1475
1476
1477QAccessible::Id QAccessibleEvent::uniqueId()
const
1481 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
1484 if (m_child != -1) {
1485 iface = iface->child(m_child);
1486 if (Q_UNLIKELY(!iface)) {
1487 qCWarning(lcAccessibilityCore) <<
"Invalid child in QAccessibleEvent:" << m_object <<
"child:" << m_child;
1491 return QAccessible::uniqueId(iface);
1494void QAccessibleEvent::setChild(
int chld)
1496 if (m_type == QAccessible::ObjectDestroyed)
1497 qCWarning(lcAccessibilityCore) <<
"Calling QAccessibleEvent::setChild on ObjectDestroyed event " <<
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1515
1516
1517
1518
1520
1521
1522
1523
1526
1527
1528
1530
1531
1532
1533
1536
1537
1538QAccessibleValueChangeEvent::~QAccessibleValueChangeEvent()
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1555
1556
1557
1558
1560
1561
1562
1563
1564
1565
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1579
1580
1581QAccessibleStateChangeEvent::~QAccessibleStateChangeEvent()
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1599
1600
1601
1602
1603
1604
1605
1606
1608
1609
1610
1612
1613
1614
1616
1617
1618
1620
1621
1622
1624
1625
1626
1628
1629
1630
1632
1633
1634
1636
1637
1638
1640
1641
1642
1644
1645
1646
1648
1649
1650
1652
1653
1654
1655
1656
1658
1659
1660QAccessibleTableModelChangeEvent::~QAccessibleTableModelChangeEvent()
1664
1665
1666
1667
1668
1669
1670
1671
1673
1674
1675
1676
1678
1679
1680
1682
1683
1684
1686
1687
1688QAccessibleTextCursorEvent::~QAccessibleTextCursorEvent()
1694
1695
1696
1697
1698
1701
1702
1703
1704
1705
1706
1707
1708
1710
1711
1712
1713
1714
1715
1716
1718
1719
1720
1722
1723
1724
1726
1727
1728QAccessibleTextInsertEvent::~QAccessibleTextInsertEvent()
1734
1735
1736
1737
1738
1739
1740
1741
1743
1744
1745
1746
1747
1748
1749
1751
1752
1753
1754
1755
1756
1757
1760
1761
1762
1764
1765
1766
1768
1769
1770QAccessibleTextRemoveEvent::~QAccessibleTextRemoveEvent()
1775
1776
1777
1778
1779
1782
1783
1784
1785
1786
1789
1790
1791
1792
1793
1794
1795
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1812
1813
1814
1815
1817
1818
1819
1821
1822
1823
1825
1826
1827
1829
1830
1831QAccessibleTextUpdateEvent::~QAccessibleTextUpdateEvent()
1837
1838
1839
1840
1841
1842
1843
1844
1846
1847
1848
1849
1851
1852
1853
1855
1856
1857
1859
1860
1861
1863
1864
1865QAccessibleTextSelectionEvent::~QAccessibleTextSelectionEvent()
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1882
1883
1884
1885
1886
1887
1888
1891
1892
1893
1894
1895
1896
1897
1900
1901
1902
1905
1906
1907
1910
1911
1912
1916
1917
1918QAccessibleAnnouncementEvent::~QAccessibleAnnouncementEvent()
1923
1924
1925QAccessibleInterface *QAccessibleEvent::accessibleInterface()
const
1927 if (m_object ==
nullptr)
1928 return QAccessible::accessibleInterface(m_uniqueId);
1930 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
1931 if (!iface || !iface->isValid())
1935 QAccessibleInterface *child = iface->child(m_child);
1939 qCWarning(lcAccessibilityCore) <<
"Cannot create accessible child interface for object: " << m_object <<
" index: " << m_child <<
"type: " << m_type;
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958QWindow *QAccessibleInterface::window()
const
1964
1965
1966
1967
1968
1969
1970
1971void QAccessibleInterface::virtual_hook(
int ,
void * )
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1993const char *qAccessibleRoleString(QAccessible::Role role)
1995 if (role >= QAccessible::UserRole)
1996 role = QAccessible::UserRole;
1997 static int roleEnum = QAccessible::staticMetaObject.indexOfEnumerator(
"Role");
1998 return QAccessible::staticMetaObject.enumerator(roleEnum).valueToKey(role);
2002const char *qAccessibleEventString(QAccessible::Event event)
2004 static int eventEnum = QAccessible::staticMetaObject.indexOfEnumerator(
"Event");
2005 return QAccessible::staticMetaObject.enumerator(eventEnum).valueToKey(event);
2008#ifndef QT_NO_DEBUG_STREAM
2009static void qAccessiblePrintInterface(QDebug d,
const QAccessibleInterface *iface)
2012 d <<
"QAccessibleInterface(0x0)";
2016 d <<
"QAccessibleInterface(" << Qt::hex << (
const void *) iface << Qt::dec;
2017 if (iface->isValid()) {
2018 d <<
" name=" << iface->text(QAccessible::Name);
2019 d <<
" role=" << qAccessibleRoleString(iface->role());
2020 if (iface->childCount())
2021 d <<
" childc=" << iface->childCount();
2022 if (iface->object()) {
2023 d <<
" obj=" << iface->object();
2025 QStringList stateStrings;
2026 QAccessible::State st = iface->state();
2028 stateStrings << u"focusable"_s;
2030 stateStrings << u"focused"_s;
2032 stateStrings << u"selected"_s;
2034 stateStrings << u"invisible"_s;
2036 if (!stateStrings.isEmpty())
2037 d <<
' ' << qUtf8Printable(stateStrings.join(u'|'));
2040 d <<
" rect=" << iface->rect();
2048static void qAccessiblePrintInterface(QDebug d,
const QAccessibleInterface *iface,
2049 const QByteArray &prefix)
2051 qAccessiblePrintInterface(d, iface);
2053 if (d.verbosity() <= QDebug::DefaultVerbosity || !iface || !iface->isValid())
2056 const int childCount = iface->childCount();
2057 for (
int i = 0; i < childCount; ++i) {
2058 const bool isLastChild = i == childCount - 1;
2059 d <<
'\n' << prefix.constData() << (isLastChild ?
"└─ " :
"├─ ");
2060 qAccessiblePrintInterface(d, iface->child(i),
2061 prefix + (isLastChild ?
" " :
"│ "));
2066
2067
2068
2069
2070
2071
2072Q_GUI_EXPORT QDebug operator<<(QDebug d,
const QAccessibleInterface *iface)
2074 QDebugStateSaver saver(d);
2076 qAccessiblePrintInterface(d, iface, QByteArray());
2081QDebug operator<<(QDebug d,
const QAccessibleEvent &ev)
2083 QDebugStateSaver saver(d);
2084 d.nospace() <<
"QAccessibleEvent(";
2086 d.nospace() <<
"object=" << Qt::hex << ev.object() << Qt::dec;
2087 d.nospace() <<
"child=" << ev.child();
2089 d.nospace() <<
"no object, uniqueId=" << ev.uniqueId();
2091 d <<
" event=" << qAccessibleEventString(ev.type());
2092 if (ev.type() == QAccessible::StateChanged) {
2093 QAccessible::State changed =
static_cast<
const QAccessibleStateChangeEvent*>(&ev)->changedStates();
2094 d <<
"State changed:";
2095 if (changed.disabled) d <<
"disabled";
2096 if (changed.selected) d <<
"selected";
2097 if (changed.focusable) d <<
"focusable";
2098 if (changed.focused) d <<
"focused";
2099 if (changed.pressed) d <<
"pressed";
2100 if (changed.checkable) d <<
"checkable";
2101 if (changed.checked) d <<
"checked";
2102 if (changed.checkStateMixed) d <<
"checkStateMixed";
2103 if (changed.readOnly) d <<
"readOnly";
2104 if (changed.hotTracked) d <<
"hotTracked";
2105 if (changed.defaultButton) d <<
"defaultButton";
2106 if (changed.expanded) d <<
"expanded";
2107 if (changed.collapsed) d <<
"collapsed";
2108 if (changed.busy) d <<
"busy";
2109 if (changed.expandable) d <<
"expandable";
2110 if (changed.marqueed) d <<
"marqueed";
2111 if (changed.animated) d <<
"animated";
2112 if (changed.invisible) d <<
"invisible";
2113 if (changed.offscreen) d <<
"offscreen";
2114 if (changed.sizeable) d <<
"sizeable";
2115 if (changed.movable) d <<
"movable";
2116 if (changed.selfVoicing) d <<
"selfVoicing";
2117 if (changed.selectable) d <<
"selectable";
2118 if (changed.linked) d <<
"linked";
2119 if (changed.traversed) d <<
"traversed";
2120 if (changed.multiSelectable) d <<
"multiSelectable";
2121 if (changed.extSelectable) d <<
"extSelectable";
2122 if (changed.passwordEdit) d <<
"passwordEdit";
2123 if (changed.hasPopup) d <<
"hasPopup";
2124 if (changed.modal) d <<
"modal";
2128 if (changed.active) d <<
"active";
2129 if (changed.invalid) d <<
"invalid";
2130 if (changed.editable) d <<
"editable";
2131 if (changed.multiLine) d <<
"multiLine";
2132 if (changed.selectableText) d <<
"selectableText";
2133 if (changed.supportsAutoCompletion) d <<
"supportsAutoCompletion";
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2161
2162
2163
2164QAccessibleTextInterface::~QAccessibleTextInterface()
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2182
2183
2184
2185
2186
2189
2190
2191
2192
2195
2196
2197
2198
2201
2202
2203
2204
2207
2208
2209
2210
2213
2214
2215
2216
2217
2218
2219
2220
2223
2224
2225
2226
2227
2228
2231
2232
2233
2234
2235static QString textLineBoundary(
int beforeAtAfter,
const QString &text,
int offset,
int *startOffset,
int *endOffset)
2237 Q_ASSERT(beforeAtAfter >= -1 && beforeAtAfter <= 1);
2238 Q_ASSERT(*startOffset == -1 && *endOffset == -1);
2239 int length = text.size();
2240 Q_ASSERT(offset >= 0 && offset <= length);
2243 if (beforeAtAfter == 1) {
2244 offset = text.indexOf(QChar::LineFeed, qMin(offset, length - 1));
2248 }
else if (beforeAtAfter == -1) {
2249 offset = text.lastIndexOf(QChar::LineFeed, qMax(offset - 1, 0));
2255 *startOffset = text.lastIndexOf(QChar::LineFeed, offset - 1);
2258 *endOffset = text.indexOf(QChar::LineFeed, qMin(offset, length - 1)) + 1;
2259 if (*endOffset <= 0 || *endOffset > length)
2260 *endOffset = length;
2262 return text.mid(*startOffset, *endOffset - *startOffset);
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282QString QAccessibleTextInterface::textBeforeOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2283 int *startOffset,
int *endOffset)
const
2285 const QString txt = text(0, characterCount());
2288 offset = txt.size();
2290 *startOffset = *endOffset = -1;
2291 if (txt.isEmpty() || offset <= 0 || offset > txt.size())
2295 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2296 switch (boundaryType) {
2297 case QAccessible::CharBoundary:
2298 type = QTextBoundaryFinder::Grapheme;
2300 case QAccessible::WordBoundary:
2301 type = QTextBoundaryFinder::Word;
2303 case QAccessible::SentenceBoundary:
2304 type = QTextBoundaryFinder::Sentence;
2306 case QAccessible::LineBoundary:
2307 case QAccessible::ParagraphBoundary:
2309 return textLineBoundary(-1, txt, offset, startOffset, endOffset);
2310 case QAccessible::NoBoundary:
2319 QTextBoundaryFinder boundary(type, txt);
2320 boundary.setPosition(offset);
2323 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2325 }
while (boundary.toPreviousBoundary() > 0);
2326 Q_ASSERT(boundary.position() >= 0);
2327 const int endPos = boundary.position();
2329 while (boundary.toPreviousBoundary() > 0) {
2330 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2333 if (boundary.position() < 0)
2336 *endOffset = endPos;
2337 *startOffset = boundary.position();
2339 return txt.mid(*startOffset, *endOffset - *startOffset);
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359QString QAccessibleTextInterface::textAfterOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2360 int *startOffset,
int *endOffset)
const
2362 const QString txt = text(0, characterCount());
2365 offset = txt.size();
2367 *startOffset = *endOffset = -1;
2368 if (txt.isEmpty() || offset < 0 || offset >= txt.size())
2372 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2373 switch (boundaryType) {
2374 case QAccessible::CharBoundary:
2375 type = QTextBoundaryFinder::Grapheme;
2377 case QAccessible::WordBoundary:
2378 type = QTextBoundaryFinder::Word;
2380 case QAccessible::SentenceBoundary:
2381 type = QTextBoundaryFinder::Sentence;
2383 case QAccessible::LineBoundary:
2384 case QAccessible::ParagraphBoundary:
2386 return textLineBoundary(1, txt, offset, startOffset, endOffset);
2387 case QAccessible::NoBoundary:
2396 QTextBoundaryFinder boundary(type, txt);
2397 boundary.setPosition(offset);
2400 int toNext = boundary.toNextBoundary();
2401 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2403 if (toNext < 0 || toNext >= txt.size())
2406 Q_ASSERT(boundary.position() <= txt.size());
2407 *startOffset = boundary.position();
2410 int toNext = boundary.toNextBoundary();
2411 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2413 if (toNext < 0 || toNext >= txt.size())
2416 Q_ASSERT(boundary.position() <= txt.size());
2417 *endOffset = boundary.position();
2419 if ((*startOffset == -1) || (*endOffset == -1) || (*startOffset == *endOffset)) {
2424 return txt.mid(*startOffset, *endOffset - *startOffset);
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444QString QAccessibleTextInterface::textAtOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2445 int *startOffset,
int *endOffset)
const
2447 const QString txt = text(0, characterCount());
2450 offset = txt.size();
2452 *startOffset = *endOffset = -1;
2453 if (txt.isEmpty() || offset < 0 || offset > txt.size())
2456 if (offset == txt.size() && boundaryType == QAccessible::CharBoundary)
2460 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2461 switch (boundaryType) {
2462 case QAccessible::CharBoundary:
2463 type = QTextBoundaryFinder::Grapheme;
2465 case QAccessible::WordBoundary:
2466 type = QTextBoundaryFinder::Word;
2468 case QAccessible::SentenceBoundary:
2469 type = QTextBoundaryFinder::Sentence;
2471 case QAccessible::LineBoundary:
2472 case QAccessible::ParagraphBoundary:
2474 return textLineBoundary(0, txt, offset, startOffset, endOffset);
2475 case QAccessible::NoBoundary:
2477 *endOffset = txt.size();
2485 QTextBoundaryFinder boundary(type, txt);
2486 boundary.setPosition(offset);
2489 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2491 }
while (boundary.toPreviousBoundary() > 0);
2492 Q_ASSERT(boundary.position() >= 0);
2493 const int startPos = boundary.position();
2495 while (boundary.toNextBoundary() < txt.size()) {
2496 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2498 if (boundary.position() == -1)
2502 Q_ASSERT(boundary.position() <= txt.size());
2503 *startOffset = startPos;
2504 *endOffset = boundary.position();
2506 return txt.mid(*startOffset, *endOffset - *startOffset);
2510
2511
2512
2513
2516
2517
2518
2519
2522
2523
2524
2525
2526
2527
2530
2531
2532
2533
2536
2537
2538
2539
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2556
2557
2558
2559QAccessibleEditableTextInterface::~QAccessibleEditableTextInterface()
2564
2565
2566
2567
2570
2571
2572
2573
2576
2577
2578
2579
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2600
2601
2602
2603QAccessibleValueInterface::~QAccessibleValueInterface()
2608
2609
2610
2611
2612
2615
2616
2617
2618
2619
2620
2621
2624
2625
2626
2627
2628
2631
2632
2633
2634
2635
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2664
2665
2666QAccessibleImageInterface::~QAccessibleImageInterface()
2671
2672
2673
2674
2675
2676
2677
2678
2679
2682
2683
2684
2685QAccessibleTableCellInterface::~QAccessibleTableCellInterface()
2690
2691
2692
2693
2696
2697
2698
2699
2702
2703
2704
2705
2708
2709
2710
2711
2714
2715
2716
2717
2720
2721
2722
2723
2726
2727
2728
2729
2732
2733
2734
2735
2739
2740
2741
2742
2743
2744
2745
2746
2747
2750
2751
2752
2753QAccessibleTableInterface::~QAccessibleTableInterface()
2758
2759
2760
2761
2764
2765
2766
2767
2770
2771
2772
2773
2776
2777
2778
2779
2782
2783
2784
2785
2788
2789
2790
2791
2794
2795
2796
2797
2800
2801
2802
2803
2806
2807
2808
2809
2812
2813
2814
2815
2818
2819
2820
2821
2824
2825
2826
2827
2830
2831
2832
2833
2834
2837
2838
2839
2840
2843
2844
2845
2846
2849
2850
2851
2852
2853
2856
2857
2858
2859
2860
2863
2864
2865
2866
2867
2870
2871
2872
2873
2874
2877
2878
2879
2880
2881
2882
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2927
2928
2929
2930QAccessibleActionInterface::~QAccessibleActionInterface()
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2966
2967
2968
2969
2970
2971
2972
2973
2974
2977
2978
2979
2980
2981
2982
2983
2984
2985
2988
2989
2990
2991
2992
2993
2994
2995
2998struct QAccessibleActionStrings
3000 QAccessibleActionStrings() :
3001 pressAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Press"))),
3002 increaseAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Increase"))),
3003 decreaseAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Decrease"))),
3004 showMenuAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Show Menu"))),
3005 setFocusAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Set Focus"))),
3006 showOnScreenAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Show on Screen"))),
3007 toggleAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Toggle"))),
3008 scrollLeftAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Left"))),
3009 scrollRightAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Right"))),
3010 scrollUpAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Up"))),
3011 scrollDownAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Down"))),
3012 previousPageAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Previous Page"))),
3013 nextPageAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Next Page")))
3016 const QString pressAction;
3017 const QString increaseAction;
3018 const QString decreaseAction;
3019 const QString showMenuAction;
3020 const QString setFocusAction;
3021 const QString showOnScreenAction;
3022 const QString toggleAction;
3023 const QString scrollLeftAction;
3024 const QString scrollRightAction;
3025 const QString scrollUpAction;
3026 const QString scrollDownAction;
3027 const QString previousPageAction;
3028 const QString nextPageAction;
3030 QString localizedDescription(
const QString &actionName)
3032 if (actionName == pressAction)
3033 return QAccessibleActionInterface::tr(
"Triggers the action");
3034 else if (actionName == increaseAction)
3035 return QAccessibleActionInterface::tr(
"Increase the value");
3036 else if (actionName == decreaseAction)
3037 return QAccessibleActionInterface::tr(
"Decrease the value");
3038 else if (actionName == showMenuAction)
3039 return QAccessibleActionInterface::tr(
"Shows the menu");
3040 else if (actionName == setFocusAction)
3041 return QAccessibleActionInterface::tr(
"Sets the focus");
3042 else if (actionName == showOnScreenAction)
3043 return QAccessibleActionInterface::tr(
"Moves the element into the visible area");
3044 else if (actionName == toggleAction)
3045 return QAccessibleActionInterface::tr(
"Toggles the state");
3046 else if (actionName == scrollLeftAction)
3047 return QAccessibleActionInterface::tr(
"Scrolls to the left");
3048 else if (actionName == scrollRightAction)
3049 return QAccessibleActionInterface::tr(
"Scrolls to the right");
3050 else if (actionName == scrollUpAction)
3051 return QAccessibleActionInterface::tr(
"Scrolls up");
3052 else if (actionName == scrollDownAction)
3053 return QAccessibleActionInterface::tr(
"Scrolls down");
3054 else if (actionName == previousPageAction)
3055 return QAccessibleActionInterface::tr(
"Goes back a page");
3056 else if (actionName == nextPageAction)
3057 return QAccessibleActionInterface::tr(
"Goes to the next page");
3064Q_GLOBAL_STATIC(QAccessibleActionStrings, accessibleActionStrings)
3066QString QAccessibleActionInterface::localizedActionName(
const QString &actionName)
const
3068 return QAccessibleActionInterface::tr(qPrintable(actionName));
3071QString QAccessibleActionInterface::localizedActionDescription(
const QString &actionName)
const
3073 return accessibleActionStrings()->localizedDescription(actionName);
3077
3078
3079
3080const QString &QAccessibleActionInterface::pressAction()
3082 return accessibleActionStrings()->pressAction;
3086
3087
3088
3089const QString &QAccessibleActionInterface::increaseAction()
3091 return accessibleActionStrings()->increaseAction;
3095
3096
3097
3098const QString &QAccessibleActionInterface::decreaseAction()
3100 return accessibleActionStrings()->decreaseAction;
3104
3105
3106
3107const QString &QAccessibleActionInterface::showMenuAction()
3109 return accessibleActionStrings()->showMenuAction;
3113
3114
3115
3116const QString &QAccessibleActionInterface::setFocusAction()
3118 return accessibleActionStrings()->setFocusAction;
3122
3123
3124
3125const QString &QAccessibleActionInterface::showOnScreenAction()
3127 return accessibleActionStrings()->showOnScreenAction;
3131
3132
3133
3134const QString &QAccessibleActionInterface::toggleAction()
3136 return accessibleActionStrings()->toggleAction;
3140
3141
3142
3143QString QAccessibleActionInterface::scrollLeftAction()
3145 return accessibleActionStrings()->scrollLeftAction;
3149
3150
3151
3152QString QAccessibleActionInterface::scrollRightAction()
3154 return accessibleActionStrings()->scrollRightAction;
3158
3159
3160
3161QString QAccessibleActionInterface::scrollUpAction()
3163 return accessibleActionStrings()->scrollUpAction;
3167
3168
3169
3170QString QAccessibleActionInterface::scrollDownAction()
3172 return accessibleActionStrings()->scrollDownAction;
3176
3177
3178
3179QString QAccessibleActionInterface::previousPageAction()
3181 return accessibleActionStrings()->previousPageAction;
3185
3186
3187
3188QString QAccessibleActionInterface::nextPageAction()
3190 return accessibleActionStrings()->nextPageAction;
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3210
3211
3212
3213QAccessibleSelectionInterface::~QAccessibleSelectionInterface()
3218
3219
3220
3221
3224
3225
3226
3227
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242QAccessibleInterface* QAccessibleSelectionInterface::selectedItem(
int selectionIndex)
const
3244 QList<QAccessibleInterface*> items = selectedItems();
3245 if (selectionIndex < 0 || selectionIndex > items.length() -1) {
3246 qCWarning(lcAccessibilityCore) <<
"Selection index" << selectionIndex <<
"out of range.";
3250 return items.at(selectionIndex);
3254
3255
3256
3257
3258
3259bool QAccessibleSelectionInterface::isSelected(QAccessibleInterface *childItem)
const
3261 return selectedItems().contains(childItem);
3265
3266
3267
3268
3269
3270
3271
3272
3275
3276
3277
3278
3279
3280
3283
3284
3285
3286
3287
3288
3291
3292
3293
3294
3295
3296
3297
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3325
3326
3327
3328QAccessibleAttributesInterface::~QAccessibleAttributesInterface()
3333
3334
3335
3336
3337
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3352QString qAccessibleLocalizedActionDescription(
const QString &actionName)
3354 return accessibleActionStrings()->localizedDescription(actionName);
3358
3359
3360
3361
3362
3365
3366
3367
3368
3369
3372
3373
3374
3375
3376
3377
3378
3379
3382
3383
3384
3385
3386
3387
3388
3390QAccessibleHyperlinkInterface::~QAccessibleHyperlinkInterface()
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3409
3410
3411
3412QAccessibleViewportInterface::~QAccessibleViewportInterface()
3417
3418
3419
3420
3421
3422
3425
3426
3427
3428
3431
3432
3433
3434
3437
3438
3439
3440
3443
3444
3445
3446
3452#include "moc_qaccessible_base.cpp"
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)