From 648623ff235c36e2482ad64a0578a4f7c36ad15a Mon Sep 17 00:00:00 2001 From: Jan Arve Saether Date: Thu, 2 Oct 2014 10:20:28 +0200 Subject: [PATCH] Consolidate how contentDescription is calculated. Previously, the behavior was different depending on if the contentDescription was calculated as a result of an event, or if it was calculated as a result of hierarchy traversal. Refactor the functionality into one single function that will be used in both scenarios. 'contentDescription' will now receive its value from one of the following sources, listed in prioritised order (QAI == QAccessibleInterface): 1. QAI::text(QAccessible::Name) 2. QAI::text(QAccessible::Description) 3. QAI::text(QAccessible::Value) 4. QAI::valueInterface()->currentValue() Change-Id: I2e4958a1e95b5f20d01da37c23ecbc09842360bc Reviewed-by: Frederik Gladhorn --- .../android/androidjniaccessibility.cpp | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/plugins/platforms/android/androidjniaccessibility.cpp b/src/plugins/platforms/android/androidjniaccessibility.cpp index 7229fd7af5..5c927da9c5 100644 --- a/src/plugins/platforms/android/androidjniaccessibility.cpp +++ b/src/plugins/platforms/android/androidjniaccessibility.cpp @@ -187,18 +187,30 @@ if (!clazz) { \ //__android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, METHOD_NAME, METHOD_SIGNATURE); - static jstring descriptionForAccessibleObject(JNIEnv *env, jobject /*thiz*/, jint objectId) + + static jstring descriptionForAccessibleObject_helper(JNIEnv *env, QAccessibleInterface *iface) { QString desc; - QAccessibleInterface *iface = interfaceFromId(objectId); if (iface && iface->isValid()) { desc = iface->text(QAccessible::Name); if (desc.isEmpty()) desc = iface->text(QAccessible::Description); + if (desc.isEmpty()) { + desc = iface->text(QAccessible::Value); + if (desc.isEmpty()) { + if (QAccessibleValueInterface *valueIface = iface->valueInterface()) { + desc= valueIface->currentValue().toString(); + } + } + } } + return env->NewString((jchar*) desc.constData(), (jsize) desc.size()); + } - jstring jdesc = env->NewString((jchar*) desc.constData(), (jsize) desc.size()); - return jdesc; + static jstring descriptionForAccessibleObject(JNIEnv *env, jobject /*thiz*/, jint objectId) + { + QAccessibleInterface *iface = interfaceFromId(objectId); + return descriptionForAccessibleObject_helper(env, iface); } static bool populateNode(JNIEnv *env, jobject /*thiz*/, jint objectId, jobject node) @@ -216,11 +228,8 @@ if (!clazz) { \ const bool hasDecreaseAction = actions.contains(QAccessibleActionInterface::decreaseAction()); // try to fill in the text property, this is what the screen reader reads - QString desc = iface->text(QAccessible::Value); - if (desc.isEmpty()) - desc = iface->text(QAccessible::Name); - if (desc.isEmpty()) - desc = iface->text(QAccessible::Description); + jstring jdesc = descriptionForAccessibleObject_helper(env, iface); + if (QAccessibleTextInterface *textIface = iface->textInterface()) { if (m_setTextSelectionMethodID && textIface->selectionCount() > 0) { int startSelection; @@ -252,7 +261,6 @@ if (!clazz) { \ env->CallVoidMethod(node, m_addActionMethodID, (int)8192); // ACTION_SCROLL_BACKWARD defined in AccessibilityNodeInfo - jstring jdesc = env->NewString((jchar*) desc.constData(), (jsize) desc.size()); //CALL_METHOD(node, "setText", "(Ljava/lang/CharSequence;)V", jdesc) env->CallVoidMethod(node, m_setContentDescriptionMethodID, jdesc);