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
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
387
388
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
409
410
411
412
413
414
415
416
417
418
419
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
455
456
457
458
459
460
461
462
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
512#if QT_CONFIG(accessibility)
515
516
517QAccessibleInterface::~QAccessibleInterface()
522
523
524
525
529Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, acLoader,
530 (QAccessibleFactoryInterface_iid,
"/accessible"_L1))
531typedef QHash<QString, QAccessiblePlugin*> QAccessiblePluginsHash;
532Q_GLOBAL_STATIC(QAccessiblePluginsHash, qAccessiblePlugins)
535Q_GLOBAL_STATIC(QList<QAccessible::InterfaceFactory>, qAccessibleFactories)
536Q_GLOBAL_STATIC(QList<QAccessible::ActivationObserver *>, qAccessibleActivationObservers)
538QAccessible::UpdateHandler QAccessible::updateHandler =
nullptr;
539QAccessible::RootObjectHandler QAccessible::rootObjectHandler =
nullptr;
541static bool cleanupAdded =
false;
543static QPlatformAccessibility *platformAccessibility()
545 QPlatformIntegration *pfIntegration = QGuiApplicationPrivate::platformIntegration();
546 return pfIntegration ? pfIntegration->accessibility() :
nullptr;
550
551
552
553
554
555
559
560
561void QAccessible::cleanup()
563 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
564 pfAccessibility->cleanup();
567static void qAccessibleCleanup()
569 qAccessibleActivationObservers()->clear();
570 qAccessibleFactories()->clear();
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
594
595
596
597
598
599
600
601
602
605
606
607
608
609
610
611
612
613
617
618
619
620void QAccessible::installFactory(InterfaceFactory factory)
626 qAddPostRoutine(qAccessibleCleanup);
629 if (qAccessibleFactories()->contains(factory))
631 qAccessibleFactories()->append(factory);
635
636
637void QAccessible::removeFactory(InterfaceFactory factory)
639 qAccessibleFactories()->removeAll(factory);
643
644
645
646
647
648
649QAccessible::UpdateHandler QAccessible::installUpdateHandler(UpdateHandler handler)
651 UpdateHandler old = updateHandler;
652 updateHandler = handler;
657
658
659
660
661
662QAccessible::RootObjectHandler QAccessible::installRootObjectHandler(RootObjectHandler handler)
664 RootObjectHandler old = rootObjectHandler;
665 rootObjectHandler = handler;
670
671
672
673
674
675
677QAccessible::ActivationObserver::~ActivationObserver()
682
683
684
685
686void QAccessible::installActivationObserver(QAccessible::ActivationObserver *observer)
692 qAddPostRoutine(qAccessibleCleanup);
695 if (qAccessibleActivationObservers()->contains(observer))
697 qAccessibleActivationObservers()->append(observer);
701 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
702 pfAccessibility->clearActiveNotificationState();
706
707
708
709
710
711void QAccessible::removeActivationObserver(ActivationObserver *observer)
713 qAccessibleActivationObservers()->removeAll(observer);
717
718
719
720
721void qAccessibleNotifyActivationObservers(
bool active)
723 for (
int i = 0; i < qAccessibleActivationObservers()->size(); ++i)
724 qAccessibleActivationObservers()->at(i)->accessibilityActiveChanged(active);
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745QAccessibleInterface *QAccessible::queryAccessibleInterface(QObject *object)
750 if (Id id = QAccessibleCache::instance()->idForObject(object))
751 return QAccessibleCache::instance()->interfaceForId(id);
755 const QMetaObject *mo = object->metaObject();
756 const auto *objectPriv = QObjectPrivate::get(object);
758
759
760
761
762
763
764
765
766 const bool qmlRelated = !objectPriv->isDeletingChildren &&
767 objectPriv->declarativeData;
768 while (qmlRelated && mo) {
769 auto mop = QMetaObjectPrivate::get(mo);
770 if (!mop || !(mop->flags & DynamicMetaObject))
773 mo = mo->superClass();
776 const QString cn = QLatin1StringView(mo->className());
779 for (
int i = qAccessibleFactories()->size(); i > 0; --i) {
780 InterfaceFactory factory = qAccessibleFactories()->at(i - 1);
781 if (QAccessibleInterface *iface = factory(cn, object)) {
782 QAccessibleCache::instance()->insert(object, iface);
783 Q_ASSERT(QAccessibleCache::instance()->containsObject(object));
789 if (!qAccessiblePlugins()->contains(cn)) {
790 QAccessiblePlugin *factory =
nullptr;
791 const int index = acLoader()->indexOf(cn);
793 factory = qobject_cast<QAccessiblePlugin *>(acLoader()->instance(index));
794 qAccessiblePlugins()->insert(cn, factory);
798 Q_ASSERT(qAccessiblePlugins()->contains(cn));
799 QAccessiblePlugin *factory = qAccessiblePlugins()->value(cn);
801 QAccessibleInterface *result = factory->create(cn, object);
803 QAccessibleCache::instance()->insert(object, result);
804 Q_ASSERT(QAccessibleCache::instance()->containsObject(object));
808 mo = mo->superClass();
811 if (object == qApp) {
812 QAccessibleInterface *appInterface =
new QAccessibleApplication;
813 QAccessibleCache::instance()->insert(object, appInterface);
814 Q_ASSERT(QAccessibleCache::instance()->containsObject(qApp));
822
823
824
825
826
827
828
829
830
831
832
833
834
835QAccessible::Id QAccessible::registerAccessibleInterface(QAccessibleInterface *iface)
838 return QAccessibleCache::instance()->insert(iface->object(), iface);
842
843
844
845
846void QAccessible::deleteAccessibleInterface(Id id)
848 QAccessibleCache::instance()->deleteInterface(id);
852
853
854QAccessible::Id QAccessible::uniqueId(QAccessibleInterface *iface)
856 Id id = QAccessibleCache::instance()->idForInterface(iface);
858 id = registerAccessibleInterface(iface);
863
864
865
866
867QAccessibleInterface *QAccessible::accessibleInterface(Id id)
869 return QAccessibleCache::instance()->interfaceForId(id);
874
875
876
877
878
879
880
881
882
883
884bool QAccessible::isActive()
886 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
887 return pfAccessibility->isActive();
892
893
894void QAccessible::setActive(
bool active)
896 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
897 pfAccessibility->setActive(active);
901
902
903
904
905
906
907
908
909
910
911
912
913
914void QAccessible::setRootObject(QObject *object)
916 if (rootObjectHandler) {
917 rootObjectHandler(object);
921 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
922 pfAccessibility->setRootObject(object);
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944void QAccessible::updateAccessibility(QAccessibleEvent *event)
953 QAccessibleInterface *iface = event->accessibleInterface();
955 if (event->type() == QAccessible::TableModelChanged) {
956 if (iface->tableInterface())
957 iface->tableInterface()->modelChange(
static_cast<QAccessibleTableModelChangeEvent*>(event));
962 updateHandler(event);
966 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
967 pfAccessibility->notifyAccessibilityUpdate(event);
971
972
973
974
975
976
977std::pair<
int,
int > QAccessible::qAccessibleTextBoundaryHelper(
const QTextCursor &offsetCursor, TextBoundaryType boundaryType)
979 Q_ASSERT(!offsetCursor.isNull());
981 QTextCursor endCursor = offsetCursor;
982 endCursor.movePosition(QTextCursor::End);
983 int characterCount = endCursor.position();
985 std::pair<
int,
int> result;
986 QTextCursor cursor = offsetCursor;
987 switch (boundaryType) {
989 result.first = cursor.position();
990 cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
991 result.second = cursor.position();
994 cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
995 result.first = cursor.position();
996 cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
997 result.second = cursor.position();
999 case SentenceBoundary: {
1003 cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
1004 result.first = cursor.position();
1005 cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
1006 result.second = cursor.position();
1007 QString blockText = cursor.selectedText();
1008 const int offsetWithinBlockText = offsetCursor.position() - result.first;
1009 QTextBoundaryFinder sentenceFinder(QTextBoundaryFinder::Sentence, blockText);
1010 sentenceFinder.setPosition(offsetWithinBlockText);
1011 int prevBoundary = offsetWithinBlockText;
1012 int nextBoundary = offsetWithinBlockText;
1013 if (!(sentenceFinder.boundaryReasons() & QTextBoundaryFinder::StartOfItem))
1014 prevBoundary = sentenceFinder.toPreviousBoundary();
1015 nextBoundary = sentenceFinder.toNextBoundary();
1016 if (nextBoundary != -1)
1017 result.second = result.first + nextBoundary;
1018 if (prevBoundary != -1)
1019 result.first += prevBoundary;
1022 cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);
1023 result.first = cursor.position();
1024 cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
1025 result.second = cursor.position();
1027 case ParagraphBoundary:
1028 cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
1029 result.first = cursor.position();
1030 cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
1031 result.second = cursor.position();
1035 result.second = characterCount;
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1134
1135
1136
1137
1138
1139
1140
1141
1144
1145
1146
1147
1148
1149
1150
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1165
1166
1167
1168
1169
1170
1171
1172
1173
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185QList<std::pair<QAccessibleInterface*, QAccessible::Relation>>
1186QAccessibleInterface::relations(QAccessible::Relation match)
const
1193
1194
1195
1196
1197QAccessibleInterface *QAccessibleInterface::focusChild()
const
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1222
1223
1224
1225
1226
1227
1228
1229
1232
1233
1234
1235
1236
1237
1238
1239
1240
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1292
1293
1294
1295
1296
1297
1298
1299
1300
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1316
1317
1318
1319
1320
1321
1322
1323
1324
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1339
1340
1341
1342
1343QColor QAccessibleInterface::foregroundColor()
const
1349
1350
1351
1352
1353QColor QAccessibleInterface::backgroundColor()
const
1359
1360
1363
1364
1365
1368
1369
1372
1373
1376
1377
1380
1381
1384
1385
1386
1389
1390
1391
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1414
1415
1416
1417
1420
1421
1422
1423
1424
1425
1428
1429
1430QAccessibleEvent::~QAccessibleEvent()
1435
1436
1439
1440
1443
1444
1447
1448
1451
1452
1453
1454
1455
1456
1457QAccessible::Id QAccessibleEvent::uniqueId()
const
1461 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
1464 if (m_child != -1) {
1465 iface = iface->child(m_child);
1466 if (Q_UNLIKELY(!iface)) {
1467 qCWarning(lcAccessibilityCore) <<
"Invalid child in QAccessibleEvent:" << m_object <<
"child:" << m_child;
1471 return QAccessible::uniqueId(iface);
1474void QAccessibleEvent::setChild(
int chld)
1476 if (m_type == QAccessible::ObjectDestroyed)
1477 qCWarning(lcAccessibilityCore) <<
"Calling QAccessibleEvent::setChild on ObjectDestroyed event " <<
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1495
1496
1497
1498
1500
1501
1502
1503
1506
1507
1508
1510
1511
1512
1513
1516
1517
1518QAccessibleValueChangeEvent::~QAccessibleValueChangeEvent()
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1535
1536
1537
1538
1540
1541
1542
1543
1544
1545
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1559
1560
1561QAccessibleStateChangeEvent::~QAccessibleStateChangeEvent()
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1579
1580
1581
1582
1583
1584
1585
1586
1588
1589
1590
1592
1593
1594
1596
1597
1598
1600
1601
1602
1604
1605
1606
1608
1609
1610
1612
1613
1614
1616
1617
1618
1620
1621
1622
1624
1625
1626
1628
1629
1630
1632
1633
1634
1635
1636
1638
1639
1640QAccessibleTableModelChangeEvent::~QAccessibleTableModelChangeEvent()
1644
1645
1646
1647
1648
1649
1650
1651
1653
1654
1655
1656
1658
1659
1660
1662
1663
1664
1666
1667
1668QAccessibleTextCursorEvent::~QAccessibleTextCursorEvent()
1674
1675
1676
1677
1678
1681
1682
1683
1684
1685
1686
1687
1688
1690
1691
1692
1693
1694
1695
1696
1698
1699
1700
1702
1703
1704
1706
1707
1708QAccessibleTextInsertEvent::~QAccessibleTextInsertEvent()
1714
1715
1716
1717
1718
1719
1720
1721
1723
1724
1725
1726
1727
1728
1729
1731
1732
1733
1734
1735
1736
1737
1740
1741
1742
1744
1745
1746
1748
1749
1750QAccessibleTextRemoveEvent::~QAccessibleTextRemoveEvent()
1755
1756
1757
1758
1759
1762
1763
1764
1765
1766
1769
1770
1771
1772
1773
1774
1775
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1792
1793
1794
1795
1797
1798
1799
1801
1802
1803
1805
1806
1807
1809
1810
1811QAccessibleTextUpdateEvent::~QAccessibleTextUpdateEvent()
1817
1818
1819
1820
1821
1822
1823
1824
1826
1827
1828
1829
1831
1832
1833
1835
1836
1837
1839
1840
1841
1843
1844
1845QAccessibleTextSelectionEvent::~QAccessibleTextSelectionEvent()
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1862
1863
1864
1865
1866
1867
1868
1871
1872
1873
1874
1875
1876
1877
1880
1881
1882
1885
1886
1887
1890
1891
1892
1896
1897
1898QAccessibleAnnouncementEvent::~QAccessibleAnnouncementEvent()
1903
1904
1905QAccessibleInterface *QAccessibleEvent::accessibleInterface()
const
1907 if (m_object ==
nullptr)
1908 return QAccessible::accessibleInterface(m_uniqueId);
1910 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
1911 if (!iface || !iface->isValid())
1915 QAccessibleInterface *child = iface->child(m_child);
1919 qCWarning(lcAccessibilityCore) <<
"Cannot create accessible child interface for object: " << m_object <<
" index: " << m_child <<
"type: " << m_type;
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938QWindow *QAccessibleInterface::window()
const
1944
1945
1946
1947
1948
1949
1950
1951void QAccessibleInterface::virtual_hook(
int ,
void * )
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1972const char *qAccessibleRoleString(QAccessible::Role role)
1974 if (role >= QAccessible::UserRole)
1975 role = QAccessible::UserRole;
1976 static int roleEnum = QAccessible::staticMetaObject.indexOfEnumerator(
"Role");
1977 return QAccessible::staticMetaObject.enumerator(roleEnum).valueToKey(role);
1981const char *qAccessibleEventString(QAccessible::Event event)
1983 static int eventEnum = QAccessible::staticMetaObject.indexOfEnumerator(
"Event");
1984 return QAccessible::staticMetaObject.enumerator(eventEnum).valueToKey(event);
1987#ifndef QT_NO_DEBUG_STREAM
1989Q_GUI_EXPORT QDebug operator<<(QDebug d,
const QAccessibleInterface *iface)
1991 QDebugStateSaver saver(d);
1993 return d <<
"QAccessibleInterface(0x0)";
1996 d <<
"QAccessibleInterface(" << Qt::hex << (
const void *) iface << Qt::dec;
1997 if (iface->isValid()) {
1998 d <<
" name=" << iface->text(QAccessible::Name) <<
' ';
1999 d <<
"role=" << qAccessibleRoleString(iface->role()) <<
' ';
2000 if (iface->childCount())
2001 d <<
"childc=" << iface->childCount() <<
' ';
2002 if (iface->object()) {
2003 d <<
"obj=" << iface->object();
2005 QStringList stateStrings;
2006 QAccessible::State st = iface->state();
2008 stateStrings << u"focusable"_s;
2010 stateStrings << u"focused"_s;
2012 stateStrings << u"selected"_s;
2014 stateStrings << u"invisible"_s;
2016 if (!stateStrings.isEmpty())
2017 d << stateStrings.join(u'|');
2020 d <<
"rect=" << iface->rect();
2030QDebug operator<<(QDebug d,
const QAccessibleEvent &ev)
2032 QDebugStateSaver saver(d);
2033 d.nospace() <<
"QAccessibleEvent(";
2035 d.nospace() <<
"object=" << Qt::hex << ev.object() << Qt::dec;
2036 d.nospace() <<
"child=" << ev.child();
2038 d.nospace() <<
"no object, uniqueId=" << ev.uniqueId();
2040 d <<
" event=" << qAccessibleEventString(ev.type());
2041 if (ev.type() == QAccessible::StateChanged) {
2042 QAccessible::State changed =
static_cast<
const QAccessibleStateChangeEvent*>(&ev)->changedStates();
2043 d <<
"State changed:";
2044 if (changed.disabled) d <<
"disabled";
2045 if (changed.selected) d <<
"selected";
2046 if (changed.focusable) d <<
"focusable";
2047 if (changed.focused) d <<
"focused";
2048 if (changed.pressed) d <<
"pressed";
2049 if (changed.checkable) d <<
"checkable";
2050 if (changed.checked) d <<
"checked";
2051 if (changed.checkStateMixed) d <<
"checkStateMixed";
2052 if (changed.readOnly) d <<
"readOnly";
2053 if (changed.hotTracked) d <<
"hotTracked";
2054 if (changed.defaultButton) d <<
"defaultButton";
2055 if (changed.expanded) d <<
"expanded";
2056 if (changed.collapsed) d <<
"collapsed";
2057 if (changed.busy) d <<
"busy";
2058 if (changed.expandable) d <<
"expandable";
2059 if (changed.marqueed) d <<
"marqueed";
2060 if (changed.animated) d <<
"animated";
2061 if (changed.invisible) d <<
"invisible";
2062 if (changed.offscreen) d <<
"offscreen";
2063 if (changed.sizeable) d <<
"sizeable";
2064 if (changed.movable) d <<
"movable";
2065 if (changed.selfVoicing) d <<
"selfVoicing";
2066 if (changed.selectable) d <<
"selectable";
2067 if (changed.linked) d <<
"linked";
2068 if (changed.traversed) d <<
"traversed";
2069 if (changed.multiSelectable) d <<
"multiSelectable";
2070 if (changed.extSelectable) d <<
"extSelectable";
2071 if (changed.passwordEdit) d <<
"passwordEdit";
2072 if (changed.hasPopup) d <<
"hasPopup";
2073 if (changed.modal) d <<
"modal";
2077 if (changed.active) d <<
"active";
2078 if (changed.invalid) d <<
"invalid";
2079 if (changed.editable) d <<
"editable";
2080 if (changed.multiLine) d <<
"multiLine";
2081 if (changed.selectableText) d <<
"selectableText";
2082 if (changed.supportsAutoCompletion) d <<
"supportsAutoCompletion";
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2110
2111
2112
2113QAccessibleTextInterface::~QAccessibleTextInterface()
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2131
2132
2133
2134
2135
2138
2139
2140
2141
2144
2145
2146
2147
2150
2151
2152
2153
2156
2157
2158
2159
2162
2163
2164
2165
2166
2167
2168
2169
2172
2173
2174
2175
2176
2177
2180
2181
2182
2183
2184static QString textLineBoundary(
int beforeAtAfter,
const QString &text,
int offset,
int *startOffset,
int *endOffset)
2186 Q_ASSERT(beforeAtAfter >= -1 && beforeAtAfter <= 1);
2187 Q_ASSERT(*startOffset == -1 && *endOffset == -1);
2188 int length = text.size();
2189 Q_ASSERT(offset >= 0 && offset <= length);
2192 if (beforeAtAfter == 1) {
2193 offset = text.indexOf(QChar::LineFeed, qMin(offset, length - 1));
2197 }
else if (beforeAtAfter == -1) {
2198 offset = text.lastIndexOf(QChar::LineFeed, qMax(offset - 1, 0));
2204 *startOffset = text.lastIndexOf(QChar::LineFeed, offset - 1);
2207 *endOffset = text.indexOf(QChar::LineFeed, qMin(offset, length - 1)) + 1;
2208 if (*endOffset <= 0 || *endOffset > length)
2209 *endOffset = length;
2211 return text.mid(*startOffset, *endOffset - *startOffset);
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231QString QAccessibleTextInterface::textBeforeOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2232 int *startOffset,
int *endOffset)
const
2234 const QString txt = text(0, characterCount());
2237 offset = txt.size();
2239 *startOffset = *endOffset = -1;
2240 if (txt.isEmpty() || offset <= 0 || offset > txt.size())
2244 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2245 switch (boundaryType) {
2246 case QAccessible::CharBoundary:
2247 type = QTextBoundaryFinder::Grapheme;
2249 case QAccessible::WordBoundary:
2250 type = QTextBoundaryFinder::Word;
2252 case QAccessible::SentenceBoundary:
2253 type = QTextBoundaryFinder::Sentence;
2255 case QAccessible::LineBoundary:
2256 case QAccessible::ParagraphBoundary:
2258 return textLineBoundary(-1, txt, offset, startOffset, endOffset);
2259 case QAccessible::NoBoundary:
2268 QTextBoundaryFinder boundary(type, txt);
2269 boundary.setPosition(offset);
2272 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2274 }
while (boundary.toPreviousBoundary() > 0);
2275 Q_ASSERT(boundary.position() >= 0);
2276 *endOffset = boundary.position();
2278 while (boundary.toPreviousBoundary() > 0) {
2279 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2282 Q_ASSERT(boundary.position() >= 0);
2283 *startOffset = boundary.position();
2285 return txt.mid(*startOffset, *endOffset - *startOffset);
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305QString QAccessibleTextInterface::textAfterOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2306 int *startOffset,
int *endOffset)
const
2308 const QString txt = text(0, characterCount());
2311 offset = txt.size();
2313 *startOffset = *endOffset = -1;
2314 if (txt.isEmpty() || offset < 0 || offset >= txt.size())
2318 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2319 switch (boundaryType) {
2320 case QAccessible::CharBoundary:
2321 type = QTextBoundaryFinder::Grapheme;
2323 case QAccessible::WordBoundary:
2324 type = QTextBoundaryFinder::Word;
2326 case QAccessible::SentenceBoundary:
2327 type = QTextBoundaryFinder::Sentence;
2329 case QAccessible::LineBoundary:
2330 case QAccessible::ParagraphBoundary:
2332 return textLineBoundary(1, txt, offset, startOffset, endOffset);
2333 case QAccessible::NoBoundary:
2342 QTextBoundaryFinder boundary(type, txt);
2343 boundary.setPosition(offset);
2346 int toNext = boundary.toNextBoundary();
2347 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2349 if (toNext < 0 || toNext >= txt.size())
2352 Q_ASSERT(boundary.position() <= txt.size());
2353 *startOffset = boundary.position();
2356 int toNext = boundary.toNextBoundary();
2357 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2359 if (toNext < 0 || toNext >= txt.size())
2362 Q_ASSERT(boundary.position() <= txt.size());
2363 *endOffset = boundary.position();
2365 if ((*startOffset == -1) || (*endOffset == -1) || (*startOffset == *endOffset)) {
2370 return txt.mid(*startOffset, *endOffset - *startOffset);
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390QString QAccessibleTextInterface::textAtOffset(
int offset, QAccessible::TextBoundaryType boundaryType,
2391 int *startOffset,
int *endOffset)
const
2393 const QString txt = text(0, characterCount());
2396 offset = txt.size();
2398 *startOffset = *endOffset = -1;
2399 if (txt.isEmpty() || offset < 0 || offset > txt.size())
2402 if (offset == txt.size() && boundaryType == QAccessible::CharBoundary)
2406 QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2407 switch (boundaryType) {
2408 case QAccessible::CharBoundary:
2409 type = QTextBoundaryFinder::Grapheme;
2411 case QAccessible::WordBoundary:
2412 type = QTextBoundaryFinder::Word;
2414 case QAccessible::SentenceBoundary:
2415 type = QTextBoundaryFinder::Sentence;
2417 case QAccessible::LineBoundary:
2418 case QAccessible::ParagraphBoundary:
2420 return textLineBoundary(0, txt, offset, startOffset, endOffset);
2421 case QAccessible::NoBoundary:
2423 *endOffset = txt.size();
2431 QTextBoundaryFinder boundary(type, txt);
2432 boundary.setPosition(offset);
2435 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2437 }
while (boundary.toPreviousBoundary() > 0);
2438 Q_ASSERT(boundary.position() >= 0);
2439 *startOffset = boundary.position();
2441 while (boundary.toNextBoundary() < txt.size()) {
2442 if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2445 Q_ASSERT(boundary.position() <= txt.size());
2446 *endOffset = boundary.position();
2448 return txt.mid(*startOffset, *endOffset - *startOffset);
2452
2453
2454
2455
2458
2459
2460
2461
2464
2465
2466
2467
2468
2469
2472
2473
2474
2475
2478
2479
2480
2481
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2498
2499
2500
2501QAccessibleEditableTextInterface::~QAccessibleEditableTextInterface()
2506
2507
2508
2509
2512
2513
2514
2515
2518
2519
2520
2521
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2542
2543
2544
2545QAccessibleValueInterface::~QAccessibleValueInterface()
2550
2551
2552
2553
2554
2557
2558
2559
2560
2561
2562
2563
2566
2567
2568
2569
2570
2573
2574
2575
2576
2577
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2606
2607
2608QAccessibleImageInterface::~QAccessibleImageInterface()
2613
2614
2615
2616
2617
2618
2619
2620
2621
2624
2625
2626
2627QAccessibleTableCellInterface::~QAccessibleTableCellInterface()
2632
2633
2634
2635
2638
2639
2640
2641
2644
2645
2646
2647
2650
2651
2652
2653
2656
2657
2658
2659
2662
2663
2664
2665
2668
2669
2670
2671
2674
2675
2676
2677
2681
2682
2683
2684
2685
2686
2687
2688
2689
2692
2693
2694
2695QAccessibleTableInterface::~QAccessibleTableInterface()
2700
2701
2702
2703
2706
2707
2708
2709
2712
2713
2714
2715
2718
2719
2720
2721
2724
2725
2726
2727
2730
2731
2732
2733
2736
2737
2738
2739
2742
2743
2744
2745
2748
2749
2750
2751
2754
2755
2756
2757
2760
2761
2762
2763
2766
2767
2768
2769
2772
2773
2774
2775
2776
2779
2780
2781
2782
2785
2786
2787
2788
2791
2792
2793
2794
2795
2798
2799
2800
2801
2802
2805
2806
2807
2808
2809
2812
2813
2814
2815
2816
2819
2820
2821
2822
2823
2824
2828
2829
2830
2831
2832
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
2868
2869
2870
2871QAccessibleActionInterface::~QAccessibleActionInterface()
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2907
2908
2909
2910
2911
2912
2913
2914
2915
2918
2919
2920
2921
2922
2923
2924
2925
2926
2929
2930
2931
2932
2933
2934
2935
2936
2939struct QAccessibleActionStrings
2941 QAccessibleActionStrings() :
2942 pressAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Press"))),
2943 increaseAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Increase"))),
2944 decreaseAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Decrease"))),
2945 showMenuAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"ShowMenu"))),
2946 setFocusAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"SetFocus"))),
2947 toggleAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Toggle"))),
2948 scrollLeftAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Left"))),
2949 scrollRightAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Right"))),
2950 scrollUpAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Up"))),
2951 scrollDownAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Scroll Down"))),
2952 previousPageAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Previous Page"))),
2953 nextPageAction(QStringLiteral(QT_TRANSLATE_NOOP(
"QAccessibleActionInterface",
"Next Page")))
2956 const QString pressAction;
2957 const QString increaseAction;
2958 const QString decreaseAction;
2959 const QString showMenuAction;
2960 const QString setFocusAction;
2961 const QString toggleAction;
2962 const QString scrollLeftAction;
2963 const QString scrollRightAction;
2964 const QString scrollUpAction;
2965 const QString scrollDownAction;
2966 const QString previousPageAction;
2967 const QString nextPageAction;
2969 QString localizedDescription(
const QString &actionName)
2971 if (actionName == pressAction)
2972 return QAccessibleActionInterface::tr(
"Triggers the action");
2973 else if (actionName == increaseAction)
2974 return QAccessibleActionInterface::tr(
"Increase the value");
2975 else if (actionName == decreaseAction)
2976 return QAccessibleActionInterface::tr(
"Decrease the value");
2977 else if (actionName == showMenuAction)
2978 return QAccessibleActionInterface::tr(
"Shows the menu");
2979 else if (actionName == setFocusAction)
2980 return QAccessibleActionInterface::tr(
"Sets the focus");
2981 else if (actionName == toggleAction)
2982 return QAccessibleActionInterface::tr(
"Toggles the state");
2983 else if (actionName == scrollLeftAction)
2984 return QAccessibleActionInterface::tr(
"Scrolls to the left");
2985 else if (actionName == scrollRightAction)
2986 return QAccessibleActionInterface::tr(
"Scrolls to the right");
2987 else if (actionName == scrollUpAction)
2988 return QAccessibleActionInterface::tr(
"Scrolls up");
2989 else if (actionName == scrollDownAction)
2990 return QAccessibleActionInterface::tr(
"Scrolls down");
2991 else if (actionName == previousPageAction)
2992 return QAccessibleActionInterface::tr(
"Goes back a page");
2993 else if (actionName == nextPageAction)
2994 return QAccessibleActionInterface::tr(
"Goes to the next page");
3001Q_GLOBAL_STATIC(QAccessibleActionStrings, accessibleActionStrings)
3003QString QAccessibleActionInterface::localizedActionName(
const QString &actionName)
const
3005 return QAccessibleActionInterface::tr(qPrintable(actionName));
3008QString QAccessibleActionInterface::localizedActionDescription(
const QString &actionName)
const
3010 return accessibleActionStrings()->localizedDescription(actionName);
3014
3015
3016
3017const QString &QAccessibleActionInterface::pressAction()
3019 return accessibleActionStrings()->pressAction;
3023
3024
3025
3026const QString &QAccessibleActionInterface::increaseAction()
3028 return accessibleActionStrings()->increaseAction;
3032
3033
3034
3035const QString &QAccessibleActionInterface::decreaseAction()
3037 return accessibleActionStrings()->decreaseAction;
3041
3042
3043
3044const QString &QAccessibleActionInterface::showMenuAction()
3046 return accessibleActionStrings()->showMenuAction;
3050
3051
3052
3053const QString &QAccessibleActionInterface::setFocusAction()
3055 return accessibleActionStrings()->setFocusAction;
3059
3060
3061
3062const QString &QAccessibleActionInterface::toggleAction()
3064 return accessibleActionStrings()->toggleAction;
3068
3069
3070
3071QString QAccessibleActionInterface::scrollLeftAction()
3073 return accessibleActionStrings()->scrollLeftAction;
3077
3078
3079
3080QString QAccessibleActionInterface::scrollRightAction()
3082 return accessibleActionStrings()->scrollRightAction;
3086
3087
3088
3089QString QAccessibleActionInterface::scrollUpAction()
3091 return accessibleActionStrings()->scrollUpAction;
3095
3096
3097
3098QString QAccessibleActionInterface::scrollDownAction()
3100 return accessibleActionStrings()->scrollDownAction;
3104
3105
3106
3107QString QAccessibleActionInterface::previousPageAction()
3109 return accessibleActionStrings()->previousPageAction;
3113
3114
3115
3116QString QAccessibleActionInterface::nextPageAction()
3118 return accessibleActionStrings()->nextPageAction;
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3138
3139
3140
3141QAccessibleSelectionInterface::~QAccessibleSelectionInterface()
3146
3147
3148
3149
3152
3153
3154
3155
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170QAccessibleInterface* QAccessibleSelectionInterface::selectedItem(
int selectionIndex)
const
3172 QList<QAccessibleInterface*> items = selectedItems();
3173 if (selectionIndex < 0 || selectionIndex > items.length() -1) {
3174 qCWarning(lcAccessibilityCore) <<
"Selection index" << selectionIndex <<
"out of range.";
3178 return items.at(selectionIndex);
3182
3183
3184
3185
3186
3187bool QAccessibleSelectionInterface::isSelected(QAccessibleInterface *childItem)
const
3189 return selectedItems().contains(childItem);
3193
3194
3195
3196
3197
3198
3199
3200
3203
3204
3205
3206
3207
3208
3211
3212
3213
3214
3215
3216
3219
3220
3221
3222
3223
3224
3225
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3253
3254
3255
3256QAccessibleAttributesInterface::~QAccessibleAttributesInterface()
3261
3262
3263
3264
3265
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3280QString qAccessibleLocalizedActionDescription(
const QString &actionName)
3282 return accessibleActionStrings()->localizedDescription(actionName);
3286
3287
3288
3289
3290
3293
3294
3295
3296
3297
3300
3301
3302
3303
3304
3305
3306
3307
3310
3311
3312
3313
3314
3315
3316
3318QAccessibleHyperlinkInterface::~QAccessibleHyperlinkInterface()
3327#include "moc_qaccessible_base.cpp"
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")