From 079aaa9b0754db9b7b2a97cb2ea22042c6f50738 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Sat, 15 Feb 2014 14:41:45 +0100 Subject: Accessibility: Use factory function instead of plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [ChangeLog][QtQuick] Accessibility for Qt Quick is now included in the qtquick library instead of being a separate plugin. Change-Id: I26a7ed14b8a387662cea8f89218485be50033e34 Reviewed-by: Jan Arve Sæther --- src/plugins/accessible/accessible.pro | 2 - src/plugins/accessible/quick/accessible.json | 3 - src/plugins/accessible/quick/main.cpp | 105 ----- .../accessible/quick/qaccessiblequickitem.cpp | 447 --------------------- .../accessible/quick/qaccessiblequickitem.h | 130 ------ .../accessible/quick/qaccessiblequickview.cpp | 187 --------- .../accessible/quick/qaccessiblequickview.h | 78 ---- src/plugins/accessible/quick/quick.pro | 22 - src/plugins/accessible/shared/qaccessiblebase.pri | 3 - src/plugins/accessible/shared/qqmlaccessible.cpp | 224 ----------- src/plugins/accessible/shared/qqmlaccessible.h | 92 ----- src/plugins/plugins.pro | 3 - src/quick/accessible/accessible.pri | 16 + src/quick/accessible/qaccessiblequickitem.cpp | 447 +++++++++++++++++++++ src/quick/accessible/qaccessiblequickitem_p.h | 130 ++++++ src/quick/accessible/qaccessiblequickview.cpp | 187 +++++++++ src/quick/accessible/qaccessiblequickview_p.h | 78 ++++ src/quick/accessible/qqmlaccessible.cpp | 224 +++++++++++ src/quick/accessible/qqmlaccessible_p.h | 92 +++++ src/quick/accessible/qquickaccessiblefactory.cpp | 68 ++++ src/quick/accessible/qquickaccessiblefactory_p.h | 55 +++ src/quick/qtquick2.cpp | 5 + src/quick/quick.pro | 3 + 23 files changed, 1305 insertions(+), 1296 deletions(-) delete mode 100644 src/plugins/accessible/accessible.pro delete mode 100644 src/plugins/accessible/quick/accessible.json delete mode 100644 src/plugins/accessible/quick/main.cpp delete mode 100644 src/plugins/accessible/quick/qaccessiblequickitem.cpp delete mode 100644 src/plugins/accessible/quick/qaccessiblequickitem.h delete mode 100644 src/plugins/accessible/quick/qaccessiblequickview.cpp delete mode 100644 src/plugins/accessible/quick/qaccessiblequickview.h delete mode 100644 src/plugins/accessible/quick/quick.pro delete mode 100644 src/plugins/accessible/shared/qaccessiblebase.pri delete mode 100644 src/plugins/accessible/shared/qqmlaccessible.cpp delete mode 100644 src/plugins/accessible/shared/qqmlaccessible.h create mode 100644 src/quick/accessible/accessible.pri create mode 100644 src/quick/accessible/qaccessiblequickitem.cpp create mode 100644 src/quick/accessible/qaccessiblequickitem_p.h create mode 100644 src/quick/accessible/qaccessiblequickview.cpp create mode 100644 src/quick/accessible/qaccessiblequickview_p.h create mode 100644 src/quick/accessible/qqmlaccessible.cpp create mode 100644 src/quick/accessible/qqmlaccessible_p.h create mode 100644 src/quick/accessible/qquickaccessiblefactory.cpp create mode 100644 src/quick/accessible/qquickaccessiblefactory_p.h diff --git a/src/plugins/accessible/accessible.pro b/src/plugins/accessible/accessible.pro deleted file mode 100644 index b97d323a08..0000000000 --- a/src/plugins/accessible/accessible.pro +++ /dev/null @@ -1,2 +0,0 @@ -TEMPLATE = subdirs -qtHaveModule(quick): SUBDIRS += quick diff --git a/src/plugins/accessible/quick/accessible.json b/src/plugins/accessible/quick/accessible.json deleted file mode 100644 index b21218f19c..0000000000 --- a/src/plugins/accessible/quick/accessible.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "Keys": [ "QQuickWindow", "QQuickItem" ] -} diff --git a/src/plugins/accessible/quick/main.cpp b/src/plugins/accessible/quick/main.cpp deleted file mode 100644 index 6c7be155ce..0000000000 --- a/src/plugins/accessible/quick/main.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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: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 "qqmlaccessible.h" -#include "qaccessiblequickview.h" -#include "qaccessiblequickitem.h" - -#include -#include -#include -#include - -#include -#include -#include -#include - -#ifndef QT_NO_ACCESSIBILITY - -QT_BEGIN_NAMESPACE - -class AccessibleQuickFactory : public QAccessiblePlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QAccessibleFactoryInterface" FILE "accessible.json") - -public: - AccessibleQuickFactory(); - - QStringList keys() const; - QAccessibleInterface *create(const QString &classname, QObject *object); -}; - -AccessibleQuickFactory::AccessibleQuickFactory() -{ -} - -QStringList AccessibleQuickFactory::keys() const -{ - QStringList list; - list << QLatin1String("QQuickWindow"); - list << QLatin1String("QQuickItem"); - return list; -} - -QAccessibleInterface *AccessibleQuickFactory::create(const QString &classname, QObject *object) -{ - if (classname == QLatin1String("QQuickWindow")) { - return new QAccessibleQuickWindow(qobject_cast(object)); - } else if (classname == QLatin1String("QQuickItem")) { - QQuickItem *item = qobject_cast(object); - Q_ASSERT(item); - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); - if (!itemPrivate->isAccessible) - return 0; - return new QAccessibleQuickItem(item); - } - - return 0; -} - -QT_END_NAMESPACE - -#include "main.moc" - -#endif // QT_NO_ACCESSIBILITY diff --git a/src/plugins/accessible/quick/qaccessiblequickitem.cpp b/src/plugins/accessible/quick/qaccessiblequickitem.cpp deleted file mode 100644 index 4b68574149..0000000000 --- a/src/plugins/accessible/quick/qaccessiblequickitem.cpp +++ /dev/null @@ -1,447 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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: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 "qaccessiblequickitem.h" - -#include - -#include "QtQuick/private/qquickitem_p.h" -#include "QtQuick/private/qquicktext_p.h" -#include "QtQuick/private/qquickaccessibleattached_p.h" -#include "QtQuick/qquicktextdocument.h" - -QT_BEGIN_NAMESPACE - -#ifndef QT_NO_ACCESSIBILITY - -QAccessibleQuickItem::QAccessibleQuickItem(QQuickItem *item) - : QQmlAccessible(item), m_doc(textDocument()) -{ -} - -int QAccessibleQuickItem::childCount() const -{ - return childItems().count(); -} - -QRect QAccessibleQuickItem::rect() const -{ - const QRect r = itemScreenRect(item()); - - if (!r.isValid()) { - qWarning() << item()->metaObject()->className() << item()->property("accessibleText") << r; - } - return r; -} - -QRect QAccessibleQuickItem::viewRect() const -{ - // ### no window in some cases. - if (!item()->window()) { - return QRect(); - } - - QQuickWindow *window = item()->window(); - QPoint screenPos = window->mapToGlobal(QPoint(0,0)); - return QRect(screenPos, window->size()); -} - - -bool QAccessibleQuickItem::clipsChildren() const -{ - return static_cast(item())->clip(); -} - -QAccessibleInterface *QAccessibleQuickItem::parent() const -{ - QQuickItem *parent = item()->parentItem(); - if (parent) { - QQuickWindow *window = item()->window(); - // Jump out to the scene widget if the parent is the root item. - // There are two root items, QQuickWindow::rootItem and - // QQuickView::declarativeRoot. The former is the true root item, - // but is not a part of the accessibility tree. Check if we hit - // it here and return an interface for the scene instead. - if (window && (parent == window->contentItem())) { - return QAccessible::queryAccessibleInterface(window); - } else { - return QAccessible::queryAccessibleInterface(parent); - } - } - return 0; -} - -QAccessibleInterface *QAccessibleQuickItem::child(int index) const -{ - QList children = childItems(); - - if (index < 0 || index >= children.count()) - return 0; - - QQuickItem *child = children.at(index); - if (!child) // FIXME can this happen? - return 0; - - return QAccessible::queryAccessibleInterface(child); -} - -int QAccessibleQuickItem::indexOfChild(const QAccessibleInterface *iface) const -{ - QList kids = childItems(); - return kids.indexOf(static_cast(iface->object())); -} - -QList QAccessibleQuickItem::childItems() const -{ - if ( role() == QAccessible::Button || - role() == QAccessible::CheckBox || - role() == QAccessible::RadioButton || - role() == QAccessible::SpinBox || - role() == QAccessible::EditableText || - role() == QAccessible::Slider || - role() == QAccessible::PageTab || - role() == QAccessible::ProgressBar) - return QList(); - - QList items; - Q_FOREACH (QQuickItem *child, item()->childItems()) { - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(child); - if (itemPrivate->isAccessible) - items.append(child); - } - return items; -} - -QAccessible::State QAccessibleQuickItem::state() const -{ - QQuickAccessibleAttached *attached = QQuickAccessibleAttached::attachedProperties(item()); - if (!attached) - return QAccessible::State(); - - QAccessible::State st = attached->state(); - - if (!item()->window() || !item()->window()->isVisible() ||!item()->isVisible() || qFuzzyIsNull(item()->opacity())) - st.invisible = true; - - if (item()->activeFocusOnTab()) - st.focusable = true; - if (item()->hasActiveFocus()) - st.focused = true; - - if (role() == QAccessible::ComboBox) - st.editable = item()->property("editable").toBool(); - - return st; -} - -QAccessible::Role QAccessibleQuickItem::role() const -{ - // Workaround for setAccessibleRole() not working for - // Text items. Text items are special since they are defined - // entirely from C++ (setting the role from QML works.) - if (qobject_cast(const_cast(item()))) - return QAccessible::StaticText; - - QVariant v = QQuickAccessibleAttached::property(item(), "role"); - bool ok; - QAccessible::Role role = (QAccessible::Role)v.toInt(&ok); - if (!ok) // Not sure if this check is needed. - role = QAccessible::Pane; - return role; -} - -bool QAccessibleQuickItem::isAccessible() const -{ - return item()->d_func()->isAccessible; -} - -QString QAccessibleQuickItem::text(QAccessible::Text textType) const -{ - // handles generic behavior not specific to an item - switch (textType) { - case QAccessible::Name: { - QVariant accessibleName = QQuickAccessibleAttached::property(object(), "name"); - if (!accessibleName.isNull()) - return accessibleName.toString(); - break;} - case QAccessible::Description: { - QVariant accessibleDecription = QQuickAccessibleAttached::property(object(), "description"); - if (!accessibleDecription.isNull()) - return accessibleDecription.toString(); - break;} -#ifdef Q_ACCESSIBLE_QUICK_ITEM_ENABLE_DEBUG_DESCRIPTION - case QAccessible::DebugDescription: { - QString debugString; - debugString = QString::fromLatin1(object()->metaObject()->className()) + QLatin1Char(' '); - debugString += isAccessible() ? QLatin1String("enabled") : QLatin1String("disabled"); - return debugString; - break; } -#endif - case QAccessible::Value: - case QAccessible::Help: - case QAccessible::Accelerator: - default: - break; - } - - // the following block handles item-specific behavior - if (role() == QAccessible::EditableText) { - if (textType == QAccessible::Value) { - if (QTextDocument *doc = textDocument()) { - return doc->toPlainText(); - } - QVariant text = object()->property("text"); - return text.toString(); - } - } - - return QString(); -} - -void *QAccessibleQuickItem::interface_cast(QAccessible::InterfaceType t) -{ - QAccessible::Role r = role(); - if (t == QAccessible::ValueInterface && - (r == QAccessible::Slider || - r == QAccessible::SpinBox || - r == QAccessible::Dial || - r == QAccessible::ScrollBar)) - return static_cast(this); - - if (t == QAccessible::TextInterface && - (r == QAccessible::EditableText)) - return static_cast(this); - - return QQmlAccessible::interface_cast(t); -} - -QVariant QAccessibleQuickItem::currentValue() const -{ - return item()->property("value"); -} - -void QAccessibleQuickItem::setCurrentValue(const QVariant &value) -{ - item()->setProperty("value", value); -} - -QVariant QAccessibleQuickItem::maximumValue() const -{ - return item()->property("maximumValue"); -} - -QVariant QAccessibleQuickItem::minimumValue() const -{ - return item()->property("minimumValue"); -} - -QVariant QAccessibleQuickItem::minimumStepSize() const -{ - return item()->property("stepSize"); -} - -/*! - \internal - Shared between QAccessibleQuickItem and QAccessibleQuickView -*/ -QRect itemScreenRect(QQuickItem *item) -{ - // ### no window in some cases. - // ### Should we really check for 0 opacity? - if (!item->window() ||!item->isVisible() || qFuzzyIsNull(item->opacity())) { - return QRect(); - } - - QSize itemSize((int)item->width(), (int)item->height()); - // ### If the bounding rect fails, we first try the implicit size, then we go for the - // parent size. WE MIGHT HAVE TO REVISIT THESE FALLBACKS. - if (itemSize.isEmpty()) { - itemSize = QSize((int)item->implicitWidth(), (int)item->implicitHeight()); - if (itemSize.isEmpty() && item->parentItem()) - // ### Seems that the above fallback is not enough, fallback to use the parent size... - itemSize = QSize((int)item->parentItem()->width(), (int)item->parentItem()->height()); - } - - QPointF scenePoint = item->mapToScene(QPointF(0, 0)); - QPoint screenPos = item->window()->mapToGlobal(scenePoint.toPoint()); - return QRect(screenPos, itemSize); -} - -QTextDocument *QAccessibleQuickItem::textDocument() const -{ - QVariant docVariant = item()->property("textDocument"); - if (docVariant.canConvert()) { - QQuickTextDocument *qqdoc = docVariant.value(); - return qqdoc->textDocument(); - } - return 0; -} - -int QAccessibleQuickItem::characterCount() const -{ - if (m_doc) { - QTextCursor cursor = QTextCursor(m_doc); - cursor.movePosition(QTextCursor::End); - return cursor.position(); - } - return text(QAccessible::Value).size(); -} - -int QAccessibleQuickItem::cursorPosition() const -{ - QVariant pos = item()->property("cursorPosition"); - return pos.toInt(); -} - -void QAccessibleQuickItem::setCursorPosition(int position) -{ - item()->setProperty("cursorPosition", position); -} - -QString QAccessibleQuickItem::text(int startOffset, int endOffset) const -{ - if (m_doc) { - QTextCursor cursor = QTextCursor(m_doc); - cursor.setPosition(startOffset); - cursor.setPosition(endOffset, QTextCursor::KeepAnchor); - return cursor.selectedText(); - } - return text(QAccessible::Value).mid(startOffset, endOffset - startOffset); -} - -QString QAccessibleQuickItem::textBeforeOffset(int offset, QAccessible::TextBoundaryType boundaryType, - int *startOffset, int *endOffset) const -{ - Q_ASSERT(startOffset); - Q_ASSERT(endOffset); - - if (m_doc) { - QTextCursor cursor = QTextCursor(m_doc); - cursor.setPosition(offset); - QPair boundaries = QAccessible::qAccessibleTextBoundaryHelper(cursor, boundaryType); - cursor.setPosition(boundaries.first - 1); - boundaries = QAccessible::qAccessibleTextBoundaryHelper(cursor, boundaryType); - - *startOffset = boundaries.first; - *endOffset = boundaries.second; - - return text(boundaries.first, boundaries.second); - } else { - return QAccessibleTextInterface::textBeforeOffset(offset, boundaryType, startOffset, endOffset); - } -} - -QString QAccessibleQuickItem::textAfterOffset(int offset, QAccessible::TextBoundaryType boundaryType, - int *startOffset, int *endOffset) const -{ - Q_ASSERT(startOffset); - Q_ASSERT(endOffset); - - if (m_doc) { - QTextCursor cursor = QTextCursor(m_doc); - cursor.setPosition(offset); - QPair boundaries = QAccessible::qAccessibleTextBoundaryHelper(cursor, boundaryType); - cursor.setPosition(boundaries.second); - boundaries = QAccessible::qAccessibleTextBoundaryHelper(cursor, boundaryType); - - *startOffset = boundaries.first; - *endOffset = boundaries.second; - - return text(boundaries.first, boundaries.second); - } else { - return QAccessibleTextInterface::textAfterOffset(offset, boundaryType, startOffset, endOffset); - } -} - -QString QAccessibleQuickItem::textAtOffset(int offset, QAccessible::TextBoundaryType boundaryType, - int *startOffset, int *endOffset) const -{ - Q_ASSERT(startOffset); - Q_ASSERT(endOffset); - - if (m_doc) { - QTextCursor cursor = QTextCursor(m_doc); - cursor.setPosition(offset); - QPair boundaries = QAccessible::qAccessibleTextBoundaryHelper(cursor, boundaryType); - - *startOffset = boundaries.first; - *endOffset = boundaries.second; - return text(boundaries.first, boundaries.second); - } else { - return QAccessibleTextInterface::textAtOffset(offset, boundaryType, startOffset, endOffset); - } -} - -void QAccessibleQuickItem::selection(int selectionIndex, int *startOffset, int *endOffset) const -{ - if (selectionIndex == 0) { - *startOffset = item()->property("selectionStart").toInt(); - *endOffset = item()->property("selectionEnd").toInt(); - } else { - *startOffset = 0; - *endOffset = 0; - } -} - -int QAccessibleQuickItem::selectionCount() const -{ - if (item()->property("selectionStart").toInt() != item()->property("selectionEnd").toInt()) - return 1; - return 0; -} - -void QAccessibleQuickItem::addSelection(int /* startOffset */, int /* endOffset */) -{ - -} -void QAccessibleQuickItem::removeSelection(int /* selectionIndex */) -{ - -} -void QAccessibleQuickItem::setSelection(int /* selectionIndex */, int /* startOffset */, int /* endOffset */) -{ - -} - - -#endif // QT_NO_ACCESSIBILITY - -QT_END_NAMESPACE diff --git a/src/plugins/accessible/quick/qaccessiblequickitem.h b/src/plugins/accessible/quick/qaccessiblequickitem.h deleted file mode 100644 index d9eb652030..0000000000 --- a/src/plugins/accessible/quick/qaccessiblequickitem.h +++ /dev/null @@ -1,130 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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: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 QACCESSIBLEQUICKITEM_H -#define QACCESSIBLEQUICKITEM_H - -#include -#include -#include "qqmlaccessible.h" - -QT_BEGIN_NAMESPACE - -#ifndef QT_NO_ACCESSIBILITY - -class QTextDocument; - -class QAccessibleQuickItem : public QQmlAccessible, public QAccessibleValueInterface, public QAccessibleTextInterface -{ -public: - QAccessibleQuickItem(QQuickItem *item); - - QRect rect() const; - QRect viewRect() const; - - bool clipsChildren() const; - - QAccessibleInterface *parent() const; - QAccessibleInterface *child(int index) const; - int childCount() const; - int indexOfChild(const QAccessibleInterface *iface) const; - QList childItems() const; - - QAccessible::State state() const; - QAccessible::Role role() const; - QString text(QAccessible::Text) const; - - bool isAccessible() const; - - // Value Interface - QVariant currentValue() const; - void setCurrentValue(const QVariant &value); - QVariant maximumValue() const; - QVariant minimumValue() const; - QVariant minimumStepSize() const; - - - // Text Interface - void selection(int selectionIndex, int *startOffset, int *endOffset) const; - int selectionCount() const; - void addSelection(int startOffset, int endOffset); - void removeSelection(int selectionIndex); - void setSelection(int selectionIndex, int startOffset, int endOffset); - - // cursor - int cursorPosition() const; - void setCursorPosition(int position); - - // text - QString text(int startOffset, int endOffset) const; - QString textBeforeOffset(int offset, QAccessible::TextBoundaryType boundaryType, - int *startOffset, int *endOffset) const; - QString textAfterOffset(int offset, QAccessible::TextBoundaryType boundaryType, - int *startOffset, int *endOffset) const; - QString textAtOffset(int offset, QAccessible::TextBoundaryType boundaryType, - int *startOffset, int *endOffset) const; - int characterCount() const; - - // character <-> geometry - QRect characterRect(int /* offset */) const { return QRect(); } - int offsetAtPoint(const QPoint & /* point */) const { return -1; } - - void scrollToSubstring(int /* startIndex */, int /* endIndex */) {} - QString attributes(int /* offset */, int *startOffset, int *endOffset) const { *startOffset = 0; *endOffset = 0; return QString(); } - - QTextDocument *textDocument() const; - -protected: - QQuickItem *item() const { return static_cast(object()); } - void *interface_cast(QAccessible::InterfaceType t); - -private: - QTextDocument *m_doc; -}; - -QRect itemScreenRect(QQuickItem *item); - - -#endif // QT_NO_ACCESSIBILITY - -QT_END_NAMESPACE - -#endif // QACCESSIBLEQUICKITEM_H diff --git a/src/plugins/accessible/quick/qaccessiblequickview.cpp b/src/plugins/accessible/quick/qaccessiblequickview.cpp deleted file mode 100644 index 1240b2ef4c..0000000000 --- a/src/plugins/accessible/quick/qaccessiblequickview.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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: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 "qaccessiblequickview.h" - -#include - -#include -#include - -#include "qaccessiblequickitem.h" -#include "qqmlaccessible.h" - -#ifndef QT_NO_ACCESSIBILITY - -QT_BEGIN_NAMESPACE - -QAccessibleQuickWindow::QAccessibleQuickWindow(QQuickWindow *object) - :QAccessibleObject(object) -{ -} - -QQuickItem *QAccessibleQuickWindow::rootItem() const -{ - if (QQuickItem *ci = window()->contentItem()) { - const QList &childItems = ci->childItems(); - if (!childItems.isEmpty()) - return childItems.first(); - } - return 0; -} - -int QAccessibleQuickWindow::childCount() const -{ - return rootItem() ? 1 : 0; -} - -QAccessibleInterface *QAccessibleQuickWindow::parent() const -{ - // FIXME: for now we assume to be a top level window... - return QAccessible::queryAccessibleInterface(qApp); -} - -QAccessibleInterface *QAccessibleQuickWindow::child(int index) const -{ - if (index == 0) - return QAccessible::queryAccessibleInterface(rootItem()); - return 0; -} - -QAccessible::Role QAccessibleQuickWindow::role() const -{ - return QAccessible::Window; // FIXME -} - -QAccessible::State QAccessibleQuickWindow::state() const -{ - QAccessible::State st; - if (window() == QGuiApplication::focusWindow()) - st.active = true; - if (!window()->isVisible()) - st.invisible = true; - return st; -} - -QRect QAccessibleQuickWindow::rect() const -{ - return QRect(window()->x(), window()->y(), window()->width(), window()->height()); -} - -QString QAccessibleQuickWindow::text(QAccessible::Text text) const -{ -#ifdef Q_ACCESSIBLE_QUICK_ITEM_ENABLE_DEBUG_DESCRIPTION - if (text == QAccessible::DebugDescription) { - return QString::fromLatin1(object()->metaObject()->className()) ; - } -#else - Q_UNUSED(text) -#endif - return window()->title(); -} - - -/*! - \internal - - Can also return \a item itself - */ -static QQuickItem *childAt_helper(QQuickItem *item, int x, int y) -{ - if (!item->isVisible() || !item->isEnabled()) - return 0; - - if (item->flags() & QQuickItem::ItemClipsChildrenToShape) { - if (!itemScreenRect(item).contains(x, y)) - return 0; - } - - QAccessibleInterface *accessibleInterface = QAccessible::queryAccessibleInterface(item); - // this item has no Accessible attached property - if (!accessibleInterface) - return 0; - - if (accessibleInterface->childCount() == 0) { - return (itemScreenRect(item).contains(x, y)) ? item : 0; - } - - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); - - QList children = itemPrivate->paintOrderChildItems(); - for (int i = children.count() - 1; i >= 0; --i) { - QQuickItem *child = children.at(i); - if (QQuickItem *childChild = childAt_helper(child, x, y)) - return childChild; - } - - QRect screenRect = itemScreenRect(item); - - if (screenRect.contains(x, y)) - return item; - - return 0; -} - -QAccessibleInterface *QAccessibleQuickWindow::childAt(int x, int y) const -{ - Q_ASSERT(window()); - QQuickItem *root = rootItem(); - if (root) { - if (QQuickItem *item = childAt_helper(root, x, y)) - return QAccessible::queryAccessibleInterface(item); - return QAccessible::queryAccessibleInterface(root); - } - return 0; -} - -int QAccessibleQuickWindow::indexOfChild(const QAccessibleInterface *iface) const -{ - if (iface) { - QQuickItem *declarativeRoot = rootItem(); - if (declarativeRoot == iface->object()) - return 0; - } - return -1; -} - -QT_END_NAMESPACE - -#endif // QT_NO_ACCESSIBILITY diff --git a/src/plugins/accessible/quick/qaccessiblequickview.h b/src/plugins/accessible/quick/qaccessiblequickview.h deleted file mode 100644 index 41c34c5432..0000000000 --- a/src/plugins/accessible/quick/qaccessiblequickview.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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: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 QAccessibleQuickView_H -#define QAccessibleQuickView_H - -#include -#include - -QT_BEGIN_NAMESPACE - -#ifndef QT_NO_ACCESSIBILITY - -class QAccessibleQuickWindow : public QAccessibleObject -{ -public: - QAccessibleQuickWindow(QQuickWindow *object); - - QAccessibleInterface *parent() const; - QAccessibleInterface *child(int index) const; - - QAccessible::Role role() const; - QAccessible::State state() const; - QRect rect() const; - - int childCount() const; - int indexOfChild(const QAccessibleInterface *iface) const; - QString text(QAccessible::Text text) const; - QAccessibleInterface *childAt(int x, int y) const; - -private: - QQuickWindow *window() const { return static_cast(object()); } - QQuickItem *rootItem() const; -}; - -#endif // QT_NO_ACCESSIBILITY - -QT_END_NAMESPACE - -#endif // QAccessibleQuickView_H diff --git a/src/plugins/accessible/quick/quick.pro b/src/plugins/accessible/quick/quick.pro deleted file mode 100644 index eeececae8b..0000000000 --- a/src/plugins/accessible/quick/quick.pro +++ /dev/null @@ -1,22 +0,0 @@ -TARGET = qtaccessiblequick - -PLUGIN_TYPE = accessible -PLUGIN_CLASS_NAME = AccessibleQuickFactory -load(qt_plugin) - -include ($$PWD/../shared/qaccessiblebase.pri) - -QT += core-private gui-private qml-private quick-private - -#DEFINES+=Q_ACCESSIBLE_QUICK_ITEM_ENABLE_DEBUG_DESCRIPTION - -SOURCES += \ - main.cpp \ - qaccessiblequickview.cpp \ - qaccessiblequickitem.cpp - -HEADERS += \ - qaccessiblequickview.h \ - qaccessiblequickitem.h - -OTHERFILES += accessible.json diff --git a/src/plugins/accessible/shared/qaccessiblebase.pri b/src/plugins/accessible/shared/qaccessiblebase.pri deleted file mode 100644 index 827df0f132..0000000000 --- a/src/plugins/accessible/shared/qaccessiblebase.pri +++ /dev/null @@ -1,3 +0,0 @@ -INCLUDEPATH += $$PWD -SOURCES += $$PWD/qqmlaccessible.cpp -HEADERS += $$PWD/qqmlaccessible.h diff --git a/src/plugins/accessible/shared/qqmlaccessible.cpp b/src/plugins/accessible/shared/qqmlaccessible.cpp deleted file mode 100644 index ecf4e56acf..0000000000 --- a/src/plugins/accessible/shared/qqmlaccessible.cpp +++ /dev/null @@ -1,224 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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: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 -#include "qqmlaccessible.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() -{ -} - -QAccessibleInterface *QQmlAccessible::childAt(int x, int y) const -{ - // Note that this function will disregard stacking order. - // (QAccessibleQuickView::childAt() does this correctly and more efficient) - - // If the item clips its children, we can return early if the coordinate is outside its rect - if (clipsChildren()) { - if (!rect().contains(x, y)) - return 0; - } - - for (int i = childCount() - 1; i >= 0; --i) { - QAccessibleInterface *childIface = child(i); - if (childIface && !childIface->state().invisible) { - if (childIface->rect().contains(x, y)) - return childIface; - } - } - return 0; -} - -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 = "accessible" + actionName.toLatin1() + "Action"; - if (object()->metaObject()->indexOfMethod(functionName + "()") != -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/plugins/accessible/shared/qqmlaccessible.h b/src/plugins/accessible/shared/qqmlaccessible.h deleted file mode 100644 index b6da016b2d..0000000000 --- a/src/plugins/accessible/shared/qqmlaccessible.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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: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 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; - QAccessibleInterface *childAt(int, int) const; - QAccessible::State state() const; - - QStringList actionNames() const; - void doAction(const QString &actionName); - QStringList keyBindingsForAction(const QString &actionName) const; - -protected: - virtual bool clipsChildren() const = 0; - // For subclasses, use instantiateObject factory method outside the class. - QQmlAccessible(QObject *object); -}; - -#endif // QT_NO_ACCESSIBILITY - -QT_END_NAMESPACE - -#endif // QQMLACCESSIBLE_H diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 9ef8c7ab72..664a457608 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -1,5 +1,2 @@ TEMPLATE = subdirs SUBDIRS += qmltooling -contains(QT_CONFIG, accessibility) { - SUBDIRS += accessible -} diff --git a/src/quick/accessible/accessible.pri b/src/quick/accessible/accessible.pri new file mode 100644 index 0000000000..88ff747488 --- /dev/null +++ b/src/quick/accessible/accessible.pri @@ -0,0 +1,16 @@ + +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 new file mode 100644 index 0000000000..bc2b4de86a --- /dev/null +++ b/src/quick/accessible/qaccessiblequickitem.cpp @@ -0,0 +1,447 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQuick 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 "qaccessiblequickitem_p.h" + +#include + +#include "QtQuick/private/qquickitem_p.h" +#include "QtQuick/private/qquicktext_p.h" +#include "QtQuick/private/qquickaccessibleattached_p.h" +#include "QtQuick/qquicktextdocument.h" + +QT_BEGIN_NAMESPACE + +#ifndef QT_NO_ACCESSIBILITY + +QAccessibleQuickItem::QAccessibleQuickItem(QQuickItem *item) + : QQmlAccessible(item), m_doc(textDocument()) +{ +} + +int QAccessibleQuickItem::childCount() const +{ + return childItems().count(); +} + +QRect QAccessibleQuickItem::rect() const +{ + const QRect r = itemScreenRect(item()); + + if (!r.isValid()) { + qWarning() << item()->metaObject()->className() << item()->property("accessibleText") << r; + } + return r; +} + +QRect QAccessibleQuickItem::viewRect() const +{ + // ### no window in some cases. + if (!item()->window()) { + return QRect(); + } + + QQuickWindow *window = item()->window(); + QPoint screenPos = window->mapToGlobal(QPoint(0,0)); + return QRect(screenPos, window->size()); +} + + +bool QAccessibleQuickItem::clipsChildren() const +{ + return static_cast(item())->clip(); +} + +QAccessibleInterface *QAccessibleQuickItem::parent() const +{ + QQuickItem *parent = item()->parentItem(); + if (parent) { + QQuickWindow *window = item()->window(); + // Jump out to the scene widget if the parent is the root item. + // There are two root items, QQuickWindow::rootItem and + // QQuickView::declarativeRoot. The former is the true root item, + // but is not a part of the accessibility tree. Check if we hit + // it here and return an interface for the scene instead. + if (window && (parent == window->contentItem())) { + return QAccessible::queryAccessibleInterface(window); + } else { + return QAccessible::queryAccessibleInterface(parent); + } + } + return 0; +} + +QAccessibleInterface *QAccessibleQuickItem::child(int index) const +{ + QList children = childItems(); + + if (index < 0 || index >= children.count()) + return 0; + + QQuickItem *child = children.at(index); + if (!child) // FIXME can this happen? + return 0; + + return QAccessible::queryAccessibleInterface(child); +} + +int QAccessibleQuickItem::indexOfChild(const QAccessibleInterface *iface) const +{ + QList kids = childItems(); + return kids.indexOf(static_cast(iface->object())); +} + +QList QAccessibleQuickItem::childItems() const +{ + if ( role() == QAccessible::Button || + role() == QAccessible::CheckBox || + role() == QAccessible::RadioButton || + role() == QAccessible::SpinBox || + role() == QAccessible::EditableText || + role() == QAccessible::Slider || + role() == QAccessible::PageTab || + role() == QAccessible::ProgressBar) + return QList(); + + QList items; + Q_FOREACH (QQuickItem *child, item()->childItems()) { + QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(child); + if (itemPrivate->isAccessible) + items.append(child); + } + return items; +} + +QAccessible::State QAccessibleQuickItem::state() const +{ + QQuickAccessibleAttached *attached = QQuickAccessibleAttached::attachedProperties(item()); + if (!attached) + return QAccessible::State(); + + QAccessible::State st = attached->state(); + + if (!item()->window() || !item()->window()->isVisible() ||!item()->isVisible() || qFuzzyIsNull(item()->opacity())) + st.invisible = true; + + if (item()->activeFocusOnTab()) + st.focusable = true; + if (item()->hasActiveFocus()) + st.focused = true; + + if (role() == QAccessible::ComboBox) + st.editable = item()->property("editable").toBool(); + + return st; +} + +QAccessible::Role QAccessibleQuickItem::role() const +{ + // Workaround for setAccessibleRole() not working for + // Text items. Text items are special since they are defined + // entirely from C++ (setting the role from QML works.) + if (qobject_cast(const_cast(item()))) + return QAccessible::StaticText; + + QVariant v = QQuickAccessibleAttached::property(item(), "role"); + bool ok; + QAccessible::Role role = (QAccessible::Role)v.toInt(&ok); + if (!ok) // Not sure if this check is needed. + role = QAccessible::Pane; + return role; +} + +bool QAccessibleQuickItem::isAccessible() const +{ + return item()->d_func()->isAccessible; +} + +QString QAccessibleQuickItem::text(QAccessible::Text textType) const +{ + // handles generic behavior not specific to an item + switch (textType) { + case QAccessible::Name: { + QVariant accessibleName = QQuickAccessibleAttached::property(object(), "name"); + if (!accessibleName.isNull()) + return accessibleName.toString(); + break;} + case QAccessible::Description: { + QVariant accessibleDecription = QQuickAccessibleAttached::property(object(), "description"); + if (!accessibleDecription.isNull()) + return accessibleDecription.toString(); + break;} +#ifdef Q_ACCESSIBLE_QUICK_ITEM_ENABLE_DEBUG_DESCRIPTION + case QAccessible::DebugDescription: { + QString debugString; + debugString = QString::fromLatin1(object()->metaObject()->className()) + QLatin1Char(' '); + debugString += isAccessible() ? QLatin1String("enabled") : QLatin1String("disabled"); + return debugString; + break; } +#endif + case QAccessible::Value: + case QAccessible::Help: + case QAccessible::Accelerator: + default: + break; + } + + // the following block handles item-specific behavior + if (role() == QAccessible::EditableText) { + if (textType == QAccessible::Value) { + if (QTextDocument *doc = textDocument()) { + return doc->toPlainText(); + } + QVariant text = object()->property("text"); + return text.toString(); + } + } + + return QString(); +} + +void *QAccessibleQuickItem::interface_cast(QAccessible::InterfaceType t) +{ + QAccessible::Role r = role(); + if (t == QAccessible::ValueInterface && + (r == QAccessible::Slider || + r == QAccessible::SpinBox || + r == QAccessible::Dial || + r == QAccessible::ScrollBar)) + return static_cast(this); + + if (t == QAccessible::TextInterface && + (r == QAccessible::EditableText)) + return static_cast(this); + + return QQmlAccessible::interface_cast(t); +} + +QVariant QAccessibleQuickItem::currentValue() const +{ + return item()->property("value"); +} + +void QAccessibleQuickItem::setCurrentValue(const QVariant &value) +{ + item()->setProperty("value", value); +} + +QVariant QAccessibleQuickItem::maximumValue() const +{ + return item()->property("maximumValue"); +} + +QVariant QAccessibleQuickItem::minimumValue() const +{ + return item()->property("minimumValue"); +} + +QVariant QAccessibleQuickItem::minimumStepSize() const +{ + return item()->property("stepSize"); +} + +/*! + \internal + Shared between QAccessibleQuickItem and QAccessibleQuickView +*/ +QRect itemScreenRect(QQuickItem *item) +{ + // ### no window in some cases. + // ### Should we really check for 0 opacity? + if (!item->window() ||!item->isVisible() || qFuzzyIsNull(item->opacity())) { + return QRect(); + } + + QSize itemSize((int)item->width(), (int)item->height()); + // ### If the bounding rect fails, we first try the implicit size, then we go for the + // parent size. WE MIGHT HAVE TO REVISIT THESE FALLBACKS. + if (itemSize.isEmpty()) { + itemSize = QSize((int)item->implicitWidth(), (int)item->implicitHeight()); + if (itemSize.isEmpty() && item->parentItem()) + // ### Seems that the above fallback is not enough, fallback to use the parent size... + itemSize = QSize((int)item->parentItem()->width(), (int)item->parentItem()->height()); + } + + QPointF scenePoint = item->mapToScene(QPointF(0, 0)); + QPoint screenPos = item->window()->mapToGlobal(scenePoint.toPoint()); + return QRect(screenPos, itemSize); +} + +QTextDocument *QAccessibleQuickItem::textDocument() const +{ + QVariant docVariant = item()->property("textDocument"); + if (docVariant.canConvert()) { + QQuickTextDocument *qqdoc = docVariant.value(); + return qqdoc->textDocument(); + } + return 0; +} + +int QAccessibleQuickItem::characterCount() const +{ + if (m_doc) { + QTextCursor cursor = QTextCursor(m_doc); + cursor.movePosition(QTextCursor::End); + return cursor.position(); + } + return text(QAccessible::Value).size(); +} + +int QAccessibleQuickItem::cursorPosition() const +{ + QVariant pos = item()->property("cursorPosition"); + return pos.toInt(); +} + +void QAccessibleQuickItem::setCursorPosition(int position) +{ + item()->setProperty("cursorPosition", position); +} + +QString QAccessibleQuickItem::text(int startOffset, int endOffset) const +{ + if (m_doc) { + QTextCursor cursor = QTextCursor(m_doc); + cursor.setPosition(startOffset); + cursor.setPosition(endOffset, QTextCursor::KeepAnchor); + return cursor.selectedText(); + } + return text(QAccessible::Value).mid(startOffset, endOffset - startOffset); +} + +QString QAccessibleQuickItem::textBeforeOffset(int offset, QAccessible::TextBoundaryType boundaryType, + int *startOffset, int *endOffset) const +{ + Q_ASSERT(startOffset); + Q_ASSERT(endOffset); + + if (m_doc) { + QTextCursor cursor = QTextCursor(m_doc); + cursor.setPosition(offset); + QPair boundaries = QAccessible::qAccessibleTextBoundaryHelper(cursor, boundaryType); + cursor.setPosition(boundaries.first - 1); + boundaries = QAccessible::qAccessibleTextBoundaryHelper(cursor, boundaryType); + + *startOffset = boundaries.first; + *endOffset = boundaries.second; + + return text(boundaries.first, boundaries.second); + } else { + return QAccessibleTextInterface::textBeforeOffset(offset, boundaryType, startOffset, endOffset); + } +} + +QString QAccessibleQuickItem::textAfterOffset(int offset, QAccessible::TextBoundaryType boundaryType, + int *startOffset, int *endOffset) const +{ + Q_ASSERT(startOffset); + Q_ASSERT(endOffset); + + if (m_doc) { + QTextCursor cursor = QTextCursor(m_doc); + cursor.setPosition(offset); + QPair boundaries = QAccessible::qAccessibleTextBoundaryHelper(cursor, boundaryType); + cursor.setPosition(boundaries.second); + boundaries = QAccessible::qAccessibleTextBoundaryHelper(cursor, boundaryType); + + *startOffset = boundaries.first; + *endOffset = boundaries.second; + + return text(boundaries.first, boundaries.second); + } else { + return QAccessibleTextInterface::textAfterOffset(offset, boundaryType, startOffset, endOffset); + } +} + +QString QAccessibleQuickItem::textAtOffset(int offset, QAccessible::TextBoundaryType boundaryType, + int *startOffset, int *endOffset) const +{ + Q_ASSERT(startOffset); + Q_ASSERT(endOffset); + + if (m_doc) { + QTextCursor cursor = QTextCursor(m_doc); + cursor.setPosition(offset); + QPair boundaries = QAccessible::qAccessibleTextBoundaryHelper(cursor, boundaryType); + + *startOffset = boundaries.first; + *endOffset = boundaries.second; + return text(boundaries.first, boundaries.second); + } else { + return QAccessibleTextInterface::textAtOffset(offset, boundaryType, startOffset, endOffset); + } +} + +void QAccessibleQuickItem::selection(int selectionIndex, int *startOffset, int *endOffset) const +{ + if (selectionIndex == 0) { + *startOffset = item()->property("selectionStart").toInt(); + *endOffset = item()->property("selectionEnd").toInt(); + } else { + *startOffset = 0; + *endOffset = 0; + } +} + +int QAccessibleQuickItem::selectionCount() const +{ + if (item()->property("selectionStart").toInt() != item()->property("selectionEnd").toInt()) + return 1; + return 0; +} + +void QAccessibleQuickItem::addSelection(int /* startOffset */, int /* endOffset */) +{ + +} +void QAccessibleQuickItem::removeSelection(int /* selectionIndex */) +{ + +} +void QAccessibleQuickItem::setSelection(int /* selectionIndex */, int /* startOffset */, int /* endOffset */) +{ + +} + + +#endif // QT_NO_ACCESSIBILITY + +QT_END_NAMESPACE diff --git a/src/quick/accessible/qaccessiblequickitem_p.h b/src/quick/accessible/qaccessiblequickitem_p.h new file mode 100644 index 0000000000..354e0bf9f7 --- /dev/null +++ b/src/quick/accessible/qaccessiblequickitem_p.h @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQuick 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 QACCESSIBLEQUICKITEM_H +#define QACCESSIBLEQUICKITEM_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +#ifndef QT_NO_ACCESSIBILITY + +class QTextDocument; + +class QAccessibleQuickItem : public QQmlAccessible, public QAccessibleValueInterface, public QAccessibleTextInterface +{ +public: + QAccessibleQuickItem(QQuickItem *item); + + QRect rect() const; + QRect viewRect() const; + + bool clipsChildren() const; + + QAccessibleInterface *parent() const; + QAccessibleInterface *child(int index) const; + int childCount() const; + int indexOfChild(const QAccessibleInterface *iface) const; + QList childItems() const; + + QAccessible::State state() const; + QAccessible::Role role() const; + QString text(QAccessible::Text) const; + + bool isAccessible() const; + + // Value Interface + QVariant currentValue() const; + void setCurrentValue(const QVariant &value); + QVariant maximumValue() const; + QVariant minimumValue() const; + QVariant minimumStepSize() const; + + + // Text Interface + void selection(int selectionIndex, int *startOffset, int *endOffset) const; + int selectionCount() const; + void addSelection(int startOffset, int endOffset); + void removeSelection(int selectionIndex); + void setSelection(int selectionIndex, int startOffset, int endOffset); + + // cursor + int cursorPosition() const; + void setCursorPosition(int position); + + // text + QString text(int startOffset, int endOffset) const; + QString textBeforeOffset(int offset, QAccessible::TextBoundaryType boundaryType, + int *startOffset, int *endOffset) const; + QString textAfterOffset(int offset, QAccessible::TextBoundaryType boundaryType, + int *startOffset, int *endOffset) const; + QString textAtOffset(int offset, QAccessible::TextBoundaryType boundaryType, + int *startOffset, int *endOffset) const; + int characterCount() const; + + // character <-> geometry + QRect characterRect(int /* offset */) const { return QRect(); } + int offsetAtPoint(const QPoint & /* point */) const { return -1; } + + void scrollToSubstring(int /* startIndex */, int /* endIndex */) {} + QString attributes(int /* offset */, int *startOffset, int *endOffset) const { *startOffset = 0; *endOffset = 0; return QString(); } + + QTextDocument *textDocument() const; + +protected: + QQuickItem *item() const { return static_cast(object()); } + void *interface_cast(QAccessible::InterfaceType t); + +private: + QTextDocument *m_doc; +}; + +QRect itemScreenRect(QQuickItem *item); + + +#endif // QT_NO_ACCESSIBILITY + +QT_END_NAMESPACE + +#endif // QACCESSIBLEQUICKITEM_H diff --git a/src/quick/accessible/qaccessiblequickview.cpp b/src/quick/accessible/qaccessiblequickview.cpp new file mode 100644 index 0000000000..05e37d6240 --- /dev/null +++ b/src/quick/accessible/qaccessiblequickview.cpp @@ -0,0 +1,187 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQuick 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 "qaccessiblequickview_p.h" + +#include + +#include +#include + +#include "qaccessiblequickitem_p.h" +#include "qqmlaccessible_p.h" + +#ifndef QT_NO_ACCESSIBILITY + +QT_BEGIN_NAMESPACE + +QAccessibleQuickWindow::QAccessibleQuickWindow(QQuickWindow *object) + :QAccessibleObject(object) +{ +} + +QQuickItem *QAccessibleQuickWindow::rootItem() const +{ + if (QQuickItem *ci = window()->contentItem()) { + const QList &childItems = ci->childItems(); + if (!childItems.isEmpty()) + return childItems.first(); + } + return 0; +} + +int QAccessibleQuickWindow::childCount() const +{ + return rootItem() ? 1 : 0; +} + +QAccessibleInterface *QAccessibleQuickWindow::parent() const +{ + // FIXME: for now we assume to be a top level window... + return QAccessible::queryAccessibleInterface(qApp); +} + +QAccessibleInterface *QAccessibleQuickWindow::child(int index) const +{ + if (index == 0) + return QAccessible::queryAccessibleInterface(rootItem()); + return 0; +} + +QAccessible::Role QAccessibleQuickWindow::role() const +{ + return QAccessible::Window; // FIXME +} + +QAccessible::State QAccessibleQuickWindow::state() const +{ + QAccessible::State st; + if (window() == QGuiApplication::focusWindow()) + st.active = true; + if (!window()->isVisible()) + st.invisible = true; + return st; +} + +QRect QAccessibleQuickWindow::rect() const +{ + return QRect(window()->x(), window()->y(), window()->width(), window()->height()); +} + +QString QAccessibleQuickWindow::text(QAccessible::Text text) const +{ +#ifdef Q_ACCESSIBLE_QUICK_ITEM_ENABLE_DEBUG_DESCRIPTION + if (text == QAccessible::DebugDescription) { + return QString::fromLatin1(object()->metaObject()->className()) ; + } +#else + Q_UNUSED(text) +#endif + return window()->title(); +} + + +/*! + \internal + + Can also return \a item itself + */ +static QQuickItem *childAt_helper(QQuickItem *item, int x, int y) +{ + if (!item->isVisible() || !item->isEnabled()) + return 0; + + if (item->flags() & QQuickItem::ItemClipsChildrenToShape) { + if (!itemScreenRect(item).contains(x, y)) + return 0; + } + + QAccessibleInterface *accessibleInterface = QAccessible::queryAccessibleInterface(item); + // this item has no Accessible attached property + if (!accessibleInterface) + return 0; + + if (accessibleInterface->childCount() == 0) { + return (itemScreenRect(item).contains(x, y)) ? item : 0; + } + + QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); + + QList children = itemPrivate->paintOrderChildItems(); + for (int i = children.count() - 1; i >= 0; --i) { + QQuickItem *child = children.at(i); + if (QQuickItem *childChild = childAt_helper(child, x, y)) + return childChild; + } + + QRect screenRect = itemScreenRect(item); + + if (screenRect.contains(x, y)) + return item; + + return 0; +} + +QAccessibleInterface *QAccessibleQuickWindow::childAt(int x, int y) const +{ + Q_ASSERT(window()); + QQuickItem *root = rootItem(); + if (root) { + if (QQuickItem *item = childAt_helper(root, x, y)) + return QAccessible::queryAccessibleInterface(item); + return QAccessible::queryAccessibleInterface(root); + } + return 0; +} + +int QAccessibleQuickWindow::indexOfChild(const QAccessibleInterface *iface) const +{ + if (iface) { + QQuickItem *declarativeRoot = rootItem(); + if (declarativeRoot == iface->object()) + return 0; + } + return -1; +} + +QT_END_NAMESPACE + +#endif // QT_NO_ACCESSIBILITY diff --git a/src/quick/accessible/qaccessiblequickview_p.h b/src/quick/accessible/qaccessiblequickview_p.h new file mode 100644 index 0000000000..f14d4c9584 --- /dev/null +++ b/src/quick/accessible/qaccessiblequickview_p.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQuick 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 QAccessibleQuickView_H +#define QAccessibleQuickView_H + +#include +#include + +QT_BEGIN_NAMESPACE + +#ifndef QT_NO_ACCESSIBILITY + +class QAccessibleQuickWindow : public QAccessibleObject +{ +public: + QAccessibleQuickWindow(QQuickWindow *object); + + QAccessibleInterface *parent() const; + QAccessibleInterface *child(int index) const; + + QAccessible::Role role() const; + QAccessible::State state() const; + QRect rect() const; + + int childCount() const; + int indexOfChild(const QAccessibleInterface *iface) const; + QString text(QAccessible::Text text) const; + QAccessibleInterface *childAt(int x, int y) const; + +private: + QQuickWindow *window() const { return static_cast(object()); } + QQuickItem *rootItem() const; +}; + +#endif // QT_NO_ACCESSIBILITY + +QT_END_NAMESPACE + +#endif // QAccessibleQuickView_H diff --git a/src/quick/accessible/qqmlaccessible.cpp b/src/quick/accessible/qqmlaccessible.cpp new file mode 100644 index 0000000000..abe94537a9 --- /dev/null +++ b/src/quick/accessible/qqmlaccessible.cpp @@ -0,0 +1,224 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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: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 +#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() +{ +} + +QAccessibleInterface *QQmlAccessible::childAt(int x, int y) const +{ + // Note that this function will disregard stacking order. + // (QAccessibleQuickView::childAt() does this correctly and more efficient) + + // If the item clips its children, we can return early if the coordinate is outside its rect + if (clipsChildren()) { + if (!rect().contains(x, y)) + return 0; + } + + for (int i = childCount() - 1; i >= 0; --i) { + QAccessibleInterface *childIface = child(i); + if (childIface && !childIface->state().invisible) { + if (childIface->rect().contains(x, y)) + return childIface; + } + } + return 0; +} + +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 new file mode 100644 index 0000000000..b6da016b2d --- /dev/null +++ b/src/quick/accessible/qqmlaccessible_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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: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 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; + QAccessibleInterface *childAt(int, int) const; + QAccessible::State state() const; + + QStringList actionNames() const; + void doAction(const QString &actionName); + QStringList keyBindingsForAction(const QString &actionName) const; + +protected: + virtual bool clipsChildren() const = 0; + // For subclasses, use instantiateObject factory method outside the class. + QQmlAccessible(QObject *object); +}; + +#endif // QT_NO_ACCESSIBILITY + +QT_END_NAMESPACE + +#endif // QQMLACCESSIBLE_H diff --git a/src/quick/accessible/qquickaccessiblefactory.cpp b/src/quick/accessible/qquickaccessiblefactory.cpp new file mode 100644 index 0000000000..d0e7f0f5e8 --- /dev/null +++ b/src/quick/accessible/qquickaccessiblefactory.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQuick 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 "qquickaccessiblefactory_p.h" + +#include "qaccessiblequickview_p.h" +#include "qaccessiblequickitem_p.h" +#include + +QT_BEGIN_NAMESPACE +#ifndef QT_NO_ACCESSIBILITY + +QAccessibleInterface *qQuickAccessibleFactory(const QString &classname, QObject *object) +{ + if (classname == QLatin1String("QQuickWindow")) { + return new QAccessibleQuickWindow(qobject_cast(object)); + } else if (classname == QLatin1String("QQuickItem")) { + QQuickItem *item = qobject_cast(object); + Q_ASSERT(item); + QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); + if (!itemPrivate->isAccessible) + return 0; + return new QAccessibleQuickItem(item); + } + + return 0; +} + +#endif +QT_END_NAMESPACE diff --git a/src/quick/accessible/qquickaccessiblefactory_p.h b/src/quick/accessible/qquickaccessiblefactory_p.h new file mode 100644 index 0000000000..792364b7fa --- /dev/null +++ b/src/quick/accessible/qquickaccessiblefactory_p.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQuick 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 QQUICKACCESSIBLEFACTORY_H +#define QQUICKACCESSIBLEFACTORY_H + +#include + +QT_BEGIN_NAMESPACE +#ifndef QT_NO_ACCESSIBILITY + +QAccessibleInterface *qQuickAccessibleFactory(const QString &classname, QObject *object); + +#endif +QT_END_NAMESPACE + +#endif diff --git a/src/quick/qtquick2.cpp b/src/quick/qtquick2.cpp index 9d2a0b0f75..fe24c2512a 100644 --- a/src/quick/qtquick2.cpp +++ b/src/quick/qtquick2.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -190,6 +191,10 @@ void QQmlQtQuick2Module::defineModule() QQuickValueTypes::registerValueTypes(); +#ifndef QT_NO_ACCESSIBILITY + QAccessible::installFactory(&qQuickAccessibleFactory); +#endif + if (QQmlDebugService::isDebuggingEnabled()) { QQmlEngineDebugService::instance()->setStatesDelegate( new QQmlQtQuick2DebugStatesDelegate); diff --git a/src/quick/quick.pro b/src/quick/quick.pro index 38e743cc5c..6e08662e61 100644 --- a/src/quick/quick.pro +++ b/src/quick/quick.pro @@ -29,6 +29,9 @@ include(util/util.pri) include(scenegraph/scenegraph.pri) include(items/items.pri) include(designer/designer.pri) +contains(QT_CONFIG, accessibility) { + include(accessible/accessible.pri) +} HEADERS += \ qtquickglobal.h \ -- cgit v1.2.3