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 <frederik.gladhorn@theqtcompany.com>
This commit is contained in:
Jan Arve Saether 2014-10-02 10:20:28 +02:00 committed by Jan Arve Sæther
parent 29ad07d0a4
commit 648623ff23

View File

@ -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);