10#include "qpa/qplatformaccessibility.h"
11#include <QtGui/private/qaccessiblebridgeutils_p.h>
15#include "QtGui/qaccessible.h"
16#include <QtCore/qmath.h>
17#include <QtCore/private/qjnihelpers_p.h>
18#include <QtCore/QJniObject>
19#include <QtGui/private/qhighdpiscaling_p.h>
21#include <QtCore/QObject>
22#include <QtCore/qpointer.h>
23#include <QtCore/qscopeguard.h>
24#include <QtCore/qvarlengtharray.h>
32using namespace Qt::StringLiterals;
90 if (m_accessibilityContext)
91 m_accessibilityContext->deleteLater();
92 m_accessibilityContext =
new QObject(parent);
95 template <
typename Func,
typename Ret>
99 __android_log_print(ANDROID_LOG_WARN,
m_qtTag,
100 "Could not run accessibility call in object context, no valid surface.");
104 QtAndroidPrivate::AndroidDeadlockProtector protector(
105 u"QtAndroidAccessibility::runInObjectContext()"_s);
106 if (!protector.acquire()) {
107 __android_log_print(ANDROID_LOG_WARN,
m_qtTag,
108 "Could not run accessibility call in object context, accessing "
109 "main thread could lead to deadlock");
113 if (!QtAndroid::blockEventLoopsWhenSuspended()
114 || QGuiApplication::applicationState() != Qt::ApplicationSuspended) {
115 QMetaObject::invokeMethod(context, func, Qt::BlockingQueuedConnection, retVal);
117 __android_log_print(ANDROID_LOG_WARN,
m_qtTag,
118 "Could not run accessibility call in object context, event loop suspended.");
131 if (!m_accessibilityContext) {
132 __android_log_print(ANDROID_LOG_DEBUG,
m_qtTag,
133 "Accessibility context is not ready, activation deferred.");
137 QMetaObject::invokeMethod(m_accessibilityContext, [active]() {
138 QMutexLocker lock(QtAndroid::platformInterfaceMutex());
141 m_modalInterfaces.clear();
143 auto *platformIntegration = QtAndroid::androidPlatformIntegration();
144 if (!platformIntegration) {
145 __android_log_print(ANDROID_LOG_DEBUG, m_qtTag,
146 "Android platform integration is not ready, accessibility activation deferred.");
149 platformIntegration->accessibility()->setActive(active);
150 }, Qt::QueuedConnection);
155 QAccessibleInterface *iface =
nullptr;
156 if (objectId == -1) {
157 QWindow *win =
qApp->focusWindow();
159 iface = win->accessibleRoot();
161 iface = QAccessible::accessibleInterface(objectId);
168 QtAndroid::notifyAccessibilityLocationChange(accessibilityObjectId);
177 const auto parentObjectId = parentId_helper(accessibilityObjectId);
178 QtAndroid::notifyObjectHide(accessibilityObjectId, parentObjectId);
183 QAccessibleInterface *iface = interfaceFromId(accessibilityObjectId);
184 if (iface && iface->isValid() && iface->state().modal
185 && !m_modalInterfaces.contains(accessibilityObjectId)) {
189 const auto parentObjectId = parentId_helper(accessibilityObjectId);
190 QtAndroid::notifyObjectShow(parentObjectId);
195 QtAndroid::notifyObjectFocus(accessibilityObjectId);
201 QtAndroid::notifyObjectDestroyed(accessibilityObjectId,
202 parentId_helper(accessibilityObjectId));
207 QtAndroid::notifyObjectCreated(parentId_helper(accessibilityObjectId));
212 QtAndroid::notifyValueChanged(accessibilityObjectId);
217 QtAndroid::notifyDescriptionOrNameChanged(accessibilityObjectId);
222 QtAndroid::notifyScrolledEvent(accessiblityObjectId);
227 QtAndroid::notifyAnnouncementEvent(accessibilityObjectId, message);
232 QAccessibleInterface *iface = interfaceFromId(objectId);
233 if (iface && iface->isValid()) {
234 const int childCount = iface->childCount();
235 QVarLengthArray<jint, 8> ifaceIdArray;
236 ifaceIdArray.reserve(childCount);
237 for (
int i = 0; i < childCount; ++i) {
238 QAccessibleInterface *child = iface->child(i);
239 if (child && child->isValid())
240 ifaceIdArray.append(QAccessible::uniqueId(child));
249 if (m_accessibilityContext) {
250 QVarLengthArray<jint, 8> ifaceIdArray;
251 runInObjectContext(m_accessibilityContext, [objectId]() {
252 return childIdListForAccessibleObject_helper(objectId);
254 jintArray jArray = env->NewIntArray(jsize(ifaceIdArray.count()));
255 env->SetIntArrayRegion(jArray, 0, ifaceIdArray.count(), ifaceIdArray.data());
259 return env->NewIntArray(jsize(0));
264 QAccessibleInterface *iface = interfaceFromId(objectId);
265 if (iface && iface->isValid()) {
266 QAccessibleInterface *parent = iface->parent();
267 if (parent && parent->isValid()) {
268 if (parent->role() == QAccessible::Application)
270 return QAccessible::uniqueId(parent);
279 if (m_accessibilityContext) {
280 runInObjectContext(m_accessibilityContext, [objectId]() {
281 return parentId_helper(objectId);
290 QAccessibleInterface *iface = interfaceFromId(objectId);
291 if (iface && iface->isValid()) {
292 rect = QHighDpi::toNativePixels(iface->rect(), iface->window());
295 if (clip && iface && iface->parent() && iface->parent()->isValid()) {
296 const auto parentRect = QHighDpi::toNativePixels(iface->parent()->rect(), iface->parent()->window());
297 rect = rect.intersected(parentRect);
305 if (m_accessibilityContext) {
306 runInObjectContext(m_accessibilityContext, [objectId]() {
307 return screenRect_helper(objectId);
310 jclass rectClass = env->FindClass(
"android/graphics/Rect");
311 jmethodID ctor = env->GetMethodID(rectClass,
"<init>",
"(IIII)V");
312 jobject jrect = env->NewObject(rectClass, ctor, rect.left(), rect.top(), rect.right(), rect.bottom());
318 QAccessibleInterface *root = interfaceFromId(-1);
319 if (root && root->isValid()) {
320 QPoint pos = QHighDpi::fromNativePixels(QPoint(
int(x),
int(y)), root->window());
322 QAccessibleInterface *child = root->childAt(pos.x(), pos.y());
323 QAccessibleInterface *lastChild =
nullptr;
324 while (child && (child != lastChild)) {
326 child = child->childAt(pos.x(), pos.y());
329 return QAccessible::uniqueId(lastChild);
337 if (m_accessibilityContext) {
338 runInObjectContext(m_accessibilityContext, [x, y]() {
339 return hitTest_helper(x, y);
346 const QString& action)
350 QMetaObject::invokeMethod(
qApp, [actionInterface, action]() {
351 actionInterface->doAction(action);
352 }, Qt::QueuedConnection);
357 QAccessibleInterface *iface = interfaceFromId(objectId);
358 if (!iface || !iface->isValid() || !iface->actionInterface())
361 const auto& actionNames = iface->actionInterface()->actionNames();
363 if (actionNames.contains(QAccessibleActionInterface::pressAction())) {
364 invokeActionOnInterfaceInMainThread(iface->actionInterface(),
365 QAccessibleActionInterface::pressAction());
366 }
else if (actionNames.contains(QAccessibleActionInterface::toggleAction())) {
367 invokeActionOnInterfaceInMainThread(iface->actionInterface(),
368 QAccessibleActionInterface::toggleAction());
377 QAccessibleInterface *iface = interfaceFromId(objectId);
378 if (!iface || !iface->isValid() || !iface->actionInterface())
381 const auto& actionNames = iface->actionInterface()->actionNames();
383 if (actionNames.contains(QAccessibleActionInterface::setFocusAction())) {
384 QAccessibleActionInterface *actionInterface = iface->actionInterface();
386 QMetaObject::invokeMethod(
qApp, [actionInterface]() {
387 auto *inputContext = QAndroidInputContext::androidInputContext();
389 inputContext->setAccessibilityFocusInProgress(
true);
390 const auto resetGuard = qScopeGuard([inputContext] {
392 inputContext->setAccessibilityFocusInProgress(
false);
394 actionInterface->doAction(QAccessibleActionInterface::setFocusAction());
395 }, Qt::QueuedConnection);
404 if (m_accessibilityContext) {
405 runInObjectContext(m_accessibilityContext, [objectId]() {
406 return clickAction_helper(objectId);
415 if (m_accessibilityContext) {
416 runInObjectContext(m_accessibilityContext, [objectId]() {
417 return focusAction_helper(objectId);
425 QAccessibleInterface *iface = interfaceFromId(objectId);
426 if (iface && iface->isValid())
427 return QAccessibleBridgeUtils::performEffectiveAction(iface, actionName);
435 const auto& ids = childIdListForAccessibleObject_helper(objectId);
439 const int firstChildId = ids.first();
440 const QRect oldPosition = screenRect_helper(firstChildId,
false);
442 if (m_accessibilityContext) {
443 runInObjectContext(m_accessibilityContext, [objectId]() {
444 return scroll_helper(objectId, QAccessibleActionInterface::increaseAction());
449 return result && oldPosition != screenRect_helper(firstChildId,
false);
456 const auto& ids = childIdListForAccessibleObject_helper(objectId);
460 const int firstChildId = ids.first();
461 const QRect oldPosition = screenRect_helper(firstChildId,
false);
463 if (m_accessibilityContext) {
464 runInObjectContext(m_accessibilityContext, [objectId]() {
465 return scroll_helper(objectId, QAccessibleActionInterface::decreaseAction());
470 return result && oldPosition != screenRect_helper(firstChildId,
false);
475 QAccessibleInterface *iface = interfaceFromId(objectId);
476 if (!iface || !iface->isValid() || !iface->actionInterface())
479 const auto actionNames = iface->actionInterface()->actionNames();
481 if (actionNames.contains(QAccessibleActionInterface::showOnScreenAction())) {
482 invokeActionOnInterfaceInMainThread(iface->actionInterface(), QAccessibleActionInterface::showOnScreenAction());
491 if (m_accessibilityContext) {
492 runInObjectContext(m_accessibilityContext, [objectId]() {
493 return showOnScreen_helper(objectId);
502 if (m_accessibilityContext) {
504 m_accessibilityContext, [objectId]() {
return clickAction_helper(objectId); },
513 if (m_accessibilityContext) {
515 m_accessibilityContext, [objectId]() {
return clickAction_helper(objectId); },
524 QAccessibleValueInterface *valueIface = iface->valueInterface();
526 const QVariant valueVar = valueIface->currentValue();
527 const auto type = valueVar.typeId();
528 if (type == QMetaType::Double || type == QMetaType::Float) {
534 const double val = valueVar.toDouble();
536 bool stepIsValid =
false;
537 const double step = qAbs(valueIface->minimumStepSize().toDouble(&stepIsValid));
538 if (!stepIsValid || qFuzzyIsNull(step)) {
540 valueStr = qFuzzyIsNull(val) ? u"0"_s : QString::number(val,
'f');
542 const int precision = [](
double s) {
544 while (s < 1. && !qFuzzyCompare(s, 1.)) {
551 const int stop = count + 3;
552 const auto fractional = [](
double v) {
554 std::modf(v + 0.5, &whole);
555 return qAbs(v - whole);
558 while (count < stop && !qFuzzyIsNull(s)) {
560 s = fractional(s * 10);
564 valueStr = qFuzzyIsNull(val / step) ? u"0"_s
565 : QString::number(val,
'f', precision);
568 valueStr = valueVar.toString();
576 case QAccessible::Role::Button:
577 case QAccessible::Role::Link:
580 return QStringLiteral(
"android.widget.ToggleButton");
581 return QStringLiteral(
"android.widget.Button");
583 case QAccessible::Role::CheckBox:
586 return QStringLiteral(
"android.widget.CompoundButton");
587 case QAccessible::Role::Switch:
588 return QStringLiteral(
"android.widget.Switch");
589 case QAccessible::Role::Clock:
590 return QStringLiteral(
"android.widget.TextClock");
591 case QAccessible::Role::ComboBox:
592 case QAccessible::Role::ButtonDropDown:
593 return QStringLiteral(
"android.widget.Spinner");
594 case QAccessible::Role::Graphic:
596 return QStringLiteral(
"android.widget.ImageView");
597 case QAccessible::Role::Grouping:
598 return QStringLiteral(
"android.view.ViewGroup");
599 case QAccessible::Role::List:
602 return QStringLiteral(
"android.widget.AbsListView");
603 case QAccessible::Role::MenuItem:
604 return QStringLiteral(
"android.view.MenuItem");
605 case QAccessible::Role::PopupMenu:
606 return QStringLiteral(
"android.widget.PopupMenu");
607 case QAccessible::Role::Separator:
608 return QStringLiteral(
"android.widget.Space");
609 case QAccessible::Role::ToolBar:
610 return QStringLiteral(
"android.view.Toolbar");
611 case QAccessible::Role::Heading: [[fallthrough]];
612 case QAccessible::Role::StaticText:
614 return QStringLiteral(
"android.widget.TextView");
615 case QAccessible::Role::EditableText:
616 return QStringLiteral(
"android.widget.EditText");
617 case QAccessible::Role::RadioButton:
618 return QStringLiteral(
"android.widget.RadioButton");
619 case QAccessible::Role::ProgressBar:
620 return QStringLiteral(
"android.widget.ProgressBar");
621 case QAccessible::Role::SpinBox:
622 return QStringLiteral(
"android.widget.NumberPicker");
623 case QAccessible::Role::WebDocument:
624 return QStringLiteral(
"android.webkit.WebView");
625 case QAccessible::Role::Dialog:
626 return QStringLiteral(
"android.app.AlertDialog");
627 case QAccessible::Role::PageTab:
628 return QStringLiteral(
"android.app.ActionBar.Tab");
629 case QAccessible::Role::PageTabList:
630 return QStringLiteral(
"android.widget.TabWidget");
631 case QAccessible::Role::ScrollBar:
632 return QStringLiteral(
"android.widget.Scroller");
633 case QAccessible::Role::Slider:
634 return QStringLiteral(
"android.widget.SeekBar");
635 case QAccessible::Role::Table:
638 return QStringLiteral(
"android.widget.GridView");
639 case QAccessible::Role::Pane:
641 return QStringLiteral(
"android.view.ViewGroup");
642 case QAccessible::Role::AlertMessage:
643 case QAccessible::Role::Animation:
644 case QAccessible::Role::Application:
645 case QAccessible::Role::Assistant:
646 case QAccessible::Role::BlockQuote:
647 case QAccessible::Role::Border:
648 case QAccessible::Role::ButtonDropGrid:
649 case QAccessible::Role::ButtonMenu:
650 case QAccessible::Role::Canvas:
651 case QAccessible::Role::Caret:
652 case QAccessible::Role::Cell:
653 case QAccessible::Role::Chart:
654 case QAccessible::Role::Client:
655 case QAccessible::Role::ColorChooser:
656 case QAccessible::Role::Column:
657 case QAccessible::Role::ColumnHeader:
658 case QAccessible::Role::ComplementaryContent:
659 case QAccessible::Role::Cursor:
660 case QAccessible::Role::Desktop:
661 case QAccessible::Role::Dial:
662 case QAccessible::Role::Document:
663 case QAccessible::Role::Equation:
664 case QAccessible::Role::Footer:
665 case QAccessible::Role::Form:
666 case QAccessible::Role::Grip:
667 case QAccessible::Role::HelpBalloon:
668 case QAccessible::Role::HotkeyField:
669 case QAccessible::Role::Indicator:
670 case QAccessible::Role::LayeredPane:
671 case QAccessible::Role::ListItem:
672 case QAccessible::Role::MenuBar:
673 case QAccessible::Role::NoRole:
674 case QAccessible::Role::Note:
675 case QAccessible::Role::Notification:
676 case QAccessible::Role::Paragraph:
677 case QAccessible::Role::PropertyPage:
678 case QAccessible::Role::Row:
679 case QAccessible::Role::RowHeader:
680 case QAccessible::Role::Section:
681 case QAccessible::Role::Sound:
682 case QAccessible::Role::Splitter:
683 case QAccessible::Role::StatusBar:
684 case QAccessible::Role::Terminal:
685 case QAccessible::Role::TitleBar:
686 case QAccessible::Role::ToolTip:
687 case QAccessible::Role::Tree:
688 case QAccessible::Role::TreeItem:
689 case QAccessible::Role::UserRole:
690 case QAccessible::Role::Whitespace:
691 case QAccessible::Role::Window:
695 return QStringLiteral(
"android.view.TextView");
701 if (!state.expandable)
710 if (iface && iface->isValid()) {
711 bool hasValue =
false;
712 desc = iface->text(QAccessible::Name);
713 const QString descStr = iface->text(QAccessible::Description);
714 if (!descStr.isEmpty()) {
716 desc.append(QStringLiteral(
", "));
717 desc.append(descStr);
719 if (desc.isEmpty()) {
720 desc = iface->text(QAccessible::Value);
721 hasValue = !desc.isEmpty();
723 if (!hasValue && iface->valueInterface()) {
724 const QString valueStr = textFromValue(iface);
725 if (!valueStr.isEmpty()) {
727 desc.append(QChar(QChar::Space));
728 desc.append(valueStr);
737 QAccessibleInterface *iface = interfaceFromId(objectId);
738 return descriptionForInterface(iface);
744 if (m_accessibilityContext) {
745 runInObjectContext(m_accessibilityContext, [objectId]() {
746 return descriptionForAccessibleObject_helper(objectId);
749 return env->NewString((jchar*) desc.constData(), (jsize) desc.size());
754 QAccessibleInterface *iface = interfaceFromId(objectId);
755 if (!iface || !iface->isValid())
758 QAccessibleAttributesInterface *attributesIface = iface->attributesInterface();
759 if (!attributesIface || !attributesIface->attributeKeys().contains(QAccessible::Attribute::Locale))
762 return attributesIface->attributeValue(QAccessible::Attribute::Locale).toLocale().bcp47Name();
768 if (m_accessibilityContext) {
769 runInObjectContext(m_accessibilityContext, [objectId]() {
770 return languageTag_helper(objectId);
773 return env->NewString((jchar*)tag.constData(), (jsize)tag.size());
777 QAccessibleInterface *iface)
779 if (!iface || !modalInterface)
782 if (iface == modalInterface)
785 return childOfModalInterface(modalInterface, iface->parent());
812 QAccessibleInterface *iface = interfaceFromId(objectId);
813 if (iface && iface->isValid()) {
815 info.state = iface->state();
816 info.role = iface->role();
817 info.actions = QAccessibleBridgeUtils::effectiveActionNames(iface);
818 info.description = descriptionForInterface(iface);
819 info.identifier = QAccessibleBridgeUtils::accessibleId(iface);
820 QAccessibleTextInterface *textIface = iface->textInterface();
821 if (textIface && (textIface->selectionCount() > 0)) {
829 if (info.state.editable) {
831 info.text = textIface->text(0, textIface->characterCount());
832 info.hint = iface->text(QAccessible::Name);
834 QAccessibleValueInterface *valueInterface = iface->valueInterface();
835 if (valueInterface) {
837 info.minValue = valueInterface->minimumValue();
838 info.maxValue = valueInterface->maximumValue();
839 info.currentValue = valueInterface->currentValue();
840 info.valueStepSize = valueInterface->minimumStepSize();
842 if (!m_modalInterfaces.isEmpty()
843 && !childOfModalInterface(interfaceFromId(m_modalInterfaces.last()), iface)) {
853 if (m_accessibilityContext) {
854 runInObjectContext(m_accessibilityContext, [objectId]() {
855 return populateNode_helper(objectId);
859 __android_log_print(ANDROID_LOG_WARN,
m_qtTag,
"Accessibility: populateNode for Invalid ID");
863 const QString role = classNameForRole(info.role, info.state);
864 jstring jrole = env->NewString((jchar*)role.constData(), (jsize)role.size());
865 env->CallVoidMethod(node, m_setClassNameMethodID, jrole);
867 const bool hasClickableAction =
868 (info.actions.contains(QAccessibleActionInterface::pressAction())
869 || info.actions.contains(QAccessibleActionInterface::toggleAction()))
870 && !(info.role == QAccessible::StaticText || info.role == QAccessible::Heading);
871 const bool hasIncreaseAction =
872 info.actions.contains(QAccessibleActionInterface::increaseAction());
873 const bool hasDecreaseAction =
874 info.actions.contains(QAccessibleActionInterface::decreaseAction());
875 const bool scrollableRole =
876 info.role == QAccessible::ScrollBar || info.role == QAccessible::List;
879 env->CallVoidMethod(node, m_setTextSelectionMethodID, info
.selectionStart,
883 if (info
.hasValue && m_setRangeInfoMethodID) {
884 int valueType = info.currentValue.typeId();
887 case QMetaType::Float:
888 case QMetaType::Double:
896 float min = info.minValue.toFloat();
897 float max = info.maxValue.toFloat();
898 float current = info.currentValue.toFloat();
899 if (info.role == QAccessible::ProgressBar) {
901 current = 100 * (current - min) / (max - min);
906 QJniObject rangeInfo(
"android/view/accessibility/AccessibilityNodeInfo$RangeInfo",
907 "(IFFF)V", rangeType, min, max, current);
909 if (rangeInfo.isValid()) {
910 env->CallVoidMethod(node, m_setRangeInfoMethodID, rangeInfo.object());
914 env->CallVoidMethod(node, m_setCheckableMethodID, (
bool)info.state.checkable);
915 env->CallVoidMethod(node, m_setCheckedMethodID, (
bool)info.state.checked);
916 if (QtAndroidPrivate::androidSdkVersion() >= 36) {
917 env->CallVoidMethod(node, m_setExpandedStateMethodID,
918 expandedStateFromState(info.state));
920 env->CallVoidMethod(node, m_setEditableMethodID, info.state.editable);
921 env->CallVoidMethod(node, m_setEnabledMethodID, !info.state.disabled);
922 env->CallVoidMethod(node, m_setFocusableMethodID, (
bool)info.state.focusable);
923 env->CallVoidMethod(node, m_setFocusedMethodID, (
bool)info.state.focused);
925 env->CallVoidMethod(node, m_setHeadingMethodID, info.role == QAccessible::Heading);
926 env->CallVoidMethod(node, m_setVisibleToUserMethodID,
928 env->CallVoidMethod(node, m_setScrollableMethodID,
929 hasIncreaseAction || hasDecreaseAction || scrollableRole);
930 env->CallVoidMethod(node, m_setClickableMethodID, hasClickableAction || info.role == QAccessible::Link);
933 if (hasClickableAction)
934 env->CallVoidMethod(node, m_addActionMethodID, (
int)0x00000010);
937 if (hasIncreaseAction)
938 env->CallVoidMethod(node, m_addActionMethodID, (
int)0x00001000);
941 if (hasDecreaseAction)
942 env->CallVoidMethod(node, m_addActionMethodID, (
int)0x00002000);
945 if (info.state.expandable) {
946 if (info.state.expanded) {
949 env->CallVoidMethod(node, m_addActionMethodID,
ACTION_EXPAND);
954 jstring jdesc = env->NewString((jchar*)info.description.constData(),
955 (jsize)info.description.size());
957 env->CallVoidMethod(node, m_setContentDescriptionMethodID, jdesc);
963 if (info.state.editable) {
965 jstring jtext = env->NewString((jchar*)info.text.constData(),
966 (jsize)info.text.size());
967 env->CallVoidMethod(node, m_setTextMethodID, jtext);
968 env->DeleteLocalRef(jtext);
972 env->CallVoidMethod(node, m_setInputTypeMethodID, (jint)0x00000001);
974 jstring jhint = env->NewString((jchar*)info.hint.constData(),
975 (jsize)info.hint.size());
976 env->CallVoidMethod(node, m_setHintTextMethodID, jhint);
977 env->DeleteLocalRef(jhint);
981 QJniObject(node).callMethod<
void>(
"setViewIdResourceName", info.identifier);
997 QAccessibleInterface *iface = interfaceFromId(objectId);
998 if (!iface || !iface->isValid())
1001 auto *viewportIface = iface->viewportInterface();
1008 info.contentSize = viewportIface->contentSize();
1009 info.position = viewportIface->position();
1010 info.viewportSize = viewportIface->viewportSize();
1018 if (m_accessibilityContext) {
1020 m_accessibilityContext,
1021 [objectId]() {
return populateScrollEvent_helper(objectId); }, &info);
1028 const int itemCount =
std::max(info.contentSize.width(), info.contentSize.height());
1029 env->CallVoidMethod(event, m_setItemCountMethodID, itemCount);
1030 const int fromIndex =
std::max(info.position.x(), info.position.y()) * itemCount;
1031 env->CallVoidMethod(event, m_setFromIndexMethodID, fromIndex);
1032 const int toIndex = fromIndex
1033 +
std::min(info.viewportSize.width(), info.viewportSize.height() * itemCount);
1034 env->CallVoidMethod(event, m_setToIndexMethodID, toIndex);
1037 env->CallVoidMethod(event, m_setScrollXMethodID,
1038 (
int)(info.position.x() * info.contentSize.width()));
1039 env->CallVoidMethod(event, m_setMaxScrollXMethodID, (
int)info.contentSize.width());
1040 env->CallVoidMethod(event, m_setScrollYMethodID,
1041 (
int)(info.position.y() * info.contentSize.height()));
1042 env->CallVoidMethod(event, m_setMaxScrollYMethodID, (
int)info.contentSize.height());
1051 {
"parentId",
"(I)I", (
void*)
parentId},
1055 {
"hitTest",
"(FF)I", (
void*)
hitTest},
1056 {
"populateNode",
"(ILandroid/view/accessibility/AccessibilityNodeInfo;)Z", (
void*)
populateNode},
1057 {
"populateScrollEvent",
"(ILandroid/view/accessibility/AccessibilityEvent;)Z", (
void*)
populateScrollEvent},
1063 {
"expand",
"(I)Z", (
void *)
expand},
1064 {
"collapse",
"(I)Z", (
void *)
collapse}
1067#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE)
1068 VAR = env->GetMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE);
1070 __android_log_print(ANDROID_LOG_FATAL, QtAndroid::qtTagText(), QtAndroid::methodErrorMsgFmt(), METHOD_NAME, METHOD_SIGNATURE);
1074#define CHECK_AND_INIT_STATIC_FIELD(TYPE, VAR, CLASS, FIELD_NAME)
1075 if (env.findStaticField<TYPE>(CLASS, FIELD_NAME) == nullptr) {
1076 __android_log_print(ANDROID_LOG_FATAL, QtAndroid::qtTagText(),
1077 QtAndroid::staticFieldErrorMsgFmt(), FIELD_NAME);
1080 VAR = QJniObject::getStaticField<TYPE>(CLASS, FIELD_NAME);
1084 if (!env.registerNativeMethods(
"org/qtproject/qt/android/QtNativeAccessibility",
1086 __android_log_print(ANDROID_LOG_FATAL,
"Qt A11y",
"RegisterNatives failed");
1090 jclass nodeInfoClass = env->FindClass(
"android/view/accessibility/AccessibilityNodeInfo");
1095 if (QtAndroidPrivate::androidSdkVersion() >= 36) {
1097 "setExpandedState",
"(I)V");
1100 GET_AND_CHECK_STATIC_METHOD(m_setContentDescriptionMethodID, nodeInfoClass,
"setContentDescription",
"(Ljava/lang/CharSequence;)V");
1109 if (QtAndroidPrivate::androidSdkVersion() >= 28) {
1116 m_setRangeInfoMethodID, nodeInfoClass,
"setRangeInfo",
1117 "(Landroid/view/accessibility/AccessibilityNodeInfo$RangeInfo;)V");
1119 jclass eventClass = env->FindClass(
"android/view/accessibility/AccessibilityEvent");
1128 jclass rangeInfoClass =
1129 env->FindClass(
"android/view/accessibility/AccessibilityNodeInfo$RangeInfo");
1133 if (QtAndroidPrivate::androidSdkVersion() >= 36) {
1135 "RANGE_TYPE_INDETERMINATE");
1140 if (QtAndroidPrivate::androidSdkVersion() >= 36) {
1142 "EXPANDED_STATE_UNDEFINED");
1144 "EXPANDED_STATE_COLLAPSED");
1146 "EXPANDED_STATE_FULL");
static const char m_qtTag[]
#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE)
#define CHECK_AND_INIT_STATIC_FIELD(TYPE, VAR, CLASS, FIELD_NAME)
\inmodule QtCore\reentrant
static int ACTION_COLLAPSE
static jmethodID m_setCheckableMethodID
static int RANGE_TYPE_FLOAT
static jboolean showOnScreen(JNIEnv *, jobject, jint objectId)
void notifyDescriptionOrNameChanged(uint accessibilityObjectId)
void notifyObjectShow(uint accessibilityObjectId)
static bool clickAction_helper(int objectId)
static const JNINativeMethod methods[]
void notifyLocationChange(uint accessibilityObjectId)
void runInObjectContext(QObject *context, Func &&func, Ret *retVal)
static jmethodID m_setFocusableMethodID
static std::atomic< bool > m_accessibilityActivated
static jmethodID m_setFocusedMethodID
static int RANGE_TYPE_INDETERMINATE
static jmethodID m_setClassNameMethodID
static jmethodID m_setInputTypeMethodID
static jmethodID m_setEditableMethodID
static jboolean scrollForward(JNIEnv *, jobject, jint objectId)
static ScrollEventInfo populateScrollEvent_helper(int objectId)
void notifyObjectFocus(uint accessibilityObjectId)
static jboolean scrollBackward(JNIEnv *, jobject, jint objectId)
static QString descriptionForInterface(QAccessibleInterface *iface)
static bool showOnScreen_helper(int objectId)
static int hitTest_helper(float x, float y)
static jmethodID m_setEnabledMethodID
static jboolean expand(JNIEnv *, jobject, jint objectId)
static int RANGE_TYPE_PERCENT
static jstring descriptionForAccessibleObject(JNIEnv *env, jobject, jint objectId)
void notifyObjectDestroyed(uint accessibilityObjectId)
static bool scroll_helper(int objectId, const QString &actionName)
static QString classNameForRole(QAccessible::Role role, QAccessible::State state)
static jmethodID m_setContentDescriptionMethodID
static jmethodID m_setFromIndexMethodID
static QString textFromValue(QAccessibleInterface *iface)
static jmethodID m_setTextMethodID
void createAccessibilityContextObject(QObject *parent)
static jmethodID m_setMaxScrollXMethodID
static QVarLengthArray< int, 8 > childIdListForAccessibleObject_helper(int objectId)
static jmethodID m_setClickableMethodID
static int EXPANDED_STATE_COLLAPSED
void notifyObjectCreated(uint accessibilityObjectId)
static NodeInfo populateNode_helper(int objectId)
static jmethodID m_setScrollYMethodID
void notifyObjectHide(uint accessibilityObjectId)
static jboolean focusAction(JNIEnv *, jobject, jint objectId)
static jmethodID m_setExpandedStateMethodID
static QList< QAccessible::Id > m_modalInterfaces
static QString languageTag_helper(int objectId)
static jmethodID m_setVisibleToUserMethodID
static jmethodID m_setScrollableMethodID
static jint hitTest(JNIEnv *, jobject, jfloat x, jfloat y)
static jmethodID m_setRangeInfoMethodID
static jstring languageTag(JNIEnv *env, jobject, jint objectId)
static jmethodID m_addActionMethodID
static bool focusAction_helper(int objectId)
static int EXPANDED_STATE_UNDEFINED
static jboolean clickAction(JNIEnv *, jobject, jint objectId)
static int RANGE_TYPE_INT
static jmethodID m_setCheckedMethodID
static jmethodID m_setScrollXMethodID
static bool childOfModalInterface(QAccessibleInterface *modalInterface, QAccessibleInterface *iface)
static void setActive(JNIEnv *, jobject, jboolean active)
static void invokeActionOnInterfaceInMainThread(QAccessibleActionInterface *actionInterface, const QString &action)
static jmethodID m_setMaxScrollYMethodID
static jmethodID m_setTextSelectionMethodID
bool registerNatives(QJniEnvironment &env)
static int EXPANDED_STATE_FULL
QAccessibleInterface * interfaceFromId(jint objectId)
void notifyValueChanged(uint accessibilityObjectId)
static jboolean populateScrollEvent(JNIEnv *env, jobject, jint objectId, jobject event)
static jmethodID m_setToIndexMethodID
static int expandedStateFromState(QAccessible::State state)
void notifyAnnouncementEvent(uint accessibilityObjectId, const QString &message)
static int parentId_helper(int objectId)
static QRect screenRect_helper(int objectId, bool clip=true)
static jmethodID m_setHeadingMethodID
static jmethodID m_setItemCountMethodID
static QString descriptionForAccessibleObject_helper(int objectId)
static jint parentId(JNIEnv *, jobject, jint objectId)
static jboolean collapse(JNIEnv *, jobject, jint objectId)
static jobject screenRect(JNIEnv *env, jobject, jint objectId)
static jintArray childIdListForAccessibleObject(JNIEnv *env, jobject, jint objectId)
static jmethodID m_setHintTextMethodID
static jboolean populateNode(JNIEnv *env, jobject, jint objectId, jobject node)
void notifyScrolledEvent(uint accessiblityObjectId)