Accessibility: Add actions for value interfaces
To support increment / decrement of sliders, dials and spin boxes. (anything with an {in,de}crementAction or a valueInterface. Other platforms will follow the same pattern in follow-up patches. Task-number: QTBUG-38832 Change-Id: Ie570acc39b3d9494a8bb9f624b61a398b1d8de89 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
This commit is contained in:
parent
7bd33c36db
commit
a14aff64a1
@ -335,13 +335,24 @@ public class QtAccessibilityDelegate extends View.AccessibilityDelegate
|
||||
{
|
||||
// Log.i(TAG, "ACTION " + action + " on " + virtualViewId);
|
||||
// dumpNodes(virtualViewId);
|
||||
boolean success = false;
|
||||
switch (action) {
|
||||
case AccessibilityNodeInfo.ACTION_CLICK:
|
||||
boolean success = QtNativeAccessibility.clickAction(virtualViewId);
|
||||
success = QtNativeAccessibility.clickAction(virtualViewId);
|
||||
if (success)
|
||||
sendEventForVirtualViewId(virtualViewId, AccessibilityEvent.TYPE_VIEW_CLICKED);
|
||||
return success;
|
||||
break;
|
||||
case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD:
|
||||
success = QtNativeAccessibility.scrollForward(virtualViewId);
|
||||
if (success)
|
||||
sendEventForVirtualViewId(virtualViewId, AccessibilityEvent.TYPE_VIEW_SCROLLED);
|
||||
break;
|
||||
case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD:
|
||||
success = QtNativeAccessibility.scrollBackward(virtualViewId);
|
||||
if (success)
|
||||
sendEventForVirtualViewId(virtualViewId, AccessibilityEvent.TYPE_VIEW_SCROLLED);
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +53,8 @@ class QtNativeAccessibility
|
||||
static native Rect screenRect(int objectId);
|
||||
static native int hitTest(float x, float y);
|
||||
static native boolean clickAction(int objectId);
|
||||
static native boolean scrollForward(int objectId);
|
||||
static native boolean scrollBackward(int objectId);
|
||||
|
||||
static native boolean populateNode(int objectId, AccessibilityNodeInfo node);
|
||||
}
|
||||
|
7
src/platformsupport/accessibility/accessibility.pri
Normal file
7
src/platformsupport/accessibility/accessibility.pri
Normal file
@ -0,0 +1,7 @@
|
||||
INCLUDEPATH += $$PWD
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/qaccessiblebridgeutils_p.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/qaccessiblebridgeutils.cpp
|
119
src/platformsupport/accessibility/qaccessiblebridgeutils.cpp
Normal file
119
src/platformsupport/accessibility/qaccessiblebridgeutils.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
#include "qaccessiblebridgeutils_p.h"
|
||||
#include <QtCore/qmath.h>
|
||||
|
||||
#ifndef QT_NO_ACCESSIBILITY
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace QAccessibleBridgeUtils {
|
||||
|
||||
static bool performAction(QAccessibleInterface *iface, const QString &actionName)
|
||||
{
|
||||
if (QAccessibleActionInterface *actionIface = iface->actionInterface()) {
|
||||
if (actionIface->actionNames().contains(actionName)) {
|
||||
actionIface->doAction(actionName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList effectiveActionNames(QAccessibleInterface *iface)
|
||||
{
|
||||
QStringList actions;
|
||||
if (QAccessibleActionInterface *actionIface = iface->actionInterface())
|
||||
actions = actionIface->actionNames();
|
||||
|
||||
if (iface->valueInterface()) {
|
||||
if (!actions.contains(QAccessibleActionInterface::increaseAction()))
|
||||
actions << QAccessibleActionInterface::increaseAction();
|
||||
if (!actions.contains(QAccessibleActionInterface::decreaseAction()))
|
||||
actions << QAccessibleActionInterface::decreaseAction();
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
|
||||
bool performEffectiveAction(QAccessibleInterface *iface, const QString &actionName)
|
||||
{
|
||||
if (!iface)
|
||||
return false;
|
||||
if (performAction(iface, actionName))
|
||||
return true;
|
||||
if (actionName != QAccessibleActionInterface::increaseAction()
|
||||
&& actionName != QAccessibleActionInterface::decreaseAction())
|
||||
return false;
|
||||
|
||||
QAccessibleValueInterface *valueIface = iface->valueInterface();
|
||||
if (!valueIface)
|
||||
return false;
|
||||
bool success;
|
||||
const QVariant currentVariant = valueIface->currentValue();
|
||||
double stepSize = valueIface->minimumStepSize().toDouble(&success);
|
||||
if (!success || qFuzzyIsNull(stepSize)) {
|
||||
const double min = valueIface->minimumValue().toDouble(&success);
|
||||
if (!success)
|
||||
return false;
|
||||
const double max = valueIface->maximumValue().toDouble(&success);
|
||||
if (!success)
|
||||
return false;
|
||||
stepSize = (max - min) / 10; // this is pretty arbitrary, we just need to provide something
|
||||
const int typ = currentVariant.type();
|
||||
if (typ != QMetaType::Float && typ != QMetaType::Double) {
|
||||
// currentValue is an integer. Round it up to ensure stepping in case it was below 1
|
||||
stepSize = qCeil(stepSize);
|
||||
}
|
||||
}
|
||||
const double current = currentVariant.toDouble(&success);
|
||||
if (!success)
|
||||
return false;
|
||||
if (actionName == QAccessibleActionInterface::decreaseAction())
|
||||
stepSize = -stepSize;
|
||||
valueIface->setCurrentValue(current + stepSize);
|
||||
return true;
|
||||
}
|
||||
|
||||
} //namespace
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif
|
61
src/platformsupport/accessibility/qaccessiblebridgeutils_p.h
Normal file
61
src/platformsupport/accessibility/qaccessiblebridgeutils_p.h
Normal file
@ -0,0 +1,61 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QACCESSIBLEBRIDGEUTILS_H
|
||||
#define QACCESSIBLEBRIDGEUTILS_H
|
||||
|
||||
#ifndef QT_NO_ACCESSIBILITY
|
||||
|
||||
#include <QtCore/qstringlist.h>
|
||||
#include <QtGui/qaccessible.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace QAccessibleBridgeUtils {
|
||||
QStringList effectiveActionNames(QAccessibleInterface *iface);
|
||||
bool performEffectiveAction(QAccessibleInterface *iface, const QString &actionName);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif
|
||||
|
||||
#endif //QACCESSIBLEBRIDGEUTILS_H
|
@ -18,6 +18,7 @@ include(input/input.pri)
|
||||
include(devicediscovery/devicediscovery.pri)
|
||||
include(services/services.pri)
|
||||
include(themes/themes.pri)
|
||||
include(accessibility/accessibility.pri)
|
||||
include(linuxaccessibility/linuxaccessibility.pri)
|
||||
include(clipboard/clipboard.pri)
|
||||
|
||||
|
@ -43,10 +43,12 @@
|
||||
#include "androidjnimain.h"
|
||||
#include "qandroidplatformintegration.h"
|
||||
#include "qpa/qplatformaccessibility.h"
|
||||
#include <QtPlatformSupport/private/qaccessiblebridgeutils_p.h>
|
||||
#include "qguiapplication.h"
|
||||
#include "qwindow.h"
|
||||
#include "qrect.h"
|
||||
#include "QtGui/qaccessible.h"
|
||||
#include <QtCore/qmath.h>
|
||||
|
||||
#include "qdebug.h"
|
||||
|
||||
@ -64,6 +66,7 @@ namespace QtAndroidAccessibility
|
||||
static jmethodID m_setEnabledMethodID = 0;
|
||||
static jmethodID m_setFocusableMethodID = 0;
|
||||
static jmethodID m_setFocusedMethodID = 0;
|
||||
static jmethodID m_setScrollableMethodID = 0;
|
||||
static jmethodID m_setTextSelectionMethodID = 0;
|
||||
static jmethodID m_setVisibleToUserMethodID = 0;
|
||||
|
||||
@ -166,6 +169,18 @@ namespace QtAndroidAccessibility
|
||||
return false;
|
||||
}
|
||||
|
||||
static jboolean scrollForward(JNIEnv */*env*/, jobject /*thiz*/, jint objectId)
|
||||
{
|
||||
QAccessibleInterface *iface = interfaceFromId(objectId);
|
||||
return QAccessibleBridgeUtils::performEffectiveAction(iface, QAccessibleActionInterface::increaseAction());
|
||||
}
|
||||
|
||||
static jboolean scrollBackward(JNIEnv */*env*/, jobject /*thiz*/, jint objectId)
|
||||
{
|
||||
QAccessibleInterface *iface = interfaceFromId(objectId);
|
||||
return QAccessibleBridgeUtils::performEffectiveAction(iface, QAccessibleActionInterface::decreaseAction());
|
||||
}
|
||||
|
||||
|
||||
#define FIND_AND_CHECK_CLASS(CLASS_NAME) \
|
||||
clazz = env->FindClass(CLASS_NAME); \
|
||||
@ -199,6 +214,11 @@ if (!clazz) { \
|
||||
return false;
|
||||
}
|
||||
QAccessible::State state = iface->state();
|
||||
const QStringList actions = QAccessibleBridgeUtils::effectiveActionNames(iface);
|
||||
const bool hasClickableAction = actions.contains(QAccessibleActionInterface::pressAction())
|
||||
|| actions.contains(QAccessibleActionInterface::toggleAction());
|
||||
const bool hasIncreaseAction = actions.contains(QAccessibleActionInterface::increaseAction());
|
||||
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);
|
||||
@ -216,21 +236,26 @@ if (!clazz) { \
|
||||
}
|
||||
|
||||
env->CallVoidMethod(node, m_setEnabledMethodID, !state.disabled);
|
||||
env->CallVoidMethod(node, m_setCheckableMethodID, (bool)state.checkable);
|
||||
env->CallVoidMethod(node, m_setCheckedMethodID, (bool)state.checked);
|
||||
env->CallVoidMethod(node, m_setFocusableMethodID, (bool)state.focusable);
|
||||
env->CallVoidMethod(node, m_setFocusedMethodID, (bool)state.focused);
|
||||
env->CallVoidMethod(node, m_setCheckableMethodID, (bool)state.checkable);
|
||||
env->CallVoidMethod(node, m_setVisibleToUserMethodID, !state.invisible);
|
||||
env->CallVoidMethod(node, m_setScrollableMethodID, hasIncreaseAction || hasDecreaseAction);
|
||||
env->CallVoidMethod(node, m_setClickableMethodID, hasClickableAction);
|
||||
|
||||
// Add ACTION_CLICK
|
||||
if (hasClickableAction)
|
||||
env->CallVoidMethod(node, m_addActionMethodID, (int)16); // ACTION_CLICK defined in AccessibilityNodeInfo
|
||||
|
||||
// Add ACTION_SCROLL_FORWARD
|
||||
if (hasIncreaseAction)
|
||||
env->CallVoidMethod(node, m_addActionMethodID, (int)4096); // ACTION_SCROLL_FORWARD defined in AccessibilityNodeInfo
|
||||
|
||||
// Add ACTION_SCROLL_BACKWARD
|
||||
if (hasDecreaseAction)
|
||||
env->CallVoidMethod(node, m_addActionMethodID, (int)8192); // ACTION_SCROLL_BACKWARD defined in AccessibilityNodeInfo
|
||||
|
||||
if (iface->actionInterface()) {
|
||||
QStringList actions = iface->actionInterface()->actionNames();
|
||||
bool clickable = actions.contains(QAccessibleActionInterface::pressAction());
|
||||
bool toggle = actions.contains(QAccessibleActionInterface::toggleAction());
|
||||
if (clickable || toggle) {
|
||||
env->CallVoidMethod(node, m_setClickableMethodID, (bool)clickable);
|
||||
env->CallVoidMethod(node, m_addActionMethodID, (int)16); // ACTION_CLICK defined in AccessibilityNodeInfo
|
||||
}
|
||||
}
|
||||
|
||||
jstring jdesc = env->NewString((jchar*) desc.constData(), (jsize) desc.size());
|
||||
//CALL_METHOD(node, "setText", "(Ljava/lang/CharSequence;)V", jdesc)
|
||||
@ -248,6 +273,8 @@ if (!clazz) { \
|
||||
{"hitTest", "(FF)I", (void*)hitTest},
|
||||
{"populateNode", "(ILandroid/view/accessibility/AccessibilityNodeInfo;)Z", (void*)populateNode},
|
||||
{"clickAction", "(I)Z", (void*)clickAction},
|
||||
{"scrollForward", "(I)Z", (void*)scrollForward},
|
||||
{"scrollBackward", "(I)Z", (void*)scrollBackward},
|
||||
};
|
||||
|
||||
#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \
|
||||
@ -277,6 +304,7 @@ if (!clazz) { \
|
||||
GET_AND_CHECK_STATIC_METHOD(m_setEnabledMethodID, nodeInfoClass, "setEnabled", "(Z)V");
|
||||
GET_AND_CHECK_STATIC_METHOD(m_setFocusableMethodID, nodeInfoClass, "setFocusable", "(Z)V");
|
||||
GET_AND_CHECK_STATIC_METHOD(m_setFocusedMethodID, nodeInfoClass, "setFocused", "(Z)V");
|
||||
GET_AND_CHECK_STATIC_METHOD(m_setScrollableMethodID, nodeInfoClass, "setScrollable", "(Z)V");
|
||||
GET_AND_CHECK_STATIC_METHOD(m_setTextSelectionMethodID, nodeInfoClass, "setTextSelection", "(II)V");
|
||||
GET_AND_CHECK_STATIC_METHOD(m_setVisibleToUserMethodID, nodeInfoClass, "setVisibleToUser", "(Z)V");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user