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;
88 if (m_accessibilityContext)
89 m_accessibilityContext->deleteLater();
90 m_accessibilityContext =
new QObject(parent);
93 template <
typename Func,
typename Ret>
97 __android_log_print(ANDROID_LOG_WARN,
m_qtTag,
98 "Could not run accessibility call in object context, no valid surface.");
102 QtAndroidPrivate::AndroidDeadlockProtector protector(
103 u"QtAndroidAccessibility::runInObjectContext()"_s);
104 if (!protector.acquire()) {
105 __android_log_print(ANDROID_LOG_WARN,
m_qtTag,
106 "Could not run accessibility call in object context, accessing "
107 "main thread could lead to deadlock");
111 if (!QtAndroid::blockEventLoopsWhenSuspended()
112 || QGuiApplication::applicationState() != Qt::ApplicationSuspended) {
113 QMetaObject::invokeMethod(context, func, Qt::BlockingQueuedConnection, retVal);
115 __android_log_print(ANDROID_LOG_WARN,
m_qtTag,
116 "Could not run accessibility call in object context, event loop suspended.");
129 if (!m_accessibilityContext) {
130 __android_log_print(ANDROID_LOG_DEBUG,
m_qtTag,
131 "Accessibility context is not ready, activation deferred.");
135 QMetaObject::invokeMethod(m_accessibilityContext, [active]() {
136 QMutexLocker lock(QtAndroid::platformInterfaceMutex());
137 auto *platformIntegration = QtAndroid::androidPlatformIntegration();
138 if (!platformIntegration) {
139 __android_log_print(ANDROID_LOG_DEBUG, m_qtTag,
140 "Android platform integration is not ready, accessibility activation deferred.");
143 platformIntegration->accessibility()->setActive(active);
144 }, Qt::QueuedConnection);
149 QAccessibleInterface *iface =
nullptr;
150 if (objectId == -1) {
151 QWindow *win =
qApp->focusWindow();
153 iface = win->accessibleRoot();
155 iface = QAccessible::accessibleInterface(objectId);
162 QtAndroid::notifyAccessibilityLocationChange(accessibilityObjectId);
169 const auto parentObjectId = parentId_helper(accessibilityObjectId);
170 QtAndroid::notifyObjectHide(accessibilityObjectId, parentObjectId);
175 const auto parentObjectId = parentId_helper(accessibilityObjectId);
176 QtAndroid::notifyObjectShow(parentObjectId);
181 QtAndroid::notifyObjectFocus(accessibilityObjectId);
186 QtAndroid::notifyObjectDestroyed(accessibilityObjectId,
187 parentId_helper(accessibilityObjectId));
192 QtAndroid::notifyObjectCreated(parentId_helper(accessibilityObjectId));
197 QtAndroid::notifyValueChanged(accessibilityObjectId);
202 QtAndroid::notifyDescriptionOrNameChanged(accessibilityObjectId);
207 QtAndroid::notifyScrolledEvent(accessiblityObjectId);
212 QtAndroid::notifyAnnouncementEvent(accessibilityObjectId, message);
217 QAccessibleInterface *iface = interfaceFromId(objectId);
218 if (iface && iface->isValid()) {
219 const int childCount = iface->childCount();
220 QVarLengthArray<jint, 8> ifaceIdArray;
221 ifaceIdArray.reserve(childCount);
222 for (
int i = 0; i < childCount; ++i) {
223 QAccessibleInterface *child = iface->child(i);
224 if (child && child->isValid())
225 ifaceIdArray.append(QAccessible::uniqueId(child));
234 if (m_accessibilityContext) {
235 QVarLengthArray<jint, 8> ifaceIdArray;
236 runInObjectContext(m_accessibilityContext, [objectId]() {
237 return childIdListForAccessibleObject_helper(objectId);
239 jintArray jArray = env->NewIntArray(jsize(ifaceIdArray.count()));
240 env->SetIntArrayRegion(jArray, 0, ifaceIdArray.count(), ifaceIdArray.data());
244 return env->NewIntArray(jsize(0));
249 QAccessibleInterface *iface = interfaceFromId(objectId);
250 if (iface && iface->isValid()) {
251 QAccessibleInterface *parent = iface->parent();
252 if (parent && parent->isValid()) {
253 if (parent->role() == QAccessible::Application)
255 return QAccessible::uniqueId(parent);
264 if (m_accessibilityContext) {
265 runInObjectContext(m_accessibilityContext, [objectId]() {
266 return parentId_helper(objectId);
275 QAccessibleInterface *iface = interfaceFromId(objectId);
276 if (iface && iface->isValid()) {
277 rect = QHighDpi::toNativePixels(iface->rect(), iface->window());
280 if (clip && iface && iface->parent() && iface->parent()->isValid()) {
281 const auto parentRect = QHighDpi::toNativePixels(iface->parent()->rect(), iface->parent()->window());
282 rect = rect.intersected(parentRect);
290 if (m_accessibilityContext) {
291 runInObjectContext(m_accessibilityContext, [objectId]() {
292 return screenRect_helper(objectId);
295 jclass rectClass = env->FindClass(
"android/graphics/Rect");
296 jmethodID ctor = env->GetMethodID(rectClass,
"<init>",
"(IIII)V");
297 jobject jrect = env->NewObject(rectClass, ctor, rect.left(), rect.top(), rect.right(), rect.bottom());
303 QAccessibleInterface *root = interfaceFromId(-1);
304 if (root && root->isValid()) {
305 QPoint pos = QHighDpi::fromNativePixels(QPoint(
int(x),
int(y)), root->window());
307 QAccessibleInterface *child = root->childAt(pos.x(), pos.y());
308 QAccessibleInterface *lastChild =
nullptr;
309 while (child && (child != lastChild)) {
311 child = child->childAt(pos.x(), pos.y());
314 return QAccessible::uniqueId(lastChild);
322 if (m_accessibilityContext) {
323 runInObjectContext(m_accessibilityContext, [x, y]() {
324 return hitTest_helper(x, y);
331 const QString& action)
335 QMetaObject::invokeMethod(
qApp, [actionInterface, action]() {
336 actionInterface->doAction(action);
337 }, Qt::QueuedConnection);
342 QAccessibleInterface *iface = interfaceFromId(objectId);
343 if (!iface || !iface->isValid() || !iface->actionInterface())
346 const auto& actionNames = iface->actionInterface()->actionNames();
348 if (actionNames.contains(QAccessibleActionInterface::pressAction())) {
349 invokeActionOnInterfaceInMainThread(iface->actionInterface(),
350 QAccessibleActionInterface::pressAction());
351 }
else if (actionNames.contains(QAccessibleActionInterface::toggleAction())) {
352 invokeActionOnInterfaceInMainThread(iface->actionInterface(),
353 QAccessibleActionInterface::toggleAction());
362 QAccessibleInterface *iface = interfaceFromId(objectId);
363 if (!iface || !iface->isValid() || !iface->actionInterface())
366 const auto& actionNames = iface->actionInterface()->actionNames();
368 if (actionNames.contains(QAccessibleActionInterface::setFocusAction())) {
369 QAccessibleActionInterface *actionInterface = iface->actionInterface();
371 QMetaObject::invokeMethod(
qApp, [actionInterface]() {
372 auto *inputContext = QAndroidInputContext::androidInputContext();
374 inputContext->setAccessibilityFocusInProgress(
true);
375 const auto resetGuard = qScopeGuard([inputContext] {
377 inputContext->setAccessibilityFocusInProgress(
false);
379 actionInterface->doAction(QAccessibleActionInterface::setFocusAction());
380 }, Qt::QueuedConnection);
389 if (m_accessibilityContext) {
390 runInObjectContext(m_accessibilityContext, [objectId]() {
391 return clickAction_helper(objectId);
400 if (m_accessibilityContext) {
401 runInObjectContext(m_accessibilityContext, [objectId]() {
402 return focusAction_helper(objectId);
410 QAccessibleInterface *iface = interfaceFromId(objectId);
411 if (iface && iface->isValid())
412 return QAccessibleBridgeUtils::performEffectiveAction(iface, actionName);
420 const auto& ids = childIdListForAccessibleObject_helper(objectId);
424 const int firstChildId = ids.first();
425 const QRect oldPosition = screenRect_helper(firstChildId,
false);
427 if (m_accessibilityContext) {
428 runInObjectContext(m_accessibilityContext, [objectId]() {
429 return scroll_helper(objectId, QAccessibleActionInterface::increaseAction());
434 return result && oldPosition != screenRect_helper(firstChildId,
false);
441 const auto& ids = childIdListForAccessibleObject_helper(objectId);
445 const int firstChildId = ids.first();
446 const QRect oldPosition = screenRect_helper(firstChildId,
false);
448 if (m_accessibilityContext) {
449 runInObjectContext(m_accessibilityContext, [objectId]() {
450 return scroll_helper(objectId, QAccessibleActionInterface::decreaseAction());
455 return result && oldPosition != screenRect_helper(firstChildId,
false);
460 QAccessibleInterface *iface = interfaceFromId(objectId);
461 if (!iface || !iface->isValid() || !iface->actionInterface())
464 const auto actionNames = iface->actionInterface()->actionNames();
466 if (actionNames.contains(QAccessibleActionInterface::showOnScreenAction())) {
467 invokeActionOnInterfaceInMainThread(iface->actionInterface(), QAccessibleActionInterface::showOnScreenAction());
476 if (m_accessibilityContext) {
477 runInObjectContext(m_accessibilityContext, [objectId]() {
478 return showOnScreen_helper(objectId);
487 if (m_accessibilityContext) {
489 m_accessibilityContext, [objectId]() {
return clickAction_helper(objectId); },
498 if (m_accessibilityContext) {
500 m_accessibilityContext, [objectId]() {
return clickAction_helper(objectId); },
509 QAccessibleValueInterface *valueIface = iface->valueInterface();
511 const QVariant valueVar = valueIface->currentValue();
512 const auto type = valueVar.typeId();
513 if (type == QMetaType::Double || type == QMetaType::Float) {
519 const double val = valueVar.toDouble();
521 bool stepIsValid =
false;
522 const double step = qAbs(valueIface->minimumStepSize().toDouble(&stepIsValid));
523 if (!stepIsValid || qFuzzyIsNull(step)) {
525 valueStr = qFuzzyIsNull(val) ? u"0"_s : QString::number(val,
'f');
527 const int precision = [](
double s) {
529 while (s < 1. && !qFuzzyCompare(s, 1.)) {
536 const int stop = count + 3;
537 const auto fractional = [](
double v) {
539 std::modf(v + 0.5, &whole);
540 return qAbs(v - whole);
543 while (count < stop && !qFuzzyIsNull(s)) {
545 s = fractional(s * 10);
549 valueStr = qFuzzyIsNull(val / step) ? u"0"_s
550 : QString::number(val,
'f', precision);
553 valueStr = valueVar.toString();
561 case QAccessible::Role::Button:
562 case QAccessible::Role::Link:
565 return QStringLiteral(
"android.widget.ToggleButton");
566 return QStringLiteral(
"android.widget.Button");
568 case QAccessible::Role::CheckBox:
571 return QStringLiteral(
"android.widget.CompoundButton");
572 case QAccessible::Role::Switch:
573 return QStringLiteral(
"android.widget.Switch");
574 case QAccessible::Role::Clock:
575 return QStringLiteral(
"android.widget.TextClock");
576 case QAccessible::Role::ComboBox:
577 case QAccessible::Role::ButtonDropDown:
578 return QStringLiteral(
"android.widget.Spinner");
579 case QAccessible::Role::Graphic:
581 return QStringLiteral(
"android.widget.ImageView");
582 case QAccessible::Role::Grouping:
583 return QStringLiteral(
"android.view.ViewGroup");
584 case QAccessible::Role::List:
587 return QStringLiteral(
"android.widget.AbsListView");
588 case QAccessible::Role::MenuItem:
589 return QStringLiteral(
"android.view.MenuItem");
590 case QAccessible::Role::PopupMenu:
591 return QStringLiteral(
"android.widget.PopupMenu");
592 case QAccessible::Role::Separator:
593 return QStringLiteral(
"android.widget.Space");
594 case QAccessible::Role::ToolBar:
595 return QStringLiteral(
"android.view.Toolbar");
596 case QAccessible::Role::Heading: [[fallthrough]];
597 case QAccessible::Role::StaticText:
599 return QStringLiteral(
"android.widget.TextView");
600 case QAccessible::Role::EditableText:
601 return QStringLiteral(
"android.widget.EditText");
602 case QAccessible::Role::RadioButton:
603 return QStringLiteral(
"android.widget.RadioButton");
604 case QAccessible::Role::ProgressBar:
605 return QStringLiteral(
"android.widget.ProgressBar");
606 case QAccessible::Role::SpinBox:
607 return QStringLiteral(
"android.widget.NumberPicker");
608 case QAccessible::Role::WebDocument:
609 return QStringLiteral(
"android.webkit.WebView");
610 case QAccessible::Role::Dialog:
611 return QStringLiteral(
"android.app.AlertDialog");
612 case QAccessible::Role::PageTab:
613 return QStringLiteral(
"android.app.ActionBar.Tab");
614 case QAccessible::Role::PageTabList:
615 return QStringLiteral(
"android.widget.TabWidget");
616 case QAccessible::Role::ScrollBar:
617 return QStringLiteral(
"android.widget.Scroller");
618 case QAccessible::Role::Slider:
619 return QStringLiteral(
"android.widget.SeekBar");
620 case QAccessible::Role::Table:
623 return QStringLiteral(
"android.widget.GridView");
624 case QAccessible::Role::Pane:
626 return QStringLiteral(
"android.view.ViewGroup");
627 case QAccessible::Role::AlertMessage:
628 case QAccessible::Role::Animation:
629 case QAccessible::Role::Application:
630 case QAccessible::Role::Assistant:
631 case QAccessible::Role::BlockQuote:
632 case QAccessible::Role::Border:
633 case QAccessible::Role::ButtonDropGrid:
634 case QAccessible::Role::ButtonMenu:
635 case QAccessible::Role::Canvas:
636 case QAccessible::Role::Caret:
637 case QAccessible::Role::Cell:
638 case QAccessible::Role::Chart:
639 case QAccessible::Role::Client:
640 case QAccessible::Role::ColorChooser:
641 case QAccessible::Role::Column:
642 case QAccessible::Role::ColumnHeader:
643 case QAccessible::Role::ComplementaryContent:
644 case QAccessible::Role::Cursor:
645 case QAccessible::Role::Desktop:
646 case QAccessible::Role::Dial:
647 case QAccessible::Role::Document:
648 case QAccessible::Role::Equation:
649 case QAccessible::Role::Footer:
650 case QAccessible::Role::Form:
651 case QAccessible::Role::Grip:
652 case QAccessible::Role::HelpBalloon:
653 case QAccessible::Role::HotkeyField:
654 case QAccessible::Role::Indicator:
655 case QAccessible::Role::LayeredPane:
656 case QAccessible::Role::ListItem:
657 case QAccessible::Role::MenuBar:
658 case QAccessible::Role::NoRole:
659 case QAccessible::Role::Note:
660 case QAccessible::Role::Notification:
661 case QAccessible::Role::Paragraph:
662 case QAccessible::Role::PropertyPage:
663 case QAccessible::Role::Row:
664 case QAccessible::Role::RowHeader:
665 case QAccessible::Role::Section:
666 case QAccessible::Role::Sound:
667 case QAccessible::Role::Splitter:
668 case QAccessible::Role::StatusBar:
669 case QAccessible::Role::Terminal:
670 case QAccessible::Role::TitleBar:
671 case QAccessible::Role::ToolTip:
672 case QAccessible::Role::Tree:
673 case QAccessible::Role::TreeItem:
674 case QAccessible::Role::UserRole:
675 case QAccessible::Role::Whitespace:
676 case QAccessible::Role::Window:
680 return QStringLiteral(
"android.view.TextView");
686 if (!state.expandable)
695 if (iface && iface->isValid()) {
696 bool hasValue =
false;
697 desc = iface->text(QAccessible::Name);
698 const QString descStr = iface->text(QAccessible::Description);
699 if (!descStr.isEmpty()) {
701 desc.append(QStringLiteral(
", "));
702 desc.append(descStr);
704 if (desc.isEmpty()) {
705 desc = iface->text(QAccessible::Value);
706 hasValue = !desc.isEmpty();
708 if (!hasValue && iface->valueInterface()) {
709 const QString valueStr = textFromValue(iface);
710 if (!valueStr.isEmpty()) {
712 desc.append(QChar(QChar::Space));
713 desc.append(valueStr);
722 QAccessibleInterface *iface = interfaceFromId(objectId);
723 return descriptionForInterface(iface);
729 if (m_accessibilityContext) {
730 runInObjectContext(m_accessibilityContext, [objectId]() {
731 return descriptionForAccessibleObject_helper(objectId);
734 return env->NewString((jchar*) desc.constData(), (jsize) desc.size());
739 QAccessibleInterface *iface = interfaceFromId(objectId);
740 if (!iface || !iface->isValid())
743 QAccessibleAttributesInterface *attributesIface = iface->attributesInterface();
744 if (!attributesIface || !attributesIface->attributeKeys().contains(QAccessible::Attribute::Locale))
747 return attributesIface->attributeValue(QAccessible::Attribute::Locale).toLocale().bcp47Name();
753 if (m_accessibilityContext) {
754 runInObjectContext(m_accessibilityContext, [objectId]() {
755 return languageTag_helper(objectId);
758 return env->NewString((jchar*)tag.constData(), (jsize)tag.size());
784 QAccessibleInterface *iface = interfaceFromId(objectId);
785 if (iface && iface->isValid()) {
787 info.state = iface->state();
788 info.role = iface->role();
789 info.actions = QAccessibleBridgeUtils::effectiveActionNames(iface);
790 info.description = descriptionForInterface(iface);
791 info.identifier = QAccessibleBridgeUtils::accessibleId(iface);
792 QAccessibleTextInterface *textIface = iface->textInterface();
793 if (textIface && (textIface->selectionCount() > 0)) {
801 if (info.state.editable) {
803 info.text = textIface->text(0, textIface->characterCount());
804 info.hint = iface->text(QAccessible::Name);
806 QAccessibleValueInterface *valueInterface = iface->valueInterface();
807 if (valueInterface) {
809 info.minValue = valueInterface->minimumValue();
810 info.maxValue = valueInterface->maximumValue();
811 info.currentValue = valueInterface->currentValue();
812 info.valueStepSize = valueInterface->minimumStepSize();
821 if (m_accessibilityContext) {
822 runInObjectContext(m_accessibilityContext, [objectId]() {
823 return populateNode_helper(objectId);
827 __android_log_print(ANDROID_LOG_WARN,
m_qtTag,
"Accessibility: populateNode for Invalid ID");
831 const QString role = classNameForRole(info.role, info.state);
832 jstring jrole = env->NewString((jchar*)role.constData(), (jsize)role.size());
833 env->CallVoidMethod(node, m_setClassNameMethodID, jrole);
835 const bool hasClickableAction =
836 (info.actions.contains(QAccessibleActionInterface::pressAction())
837 || info.actions.contains(QAccessibleActionInterface::toggleAction()))
838 && !(info.role == QAccessible::StaticText || info.role == QAccessible::Heading);
839 const bool hasIncreaseAction =
840 info.actions.contains(QAccessibleActionInterface::increaseAction());
841 const bool hasDecreaseAction =
842 info.actions.contains(QAccessibleActionInterface::decreaseAction());
843 const bool scrollableRole =
844 info.role == QAccessible::ScrollBar || info.role == QAccessible::List;
847 env->CallVoidMethod(node, m_setTextSelectionMethodID, info
.selectionStart,
851 if (info
.hasValue && m_setRangeInfoMethodID) {
852 int valueType = info.currentValue.typeId();
855 case QMetaType::Float:
856 case QMetaType::Double:
864 float min = info.minValue.toFloat();
865 float max = info.maxValue.toFloat();
866 float current = info.currentValue.toFloat();
867 if (info.role == QAccessible::ProgressBar) {
869 current = 100 * (current - min) / (max - min);
874 QJniObject rangeInfo(
"android/view/accessibility/AccessibilityNodeInfo$RangeInfo",
875 "(IFFF)V", rangeType, min, max, current);
877 if (rangeInfo.isValid()) {
878 env->CallVoidMethod(node, m_setRangeInfoMethodID, rangeInfo.object());
882 env->CallVoidMethod(node, m_setCheckableMethodID, (
bool)info.state.checkable);
883 env->CallVoidMethod(node, m_setCheckedMethodID, (
bool)info.state.checked);
884 if (QtAndroidPrivate::androidSdkVersion() >= 36) {
885 env->CallVoidMethod(node, m_setExpandedStateMethodID,
886 expandedStateFromState(info.state));
888 env->CallVoidMethod(node, m_setEditableMethodID, info.state.editable);
889 env->CallVoidMethod(node, m_setEnabledMethodID, !info.state.disabled);
890 env->CallVoidMethod(node, m_setFocusableMethodID, (
bool)info.state.focusable);
891 env->CallVoidMethod(node, m_setFocusedMethodID, (
bool)info.state.focused);
893 env->CallVoidMethod(node, m_setHeadingMethodID, info.role == QAccessible::Heading);
894 env->CallVoidMethod(node, m_setVisibleToUserMethodID, !info.state.invisible);
895 env->CallVoidMethod(node, m_setScrollableMethodID,
896 hasIncreaseAction || hasDecreaseAction || scrollableRole);
897 env->CallVoidMethod(node, m_setClickableMethodID, hasClickableAction || info.role == QAccessible::Link);
900 if (hasClickableAction)
901 env->CallVoidMethod(node, m_addActionMethodID, (
int)0x00000010);
904 if (hasIncreaseAction)
905 env->CallVoidMethod(node, m_addActionMethodID, (
int)0x00001000);
908 if (hasDecreaseAction)
909 env->CallVoidMethod(node, m_addActionMethodID, (
int)0x00002000);
912 if (info.state.expandable) {
913 if (info.state.expanded) {
916 env->CallVoidMethod(node, m_addActionMethodID,
ACTION_EXPAND);
921 jstring jdesc = env->NewString((jchar*)info.description.constData(),
922 (jsize)info.description.size());
924 env->CallVoidMethod(node, m_setContentDescriptionMethodID, jdesc);
930 if (info.state.editable) {
932 jstring jtext = env->NewString((jchar*)info.text.constData(),
933 (jsize)info.text.size());
934 env->CallVoidMethod(node, m_setTextMethodID, jtext);
935 env->DeleteLocalRef(jtext);
939 env->CallVoidMethod(node, m_setInputTypeMethodID, (jint)0x00000001);
941 jstring jhint = env->NewString((jchar*)info.hint.constData(),
942 (jsize)info.hint.size());
943 env->CallVoidMethod(node, m_setHintTextMethodID, jhint);
944 env->DeleteLocalRef(jhint);
948 QJniObject(node).callMethod<
void>(
"setViewIdResourceName", info.identifier);
964 QAccessibleInterface *iface = interfaceFromId(objectId);
965 if (!iface || !iface->isValid())
968 auto *viewportIface = iface->viewportInterface();
975 info.contentSize = viewportIface->contentSize();
976 info.position = viewportIface->position();
977 info.viewportSize = viewportIface->viewportSize();
985 if (m_accessibilityContext) {
987 m_accessibilityContext,
988 [objectId]() {
return populateScrollEvent_helper(objectId); }, &info);
995 const int itemCount =
std::max(info.contentSize.width(), info.contentSize.height());
996 env->CallVoidMethod(event, m_setItemCountMethodID, itemCount);
997 const int fromIndex =
std::max(info.position.x(), info.position.y()) * itemCount;
998 env->CallVoidMethod(event, m_setFromIndexMethodID, fromIndex);
999 const int toIndex = fromIndex
1000 +
std::min(info.viewportSize.width(), info.viewportSize.height() * itemCount);
1001 env->CallVoidMethod(event, m_setToIndexMethodID, toIndex);
1004 env->CallVoidMethod(event, m_setScrollXMethodID,
1005 (
int)(info.position.x() * info.contentSize.width()));
1006 env->CallVoidMethod(event, m_setMaxScrollXMethodID, (
int)info.contentSize.width());
1007 env->CallVoidMethod(event, m_setScrollYMethodID,
1008 (
int)(info.position.y() * info.contentSize.height()));
1009 env->CallVoidMethod(event, m_setMaxScrollYMethodID, (
int)info.contentSize.height());
1018 {
"parentId",
"(I)I", (
void*)
parentId},
1022 {
"hitTest",
"(FF)I", (
void*)
hitTest},
1023 {
"populateNode",
"(ILandroid/view/accessibility/AccessibilityNodeInfo;)Z", (
void*)
populateNode},
1024 {
"populateScrollEvent",
"(ILandroid/view/accessibility/AccessibilityEvent;)Z", (
void*)
populateScrollEvent},
1030 {
"expand",
"(I)Z", (
void *)
expand},
1031 {
"collapse",
"(I)Z", (
void *)
collapse}
1034#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE)
1035 VAR = env->GetMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE);
1037 __android_log_print(ANDROID_LOG_FATAL, QtAndroid::qtTagText(), QtAndroid::methodErrorMsgFmt(), METHOD_NAME, METHOD_SIGNATURE);
1041#define CHECK_AND_INIT_STATIC_FIELD(TYPE, VAR, CLASS, FIELD_NAME)
1042 if (env.findStaticField<TYPE>(CLASS, FIELD_NAME) == nullptr) {
1043 __android_log_print(ANDROID_LOG_FATAL, QtAndroid::qtTagText(),
1044 QtAndroid::staticFieldErrorMsgFmt(), FIELD_NAME);
1047 VAR = QJniObject::getStaticField<TYPE>(CLASS, FIELD_NAME);
1051 if (!env.registerNativeMethods(
"org/qtproject/qt/android/QtNativeAccessibility",
1053 __android_log_print(ANDROID_LOG_FATAL,
"Qt A11y",
"RegisterNatives failed");
1057 jclass nodeInfoClass = env->FindClass(
"android/view/accessibility/AccessibilityNodeInfo");
1062 if (QtAndroidPrivate::androidSdkVersion() >= 36) {
1064 "setExpandedState",
"(I)V");
1067 GET_AND_CHECK_STATIC_METHOD(m_setContentDescriptionMethodID, nodeInfoClass,
"setContentDescription",
"(Ljava/lang/CharSequence;)V");
1076 if (QtAndroidPrivate::androidSdkVersion() >= 28) {
1083 m_setRangeInfoMethodID, nodeInfoClass,
"setRangeInfo",
1084 "(Landroid/view/accessibility/AccessibilityNodeInfo$RangeInfo;)V");
1086 jclass eventClass = env->FindClass(
"android/view/accessibility/AccessibilityEvent");
1095 jclass rangeInfoClass =
1096 env->FindClass(
"android/view/accessibility/AccessibilityNodeInfo$RangeInfo");
1100 if (QtAndroidPrivate::androidSdkVersion() >= 36) {
1102 "RANGE_TYPE_INDETERMINATE");
1107 if (QtAndroidPrivate::androidSdkVersion() >= 36) {
1109 "EXPANDED_STATE_UNDEFINED");
1111 "EXPANDED_STATE_COLLAPSED");
1113 "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 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 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)