From be2954a0b7d26942f7b6fcf4d4c45e7c6164872c Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Mon, 27 Oct 2014 15:21:32 +0100 Subject: Merge QQmlAccessible into QAccessibleQuickItem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The idea of the separation was to keep Qt Quick 1 and 2 accessibilty in sync. This is not going to happen because Qt Quick 1 accessibility was never supported and will not be in the future either, so instead remove code duplication and merge the two classes. Change-Id: I508eb0ae20ab22ee92806a4c648c39b35259b6b9 Reviewed-by: Jan Arve Sæther Reviewed-by: Frederik Gladhorn --- src/quick/accessible/accessible.pri | 2 - src/quick/accessible/qaccessiblequickitem.cpp | 121 ++++++++++++++-- src/quick/accessible/qaccessiblequickitem_p.h | 4 +- src/quick/accessible/qaccessiblequickview.cpp | 1 - src/quick/accessible/qqmlaccessible.cpp | 195 -------------------------- src/quick/accessible/qqmlaccessible_p.h | 82 ----------- 6 files changed, 109 insertions(+), 296 deletions(-) delete mode 100644 src/quick/accessible/qqmlaccessible.cpp delete mode 100644 src/quick/accessible/qqmlaccessible_p.h diff --git a/src/quick/accessible/accessible.pri b/src/quick/accessible/accessible.pri index 88ff747488..bff1325bd9 100644 --- a/src/quick/accessible/accessible.pri +++ b/src/quick/accessible/accessible.pri @@ -4,13 +4,11 @@ QT += core-private gui-private qml-private #DEFINES+=Q_ACCESSIBLE_QUICK_ITEM_ENABLE_DEBUG_DESCRIPTION SOURCES += \ - $$PWD/qqmlaccessible.cpp \ $$PWD/qaccessiblequickview.cpp \ $$PWD/qaccessiblequickitem.cpp \ $$PWD/qquickaccessiblefactory.cpp \ HEADERS += \ - $$PWD/qqmlaccessible_p.h \ $$PWD/qaccessiblequickview_p.h \ $$PWD/qaccessiblequickitem_p.h \ $$PWD/qquickaccessiblefactory_p.h \ diff --git a/src/quick/accessible/qaccessiblequickitem.cpp b/src/quick/accessible/qaccessiblequickitem.cpp index e13224f6fb..f86dcc1f13 100644 --- a/src/quick/accessible/qaccessiblequickitem.cpp +++ b/src/quick/accessible/qaccessiblequickitem.cpp @@ -44,7 +44,7 @@ QT_BEGIN_NAMESPACE #ifndef QT_NO_ACCESSIBILITY QAccessibleQuickItem::QAccessibleQuickItem(QQuickItem *item) - : QQmlAccessible(item), m_doc(textDocument()) + : QAccessibleObject(item), m_doc(textDocument()) { } @@ -178,16 +178,22 @@ QAccessible::State QAccessibleQuickItem::state() const if (!attached) return QAccessible::State(); - QAccessible::State st = attached->state(); + QAccessible::State state = attached->state(); - if (!item()->window() || !item()->window()->isVisible() ||!item()->isVisible() || qFuzzyIsNull(item()->opacity())) - st.invisible = true; + QRect viewRect_ = viewRect(); + QRect itemRect = rect(); - if (item()->activeFocusOnTab()) - st.focusable = true; + if (viewRect_.isNull() || itemRect.isNull() || !item()->window() || !item()->window()->isVisible() ||!item()->isVisible() || qFuzzyIsNull(item()->opacity())) + state.invisible = true; + if (!viewRect_.intersects(itemRect)) + state.offscreen = true; + if ((role() == QAccessible::CheckBox || role() == QAccessible::RadioButton) && object()->property("checked").toBool()) + state.checked = true; + if (item()->activeFocusOnTab() || role() == QAccessible::EditableText) + state.focusable = true; if (item()->hasActiveFocus()) - st.focused = true; - return st; + state.focused = true; + return state; } QAccessible::Role QAccessibleQuickItem::role() const @@ -213,11 +219,29 @@ bool QAccessibleQuickItem::isAccessible() const QStringList QAccessibleQuickItem::actionNames() const { - QStringList actions = QQmlAccessible::actionNames(); + QStringList actions; + switch (role()) { + case QAccessible::PushButton: + actions << QAccessibleActionInterface::pressAction(); + break; + case QAccessible::RadioButton: + case QAccessible::CheckBox: + actions << QAccessibleActionInterface::toggleAction() + << QAccessibleActionInterface::pressAction(); + break; + case QAccessible::Slider: + case QAccessible::SpinBox: + case QAccessible::ScrollBar: + actions << QAccessibleActionInterface::increaseAction() + << QAccessibleActionInterface::decreaseAction(); + break; + default: + break; + } if (state().focusable) actions.append(QAccessibleActionInterface::setFocusAction()); - // ### The following can lead to duplicate action names. We'll fix that when we kill QQmlAccessible + // ### The following can lead to duplicate action names. if (QQuickAccessibleAttached *attached = QQuickAccessibleAttached::attachedProperties(item())) attached->availableActions(&actions); return actions; @@ -232,13 +256,80 @@ void QAccessibleQuickItem::doAction(const QString &actionName) } if (QQuickAccessibleAttached *attached = QQuickAccessibleAttached::attachedProperties(item())) accepted = attached->doAction(actionName); - if (!accepted) - QQmlAccessible::doAction(actionName); + + if (accepted) + return; + // Look for and call the accessible[actionName]Action() function on the item. + // This allows for overriding the default action handling. + const QByteArray functionName = QByteArrayLiteral("accessible") + actionName.toLatin1() + QByteArrayLiteral("Action"); + if (object()->metaObject()->indexOfMethod(QByteArray(functionName + QByteArrayLiteral("()"))) != -1) { + QMetaObject::invokeMethod(object(), functionName); + return; + } + + // Role-specific default action handling follows. Items are expected to provide + // properties according to role conventions. These will then be read and/or updated + // by the accessibility system. + // Checkable roles : checked + // Value-based roles : (via the value interface: value, minimumValue, maximumValue), stepSize + switch (role()) { + case QAccessible::RadioButton: + case QAccessible::CheckBox: { + QVariant checked = object()->property("checked"); + if (checked.isValid()) { + if (actionName == QAccessibleActionInterface::toggleAction() || + actionName == QAccessibleActionInterface::pressAction()) { + + object()->setProperty("checked", QVariant(!checked.toBool())); + } + } + break; + } + case QAccessible::Slider: + case QAccessible::SpinBox: + case QAccessible::Dial: + case QAccessible::ScrollBar: { + if (actionName != QAccessibleActionInterface::increaseAction() && + actionName != QAccessibleActionInterface::decreaseAction()) + break; + + // Update the value using QAccessibleValueInterface, respecting + // the minimum and maximum value (if set). Also check for and + // use the "stepSize" property on the item + if (QAccessibleValueInterface *valueIface = valueInterface()) { + QVariant valueV = valueIface->currentValue(); + qreal newValue = valueV.toReal(); + + QVariant stepSizeV = object()->property("stepSize"); + qreal stepSize = stepSizeV.isValid() ? stepSizeV.toReal() : qreal(1.0); + if (actionName == QAccessibleActionInterface::increaseAction()) { + newValue += stepSize; + } else { + newValue -= stepSize; + } + + QVariant minimumValueV = valueIface->minimumValue(); + if (minimumValueV.isValid()) { + newValue = qMax(newValue, minimumValueV.toReal()); + } + QVariant maximumValueV = valueIface->maximumValue(); + if (maximumValueV.isValid()) { + newValue = qMin(newValue, maximumValueV.toReal()); + } + + valueIface->setCurrentValue(QVariant(newValue)); + } + break; + } + default: + break; + } } QStringList QAccessibleQuickItem::keyBindingsForAction(const QString &actionName) const { - return QQmlAccessible::keyBindingsForAction(actionName); + Q_UNUSED(actionName) + return QStringList(); } QString QAccessibleQuickItem::text(QAccessible::Text textType) const @@ -287,6 +378,8 @@ QString QAccessibleQuickItem::text(QAccessible::Text textType) const void *QAccessibleQuickItem::interface_cast(QAccessible::InterfaceType t) { QAccessible::Role r = role(); + if (t == QAccessible::ActionInterface) + return static_cast(this); if (t == QAccessible::ValueInterface && (r == QAccessible::Slider || r == QAccessible::SpinBox || @@ -298,7 +391,7 @@ void *QAccessibleQuickItem::interface_cast(QAccessible::InterfaceType t) (r == QAccessible::EditableText)) return static_cast(this); - return QQmlAccessible::interface_cast(t); + return QAccessibleObject::interface_cast(t); } QVariant QAccessibleQuickItem::currentValue() const diff --git a/src/quick/accessible/qaccessiblequickitem_p.h b/src/quick/accessible/qaccessiblequickitem_p.h index e8486721f3..5525e60493 100644 --- a/src/quick/accessible/qaccessiblequickitem_p.h +++ b/src/quick/accessible/qaccessiblequickitem_p.h @@ -36,7 +36,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE @@ -44,7 +44,7 @@ QT_BEGIN_NAMESPACE class QTextDocument; -class QAccessibleQuickItem : public QQmlAccessible, public QAccessibleValueInterface, public QAccessibleTextInterface +class QAccessibleQuickItem : public QAccessibleObject, public QAccessibleActionInterface, public QAccessibleValueInterface, public QAccessibleTextInterface { public: QAccessibleQuickItem(QQuickItem *item); diff --git a/src/quick/accessible/qaccessiblequickview.cpp b/src/quick/accessible/qaccessiblequickview.cpp index e3ee1d2722..3f6f53e6b5 100644 --- a/src/quick/accessible/qaccessiblequickview.cpp +++ b/src/quick/accessible/qaccessiblequickview.cpp @@ -39,7 +39,6 @@ #include #include "qaccessiblequickitem_p.h" -#include "qqmlaccessible_p.h" #ifndef QT_NO_ACCESSIBILITY diff --git a/src/quick/accessible/qqmlaccessible.cpp b/src/quick/accessible/qqmlaccessible.cpp deleted file mode 100644 index 53eb6a7a0d..0000000000 --- a/src/quick/accessible/qqmlaccessible.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtQml module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** 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 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** 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. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include "qqmlaccessible_p.h" - -#ifndef QT_NO_ACCESSIBILITY - -QT_BEGIN_NAMESPACE - -QQmlAccessible::QQmlAccessible(QObject *object) - :QAccessibleObject(object) -{ -} - -void *QQmlAccessible::interface_cast(QAccessible::InterfaceType t) -{ - if (t == QAccessible::ActionInterface) - return static_cast(this); - return QAccessibleObject::interface_cast(t); -} - -QQmlAccessible::~QQmlAccessible() -{ -} - -QAccessible::State QQmlAccessible::state() const -{ - QAccessible::State state; - - //QRect viewRect(QPoint(0, 0), m_implementation->size()); - //QRect itemRect(m_item->scenePos().toPoint(), m_item->boundingRect().size().toSize()); - - QRect viewRect_ = viewRect(); - QRect itemRect = rect(); - - // qDebug() << "viewRect" << viewRect << "itemRect" << itemRect; - // error case: - if (viewRect_.isNull() || itemRect.isNull()) { - state.invisible = true; - } - - if (!viewRect_.intersects(itemRect)) { - state.offscreen = true; - // state.invisible = true; // no set at this point to ease development - } - - if (!object()->property("visible").toBool() || qFuzzyIsNull(object()->property("opacity").toDouble())) { - state.invisible = true; - } - - if ((role() == QAccessible::CheckBox || role() == QAccessible::RadioButton) && object()->property("checked").toBool()) { - state.checked = true; - } - - if (role() == QAccessible::EditableText) - state.focusable = true; - - //qDebug() << "state?" << m_item->property("state").toString() << m_item->property("status").toString() << m_item->property("visible").toString(); - - return state; -} - -QStringList QQmlAccessible::actionNames() const -{ - QStringList actions; - switch (role()) { - case QAccessible::PushButton: - actions << QAccessibleActionInterface::pressAction(); - break; - case QAccessible::RadioButton: - case QAccessible::CheckBox: - actions << QAccessibleActionInterface::toggleAction() - << QAccessibleActionInterface::pressAction(); - break; - case QAccessible::Slider: - case QAccessible::SpinBox: - case QAccessible::ScrollBar: - actions << QAccessibleActionInterface::increaseAction() - << QAccessibleActionInterface::decreaseAction(); - break; - default: - break; - } - return actions; -} - -void QQmlAccessible::doAction(const QString &actionName) -{ - // Look for and call the accessible[actionName]Action() function on the item. - // This allows for overriding the default action handling. - const QByteArray functionName = QByteArrayLiteral("accessible") + actionName.toLatin1() + QByteArrayLiteral("Action"); - if (object()->metaObject()->indexOfMethod(QByteArray(functionName + QByteArrayLiteral("()"))) != -1) { - QMetaObject::invokeMethod(object(), functionName); - return; - } - - // Role-specific default action handling follows. Items are expected to provide - // properties according to role conventions. These will then be read and/or updated - // by the accessibility system. - // Checkable roles : checked - // Value-based roles : (via the value interface: value, minimumValue, maximumValue), stepSize - switch (role()) { - case QAccessible::RadioButton: - case QAccessible::CheckBox: { - QVariant checked = object()->property("checked"); - if (checked.isValid()) { - if (actionName == QAccessibleActionInterface::toggleAction() || - actionName == QAccessibleActionInterface::pressAction()) { - - object()->setProperty("checked", QVariant(!checked.toBool())); - } - } - break; - } - case QAccessible::Slider: - case QAccessible::SpinBox: - case QAccessible::Dial: - case QAccessible::ScrollBar: { - if (actionName != QAccessibleActionInterface::increaseAction() && - actionName != QAccessibleActionInterface::decreaseAction()) - break; - - // Update the value using QAccessibleValueInterface, respecting - // the minimum and maximum value (if set). Also check for and - // use the "stepSize" property on the item - if (QAccessibleValueInterface *valueIface = valueInterface()) { - QVariant valueV = valueIface->currentValue(); - qreal newValue = valueV.toReal(); - - QVariant stepSizeV = object()->property("stepSize"); - qreal stepSize = stepSizeV.isValid() ? stepSizeV.toReal() : qreal(1.0); - if (actionName == QAccessibleActionInterface::increaseAction()) { - newValue += stepSize; - } else { - newValue -= stepSize; - } - - QVariant minimumValueV = valueIface->minimumValue(); - if (minimumValueV.isValid()) { - newValue = qMax(newValue, minimumValueV.toReal()); - } - QVariant maximumValueV = valueIface->maximumValue(); - if (maximumValueV.isValid()) { - newValue = qMin(newValue, maximumValueV.toReal()); - } - - valueIface->setCurrentValue(QVariant(newValue)); - } - break; - } - default: - break; - } -} - -QStringList QQmlAccessible::keyBindingsForAction(const QString &actionName) const -{ - Q_UNUSED(actionName) - return QStringList(); -} - -QT_END_NAMESPACE - -#endif // QT_NO_ACCESSIBILITY diff --git a/src/quick/accessible/qqmlaccessible_p.h b/src/quick/accessible/qqmlaccessible_p.h deleted file mode 100644 index 5948f06cb5..0000000000 --- a/src/quick/accessible/qqmlaccessible_p.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtQml module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** 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 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** 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. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQMLACCESSIBLE_H -#define QQMLACCESSIBLE_H - -#include -#include - -QT_BEGIN_NAMESPACE - -#ifndef QT_NO_ACCESSIBILITY - -/* - -- Declarative Accessibility Overview. -- - - * Item interface classes: - QAccessibleDeclarativeItem for Qt Quick 1 - QAccessibleQuickItem for for Qt Quick 2 - Common base class: QQmlAccessible - - * View interface classes. - - These are the root of the QML accessible tree and connects it to the widget hierarchy. - - QAccessbileDeclarativeView is the root for the QGraphicsView implementation - QAccessbileQuickView is the root for the SceneGraph implementation - -*/ -class QQmlAccessible: public QAccessibleObject, public QAccessibleActionInterface -{ -public: - ~QQmlAccessible(); - void *interface_cast(QAccessible::InterfaceType t); - - virtual QRect viewRect() const = 0; - QAccessible::State state() const; - - QStringList actionNames() const; - void doAction(const QString &actionName); - QStringList keyBindingsForAction(const QString &actionName) const; - -protected: - // For subclasses, use instantiateObject factory method outside the class. - QQmlAccessible(QObject *object); -}; - -#endif // QT_NO_ACCESSIBILITY - -QT_END_NAMESPACE - -#endif // QQMLACCESSIBLE_H -- cgit v1.2.3